Bug 453532

Summary: [Wayland] Context menu opens in the middle of the screen with window decoration when Places panel is right-clicked while another window is focused
Product: [Frameworks and Libraries] frameworks-kio Reporter: Patrick Silva <bugseforuns>
Component: PlacesAssignee: KIO Bugs <kio-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: aguyshat, gudvinr+kde, indecisiveautomator, kde, kdelibs-bugs, kfm-devel, oded, phyllon
Priority: NOR    
Version: 5.101.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: screenshot

Description Patrick Silva 2022-05-08 10:42:12 UTC
Created attachment 148654 [details]
screenshot

STEPS TO REPRODUCE
1. use Wayland session
2. open Dolphin and maximize it
3. open Kate and do not maximize it
4. while Kate is focused, right-click on any item in the Places panel of Dolphin

OBSERVED RESULT
as we can see in the atached screenshot, context menu opens in the middle of the screen with window decoration

EXPECTED RESULT
context menu opens in the correct position without window decoration

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.24.80
KDE Frameworks Version: 5.94.0
Qt Version: 5.15.3
Graphics Platform: Wayland
Comment 1 Patrick Silva 2022-09-20 13:02:00 UTC
*** Bug 459416 has been marked as a duplicate of this bug. ***
Comment 2 Oded Arbel 2022-10-25 13:30:34 UTC
I cannot reproduce this issue with Dolphin, though I can reproduce a similar issue with kate. I opened a different bug report about it here: #460983
Comment 3 Phos 2022-10-30 17:11:08 UTC
Still can replicate in Okular 22.08.2
Comment 4 Phos 2022-10-30 17:15:27 UTC
Seems to be similar to the one I'm experiencing in Okular, I can also replicate this bug in 22.08.2
Comment 5 Patrick Silva 2022-11-21 00:36:41 UTC
*** Bug 462079 has been marked as a duplicate of this bug. ***
Comment 6 Patrick Silva 2022-12-19 12:21:06 UTC
*** Bug 463220 has been marked as a duplicate of this bug. ***
Comment 7 Oded Arbel 2022-12-19 14:14:46 UTC
Correction: I *can* reproduce this issue with Dolphin, and also with Gwenview, K3b - so it isn't a Dolphin issue.

The problem appears to be with kio's KFilePlacesView (https://invent.kde.org/frameworks/kio/-/blob/master/src/filewidgets/kfileplacesview.cpp#L1077) that creates the places context menu without a proper parent (possibly other filewidgets suffer from the same issue - I think K3b uses a widget that isn't KFilePlacesView).

I tried to fix this locally in Dolphin by setting the parent widget in the `contextMenuAboutToShow` signal handler, but I didn't get much success with that (I either can't find a valid parent, I'm doing something wrong or at this point it is too late anyway).

BTW: for repro, you don't need a maximized window - it is easy to repro with any app that uses a KIO file widget: after opening the app and making sure the tested file widget is showing, activate another app that does not overlap the tested area, then right click the tested widget. Because the right-clicked app does not have an active window, and the menu has no parent, Qt fails to associate the menu correctly and it displays as a top level window.

I have found a tangentially related old Qt bug that discusses some of the issue - https://bugreports.qt.io/browse/QTBUG-60932 - that specific use case was fixed in Qt 5.9, but as noted in that reports' comments - there's a more general issue that wasn't fixed in Qt.
Comment 8 Bug Janitor Service 2022-12-25 09:37:49 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1091
Comment 9 Kai Uwe Broulik 2023-01-10 14:27:27 UTC
Git commit 2676d7b0a0c37115dd6df236cddcdddd674d50bb by Kai Uwe Broulik.
Committed on 10/01/2023 at 13:49.
Pushed by broulik into branch 'master'.

KFilePlacesView: Set transientParent on context menu

Without a parent widget, Qt cannot figure out what's the transient parent
if the window has no focus, resulting in the menu opening as a
standalone window.

M  +5    -0    src/filewidgets/kfileplacesview.cpp

https://invent.kde.org/frameworks/kio/commit/2676d7b0a0c37115dd6df236cddcdddd674d50bb
Comment 10 Kai Uwe Broulik 2023-01-10 14:35:25 UTC
Git commit aaab1e4482845bee3c35c0fb618c37889acfdfa7 by Kai Uwe Broulik.
Committed on 10/01/2023 at 14:35.
Pushed by broulik into branch 'kf5'.

KFilePlacesView: Set transientParent on context menu

Without a parent widget, Qt cannot figure out what's the transient parent
if the window has no focus, resulting in the menu opening as a
standalone window.


(cherry picked from commit 2676d7b0a0c37115dd6df236cddcdddd674d50bb)

M  +5    -0    src/filewidgets/kfileplacesview.cpp

https://invent.kde.org/frameworks/kio/commit/aaab1e4482845bee3c35c0fb618c37889acfdfa7