From 1416c998f11f3ed8275c0b592842325ef3a8aae2 Mon Sep 17 00:00:00 2001 From: eylles Date: Sat, 12 Jul 2025 08:57:17 -0600 Subject: [PATCH] Add prev_layout method to keyboardlayout.new No, the math for the layout index decreasing does not make the most sense ever but i stopped questioning it and trying to make the in theory correct math work and just accepted that this is what produces the expected behaviour, as whatever happens in the c part of awesome or the x11 side prevents what looks like an off by one error from happening, or maybe it just makes it work somehow i honestly got no idea whatsoever why this works as intended nor i want to know why, all i care is it behaves how i want for all the amounts of layouts i have tried on my machine... --- lib/awful/widget/keyboardlayout.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/awful/widget/keyboardlayout.lua b/lib/awful/widget/keyboardlayout.lua index 8a41b64a23..b693c07107 100644 --- a/lib/awful/widget/keyboardlayout.lua +++ b/lib/awful/widget/keyboardlayout.lua @@ -260,6 +260,10 @@ end -- @noreturn -- @method next_layout +--- Select the previous layout. +-- @noreturn +-- @method prev_layout + --- Create a keyboard layout widget. -- -- It shows current keyboard layout name in a textbox. @@ -292,6 +296,10 @@ function keyboardlayout.new(args) self.set_layout((self._current + 1) % (#self._layout + 1)) end + self.prev_layout = function() + self.set_layout((self._current - 1) % (#self._layout)) + end + self.set_layout = function(group_number) if (0 > group_number) or (group_number > #self._layout) then error("Invalid group number: " .. group_number .. @@ -311,7 +319,8 @@ function keyboardlayout.new(args) -- Mouse bindings self.buttons = { - button({ }, 1, self.next_layout) + button({ }, 1, self.next_layout), + button({ }, 3, self.prev_layout) } return self