Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluelight widget #463

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
57 changes: 57 additions & 0 deletions bluelight-widget/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

# Blue Light Filter Widget

This widget provides a simple way to toggle a blue light filter using [Redshift](https://github.com/jonls/redshift). It offers an easy mechanism to switch between day and night modes, reducing eye strain during late-night computer use.

| Day Mode | Night Mode |
|----------|------------|
|![Day Mode](day.png) | ![Night Mode](night.png) |

(I couldn't capture the effect itself)

I usually use every widget with my custom (kinda janky) [wrapper widget](https://github.com/VMatt013/MySetup/blob/Debian/.config/awesome/widgets/margin.lua) to make them look cleaner and more unified.


**With wrapper**

![With wrapper](with_wrapper.png)


## Installation

Clone this repository then add the widget to your wibar:

```lua
local bluelight_widget = require("awesome-wm-widgets.bluelight-widget")
local margin = require("awesome-wm-widgets.margin") -- In case you use my wrapper

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
...
}
```

## Usage

- Click the widget to toggle between **Day Mode** and **Night Mode**.
- **Day Mode:** Disables the blue light filter.
- **Night Mode:** Activates the blue light filter with a warm color temperature.

## Customization

You can customize the widget by modifying the following parameters in the widget's source file:

| 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. |

## Dependencies

- [Redshift](https://github.com/jonls/redshift): Make sure Redshift is installed on your system.
Binary file added bluelight-widget/day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions bluelight-widget/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-------------------------------------------------
-- Blue Light Filter Widget for Awesome Window Manager
-- More details could be found here:
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/bluelight-widget

-- @author VMatt
-- @copyright 2025 VMatt
-------------------------------------------------

local awful = require("awful")
local wibox = require("wibox")
local gfs = require("gears.filesystem")

local ICON_DIR = gfs.get_configuration_dir() .. "awesome-wm-widgets/bluelight-widget/"
local DAY_ICON = ICON_DIR .. "sun.svg"
local NIGHT_ICON = ICON_DIR .. "moon.svg"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, given that these are white, I wonder how they work on a light theme.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just recolored them to white for myself, but not sure what is the usual approach, I found the gears.recolor_image which I never saw or used, or I could just include a "dark" and "light" version of the icons and have a config variable for it


local CMD = "redshift"
local NIGHT_CMD = "-O 2500 -g 0.75"
local DAY_CMD = "-x"
local day = true

local widget = wibox.widget({
{

{
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,
})

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

local function on_day()
awful.spawn(CMD .. " " .. DAY_CMD)
widget:update()
end

local function on_night()
awful.spawn(CMD .. " " .. NIGHT_CMD)
widget:update()
end

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

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

return widget
4 changes: 4 additions & 0 deletions bluelight-widget/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bluelight-widget/night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions bluelight-widget/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bluelight-widget/with_wrapper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading