247 lines
5.3 KiB
Lua
247 lines
5.3 KiB
Lua
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 ="#000000FF",
|
|
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)
|
|
|
|
if value == nil then
|
|
value = 0
|
|
end
|
|
|
|
-- 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
|
|
|