Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions bluelight-widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
bluelight_widget, -- Add the widget here
margin(bluelight, true), -- Add the widget with my wrapper
bluelight_widget(), -- Add the widget here
margin(bluelight_widget(), true), -- Add the widget with my wrapper
bluelight_widget({night_args = {"-O", "3500", "-P", "-g", "0.75"}}), -- Pass arguments in string or table of strings
...
}
```
Expand All @@ -43,14 +44,15 @@ s.mytasklist, -- Middle widget

## Customization

You can customize the widget by modifying the following parameters in the widget's source file:
You can pass arguments to the bluelight method. The following arguments are avaliable:

| Name | Default | Description |
|------------|----------------------------------------|------------------------------------------------------------|
| `ICON_DIR` | ```awesome-wm-widgets/bluelight-widget/``` | Directory where the widget icons (sun.svg and moon.svg) are stored. |
| `CMD` | ```redshift``` | Command to run Redshift. |
| `NIGHT_CMD`| ```-O 2500 -g 0.75``` | Command options for activating Night Mode. |
| `DAY_CMD` | ```-x``` | Command options for activating Day Mode. |
| `cmd` | ```redshift``` | Command to run Redshift. |
| `night_args`| ```-O 2500 -g 0.75 -P``` | Command options for activating Night Mode. |
| `day_args` | ```-x``` | Command options for activating Day Mode. |
| `night_icon` | ```awesome-wm-widgets/bluelight-widget/moon.svg``` | Image to show when Night Mode is activated. |
| `day_icon` | ```awesome-wm-widgets/bluelight-widget/sun.svg``` | Image to show when Day Mode is activated |

## Dependencies

Expand Down
109 changes: 67 additions & 42 deletions bluelight-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,83 @@ local ICON_DIR = gfs.get_configuration_dir() .. "awesome-wm-widgets/bluelight-wi
local DAY_ICON = ICON_DIR .. "sun.svg"
local NIGHT_ICON = ICON_DIR .. "moon.svg"

local CMD = "redshift"
local NIGHT_CMD = "-O 2500 -g 0.75"
local DAY_CMD = "-x"
local day = true
---@class Bluelight.Widget.Opts
---@field cmd string?
---@field night_args string[] | string?
---@field day_args string[]? | string?
---@field day_icon string?
---@field night_icon string?

local widget = wibox.widget({
{
---@type Bluelight.Widget.Opts
local default_opts = {
cmd = "redshift",
night_args = { "-O", "2500", "-g", "0.75", "-P" },
day_args = { "-x" },
day_icon = DAY_ICON,
night_icon = NIGHT_ICON,
}

---@param opts Bluelight.Widget.Opts
local factory = function(opts)
opts = opts or {}
local cmd = opts.cmd or default_opts.cmd
local night_args = opts.night_args or default_opts.night_args
local day_args = opts.day_args or default_opts.day_args
local day_icon = opts.day_icon or default_opts.day_icon
local night_icon = opts.night_icon or default_opts.night_icon

local day = true

local widget = wibox.widget({
{
id = "icon",
image = DAY_ICON,
resize = true,
widget = wibox.widget.imagebox,
{
id = "icon",
image = DAY_ICON,
resize = true,
widget = wibox.widget.imagebox,
},
layout = wibox.layout.fixed.horizontal,
widget = wibox.container.margin,
},
border_width = 5,
widget = wibox.container.background,
layout = wibox.layout.fixed.horizontal,
widget = wibox.container.margin,
},
border_width = 5,
widget = wibox.container.background,
layout = wibox.layout.fixed.horizontal,
})
})

function widget:update()
local icon = self:get_children_by_id("icon")[1]
if day then
icon:set_image(DAY_ICON)
else
icon:set_image(NIGHT_ICON)
function widget:update()
local icon = self:get_children_by_id("icon")[1]
if day then
icon:set_image(day_icon)
else
icon:set_image(night_icon)
end
end
end

local function on_day()
awful.spawn(CMD .. " " .. DAY_CMD)
widget:update()
end
local function on_day()
local args = type(day_args) == "table" and table.concat(day_args, " ") or day_args
awful.spawn(cmd .. " " .. args)
widget:update()
end

local function on_night()
awful.spawn(CMD .. " " .. NIGHT_CMD)
widget:update()
end
local function on_night()
local args = type(night_args) == "table" and table.concat(night_args, " ") or night_args
awful.spawn(cmd .. " " .. args)
widget:update()
end

local function toggle()
day = not day
if day then
on_day()
else
on_night()
local function toggle()
day = not day
if day then
on_day()
else
on_night()
end
end
end

widget:buttons(awful.util.table.join(awful.button({}, 1, function()
toggle()
end)))
widget:buttons(awful.util.table.join(awful.button({}, 1, function()
toggle()
end)))
return widget
end

return widget
return factory