-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdualsense.lua
57 lines (47 loc) · 1.67 KB
/
dualsense.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-------------------------------------------------
-- Dualsense for Awesome Window Manager
-- Requires dualsensectl
-------------------------------------------------
local awful = require("awful")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
local BATTERY = "dualsensectl battery"
local POWER_OFF = "dualsensectl power-off"
local controller_icon = os.getenv("HOME") .. '/.config/awesome/widgets/dualsense/controller_icon.png'
local function worker(args)
local args = args or {}
local timeout = args.timeout or 1
local font = args.font or 'Play 9'
local controller = wibox.widget {
{
id = "icon",
image = controller_icon,
widget = wibox.widget.imagebox,
},
{
id="battery",
markup = "",
widget = wibox.widget.textbox,
font = font
},
layout = wibox.layout.align.horizontal,
}
function controller.update(_, text, _, _)
local bat = tonumber(string.match(text, "%d*"))
if bat == nil then
controller:get_children_by_id('battery')[1]:set_markup('')
controller:set_visible(false)
elseif controller:get_children_by_id('battery')[1]:get_markup() ~= text then
controller:get_children_by_id('battery')[1]:set_markup(' ' .. bat .. '%')
controller:set_visible(true)
end
end
watch(BATTERY, timeout, controller.update, controller)
controller:connect_signal("button::press", function(_, _, _, button)
if (button == 2) then
awful.spawn(POWER_OFF, false) -- middle click
end
end)
return controller
end
return worker