Repository: qtile/qtile

Issue:
cursor_warp makes impossible to put back a browser tab on chrome window (maybe any other browse)
# Issue description
 
When using multi monitors, I find it very useful to change cursor position when changing focus of workspaces and windows.

But as you can see in the video, that's an undesired behavior. As the title already says, I can't put it back.

# Other minor issues

When I click, holding CTRL, on a link to open a new tab inside a browser, for example, the cursor goes back to the center of that window.

If i click on someone's profile picture inside telegram-desktop, the cursor also goes back to the center of the window (in this case is indeed a new window because of the way telegram handles this situation specifically).

Thee might be a lot of other examples, but that's the general idea.

# Wish list

It would be very nice (at least for me) if we could change this behavior on specifics windows, or if I could invoke a function (with lazy?) that centers the cursor manually when switch to a window or workspace.

# Other

If there is documentation for the issue that I'm pointing here, I apologize, but I did a little bit of research before posting this issue.

I'm not demanding the devs to solve my problem, and by the fact that english is not my native language, I'm afraid I'm being a little rude.

https://user-images.githubusercontent.com/50176483/147363025-07b54054-bd96-4fe3-8024-ea7803bb35a2.mp4

# Configuration

My config is very long and I don't want to pollute this post, but I can confirm that `cursor_warp = True`



Discussion:
Hi @erlonbie ,

Don't worry, you're not being rude at all!

I'll be honest, however, I can't see anything in your video at all so I'm not sure what the problem is. The video is just a black screen for me.
@elParaguayo I just noticed that, sorry! In the preview tab was everything normal. How can I upload the video?

can you access this link?
 `https://user-images.githubusercontent.com/50176483/147363025-07b54054-bd96-4fe3-8024-ea7803bb35a2.mp4`
Thanks. That video works.

Yes, that behaviour does look very annoying!

I'll see if I can take a look later. Hopefully there's an easy fix for it.
> Thanks. That video works.
> 
> Yes, that behaviour does look very annoying!
> 
> I'll see if I can take a look later. Hopefully there's an easy fix for it.

Thank you in advance! 
I just realized that I posted an issue in Christmas eve, I'm very sorry about that! 😅

(Merry Christmas to all of you and thank you for the great work in qtile! 🎄)
Boas Festas!
I just saw this and decided to try it, i can't replicate that behavior in firefox.

Also thanks for the part of the config that i needed to change for the cursor to move when i change focus, i was just seeking for that
i think an important part of your configuration here is the keybindings, that might be the reason for this behavior 
Ok, i did find a weird behavior, i went and moved windows from one screen to the other, when i was in the middle of the second screen it moved my cursor, it also did the same when trying to change windows, i think it might be trying to warp the cursor in events that are undesirable, like while dragging something from one screen to another, or when changing focus of windows, i hope my testings help a little 
If I set `cursor_warp=True` I get this behaviour.
I tried a few more things, finally i get that, if i set 
```
follow_mouse_focus = False
bring_front_click = False
cursor_warp = True
```
i get most issues kinda solved, but i still get that the window on top would not change when i try to use another window, 
if i add `bring_front_click = True` then i might or might not be able to change windows, depending on if i have a widow maximized or not 
that leads me to believe it is more about the different configurations interacting with each other, i have not read the code enough to make a good conclusion, but now i can add that the behavior changes depending on other configuration parameters
Yeah. It's to do with windows being focused.
That's how this parameters are set for me.

![image](https://user-images.githubusercontent.com/50176483/147369892-f0f68944-ba37-4f99-b618-bc8bf0b2dc65.png)

(just in case my image does not loads properly)
`follow_mouse_focus = True`
`bring_front_click = False`
`cursor_warp = True`

If I change `bring_front_click = True`, I still get the same behavior.
Try changing `follow_mouse_focus` to True, that one is the one that caused more unexpected behavior, there also might be other options interacting, those where the ones i tried
Have found another time when this is annoying: triple-clicking to select all text in LibreOffice Calc warps the cursor back to the centre!
I have `follow_mouse_focus = False` so maybe that is linked to this.

EDIT: no. Still happens if I set this to True.
I think this is to do with handling of the focus event. The cursor warps when the window is told to focus but we probably only want to do this if the window isn't already focused.
> I think this is to do with handling of the focus event. The cursor warps when the window is told to focus but we probably only want to do this if the window isn't already focused.

This would already solve a lot of annoyances !



Resolving patch:
diff --git a/libqtile/group.py b/libqtile/group.py
--- a/libqtile/group.py
+++ b/libqtile/group.py
@@ -57,6 +57,7 @@ def __init__(self, name, layout=None, label=None):
         self.focus_history = []
         self.screen = None
         self.current_layout = None
+        self.last_focused = None
 
     def _configure(self, layouts, floating_layout, qtile):
         self.screen = None
@@ -153,6 +154,10 @@ def layout_all(self, warp=False):
                     self.floating_layout.layout(floating, screen_rect)
                 if self.current_window and self.screen == self.qtile.current_screen:
                     self.current_window.focus(warp)
+                else:
+                    # Screen has lost focus so we reset record of focused window so
+                    # focus will warp when screen is focused again
+                    self.last_focused = None
 
     def set_screen(self, screen, warp=True):
         """Set this group's screen to screen"""
@@ -200,7 +205,13 @@ def focus(self, win, warp=True, force=False):
         if win:
             if win not in self.windows:
                 return
+
+            # ignore focus events if window is the current window
+            if win is self.last_focused:
+                warp = False
+
             self.current_window = win
+            self.last_focused = self.current_window
             if win.floating:
                 for layout in self.layouts:
                     layout.blur()


Test patch: