SUMMARY [Wayland] When the application is calling QEventLoop::exec() in a slot connected to KTextEditor::View::contextMenuAboutToShow And the user uses the Keyboard 'Menu' button in the text area of the View to open the right-click-context-menu The signal KTextEditor::View::contextMenuAboutToShow gets called another time on QEventLoop::exec() This happens despite using the `QEventLoop::ExcludeUserInputEvents` flag. STEPS TO REPRODUCE 1. Use the minimal example at https://invent.kde.org/ulterno/UsingKTextEditor/-/tree/minimal. Build and run 2. Use the keyboard 'Menu' key to invoke the menu 3. Look at the debug output OBSERVED RESULT - The function MainWindow::doSomeMenuStuff gets called twice, corresponding to KTextEditor::View::contextMenuAboutToShow being emitted twice EXPECTED RESULT - KTextEditor::View::contextMenuAboutToShow is emitted only once and all subsequent connections act accordingly SOFTWARE/OS VERSIONS KTextEditor: master (dd56ddc2d64d02a4e258330af0d772444d94a488) Operating System: EndeavourOS KDE Plasma Version: 6.3.5 KDE Frameworks Version: 6.14.0 Qt Version: 6.9.0 Kernel Version: 6.14.6-arch1-1 (64-bit) Graphics Platform: Wayland ADDITIONAL INFORMATION Related to BUG 503813 Unable to reproduce on X11 session
Using guidance by Igor Kushnir, I see contextMenuEvent being called twice, in case the 'Menu' key is used. The QContextMenuEvent in this case, has different addresses. The resulting QMenu pointer for the KTextEditor::View::contextMenuAboutToShow signal ends up being the same due to KTextEditor::ViewPrivate::contextMenu() using the KXMLGUIFactory
We could block that until aboutToHideContextMenu is triggered.
That should work since we don't open another context menu on right click when one is already open (unlike Microsoft things). It might be good if we could find out why that happens in case of Wayland and not X11. Maybe one can try checking with something other than KWin?
Has somebody time to test that and provide a patch?