Bug 278981 - Calling QWidget::setGeometry() on a top-level window makes it appear on different coordinates each time it is shown
Summary: Calling QWidget::setGeometry() on a top-level window makes it appear on diffe...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: compatibility (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
: 288741 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-07-31 23:51 UTC by Bartosz Brachaczek
Modified: 2011-12-18 18:52 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
testcase.cpp (613 bytes, text/plain)
2011-07-31 23:51 UTC, Bartosz Brachaczek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bartosz Brachaczek 2011-07-31 23:51:05 UTC
Created attachment 62402 [details]
testcase.cpp

Version:           unspecified (using KDE 4.7.0) 
OS:                Linux

Calling QWidget::setGeometry() on a top-level window makes it appear on different coordinates each time it is shown. More precisely, it seems it moves to the bottom-right corner in steps of window's geometry().topLeft()-frameGeometry().topLeft().
Normally I would report such thing to the Qt bugtracker but it didn't behave like that in KDE SC 4.6.x. It is a new thing in KDE SC 4.7.0. Maybe it's still a Qt bug or not a bug at all, but I'm not the one to decide.

Calling regular resize() + move() instead of setGeometry() does not result in any similar problems.

Attaching example code that shows the issue quite good.

Reproducible: Always

Steps to Reproduce:
1. Grab my testcase and save it as testcase.cpp.
2. Run
    $ moc testcase.cpp > testcase_moc.cx
3. Run
    $ g++ `pkg-config --libs --cflags QtGui` -o testcase testcase.cpp
4. Run
    $ ./testcase
and watch the window showing up every time in a different place.


Expected Results:  
If KWin devs consider it a bug in KWin, it is fixed so that the window shows every time on the same coordinates. If it is a bug Qt, it gets reported.

I discovered it because an app I am developer of (Kadu IM) was calling setGeometry() on top-level windows and we were experiencing that kind of moving windows when restoring from tray. We have already fixed it to resize() + move() but there may be more apps doing like we before (I don't know any, though).
Comment 1 Martin Flöser 2011-09-25 09:23:34 UTC
no matter what: do not workaround bugs in window managers or GUI libraries. By workarounding the issue you end up being wrong again when the window manager changes the code.

My recommendation: don't set the geometry yourself. The window manager may be positioning it somewhere completely else (e.g. a tiling one). It's nothing under the control of the application developer.
Comment 2 Thomas Lübking 2011-11-14 14:25:48 UTC
On some examination, i *think* this is a bug in Qt.
KWin only sends "correct" configure notification (tells the client that the geometry has changed), but:

The notified geometry is corrected by the decoration extents, ie. if the topleft of the *window* is 0,0 the topleft of the client may be like 4,20 and kwin tells the client: "you are at position 4,20" - at that time there's however also a (present, i've checked that) static info: "you have a 4,4,20,4 pixel frame" which is (when the client, thus the decoration is withdrawn) removed shortly after the configuration.
Also lying about the position in the confiuration has no impact.

What instead does work is to move(frameGeometry().topLeft()) right before the show() - what suggests that Qt assumes a Static geometry (while the window has indeed a NorthWestern one (iirc the default one))

An alternatve would be that Qt ignores configure events altogether and when it stores the geometry, it has not updated it's internal geometry and checks the strut (decoration extents) which have already been withdrawn (ignored property change as well?) and therefore miscalculates it's position (but that would have impact on the size as well, so i rather doubt this)

All in all, i'm rather confident that this is a Qt bug - did you maybe happen to update Qt alongside KDE back then? (yeah, great question  - i know ;-)
Comment 3 Bartosz Brachaczek 2011-11-14 16:41:47 UTC
I don't know, but it's likely that it's a Qt bug. Though, I'm sure a I was using Qt 4.7.3 before and after KDE SC update back then so KWin behavior must have changed somehow (nevertheless the bug report is not against this change but rather against incorrect behavior caused possibly by a Qt bug).
Comment 4 Thomas Lübking 2011-12-12 02:16:22 UTC
Nope, it's not.
Compositors fault (it creates the decoration before the placement for painting stuff and as a side effect pollutes the gravity)

Thanks for testcase and sorry for being wrong (until now =)
Comment 5 Thomas Lübking 2011-12-12 02:17:07 UTC
*** Bug 288741 has been marked as a duplicate of this bug. ***
Comment 6 Thomas Lübking 2011-12-18 18:52:37 UTC
Git commit 5dc917c4a3998053e793920e11375180c50675b4 by Thomas Lübking.
Committed on 12/12/2011 at 03:17.
Pushed by luebking into branch 'master'.

fix gravitation after compositor "polluted" it by updating the decoration _before_ placement

BUG: 278981
REVIEW: 103391

M  +1    -0    kwin/composite.cpp

http://commits.kde.org/kde-workspace/5dc917c4a3998053e793920e11375180c50675b4