Skip to content

Commit

Permalink
Fix focus event on Window.focus() (#4585)
Browse files Browse the repository at this point in the history
When calling `Window.focus()` the borders did not update on the focused window and the `WindowName` widget did not reflect the change.

Fixes #3751
  • Loading branch information
elParaguayo committed Dec 24, 2023
1 parent 7f84c40 commit 59f9199
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libqtile/backend/wayland/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ def focus(self, warp: bool = True) -> None:
self.y + self._height / 2,
)

if self.group:
self.group.current_window = self
if self.group and self.group.current_window is not self:
self.group.focus(self)

hook.fire("client_focus", self)

Expand Down
6 changes: 3 additions & 3 deletions libqtile/backend/x11/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,12 +1327,12 @@ def focus(self, warp: bool = True) -> None:
self.qtile.core._root.set_property("_NET_ACTIVE_WINDOW", self.window.wid)
self._ungrab_click()

if self.group:
self.group.current_window = self

# Check if we need to restack a previously focused fullscreen window
self.qtile.core.check_stacking(self)

if self.group and self.group.current_window is not self:
self.group.focus(self)

hook.fire("client_focus", self)

@expose_command()
Expand Down
30 changes: 29 additions & 1 deletion test/test_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from libqtile import config, layout, resources
from libqtile import bar, config, layout, resources, widget
from libqtile.confreader import Config
from test.conftest import BareConfig, dualmonitor
from test.layouts.layout_utils import assert_focused
Expand Down Expand Up @@ -305,3 +305,31 @@ def test_set_position(manager):

# Also check if there is only one client now
assert len(manager.c.layout.info()["clients"]) == 1


class WindowNameConfig(BareConfig):
screens = [
config.Screen(
bottom=bar.Bar(
[
widget.WindowName(),
],
20,
),
),
]
layouts = [layout.Columns()]


@pytest.mark.parametrize("manager", [WindowNameConfig], indirect=True)
def test_focus_switch(manager):
def _wnd(name):
return manager.c.window[{w["name"]: w["id"] for w in manager.c.windows()}[name]]

manager.test_window("One")
manager.test_window("Two")

assert manager.c.widget["windowname"].info()["text"] == "Two"

_wnd("One").focus()
assert manager.c.widget["windowname"].info()["text"] == "One"

0 comments on commit 59f9199

Please sign in to comment.