Skip to content

Commit 8ab87d2

Browse files
authored
Merge pull request #444 from Stasky745/master
Allow setting up logout-popup-widget button keybindings and ignore case
2 parents 7dd0041 + 60a262f commit 8ab87d2

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

logout-popup-widget/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ 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 |
74+
| `ignore_case` | true | Ignore if CAPS LOCK is enabled |
6975

7076
Some color themes for inspiration:
7177

logout-popup-widget/logout-popup.lua

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ 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+
local all_keys = onlogout_key .. onlock_key .. onreboot_key .. onsuspend_key .. onpoweroff_key
90+
91+
local ignore_case = args.ignore_case or true
92+
8493
w:set_bg(bg_color)
8594
if #phrases > 0 then
8695
phrase_widget:set_markup(
@@ -92,15 +101,15 @@ local function launch(args)
92101
phrase_widget,
93102
{
94103
{
95-
create_button('log-out', 'Log Out (l)',
104+
create_button('log-out', 'Log Out (' .. onlogout_key .. ')',
96105
accent_color, label_color, onlogout, icon_size, icon_margin),
97-
create_button('lock', 'Lock (k)',
106+
create_button('lock', 'Lock (' .. onlock_key .. ')',
98107
accent_color, label_color, onlock, icon_size, icon_margin),
99-
create_button('refresh-cw', 'Reboot (r)',
108+
create_button('refresh-cw', 'Reboot (' .. onreboot_key .. ')',
100109
accent_color, label_color, onreboot, icon_size, icon_margin),
101-
create_button('moon', 'Suspend (u)',
110+
create_button('moon', 'Suspend (' .. onsuspend_key .. ')',
102111
accent_color, label_color, onsuspend, icon_size, icon_margin),
103-
create_button('power', 'Power Off (s)',
112+
create_button('power', 'Power Off (' .. onpoweroff_key .. ')',
104113
accent_color, label_color, onpoweroff, icon_size, icon_margin),
105114
id = 'buttons',
106115
spacing = 8,
@@ -141,17 +150,29 @@ local function launch(args)
141150
phrase_widget:set_text('')
142151
capi.keygrabber.stop()
143152
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()
149-
end
153+
else
154+
if ignore_case then
155+
key = string.lower(key)
156+
onlogout_key = string.lower(onlogout_key)
157+
onlock_key = string.lower(onlock_key)
158+
onreboot_key = string.lower(onreboot_key)
159+
onsuspend_key = string.lower(onsuspend_key)
160+
onpoweroff_key = string.lower(onpoweroff_key)
161+
all_keys = string.lower(all_keys)
162+
end
150163

151-
if key == 'Escape' or string.match("srukl", key) then
152-
phrase_widget:set_text('')
153-
capi.keygrabber.stop()
154-
w.visible = false
164+
if key == onpoweroff_key then onpoweroff()
165+
elseif key == onreboot_key then onreboot()
166+
elseif key == onsuspend_key then onsuspend()
167+
elseif key == onlock_key then onlock()
168+
elseif key == onlogout_key then onlogout()
169+
end
170+
171+
if string.match(all_keys, key) then
172+
phrase_widget:set_text('')
173+
capi.keygrabber.stop()
174+
w.visible = false
175+
end
155176
end
156177
end
157178
end)

0 commit comments

Comments
 (0)