Repository: qtile/qtile

Issue:
press mod key with mouse on bar.
qtile version 0.19.0
OS: Arch Linux x86_64
Kernel: 5.10.88-2-lts
if i press mod key and any mouse button on bar, qtile start spawn new windows with floating and freeze a little, and sometime throw error on qtile log. some time i have no errors in qtile log but strange behavior continue.

> Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/backend/x11/core.py", line 304, in _xpoll
    ret = target(event)
  File "/usr/lib/python3.10/site-packages/libqtile/backend/x11/window.py", line 1131, in handle_KeyPress
    self.process_key_press(keysym)
  File "/usr/lib/python3.10/site-packages/libqtile/bar.py", line 489, in process_key_press
    if self.has_keyboard:
  File "/usr/lib/python3.10/site-packages/libqtile/configurable.py", line 51, in __getattr__
    raise AttributeError("%s has no attribute: %s" % (cname, name))
AttributeError: Bar has no attribute: has_keyboard
2021-12-27 16:38:25,172 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:29,146 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:32,774 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:33,041 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:33,307 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:35,736 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:35,924 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:36,118 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:36,310 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:36,548 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:37,021 ERROR libqtile manager.py:process_key_event():L389 KB command error next_window: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/command/interface.py", line 316, in call
    return SUCCESS, cmd(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/libqtile/group.py", line 421, in cmd_next_window
    if self.current_window.floating:
AttributeError: 'NoneType' object has no attribute 'floating'

>2021-12-27 16:38:37,242 ERROR libqtile manager.py:process_key_event():L389 KB command error next_window: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/command/interface.py", line 316, in call
    return SUCCESS, cmd(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/libqtile/group.py", line 421, in cmd_next_window
    if self.current_window.floating:
AttributeError: 'NoneType' object has no attribute 'floating'

>2021-12-27 16:38:37,436 ERROR libqtile manager.py:process_key_event():L389 KB command error next_window: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/command/interface.py", line 316, in call
    return SUCCESS, cmd(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/libqtile/group.py", line 421, in cmd_next_window
    if self.current_window.floating:
AttributeError: 'NoneType' object has no attribute 'floating'

>2021-12-27 16:38:42,327 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:42,556 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:51,113 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:51,379 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:51,661 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:51,894 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:52,797 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'
2021-12-27 16:38:53,022 ERROR libqtile manager.py:process_key_event():L389 KB command error kill: No object window in path 'window'



Discussion:
Do these steps reproduce reliably?:

1. Have no windows visible on group
2. move mouse over bar
3. hold down mod key
4. click left mouse button

If not, please could you post some stepts to reproduce?

Also, please could you post your config or a link to it?
> Do these steps reproduce reliably?:
> 
>     1. Have no windows visible on group
> 
>     2. move mouse over bar
> 
>     3. hold down mod key
> 
>     4. click left mouse button
> 
> 
> If not, please could you post some stepts to reproduce?
> 
> Also, please could you post your config or a link to it?

ok i found how to repeat this error
1. spawn some windows on group have widget.TaskList on bar.
2. hold mod key
3. then press mouse lmb over bar TaskList title names windows three or more times fast.
4. try to spawn new window on this group.
5. try to close them
get this error
config attached
>2021-12-27 18:03:22,598 ERROR libqtile core.py:_xpoll():L336 Got an exception in poll loop
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/libqtile/backend/x11/core.py", line 304, in _xpoll
    ret = target(event)
  File "/usr/lib/python3.10/site-packages/libqtile/backend/x11/window.py", line 1131, in handle_KeyPress
    self.process_key_press(keysym)
  File "/usr/lib/python3.10/site-packages/libqtile/bar.py", line 489, in process_key_press
    if self.has_keyboard:
  File "/usr/lib/python3.10/site-packages/libqtile/configurable.py", line 51, in __getattr__
    raise AttributeError("%s has no attribute: %s" % (cname, name))
AttributeError: Bar has no attribute: has_keyboard
2021-12-27 18:03:44,523 ERROR libqtile manager.py:process_button_motion():L753 Mouse command error set_position_floating: No object window in path 'window'

[config.txt](https://github.com/qtile/qtile/files/7780743/config.txt)

It looks like this is a rare bug, and it appears in rare conditions, is it worth reporting these at all?
Does it happen only when the cursor is above `TaskList` and not any other widget?

> It looks like this is a rare bug, and it appears in rare conditions, is it worth reporting these at all?

Yeah just in case - it could be indicative of a larger problem!
> Does it happen only when the cursor is above `TaskList` and not any other widget?
> 
> > It looks like this is a rare bug, and it appears in rare conditions, is it worth reporting these at all?
> 
> Yeah just in case - it could be indicative of a larger problem!

tried with default config, same behavior
1.spawn window on group
2.hold press mod key
3.quick pressing of several 3 or more times on bar
4.try to spawn new window




Weird!

Doesn't seem to be anything to do with TaskList. I just get this on an empty bit of my bar (well, it would be the WindowName widget that I'm clicking on).

I don't get the error messages but I do get a window that doesn't open correctly. (EDIT: ah, got them this time, it's like none of the windows in the group have the focus)

Need to look into this.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Trying to look into this a bit.

Interestingly, if you comment out the `Click` and `Drag` objects `mouse` in the config then this issue disappears.

I think the issue is that, when the bar is clicked, the `Drag` object results in the `qtile._drag` value being set. When a window opens, it's unable to focus because `Group._focus` returns immediately if `_drag` is set without `force` being True.

So it looks like we need to capture the key release and reset `_drag`. Will investigate as we should have this code already so something's not working right.

EDIT: Interesting... the button is only released when you subsequently click on another window so `_drag` is not unset until then.

EDIT 2: Fixed it.

Resolving patch:
diff --git a/libqtile/backend/x11/window.py b/libqtile/backend/x11/window.py
--- a/libqtile/backend/x11/window.py
+++ b/libqtile/backend/x11/window.py
@@ -1134,6 +1134,8 @@ def handle_ButtonPress(self, e):  # noqa: N802
 
     def handle_ButtonRelease(self, e):  # noqa: N802
         self.process_button_release(e.event_x, e.event_y, e.detail)
+        # return True to ensure Core also processes the release
+        return True
 
     def handle_EnterNotify(self, e):  # noqa: N802
         self.process_pointer_enter(e.event_x, e.event_y)


Test patch: