Repository: qtile/qtile

Issue:
alacritty and kitty terminals focus is messed up
# Issue description
Both terminals focus is so much buggy for alacritty focus working only by mouse follow till I switch screens after this focus stop working and stay on another monitor, in kitty is similar but cannot focus another instation even by mouse. gnome-terminal work fine ;)

Reverting to https://github.com/qtile/qtile/commit/ae354a27eafda53316973f35db0363eaec686c38 fix problem

alacritty xprop:
```
WM_HINTS(WM_HINTS):
_NET_WM_DESKTOP(CARDINAL) = 0
WM_STATE(WM_STATE):
		window state: Normal
		icon window: 0x0
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, _NET_WM_PING
_NET_WM_ICON(CARDINAL) =
WM_NORMAL_HINTS(WM_SIZE_HINTS):
		program specified size: 800 by 600
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
WM_CLIENT_MACHINE(STRING) = "user-e5400"
_NET_WM_PID(CARDINAL) = 148565
WM_CLASS(STRING) = "Alacritty", "Alacritty"
XdndAware(ATOM) = BITMAP
_MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x2, 0x0, 0x0, 0x0, 0x0
_NET_WM_NAME(UTF8_STRING) = "xprop /home/user"
WM_NAME(STRING) = "xprop /home/user"
```

kitty xprop:
```
_NET_WM_ICON(CARDINAL) = 
_NET_WM_DESKTOP(CARDINAL) = 1
WM_STATE(WM_STATE):
		window state: Normal
		icon window: 0x0
_NET_WM_ICON_NAME(UTF8_STRING) = "xprop /home/user"
_NET_WM_NAME(UTF8_STRING) = "xprop /home/user"
WM_LOCALE_NAME(STRING) = "pl_PL.UTF-8"
WM_CLIENT_MACHINE(STRING) = "user-e5400"
WM_ICON_NAME(STRING) = "xprop /home/user"
WM_NAME(STRING) = "xprop /home/user"
XdndAware(ATOM) = BITMAP
WM_CLASS(STRING) = "kitty", "kitty"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
		window gravity: Static
WM_HINTS(WM_HINTS):
		Initial state is Normal State.
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_PID(CARDINAL) = 154832
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, _NET_WM_PING
```



Discussion:
Can you bisect and see which commit causes it?
I mentioned this in another thread, but d58cb2dd67fbef9e6053ca658d3bf485df284a8e is suspicious.
Hello @tych0,
I'll try to bisect.

Just for transparency, some related messages from other threads:
https://github.com/qtile/qtile/issues/1548#issuecomment-637674737
https://github.com/qtile/qtile/pull/1760#issuecomment-637682344
> Hello @tych0,
> I'll try to bisect.

Done. You were right, d58cb2d is the first bad commit.
On Wed, Jun 03, 2020 at 02:28:03PM -0700, Aliaksei Urbanski wrote:
> > Hello @tych0,
> > I'll try to bisect.
> 
> Done. You were right, d58cb2d is the first bad commit.

Thanks, can you post an xtrace of xprop on one of terminals?

Here you go.
[xprop-alacritty.log](https://github.com/qtile/qtile/files/4726332/xprop-alacritty.log)
On Wed, Jun 03, 2020 at 02:40:20PM -0700, Aliaksei Urbanski wrote:
> Here you go.
> [xprop-alacritty.log](https://github.com/qtile/qtile/files/4726332/xprop-alacritty.log)

Awesome, thank you.

So it looks like alacritty is not setting the input hint, so we should
not be unsetting it. Should be a reasonably simple fix... :)


Resolving patch:
diff --git a/libqtile/window.py b/libqtile/window.py
--- a/libqtile/window.py
+++ b/libqtile/window.py
@@ -309,7 +309,7 @@ def update_hints(self):
             self.hints['urgent'] = False
             hook.fire('client_urgent_hint_changed', self)
 
-        if h and 'input' in h:
+        if h and 'InputHint' in h['flags']:
             self.hints['input'] = h['input']
 
         if getattr(self, 'group', None):
@@ -611,6 +611,10 @@ def cmd_info(self):
         """Returns a dictionary of info for this object"""
         return self.info()
 
+    def cmd_hints(self):
+        """Returns the X11 hints (WM_HINTS and WM_SIZE_HINTS) for this window."""
+        return self.hints
+
     def cmd_inspect(self):
         """Tells you more than you ever wanted to know about a window"""
         a = self.window.get_attributes()


Test patch:
diff --git a/test/test_manager.py b/test/test_manager.py
--- a/test/test_manager.py
+++ b/test/test_manager.py
@@ -1266,6 +1266,7 @@ def no_focus():
         w.set_property("WM_CLASS", "xclock", type="STRING", format=8)
 
         hints = [0] * 14
+        hints[0] = xcbq.HintsFlags["InputHint"]
         w.set_property("WM_HINTS", hints, type="WM_HINTS", format=32)
         w.map()
         conn.conn.flush()
@@ -1278,3 +1279,50 @@ def no_focus():
     finally:
         w.kill_client()
         conn.finalize()
+
+
+@manager_config
+def test_hints_setting_unsetting(qtile):
+    w = None
+    conn = xcbq.Connection(qtile.display)
+
+    def no_input_hint():
+        nonlocal w
+        w = conn.create_window(5, 5, 10, 10)
+        w.map()
+        conn.conn.flush()
+
+    try:
+        qtile.create_window(no_input_hint)
+        # We default the input hint to true since some non-trivial number of
+        # windows don't set it, and most of them want focus. The spec allows
+        # WMs to assume "convenient" values.
+        assert qtile.c.window.hints()['input']
+
+        # now try to "update" it, but don't really set an update (i.e. the
+        # InputHint bit is 0, so the WM should not derive a new hint from the
+        # content of the message at the input hint's offset)
+        hints = [0] * 14
+        w.set_property("WM_HINTS", hints, type="WM_HINTS", format=32)
+        conn.flush()
+
+        # should still have the hint
+        assert qtile.c.window.hints()['input']
+
+        # now do an update: turn it off
+        hints[0] = xcbq.HintsFlags["InputHint"]
+        hints[1] = 0
+        w.set_property("WM_HINTS", hints, type="WM_HINTS", format=32)
+        conn.flush()
+        assert not qtile.c.window.hints()['input']
+
+        # turn it back on
+        hints[0] = xcbq.HintsFlags["InputHint"]
+        hints[1] = 1
+        w.set_property("WM_HINTS", hints, type="WM_HINTS", format=32)
+        conn.flush()
+        assert qtile.c.window.hints()['input']
+
+    finally:
+        w.kill_client()
+        conn.finalize()