Skip to content

Commit 4d161f8

Browse files
committed
Add the argument to ignore CAPS LOCK
1 parent f147c60 commit 4d161f8

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

logout-popup-widget/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Then
7171
| `onreboot_key` | <kbd>r</kbd> | Keybinding to execute the reboot function |
7272
| `onsuspend_key` | <kbd>u</kbd> | Keybinding to execute the suspend function |
7373
| `onpoweroff_key` | <kbd>s</kbd> | Keybinding to execute the poweroff function |
74+
| `ignore_case` | true | Ignore if CAPS LOCK is enabled |
7475

7576
Some color themes for inspiration:
7677

logout-popup-widget/logout-popup.lua

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ local function launch(args)
8686
local onreboot_key = args.onreboot_key or 'r'
8787
local onsuspend_key = args.onsuspend_key or 'u'
8888
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+
93+
if ignore_case then
94+
onlogout_key = string.lower(onlogout_key)
95+
onlock_key = string.lower(onlock_key)
96+
onreboot_key = string.lower(onreboot_key)
97+
onsuspend_key = string.lower(onsuspend_key)
98+
onpoweroff_key = string.lower(onpoweroff_key)
99+
all_keys = string.lower(all_keys)
100+
end
89101

90102
w:set_bg(bg_color)
91103
if #phrases > 0 then
@@ -147,19 +159,23 @@ local function launch(args)
147159
phrase_widget:set_text('')
148160
capi.keygrabber.stop()
149161
w.visible = false
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()
155-
end
162+
else
163+
if ignore_case then
164+
key = string.lower(key)
165+
end
156166

157-
local all_keys = onlogout_key .. onlock_key .. onreboot_key .. onsuspend_key .. onpoweroff_key
167+
if key == onpoweroff_key then onpoweroff()
168+
elseif key == onreboot_key then onreboot()
169+
elseif key == onsuspend_key then onsuspend()
170+
elseif key == onlock_key then onlock()
171+
elseif key == onlogout_key then onlogout()
172+
end
158173

159-
if key == 'Escape' or string.match(string.lower(all_keys), string.lower(key)) then
160-
phrase_widget:set_text('')
161-
capi.keygrabber.stop()
162-
w.visible = false
174+
if string.match(all_keys, key) then
175+
phrase_widget:set_text('')
176+
capi.keygrabber.stop()
177+
w.visible = false
178+
end
163179
end
164180
end
165181
end)

0 commit comments

Comments
 (0)