Rewrote backlight manager
This commit is contained in:
99
backlight/arc_widget.lua
Normal file
99
backlight/arc_widget.lua
Normal file
@ -0,0 +1,99 @@
|
||||
local P = {}
|
||||
|
||||
function P:set_value(value)
|
||||
-- Set widget value. (0 - 100)
|
||||
self.arc.value = value
|
||||
|
||||
--[[
|
||||
if value > 90 then self.icon.image = beautiful.icons.brightness.i
|
||||
elseif value > 80 then self.icon.image = beautiful.icons.brightness.h
|
||||
elseif value > 70 then self.icon.image = beautiful.icons.brightness.g
|
||||
elseif value > 60 then self.icon.image = beautiful.icons.brightness.f
|
||||
elseif value > 50 then self.icon.image = beautiful.icons.brightness.e
|
||||
elseif value > 40 then self.icon.image = beautiful.icons.brightness.d
|
||||
elseif value > 30 then self.icon.image = beautiful.icons.brightness.c
|
||||
elseif value > 20 then self.icon.image = beautiful.icons.brightness.b
|
||||
elseif value <= 10 then self.icon.image = beautiful.icons.brightness.a
|
||||
end
|
||||
--]]
|
||||
end
|
||||
|
||||
function P:set_state(state)
|
||||
return
|
||||
end
|
||||
|
||||
function P:set_tooltip(text)
|
||||
-- Set widget value. (0 - 100)
|
||||
self.tooltip.text = text
|
||||
end
|
||||
|
||||
function P:new()
|
||||
widget = {}
|
||||
setmetatable(widget, self)
|
||||
self.__index = self
|
||||
|
||||
widget.icon = wibox.widget {
|
||||
id = "icon",
|
||||
image = beautiful.icons.brightness.i,
|
||||
resize = true,
|
||||
widget = wibox.widget.imagebox,
|
||||
}
|
||||
|
||||
widget.arc = wibox.widget {
|
||||
{
|
||||
widget.icon,
|
||||
top = beautiful.dpi(1),
|
||||
bottom = beautiful.dpi(1),
|
||||
layout = wibox.container.margin,
|
||||
},
|
||||
max_value = 100,
|
||||
thickness = beautiful.dpi(4),
|
||||
start_angle = 4.71238898, -- 2pi*3/4
|
||||
--forced_height = beautiful.dpi(16),
|
||||
--forced_width = beautiful.dpi(16),
|
||||
colors = {"#27D4CC", "#00446B"},
|
||||
bg = "#FFFFFF30",
|
||||
paddings = beautiful.dpi(2),
|
||||
widget = wibox.container.arcchart
|
||||
}
|
||||
|
||||
widget.widget = wibox.widget {
|
||||
{
|
||||
{ -- Right space
|
||||
widget = wibox.widget.separator,
|
||||
color = beautiful.color.transparent,
|
||||
forced_width = beautiful.dpi(3)
|
||||
},
|
||||
{
|
||||
widget.arc,
|
||||
top = beautiful.dpi(2),
|
||||
bottom = beautiful.dpi(2),
|
||||
layout = wibox.container.margin,
|
||||
},
|
||||
{ -- Left space
|
||||
widget = wibox.widget.separator,
|
||||
color = beautiful.color.transparent,
|
||||
forced_width = beautiful.dpi(3)
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
},
|
||||
layout = wibox.container.background,
|
||||
}
|
||||
|
||||
widget.tooltip = awful.tooltip {
|
||||
objects = { widget.widget },
|
||||
text = ""
|
||||
}
|
||||
|
||||
widget.widget:connect_signal("mouse::enter", function(result)
|
||||
widget.widget.bg = beautiful.color.bar.hover_bg
|
||||
end)
|
||||
|
||||
widget.widget:connect_signal("mouse::leave", function(result)
|
||||
widget.widget.bg = beautiful.color.transparent
|
||||
end)
|
||||
|
||||
return widget
|
||||
end
|
||||
|
||||
return P
|
133
backlight/backlight.lua
Normal file
133
backlight/backlight.lua
Normal file
@ -0,0 +1,133 @@
|
||||
local widget_types = {
|
||||
arc = require("backlight/arc_widget")
|
||||
}
|
||||
|
||||
local P = {}
|
||||
|
||||
|
||||
---
|
||||
-- Internal methods
|
||||
---
|
||||
function P:_get_status()
|
||||
awful.spawn.easy_async(
|
||||
script_dir .. "backlight get",
|
||||
function(stdout, stderr, exitreason, exitcode)
|
||||
self._ready = true
|
||||
self.brightness = tonumber(stdout)
|
||||
self:_update_widget()
|
||||
end
|
||||
)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
function P:_update_widget()
|
||||
if (not self._ready) then
|
||||
self.widget:set_state("error")
|
||||
self.widget:set_value(self.max_value);
|
||||
self.widget:set_tooltip("Backlight error");
|
||||
return
|
||||
end
|
||||
|
||||
self.widget:set_value(self.brightness);
|
||||
self.widget:set_tooltip("Backlight " .. self.brightness .. "u");
|
||||
self.widget:set_state("ready")
|
||||
end
|
||||
|
||||
---
|
||||
-- Simple actions
|
||||
---
|
||||
function P:backlight_up()
|
||||
if (not self._ready) or (self.brightness >= self.max_value) then
|
||||
return
|
||||
end
|
||||
|
||||
awful.spawn(script_dir .. "backlight up 5", false)
|
||||
self.brightness = self.brightness + 5
|
||||
if self.brightness > self.max_value then
|
||||
self.brightness = self.max_value
|
||||
end
|
||||
self:_update_widget()
|
||||
end
|
||||
|
||||
function P:backlight_down()
|
||||
if (not self._ready) or (self.brightness <= self.min_value) then
|
||||
return
|
||||
end
|
||||
|
||||
awful.spawn(script_dir .. "backlight down 5", false)
|
||||
self.brightness = self.brightness - 5
|
||||
if self.brightness < self.min_value then
|
||||
self.brightness = self.min_value
|
||||
end
|
||||
self:_update_widget()
|
||||
end
|
||||
|
||||
function P:backlight_set(value)
|
||||
if (not self._ready) then
|
||||
return
|
||||
end
|
||||
|
||||
if (value < self.min_value) then
|
||||
value = self.min_value
|
||||
end
|
||||
|
||||
if (value > self.max_value) then
|
||||
value = self.max_value
|
||||
end
|
||||
|
||||
awful.spawn(script_dir .. "backlight set " .. value, false)
|
||||
self.brightness = value
|
||||
self:_update_widget()
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- Create new volume_interface
|
||||
---
|
||||
function P:new(args)
|
||||
-- Arguments
|
||||
b = {
|
||||
update_interval = args.update_interal or 5,
|
||||
min_value = args.min_value or 0,
|
||||
max_value = args.max_value or 100,
|
||||
widget_type = args.widget_type or "arc",
|
||||
|
||||
|
||||
_ready = false, -- is all the information in this class up-to-date?
|
||||
-- if this is false, ui will show an error and most methods will
|
||||
-- do nothing. Updated in _get_status()
|
||||
}
|
||||
|
||||
b.widget = widget_types[b.widget_type]:new()
|
||||
|
||||
b.widget.widget:connect_signal("button::press",
|
||||
function(_, _, _, button, mods)
|
||||
-- Scroll up
|
||||
if (button == 4) then
|
||||
b:backlight_up()
|
||||
-- Scroll down
|
||||
elseif (button == 5) then
|
||||
b:backlight_down()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
setmetatable(b, self)
|
||||
self.__index = self
|
||||
|
||||
-- This timer keeps mute and volume status up-to-date.
|
||||
b.timer = gears.timer {
|
||||
timeout = b.update_interval,
|
||||
call_now = true,
|
||||
autostart = true,
|
||||
callback = function()
|
||||
b:_get_status()
|
||||
end
|
||||
}
|
||||
|
||||
return b
|
||||
end
|
||||
|
||||
return P
|
7
backlight/init.lua
Normal file
7
backlight/init.lua
Normal file
@ -0,0 +1,7 @@
|
||||
local P = require("backlight/backlight")
|
||||
|
||||
local F = function(args)
|
||||
return P:new(args)
|
||||
end
|
||||
|
||||
return F
|
Reference in New Issue
Block a user