|
| 1 | +------------------------------------------------- |
| 2 | +-- Blue Light Filter Widget for Awesome Window Manager |
| 3 | +-- More details could be found here: |
| 4 | +-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/bluelight-widget |
| 5 | + |
| 6 | +-- @author VMatt |
| 7 | +-- @copyright 2025 VMatt |
| 8 | +------------------------------------------------- |
| 9 | + |
| 10 | +local awful = require("awful") |
| 11 | +local wibox = require("wibox") |
| 12 | +local gfs = require("gears.filesystem") |
| 13 | + |
| 14 | +local ICON_DIR = gfs.get_configuration_dir() .. "awesome-wm-widgets/bluelight-widget/" |
| 15 | +local DAY_ICON = ICON_DIR .. "sun.svg" |
| 16 | +local NIGHT_ICON = ICON_DIR .. "moon.svg" |
| 17 | + |
| 18 | +local CMD = "redshift" |
| 19 | +local NIGHT_CMD = "-O 2500 -g 0.75" |
| 20 | +local DAY_CMD = "-x" |
| 21 | +local day = true |
| 22 | + |
| 23 | +local widget = wibox.widget({ |
| 24 | + { |
| 25 | + |
| 26 | + { |
| 27 | + id = "icon", |
| 28 | + image = DAY_ICON, |
| 29 | + resize = true, |
| 30 | + widget = wibox.widget.imagebox, |
| 31 | + }, |
| 32 | + layout = wibox.layout.fixed.horizontal, |
| 33 | + widget = wibox.container.margin, |
| 34 | + }, |
| 35 | + border_width = 5, |
| 36 | + widget = wibox.container.background, |
| 37 | + layout = wibox.layout.fixed.horizontal, |
| 38 | +}) |
| 39 | + |
| 40 | +function widget:update() |
| 41 | + local icon = self:get_children_by_id("icon")[1] |
| 42 | + if day then |
| 43 | + icon:set_image(DAY_ICON) |
| 44 | + else |
| 45 | + icon:set_image(NIGHT_ICON) |
| 46 | + end |
| 47 | +end |
| 48 | + |
| 49 | +local function on_day() |
| 50 | + awful.spawn(CMD .. " " .. DAY_CMD) |
| 51 | + widget:update() |
| 52 | +end |
| 53 | + |
| 54 | +local function on_night() |
| 55 | + awful.spawn(CMD .. " " .. NIGHT_CMD) |
| 56 | + widget:update() |
| 57 | +end |
| 58 | + |
| 59 | +local function toggle() |
| 60 | + day = not day |
| 61 | + if day then |
| 62 | + on_day() |
| 63 | + else |
| 64 | + on_night() |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +widget:buttons(awful.util.table.join(awful.button({}, 1, function() |
| 69 | + toggle() |
| 70 | +end))) |
| 71 | + |
| 72 | +return widget |
0 commit comments