author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 19 | fcece45ef507 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qevent.h" |
|
43 |
#include "qwidget.h" |
|
44 |
#include "qdesktopwidget.h" |
|
45 |
#include "qapplication.h" |
|
46 |
#include "qapplication_p.h" |
|
47 |
#include "qnamespace.h" |
|
48 |
#include "qpainter.h" |
|
49 |
#include "qbitmap.h" |
|
50 |
#include "qlayout.h" |
|
51 |
#include "qtextcodec.h" |
|
52 |
#include "qdatetime.h" |
|
53 |
#include "qcursor.h" |
|
54 |
#include "qstack.h" |
|
55 |
#include "qcolormap.h" |
|
56 |
#include "qdebug.h" |
|
57 |
#include "qmenu.h" |
|
58 |
#include "private/qmenu_p.h" |
|
59 |
#include "private/qbackingstore_p.h" |
|
60 |
#include "private/qwindowsurface_x11_p.h" |
|
61 |
||
62 |
//extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_x11.cpp |
|
63 |
||
64 |
#include <private/qpixmap_x11_p.h> |
|
65 |
#include <private/qpaintengine_x11_p.h> |
|
66 |
#include "qt_x11_p.h" |
|
67 |
#include "qx11info_x11.h" |
|
68 |
||
69 |
#include <stdlib.h> |
|
70 |
||
71 |
//#define ALIEN_DEBUG |
|
72 |
||
73 |
// defined in qapplication_x11.cpp |
|
74 |
//bool qt_wstate_iconified(WId); |
|
75 |
//void qt_updated_rootinfo(); |
|
76 |
||
77 |
||
78 |
#if !defined(QT_NO_IM) |
|
79 |
#include "qinputcontext.h" |
|
80 |
#include "qinputcontextfactory.h" |
|
81 |
#endif |
|
82 |
||
83 |
#include "qwidget_p.h" |
|
84 |
||
85 |
#define XCOORD_MAX 16383 |
|
86 |
#define WRECT_MAX 8191 |
|
87 |
||
88 |
QT_BEGIN_NAMESPACE |
|
89 |
||
90 |
extern bool qt_nograb(); |
|
91 |
||
92 |
QWidget *QWidgetPrivate::mouseGrabber = 0; |
|
93 |
QWidget *QWidgetPrivate::keyboardGrabber = 0; |
|
94 |
||
95 |
void qt_net_remove_user_time(QWidget *tlw); |
|
96 |
void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp); |
|
97 |
||
98 |
int qt_x11_create_desktop_on_screen = -1; |
|
99 |
||
100 |
extern void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp); |
|
101 |
||
102 |
// MWM support |
|
103 |
struct QtMWMHints { |
|
104 |
ulong flags, functions, decorations; |
|
105 |
long input_mode; |
|
106 |
ulong status; |
|
107 |
}; |
|
108 |
||
109 |
enum { |
|
110 |
MWM_HINTS_FUNCTIONS = (1L << 0), |
|
111 |
||
112 |
MWM_FUNC_ALL = (1L << 0), |
|
113 |
MWM_FUNC_RESIZE = (1L << 1), |
|
114 |
MWM_FUNC_MOVE = (1L << 2), |
|
115 |
MWM_FUNC_MINIMIZE = (1L << 3), |
|
116 |
MWM_FUNC_MAXIMIZE = (1L << 4), |
|
117 |
MWM_FUNC_CLOSE = (1L << 5), |
|
118 |
||
119 |
MWM_HINTS_DECORATIONS = (1L << 1), |
|
120 |
||
121 |
MWM_DECOR_ALL = (1L << 0), |
|
122 |
MWM_DECOR_BORDER = (1L << 1), |
|
123 |
MWM_DECOR_RESIZEH = (1L << 2), |
|
124 |
MWM_DECOR_TITLE = (1L << 3), |
|
125 |
MWM_DECOR_MENU = (1L << 4), |
|
126 |
MWM_DECOR_MINIMIZE = (1L << 5), |
|
127 |
MWM_DECOR_MAXIMIZE = (1L << 6), |
|
128 |
||
129 |
MWM_HINTS_INPUT_MODE = (1L << 2), |
|
130 |
||
131 |
MWM_INPUT_MODELESS = 0L, |
|
132 |
MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L, |
|
133 |
MWM_INPUT_FULL_APPLICATION_MODAL = 3L |
|
134 |
}; |
|
135 |
||
136 |
||
137 |
static QtMWMHints GetMWMHints(Display *display, Window window) |
|
138 |
{ |
|
139 |
QtMWMHints mwmhints; |
|
140 |
||
141 |
Atom type; |
|
142 |
int format; |
|
143 |
ulong nitems, bytesLeft; |
|
144 |
uchar *data = 0; |
|
145 |
if ((XGetWindowProperty(display, window, ATOM(_MOTIF_WM_HINTS), 0, 5, false, |
|
146 |
ATOM(_MOTIF_WM_HINTS), &type, &format, &nitems, &bytesLeft, |
|
147 |
&data) == Success) |
|
148 |
&& (type == ATOM(_MOTIF_WM_HINTS) |
|
149 |
&& format == 32 |
|
150 |
&& nitems >= 5)) { |
|
151 |
mwmhints = *(reinterpret_cast<QtMWMHints *>(data)); |
|
152 |
} else { |
|
153 |
mwmhints.flags = 0L; |
|
154 |
mwmhints.functions = MWM_FUNC_ALL; |
|
155 |
mwmhints.decorations = MWM_DECOR_ALL; |
|
156 |
mwmhints.input_mode = 0L; |
|
157 |
mwmhints.status = 0L; |
|
158 |
} |
|
159 |
||
160 |
if (data) |
|
161 |
XFree(data); |
|
162 |
||
163 |
return mwmhints; |
|
164 |
} |
|
165 |
||
166 |
static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints) |
|
167 |
{ |
|
168 |
if (mwmhints.flags != 0l) { |
|
169 |
XChangeProperty(display, window, ATOM(_MOTIF_WM_HINTS), ATOM(_MOTIF_WM_HINTS), 32, |
|
170 |
PropModeReplace, (unsigned char *) &mwmhints, 5); |
|
171 |
} else { |
|
172 |
XDeleteProperty(display, window, ATOM(_MOTIF_WM_HINTS)); |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
// Returns true if we should set WM_TRANSIENT_FOR on \a w |
|
177 |
static inline bool isTransient(const QWidget *w) |
|
178 |
{ |
|
179 |
return ((w->windowType() == Qt::Dialog |
|
180 |
|| w->windowType() == Qt::Sheet |
|
181 |
|| w->windowType() == Qt::Tool |
|
182 |
|| w->windowType() == Qt::SplashScreen |
|
183 |
|| w->windowType() == Qt::ToolTip |
|
184 |
|| w->windowType() == Qt::Drawer |
|
185 |
|| w->windowType() == Qt::Popup) |
|
186 |
&& !w->testAttribute(Qt::WA_X11BypassTransientForHint)); |
|
187 |
} |
|
188 |
||
189 |
static void do_size_hints(QWidget* widget, QWExtra *x); |
|
190 |
||
191 |
/***************************************************************************** |
|
192 |
QWidget member functions |
|
193 |
*****************************************************************************/ |
|
194 |
||
195 |
const uint stdWidgetEventMask = // X event mask |
|
196 |
(uint)( |
|
197 |
KeyPressMask | KeyReleaseMask | |
|
198 |
ButtonPressMask | ButtonReleaseMask | |
|
199 |
KeymapStateMask | |
|
200 |
ButtonMotionMask | PointerMotionMask | |
|
201 |
EnterWindowMask | LeaveWindowMask | |
|
202 |
FocusChangeMask | |
|
203 |
ExposureMask | |
|
204 |
PropertyChangeMask | |
|
205 |
StructureNotifyMask |
|
206 |
); |
|
207 |
||
208 |
const uint stdDesktopEventMask = // X event mask |
|
209 |
(uint)( |
|
210 |
KeymapStateMask | |
|
211 |
EnterWindowMask | LeaveWindowMask | |
|
212 |
PropertyChangeMask |
|
213 |
); |
|
214 |
||
215 |
||
216 |
/* |
|
217 |
The qt_ functions below are implemented in qwidgetcreate_x11.cpp. |
|
218 |
*/ |
|
219 |
||
220 |
Window qt_XCreateWindow(const QWidget *creator, |
|
221 |
Display *display, Window parent, |
|
222 |
int x, int y, uint w, uint h, |
|
223 |
int borderwidth, int depth, |
|
224 |
uint windowclass, Visual *visual, |
|
225 |
ulong valuemask, XSetWindowAttributes *attributes); |
|
226 |
Window qt_XCreateSimpleWindow(const QWidget *creator, |
|
227 |
Display *display, Window parent, |
|
228 |
int x, int y, uint w, uint h, int borderwidth, |
|
229 |
ulong border, ulong background); |
|
230 |
void qt_XDestroyWindow(const QWidget *destroyer, |
|
231 |
Display *display, Window window); |
|
232 |
||
233 |
||
234 |
static void qt_insert_sip(QWidget* scrolled_widget, int dx, int dy) |
|
235 |
{ |
|
236 |
if (!scrolled_widget->isWindow() && !scrolled_widget->internalWinId()) |
|
237 |
return; |
|
238 |
QX11Data::ScrollInProgress sip = { X11->sip_serial++, scrolled_widget, dx, dy }; |
|
239 |
X11->sip_list.append(sip); |
|
240 |
||
241 |
XClientMessageEvent client_message; |
|
242 |
client_message.type = ClientMessage; |
|
243 |
client_message.window = scrolled_widget->internalWinId(); |
|
244 |
client_message.format = 32; |
|
245 |
client_message.message_type = ATOM(_QT_SCROLL_DONE); |
|
246 |
client_message.data.l[0] = sip.id; |
|
247 |
||
248 |
XSendEvent(X11->display, scrolled_widget->internalWinId(), False, NoEventMask, |
|
249 |
(XEvent*)&client_message); |
|
250 |
} |
|
251 |
||
252 |
static int qt_sip_count(QWidget* scrolled_widget) |
|
253 |
{ |
|
254 |
int sips=0; |
|
255 |
||
256 |
for (int i = 0; i < X11->sip_list.size(); ++i) { |
|
257 |
const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i); |
|
258 |
if (sip.scrolled_widget == scrolled_widget) |
|
259 |
sips++; |
|
260 |
} |
|
261 |
||
262 |
return sips; |
|
263 |
} |
|
264 |
||
265 |
static void create_wm_client_leader() |
|
266 |
{ |
|
267 |
if (X11->wm_client_leader) return; |
|
268 |
||
269 |
X11->wm_client_leader = |
|
270 |
XCreateSimpleWindow(X11->display, |
|
271 |
QX11Info::appRootWindow(), |
|
272 |
0, 0, 1, 1, 0, 0, 0); |
|
273 |
||
274 |
// set client leader property to itself |
|
275 |
XChangeProperty(X11->display, |
|
276 |
X11->wm_client_leader, ATOM(WM_CLIENT_LEADER), |
|
277 |
XA_WINDOW, 32, PropModeReplace, |
|
278 |
(unsigned char *)&X11->wm_client_leader, 1); |
|
279 |
||
280 |
#ifndef QT_NO_SESSIONMANAGER |
|
281 |
// If we are session managed, inform the window manager about it |
|
282 |
QByteArray session = qApp->sessionId().toLatin1(); |
|
283 |
if (!session.isEmpty()) { |
|
284 |
XChangeProperty(X11->display, |
|
285 |
X11->wm_client_leader, ATOM(SM_CLIENT_ID), |
|
286 |
XA_STRING, 8, PropModeReplace, |
|
287 |
(unsigned char *)session.data(), session.size()); |
|
288 |
} |
|
289 |
#endif |
|
290 |
} |
|
291 |
||
292 |
/*! |
|
293 |
\internal |
|
294 |
Update the X11 cursor of the widget w. |
|
295 |
\a force is true if this function is called from dispatchEnterLeave, it means that the |
|
296 |
mouse is actually directly under this widget. |
|
297 |
*/ |
|
298 |
void qt_x11_enforce_cursor(QWidget * w, bool force) |
|
299 |
{ |
|
300 |
if (!w->testAttribute(Qt::WA_WState_Created)) |
|
301 |
return; |
|
302 |
||
303 |
static QPointer<QWidget> lastUnderMouse = 0; |
|
304 |
if (force) { |
|
305 |
lastUnderMouse = w; |
|
306 |
} else if (lastUnderMouse && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) { |
|
307 |
w = lastUnderMouse; |
|
308 |
} else if (!w->internalWinId()) { |
|
309 |
return; //the mouse is not under this widget, and it's not native, so don't change it |
|
310 |
} |
|
311 |
||
312 |
while (!w->internalWinId() && w->parentWidget() && !w->isWindow() && !w->testAttribute(Qt::WA_SetCursor)) |
|
313 |
w = w->parentWidget(); |
|
314 |
||
315 |
QWidget *nativeParent = w; |
|
316 |
if (!w->internalWinId()) |
|
317 |
nativeParent = w->nativeParentWidget(); |
|
318 |
// This does the same as effectiveWinId(), but since it is possible |
|
319 |
// to not have a native parent widget due to a special hack in |
|
320 |
// qwidget for reparenting widgets to a different X11 screen, |
|
321 |
// added additional check to make sure native parent widget exists. |
|
322 |
if (!nativeParent || !nativeParent->internalWinId()) |
|
323 |
return; |
|
324 |
WId winid = nativeParent->internalWinId(); |
|
325 |
||
326 |
if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) { |
|
327 |
#ifndef QT_NO_CURSOR |
|
328 |
QCursor *oc = QApplication::overrideCursor(); |
|
329 |
if (oc) { |
|
330 |
XDefineCursor(X11->display, winid, oc->handle()); |
|
331 |
} else if (w->isEnabled()) { |
|
332 |
XDefineCursor(X11->display, winid, w->cursor().handle()); |
|
333 |
} else { |
|
334 |
// enforce the windows behavior of clearing the cursor on |
|
335 |
// disabled widgets |
|
336 |
XDefineCursor(X11->display, winid, XNone); |
|
337 |
} |
|
338 |
#endif |
|
339 |
} else { |
|
340 |
XDefineCursor(X11->display, winid, XNone); |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
Q_GUI_EXPORT void qt_x11_enforce_cursor(QWidget * w) |
|
345 |
{ |
|
346 |
qt_x11_enforce_cursor(w, false); |
|
347 |
} |
|
348 |
||
349 |
Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget* w) |
|
350 |
{ |
|
351 |
if (!w || (!w->isWindow() && !w->internalWinId())) |
|
352 |
return; |
|
353 |
QApplication::flush(); |
|
354 |
XEvent ev; |
|
355 |
QTime t; |
|
356 |
t.start(); |
|
357 |
static const int maximumWaitTime = 2000; |
|
358 |
if (!w->testAttribute(Qt::WA_WState_Created)) |
|
359 |
return; |
|
360 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
361 |
WId winid = w->internalWinId(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
362 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
363 |
// first deliver events that are already in the local queue |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
364 |
QApplication::sendPostedEvents(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
365 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
366 |
// the normal sequence is: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
367 |
// ... ConfigureNotify ... ReparentNotify ... MapNotify ... Expose |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
368 |
// with X11BypassWindowManagerHint: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
369 |
// ConfigureNotify ... MapNotify ... Expose |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
370 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
371 |
enum State { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
372 |
Initial, Reparented, Mapped |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
373 |
} state = Initial; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
374 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
375 |
do { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
376 |
if (XEventsQueued(X11->display, QueuedAlready)) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
377 |
XNextEvent(X11->display, &ev); |
0 | 378 |
qApp->x11ProcessEvent(&ev); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
379 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
380 |
if (w->windowFlags() & Qt::X11BypassWindowManagerHint) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
381 |
switch (state) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
382 |
case Initial: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
383 |
case Reparented: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
384 |
if (ev.type == MapNotify && ev.xany.window == winid) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
385 |
state = Mapped; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
386 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
387 |
case Mapped: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
388 |
if (ev.type == Expose && ev.xany.window == winid) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
389 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
390 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
391 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
392 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
393 |
switch (state) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
394 |
case Initial: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
395 |
if (ev.type == ReparentNotify && ev.xany.window == winid) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
396 |
state = Reparented; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
397 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
398 |
case Reparented: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
399 |
if (ev.type == MapNotify && ev.xany.window == winid) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
400 |
state = Mapped; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
401 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
402 |
case Mapped: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
403 |
if (ev.type == Expose && ev.xany.window == winid) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
404 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
405 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
406 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
407 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
408 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
409 |
if (!XEventsQueued(X11->display, QueuedAfterFlush)) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
410 |
qApp->syncX(); // non-busy wait |
0 | 411 |
} |
412 |
if (t.elapsed() > maximumWaitTime) |
|
413 |
return; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
414 |
} while(1); |
0 | 415 |
} |
416 |
||
417 |
void qt_change_net_wm_state(const QWidget* w, bool set, Atom one, Atom two = 0) |
|
418 |
{ |
|
419 |
if (!w->isVisible()) // not managed by the window manager |
|
420 |
return; |
|
421 |
||
422 |
XEvent e; |
|
423 |
e.xclient.type = ClientMessage; |
|
424 |
e.xclient.message_type = ATOM(_NET_WM_STATE); |
|
425 |
e.xclient.display = X11->display; |
|
426 |
e.xclient.window = w->internalWinId(); |
|
427 |
e.xclient.format = 32; |
|
428 |
e.xclient.data.l[0] = set ? 1 : 0; |
|
429 |
e.xclient.data.l[1] = one; |
|
430 |
e.xclient.data.l[2] = two; |
|
431 |
e.xclient.data.l[3] = 0; |
|
432 |
e.xclient.data.l[4] = 0; |
|
433 |
XSendEvent(X11->display, RootWindow(X11->display, w->x11Info().screen()), |
|
434 |
false, (SubstructureNotifyMask | SubstructureRedirectMask), &e); |
|
435 |
} |
|
436 |
||
437 |
struct QX11WindowAttributes { |
|
438 |
const XWindowAttributes *att; |
|
439 |
}; |
|
440 |
||
441 |
void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const XWindowAttributes &a) |
|
442 |
{ |
|
443 |
QX11WindowAttributes att; |
|
444 |
att.att = &a; |
|
445 |
qt_x11_getX11InfoForWindow(xinfo,att); |
|
446 |
} |
|
447 |
||
448 |
||
449 |
static QVector<Atom> getNetWmState(QWidget *w) |
|
450 |
{ |
|
451 |
QVector<Atom> returnValue; |
|
452 |
||
453 |
// Don't read anything, just get the size of the property data |
|
454 |
Atom actualType; |
|
455 |
int actualFormat; |
|
456 |
ulong propertyLength; |
|
457 |
ulong bytesLeft; |
|
458 |
uchar *propertyData = 0; |
|
459 |
if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0, 0, |
|
460 |
False, XA_ATOM, &actualType, &actualFormat, |
|
461 |
&propertyLength, &bytesLeft, &propertyData) == Success |
|
462 |
&& actualType == XA_ATOM && actualFormat == 32) { |
|
463 |
returnValue.resize(bytesLeft / 4); |
|
464 |
XFree((char*) propertyData); |
|
465 |
||
466 |
// fetch all data |
|
467 |
if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0, |
|
468 |
returnValue.size(), False, XA_ATOM, &actualType, &actualFormat, |
|
469 |
&propertyLength, &bytesLeft, &propertyData) != Success) { |
|
470 |
returnValue.clear(); |
|
471 |
} else if (propertyLength != (ulong)returnValue.size()) { |
|
472 |
returnValue.resize(propertyLength); |
|
473 |
} |
|
474 |
||
475 |
// put it into netWmState |
|
476 |
if (!returnValue.isEmpty()) { |
|
477 |
memcpy(returnValue.data(), propertyData, returnValue.size() * sizeof(Atom)); |
|
478 |
} |
|
479 |
XFree((char*) propertyData); |
|
480 |
} |
|
481 |
||
482 |
return returnValue; |
|
483 |
} |
|
484 |
||
485 |
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) |
|
486 |
{ |
|
487 |
Q_Q(QWidget); |
|
488 |
Qt::WindowType type = q->windowType(); |
|
489 |
Qt::WindowFlags &flags = data.window_flags; |
|
490 |
QWidget *parentWidget = q->parentWidget(); |
|
491 |
||
492 |
if (type == Qt::ToolTip) |
|
493 |
flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint; |
|
494 |
if (type == Qt::Popup) |
|
495 |
flags |= Qt::X11BypassWindowManagerHint; |
|
496 |
||
497 |
bool topLevel = (flags & Qt::Window); |
|
498 |
bool popup = (type == Qt::Popup); |
|
499 |
bool dialog = (type == Qt::Dialog |
|
500 |
|| type == Qt::Sheet); |
|
501 |
bool desktop = (type == Qt::Desktop); |
|
502 |
bool tool = (type == Qt::Tool || type == Qt::SplashScreen |
|
503 |
|| type == Qt::ToolTip || type == Qt::Drawer); |
|
504 |
||
505 |
#ifdef ALIEN_DEBUG |
|
506 |
qDebug() << "QWidgetPrivate::create_sys START:" << q << "topLevel?" << topLevel << "WId:" |
|
507 |
<< window << "initializeWindow:" << initializeWindow << "destroyOldWindow" << destroyOldWindow; |
|
508 |
#endif |
|
509 |
if (topLevel) { |
|
510 |
if (parentWidget) { // if our parent stays on top, so must we |
|
511 |
QWidget *ptl = parentWidget->window(); |
|
512 |
if(ptl && (ptl->windowFlags() & Qt::WindowStaysOnTopHint)) |
|
513 |
flags |= Qt::WindowStaysOnTopHint; |
|
514 |
} |
|
515 |
||
516 |
if (type == Qt::SplashScreen) { |
|
517 |
if (X11->isSupportedByWM(ATOM(_NET_WM_WINDOW_TYPE_SPLASH))) { |
|
518 |
flags &= ~Qt::X11BypassWindowManagerHint; |
|
519 |
} else { |
|
520 |
flags |= Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint; |
|
521 |
} |
|
522 |
} |
|
523 |
// All these buttons depend on the system menu, so we enable it |
|
524 |
if (flags & (Qt::WindowMinimizeButtonHint |
|
525 |
| Qt::WindowMaximizeButtonHint |
|
526 |
| Qt::WindowContextHelpButtonHint)) |
|
527 |
flags |= Qt::WindowSystemMenuHint; |
|
528 |
} |
|
529 |
||
530 |
||
531 |
Window parentw, destroyw = 0; |
|
532 |
WId id = 0; |
|
533 |
||
534 |
// always initialize |
|
535 |
if (!window) |
|
536 |
initializeWindow = true; |
|
537 |
||
538 |
QX11Info *parentXinfo = parentWidget ? &parentWidget->d_func()->xinfo : 0; |
|
539 |
||
540 |
if (desktop && |
|
541 |
qt_x11_create_desktop_on_screen >= 0 && |
|
542 |
qt_x11_create_desktop_on_screen != xinfo.screen()) { |
|
543 |
// desktop on a certain screen other than the default requested |
|
544 |
QX11InfoData *xd = &X11->screens[qt_x11_create_desktop_on_screen]; |
|
545 |
xinfo.setX11Data(xd); |
|
546 |
} else if (parentXinfo && (parentXinfo->screen() != xinfo.screen() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
|| (parentXinfo->visual() != xinfo.visual() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
&& !q->inherits("QGLWidget")))) |
0 | 549 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
// QGLWidgets have to be excluded here as they have a |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
// specially crafted QX11Info structure which can't be swapped |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
// out with the parent widgets QX11Info. The parent visual, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
// for instance, might not even be GL capable. |
0 | 554 |
xinfo = *parentXinfo; |
555 |
} |
|
556 |
||
557 |
//get display, screen number, root window and desktop geometry for |
|
558 |
//the current screen |
|
559 |
Display *dpy = X11->display; |
|
560 |
int scr = xinfo.screen(); |
|
561 |
Window root_win = RootWindow(dpy, scr); |
|
562 |
int sw = DisplayWidth(dpy,scr); |
|
563 |
int sh = DisplayHeight(dpy,scr); |
|
564 |
||
565 |
if (desktop) { // desktop widget |
|
566 |
dialog = popup = false; // force these flags off |
|
567 |
data.crect.setRect(0, 0, sw, sh); |
|
568 |
} else if (topLevel && !q->testAttribute(Qt::WA_Resized)) { |
|
569 |
QDesktopWidget *desktopWidget = qApp->desktop(); |
|
570 |
if (desktopWidget->isVirtualDesktop()) { |
|
571 |
QRect r = desktopWidget->screenGeometry(); |
|
572 |
sw = r.width(); |
|
573 |
sh = r.height(); |
|
574 |
} |
|
575 |
||
576 |
int width = sw / 2; |
|
577 |
int height = 4 * sh / 10; |
|
578 |
if (extra) { |
|
579 |
width = qMax(qMin(width, extra->maxw), extra->minw); |
|
580 |
height = qMax(qMin(height, extra->maxh), extra->minh); |
|
581 |
} |
|
582 |
data.crect.setSize(QSize(width, height)); |
|
583 |
} |
|
584 |
||
585 |
parentw = topLevel ? root_win : parentWidget->effectiveWinId(); |
|
586 |
||
587 |
XSetWindowAttributes wsa; |
|
588 |
||
589 |
if (window) { // override the old window |
|
590 |
if (destroyOldWindow) { |
|
591 |
if (topLevel) |
|
592 |
X11->dndEnable(q, false); |
|
593 |
destroyw = data.winid; |
|
594 |
} |
|
595 |
id = window; |
|
596 |
setWinId(window); |
|
597 |
XWindowAttributes a; |
|
598 |
XGetWindowAttributes(dpy, window, &a); |
|
599 |
data.crect.setRect(a.x, a.y, a.width, a.height); |
|
600 |
||
601 |
if (a.map_state == IsUnmapped) |
|
602 |
q->setAttribute(Qt::WA_WState_Visible, false); |
|
603 |
else |
|
604 |
q->setAttribute(Qt::WA_WState_Visible); |
|
605 |
||
606 |
qt_x11_getX11InfoForWindow(&xinfo,a); |
|
607 |
||
608 |
} else if (desktop) { // desktop widget |
|
609 |
#ifdef QWIDGET_EXTRA_DEBUG |
|
610 |
qDebug() << "create desktop"; |
|
611 |
#endif |
|
612 |
id = (WId)parentw; // id = root window |
|
613 |
// QWidget *otherDesktop = find(id); // is there another desktop? |
|
614 |
// if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) { |
|
615 |
// otherDesktop->d->setWinId(0); // remove id from widget mapper |
|
616 |
// d->setWinId(id); // make sure otherDesktop is |
|
617 |
// otherDesktop->d->setWinId(id); // found first |
|
618 |
// } else { |
|
619 |
setWinId(id); |
|
620 |
// } |
|
621 |
} else if (topLevel || q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { |
|
622 |
#ifdef QWIDGET_EXTRA_DEBUG |
|
623 |
static int topLevels = 0; |
|
624 |
static int children = 0; |
|
625 |
if (parentw == root_win) |
|
626 |
qDebug() << "create toplevel" << ++topLevels; |
|
627 |
else |
|
628 |
qDebug() << "create child" << ++children; |
|
629 |
#endif |
|
630 |
QRect safeRect = data.crect; //##### must handle huge sizes as well.... i.e. wrect |
|
631 |
if (safeRect.width() < 1|| safeRect.height() < 1) { |
|
632 |
if (topLevel) { |
|
633 |
// top-levels must be at least 1x1 |
|
634 |
safeRect.setSize(safeRect.size().expandedTo(QSize(1, 1))); |
|
635 |
} else { |
|
636 |
// create it way off screen, and rely on |
|
637 |
// setWSGeometry() to do the right thing with it later |
|
638 |
safeRect = QRect(-1000,-1000,1,1); |
|
639 |
} |
|
640 |
} |
|
641 |
#ifndef QT_NO_XRENDER |
|
642 |
int screen = xinfo.screen(); |
|
643 |
if (topLevel && X11->use_xrender |
|
644 |
&& xinfo.depth() != 32 && X11->argbVisuals[screen] |
|
645 |
&& q->testAttribute(Qt::WA_TranslucentBackground)) |
|
646 |
{ |
|
647 |
QX11InfoData *xd = xinfo.getX11Data(true); |
|
648 |
||
649 |
xd->screen = screen; |
|
650 |
xd->visual = X11->argbVisuals[screen]; |
|
651 |
xd->colormap = X11->argbColormaps[screen]; |
|
652 |
xd->depth = 32; |
|
653 |
xd->defaultVisual = false; |
|
654 |
xd->defaultColormap = false; |
|
655 |
xd->cells = xd->visual->map_entries; |
|
656 |
xinfo.setX11Data(xd); |
|
657 |
} |
|
658 |
#endif |
|
659 |
if (xinfo.defaultVisual() && xinfo.defaultColormap()) { |
|
660 |
id = (WId)qt_XCreateSimpleWindow(q, dpy, parentw, |
|
661 |
safeRect.left(), safeRect.top(), |
|
662 |
safeRect.width(), safeRect.height(), |
|
663 |
0, |
|
664 |
BlackPixel(dpy, xinfo.screen()), |
|
665 |
WhitePixel(dpy, xinfo.screen())); |
|
666 |
} else { |
|
667 |
wsa.background_pixel = WhitePixel(dpy, xinfo.screen()); |
|
668 |
wsa.border_pixel = BlackPixel(dpy, xinfo.screen()); |
|
669 |
wsa.colormap = xinfo.colormap(); |
|
670 |
id = (WId)qt_XCreateWindow(q, dpy, parentw, |
|
671 |
safeRect.left(), safeRect.top(), |
|
672 |
safeRect.width(), safeRect.height(), |
|
673 |
0, xinfo.depth(), InputOutput, |
|
674 |
(Visual *) xinfo.visual(), |
|
675 |
CWBackPixel|CWBorderPixel|CWColormap, |
|
676 |
&wsa); |
|
677 |
} |
|
678 |
||
679 |
setWinId(id); // set widget id/handle + hd |
|
680 |
} |
|
681 |
||
682 |
#ifndef QT_NO_XRENDER |
|
683 |
if (picture) { |
|
684 |
XRenderFreePicture(X11->display, picture); |
|
685 |
picture = 0; |
|
686 |
} |
|
687 |
||
688 |
if (X11->use_xrender && !desktop && q->internalWinId()) { |
|
689 |
XRenderPictFormat *format = XRenderFindVisualFormat(dpy, (Visual *) xinfo.visual()); |
|
690 |
if (format) |
|
691 |
picture = XRenderCreatePicture(dpy, id, format, 0, 0); |
|
692 |
} |
|
693 |
#endif // QT_NO_XRENDER |
|
694 |
||
695 |
QtMWMHints mwmhints; |
|
696 |
mwmhints.flags = 0L; |
|
697 |
mwmhints.functions = 0L; |
|
698 |
mwmhints.decorations = 0; |
|
699 |
mwmhints.input_mode = 0L; |
|
700 |
mwmhints.status = 0L; |
|
701 |
||
702 |
if (topLevel) { |
|
703 |
ulong wsa_mask = 0; |
|
704 |
if (type != Qt::SplashScreen) { // && customize) { |
|
705 |
mwmhints.flags |= MWM_HINTS_DECORATIONS; |
|
706 |
||
707 |
bool customize = flags & Qt::CustomizeWindowHint; |
|
708 |
if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) { |
|
709 |
mwmhints.decorations |= MWM_DECOR_BORDER; |
|
710 |
mwmhints.decorations |= MWM_DECOR_RESIZEH; |
|
711 |
||
712 |
if (flags & Qt::WindowTitleHint) |
|
713 |
mwmhints.decorations |= MWM_DECOR_TITLE; |
|
714 |
||
715 |
if (flags & Qt::WindowSystemMenuHint) |
|
716 |
mwmhints.decorations |= MWM_DECOR_MENU; |
|
717 |
||
718 |
if (flags & Qt::WindowMinimizeButtonHint) { |
|
719 |
mwmhints.decorations |= MWM_DECOR_MINIMIZE; |
|
720 |
mwmhints.functions |= MWM_FUNC_MINIMIZE; |
|
721 |
} |
|
722 |
||
723 |
if (flags & Qt::WindowMaximizeButtonHint) { |
|
724 |
mwmhints.decorations |= MWM_DECOR_MAXIMIZE; |
|
725 |
mwmhints.functions |= MWM_FUNC_MAXIMIZE; |
|
726 |
} |
|
727 |
||
728 |
if (flags & Qt::WindowCloseButtonHint) |
|
729 |
mwmhints.functions |= MWM_FUNC_CLOSE; |
|
730 |
} |
|
731 |
} else { |
|
732 |
// if type == Qt::SplashScreen |
|
733 |
mwmhints.decorations = MWM_DECOR_ALL; |
|
734 |
} |
|
735 |
||
736 |
if (tool) { |
|
737 |
wsa.save_under = True; |
|
738 |
wsa_mask |= CWSaveUnder; |
|
739 |
} |
|
740 |
||
741 |
if (flags & Qt::X11BypassWindowManagerHint) { |
|
742 |
wsa.override_redirect = True; |
|
743 |
wsa_mask |= CWOverrideRedirect; |
|
744 |
} |
|
745 |
||
746 |
if (wsa_mask && initializeWindow) { |
|
747 |
Q_ASSERT(id); |
|
748 |
XChangeWindowAttributes(dpy, id, wsa_mask, &wsa); |
|
749 |
} |
|
750 |
||
751 |
if (mwmhints.functions != 0) { |
|
752 |
mwmhints.flags |= MWM_HINTS_FUNCTIONS; |
|
753 |
mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE; |
|
754 |
} else { |
|
755 |
mwmhints.functions = MWM_FUNC_ALL; |
|
756 |
} |
|
757 |
||
758 |
if (!(flags & Qt::FramelessWindowHint) |
|
759 |
&& flags & Qt::CustomizeWindowHint |
|
760 |
&& flags & Qt::WindowTitleHint |
|
761 |
&& !(flags & |
|
762 |
(Qt::WindowMinimizeButtonHint |
|
763 |
| Qt::WindowMaximizeButtonHint |
|
764 |
| Qt::WindowCloseButtonHint))) { |
|
765 |
// a special case - only the titlebar without any button |
|
766 |
mwmhints.flags = MWM_HINTS_FUNCTIONS; |
|
767 |
mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE; |
|
768 |
mwmhints.decorations = 0; |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
if (!initializeWindow) { |
|
773 |
// do no initialization |
|
774 |
} else if (popup) { // popup widget |
|
775 |
// set EWMH window types |
|
776 |
setNetWmWindowTypes(); |
|
777 |
||
778 |
wsa.override_redirect = True; |
|
779 |
wsa.save_under = True; |
|
780 |
Q_ASSERT(id); |
|
781 |
XChangeWindowAttributes(dpy, id, CWOverrideRedirect | CWSaveUnder, |
|
782 |
&wsa); |
|
783 |
} else if (topLevel && !desktop) { // top-level widget |
|
784 |
if (!X11->wm_client_leader) |
|
785 |
create_wm_client_leader(); |
|
786 |
||
787 |
// note: WM_TRANSIENT_FOR is set in QWidgetPrivate::show_sys() |
|
788 |
||
789 |
XSizeHints size_hints; |
|
790 |
size_hints.flags = USSize | PSize | PWinGravity; |
|
791 |
size_hints.x = data.crect.left(); |
|
792 |
size_hints.y = data.crect.top(); |
|
793 |
size_hints.width = data.crect.width(); |
|
794 |
size_hints.height = data.crect.height(); |
|
795 |
size_hints.win_gravity = |
|
796 |
QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity; |
|
797 |
||
798 |
XWMHints wm_hints; // window manager hints |
|
799 |
memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy |
|
800 |
wm_hints.flags = InputHint | StateHint | WindowGroupHint; |
|
801 |
wm_hints.input = True; |
|
802 |
wm_hints.initial_state = NormalState; |
|
803 |
wm_hints.window_group = X11->wm_client_leader; |
|
804 |
||
805 |
XClassHint class_hint; |
|
806 |
QByteArray appName = qAppName().toLatin1(); |
|
807 |
class_hint.res_name = appName.data(); // application name |
|
808 |
class_hint.res_class = const_cast<char *>(QX11Info::appClass()); // application class |
|
809 |
||
810 |
XSetWMProperties(dpy, id, 0, 0, |
|
811 |
qApp->d_func()->argv, qApp->d_func()->argc, |
|
812 |
&size_hints, &wm_hints, &class_hint); |
|
813 |
||
814 |
XResizeWindow(dpy, id, |
|
815 |
qBound(1, data.crect.width(), XCOORD_MAX), |
|
816 |
qBound(1, data.crect.height(), XCOORD_MAX)); |
|
817 |
XStoreName(dpy, id, appName.data()); |
|
818 |
Atom protocols[5]; |
|
819 |
int n = 0; |
|
820 |
protocols[n++] = ATOM(WM_DELETE_WINDOW); // support del window protocol |
|
821 |
protocols[n++] = ATOM(WM_TAKE_FOCUS); // support take focus window protocol |
|
822 |
protocols[n++] = ATOM(_NET_WM_PING); // support _NET_WM_PING protocol |
|
823 |
#ifndef QT_NO_XSYNC |
|
824 |
protocols[n++] = ATOM(_NET_WM_SYNC_REQUEST); // support _NET_WM_SYNC_REQUEST protocol |
|
825 |
#endif // QT_NO_XSYNC |
|
826 |
if (flags & Qt::WindowContextHelpButtonHint) |
|
827 |
protocols[n++] = ATOM(_NET_WM_CONTEXT_HELP); |
|
828 |
XSetWMProtocols(dpy, id, protocols, n); |
|
829 |
||
830 |
// set mwm hints |
|
831 |
SetMWMHints(dpy, id, mwmhints); |
|
832 |
||
833 |
// set EWMH window types |
|
834 |
setNetWmWindowTypes(); |
|
835 |
||
836 |
// set _NET_WM_PID |
|
837 |
long curr_pid = getpid(); |
|
838 |
XChangeProperty(dpy, id, ATOM(_NET_WM_PID), XA_CARDINAL, 32, PropModeReplace, |
|
839 |
(unsigned char *) &curr_pid, 1); |
|
840 |
||
841 |
// when we create a toplevel widget, the frame strut should be dirty |
|
842 |
data.fstrut_dirty = 1; |
|
843 |
||
844 |
// declare the widget's window role |
|
845 |
if (QTLWExtra *topData = maybeTopData()) { |
|
846 |
if (!topData->role.isEmpty()) { |
|
847 |
QByteArray windowRole = topData->role.toUtf8(); |
|
848 |
XChangeProperty(dpy, id, |
|
849 |
ATOM(WM_WINDOW_ROLE), XA_STRING, 8, PropModeReplace, |
|
850 |
(unsigned char *)windowRole.constData(), windowRole.length()); |
|
851 |
} |
|
852 |
} |
|
853 |
||
854 |
// set client leader property |
|
855 |
XChangeProperty(dpy, id, ATOM(WM_CLIENT_LEADER), |
|
856 |
XA_WINDOW, 32, PropModeReplace, |
|
857 |
(unsigned char *)&X11->wm_client_leader, 1); |
|
858 |
} else { |
|
859 |
// non-toplevel widgets don't have a frame, so no need to |
|
860 |
// update the strut |
|
861 |
data.fstrut_dirty = 0; |
|
862 |
} |
|
863 |
||
864 |
if (initializeWindow && q->internalWinId()) { |
|
865 |
// don't erase when resizing |
|
866 |
wsa.bit_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity; |
|
867 |
Q_ASSERT(id); |
|
868 |
XChangeWindowAttributes(dpy, id, CWBitGravity, &wsa); |
|
869 |
} |
|
870 |
||
871 |
// set X11 event mask |
|
872 |
if (desktop) { |
|
873 |
// QWidget* main_desktop = find(id); |
|
874 |
// if (main_desktop->testWFlags(Qt::WPaintDesktop)) |
|
875 |
// XSelectInput(dpy, id, stdDesktopEventMask | ExposureMask); |
|
876 |
// else |
|
877 |
XSelectInput(dpy, id, stdDesktopEventMask); |
|
878 |
} else if (q->internalWinId()) { |
|
879 |
XSelectInput(dpy, id, stdWidgetEventMask); |
|
880 |
#if !defined (QT_NO_TABLET) |
|
881 |
QTabletDeviceDataList *tablet_list = qt_tablet_devices(); |
|
882 |
if (X11->ptrXSelectExtensionEvent) { |
|
883 |
for (int i = 0; i < tablet_list->size(); ++i) { |
|
884 |
QTabletDeviceData tablet = tablet_list->at(i); |
|
885 |
X11->ptrXSelectExtensionEvent(dpy, id, reinterpret_cast<XEventClass*>(tablet.eventList), |
|
886 |
tablet.eventCount); |
|
887 |
} |
|
888 |
} |
|
889 |
#endif |
|
890 |
} |
|
891 |
||
892 |
if (desktop) { |
|
893 |
q->setAttribute(Qt::WA_WState_Visible); |
|
894 |
} else if (topLevel) { // set X cursor |
|
895 |
if (initializeWindow) { |
|
896 |
qt_x11_enforce_cursor(q); |
|
897 |
||
898 |
if (QTLWExtra *topData = maybeTopData()) |
|
899 |
if (!topData->caption.isEmpty()) |
|
900 |
setWindowTitle_helper(topData->caption); |
|
901 |
||
902 |
//always enable dnd: it's not worth the effort to maintain the state |
|
903 |
// NOTE: this always creates topData() |
|
904 |
X11->dndEnable(q, true); |
|
905 |
||
906 |
if (maybeTopData() && maybeTopData()->opacity != 255) |
|
907 |
q->setWindowOpacity(maybeTopData()->opacity/255.); |
|
908 |
||
909 |
} |
|
910 |
} else if (q->testAttribute(Qt::WA_SetCursor) && q->internalWinId()) { |
|
911 |
qt_x11_enforce_cursor(q); |
|
912 |
} |
|
913 |
||
914 |
if (extra && !extra->mask.isEmpty() && q->internalWinId()) |
|
915 |
XShapeCombineRegion(X11->display, q->internalWinId(), ShapeBounding, 0, 0, |
|
916 |
extra->mask.handle(), ShapeSet); |
|
917 |
||
918 |
if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled)) { |
|
919 |
QInputContext *inputContext = q->inputContext(); |
|
920 |
if (inputContext) |
|
921 |
inputContext->setFocusWidget(q); |
|
922 |
} |
|
923 |
||
924 |
if (destroyw) |
|
925 |
qt_XDestroyWindow(q, dpy, destroyw); |
|
926 |
||
927 |
// newly created windows are positioned at the window system's |
|
928 |
// (0,0) position. If the parent uses wrect mapping to expand the |
|
929 |
// coordinate system, we must also adjust this widget's window |
|
930 |
// system position |
|
931 |
if (!topLevel && !parentWidget->data->wrect.topLeft().isNull()) |
|
932 |
setWSGeometry(); |
|
933 |
else if (topLevel && (data.crect.width() == 0 || data.crect.height() == 0)) |
|
934 |
q->setAttribute(Qt::WA_OutsideWSRange, true); |
|
935 |
||
936 |
if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) { |
|
937 |
Q_ASSERT(q->internalWinId()); |
|
938 |
XMapWindow(X11->display, q->internalWinId()); |
|
939 |
// Ensure that mapped alien widgets are flushed immediately when re-created as native widgets. |
|
940 |
if (QWindowSurface *surface = q->windowSurface()) |
|
941 |
surface->flush(q, q->rect(), q->mapTo(surface->window(), QPoint())); |
|
942 |
} |
|
943 |
||
944 |
#ifdef ALIEN_DEBUG |
|
945 |
qDebug() << "QWidgetPrivate::create_sys END:" << q; |
|
946 |
#endif |
|
947 |
} |
|
948 |
||
949 |
static void qt_x11_recreateWidget(QWidget *widget) |
|
950 |
{ |
|
951 |
if (widget->inherits("QGLWidget")) { |
|
952 |
// We send QGLWidgets a ParentChange event which causes them to |
|
953 |
// recreate their GL context, which in turn causes them to choose |
|
954 |
// their visual again. Now that WA_TranslucentBackground is set, |
|
955 |
// QGLContext::chooseVisual will select an ARGB visual. |
|
956 |
QEvent e(QEvent::ParentChange); |
|
957 |
QApplication::sendEvent(widget, &e); |
|
958 |
} else { |
|
959 |
// For regular widgets, reparent them with their parent which |
|
960 |
// also triggers a recreation of the native window |
|
961 |
QPoint pos = widget->pos(); |
|
962 |
bool visible = widget->isVisible(); |
|
963 |
if (visible) |
|
964 |
widget->hide(); |
|
965 |
||
966 |
widget->setParent(widget->parentWidget(), widget->windowFlags()); |
|
967 |
widget->move(pos); |
|
968 |
if (visible) |
|
969 |
widget->show(); |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
static void qt_x11_recreateNativeWidgetsRecursive(QWidget *widget) |
|
974 |
{ |
|
975 |
if (widget->internalWinId()) |
|
976 |
qt_x11_recreateWidget(widget); |
|
977 |
||
978 |
const QObjectList &children = widget->children(); |
|
979 |
for (int i = 0; i < children.size(); ++i) { |
|
980 |
QWidget *child = qobject_cast<QWidget*>(children.at(i)); |
|
981 |
if (child) |
|
982 |
qt_x11_recreateNativeWidgetsRecursive(child); |
|
983 |
} |
|
984 |
} |
|
985 |
||
986 |
void QWidgetPrivate::x11UpdateIsOpaque() |
|
987 |
{ |
|
988 |
#ifndef QT_NO_XRENDER |
|
989 |
Q_Q(QWidget); |
|
990 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->testAttribute(Qt::WA_TranslucentBackground)) |
|
991 |
return; |
|
992 |
||
993 |
bool topLevel = (data.window_flags & Qt::Window); |
|
994 |
int screen = xinfo.screen(); |
|
995 |
if (topLevel && X11->use_xrender |
|
996 |
&& X11->argbVisuals[screen] && xinfo.depth() != 32) |
|
997 |
{ |
|
998 |
qt_x11_recreateNativeWidgetsRecursive(q); |
|
999 |
} |
|
1000 |
#endif |
|
1001 |
} |
|
1002 |
||
1003 |
/* |
|
1004 |
Returns true if the background is inherited; otherwise returns |
|
1005 |
false. |
|
1006 |
||
1007 |
Mainly used in the paintOnScreen case. |
|
1008 |
*/ |
|
1009 |
bool QWidgetPrivate::isBackgroundInherited() const |
|
1010 |
{ |
|
1011 |
Q_Q(const QWidget); |
|
1012 |
||
1013 |
// windows do not inherit their background |
|
1014 |
if (q->isWindow() || q->windowType() == Qt::SubWindow) |
|
1015 |
return false; |
|
1016 |
||
1017 |
if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent)) |
|
1018 |
return false; |
|
1019 |
||
1020 |
const QPalette &pal = q->palette(); |
|
1021 |
QPalette::ColorRole bg = q->backgroundRole(); |
|
1022 |
QBrush brush = pal.brush(bg); |
|
1023 |
||
1024 |
// non opaque brushes leaves us no choice, we must inherit |
|
1025 |
if (!q->autoFillBackground() || !brush.isOpaque()) |
|
1026 |
return true; |
|
1027 |
||
1028 |
if (brush.style() == Qt::SolidPattern) { |
|
1029 |
// the background is just a solid color. If there is no |
|
1030 |
// propagated contents, then we claim as performance |
|
1031 |
// optimization that it was not inheritet. This is the normal |
|
1032 |
// case in standard Windows or Motif style. |
|
1033 |
const QWidget *w = q->parentWidget(); |
|
1034 |
if (!w->d_func()->isBackgroundInherited()) |
|
1035 |
return false; |
|
1036 |
} |
|
1037 |
||
1038 |
return true; |
|
1039 |
} |
|
1040 |
||
1041 |
void QWidget::destroy(bool destroyWindow, bool destroySubWindows) |
|
1042 |
{ |
|
1043 |
Q_D(QWidget); |
|
1044 |
if (!isWindow() && parentWidget()) |
|
1045 |
parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); |
|
1046 |
d->deactivateWidgetCleanup(); |
|
1047 |
if (testAttribute(Qt::WA_WState_Created)) { |
|
1048 |
setAttribute(Qt::WA_WState_Created, false); |
|
1049 |
QObjectList childList = children(); |
|
1050 |
for (int i = 0; i < childList.size(); ++i) { // destroy all widget children |
|
1051 |
register QObject *obj = childList.at(i); |
|
1052 |
if (obj->isWidgetType()) |
|
1053 |
static_cast<QWidget*>(obj)->destroy(destroySubWindows, |
|
1054 |
destroySubWindows); |
|
1055 |
} |
|
1056 |
if (QWidgetPrivate::mouseGrabber == this) |
|
1057 |
releaseMouse(); |
|
1058 |
if (QWidgetPrivate::keyboardGrabber == this) |
|
1059 |
releaseKeyboard(); |
|
1060 |
if (isWindow()) |
|
1061 |
X11->deferred_map.removeAll(this); |
|
1062 |
if (isModal()) { |
|
1063 |
// just be sure we leave modal |
|
1064 |
QApplicationPrivate::leaveModal(this); |
|
1065 |
} |
|
1066 |
else if ((windowType() == Qt::Popup)) |
|
1067 |
qApp->d_func()->closePopup(this); |
|
1068 |
||
1069 |
#ifndef QT_NO_XRENDER |
|
1070 |
if (d->picture) { |
|
1071 |
if (destroyWindow) |
|
1072 |
XRenderFreePicture(X11->display, d->picture); |
|
1073 |
d->picture = 0; |
|
1074 |
} |
|
1075 |
#endif // QT_NO_XRENDER |
|
1076 |
||
1077 |
// delete the _NET_WM_USER_TIME_WINDOW |
|
1078 |
qt_net_remove_user_time(this); |
|
1079 |
||
1080 |
if ((windowType() == Qt::Desktop)) { |
|
1081 |
if (acceptDrops()) |
|
1082 |
X11->dndEnable(this, false); |
|
1083 |
} else { |
|
1084 |
if (isWindow()) |
|
1085 |
X11->dndEnable(this, false); |
|
1086 |
if (destroyWindow) |
|
1087 |
qt_XDestroyWindow(this, X11->display, data->winid); |
|
1088 |
} |
|
1089 |
QT_TRY { |
|
1090 |
d->setWinId(0); |
|
1091 |
} QT_CATCH (const std::bad_alloc &) { |
|
1092 |
// swallow - destructors must not throw |
|
1093 |
} |
|
1094 |
||
1095 |
extern void qPRCleanup(QWidget *widget); // from qapplication_x11.cpp |
|
1096 |
if (testAttribute(Qt::WA_WState_Reparented)) |
|
1097 |
qPRCleanup(this); |
|
1098 |
||
1099 |
if(d->ic) { |
|
1100 |
delete d->ic; |
|
1101 |
} else { |
|
1102 |
// release previous focus information participating with |
|
1103 |
// preedit preservation of qic |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1104 |
QInputContext *qic = QApplicationPrivate::inputContext; |
0 | 1105 |
if (qic) |
1106 |
qic->widgetDestroyed(this); |
|
1107 |
} |
|
1108 |
} |
|
1109 |
} |
|
1110 |
||
1111 |
void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) |
|
1112 |
{ |
|
1113 |
Q_Q(QWidget); |
|
1114 |
#ifdef ALIEN_DEBUG |
|
1115 |
qDebug() << "QWidgetPrivate::setParent_sys START" << q << "parent:" << parent; |
|
1116 |
#endif |
|
1117 |
QX11Info old_xinfo = xinfo; |
|
1118 |
if (parent && parent->windowType() == Qt::Desktop) { |
|
1119 |
// make sure the widget is created on the same screen as the |
|
1120 |
// programmer specified desktop widget |
|
1121 |
xinfo = parent->d_func()->xinfo; |
|
1122 |
parent = 0; |
|
1123 |
} |
|
1124 |
||
1125 |
QTLWExtra *topData = maybeTopData(); |
|
1126 |
bool wasCreated = q->testAttribute(Qt::WA_WState_Created); |
|
1127 |
if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) |
|
1128 |
q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); |
|
1129 |
extern void qPRCreate(const QWidget *, Window); |
|
1130 |
#ifndef QT_NO_CURSOR |
|
1131 |
QCursor oldcurs; |
|
1132 |
#endif |
|
1133 |
||
1134 |
// dnd unregister (we will register again below) |
|
1135 |
if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
1136 |
q->setAttribute(Qt::WA_DropSiteRegistered, false); |
|
1137 |
||
1138 |
// if we are a top then remove our dnd prop for now |
|
1139 |
// it will get rest later |
|
1140 |
if (q->isWindow() && wasCreated) |
|
1141 |
X11->dndEnable(q, false); |
|
1142 |
||
1143 |
if (topData) |
|
1144 |
qt_net_remove_user_time(q); |
|
1145 |
||
1146 |
// QWidget *oldparent = q->parentWidget(); |
|
1147 |
WId old_winid = wasCreated ? data.winid : 0; |
|
1148 |
if ((q->windowType() == Qt::Desktop)) |
|
1149 |
old_winid = 0; |
|
1150 |
setWinId(0); |
|
1151 |
||
1152 |
#ifndef QT_NO_XRENDER |
|
1153 |
if (picture) { |
|
1154 |
XRenderFreePicture(X11->display, picture); |
|
1155 |
picture = 0; |
|
1156 |
} |
|
1157 |
#endif |
|
1158 |
||
1159 |
// hide and reparent our own window away. Otherwise we might get |
|
1160 |
// destroyed when emitting the child remove event below. See QWorkspace. |
|
1161 |
if (wasCreated && old_winid) { |
|
1162 |
XUnmapWindow(X11->display, old_winid); |
|
1163 |
if (!old_xinfo.screen() != xinfo.screen()) |
|
1164 |
XReparentWindow(X11->display, old_winid, RootWindow(X11->display, xinfo.screen()), 0, 0); |
|
1165 |
} |
|
1166 |
if (topData) { |
|
1167 |
topData->parentWinId = 0; |
|
1168 |
// zero the frame strut and mark it dirty |
|
1169 |
topData->frameStrut.setCoords(0, 0, 0, 0); |
|
1170 |
||
1171 |
// reparenting from top-level, make sure show() works again |
|
1172 |
topData->waitingForMapNotify = 0; |
|
1173 |
topData->validWMState = 0; |
|
1174 |
} |
|
1175 |
data.fstrut_dirty = (!parent || (f & Qt::Window)); // toplevels get a dirty framestrut |
|
1176 |
||
1177 |
QObjectPrivate::setParent_helper(parent); |
|
1178 |
bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); |
|
1179 |
||
1180 |
data.window_flags = f; |
|
1181 |
q->setAttribute(Qt::WA_WState_Created, false); |
|
1182 |
q->setAttribute(Qt::WA_WState_Visible, false); |
|
1183 |
q->setAttribute(Qt::WA_WState_Hidden, false); |
|
1184 |
adjustFlags(data.window_flags, q); |
|
1185 |
// keep compatibility with previous versions, we need to preserve the created state |
|
1186 |
// (but we recreate the winId for the widget being reparented, again for compatibility) |
|
1187 |
if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created))) |
|
1188 |
createWinId(); |
|
1189 |
if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden) |
|
1190 |
q->setAttribute(Qt::WA_WState_Hidden); |
|
1191 |
q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); |
|
1192 |
||
1193 |
if (wasCreated) { |
|
1194 |
QObjectList chlist = q->children(); |
|
1195 |
for (int i = 0; i < chlist.size(); ++i) { // reparent children |
|
1196 |
QObject *obj = chlist.at(i); |
|
1197 |
if (obj->isWidgetType()) { |
|
1198 |
QWidget *w = (QWidget *)obj; |
|
1199 |
if (!w->testAttribute(Qt::WA_WState_Created)) |
|
1200 |
continue; |
|
1201 |
if (xinfo.screen() != w->d_func()->xinfo.screen()) { |
|
1202 |
// ### force setParent() to not shortcut out (because |
|
1203 |
// ### we're setting the parent to the current parent) |
|
1204 |
// ### setParent will add child back to the list |
|
1205 |
// ### of children so we need to make sure the |
|
1206 |
// ### widget won't be added twice. |
|
1207 |
w->d_func()->parent = 0; |
|
1208 |
this->children.removeOne(w); |
|
1209 |
w->setParent(q); |
|
1210 |
} else if (!w->isWindow()) { |
|
1211 |
w->d_func()->invalidateBuffer(w->rect()); |
|
1212 |
if (w->internalWinId()) { |
|
1213 |
if (w->testAttribute(Qt::WA_NativeWindow)) { |
|
1214 |
QWidget *nativeParentWidget = w->nativeParentWidget(); |
|
1215 |
// Qt::WA_NativeWindow ensures that we always have a nativeParentWidget |
|
1216 |
Q_ASSERT(nativeParentWidget != 0); |
|
1217 |
QPoint p = w->mapTo(nativeParentWidget, QPoint()); |
|
1218 |
XReparentWindow(X11->display, |
|
1219 |
w->internalWinId(), |
|
1220 |
nativeParentWidget->internalWinId(), |
|
1221 |
p.x(), p.y()); |
|
1222 |
} else { |
|
1223 |
w->d_func()->setParent_sys(q, w->data->window_flags); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
} else if (isTransient(w)) { |
|
1227 |
/* |
|
1228 |
when reparenting toplevel windows with toplevel-transient children, |
|
1229 |
we need to make sure that the window manager gets the updated |
|
1230 |
WM_TRANSIENT_FOR information... unfortunately, some window managers |
|
1231 |
don't handle changing WM_TRANSIENT_FOR before the toplevel window is |
|
1232 |
visible, so we unmap and remap all toplevel-transient children *after* |
|
1233 |
the toplevel parent has been mapped. thankfully, this is easy in Qt :) |
|
1234 |
||
1235 |
note that the WM_TRANSIENT_FOR hint is actually updated in |
|
1236 |
QWidgetPrivate::show_sys() |
|
1237 |
*/ |
|
1238 |
if (w->internalWinId()) |
|
1239 |
XUnmapWindow(X11->display, w->internalWinId()); |
|
1240 |
QApplication::postEvent(w, new QEvent(QEvent::ShowWindowRequest)); |
|
1241 |
} |
|
1242 |
} |
|
1243 |
} |
|
1244 |
qPRCreate(q, old_winid); |
|
1245 |
updateSystemBackground(); |
|
1246 |
||
1247 |
if (old_winid) { |
|
1248 |
Window *cmwret; |
|
1249 |
int count; |
|
1250 |
if (XGetWMColormapWindows(X11->display, old_winid, &cmwret, &count)) { |
|
1251 |
Window *cmw; |
|
1252 |
int cmw_size = sizeof(Window)*count; |
|
1253 |
cmw = new Window[count]; |
|
1254 |
memcpy((char *)cmw, (char *)cmwret, cmw_size); |
|
1255 |
XFree((char *)cmwret); |
|
1256 |
int i; |
|
1257 |
for (i=0; i<count; i++) { |
|
1258 |
if (cmw[i] == old_winid) { |
|
1259 |
cmw[i] = q->internalWinId(); |
|
1260 |
break; |
|
1261 |
} |
|
1262 |
} |
|
1263 |
int top_count; |
|
1264 |
if (XGetWMColormapWindows(X11->display, q->window()->internalWinId(), |
|
1265 |
&cmwret, &top_count)) |
|
1266 |
{ |
|
1267 |
Window *merged_cmw = new Window[count + top_count]; |
|
1268 |
memcpy((char *)merged_cmw, (char *)cmw, cmw_size); |
|
1269 |
memcpy((char *)merged_cmw + cmw_size, (char *)cmwret, sizeof(Window)*top_count); |
|
1270 |
delete [] cmw; |
|
1271 |
XFree((char *)cmwret); |
|
1272 |
cmw = merged_cmw; |
|
1273 |
count += top_count; |
|
1274 |
} |
|
1275 |
||
1276 |
XSetWMColormapWindows(X11->display, q->window()->internalWinId(), cmw, count); |
|
1277 |
delete [] cmw; |
|
1278 |
} |
|
1279 |
||
1280 |
qt_XDestroyWindow(q, X11->display, old_winid); |
|
1281 |
} |
|
1282 |
} |
|
1283 |
||
1284 |
// check if we need to register our dropsite |
|
1285 |
if (q->testAttribute(Qt::WA_AcceptDrops) |
|
1286 |
|| (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) { |
|
1287 |
q->setAttribute(Qt::WA_DropSiteRegistered, true); |
|
1288 |
} |
|
1289 |
#if !defined(QT_NO_IM) |
|
1290 |
ic = 0; |
|
1291 |
#endif |
|
1292 |
invalidateBuffer(q->rect()); |
|
1293 |
#ifdef ALIEN_DEBUG |
|
1294 |
qDebug() << "QWidgetPrivate::setParent_sys END" << q; |
|
1295 |
#endif |
|
1296 |
} |
|
1297 |
||
1298 |
||
1299 |
QPoint QWidget::mapToGlobal(const QPoint &pos) const |
|
1300 |
{ |
|
1301 |
Q_D(const QWidget); |
|
1302 |
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
|
1303 |
QPoint p = pos + data->crect.topLeft(); |
|
1304 |
//cannot trust that !isWindow() implies parentWidget() before create |
|
1305 |
return (isWindow() || !parentWidget()) ? p : parentWidget()->mapToGlobal(p); |
|
1306 |
} |
|
1307 |
int x, y; |
|
1308 |
Window child; |
|
1309 |
QPoint p = d->mapToWS(pos); |
|
1310 |
XTranslateCoordinates(X11->display, internalWinId(), |
|
1311 |
QApplication::desktop()->screen(d->xinfo.screen())->internalWinId(), |
|
1312 |
p.x(), p.y(), &x, &y, &child); |
|
1313 |
return QPoint(x, y); |
|
1314 |
} |
|
1315 |
||
1316 |
||
1317 |
QPoint QWidget::mapFromGlobal(const QPoint &pos) const |
|
1318 |
{ |
|
1319 |
Q_D(const QWidget); |
|
1320 |
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
|
1321 |
//cannot trust that !isWindow() implies parentWidget() before create |
|
1322 |
QPoint p = (isWindow() || !parentWidget()) ? pos : parentWidget()->mapFromGlobal(pos); |
|
1323 |
return p - data->crect.topLeft(); |
|
1324 |
} |
|
1325 |
int x, y; |
|
1326 |
Window child; |
|
1327 |
XTranslateCoordinates(X11->display, |
|
1328 |
QApplication::desktop()->screen(d->xinfo.screen())->internalWinId(), |
|
1329 |
internalWinId(), pos.x(), pos.y(), &x, &y, &child); |
|
1330 |
return d->mapFromWS(QPoint(x, y)); |
|
1331 |
} |
|
1332 |
||
1333 |
void QWidgetPrivate::updateSystemBackground() |
|
1334 |
{ |
|
1335 |
Q_Q(QWidget); |
|
1336 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->internalWinId()) |
|
1337 |
return; |
|
1338 |
QBrush brush = q->palette().brush(QPalette::Active, q->backgroundRole()); |
|
1339 |
Qt::WindowType type = q->windowType(); |
|
1340 |
if (brush.style() == Qt::NoBrush |
|
1341 |
|| q->testAttribute(Qt::WA_NoSystemBackground) |
|
1342 |
|| q->testAttribute(Qt::WA_UpdatesDisabled) |
|
1343 |
|| type == Qt::Popup || type == Qt::ToolTip |
|
1344 |
) |
|
1345 |
XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone); |
|
1346 |
else if (brush.style() == Qt::SolidPattern && brush.isOpaque()) |
|
1347 |
XSetWindowBackground(X11->display, q->internalWinId(), |
|
1348 |
QColormap::instance(xinfo.screen()).pixel(brush.color())); |
|
1349 |
else if (isBackgroundInherited()) |
|
1350 |
XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), ParentRelative); |
|
1351 |
else if (brush.style() == Qt::TexturePattern) { |
|
1352 |
extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp |
|
1353 |
XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), |
|
1354 |
static_cast<QX11PixmapData*>(qt_toX11Pixmap(brush.texture()).data.data())->x11ConvertToDefaultDepth()); |
|
1355 |
} else |
|
1356 |
XSetWindowBackground(X11->display, q->internalWinId(), |
|
1357 |
QColormap::instance(xinfo.screen()).pixel(brush.color())); |
|
1358 |
} |
|
1359 |
||
1360 |
#ifndef QT_NO_CURSOR |
|
1361 |
void QWidgetPrivate::setCursor_sys(const QCursor &) |
|
1362 |
{ |
|
1363 |
Q_Q(QWidget); |
|
1364 |
qt_x11_enforce_cursor(q); |
|
1365 |
XFlush(X11->display); |
|
1366 |
} |
|
1367 |
||
1368 |
void QWidgetPrivate::unsetCursor_sys() |
|
1369 |
{ |
|
1370 |
Q_Q(QWidget); |
|
1371 |
qt_x11_enforce_cursor(q); |
|
1372 |
XFlush(X11->display); |
|
1373 |
} |
|
1374 |
#endif |
|
1375 |
||
1376 |
static XTextProperty* |
|
1377 |
qstring_to_xtp(const QString& s) |
|
1378 |
{ |
|
1379 |
static XTextProperty tp = { 0, 0, 0, 0 }; |
|
1380 |
static bool free_prop = true; // we can't free tp.value in case it references |
|
1381 |
// the data of the static QCString below. |
|
1382 |
if (tp.value) { |
|
1383 |
if (free_prop) |
|
1384 |
XFree(tp.value); |
|
1385 |
tp.value = 0; |
|
1386 |
free_prop = true; |
|
1387 |
} |
|
1388 |
||
1389 |
static const QTextCodec* mapper = QTextCodec::codecForLocale(); |
|
1390 |
int errCode = 0; |
|
1391 |
if (mapper) { |
|
1392 |
QByteArray mapped = mapper->fromUnicode(s); |
|
1393 |
char* tl[2]; |
|
1394 |
tl[0] = mapped.data(); |
|
1395 |
tl[1] = 0; |
|
1396 |
errCode = XmbTextListToTextProperty(X11->display, tl, 1, XStdICCTextStyle, &tp); |
|
1397 |
#if defined(QT_DEBUG) |
|
1398 |
if (errCode < 0) |
|
1399 |
qDebug("qstring_to_xtp result code %d", errCode); |
|
1400 |
#endif |
|
1401 |
} |
|
1402 |
if (!mapper || errCode < 0) { |
|
1403 |
static QByteArray qcs; |
|
1404 |
qcs = s.toAscii(); |
|
1405 |
tp.value = (uchar*)qcs.data(); |
|
1406 |
tp.encoding = XA_STRING; |
|
1407 |
tp.format = 8; |
|
1408 |
tp.nitems = qcs.length(); |
|
1409 |
free_prop = false; |
|
1410 |
} |
|
1411 |
||
1412 |
// ### If we knew WM could understand unicode, we could use |
|
1413 |
// ### a much simpler, cheaper encoding... |
|
1414 |
/* |
|
1415 |
tp.value = (XChar2b*)s.unicode(); |
|
1416 |
tp.encoding = XA_UNICODE; // wish |
|
1417 |
tp.format = 16; |
|
1418 |
tp.nitems = s.length(); |
|
1419 |
*/ |
|
1420 |
||
1421 |
return &tp; |
|
1422 |
} |
|
1423 |
||
1424 |
void QWidgetPrivate::setWindowTitle_sys(const QString &caption) |
|
1425 |
{ |
|
1426 |
Q_Q(QWidget); |
|
1427 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
1428 |
if (!q->internalWinId()) |
|
1429 |
return; |
|
1430 |
XSetWMName(X11->display, q->internalWinId(), qstring_to_xtp(caption)); |
|
1431 |
||
1432 |
QByteArray net_wm_name = caption.toUtf8(); |
|
1433 |
XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_NAME), ATOM(UTF8_STRING), 8, |
|
1434 |
PropModeReplace, (unsigned char *)net_wm_name.data(), net_wm_name.size()); |
|
1435 |
} |
|
1436 |
||
1437 |
void QWidgetPrivate::setWindowIcon_sys(bool forceReset) |
|
1438 |
{ |
|
1439 |
Q_Q(QWidget); |
|
1440 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
1441 |
return; |
|
1442 |
QTLWExtra *topData = this->topData(); |
|
1443 |
if (topData->iconPixmap && !forceReset) |
|
1444 |
// already been set |
|
1445 |
return; |
|
1446 |
||
1447 |
// preparing images to set the _NET_WM_ICON property |
|
1448 |
QIcon icon = q->windowIcon(); |
|
1449 |
QVector<long> icon_data; |
|
1450 |
Qt::HANDLE pixmap_handle = 0; |
|
1451 |
if (!icon.isNull()) { |
|
1452 |
QList<QSize> availableSizes = icon.availableSizes(); |
|
1453 |
if(availableSizes.isEmpty()) { |
|
1454 |
// try to use default sizes since the icon can be a scalable image like svg. |
|
1455 |
availableSizes.push_back(QSize(16,16)); |
|
1456 |
availableSizes.push_back(QSize(32,32)); |
|
1457 |
availableSizes.push_back(QSize(64,64)); |
|
1458 |
availableSizes.push_back(QSize(128,128)); |
|
1459 |
} |
|
1460 |
for(int i = 0; i < availableSizes.size(); ++i) { |
|
1461 |
QSize size = availableSizes.at(i); |
|
1462 |
QPixmap pixmap = icon.pixmap(size); |
|
1463 |
if (!pixmap.isNull()) { |
|
1464 |
QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
|
1465 |
int pos = icon_data.size(); |
|
1466 |
icon_data.resize(pos + 2 + image.width()*image.height()); |
|
1467 |
icon_data[pos++] = image.width(); |
|
1468 |
icon_data[pos++] = image.height(); |
|
1469 |
if (sizeof(long) == sizeof(quint32)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1470 |
memcpy(icon_data.data() + pos, image.scanLine(0), image.byteCount()); |
0 | 1471 |
} else { |
1472 |
for (int y = 0; y < image.height(); ++y) { |
|
1473 |
uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y)); |
|
1474 |
for (int x = 0; x < image.width(); ++x) |
|
1475 |
icon_data[pos + y*image.width() + x] = scanLine[x]; |
|
1476 |
} |
|
1477 |
} |
|
1478 |
} |
|
1479 |
} |
|
1480 |
if (!icon_data.isEmpty()) { |
|
1481 |
extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); |
|
1482 |
/* |
|
1483 |
if the app is running on an unknown desktop, or it is not |
|
1484 |
using the default visual, convert the icon to 1bpp as stated |
|
1485 |
in the ICCCM section 4.1.2.4; otherwise, create the icon pixmap |
|
1486 |
in the default depth (even though this violates the ICCCM) |
|
1487 |
*/ |
|
1488 |
if (X11->desktopEnvironment == DE_UNKNOWN |
|
1489 |
|| !QX11Info::appDefaultVisual(xinfo.screen()) |
|
1490 |
|| !QX11Info::appDefaultColormap(xinfo.screen())) { |
|
1491 |
// unknown DE or non-default visual/colormap, use 1bpp bitmap |
|
1492 |
if (!forceReset || !topData->iconPixmap) |
|
1493 |
topData->iconPixmap = new QBitmap(qt_toX11Pixmap(icon.pixmap(QSize(64,64)))); |
|
1494 |
pixmap_handle = topData->iconPixmap->handle(); |
|
1495 |
} else { |
|
1496 |
// default depth, use a normal pixmap (even though this |
|
1497 |
// violates the ICCCM), since this works on all DEs known to Qt |
|
1498 |
if (!forceReset || !topData->iconPixmap) |
|
1499 |
topData->iconPixmap = new QPixmap(qt_toX11Pixmap(icon.pixmap(QSize(64,64)))); |
|
1500 |
pixmap_handle = static_cast<QX11PixmapData*>(topData->iconPixmap->data.data())->x11ConvertToDefaultDepth(); |
|
1501 |
} |
|
1502 |
} |
|
1503 |
} |
|
1504 |
||
1505 |
if (!q->internalWinId()) |
|
1506 |
return; |
|
1507 |
||
1508 |
if (!icon_data.isEmpty()) { |
|
1509 |
XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON), XA_CARDINAL, 32, |
|
1510 |
PropModeReplace, (unsigned char *) icon_data.data(), |
|
1511 |
icon_data.size()); |
|
1512 |
} else { |
|
1513 |
XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON)); |
|
1514 |
} |
|
1515 |
||
1516 |
XWMHints *h = XGetWMHints(X11->display, q->internalWinId()); |
|
1517 |
XWMHints wm_hints; |
|
1518 |
if (!h) { |
|
1519 |
memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy |
|
1520 |
h = &wm_hints; |
|
1521 |
} |
|
1522 |
||
1523 |
if (pixmap_handle) { |
|
1524 |
h->icon_pixmap = pixmap_handle; |
|
1525 |
h->flags |= IconPixmapHint; |
|
1526 |
} else { |
|
1527 |
h->icon_pixmap = 0; |
|
1528 |
h->flags &= ~(IconPixmapHint | IconMaskHint); |
|
1529 |
} |
|
1530 |
||
1531 |
XSetWMHints(X11->display, q->internalWinId(), h); |
|
1532 |
if (h != &wm_hints) |
|
1533 |
XFree((char *)h); |
|
1534 |
} |
|
1535 |
||
1536 |
void QWidgetPrivate::setWindowIconText_sys(const QString &iconText) |
|
1537 |
{ |
|
1538 |
Q_Q(QWidget); |
|
1539 |
if (!q->internalWinId()) |
|
1540 |
return; |
|
1541 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
1542 |
XSetWMIconName(X11->display, q->internalWinId(), qstring_to_xtp(iconText)); |
|
1543 |
||
1544 |
QByteArray icon_name = iconText.toUtf8(); |
|
1545 |
XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON_NAME), ATOM(UTF8_STRING), 8, |
|
1546 |
PropModeReplace, (unsigned char *) icon_name.constData(), icon_name.size()); |
|
1547 |
} |
|
1548 |
||
1549 |
||
1550 |
void QWidget::grabMouse() |
|
1551 |
{ |
|
1552 |
if (isVisible() && !qt_nograb()) { |
|
1553 |
if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
|
1554 |
QWidgetPrivate::mouseGrabber->releaseMouse(); |
|
1555 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
1556 |
#ifndef QT_NO_DEBUG |
|
1557 |
int status = |
|
1558 |
#endif |
|
1559 |
XGrabPointer(X11->display, effectiveWinId(), False, |
|
1560 |
(uint)(ButtonPressMask | ButtonReleaseMask | |
|
1561 |
PointerMotionMask | EnterWindowMask | |
|
1562 |
LeaveWindowMask), |
|
1563 |
GrabModeAsync, GrabModeAsync, |
|
1564 |
XNone, XNone, X11->time); |
|
1565 |
#ifndef QT_NO_DEBUG |
|
1566 |
if (status) { |
|
1567 |
const char *s = |
|
1568 |
status == GrabNotViewable ? "\"GrabNotViewable\"" : |
|
1569 |
status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" : |
|
1570 |
status == GrabFrozen ? "\"GrabFrozen\"" : |
|
1571 |
status == GrabInvalidTime ? "\"GrabInvalidTime\"" : |
|
1572 |
"<?>"; |
|
1573 |
qWarning("QWidget::grabMouse: Failed with %s", s); |
|
1574 |
} |
|
1575 |
#endif |
|
1576 |
QWidgetPrivate::mouseGrabber = this; |
|
1577 |
} |
|
1578 |
} |
|
1579 |
||
1580 |
||
1581 |
#ifndef QT_NO_CURSOR |
|
1582 |
void QWidget::grabMouse(const QCursor &cursor) |
|
1583 |
{ |
|
1584 |
if (!qt_nograb()) { |
|
1585 |
if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) |
|
1586 |
QWidgetPrivate::mouseGrabber->releaseMouse(); |
|
1587 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
1588 |
#ifndef QT_NO_DEBUG |
|
1589 |
int status = |
|
1590 |
#endif |
|
1591 |
XGrabPointer(X11->display, effectiveWinId(), False, |
|
1592 |
(uint)(ButtonPressMask | ButtonReleaseMask | |
|
1593 |
PointerMotionMask | EnterWindowMask | LeaveWindowMask), |
|
1594 |
GrabModeAsync, GrabModeAsync, |
|
1595 |
XNone, cursor.handle(), X11->time); |
|
1596 |
#ifndef QT_NO_DEBUG |
|
1597 |
if (status) { |
|
1598 |
const char *s = |
|
1599 |
status == GrabNotViewable ? "\"GrabNotViewable\"" : |
|
1600 |
status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" : |
|
1601 |
status == GrabFrozen ? "\"GrabFrozen\"" : |
|
1602 |
status == GrabInvalidTime ? "\"GrabInvalidTime\"" : |
|
1603 |
"<?>"; |
|
1604 |
qWarning("QWidget::grabMouse: Failed with %s", s); |
|
1605 |
} |
|
1606 |
#endif |
|
1607 |
QWidgetPrivate::mouseGrabber = this; |
|
1608 |
} |
|
1609 |
} |
|
1610 |
#endif |
|
1611 |
||
1612 |
||
1613 |
void QWidget::releaseMouse() |
|
1614 |
{ |
|
1615 |
if (!qt_nograb() && QWidgetPrivate::mouseGrabber == this) { |
|
1616 |
XUngrabPointer(X11->display, X11->time); |
|
1617 |
XFlush(X11->display); |
|
1618 |
QWidgetPrivate::mouseGrabber = 0; |
|
1619 |
} |
|
1620 |
} |
|
1621 |
||
1622 |
||
1623 |
void QWidget::grabKeyboard() |
|
1624 |
{ |
|
1625 |
if (!qt_nograb()) { |
|
1626 |
if (QWidgetPrivate::keyboardGrabber && QWidgetPrivate::keyboardGrabber != this) |
|
1627 |
QWidgetPrivate::keyboardGrabber->releaseKeyboard(); |
|
1628 |
XGrabKeyboard(X11->display, effectiveWinId(), False, GrabModeAsync, GrabModeAsync, |
|
1629 |
X11->time); |
|
1630 |
QWidgetPrivate::keyboardGrabber = this; |
|
1631 |
} |
|
1632 |
} |
|
1633 |
||
1634 |
||
1635 |
void QWidget::releaseKeyboard() |
|
1636 |
{ |
|
1637 |
if (!qt_nograb() && QWidgetPrivate::keyboardGrabber == this) { |
|
1638 |
XUngrabKeyboard(X11->display, X11->time); |
|
1639 |
QWidgetPrivate::keyboardGrabber = 0; |
|
1640 |
} |
|
1641 |
} |
|
1642 |
||
1643 |
||
1644 |
QWidget *QWidget::mouseGrabber() |
|
1645 |
{ |
|
1646 |
return QWidgetPrivate::mouseGrabber; |
|
1647 |
} |
|
1648 |
||
1649 |
||
1650 |
QWidget *QWidget::keyboardGrabber() |
|
1651 |
{ |
|
1652 |
return QWidgetPrivate::keyboardGrabber; |
|
1653 |
} |
|
1654 |
||
1655 |
void QWidget::activateWindow() |
|
1656 |
{ |
|
1657 |
QWidget *tlw = window(); |
|
1658 |
if (tlw->isVisible() && !tlw->d_func()->topData()->embedded && !X11->deferred_map.contains(tlw)) { |
|
1659 |
if (X11->userTime == 0) |
|
1660 |
X11->userTime = X11->time; |
|
1661 |
qt_net_update_user_time(tlw, X11->userTime); |
|
1662 |
XSetInputFocus(X11->display, tlw->internalWinId(), XRevertToParent, X11->time); |
|
1663 |
} |
|
1664 |
} |
|
1665 |
||
1666 |
void QWidget::setWindowState(Qt::WindowStates newstate) |
|
1667 |
{ |
|
1668 |
Q_D(QWidget); |
|
1669 |
bool needShow = false; |
|
1670 |
Qt::WindowStates oldstate = windowState(); |
|
1671 |
if (oldstate == newstate) |
|
1672 |
return; |
|
1673 |
if (isWindow()) { |
|
1674 |
// Ensure the initial size is valid, since we store it as normalGeometry below. |
|
1675 |
if (!testAttribute(Qt::WA_Resized) && !isVisible()) |
|
1676 |
adjustSize(); |
|
1677 |
||
1678 |
QTLWExtra *top = d->topData(); |
|
1679 |
||
1680 |
if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) { |
|
1681 |
if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)) |
|
1682 |
&& X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))) { |
|
1683 |
if ((newstate & Qt::WindowMaximized) && !(oldstate & Qt::WindowFullScreen)) |
|
1684 |
top->normalGeometry = geometry(); |
|
1685 |
qt_change_net_wm_state(this, (newstate & Qt::WindowMaximized), |
|
1686 |
ATOM(_NET_WM_STATE_MAXIMIZED_HORZ), |
|
1687 |
ATOM(_NET_WM_STATE_MAXIMIZED_VERT)); |
|
1688 |
} else if (! (newstate & Qt::WindowFullScreen)) { |
|
1689 |
if (newstate & Qt::WindowMaximized) { |
|
1690 |
// save original geometry |
|
1691 |
const QRect normalGeometry = geometry(); |
|
1692 |
||
1693 |
if (isVisible()) { |
|
1694 |
data->fstrut_dirty = true; |
|
1695 |
const QRect maxRect = QApplication::desktop()->availableGeometry(this); |
|
1696 |
const QRect r = top->normalGeometry; |
|
1697 |
const QRect fs = d->frameStrut(); |
|
1698 |
setGeometry(maxRect.x() + fs.left(), |
|
1699 |
maxRect.y() + fs.top(), |
|
1700 |
maxRect.width() - fs.left() - fs.right(), |
|
1701 |
maxRect.height() - fs.top() - fs.bottom()); |
|
1702 |
top->normalGeometry = r; |
|
1703 |
} |
|
1704 |
||
1705 |
if (top->normalGeometry.width() < 0) |
|
1706 |
top->normalGeometry = normalGeometry; |
|
1707 |
} else { |
|
1708 |
// restore original geometry |
|
1709 |
setGeometry(top->normalGeometry); |
|
1710 |
} |
|
1711 |
} |
|
1712 |
} |
|
1713 |
||
1714 |
if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) { |
|
1715 |
if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) { |
|
1716 |
if (newstate & Qt::WindowFullScreen) { |
|
1717 |
top->normalGeometry = geometry(); |
|
1718 |
top->fullScreenOffset = d->frameStrut().topLeft(); |
|
1719 |
} |
|
1720 |
qt_change_net_wm_state(this, (newstate & Qt::WindowFullScreen), |
|
1721 |
ATOM(_NET_WM_STATE_FULLSCREEN)); |
|
1722 |
} else { |
|
1723 |
needShow = isVisible(); |
|
1724 |
||
1725 |
if (newstate & Qt::WindowFullScreen) { |
|
1726 |
data->fstrut_dirty = true; |
|
1727 |
const QRect normalGeometry = geometry(); |
|
1728 |
const QPoint fullScreenOffset = d->frameStrut().topLeft(); |
|
1729 |
||
1730 |
top->savedFlags = windowFlags(); |
|
1731 |
setParent(0, Qt::Window | Qt::FramelessWindowHint); |
|
1732 |
const QRect r = top->normalGeometry; |
|
1733 |
setGeometry(qApp->desktop()->screenGeometry(this)); |
|
1734 |
top->normalGeometry = r; |
|
1735 |
||
1736 |
if (top->normalGeometry.width() < 0) { |
|
1737 |
top->normalGeometry = normalGeometry; |
|
1738 |
top->fullScreenOffset = fullScreenOffset; |
|
1739 |
} |
|
1740 |
} else { |
|
1741 |
setParent(0, top->savedFlags); |
|
1742 |
||
1743 |
if (newstate & Qt::WindowMaximized) { |
|
1744 |
// from fullscreen to maximized |
|
1745 |
data->fstrut_dirty = true; |
|
1746 |
const QRect maxRect = QApplication::desktop()->availableGeometry(this); |
|
1747 |
const QRect r = top->normalGeometry; |
|
1748 |
const QRect fs = d->frameStrut(); |
|
1749 |
setGeometry(maxRect.x() + fs.left(), |
|
1750 |
maxRect.y() + fs.top(), |
|
1751 |
maxRect.width() - fs.left() - fs.right(), |
|
1752 |
maxRect.height() - fs.top() - fs.bottom()); |
|
1753 |
top->normalGeometry = r; |
|
1754 |
} else { |
|
1755 |
// restore original geometry |
|
1756 |
setGeometry(top->normalGeometry.adjusted(-top->fullScreenOffset.x(), |
|
1757 |
-top->fullScreenOffset.y(), |
|
1758 |
-top->fullScreenOffset.x(), |
|
1759 |
-top->fullScreenOffset.y())); |
|
1760 |
} |
|
1761 |
} |
|
1762 |
} |
|
1763 |
} |
|
1764 |
||
1765 |
createWinId(); |
|
1766 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
1767 |
if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) { |
|
1768 |
if (isVisible()) { |
|
1769 |
if (newstate & Qt::WindowMinimized) { |
|
1770 |
XEvent e; |
|
1771 |
e.xclient.type = ClientMessage; |
|
1772 |
e.xclient.message_type = ATOM(WM_CHANGE_STATE); |
|
1773 |
e.xclient.display = X11->display; |
|
1774 |
e.xclient.window = data->winid; |
|
1775 |
e.xclient.format = 32; |
|
1776 |
e.xclient.data.l[0] = IconicState; |
|
1777 |
e.xclient.data.l[1] = 0; |
|
1778 |
e.xclient.data.l[2] = 0; |
|
1779 |
e.xclient.data.l[3] = 0; |
|
1780 |
e.xclient.data.l[4] = 0; |
|
1781 |
XSendEvent(X11->display, |
|
1782 |
RootWindow(X11->display,d->xinfo.screen()), |
|
1783 |
False, (SubstructureNotifyMask|SubstructureRedirectMask), &e); |
|
1784 |
} else { |
|
1785 |
setAttribute(Qt::WA_Mapped); |
|
1786 |
XMapWindow(X11->display, effectiveWinId()); |
|
1787 |
} |
|
1788 |
} |
|
1789 |
||
1790 |
needShow = false; |
|
1791 |
} |
|
1792 |
} |
|
1793 |
||
1794 |
data->window_state = newstate; |
|
1795 |
||
1796 |
if (needShow) |
|
1797 |
show(); |
|
1798 |
||
1799 |
if (newstate & Qt::WindowActive) |
|
1800 |
activateWindow(); |
|
1801 |
||
1802 |
QWindowStateChangeEvent e(oldstate); |
|
1803 |
QApplication::sendEvent(this, &e); |
|
1804 |
} |
|
1805 |
||
1806 |
/*! |
|
1807 |
\internal |
|
1808 |
Platform-specific part of QWidget::show(). |
|
1809 |
*/ |
|
1810 |
||
1811 |
void QWidgetPrivate::show_sys() |
|
1812 |
{ |
|
1813 |
Q_Q(QWidget); |
|
1814 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
1815 |
||
1816 |
if (q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
1817 |
invalidateBuffer(q->rect()); |
|
1818 |
q->setAttribute(Qt::WA_Mapped); |
|
1819 |
if (QTLWExtra *tlwExtra = maybeTopData()) |
|
1820 |
tlwExtra->waitingForMapNotify = 0; |
|
1821 |
return; |
|
1822 |
} |
|
1823 |
||
1824 |
if (q->isWindow()) { |
|
1825 |
XWMHints *h = XGetWMHints(X11->display, q->internalWinId()); |
|
1826 |
XWMHints wm_hints; |
|
1827 |
bool got_hints = h != 0; |
|
1828 |
if (!got_hints) { |
|
1829 |
memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy |
|
1830 |
h = &wm_hints; |
|
1831 |
} |
|
1832 |
h->initial_state = q->isMinimized() ? IconicState : NormalState; |
|
1833 |
h->flags |= StateHint; |
|
1834 |
XSetWMHints(X11->display, q->internalWinId(), h); |
|
1835 |
if (got_hints) |
|
1836 |
XFree((char *)h); |
|
1837 |
||
1838 |
// update WM_NORMAL_HINTS |
|
1839 |
do_size_hints(q, extra); |
|
1840 |
||
1841 |
// udpate WM_TRANSIENT_FOR |
|
1842 |
if (isTransient(q)) { |
|
1843 |
QWidget *p = q->parentWidget(); |
|
1844 |
||
1845 |
#ifndef QT_NO_MENU |
|
1846 |
// hackish ... try to find the main window related to this QMenu |
|
1847 |
if (qobject_cast<QMenu *>(q)) { |
|
1848 |
p = static_cast<QMenuPrivate*>(this)->causedPopup.widget; |
|
1849 |
if (!p) |
|
1850 |
p = q->parentWidget(); |
|
1851 |
if (!p) |
|
1852 |
p = QApplication::widgetAt(q->pos()); |
|
1853 |
if (!p) |
|
1854 |
p = qApp->activeWindow(); |
|
1855 |
} |
|
1856 |
#endif |
|
1857 |
if (p) |
|
1858 |
p = p->window(); |
|
1859 |
if (p) { |
|
1860 |
// transient for window |
|
1861 |
XSetTransientForHint(X11->display, q->internalWinId(), p->internalWinId()); |
|
1862 |
} else { |
|
1863 |
// transient for group |
|
1864 |
XSetTransientForHint(X11->display, q->internalWinId(), X11->wm_client_leader); |
|
1865 |
} |
|
1866 |
} |
|
1867 |
||
1868 |
// update _MOTIF_WM_HINTS |
|
1869 |
QtMWMHints mwmhints = GetMWMHints(X11->display, q->internalWinId()); |
|
1870 |
||
1871 |
if (data.window_modality != Qt::NonModal) { |
|
1872 |
switch (data.window_modality) { |
|
1873 |
case Qt::WindowModal: |
|
1874 |
mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL; |
|
1875 |
break; |
|
1876 |
case Qt::ApplicationModal: |
|
1877 |
default: |
|
1878 |
mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL; |
|
1879 |
break; |
|
1880 |
} |
|
1881 |
mwmhints.flags |= MWM_HINTS_INPUT_MODE; |
|
1882 |
} else { |
|
1883 |
mwmhints.input_mode = MWM_INPUT_MODELESS; |
|
1884 |
mwmhints.flags &= ~MWM_HINTS_INPUT_MODE; |
|
1885 |
} |
|
1886 |
||
1887 |
if (q->minimumSize() == q->maximumSize()) { |
|
1888 |
// fixed size, remove the resize handle (since mwm/dtwm |
|
1889 |
// isn't smart enough to do it itself) |
|
1890 |
mwmhints.flags |= MWM_HINTS_FUNCTIONS; |
|
1891 |
if (mwmhints.functions == MWM_FUNC_ALL) { |
|
1892 |
mwmhints.functions = MWM_FUNC_MOVE; |
|
1893 |
} else { |
|
1894 |
mwmhints.functions &= ~MWM_FUNC_RESIZE; |
|
1895 |
} |
|
1896 |
||
1897 |
if (mwmhints.decorations == MWM_DECOR_ALL) { |
|
1898 |
mwmhints.flags |= MWM_HINTS_DECORATIONS; |
|
1899 |
mwmhints.decorations = (MWM_DECOR_BORDER |
|
1900 |
| MWM_DECOR_TITLE |
|
1901 |
| MWM_DECOR_MENU); |
|
1902 |
} else { |
|
1903 |
mwmhints.decorations &= ~MWM_DECOR_RESIZEH; |
|
1904 |
} |
|
1905 |
||
1906 |
if (q->windowFlags() & Qt::WindowMinimizeButtonHint) { |
|
1907 |
mwmhints.flags |= MWM_HINTS_DECORATIONS; |
|
1908 |
mwmhints.decorations |= MWM_DECOR_MINIMIZE; |
|
1909 |
mwmhints.functions |= MWM_FUNC_MINIMIZE; |
|
1910 |
} |
|
1911 |
if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { |
|
1912 |
mwmhints.flags |= MWM_HINTS_DECORATIONS; |
|
1913 |
mwmhints.decorations |= MWM_DECOR_MAXIMIZE; |
|
1914 |
mwmhints.functions |= MWM_FUNC_MAXIMIZE; |
|
1915 |
} |
|
1916 |
if (q->windowFlags() & Qt::WindowCloseButtonHint) |
|
1917 |
mwmhints.functions |= MWM_FUNC_CLOSE; |
|
1918 |
} |
|
1919 |
||
1920 |
SetMWMHints(X11->display, q->internalWinId(), mwmhints); |
|
1921 |
||
1922 |
// update _NET_WM_STATE |
|
1923 |
QVector<Atom> netWmState = getNetWmState(q); |
|
1924 |
||
1925 |
Qt::WindowFlags flags = q->windowFlags(); |
|
1926 |
if (flags & Qt::WindowStaysOnTopHint) { |
|
1927 |
if (flags & Qt::WindowStaysOnBottomHint) |
|
1928 |
qWarning() << "QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time"; |
|
1929 |
netWmState.append(ATOM(_NET_WM_STATE_ABOVE)); |
|
1930 |
netWmState.append(ATOM(_NET_WM_STATE_STAYS_ON_TOP)); |
|
1931 |
} else if (flags & Qt::WindowStaysOnBottomHint) { |
|
1932 |
netWmState.append(ATOM(_NET_WM_STATE_BELOW)); |
|
1933 |
} |
|
1934 |
if (q->isFullScreen()) { |
|
1935 |
netWmState.append(ATOM(_NET_WM_STATE_FULLSCREEN)); |
|
1936 |
} |
|
1937 |
if (q->isMaximized()) { |
|
1938 |
netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)); |
|
1939 |
netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)); |
|
1940 |
} |
|
1941 |
if (data.window_modality != Qt::NonModal) { |
|
1942 |
netWmState.append(ATOM(_NET_WM_STATE_MODAL)); |
|
1943 |
} |
|
1944 |
||
1945 |
if (!netWmState.isEmpty()) { |
|
1946 |
XChangeProperty(X11->display, q->internalWinId(), |
|
1947 |
ATOM(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace, |
|
1948 |
(unsigned char *) netWmState.data(), netWmState.size()); |
|
1949 |
} else { |
|
1950 |
XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_STATE)); |
|
1951 |
} |
|
1952 |
||
1953 |
// set _NET_WM_USER_TIME |
|
1954 |
Time userTime = X11->userTime; |
|
1955 |
bool setUserTime = false; |
|
1956 |
if (q->testAttribute(Qt::WA_ShowWithoutActivating)) { |
|
1957 |
userTime = 0; |
|
1958 |
setUserTime = true; |
|
1959 |
} else if (userTime != CurrentTime) { |
|
1960 |
setUserTime = true; |
|
1961 |
} |
|
1962 |
if (setUserTime) |
|
1963 |
qt_net_update_user_time(q, userTime); |
|
1964 |
||
1965 |
#ifndef QT_NO_XSYNC |
|
1966 |
if (!topData()->syncUpdateCounter) { |
|
1967 |
XSyncValue value; |
|
1968 |
XSyncIntToValue(&value, 0); |
|
1969 |
topData()->syncUpdateCounter = XSyncCreateCounter(X11->display, value); |
|
1970 |
||
1971 |
XChangeProperty(X11->display, q->internalWinId(), |
|
1972 |
ATOM(_NET_WM_SYNC_REQUEST_COUNTER), |
|
1973 |
XA_CARDINAL, |
|
1974 |
32, PropModeReplace, |
|
1975 |
(uchar *) &topData()->syncUpdateCounter, 1); |
|
1976 |
||
1977 |
topData()->newCounterValueHi = 0; |
|
1978 |
topData()->newCounterValueLo = 0; |
|
1979 |
} |
|
1980 |
#endif |
|
1981 |
||
1982 |
if (!topData()->embedded |
|
1983 |
&& (topData()->validWMState || topData()->waitingForMapNotify) |
|
1984 |
&& !q->isMinimized()) { |
|
1985 |
X11->deferred_map.append(q); |
|
1986 |
return; |
|
1987 |
} |
|
1988 |
||
1989 |
if (q->isMaximized() && !q->isFullScreen() |
|
1990 |
&& !(X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)) |
|
1991 |
&& X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)))) { |
|
1992 |
XMapWindow(X11->display, q->internalWinId()); |
|
1993 |
data.fstrut_dirty = true; |
|
1994 |
qt_x11_wait_for_window_manager(q); |
|
1995 |
||
1996 |
// if the wm was not smart enough to adjust our size, do that manually |
|
1997 |
QRect maxRect = QApplication::desktop()->availableGeometry(q); |
|
1998 |
||
1999 |
QTLWExtra *top = topData(); |
|
2000 |
QRect normalRect = top->normalGeometry; |
|
2001 |
const QRect fs = frameStrut(); |
|
2002 |
||
2003 |
q->setGeometry(maxRect.x() + fs.left(), |
|
2004 |
maxRect.y() + fs.top(), |
|
2005 |
maxRect.width() - fs.left() - fs.right(), |
|
2006 |
maxRect.height() - fs.top() - fs.bottom()); |
|
2007 |
||
2008 |
// restore the original normalGeometry |
|
2009 |
top->normalGeometry = normalRect; |
|
2010 |
// internalSetGeometry() clears the maximized flag... make sure we set it back |
|
2011 |
data.window_state = data.window_state | Qt::WindowMaximized; |
|
2012 |
q->setAttribute(Qt::WA_Mapped); |
|
2013 |
return; |
|
2014 |
} |
|
2015 |
||
2016 |
if (q->isFullScreen() && !X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) { |
|
2017 |
XMapWindow(X11->display, q->internalWinId()); |
|
2018 |
qt_x11_wait_for_window_manager(q); |
|
2019 |
q->setAttribute(Qt::WA_Mapped); |
|
2020 |
return; |
|
2021 |
} |
|
2022 |
} |
|
2023 |
||
2024 |
invalidateBuffer(q->rect()); |
|
2025 |
||
2026 |
if (q->testAttribute(Qt::WA_OutsideWSRange)) |
|
2027 |
return; |
|
2028 |
q->setAttribute(Qt::WA_Mapped); |
|
2029 |
if (q->isWindow()) |
|
2030 |
topData()->waitingForMapNotify = 1; |
|
2031 |
||
2032 |
if (!q->isWindow() |
|
2033 |
&& (!q->autoFillBackground() |
|
2034 |
|| q->palette().brush(q->backgroundRole()).style() == Qt::LinearGradientPattern)) { |
|
2035 |
if (q->internalWinId()) { |
|
2036 |
XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone); |
|
2037 |
XMapWindow(X11->display, q->internalWinId()); |
|
2038 |
updateSystemBackground(); |
|
2039 |
} |
|
2040 |
return; |
|
2041 |
} |
|
2042 |
||
2043 |
if (q->internalWinId()) |
|
2044 |
XMapWindow(X11->display, q->internalWinId()); |
|
2045 |
||
2046 |
// Freedesktop.org Startup Notification |
|
2047 |
if (X11->startupId && q->isWindow()) { |
|
2048 |
QByteArray message("remove: ID="); |
|
2049 |
message.append(X11->startupId); |
|
2050 |
sendStartupMessage(message.constData()); |
|
2051 |
X11->startupId = 0; |
|
2052 |
} |
|
2053 |
} |
|
2054 |
||
2055 |
/*! |
|
2056 |
\internal |
|
2057 |
Platform-specific part of QWidget::show(). |
|
2058 |
*/ |
|
2059 |
||
2060 |
void QWidgetPrivate::sendStartupMessage(const char *message) const |
|
2061 |
{ |
|
2062 |
Q_Q(const QWidget); |
|
2063 |
||
2064 |
if (!message) |
|
2065 |
return; |
|
2066 |
||
2067 |
XEvent xevent; |
|
2068 |
xevent.xclient.type = ClientMessage; |
|
2069 |
xevent.xclient.message_type = ATOM(_NET_STARTUP_INFO_BEGIN); |
|
2070 |
xevent.xclient.display = X11->display; |
|
2071 |
xevent.xclient.window = q->internalWinId(); |
|
2072 |
xevent.xclient.format = 8; |
|
2073 |
||
2074 |
Window rootWindow = RootWindow(X11->display, DefaultScreen(X11->display)); |
|
2075 |
uint sent = 0; |
|
2076 |
uint length = strlen(message) + 1; |
|
2077 |
do { |
|
2078 |
if (sent == 20) |
|
2079 |
xevent.xclient.message_type = ATOM(_NET_STARTUP_INFO); |
|
2080 |
||
2081 |
for (uint i = 0; i < 20 && i + sent <= length; i++) |
|
2082 |
xevent.xclient.data.b[i] = message[i + sent++]; |
|
2083 |
||
2084 |
XSendEvent(X11->display, rootWindow, false, PropertyChangeMask, &xevent); |
|
2085 |
} while (sent <= length); |
|
2086 |
} |
|
2087 |
||
2088 |
void QWidgetPrivate::setNetWmWindowTypes() |
|
2089 |
{ |
|
2090 |
Q_Q(QWidget); |
|
2091 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2092 |
||
2093 |
if (!q->isWindow()) { |
|
2094 |
if (q->internalWinId()) |
|
2095 |
XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_WINDOW_TYPE)); |
|
2096 |
return; |
|
2097 |
} |
|
2098 |
||
2099 |
QVector<long> windowTypes; |
|
2100 |
||
2101 |
// manual selection 1 (these are never set by Qt and take precedence) |
|
2102 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDesktop)) |
|
2103 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DESKTOP)); |
|
2104 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDock)) |
|
2105 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DOCK)); |
|
2106 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeNotification)) |
|
2107 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_NOTIFICATION)); |
|
2108 |
||
2109 |
// manual selection 2 (Qt uses these during auto selection); |
|
2110 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeUtility)) |
|
2111 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_UTILITY)); |
|
2112 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeSplash)) |
|
2113 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_SPLASH)); |
|
2114 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDialog)) |
|
2115 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DIALOG)); |
|
2116 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip)) |
|
2117 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLTIP)); |
|
2118 |
||
2119 |
// manual selection 3 (these can be set by Qt, but don't have a |
|
2120 |
// corresponding Qt::WindowType). note that order of the *MENU |
|
2121 |
// atoms is important |
|
2122 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeMenu)) |
|
2123 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_MENU)); |
|
2124 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu)) |
|
2125 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DROPDOWN_MENU)); |
|
2126 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypePopupMenu)) |
|
2127 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_POPUP_MENU)); |
|
2128 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolBar)) |
|
2129 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR)); |
|
2130 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeCombo)) |
|
2131 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_COMBO)); |
|
2132 |
if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDND)) |
|
2133 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DND)); |
|
2134 |
||
2135 |
// automatic selection |
|
2136 |
switch (q->windowType()) { |
|
2137 |
case Qt::Dialog: |
|
2138 |
case Qt::Sheet: |
|
2139 |
// dialog netwm type |
|
2140 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DIALOG)); |
|
2141 |
break; |
|
2142 |
||
2143 |
case Qt::Tool: |
|
2144 |
case Qt::Drawer: |
|
2145 |
// utility netwm type |
|
2146 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_UTILITY)); |
|
2147 |
break; |
|
2148 |
||
2149 |
case Qt::ToolTip: |
|
2150 |
// tooltip netwm type |
|
2151 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLTIP)); |
|
2152 |
break; |
|
2153 |
||
2154 |
case Qt::SplashScreen: |
|
2155 |
// splash netwm type |
|
2156 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_SPLASH)); |
|
2157 |
break; |
|
2158 |
||
2159 |
default: |
|
2160 |
break; |
|
2161 |
} |
|
2162 |
||
2163 |
if (q->windowFlags() & Qt::FramelessWindowHint) { |
|
2164 |
// override netwm type - quick and easy for KDE noborder |
|
2165 |
windowTypes.append(ATOM(_KDE_NET_WM_WINDOW_TYPE_OVERRIDE)); |
|
2166 |
} |
|
2167 |
||
2168 |
// normal netwm type - default |
|
2169 |
windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_NORMAL)); |
|
2170 |
||
2171 |
if (!windowTypes.isEmpty()) { |
|
2172 |
XChangeProperty(X11->display, q->winId(), ATOM(_NET_WM_WINDOW_TYPE), XA_ATOM, 32, |
|
2173 |
PropModeReplace, (unsigned char *) windowTypes.constData(), |
|
2174 |
windowTypes.count()); |
|
2175 |
} else { |
|
2176 |
XDeleteProperty(X11->display, q->winId(), ATOM(_NET_WM_WINDOW_TYPE)); |
|
2177 |
} |
|
2178 |
} |
|
2179 |
||
2180 |
/*! |
|
2181 |
\internal |
|
2182 |
Platform-specific part of QWidget::hide(). |
|
2183 |
*/ |
|
2184 |
||
2185 |
void QWidgetPrivate::hide_sys() |
|
2186 |
{ |
|
2187 |
Q_Q(QWidget); |
|
2188 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2189 |
deactivateWidgetCleanup(); |
|
2190 |
if (q->isWindow()) { |
|
2191 |
X11->deferred_map.removeAll(q); |
|
2192 |
if (q->internalWinId()) // in nsplugin, may be 0 |
|
2193 |
XWithdrawWindow(X11->display, q->internalWinId(), xinfo.screen()); |
|
2194 |
XFlush(X11->display); |
|
2195 |
} else { |
|
2196 |
invalidateBuffer(q->rect()); |
|
2197 |
if (q->internalWinId()) // in nsplugin, may be 0 |
|
2198 |
XUnmapWindow(X11->display, q->internalWinId()); |
|
2199 |
} |
|
2200 |
q->setAttribute(Qt::WA_Mapped, false); |
|
2201 |
} |
|
2202 |
||
2203 |
void QWidgetPrivate::setFocus_sys() |
|
2204 |
{ |
|
2205 |
||
2206 |
} |
|
2207 |
||
2208 |
||
2209 |
void QWidgetPrivate::raise_sys() |
|
2210 |
{ |
|
2211 |
Q_Q(QWidget); |
|
2212 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2213 |
if (q->internalWinId()) |
|
2214 |
XRaiseWindow(X11->display, q->internalWinId()); |
|
2215 |
} |
|
2216 |
||
2217 |
void QWidgetPrivate::lower_sys() |
|
2218 |
{ |
|
2219 |
Q_Q(QWidget); |
|
2220 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2221 |
if (q->internalWinId()) |
|
2222 |
XLowerWindow(X11->display, q->internalWinId()); |
|
2223 |
if(!q->isWindow()) |
|
2224 |
invalidateBuffer(q->rect()); |
|
2225 |
} |
|
2226 |
||
2227 |
void QWidgetPrivate::stackUnder_sys(QWidget* w) |
|
2228 |
{ |
|
2229 |
Q_Q(QWidget); |
|
2230 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2231 |
if (q->internalWinId() && w->internalWinId()) { |
|
2232 |
Window stack[2]; |
|
2233 |
stack[0] = w->internalWinId();; |
|
2234 |
stack[1] = q->internalWinId(); |
|
2235 |
XRestackWindows(X11->display, stack, 2); |
|
2236 |
} |
|
2237 |
if(!q->isWindow() || !w->internalWinId()) |
|
2238 |
invalidateBuffer(q->rect()); |
|
2239 |
} |
|
2240 |
||
2241 |
||
2242 |
static void do_size_hints(QWidget* widget, QWExtra *x) |
|
2243 |
{ |
|
2244 |
Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created)); |
|
2245 |
XSizeHints s; |
|
2246 |
s.flags = 0; |
|
2247 |
if (x) { |
|
2248 |
QRect g = widget->geometry(); |
|
2249 |
s.x = g.x(); |
|
2250 |
s.y = g.y(); |
|
2251 |
s.width = g.width(); |
|
2252 |
s.height = g.height(); |
|
2253 |
if (x->minw > 0 || x->minh > 0) { |
|
2254 |
// add minimum size hints |
|
2255 |
s.flags |= PMinSize; |
|
2256 |
s.min_width = qMin(XCOORD_MAX, x->minw); |
|
2257 |
s.min_height = qMin(XCOORD_MAX, x->minh); |
|
2258 |
} |
|
2259 |
if (x->maxw < QWIDGETSIZE_MAX || x->maxh < QWIDGETSIZE_MAX) { |
|
2260 |
// add maximum size hints |
|
2261 |
s.flags |= PMaxSize; |
|
2262 |
s.max_width = qMin(XCOORD_MAX, x->maxw); |
|
2263 |
s.max_height = qMin(XCOORD_MAX, x->maxh); |
|
2264 |
} |
|
2265 |
if (x->topextra && |
|
2266 |
(x->topextra->incw > 0 || x->topextra->inch > 0)) { |
|
2267 |
// add resize increment hints |
|
2268 |
s.flags |= PResizeInc | PBaseSize; |
|
2269 |
s.width_inc = x->topextra->incw; |
|
2270 |
s.height_inc = x->topextra->inch; |
|
2271 |
s.base_width = x->topextra->basew; |
|
2272 |
s.base_height = x->topextra->baseh; |
|
2273 |
} |
|
2274 |
} |
|
2275 |
if (widget->testAttribute(Qt::WA_Moved)) { |
|
2276 |
// user (i.e. command-line) specified position |
|
2277 |
s.flags |= USPosition; |
|
2278 |
s.flags |= PPosition; |
|
2279 |
} |
|
2280 |
if (widget->testAttribute(Qt::WA_Resized)) { |
|
2281 |
// user (i.e. command-line) specified size |
|
2282 |
s.flags |= USSize; |
|
2283 |
s.flags |= PSize; |
|
2284 |
} |
|
2285 |
s.flags |= PWinGravity; |
|
2286 |
if (widget->testAttribute(Qt::WA_Moved) && x && x->topextra && !x->topextra->posFromMove) { |
|
2287 |
// position came from setGeometry(), tell the WM that we don't |
|
2288 |
// want our window gravity-shifted |
|
2289 |
s.win_gravity = StaticGravity; |
|
2290 |
} else { |
|
2291 |
// position came from move() |
|
2292 |
s.x = widget->x(); |
|
2293 |
s.y = widget->y(); |
|
2294 |
s.win_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity; |
|
2295 |
} |
|
2296 |
if (widget->internalWinId()) |
|
2297 |
XSetWMNormalHints(X11->display, widget->internalWinId(), &s); |
|
2298 |
} |
|
2299 |
||
2300 |
||
2301 |
/* |
|
2302 |
Helper function for non-toplevel widgets. Helps to map Qt's 32bit |
|
2303 |
coordinate system to X11's 16bit coordinate system. |
|
2304 |
||
2305 |
Sets the geometry of the widget to data.crect, but clipped to sizes |
|
2306 |
that X can handle. Unmaps widgets that are completely outside the |
|
2307 |
valid range. |
|
2308 |
||
2309 |
Maintains data.wrect, which is the geometry of the X widget, |
|
2310 |
measured in this widget's coordinate system. |
|
2311 |
||
2312 |
if the parent is not clipped, parentWRect is empty, otherwise |
|
2313 |
parentWRect is the geometry of the parent's X rect, measured in |
|
2314 |
parent's coord sys |
|
2315 |
*/ |
|
2316 |
void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &) |
|
2317 |
{ |
|
2318 |
Q_Q(QWidget); |
|
2319 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2320 |
||
2321 |
/* |
|
2322 |
There are up to four different coordinate systems here: |
|
2323 |
Qt coordinate system for this widget. |
|
2324 |
X coordinate system for this widget (relative to wrect). |
|
2325 |
Qt coordinate system for parent |
|
2326 |
X coordinate system for parent (relative to parent's wrect). |
|
2327 |
*/ |
|
2328 |
Display *dpy = xinfo.display(); |
|
2329 |
QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX); |
|
2330 |
QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX); |
|
2331 |
QRect wrect; |
|
2332 |
//xrect is the X geometry of my X widget. (starts out in parent's Qt coord sys, and ends up in parent's X coord sys) |
|
2333 |
QRect xrect = data.crect; |
|
2334 |
||
2335 |
const QWidget *const parent = q->parentWidget(); |
|
2336 |
QRect parentWRect = parent->data->wrect; |
|
2337 |
||
2338 |
if (parentWRect.isValid()) { |
|
2339 |
// parent is clipped, and we have to clip to the same limit as parent |
|
2340 |
if (!parentWRect.contains(xrect)) { |
|
2341 |
xrect &= parentWRect; |
|
2342 |
wrect = xrect; |
|
2343 |
//translate from parent's to my Qt coord sys |
|
2344 |
wrect.translate(-data.crect.topLeft()); |
|
2345 |
} |
|
2346 |
//translate from parent's Qt coords to parent's X coords |
|
2347 |
xrect.translate(-parentWRect.topLeft()); |
|
2348 |
||
2349 |
} else { |
|
2350 |
// parent is not clipped, we may or may not have to clip |
|
2351 |
||
2352 |
if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) { |
|
2353 |
// This is where the main optimization is: we are already |
|
2354 |
// clipped, and if our clip is still valid, we can just |
|
2355 |
// move our window, and do not need to move or clip |
|
2356 |
// children |
|
2357 |
||
2358 |
QRect vrect = xrect & parent->rect(); |
|
2359 |
vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords |
|
2360 |
if (data.wrect.contains(vrect)) { |
|
2361 |
xrect = data.wrect; |
|
2362 |
xrect.translate(data.crect.topLeft()); |
|
2363 |
if (data.winid) |
|
2364 |
XMoveWindow(dpy, data.winid, xrect.x(), xrect.y()); |
|
2365 |
return; |
|
2366 |
} |
|
2367 |
} |
|
2368 |
||
2369 |
if (!validRange.contains(xrect)) { |
|
2370 |
// we are too big, and must clip |
|
2371 |
xrect &=wrectRange; |
|
2372 |
wrect = xrect; |
|
2373 |
wrect.translate(-data.crect.topLeft()); |
|
2374 |
//parent's X coord system is equal to parent's Qt coord |
|
2375 |
//sys, so we don't need to map xrect. |
|
2376 |
} |
|
2377 |
||
2378 |
} |
|
2379 |
||
2380 |
// unmap if we are outside the valid window system coord system |
|
2381 |
bool outsideRange = !xrect.isValid(); |
|
2382 |
bool mapWindow = false; |
|
2383 |
if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) { |
|
2384 |
q->setAttribute(Qt::WA_OutsideWSRange, outsideRange); |
|
2385 |
if (outsideRange) { |
|
2386 |
if (data.winid) |
|
2387 |
XUnmapWindow(dpy, data.winid); |
|
2388 |
q->setAttribute(Qt::WA_Mapped, false); |
|
2389 |
} else if (!q->isHidden()) { |
|
2390 |
mapWindow = true; |
|
2391 |
} |
|
2392 |
} |
|
2393 |
||
2394 |
if (outsideRange) |
|
2395 |
return; |
|
2396 |
||
2397 |
bool jump = (data.wrect != wrect); |
|
2398 |
data.wrect = wrect; |
|
2399 |
||
2400 |
||
2401 |
// and now recursively for all children... |
|
2402 |
// ### can be optimized |
|
2403 |
for (int i = 0; i < children.size(); ++i) { |
|
2404 |
QObject *object = children.at(i); |
|
2405 |
if (object->isWidgetType()) { |
|
2406 |
QWidget *w = static_cast<QWidget *>(object); |
|
2407 |
if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created)) |
|
2408 |
w->d_func()->setWSGeometry(jump); |
|
2409 |
} |
|
2410 |
} |
|
2411 |
||
2412 |
if (data.winid) { |
|
2413 |
// move ourselves to the new position and map (if necessary) after |
|
2414 |
// the movement. Rationale: moving unmapped windows is much faster |
|
2415 |
// than moving mapped windows |
|
2416 |
if (jump) //avoid flicker when jumping |
|
2417 |
XSetWindowBackgroundPixmap(dpy, data.winid, XNone); |
|
2418 |
if (!parent->internalWinId()) |
|
2419 |
xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0))); |
|
2420 |
XMoveResizeWindow(dpy, data.winid, xrect.x(), xrect.y(), xrect.width(), xrect.height()); |
|
2421 |
} |
|
2422 |
||
2423 |
//to avoid flicker, we have to show children after the helper widget has moved |
|
2424 |
if (jump) { |
|
2425 |
for (int i = 0; i < children.size(); ++i) { |
|
2426 |
QObject *object = children.at(i); |
|
2427 |
if (object->isWidgetType()) { |
|
2428 |
QWidget *w = static_cast<QWidget *>(object); |
|
2429 |
if (!w->testAttribute(Qt::WA_OutsideWSRange) && !w->testAttribute(Qt::WA_Mapped) && !w->isHidden()) { |
|
2430 |
w->setAttribute(Qt::WA_Mapped); |
|
2431 |
if (w->internalWinId()) |
|
2432 |
XMapWindow(dpy, w->data->winid); |
|
2433 |
} |
|
2434 |
} |
|
2435 |
} |
|
2436 |
} |
|
2437 |
||
2438 |
||
2439 |
if (jump && data.winid) |
|
2440 |
XClearArea(dpy, data.winid, 0, 0, wrect.width(), wrect.height(), True); |
|
2441 |
||
2442 |
if (mapWindow && !dontShow) { |
|
2443 |
q->setAttribute(Qt::WA_Mapped); |
|
2444 |
if (data.winid) |
|
2445 |
XMapWindow(dpy, data.winid); |
|
2446 |
} |
|
2447 |
} |
|
2448 |
||
2449 |
void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) |
|
2450 |
{ |
|
2451 |
Q_Q(QWidget); |
|
2452 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
2453 |
Display *dpy = X11->display; |
|
2454 |
||
2455 |
if ((q->windowType() == Qt::Desktop)) |
|
2456 |
return; |
|
2457 |
if (q->isWindow()) { |
|
2458 |
if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)) |
|
2459 |
&& !X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))) |
|
2460 |
data.window_state &= ~Qt::WindowMaximized; |
|
2461 |
if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) |
|
2462 |
data.window_state &= ~Qt::WindowFullScreen; |
|
2463 |
if (QTLWExtra *topData = maybeTopData()) |
|
2464 |
topData->normalGeometry = QRect(0,0,-1,-1); |
|
2465 |
} else { |
|
2466 |
uint s = data.window_state; |
|
2467 |
s &= ~(Qt::WindowMaximized | Qt::WindowFullScreen); |
|
2468 |
data.window_state = s; |
|
2469 |
} |
|
2470 |
if (extra) { // any size restrictions? |
|
2471 |
w = qMin(w,extra->maxw); |
|
2472 |
h = qMin(h,extra->maxh); |
|
2473 |
w = qMax(w,extra->minw); |
|
2474 |
h = qMax(h,extra->minh); |
|
2475 |
} |
|
2476 |
QPoint oldPos(q->pos()); |
|
2477 |
QSize oldSize(q->size()); |
|
2478 |
QRect oldGeom(data.crect); |
|
2479 |
QRect r(x, y, w, h); |
|
2480 |
||
2481 |
// We only care about stuff that changes the geometry, or may |
|
2482 |
// cause the window manager to change its state |
|
2483 |
if (!q->isWindow() && oldGeom == r) |
|
2484 |
return; |
|
2485 |
||
2486 |
data.crect = r; |
|
2487 |
bool isResize = q->size() != oldSize; |
|
2488 |
||
2489 |
if (q->isWindow()) { |
|
2490 |
if (w == 0 || h == 0) { |
|
2491 |
q->setAttribute(Qt::WA_OutsideWSRange, true); |
|
2492 |
if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) |
|
2493 |
hide_sys(); |
|
2494 |
} else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) { |
|
2495 |
q->setAttribute(Qt::WA_OutsideWSRange, false); |
|
2496 |
||
2497 |
// put the window in its place and show it |
|
2498 |
if (data.winid) |
|
2499 |
XMoveResizeWindow(dpy, data.winid, x, y, w, h); |
|
2500 |
topData()->posFromMove = false; // force StaticGravity |
|
2501 |
do_size_hints(q, extra); |
|
2502 |
show_sys(); |
|
2503 |
} else { |
|
2504 |
q->setAttribute(Qt::WA_OutsideWSRange, false); |
|
2505 |
if (!q->isVisible()) |
|
2506 |
do_size_hints(q, extra); |
|
2507 |
if (isMove) { |
|
2508 |
if ((data.window_flags & Qt::X11BypassWindowManagerHint) == Qt::X11BypassWindowManagerHint |
|
2509 |
// work around 4Dwm's incompliance with ICCCM 4.1.5 |
|
2510 |
|| X11->desktopEnvironment == DE_4DWM) { |
|
2511 |
if (data.winid) |
|
2512 |
XMoveResizeWindow(dpy, data.winid, x, y, w, h); |
|
2513 |
} else if (q->isVisible() |
|
2514 |
&& topData()->validWMState |
|
2515 |
&& X11->isSupportedByWM(ATOM(_NET_MOVERESIZE_WINDOW))) { |
|
2516 |
XEvent e; |
|
2517 |
e.xclient.type = ClientMessage; |
|
2518 |
e.xclient.message_type = ATOM(_NET_MOVERESIZE_WINDOW); |
|
2519 |
e.xclient.display = X11->display; |
|
2520 |
e.xclient.window = q->internalWinId(); |
|
2521 |
e.xclient.format = 32; |
|
2522 |
e.xclient.data.l[0] = StaticGravity | 1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<12; |
|
2523 |
e.xclient.data.l[1] = x; |
|
2524 |
e.xclient.data.l[2] = y; |
|
2525 |
e.xclient.data.l[3] = w; |
|
2526 |
e.xclient.data.l[4] = h; |
|
2527 |
XSendEvent(X11->display, RootWindow(X11->display, q->x11Info().screen()), |
|
2528 |
false, (SubstructureNotifyMask | SubstructureRedirectMask), &e); |
|
2529 |
} else if (data.winid) { |
|
2530 |
// pos() is right according to ICCCM 4.1.5 |
|
2531 |
XMoveResizeWindow(dpy, data.winid, q->pos().x(), q->pos().y(), w, h); |
|
2532 |
} |
|
2533 |
} else if (isResize && data.winid) { |
|
2534 |
if (!q->isVisible() |
|
2535 |
&& topData()->validWMState |
|
2536 |
&& !q->testAttribute(Qt::WA_PendingMoveEvent)) { |
|
2537 |
/* |
|
2538 |
even though we've not visible, we could be in a |
|
2539 |
race w/ the window manager, and it may ignore |
|
2540 |
our ConfigureRequest. setting posFromMove to |
|
2541 |
false makes sure that doDeferredMap() in |
|
2542 |
qapplication_x11.cpp keeps the window in the |
|
2543 |
right place |
|
2544 |
*/ |
|
2545 |
topData()->posFromMove = false; |
|
2546 |
} |
|
2547 |
XResizeWindow(dpy, data.winid, w, h); |
|
2548 |
} |
|
2549 |
} |
|
2550 |
if (isResize && !q->testAttribute(Qt::WA_DontShowOnScreen)) // set config pending only on resize, see qapplication_x11.cpp, translateConfigEvent() |
|
2551 |
q->setAttribute(Qt::WA_WState_ConfigPending); |
|
2552 |
||
2553 |
} else { |
|
2554 |
QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); |
|
2555 |
const bool inTopLevelResize = tlwExtra ? tlwExtra->inTopLevelResize : false; |
|
2556 |
const bool disableInTopLevelResize = inTopLevelResize && q->internalWinId(); |
|
2557 |
if (disableInTopLevelResize) { |
|
2558 |
// Top-level resize optimization does not work for native child widgets; |
|
2559 |
// disable it for this particular widget. |
|
2560 |
tlwExtra->inTopLevelResize = false; |
|
2561 |
} |
|
2562 |
||
2563 |
if (!isResize && (!inTopLevelResize || disableInTopLevelResize) && q->isVisible()) { |
|
2564 |
moveRect(QRect(oldPos, oldSize), x - oldPos.x(), y - oldPos.y()); |
|
2565 |
} |
|
2566 |
if (q->testAttribute(Qt::WA_WState_Created)) |
|
2567 |
setWSGeometry(); |
|
2568 |
||
2569 |
if (isResize && (!inTopLevelResize || disableInTopLevelResize) && q->isVisible()) |
|
2570 |
invalidateBuffer_resizeHelper(oldPos, oldSize); |
|
2571 |
||
2572 |
if (disableInTopLevelResize) |
|
2573 |
tlwExtra->inTopLevelResize = true; |
|
2574 |
} |
|
2575 |
||
2576 |
if (q->isVisible()) { |
|
2577 |
if (isMove && q->pos() != oldPos) { |
|
2578 |
if (X11->desktopEnvironment != DE_4DWM) { |
|
2579 |
// pos() is right according to ICCCM 4.1.5 |
|
2580 |
QMoveEvent e(q->pos(), oldPos); |
|
2581 |
QApplication::sendEvent(q, &e); |
|
2582 |
} else { |
|
2583 |
// work around 4Dwm's incompliance with ICCCM 4.1.5 |
|
2584 |
QMoveEvent e(data.crect.topLeft(), oldGeom.topLeft()); |
|
2585 |
QApplication::sendEvent(q, &e); |
|
2586 |
} |
|
2587 |
} |
|
2588 |
if (isResize) { |
|
2589 |
static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt(); |
|
2590 |
// If we have a backing store with static contents, we have to disable the top-level |
|
2591 |
// resize optimization in order to get invalidated regions for resized widgets. |
|
2592 |
// The optimization discards all invalidateBuffer() calls since we're going to |
|
2593 |
// repaint everything anyways, but that's not the case with static contents. |
|
2594 |
const bool setTopLevelResize = !slowResize && q->isWindow() && extra && extra->topextra |
|
2595 |
&& !extra->topextra->inTopLevelResize |
|
2596 |
&& (!extra->topextra->backingStore |
|
2597 |
|| !extra->topextra->backingStore->hasStaticContents()); |
|
2598 |
if (setTopLevelResize) |
|
2599 |
extra->topextra->inTopLevelResize = true; |
|
2600 |
QResizeEvent e(q->size(), oldSize); |
|
2601 |
QApplication::sendEvent(q, &e); |
|
2602 |
if (setTopLevelResize) |
|
2603 |
extra->topextra->inTopLevelResize = false; |
|
2604 |
} |
|
2605 |
} else { |
|
2606 |
if (isMove && q->pos() != oldPos) |
|
2607 |
q->setAttribute(Qt::WA_PendingMoveEvent, true); |
|
2608 |
if (isResize) |
|
2609 |
q->setAttribute(Qt::WA_PendingResizeEvent, true); |
|
2610 |
} |
|
2611 |
} |
|
2612 |
||
2613 |
void QWidgetPrivate::setConstraints_sys() |
|
2614 |
{ |
|
2615 |
Q_Q(QWidget); |
|
2616 |
#ifdef ALIEN_DEBUG |
|
2617 |
qDebug() << "QWidgetPrivate::setConstraints_sys START" << q; |
|
2618 |
#endif |
|
2619 |
if (q->testAttribute(Qt::WA_WState_Created)) |
|
2620 |
do_size_hints(q, extra); |
|
2621 |
#ifdef ALIEN_DEBUG |
|
2622 |
qDebug() << "QWidgetPrivate::setConstraints_sys END" << q; |
|
2623 |
#endif |
|
2624 |
} |
|
2625 |
||
2626 |
void QWidgetPrivate::scroll_sys(int dx, int dy) |
|
2627 |
{ |
|
2628 |
Q_Q(QWidget); |
|
2629 |
||
2630 |
scrollChildren(dx, dy); |
|
2631 |
if (!paintOnScreen()) { |
|
2632 |
scrollRect(q->rect(), dx, dy); |
|
2633 |
} else { |
|
2634 |
scroll_sys(dx, dy, QRect()); |
|
2635 |
} |
|
2636 |
} |
|
2637 |
||
2638 |
void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r) |
|
2639 |
{ |
|
2640 |
Q_Q(QWidget); |
|
2641 |
||
2642 |
if (!paintOnScreen()) { |
|
2643 |
scrollRect(r, dx, dy); |
|
2644 |
return; |
|
2645 |
} |
|
2646 |
bool valid_rect = r.isValid(); |
|
2647 |
bool just_update = qAbs(dx) > q->width() || qAbs(dy) > q->height(); |
|
2648 |
QRect sr = valid_rect ? r : clipRect(); |
|
2649 |
if (just_update) |
|
2650 |
q->update(); |
|
2651 |
else if (!valid_rect) |
|
2652 |
dirty.translate(dx, dy); |
|
2653 |
||
2654 |
int x1, y1, x2, y2, w = sr.width(), h = sr.height(); |
|
2655 |
if (dx > 0) { |
|
2656 |
x1 = sr.x(); |
|
2657 |
x2 = x1+dx; |
|
2658 |
w -= dx; |
|
2659 |
} else { |
|
2660 |
x2 = sr.x(); |
|
2661 |
x1 = x2-dx; |
|
2662 |
w += dx; |
|
2663 |
} |
|
2664 |
if (dy > 0) { |
|
2665 |
y1 = sr.y(); |
|
2666 |
y2 = y1+dy; |
|
2667 |
h -= dy; |
|
2668 |
} else { |
|
2669 |
y2 = sr.y(); |
|
2670 |
y1 = y2-dy; |
|
2671 |
h += dy; |
|
2672 |
} |
|
2673 |
||
2674 |
if (dx == 0 && dy == 0) |
|
2675 |
return; |
|
2676 |
||
2677 |
Display *dpy = X11->display; |
|
2678 |
// Want expose events |
|
2679 |
if (w > 0 && h > 0 && !just_update && q->internalWinId()) { |
|
2680 |
GC gc = XCreateGC(dpy, q->internalWinId(), 0, 0); |
|
2681 |
XSetGraphicsExposures(dpy, gc, True); |
|
2682 |
XCopyArea(dpy, q->internalWinId(), q->internalWinId(), gc, x1, y1, w, h, x2, y2); |
|
2683 |
XFreeGC(dpy, gc); |
|
2684 |
} |
|
2685 |
||
2686 |
if (!valid_rect && !children.isEmpty()) { // scroll children |
|
2687 |
QPoint pd(dx, dy); |
|
2688 |
for (int i = 0; i < children.size(); ++i) { // move all children |
|
2689 |
register QObject *object = children.at(i); |
|
2690 |
if (object->isWidgetType()) { |
|
2691 |
QWidget *w = static_cast<QWidget *>(object); |
|
2692 |
if (!w->isWindow()) |
|
2693 |
w->move(w->pos() + pd); |
|
2694 |
} |
|
2695 |
} |
|
2696 |
} |
|
2697 |
||
2698 |
if (just_update) |
|
2699 |
return; |
|
2700 |
||
2701 |
// Don't let the server be bogged-down with repaint events |
|
2702 |
bool repaint_immediately = (qt_sip_count(q) < 3 && !q->testAttribute(Qt::WA_WState_InPaintEvent)); |
|
2703 |
||
2704 |
if (dx) { |
|
2705 |
int x = x2 == sr.x() ? sr.x()+w : sr.x(); |
|
2706 |
if (repaint_immediately) |
|
2707 |
q->repaint(x, sr.y(), qAbs(dx), sr.height()); |
|
2708 |
else if (q->internalWinId()) |
|
2709 |
XClearArea(dpy, data.winid, x, sr.y(), qAbs(dx), sr.height(), True); |
|
2710 |
} |
|
2711 |
if (dy) { |
|
2712 |
int y = y2 == sr.y() ? sr.y()+h : sr.y(); |
|
2713 |
if (repaint_immediately) |
|
2714 |
q->repaint(sr.x(), y, sr.width(), qAbs(dy)); |
|
2715 |
else if (q->internalWinId()) |
|
2716 |
XClearArea(dpy, data.winid, sr.x(), y, sr.width(), qAbs(dy), True); |
|
2717 |
} |
|
2718 |
||
2719 |
qt_insert_sip(q, dx, dy); // #### ignores r |
|
2720 |
} |
|
2721 |
||
2722 |
int QWidget::metric(PaintDeviceMetric m) const |
|
2723 |
{ |
|
2724 |
Q_D(const QWidget); |
|
2725 |
int val; |
|
2726 |
if (m == PdmWidth) { |
|
2727 |
val = data->crect.width(); |
|
2728 |
} else if (m == PdmHeight) { |
|
2729 |
val = data->crect.height(); |
|
2730 |
} else { |
|
2731 |
Display *dpy = X11->display; |
|
2732 |
int scr = d->xinfo.screen(); |
|
2733 |
switch (m) { |
|
2734 |
case PdmDpiX: |
|
2735 |
case PdmPhysicalDpiX: |
|
2736 |
if (d->extra && d->extra->customDpiX) |
|
2737 |
val = d->extra->customDpiX; |
|
2738 |
else if (d->parent) |
|
2739 |
val = static_cast<QWidget *>(d->parent)->metric(m); |
|
2740 |
else |
|
2741 |
val = QX11Info::appDpiX(scr); |
|
2742 |
break; |
|
2743 |
case PdmDpiY: |
|
2744 |
case PdmPhysicalDpiY: |
|
2745 |
if (d->extra && d->extra->customDpiY) |
|
2746 |
val = d->extra->customDpiY; |
|
2747 |
else if (d->parent) |
|
2748 |
val = static_cast<QWidget *>(d->parent)->metric(m); |
|
2749 |
else |
|
2750 |
val = QX11Info::appDpiY(scr); |
|
2751 |
break; |
|
2752 |
case PdmWidthMM: |
|
2753 |
val = (DisplayWidthMM(dpy,scr)*data->crect.width())/ |
|
2754 |
DisplayWidth(dpy,scr); |
|
2755 |
break; |
|
2756 |
case PdmHeightMM: |
|
2757 |
val = (DisplayHeightMM(dpy,scr)*data->crect.height())/ |
|
2758 |
DisplayHeight(dpy,scr); |
|
2759 |
break; |
|
2760 |
case PdmNumColors: |
|
2761 |
val = d->xinfo.cells(); |
|
2762 |
break; |
|
2763 |
case PdmDepth: |
|
2764 |
val = d->xinfo.depth(); |
|
2765 |
break; |
|
2766 |
default: |
|
2767 |
val = 0; |
|
2768 |
qWarning("QWidget::metric: Invalid metric command"); |
|
2769 |
} |
|
2770 |
} |
|
2771 |
return val; |
|
2772 |
} |
|
2773 |
||
2774 |
void QWidgetPrivate::createSysExtra() |
|
2775 |
{ |
|
2776 |
extra->compress_events = true; |
|
2777 |
extra->xDndProxy = 0; |
|
2778 |
} |
|
2779 |
||
2780 |
void QWidgetPrivate::deleteSysExtra() |
|
2781 |
{ |
|
2782 |
} |
|
2783 |
||
2784 |
void QWidgetPrivate::createTLSysExtra() |
|
2785 |
{ |
|
2786 |
extra->topextra->spont_unmapped = 0; |
|
2787 |
extra->topextra->dnd = 0; |
|
2788 |
extra->topextra->validWMState = 0; |
|
2789 |
extra->topextra->waitingForMapNotify = 0; |
|
2790 |
extra->topextra->parentWinId = 0; |
|
2791 |
extra->topextra->userTimeWindow = 0; |
|
2792 |
#ifndef QT_NO_XSYNC |
|
2793 |
extra->topextra->syncUpdateCounter = 0; |
|
2794 |
extra->topextra->syncRequestTimestamp = 0; |
|
2795 |
extra->topextra->newCounterValueHi = 0; |
|
2796 |
extra->topextra->newCounterValueLo = 0; |
|
2797 |
#endif |
|
2798 |
} |
|
2799 |
||
2800 |
void QWidgetPrivate::deleteTLSysExtra() |
|
2801 |
{ |
|
2802 |
// don't destroy input context here. it will be destroyed in |
|
2803 |
// QWidget::destroy() destroyInputContext(); |
|
2804 |
} |
|
2805 |
||
2806 |
void QWidgetPrivate::registerDropSite(bool on) |
|
2807 |
{ |
|
2808 |
Q_UNUSED(on); |
|
2809 |
} |
|
2810 |
||
2811 |
void QWidgetPrivate::setMask_sys(const QRegion ®ion) |
|
2812 |
{ |
|
2813 |
Q_Q(QWidget); |
|
2814 |
if (!q->internalWinId()) |
|
2815 |
return; |
|
2816 |
||
2817 |
if (region.isEmpty()) { |
|
2818 |
XShapeCombineMask(X11->display, q->internalWinId(), ShapeBounding, 0, 0, |
|
2819 |
XNone, ShapeSet); |
|
2820 |
} else { |
|
2821 |
XShapeCombineRegion(X11->display, q->internalWinId(), ShapeBounding, 0, 0, |
|
2822 |
region.handle(), ShapeSet); |
|
2823 |
} |
|
2824 |
} |
|
2825 |
||
2826 |
/*! |
|
2827 |
\internal |
|
2828 |
||
2829 |
Computes the frame rectangle when needed. This is an internal function, you |
|
2830 |
should never call this. |
|
2831 |
*/ |
|
2832 |
||
2833 |
void QWidgetPrivate::updateFrameStrut() |
|
2834 |
{ |
|
2835 |
Q_Q(QWidget); |
|
2836 |
||
2837 |
QTLWExtra *top = topData(); |
|
2838 |
if (!top->validWMState) { |
|
2839 |
return; |
|
2840 |
} |
|
2841 |
if (!q->isWindow() && !q->internalWinId()) { |
|
2842 |
data.fstrut_dirty = false; |
|
2843 |
return; |
|
2844 |
} |
|
2845 |
||
2846 |
Atom type_ret; |
|
2847 |
Window l = q->effectiveWinId(), w = l, p, r; // target window, its parent, root |
|
2848 |
Window *c; |
|
2849 |
int i_unused; |
|
2850 |
unsigned int nc; |
|
2851 |
unsigned char *data_ret; |
|
2852 |
unsigned long l_unused; |
|
2853 |
||
2854 |
while (XQueryTree(X11->display, w, &r, &p, &c, &nc)) { |
|
2855 |
if (c && nc > 0) |
|
2856 |
XFree(c); |
|
2857 |
||
2858 |
if (! p) { |
|
2859 |
qWarning("QWidget::updateFrameStrut: No parent"); |
|
2860 |
return; |
|
2861 |
} |
|
2862 |
||
2863 |
// if the parent window is the root window, an Enlightenment virtual root or |
|
2864 |
// a NET WM virtual root window, stop here |
|
2865 |
data_ret = 0; |
|
2866 |
if (p == r || |
|
2867 |
(XGetWindowProperty(X11->display, p, |
|
2868 |
ATOM(ENLIGHTENMENT_DESKTOP), 0, 1, False, XA_CARDINAL, |
|
2869 |
&type_ret, &i_unused, &l_unused, &l_unused, |
|
2870 |
&data_ret) == Success && |
|
2871 |
type_ret == XA_CARDINAL)) { |
|
2872 |
if (data_ret) |
|
2873 |
XFree(data_ret); |
|
2874 |
||
2875 |
break; |
|
2876 |
} else if (X11->isSupportedByWM(ATOM(_NET_VIRTUAL_ROOTS)) && X11->net_virtual_root_list) { |
|
2877 |
int i = 0; |
|
2878 |
while (X11->net_virtual_root_list[i] != 0) { |
|
2879 |
if (X11->net_virtual_root_list[i++] == p) |
|
2880 |
break; |
|
2881 |
} |
|
2882 |
} |
|
2883 |
||
2884 |
l = w; |
|
2885 |
w = p; |
|
2886 |
} |
|
2887 |
||
2888 |
// we have our window |
|
2889 |
int transx, transy; |
|
2890 |
XWindowAttributes wattr; |
|
2891 |
if (XTranslateCoordinates(X11->display, l, w, |
|
2892 |
0, 0, &transx, &transy, &p) && |
|
2893 |
XGetWindowAttributes(X11->display, w, &wattr)) { |
|
2894 |
top->frameStrut.setCoords(transx, |
|
2895 |
transy, |
|
2896 |
wattr.width - data.crect.width() - transx, |
|
2897 |
wattr.height - data.crect.height() - transy); |
|
2898 |
||
2899 |
// add the border_width for the window managers frame... some window managers |
|
2900 |
// do not use a border_width of zero for their frames, and if we the left and |
|
2901 |
// top strut, we ensure that pos() is absolutely correct. frameGeometry() |
|
2902 |
// will still be incorrect though... perhaps i should have foffset as well, to |
|
2903 |
// indicate the frame offset (equal to the border_width on X). |
|
2904 |
// - Brad |
|
2905 |
top->frameStrut.adjust(wattr.border_width, |
|
2906 |
wattr.border_width, |
|
2907 |
wattr.border_width, |
|
2908 |
wattr.border_width); |
|
2909 |
} |
|
2910 |
||
2911 |
data.fstrut_dirty = false; |
|
2912 |
} |
|
2913 |
||
2914 |
void QWidgetPrivate::setWindowOpacity_sys(qreal opacity) |
|
2915 |
{ |
|
2916 |
Q_Q(QWidget); |
|
2917 |
ulong value = ulong(opacity * 0xffffffff); |
|
2918 |
XChangeProperty(QX11Info::display(), q->internalWinId(), ATOM(_NET_WM_WINDOW_OPACITY), XA_CARDINAL, |
|
2919 |
32, PropModeReplace, (uchar*)&value, 1); |
|
2920 |
} |
|
2921 |
||
2922 |
const QX11Info &QWidget::x11Info() const |
|
2923 |
{ |
|
2924 |
Q_D(const QWidget); |
|
2925 |
return d->xinfo; |
|
2926 |
} |
|
2927 |
||
2928 |
void QWidgetPrivate::setWindowRole() |
|
2929 |
{ |
|
2930 |
Q_Q(QWidget); |
|
2931 |
if (!q->internalWinId()) |
|
2932 |
return; |
|
2933 |
QByteArray windowRole = topData()->role.toUtf8(); |
|
2934 |
XChangeProperty(X11->display, q->internalWinId(), |
|
2935 |
ATOM(WM_WINDOW_ROLE), XA_STRING, 8, PropModeReplace, |
|
2936 |
(unsigned char *)windowRole.constData(), windowRole.length()); |
|
2937 |
} |
|
2938 |
||
2939 |
Q_GLOBAL_STATIC(QX11PaintEngine, qt_widget_paintengine) |
|
2940 |
QPaintEngine *QWidget::paintEngine() const |
|
2941 |
{ |
|
2942 |
Q_D(const QWidget); |
|
2943 |
if (qt_widget_paintengine()->isActive()) { |
|
2944 |
if (d->extraPaintEngine) |
|
2945 |
return d->extraPaintEngine; |
|
2946 |
QWidget *self = const_cast<QWidget *>(this); |
|
2947 |
self->d_func()->extraPaintEngine = new QX11PaintEngine(); |
|
2948 |
return d->extraPaintEngine; |
|
2949 |
} |
|
2950 |
return qt_widget_paintengine(); |
|
2951 |
} |
|
2952 |
||
2953 |
QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() |
|
2954 |
{ |
|
2955 |
return new QX11WindowSurface(q_func()); |
|
2956 |
} |
|
2957 |
||
2958 |
Qt::HANDLE QWidget::x11PictureHandle() const |
|
2959 |
{ |
|
2960 |
#ifndef QT_NO_XRENDER |
|
2961 |
Q_D(const QWidget); |
|
2962 |
if (!internalWinId() && testAttribute(Qt::WA_WState_Created)) |
|
2963 |
(void)winId(); // enforce native window |
|
2964 |
return d->picture; |
|
2965 |
#else |
|
2966 |
return 0; |
|
2967 |
#endif // QT_NO_XRENDER |
|
2968 |
} |
|
2969 |
||
2970 |
#ifndef QT_NO_XRENDER |
|
2971 |
XRenderColor QX11Data::preMultiply(const QColor &c) |
|
2972 |
{ |
|
2973 |
XRenderColor color; |
|
2974 |
const uint A = c.alpha(), |
|
2975 |
R = c.red(), |
|
2976 |
G = c.green(), |
|
2977 |
B = c.blue(); |
|
2978 |
color.alpha = (A | A << 8); |
|
2979 |
color.red = (R | R << 8) * color.alpha / 0x10000; |
|
2980 |
color.green = (G | G << 8) * color.alpha / 0x10000; |
|
2981 |
color.blue = (B | B << 8) * color.alpha / 0x10000; |
|
2982 |
return color; |
|
2983 |
} |
|
2984 |
Picture QX11Data::getSolidFill(int screen, const QColor &c) |
|
2985 |
{ |
|
2986 |
if (!X11->use_xrender) |
|
2987 |
return XNone; |
|
2988 |
||
2989 |
XRenderColor color = preMultiply(c); |
|
2990 |
for (int i = 0; i < X11->solid_fill_count; ++i) { |
|
2991 |
if (X11->solid_fills[i].screen == screen |
|
2992 |
&& X11->solid_fills[i].color.alpha == color.alpha |
|
2993 |
&& X11->solid_fills[i].color.red == color.red |
|
2994 |
&& X11->solid_fills[i].color.green == color.green |
|
2995 |
&& X11->solid_fills[i].color.blue == color.blue) |
|
2996 |
return X11->solid_fills[i].picture; |
|
2997 |
} |
|
2998 |
// none found, replace one |
|
2999 |
int i = rand() % 16; |
|
3000 |
||
3001 |
if (X11->solid_fills[i].screen != screen && X11->solid_fills[i].picture) { |
|
3002 |
XRenderFreePicture (X11->display, X11->solid_fills[i].picture); |
|
3003 |
X11->solid_fills[i].picture = 0; |
|
3004 |
} |
|
3005 |
||
3006 |
if (!X11->solid_fills[i].picture) { |
|
3007 |
Pixmap pixmap = XCreatePixmap (X11->display, RootWindow (X11->display, screen), 1, 1, 32); |
|
3008 |
XRenderPictureAttributes attrs; |
|
3009 |
attrs.repeat = True; |
|
3010 |
X11->solid_fills[i].picture = XRenderCreatePicture (X11->display, pixmap, |
|
3011 |
XRenderFindStandardFormat(X11->display, PictStandardARGB32), |
|
3012 |
CPRepeat, &attrs); |
|
3013 |
XFreePixmap (X11->display, pixmap); |
|
3014 |
} |
|
3015 |
||
3016 |
X11->solid_fills[i].color = color; |
|
3017 |
X11->solid_fills[i].screen = screen; |
|
3018 |
XRenderFillRectangle (X11->display, PictOpSrc, X11->solid_fills[i].picture, &color, 0, 0, 1, 1); |
|
3019 |
return X11->solid_fills[i].picture; |
|
3020 |
} |
|
3021 |
#endif |
|
3022 |
||
3023 |
void QWidgetPrivate::setModal_sys() |
|
3024 |
{ |
|
3025 |
} |
|
3026 |
||
3027 |
void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const QX11WindowAttributes &att) |
|
3028 |
{ |
|
3029 |
QX11InfoData* xd = xinfo->getX11Data(true); |
|
3030 |
const XWindowAttributes &a = *(att.att); |
|
3031 |
// find which screen the window is on... |
|
3032 |
xd->screen = QX11Info::appScreen(); // by default, use the default :) |
|
3033 |
int i; |
|
3034 |
for (i = 0; i < ScreenCount(X11->display); i++) { |
|
3035 |
if (RootWindow(X11->display, i) == a.root) { |
|
3036 |
xd->screen = i; |
|
3037 |
break; |
|
3038 |
} |
|
3039 |
} |
|
3040 |
||
3041 |
xd->depth = a.depth; |
|
3042 |
xd->cells = DisplayCells(X11->display, xd->screen); |
|
3043 |
xd->visual = a.visual; |
|
3044 |
xd->defaultVisual = (XVisualIDFromVisual((Visual *) a.visual) == |
|
3045 |
XVisualIDFromVisual((Visual *) QX11Info::appVisual(xinfo->screen()))); |
|
3046 |
xd->colormap = a.colormap; |
|
3047 |
xd->defaultColormap = (a.colormap == QX11Info::appColormap(xinfo->screen())); |
|
3048 |
xinfo->setX11Data(xd); |
|
3049 |
} |
|
3050 |
||
3051 |
QT_END_NAMESPACE |