Bug 406780 - Smart Window Placement Algorithm ignores window decorations
Summary: Smart Window Placement Algorithm ignores window decorations
Status: RESOLVED INTENTIONAL
Alias: None
Product: kwin
Classification: Plasma
Component: core (show other bugs)
Version: git master
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-22 18:39 UTC by drew101
Modified: 2019-04-23 23:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description drew101 2019-04-22 18:39:28 UTC
SUMMARY
When opening a new window on an empty desktop the Smart Placement algorithm does not consider the window decorations in it's left most calculations.  

STEPS TO REPRODUCE
1. Open a new desktop
2. Open any application (eg: konsole, xterm, etc.)
3. Move the window slightly to the right to snap to the screen edge.

OBSERVED RESULT
The left side of the window decoration will be off screen.

EXPECTED RESULT
After the window is moved it will snap to the screen edge showing the full window decoration.

SOFTWARE/OS VERSIONS
Windows: 
Linux/KDE Plasma: 4.14.3 (Slackware 14.2) PLEASE SEE BELOW
(available in About System)
KDE Plasma Version: 4.14.3
KDE Frameworks Version: 4.14.3
Qt Version: 4.8.7

ADDITIONAL INFORMATION

I realize this is an older release of KDE, but I have pulled the current release of placement.cpp from the GIT repository and compared to the source code Slackware used to build this package.  The Placement::placeSmart function is almost identical in both versions.  The line I believe needs review is around line 220:

 int x = maxRect.left(), y = maxRect.top();

and then a few lines later:

        if (overlap == none) {
            x_optimal = x;
            y_optimal = y;
            break;
        }

        if (first_pass) {
            first_pass = false;
            min_overlap = overlap;
        }
        //CT save the best position and the minimum overlap up to now
        else if (overlap >= none && overlap < min_overlap) {
            min_overlap = overlap;
            x_optimal = x;
            y_optimal = y;
        }

x_optimal and y_optimal are being used to display the window without considering the width of the Window decorations.

Additional windows do not overlap, which the algorithm tests for and adjusts to make sure there isn't.  This only affects windows placed on the left hand edge of the screen.
Comment 1 Vlad Zahorodnii 2019-04-22 20:20:38 UTC
As far as I know this is intended behavior (according to the source code), though I don't know why.
As a workaround, you could disable window snapping.
Comment 2 drew101 2019-04-23 03:34:39 UTC
My apologies if I was clear, the window snap is working as intended, the smart placement algorithm is not.  It is not taking into account the window decorations when calculating the "left" side of the window when being placed on an empty desktop.

It should place the window on the desktop showing the full window decoration.  

And you are correct, it is what the code is doing.  This is the bug... :)
Comment 3 drew101 2019-04-23 03:36:31 UTC
(In reply to drew101 from comment #2)
> My apologies if I was 

That should read *wasn't*.  Sorry, I was typing and not reading... :)
Comment 4 Vlad Zahorodnii 2019-04-23 08:34:41 UTC
> the smart placement algorithm is not

No, it's working as intended.

The "bug" you experience is caused by border snapping. In either case, if you would like to disable it, just set "Border snap zone" to zero.
Comment 5 Vlad Zahorodnii 2019-04-23 21:24:10 UTC
See bug 318107 for explanation why windows are snapped.
Comment 6 drew101 2019-04-23 23:16:40 UTC
Thank you!  Annoyance resolved.  

Maybe there needs to be a better explanation about this effect and what it is doing.  I fought with this for hours, including digging into the code (which I obviously didn't totally understand).

In any case your help is much appreciated.