Bug 466135 - Window cascades if *any* window would be covered up by it, not just the one below it in the stacking order
Summary: Window cascades if *any* window would be covered up by it, not just the one b...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: core (show other bugs)
Version: 5.27.0
Platform: unspecified Linux
: NOR minor
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-20 11:06 UTC by Ennea
Modified: 2023-03-11 04:02 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ennea 2023-02-20 11:06:05 UTC
SUMMARY
Windows are now being cascaded after https://bugs.kde.org/show_bug.cgi?id=58063 was implemented for 5.27. This feature can currently be a bit unexpected in some specific scenarios, and I'd like to suggest changing it slightly to take care of this.

As an example scenario, consider this: a user has opened a Dolphin window with a relatively small window size. They have opened a maximized terminal emulator above this Dolphin window. They then open System Settings, and its window is larger than the Dolphin window. The System Settings window is then being cascaded, despite Dolphin being behind the (maximized) terminal emulator.

My proposal would be: do not consider windows that are already being covered by other existing windows when deciding whether a new window is being cascaded or not. In the example scenario above, the System Settings window is being cascaded, even though the Dolphin window that triggers this behavior is not currently visible to begin with.


STEPS TO REPRODUCE
1. Set window placement to "Centered"
2. Open a small window
3. Open or move a maximized window in front/on top
4. Open a window that would cover the previously opened small window

OBSERVED RESULT
The window opened last is being cascaded, therefore being off center.

EXPECTED RESULT
The window is not being cascaded, because cascading it does not prevent the small window being covered in this case, as it had already been covered before.

SOFTWARE/OS VERSIONS
KDE Plasma Version: 5.27.0

ADDITIONAL INFORMATION
This may also be of relevance: as of this change, forcing a centered window placement via "Window Rules" -> "Initial Placement" can also cascade the window. This may be unwanted behavior, assuming the user actually wants to force the window to be in a centered position.
Comment 1 Nate Graham 2023-02-21 23:23:44 UTC
Makes sense to me.
Comment 2 mccambria 2023-03-04 17:04:35 UTC
I'd like to second the issue raised in the original post's additional information section. I think I'm in the minority, but I preferred the original behavior where new windows just stacked on top of each other and did not cascade. It would be nice to have a switch to turn the cascading off, or at least be able to override it with a rule.
Comment 3 Natalie Clarius 2023-03-04 17:15:29 UTC
(In reply to mccambria from comment #2)
> I'd like to second the issue raised in the original post's additional
> information section. I think I'm in the minority, but I preferred the
> original behavior where new windows just stacked on top of each other and
> did not cascade. It would be nice to have a switch to turn the cascading
> off, or at least be able to override it with a rule.

To get custom window behavior we have scripting functionality in KWin, here is one that does what you want: https://www.reddit.com/r/kde/comments/117oywo/comment/j9d3ewk/?context=3

In any event this is a different feature request; if the above solution is not satisfactory could you file a separate report for that, and explain what the use case is and why a KWin script is not enough?
Comment 4 mccambria 2023-03-04 17:58:15 UTC
(In reply to Natalie Clarius from comment #3)
> (In reply to mccambria from comment #2)
> > I'd like to second the issue raised in the original post's additional
> > information section. I think I'm in the minority, but I preferred the
> > original behavior where new windows just stacked on top of each other and
> > did not cascade. It would be nice to have a switch to turn the cascading
> > off, or at least be able to override it with a rule.
> 
> To get custom window behavior we have scripting functionality in KWin, here
> is one that does what you want:
> https://www.reddit.com/r/kde/comments/117oywo/comment/j9d3ewk/?context=3
> 
> In any event this is a different feature request; if the above solution is
> not satisfactory could you file a separate report for that, and explain what
> the use case is and why a KWin script is not enough?

That worked perfectly! Thank you for pointing out that option.
Comment 5 Nate Graham 2023-03-06 16:12:10 UTC Comment hidden (spam)
Comment 6 Ennea 2023-03-06 16:18:17 UTC Comment hidden (spam)
Comment 7 Nate Graham 2023-03-06 16:19:19 UTC Comment hidden (spam)
Comment 8 Natalie Clarius 2023-03-06 16:25:26 UTC
Re. the original issue, I think the issue is valid but haven't been able to think of a solution that wouldn't be O(n^2) which Vlad said should better be avoided.
Comment 9 Ennea 2023-03-06 16:32:23 UTC
Could you not get a sorted list of windows, trim any elements behind the topmost maximized window and then run your overlap checks on the remaining windows? This would not properly handle all cases, but I think it handles many of the common cases. Maybe. I'll need to think about this more.
Comment 10 Natalie Clarius 2023-03-06 16:40:27 UTC
(In reply to Ennea from comment #9)
> Could you not get a sorted list of windows, trim any elements behind the
> topmost maximized window and then run your overlap checks on the remaining
> windows? This would not properly handle all cases, but I think it handles
> many of the common cases. Maybe. I'll need to think about this more.

Yeah, something like that might work well enough for the most prominent cases. The relevant code is at https://invent.kde.org/plasma/kwin/-/blob/master/src/placement.cpp#L593. Feel free to give it a shot!
Comment 11 Bug Janitor Service 2023-03-07 00:53:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/3761
Comment 12 Vlad Zahorodnii 2023-03-08 19:42:25 UTC
Git commit 39cea49a8fac55beae6d3bff51814b81ec34df87 by Vlad Zahorodnii, on behalf of Natalie Clarius.
Committed on 08/03/2023 at 19:04.
Pushed by vladz into branch 'master'.

placement: don't cascade for the sake of windows that are already covered

When checking for overlap with other windows when placing a new window and cascading to avoid complete overlap, ignore those windows that are already covered by other windows further on the top anyway.

The computation of the covered area is not entirely accurate as it uses the bounding rect rather than the combined rects of the windows, but okay enough for our use case imo.

M  +16   -4    src/placement.cpp

https://invent.kde.org/plasma/kwin/commit/39cea49a8fac55beae6d3bff51814b81ec34df87