Repository: qtile/qtile

Issue:
Scratchpad alternates opening with and without focus
I'm seeing some slightly odd behaviour in my scratchpad (running Alacritty) where the alt key is not being respected. For exampled `alt`+`.` in a terminal would give me the last argument from the previous command and `alt` + number gives a different screen in `irssi`.

This occurs when the scratchpad window is visible but doesn't have focus.

If I toggle the scratchpad, it alternates having focus and not having focus. There needs to be another window open on the active group for this to happen.

This bug is present on latest master: d5425eeb


Discussion:
Did some bisecting and it seems to be 41cadb19 that's the start of the issue. Before this, the scratchpad toggles ok and takes focus each time. After it, it alternates getting focus and not having it. 

However, with this one, the scratchpad appears when first toggled but isn't hidden when toggled again.

A bit more digging neede.
> If I toggle the scratchpad, it alternates having focus and not having focus. There needs to be another window open on the active group for this to happen.

Is this a separate issue from the alt key issue you describe? I can't reproduce on either x11 or wayland, scratchpad seems to work fine, even with alacritty. Possibly due to your configuration? The bisected commit is interesting, one line change in scratchpad.py and the commit pertains to pointer warping - suggesting it would be config related. However I changed around my `warp_pointer` and `follow_mouse_focus` options and still couldn't reproduce.

I also can't reproduce the alt issue.
The alt issue seems to be because certain keypresses are being sent to the terminal (e.g. the `.`) but not the alt.

Interesting that you can't reproduce. Did you have another window open in the group?
I tried with other windows, changing the focus around - all seems fine. Do you
have a reliable step-by-step i could use?

On 210629 02:21, elParaguayo wrote:
>The alt issue seems to be because certain keypresses are being sent to the terminal (e.g. the `.`) but not the alt.
>
>Interesting that you can't reproduce. Did you have another window open in the group?
>
>-- 
>You are receiving this because you commented.
>Reply to this email directly or view it on GitHub:
>https://github.com/qtile/qtile/issues/2588#issuecomment-870430109

It was as simple as:
1) Open an Alacritty session (mod + enter)
2) Open scratchpad via toggle key (it has focus - cursor is solid white block)
3) Close scratchpad via toggle key
4) Reopen scratchpad via toggle (Alacritty has hollow white square cursor and `alt` + `.` doesn't work - just types a `.`)
Tested with default config and this added at the bottom:
``` python
groups.append(ScratchPad("scratchpad", position=99, dropdowns=[
                DropDown("term", "alacritty",
                         on_focus_lost_hide=True),
                      ]),
          )

keys.extend([Key([], 'F12', lazy.group['scratchpad'].dropdown_toggle("term")),])
```
Get the same behaviour.
Here's a video of the issue. Look at the cursor character each time the dropdown window opens:


https://user-images.githubusercontent.com/946265/124389896-27e4f200-dce1-11eb-92cc-634d2e761b7c.mp4


Does seem to be x11 only for me.
I think this is Alacritty related. Closing this as I should be able to solve with a hook.
> 
> 
> I think this is Alacritty related. Closing this as I should be able to solve with a hook.

How did you solve it with a hook? I have the same problem.

Edit: It not only happens with alacritty for me but also emacs. And it only happens with ```on_focus_lost_hide=True``` with alacritty. For emacs it does not focus after the second toggle. I believe this is a qtile bug
This seems to be a bug with the x11 backend. Commenting out this line fixes it (but will give other unwanted behaviour probably so not a good fix) https://github.com/qtile/qtile/blob/8a7a9841e6c02c1ab22a51066cb64f2d9479c2fe/libqtile/backend/x11/core.py#L271 the commit @elParaguayo referenced (41cadb1) wanted to abstract the warp pointer by moving it to the core backend. However, setting input focus to root should not be done when we're warping to windows. Before in x11, the window's own warp_pointer https://github.com/qtile/qtile/blob/41cadb19c2bf7fc6fe9c7549b59b062b4efea2ab/libqtile/backend/x11/window.py#L144 was used which does not focus the root window.
Nice work looking at this more. Let's reopen this for now and see if we can get a proper fix.

Resolving patch:
diff --git a/libqtile/scratchpad.py b/libqtile/scratchpad.py
--- a/libqtile/scratchpad.py
+++ b/libqtile/scratchpad.py
@@ -112,7 +112,7 @@ def show(self):
             # add hooks to determine if focus get lost
             if self.on_focus_lost_hide:
                 if self.warp_pointer:
-                    win.qtile.core.warp_pointer(win.x + win.width // 2, win.y + win.height // 2)
+                    win.focus(warp=True)
                 hook.subscribe.client_focus(self.on_focus_change)
                 hook.subscribe.setgroup(self.on_focus_change)
 


Test patch: