File: qmenu_set_transient_parent.diff

package info (click to toggle)
qtbase-opensource-src-gles 5.15.15%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 349,396 kB
  • sloc: cpp: 2,089,897; ansic: 336,851; xml: 115,491; python: 9,447; java: 7,499; asm: 4,023; perl: 2,047; sh: 2,033; yacc: 1,687; lex: 1,333; javascript: 878; makefile: 260; objc: 70
file content (60 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Description: widgets: setTransientParent() when a QMenu is a window
 On some platforms, such as X11 and Wayland with some compositors,
 QMenu could be a popup window, which should be set a transient parent
 to get relative position, which is requested by Wayland.
 .
 Added transientParentWindow() for QMenuPrivate like QDialogPrivate.
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=493a85a9e4688744
Last-Update: 2022-10-16

--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -624,6 +624,29 @@ void QMenuPrivate::hideMenu(QMenu *menu)
     menu->d_func()->causedPopup.widget = nullptr;
 }
 
+QWindow *QMenuPrivate::transientParentWindow() const
+{
+    Q_Q(const QMenu);
+    if (const QWidget *parent = q->nativeParentWidget()) {
+        if (parent->windowHandle())
+            return parent->windowHandle();
+    }
+
+    if (const QWindow *w = q->windowHandle()) {
+        if (w->transientParent())
+            return w->transientParent();
+    }
+
+    if (causedPopup.widget) {
+        if (const QWidget *w = causedPopup.widget.data()) {
+            if (const QWidget *ww = w->window())
+                return ww->windowHandle();
+        }
+    }
+
+    return nullptr;
+}
+
 void QMenuPrivate::popupAction(QAction *action, int delay, bool activateFirst)
 {
     Q_Q(QMenu);
@@ -3060,6 +3083,8 @@ QMenu::event(QEvent *e)
         d->sloppyState.reset();
         if (d->currentAction)
             d->popupAction(d->currentAction, 0, false);
+        if (isWindow() && window() && window()->windowHandle() && !window()->windowHandle()->transientParent())
+            window()->windowHandle()->setTransientParent(d->transientParentWindow());
         break;
 #ifndef QT_NO_TOOLTIP
     case QEvent::ToolTip:
--- a/src/widgets/widgets/qmenu_p.h
+++ b/src/widgets/widgets/qmenu_p.h
@@ -440,6 +440,7 @@ public:
     QMenuCaused causedPopup;
     void hideUpToMenuBar();
     void hideMenu(QMenu *menu);
+    QWindow *transientParentWindow() const;
 
     //index mappings
     inline QAction *actionAt(int i) const { return q_func()->actions().at(i); }