From 97d9a87fd284680e3c2ce9ae818249867c218f31 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Wed, 1 May 2024 20:52:00 +0800 Subject: [PATCH] Better X11 window focus handling for scratchpads. Prior to this commit, the behavior regarding window focus within a scratchpad was unexpected. When a window in the scratchpad was focused, the entire scratchpad group would also be focused, based on the settings of focus_on_window_activation being set to "focus" or "smart". With this commit, the focus behavior has been refined. Now, only the activated window within the scratchpad will be focused and brought to the front, mirroring the expected toggle behavior. --- libqtile/backend/x11/window.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libqtile/backend/x11/window.py b/libqtile/backend/x11/window.py index 2f7fef900a..f015af4362 100644 --- a/libqtile/backend/x11/window.py +++ b/libqtile/backend/x11/window.py @@ -2149,8 +2149,15 @@ def handle_ClientMessage(self, event): # noqa: N802 focus_behavior = self.qtile.config.focus_on_window_activation if focus_behavior == "focus": logger.debug("Focusing window") - self.qtile.current_screen.set_group(self.group) - self.group.focus(self) + # Windows belonging to a scratchpad need to be toggled properly + if isinstance(self.group, ScratchPad): + for dropdown in self.group.dropdowns.values(): + if dropdown.window is self: + dropdown.show() + break + else: + self.qtile.current_screen.set_group(self.group) + self.group.focus(self) elif focus_behavior == "smart": if not self.group.screen: logger.debug( @@ -2159,8 +2166,15 @@ def handle_ClientMessage(self, event): # noqa: N802 return if self.group.screen == self.qtile.current_screen: logger.debug("Focusing window") - self.qtile.current_screen.set_group(self.group) - self.group.focus(self) + # Windows belonging to a scratchpad need to be toggled properly + if isinstance(self.group, ScratchPad): + for dropdown in self.group.dropdowns.values(): + if dropdown.window is self: + dropdown.show() + break + else: + self.qtile.current_screen.set_group(self.group) + self.group.focus(self) else: # self.group.screen != self.qtile.current_screen: logger.debug("Setting urgent flag for window") self.urgent = True