Added backlight popup

master
Mark 2022-11-05 11:31:12 -07:00
parent e5b253411f
commit 40634f0de5
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
11 changed files with 341 additions and 76 deletions

View File

@ -1,6 +1,6 @@
-- Some subdir variables,
-- to make switching icon sets easy.
local brightnessdir = conf_dir .. "assets/icons/brightness/clockwise/"
local brightnessdir = conf_dir .. "assets/icons/brightness/counterclockwise/"
local titlebardir = conf_dir .. "assets/icons/titlebar/"
return {

View File

@ -19,9 +19,9 @@ function backlight
case "set"
xbacklight -set $argv[2]
case "up"
xbacklight -inc 10
xbacklight -inc $argv[2]
case "down"
xbacklight -dec 10
xbacklight -dec $argv[2]
case "*"
echo "Unknown function \"$argv[1]\""
echo ""

View File

@ -1,4 +1,14 @@
local popup = require("modules.backlight.popup")
return {
widget = require("modules.backlight.widget").widget,
keybinds = require("modules.backlight.keybinds"),
init = function()
awesome.emit_signal("modules::backlight:update_read")
end,
for_each_screen = function (s)
popup(s)
end
}

View File

@ -3,7 +3,8 @@ local backlight = req_rel(..., "util")
return gears.table.join(
awful.key( {}, "XF86MonBrightnessUp",
function ()
backlight.backlight_up()
backlight.backlight_up(config.backlight.button_step)
awesome.emit_signal("module::backlight:popup_show")
end,
{
description = "Raise brightness",
@ -13,7 +14,8 @@ return gears.table.join(
awful.key( {}, "XF86MonBrightnessDown",
function ()
backlight.backlight_down()
backlight.backlight_down(config.backlight.button_step)
awesome.emit_signal("module::backlight:popup_show")
end,
{
description = "Lower brightness",

242
modules/backlight/popup.lua Normal file
View File

@ -0,0 +1,242 @@
local backlight = req_rel(..., "util")
return function(s)
local widget = wibox.widget {
{
{
{
{ -- Icon and margins
nil,
{
nil,
{
id = "icon",
forced_height = beautiful.dpi(100),
image = beautiful.icons.brightness.i,
widget = wibox.widget.imagebox
},
nil,
expand = "none",
id = "icon_margin2",
layout = wibox.layout.align.vertical
},
nil,
id = "icon_margin1",
expand = "none",
layout = wibox.layout.align.horizontal
},
{ -- Text and percentage
{
id = "label",
text = "Backlight",
align = "left",
valign = "center",
widget = wibox.widget.textbox
},
nil,
{
id = "value",
text = "0%",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "label_value_layout",
forced_height = beautiful.dpi(48),
layout = wibox.layout.align.horizontal,
},
{ -- Progress bar
{
id = "backlight_bar",
shape = gears.shape.rounded_bar,
forced_height = beautiful.dpi(10),
background_color = "#AAAAAA88",
bar_color = "#ffffff",
color = "#ffffff",
bar_shape = gears.shape.rounded_bar,
max_value = 100,
widget = wibox.widget.progressbar
},
id = "bar_layout",
forced_height = beautiful.dpi(24),
widget = wibox.container.place
},
id = "icon_bar_layout",
spacing = beautiful.dpi(0),
layout = wibox.layout.align.vertical
},
id = "popup_layout",
layout = wibox.layout.align.vertical,
},
id = "container",
left = beautiful.dpi(20),
right = beautiful.dpi(20),
top = beautiful.dpi(10),
bottom = beautiful.dpi(10),
widget = wibox.container.margin
},
bg ="#000000CC",
widget = wibox.container.background,
ontop = true,
visible = true,
type = "notification",
forced_height = beautiful.dpi(180),
forced_width = beautiful.dpi(300),
offset = beautiful.dpi(5),
}
local popup_container = awful.popup {
widget = wibox.container.background,
ontop = true,
bg = "#00000000",
stretch = false,
visible = false,
screen = s,
placement = function(c)
awful.placement.bottom_right(
c,
{
honor_workarea = true,
margins = {
top = beautiful.dpi(200)
}
}
)
end,
-- Only set corner radius here.
shape = function(cr, width, height)
gears.shape.partially_rounded_rect(
cr,
width,
height,
true,
false,
false,
false,
beautiful.dpi(20)
)
end
}
popup_container:setup {
widget,
layout = wibox.layout.fixed.horizontal
}
awesome.connect_signal("module::backlight:update",
function(value)
-- Update slider
widget.
container.
popup_layout.
icon_bar_layout.
bar_layout.
backlight_bar:set_value(value)
-- Update text
widget.
container.
popup_layout.
icon_bar_layout.
label_value_layout.
value:set_text(value .. "%")
-- Update icon
local icon
if value >= 90 then icon = beautiful.icons.brightness.i
elseif value >= 80 then icon = beautiful.icons.brightness.h
elseif value >= 70 then icon = beautiful.icons.brightness.g
elseif value >= 60 then icon = beautiful.icons.brightness.f
elseif value >= 50 then icon = beautiful.icons.brightness.e
elseif value >= 40 then icon = beautiful.icons.brightness.d
elseif value >= 30 then icon = beautiful.icons.brightness.c
elseif value >= 20 then icon = beautiful.icons.brightness.b
elseif value <= 10 then icon = beautiful.icons.brightness.a end
widget.
container.
popup_layout.
icon_bar_layout.
icon_margin1.
icon_margin2.
icon:set_image(icon)
end
)
local hide_popup_timer = gears.timer {
timeout = 1,
autostart = true,
callback = function()
popup_container.visible = false
end
}
awesome.connect_signal("module::all:popup_hide",
function(except)
if (except == "backlight") then
return
end
popup_container.visible = false
if hide_popup_timer.started then
hide_popup_timer:stop()
end
end
)
awesome.connect_signal("module::backlight:popup_show",
function()
awesome.emit_signal("module::all:popup_hide", "backlight")
if s == mouse.screen then
popup_container.visible = true
end
if hide_popup_timer.started then
hide_popup_timer:again()
else
hide_popup_timer:start()
end
end
)
awesome.connect_signal("module::backlight:popup_show_stay",
function()
awesome.emit_signal("module::all:popup_hide", "backlight")
if s == mouse.screen then
popup_container.visible = true
end
if hide_popup_timer.started then
hide_popup_timer:stop()
end
end
)
popup_container:connect_signal("button::press",
function(_, _, _, button, mods)
-- Scroll up
if (button == 4) then
backlight.backlight_up(config.backlight.scroll_step)
-- Scroll down
elseif (button == 5) then
backlight.backlight_down(config.backlight.scroll_step)
end
end
)
popup_container:connect_signal("mouse::enter", function(result)
awesome.emit_signal("module::backlight:popup_show_stay")
end)
popup_container:connect_signal("mouse::leave", function(result)
awesome.emit_signal("module::backlight:popup_show")
end)
end

View File

@ -4,20 +4,8 @@ local backlight = {}
local script = conf_dir .. "modules/backlight/backlight.fish"
script = script .. " "
backlight.hooks = {}
backlight.add_hook = function(callback)
backlight.hooks[#backlight.hooks + 1] = callback
end
backlight.exec_hooks = function()
backlight.read(function(status)
for i=1, #backlight.hooks do
backlight.hooks[i](status)
end
end)
end
backlight.read = function(callback)
backlight.get = function(callback)
awful.spawn.easy_async(
script .. "get",
function(stdout, stderr, exitreason, exitcode)
@ -40,25 +28,36 @@ backlight.watch = function(timeout, callback, widget)
end
backlight.backlight_up = function()
awful.spawn(script .. "up", false)
backlight.exec_hooks()
backlight.backlight_up = function(value)
awful.spawn.easy_async(
script .. "up " .. value,
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::backlight:update_read")
end
)
end
backlight.backlight_down = function()
awful.spawn(script .. "down", false)
backlight.exec_hooks()
backlight.backlight_down = function(value)
awful.spawn.easy_async(
script .. "down " .. value,
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::backlight:update_read")
end
)
end
--[[
backlight.redshift = function(temp)
awful.spawn("redshift -O " .. tostring(temp), false)
awesome.connect_signal("module::backlight:update_read",
function()
backlight.get(
function(value)
awesome.emit_signal(
"module::backlight:update",
value
)
end
backlight.reset_redshift = function()
awful.spawn("redshift -x", false)
)
end
--]]
)
return backlight

View File

@ -53,47 +53,47 @@ widget.widget = wibox.widget {
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
awesome.emit_signal("module::backlight:popup_show_stay")
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
awesome.emit_signal("module::backlight:popup_show")
end)
widget.widget:connect_signal("button::press",
function(_, _, _, button, mods)
-- Scroll up
if (button == 4) then
backlight.backlight_up()
backlight.backlight_up(config.backlight.scroll_step)
-- Scroll down
elseif (button == 5) then
backlight.backlight_down()
backlight.backlight_down(config.backlight.scroll_step)
end
end
)
widget.update = function(value)
awesome.connect_signal("module::backlight:update",
function(value)
widget.arc.value = value
--[[if value > 90 then widget.icon.image = beautiful.icons.brightness.i
elseif value > 80 then widget.icon.image = beautiful.icons.brightness.h
elseif value > 70 then widget.icon.image = beautiful.icons.brightness.g
elseif value > 60 then widget.icon.image = beautiful.icons.brightness.f
elseif value > 50 then widget.icon.image = beautiful.icons.brightness.e
elseif value > 40 then widget.icon.image = beautiful.icons.brightness.d
elseif value > 30 then widget.icon.image = beautiful.icons.brightness.c
elseif value > 20 then widget.icon.image = beautiful.icons.brightness.b
if value >= 90 then widget.icon.image = beautiful.icons.brightness.i
elseif value >= 80 then widget.icon.image = beautiful.icons.brightness.h
elseif value >= 70 then widget.icon.image = beautiful.icons.brightness.g
elseif value >= 60 then widget.icon.image = beautiful.icons.brightness.f
elseif value >= 50 then widget.icon.image = beautiful.icons.brightness.e
elseif value >= 40 then widget.icon.image = beautiful.icons.brightness.d
elseif value >= 30 then widget.icon.image = beautiful.icons.brightness.c
elseif value >= 20 then widget.icon.image = beautiful.icons.brightness.b
elseif value <= 10 then widget.icon.image = beautiful.icons.brightness.a end
--]]
end
)
backlight.add_hook(widget.update)
backlight.watch(
5,
function()
backlight.read(widget.update)
awesome.emit_signal("module::backlight::update_read")
end,
widget.widget
)

View File

@ -1,5 +1,4 @@
local volume = require("modules.volume.util")
local widget = require("modules.volume.widget")
local popup = require("modules.volume.popup")
return {

View File

@ -4,7 +4,7 @@ return gears.table.join(
awful.key( {}, "XF86AudioRaiseVolume",
function ()
volume.volume_up(config.volume.button_step)
awesome.emit_signal("module::volume_popup:show")
awesome.emit_signal("module::volume:popup_show")
end,
{
description = "Volume up",
@ -15,7 +15,7 @@ return gears.table.join(
awful.key( {}, "XF86AudioLowerVolume",
function ()
volume.volume_down(config.volume.button_step)
awesome.emit_signal("module::volume_popup:show")
awesome.emit_signal("module::volume:popup_show")
end,
{
description = "Volume down",
@ -26,7 +26,7 @@ return gears.table.join(
awful.key( {}, "XF86AudioMute",
function ()
volume.toggle_mute()
awesome.emit_signal("module::volume_popup:show")
awesome.emit_signal("module::volume:popup_show")
end,
{
description = "Mute",

View File

@ -125,6 +125,26 @@ return function(s)
layout = wibox.layout.fixed.horizontal
}
local hide_popup_timer = gears.timer {
timeout = 1,
autostart = true,
callback = function()
popup_container.visible = false
end
}
awesome.connect_signal("module::all:popup_hide",
function(except)
if (except == "volume") then
return
end
popup_container.visible = false
if hide_popup_timer.started then
hide_popup_timer:stop()
end
end
)
awesome.connect_signal("module::volume:update",
function(status)
@ -169,17 +189,9 @@ return function(s)
end
)
local hide_popup_timer = gears.timer {
timeout = 1,
autostart = true,
callback = function()
popup_container.visible = false
end
}
awesome.connect_signal("module::volume_popup:show",
awesome.connect_signal("module::volume:popup_show",
function()
awesome.emit_signal("module::all:popup_hide", "volume")
if s == mouse.screen then
popup_container.visible = true
end
@ -192,8 +204,9 @@ return function(s)
end
)
awesome.connect_signal("module::volume_popup:show_stay",
awesome.connect_signal("module::volume:popup_show_stay",
function()
awesome.emit_signal("module::all:popup_hide", "volume")
if s == mouse.screen then
popup_container.visible = true
end
@ -207,7 +220,7 @@ return function(s)
popup_container:connect_signal("button::press",
function(_, _, _, button, mods)
-- Right-click
-- Left-click
if (button == 1) then
volume.toggle_mute()
@ -223,11 +236,11 @@ return function(s)
)
popup_container:connect_signal("mouse::enter", function(result)
awesome.emit_signal("module::volume_popup:show_stay")
awesome.emit_signal("module::volume:popup_show_stay")
end)
popup_container:connect_signal("mouse::leave", function(result)
awesome.emit_signal("module::volume_popup:show")
awesome.emit_signal("module::volume:popup_show")
end)
end

View File

@ -70,19 +70,19 @@ widget.widget = wibox.widget {
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
awesome.emit_signal("module::volume_popup:show_stay")
awesome.emit_signal("module::volume:popup_show_stay")
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
awesome.emit_signal("module::volume_popup:show")
awesome.emit_signal("module::volume:popup_show")
end)
widget.widget:connect_signal("button::press",
function(_, _, _, button, mods)
-- Right-click
if (button == 3) then
-- Left-click
if (button == 1) then
volume.toggle_mute()
-- Scroll up
@ -93,7 +93,7 @@ widget.widget:connect_signal("button::press",
elseif (button == 5) then
volume.volume_down(config.volume.scroll_step)
end
awesome.emit_signal("module::volume_popup:update")
awesome.emit_signal("module::volume:popup_update")
end
)