Skip to content

Commit 3a9990f

Browse files
committed
Allow setting up logout-popup-widget button keybindings and ignore case
1 parent 6f89bdb commit 3a9990f

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

logout-popup-widget/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ Then
6666
| `onreboot` | `function() awful.spawn.with_shell("reboot") end` | Function which is called when the reboot button is pressed |
6767
| `onsuspend` | `function() awful.spawn.with_shell("systemctl suspend") end` | Function which is called when the suspend button is pressed |
6868
| `onpoweroff` | `function() awful.spawn.with_shell("shutdown now") end` | Function which is called when the poweroff button is pressed |
69+
| `onlogout_key` | <kbd>l</kbd> | Keybinding to execute the logout function |
70+
| `onlock_key` | <kbd>k</kbd> | Keybinding to execute the lock function |
71+
| `onreboot_key` | <kbd>r</kbd> | Keybinding to execute the reboot function |
72+
| `onsuspend_key` | <kbd>u</kbd> | Keybinding to execute the suspend function |
73+
| `onpoweroff_key` | <kbd>s</kbd> | Keybinding to execute the poweroff function |
6974

7075
Some color themes for inspiration:
7176

logout-popup-widget/logout-popup.lua

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ local function launch(args)
8181
local onsuspend = args.onsuspend or function() awful.spawn.with_shell("systemctl suspend") end
8282
local onpoweroff = args.onpoweroff or function() awful.spawn.with_shell("shutdown now") end
8383

84+
local onlogout_key = args.onlogout_key or 'l'
85+
local onlock_key = args.onlock_key or 'k'
86+
local onreboot_key = args.onreboot_key or 'r'
87+
local onsuspend_key = args.onsuspend_key or 'u'
88+
local onpoweroff_key = args.onpoweroff_key or 's'
89+
8490
w:set_bg(bg_color)
8591
if #phrases > 0 then
8692
phrase_widget:set_markup(
@@ -92,15 +98,15 @@ local function launch(args)
9298
phrase_widget,
9399
{
94100
{
95-
create_button('log-out', 'Log Out (l)',
101+
create_button('log-out', 'Log Out (' .. onlogout_key .. ')',
96102
accent_color, label_color, onlogout, icon_size, icon_margin),
97-
create_button('lock', 'Lock (k)',
103+
create_button('lock', 'Lock (' .. onlock_key .. ')',
98104
accent_color, label_color, onlock, icon_size, icon_margin),
99-
create_button('refresh-cw', 'Reboot (r)',
105+
create_button('refresh-cw', 'Reboot (' .. onreboot_key .. ')',
100106
accent_color, label_color, onreboot, icon_size, icon_margin),
101-
create_button('moon', 'Suspend (u)',
107+
create_button('moon', 'Suspend (' .. onsuspend_key .. ')',
102108
accent_color, label_color, onsuspend, icon_size, icon_margin),
103-
create_button('power', 'Power Off (s)',
109+
create_button('power', 'Power Off (' .. onpoweroff_key .. ')',
104110
accent_color, label_color, onpoweroff, icon_size, icon_margin),
105111
id = 'buttons',
106112
spacing = 8,
@@ -141,14 +147,16 @@ local function launch(args)
141147
phrase_widget:set_text('')
142148
capi.keygrabber.stop()
143149
w.visible = false
144-
elseif key == 's' then onpoweroff()
145-
elseif key == 'r' then onreboot()
146-
elseif key == 'u' then onsuspend()
147-
elseif key == 'k' then onlock()
148-
elseif key == 'l' then onlogout()
150+
elseif string.lower(key) == string.lower(onpoweroff_key) then onpoweroff()
151+
elseif string.lower(key) == string.lower(onreboot_key) then onreboot()
152+
elseif string.lower(key) == string.lower(onsuspend_key) then onsuspend()
153+
elseif string.lower(key) == string.lower(onlock_key) then onlock()
154+
elseif string.lower(key) == string.lower(onlogout_key) then onlogout()
149155
end
150156

151-
if key == 'Escape' or string.match("srukl", key) then
157+
local all_keys = onlogout_key .. onlock_key .. onreboot_key .. onsuspend_key .. onpoweroff_key
158+
159+
if key == 'Escape' or string.match(all_keys, key) then
152160
phrase_widget:set_text('')
153161
capi.keygrabber.stop()
154162
w.visible = false

0 commit comments

Comments
 (0)