summaryrefslogtreecommitdiff
path: root/debian/patches/0178-transparency-window-types.diff
blob: e0ef3d8f8d71156be86edc40baec01fe4e04a0fa (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
qt-bugs@ issue : none yet
Trolltech task ID : none
bugs.kde.org number : none
applied: no
author: Lubos Lunak <l.lunak@kde.org>

This patch adds Qt support for new window types used for compositing.

--- qt4-x11-4.3.1.orig/src/gui/kernel/qapplication_x11.cpp
+++ qt4-x11-4.3.1/src/gui/kernel/qapplication_x11.cpp
@@ -214,6 +214,11 @@
     "_NET_WM_WINDOW_TYPE_SPLASH\0"
     "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
     "_NET_WM_WINDOW_TYPE_UTILITY\0"
+    "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
+    "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
+    "_NET_WM_WINDOW_TYPE_COMBO\0"
+    "_NET_WM_WINDOW_TYPE_DND\0"
+    "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
 
     "_KDE_NET_WM_FRAME_STRUT\0"
 
--- qt4-x11-4.3.1.orig/src/gui/kernel/qdnd_x11.cpp
+++ qt4-x11-4.3.1/src/gui/kernel/qdnd_x11.cpp
@@ -270,6 +270,7 @@
         QWidget(QApplication::desktop()->screen(screen),
                 Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint)
     {
+    x11SetWindowType( X11WindowTypeDND );
     }
 
     void setPixmap(const QPixmap &pm)
@@ -1438,6 +1439,7 @@
         // recreate the pixmap on the new screen...
         delete xdnd_data.deco;
         xdnd_data.deco = new QShapedPixmapWidget(screen);
+        xdnd_data.deco->x11SetWindowTransient( object->source()->topLevelWidget());
         if (!QWidget::mouseGrabber()) {
             updatePixmap();
             xdnd_data.deco->grabMouse();
@@ -1899,6 +1901,7 @@
     object = o;
     object->d_func()->target = 0;
     xdnd_data.deco = new QShapedPixmapWidget();
+    xdnd_data.deco->x11SetWindowTransient( object->source()->topLevelWidget());
 
     willDrop = false;
 
--- qt4-x11-4.3.1.orig/src/gui/kernel/qt_x11_p.h
+++ qt4-x11-4.3.1/src/gui/kernel/qt_x11_p.h
@@ -530,6 +530,11 @@
         _NET_WM_WINDOW_TYPE_SPLASH,
         _NET_WM_WINDOW_TYPE_TOOLBAR,
         _NET_WM_WINDOW_TYPE_UTILITY,
+        _NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
+        _NET_WM_WINDOW_TYPE_POPUP_MENU,
+        _NET_WM_WINDOW_TYPE_COMBO,
+        _NET_WM_WINDOW_TYPE_DND,
+        _NET_WM_WINDOW_TYPE_TOOLTIP,
 
         _KDE_NET_WM_FRAME_STRUT,
 
--- qt4-x11-4.3.1.orig/src/gui/kernel/qtooltip.cpp
+++ qt4-x11-4.3.1/src/gui/kernel/qtooltip.cpp
@@ -149,6 +149,9 @@
     setMouseTracking(true);
     fadingOut = false;
     reuseTip(text);
+#ifdef Q_WS_X11
+    x11SetWindowType( X11WindowTypeTooltip );
+#endif
 }
 
 void QTipLabel::restartHideTimer()
@@ -369,6 +372,10 @@
             // that is showing (removes flickering)
             if (QTipLabel::instance->tipChanged(pos, text, w)){
                 QTipLabel::instance->reuseTip(text);
+#ifdef Q_WS_X11
+                if (w)
+                    QTipLabel::instance->x11SetWindowTransient( w->topLevelWidget());
+#endif
                 QTipLabel::instance->setTipRect(w, rect);
                 QTipLabel::instance->placeTip(pos, w);
             }
@@ -378,6 +385,10 @@
 
     if (!text.isEmpty()){ // no tip can be reused, create new tip:
         new QTipLabel(pos, text, w); // sets QTipLabel::instance to itself
+#ifdef Q_WS_X11
+        if (w)
+            QTipLabel::instance->x11SetWindowTransient( w->topLevelWidget());
+#endif
         QTipLabel::instance->setTipRect(w, rect);
         QTipLabel::instance->placeTip(pos, w);
         QTipLabel::instance->setObjectName(QLatin1String("qtooltip_label"));
--- qt4-x11-4.3.1.orig/src/gui/kernel/qwidget.h
+++ qt4-x11-4.3.1/src/gui/kernel/qwidget.h
@@ -354,6 +354,19 @@
 
     void setWindowOpacity(qreal level);
     qreal windowOpacity() const;
+#if defined(Q_WS_X11)
+    enum X11WindowType {
+        X11WindowTypeSelect,
+        X11WindowTypeCombo,
+        X11WindowTypeDND,
+        X11WindowTypeTooltip,
+        X11WindowTypeMenu, // torn-off
+        X11WindowTypeDropdown,
+        X11WindowTypePopup
+    };
+    void x11SetWindowType( X11WindowType type = X11WindowTypeSelect );
+    void x11SetWindowTransient( QWidget* parent );
+#endif
 
     bool isWindowModified() const;
 #ifndef QT_NO_TOOLTIP
--- qt4-x11-4.3.1.orig/src/gui/kernel/qwidget_x11.cpp
+++ qt4-x11-4.3.1/src/gui/kernel/qwidget_x11.cpp
@@ -562,10 +562,6 @@
     }
 #endif // QT_NO_XRENDER
 
-    // NET window types
-    long net_wintypes[7] = { 0, 0, 0, 0, 0, 0, 0 };
-    int curr_wintype = 0;
-
     QtMWMHints mwmhints;
     mwmhints.flags = 0L;
     mwmhints.functions = MWM_FUNC_ALL;
@@ -576,15 +572,11 @@
     if (topLevel) {
         ulong wsa_mask = 0;
         if (type == Qt::SplashScreen) {
-            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
         } else { //       if (customize) {
             mwmhints.decorations = 0L;
             mwmhints.flags |= MWM_HINTS_DECORATIONS;
 
-            if (flags & Qt::FramelessWindowHint) {
-                // override netwm type - quick and easy for KDE noborder
-                net_wintypes[curr_wintype++] = ATOM(_KDE_NET_WM_WINDOW_TYPE_OVERRIDE);
-            } else {
+            if ((flags & Qt::FramelessWindowHint) == 0 ) {
                 mwmhints.decorations |= MWM_DECOR_BORDER;
                 mwmhints.decorations |= MWM_DECOR_RESIZEH;
 
@@ -606,22 +598,6 @@
             wsa.save_under = True;
             wsa_mask |= CWSaveUnder;
         }
-        // ### need a better way to do this
-        if (q->inherits("QMenu")) {
-            // menu netwm type
-            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_MENU);
-        } else if (q->inherits("QToolBar")) {
-            // toolbar netwm type
-            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
-        } else if (type == Qt::Tool || type == Qt::Drawer) {
-            // utility netwm type
-            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
-        }
-
-        if (dialog) // dialog netwm type
-            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
-        // normal netwm type - default
-        net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_NORMAL);
 
         if (flags & Qt::X11BypassWindowManagerHint) {
             wsa.override_redirect = True;
@@ -640,6 +616,7 @@
         wsa.save_under = True;
         XChangeWindowAttributes(dpy, id, CWOverrideRedirect | CWSaveUnder,
                                 &wsa);
+        q->x11SetWindowType();
     } else if (topLevel && !desktop) {        // top-level widget
         if (!X11->wm_client_leader)
             create_wm_client_leader();
@@ -684,12 +661,7 @@
         // set mwm hints
         SetMWMHints(dpy, id, mwmhints);
 
-        // set _NET_WM_WINDOW_TYPE
-        if (curr_wintype > 0)
-            XChangeProperty(dpy, id, ATOM(_NET_WM_WINDOW_TYPE), XA_ATOM, 32, PropModeReplace,
-                            (unsigned char *) net_wintypes, curr_wintype);
-        else
-            XDeleteProperty(dpy, id, ATOM(_NET_WM_WINDOW_TYPE));
+        q->x11SetWindowType(); // set _NET_WM_WINDOW_TYPE
 
         // set _NET_WM_PID
         long curr_pid = getpid();
@@ -785,6 +757,63 @@
         q->setAttribute(Qt::WA_OutsideWSRange, true);
 }
 
+// Sets the EWMH (netwm) window type. Needed as a separate function
+// because create() may be too soon in some cases.
+void QWidget::x11SetWindowType( X11WindowType type )
+{
+    Display* dpy = X11->display;
+    // NET window types
+    long net_wintypes[7] = { 0, 0, 0, 0, 0, 0, 0 };
+    int curr_wintype = 0;
+    if( type == X11WindowTypeSelect ) {
+        if ( windowType() == Qt::SplashScreen ) {
+            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_SPLASH);
+        } else if (inherits("QToolBar")) {
+	    // toolbar netwm type
+	    net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR);
+        } else if (windowType() == Qt::Tool || windowType() == Qt::Drawer) {
+	    // utility netwm type
+	    net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_UTILITY);
+        } else if (windowType() == Qt::Dialog || windowType() == Qt::Sheet
+            || (windowFlags() & Qt::MSWindowsFixedSizeDialogHint)) {
+            // dialog netwm type
+            net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_DIALOG);
+        }
+    } else if( type == X11WindowTypeCombo ) {
+        // combo netwm type
+	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_COMBO);
+    } else if( type == X11WindowTypeDND ) {
+        // dnd netwm type
+    	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_DND);
+    } else if( type == X11WindowTypeDropdown ) {
+        // dropdown netwm type
+    	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_DROPDOWN_MENU);
+    } else if( type == X11WindowTypePopup ) {
+        // popup netwm type
+    	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_POPUP_MENU);
+    } else if( type == X11WindowTypeMenu ) {
+        // menu netwm type
+	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_MENU);
+    } else if( type == X11WindowTypeTooltip ) {
+        // tooltip netwm type
+    	net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_TOOLTIP);
+    }
+
+    // normal netwm type - default
+    net_wintypes[curr_wintype++] = ATOM(_NET_WM_WINDOW_TYPE_NORMAL);
+    // set _NET_WM_WINDOW_TYPE
+    if (curr_wintype > 0)
+        XChangeProperty(dpy, winId(), ATOM(_NET_WM_WINDOW_TYPE), XA_ATOM, 32, PropModeReplace,
+			(unsigned char *) net_wintypes, curr_wintype);
+    else
+        XDeleteProperty(dpy, winId(), ATOM(_NET_WM_WINDOW_TYPE));
+}
+
+void QWidget::x11SetWindowTransient( QWidget* parent )
+{
+    XSetTransientForHint( X11->display, winId(), parent->window()->winId());
+}
+
 /*!
     Frees up window system resources. Destroys the widget window if \a
     destroyWindow is true.
--- qt4-x11-4.3.1.orig/src/gui/widgets/qcombobox.cpp
+++ qt4-x11-4.3.1/src/gui/widgets/qcombobox.cpp
@@ -333,6 +333,10 @@
             combo->update();
         }
     }
+#ifdef Q_WS_X11
+    x11SetWindowType( X11WindowTypeCombo );
+    x11SetWindowTransient( combo->topLevelWidget());
+#endif
 }
 
 void QComboBoxPrivateContainer::leaveEvent(QEvent *)
--- qt4-x11-4.3.1.orig/src/gui/widgets/qmenu.cpp
+++ qt4-x11-4.3.1/src/gui/widgets/qmenu.cpp
@@ -99,6 +99,9 @@
     QTornOffMenu(QMenu *p) : QMenu(*(new QTornOffMenuPrivate(p)))
     {
         setParent(p, Qt::Window | Qt::Tool);
+#ifdef Q_WS_X11
+        x11SetWindowType( X11WindowTypeMenu );
+#endif
 	setAttribute(Qt::WA_DeleteOnClose, true);
         setWindowTitle(p->windowTitle());
         setEnabled(p->isEnabled());
@@ -145,6 +148,9 @@
     }
     defaultMenuAction = menuAction = new QAction(q);
     menuAction->d_func()->menu = q;
+#ifdef Q_WS_X11
+    q->x11SetWindowType( QWidget::X11WindowTypePopup );
+#endif
 }
 
 //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't
@@ -1669,6 +1675,32 @@
     }
     setGeometry(QRect(pos, size));
 
+#ifdef Q_WS_X11
+    QWidget* top = this;
+    for(;;) {
+        if( QMenu* m = qobject_cast< QMenu* >( top )) {
+            if( m->d_func()->causedPopup.widget == NULL )
+                break; // --->
+            top = m->d_func()->causedPopup.widget;
+        } else
+            break; // -->
+    }
+    if( QMenu* m = qobject_cast< QMenu* >( top ))
+        x11SetWindowType( X11WindowTypePopup );
+    else
+        x11SetWindowType( X11WindowTypeDropdown );
+    // hackish ... try to find the main window related to this popup
+    QWidget* parent = d_func()->causedPopup.widget;
+    if( parent == NULL )
+        parent = parentWidget() ? parentWidget()->topLevelWidget() : NULL;
+    if( parent == NULL )
+        parent = QApplication::widgetAt( pos );
+    if( parent == NULL )
+        parent = qApp->activeWindow();
+    if( parent != NULL )
+        x11SetWindowTransient( parent );
+#endif
+
 #ifndef QT_NO_EFFECTS
     int hGuess = qApp->layoutDirection() == Qt::RightToLeft ? QEffects::LeftScroll : QEffects::RightScroll;
     int vGuess = QEffects::DownScroll;
@@ -1865,6 +1897,9 @@
     if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget))
         mb->d_func()->setCurrentAction(0);
 #endif
+#ifdef Q_WS_X11
+    x11SetWindowType( X11WindowTypePopup ); // reset
+#endif
     d->mouseDown = 0;
     d->hasHadMouse = false;
     d->causedPopup.widget = 0;