Correctly position context menu of the information panel under wayland with a secondary screen
ClosedPublic

Authored by meven on Mar 5 2019, 8:48 AM.

Details

Summary

According to my testing this bug occurs because Qcursor::pos() does not work as expected under wayland on a secondary screen, then it returns inaccurate data.
This could hide bugs elsewhere.

BUG: 404799
FIXED-IN: 19.04.0

Test Plan

Under Wayland test the context menu on both screens.
Do the same under Xorg.

Diff Detail

Repository
R318 Dolphin
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
meven created this revision.Mar 5 2019, 8:48 AM
Restricted Application added a project: Dolphin. · View Herald TranscriptMar 5 2019, 8:48 AM
Restricted Application added a subscriber: kfm-devel. · View Herald Transcript
meven requested review of this revision.Mar 5 2019, 8:48 AM
meven edited the summary of this revision. (Show Details)Mar 5 2019, 8:54 AM
meven edited the test plan for this revision. (Show Details)
meven updated this revision to Diff 53184.Mar 5 2019, 8:56 AM
meven edited the test plan for this revision. (Show Details)

Removed unneeded change

meven retitled this revision from Correctly position context menu under wayland with a secondary screen to Correctly position context menu of the information panel under wayland with a secondary screen.Mar 5 2019, 8:57 AM
nicolasfella added inline comments.
src/panels/information/informationpanelcontent.cpp
291

Please remove

meven updated this revision to Diff 53186.Mar 5 2019, 9:05 AM

Remove debug trace

meven edited the summary of this revision. (Show Details)Mar 5 2019, 9:10 AM
meven marked an inline comment as done.Mar 5 2019, 9:12 AM
ngraham edited the summary of this revision. (Show Details)Mar 5 2019, 5:02 PM
ngraham added a reviewer: Dolphin.
ngraham added a subscriber: ngraham.Mar 5 2019, 5:04 PM

This feels like a workaround to the actual issue itself. Why don't the context menus appear in the right place automatically? That seems like something that KWin is responsible for.

meven added a comment.Mar 5 2019, 5:17 PM

This feels like a workaround to the actual issue itself. Why don't the context menus appear in the right place automatically? That seems like something that KWin is responsible for.

The origin of the issue is that on a fresh new dolphin window on the left screen QCursor->pos() returns always QPoint(0,0) which is not correct.

After some more testing I discovered that once I switch the window to the other screen and back, the cursor position can be correct sometimes or has different bad position (not (0,0)), and on the other screen the cursor position con be become incorrect as well.

Also I wrote this code this way based on PlacesPanel::slotItemContextMenuRequested which is not affected by the same bug.

meven added a comment.Mar 7 2019, 8:30 AM

I am not sure this is a KWin bug.

The QCursor::pos() according to the documentation :

Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.

https://doc.qt.io/qt-5/qcursor.html#pos

But in a multi-screen context, this should not be used because it can't handle secondary screen as documented, which is the case here.
If that is the problem's root it also means that any use of QCursor::pos() will cause a bug in multi-screen contexts.
What do you think @ngraham KWin ?

elvisangelaccio accepted this revision.Mar 10 2019, 10:31 AM
elvisangelaccio added a subscriber: elvisangelaccio.

This is not a KWin bug. QCursor::pos()} is not reliable on Wayland and should not be used.

Do you have commit access?

This revision is now accepted and ready to land.Mar 10 2019, 10:31 AM
meven added a comment.EditedMar 12 2019, 7:51 AM

This is not a KWin bug. QCursor::pos()} is not reliable on Wayland and should not be used.

Could we document this ? So that the community avoids discovering a horde a bugs once wayland usage grows. Maybe on https://community.kde.org/Plasma/Wayland_Showstoppers

Or maybe QCursor::pos() will be fix down the line, which I doubt since it would be an Qt API change.

Do you have commit access?

I don't have commit access.

meven added a comment.EditedMar 12 2019, 11:37 AM

Just in kdevelop I have a bunch of bugs I could report in similar situation :
https://github.com/KDE/kdevelop/search?q=Qcursor%3A%3Apos&unscoped_q=Qcursor%3A%3Apos

This revision was automatically updated to reflect the committed changes.

My pleasure. :)

This is not a KWin bug. QCursor::pos()} is not reliable on Wayland and should not be used.

Could we document this ? So that the community avoids discovering a horde a bugs once wayland usage grows. Maybe on https://community.kde.org/Plasma/Wayland_Showstoppers

Better on https://community.kde.org/Guidelines_and_HOWTOs/Wayland_Porting_Notes (where we already explain how to avoid similar bugs).

meven added a comment.Mar 17 2019, 4:51 PM

This is not a KWin bug. QCursor::pos()} is not reliable on Wayland and should not be used.

Could we document this ? So that the community avoids discovering a horde a bugs once wayland usage grows. Maybe on https://community.kde.org/Plasma/Wayland_Showstoppers

Better on https://community.kde.org/Guidelines_and_HOWTOs/Wayland_Porting_Notes (where we already explain how to avoid similar bugs).

I've added a note about context Menus and QCursor::pos() :
https://community.kde.org/Guidelines_and_HOWTOs/Wayland_Porting_Notes#Context_Menu
Thanks :)