Bug 306281

Summary: autoraise raises inactive window under mouse when switching workspaces or closing active window
Product: [Plasma] kwin Reporter: Michael Hohmuth <hohmuth>
Component: coreAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: woebbeking
Priority: NOR    
Version: git master   
Target Milestone: 4.9.2   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 4.9.2
Sentry Crash Report:
Attachments: Proposed patch: predicate autoraise on moving mouse
Proposed patch v2: predicate autoraise on moving mouse

Description Michael Hohmuth 2012-09-05 07:20:25 UTC
When autoraise is enabled, switching workspaces or closing an active window raises the window that happens to be under the mouse instead of respecting the current stacking order.  This is wrong and annoying, especially when frequently switching virtual desktops, because it messes with the target workspace's stacking order when the mouse has been moved between two switches.

The problem is even worse when focus-follows-mouse is also enabled. Focus-follows-mouse correctly assumes that it should not activate the window under the mouse unless the mouse has actually been moved. In result, the window that's autoraised is often an inactive one, hiding the window actual active window.

This is a regression to KDE 3.5.

The fix is simple: autoraise needs to respect the same mouse-has-been-moved constraint that focus-follows-mouse uses.

Attaching patch.  Tested with kwin 4.7.2 (installed on my OpenSUSE box).  Patch forward ported to kwin git-master.


Reproducible: Always

Steps to Reproduce:
Reproduce when closing active window:
1. Enable focus-follows-mouse and autoraise
2. Open three windows, A, B, C.  Have B and C partially overlap. Place A over C.  Establish stacking order: A (focused) -> B -> C.
3. Move the mouse into A.  Close window A using a keyboard shortcut (typically Alt-F4).
4. Result: Window B will receive focus (according to stacking order), but window C will be raised over B (because the mouse will now be over C).

Reproduce when switching virtual desktops:
1. Enable focus-follows-mouse and autoraise
2. On workspace 1, open two windows, A and B.  Focus and raise A.
3. Switch to workspace 2 using a keyboard shortcut (typically Ctrl-F2).
4. Move the mouse so that it is over window B when switching back to workspace 1.
5. Switch to workspace 1 using a keyboard shortcut (typically Ctrl-F1).  Now window A will (correctly) remain focused , but window B will be raised.


Actual Results:  
In each case, the window under the mouse is raised, but not focused. This can lead to an unfocused window obscuring a focused window.

Expected Results:  
The unfocused window should not have been raised.  Autoraise should be predicated by a mouse move.
Comment 1 Michael Hohmuth 2012-09-05 07:23:05 UTC
Created attachment 73666 [details]
Proposed patch: predicate autoraise on moving mouse
Comment 2 Thomas Lübking 2012-09-05 12:47:36 UTC
No idea whether that's a regression (ie. how it behaved on 3.5) but feels wrong.
Please move the check before the more expensive topClientOnDesktop()

Do you have commit rights? Otherwise please provide a "git format-patch" so we can commit on your behalf.

And thanks for the notice & patch, btw.
Comment 3 Michael Hohmuth 2012-09-05 13:26:16 UTC
Created attachment 73672 [details]
Proposed patch v2: predicate autoraise on moving mouse

Thanks for your quick feedback. Updated patch attached. 

No, I do not have commit privileges.
Comment 4 Thomas Lübking 2012-09-05 19:14:02 UTC
Patch is fine and works
@Martin: any comments from your side? (9/10, "no way" ;-)

 @Michael:
Thanks again, ideally http://use git.reviewboard.kde.org to get future patches reviewed (if there will be such)
Comment 5 Martin Flöser 2012-09-05 19:24:30 UTC
only commit is that I will be very happy about that fix :-) And I'm quite sure this report is a duplicate, but I cannot find it
Comment 6 Thomas Lübking 2012-09-19 19:09:19 UTC
Git commit 6d098c60a5b998b6eb23cd6a30ffce8858f0aa16 by Thomas Lübking, on behalf of Michael Hohmuth.
Committed on 04/09/2012 at 23:36.
Pushed by luebking into branch 'KDE/4.9'.

Do not autoraise a window unless the mouse has been moved.

Fixes unintended autoraises when switching workspaces.
FIXED-IN: 4.9.2

M  +2    -1    kwin/events.cpp

http://commits.kde.org/kde-workspace/6d098c60a5b998b6eb23cd6a30ffce8858f0aa16
Comment 7 Andre Woebbeking 2012-09-20 20:24:12 UTC
(In reply to comment #5)
> only commit is that I will be very happy about that fix :-) And I'm quite
> sure this report is a duplicate, but I cannot find it

Isn't this 'related' to 92290?
Comment 8 Thomas Lübking 2012-09-20 20:35:52 UTC
focus != raising
I don't know whether there's an actual dupe.

FTR: original bug #92290 lead to the introduction of the last_mouse_pos variable, last remaining part was about unhiding dropdowns (and similar windows)