author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
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 |
// ### 4.0: examine Q_EXPORT's below. The respective symbols had all |
|
43 |
// been in use (e.g. in the KDE wm) before the introduction of a version |
|
44 |
// map. One might want to turn some of them into proper public API and |
|
45 |
// provide a proper alternative for others. See also the exports in |
|
46 |
// qapplication_win.cpp, which suggest a unification. |
|
47 |
||
48 |
#include "qplatformdefs.h" |
|
49 |
||
50 |
#include "qcolormap.h" |
|
51 |
#include "qdesktopwidget.h" |
|
52 |
#include "qapplication.h" |
|
53 |
#include "qapplication_p.h" |
|
54 |
#include "qcursor.h" |
|
55 |
#include "qwidget.h" |
|
56 |
#include "qbitarray.h" |
|
57 |
#include "qpainter.h" |
|
58 |
#include "qfile.h" |
|
59 |
#include "qpixmapcache.h" |
|
60 |
#include "qdatetime.h" |
|
61 |
#include "qtextcodec.h" |
|
62 |
#include "qdatastream.h" |
|
63 |
#include "qbuffer.h" |
|
64 |
#include "qsocketnotifier.h" |
|
65 |
#include "qsessionmanager.h" |
|
66 |
#include "qclipboard.h" |
|
67 |
#include "qwhatsthis.h" |
|
68 |
#include "qsettings.h" |
|
69 |
#include "qstylefactory.h" |
|
70 |
#include "qfileinfo.h" |
|
71 |
#include "qdir.h" |
|
72 |
#include "qhash.h" |
|
73 |
#include "qevent.h" |
|
74 |
#include "qevent_p.h" |
|
75 |
#include "qvarlengtharray.h" |
|
76 |
#include "qdebug.h" |
|
77 |
#include <private/qunicodetables_p.h> |
|
78 |
#include <private/qcrashhandler_p.h> |
|
79 |
#include <private/qcolor_p.h> |
|
80 |
#include <private/qcursor_p.h> |
|
81 |
#include <private/qiconloader_p.h> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
#include <qgtkstyle.h> |
0 | 83 |
#include "qstyle.h" |
84 |
#include "qmetaobject.h" |
|
85 |
#include "qtimer.h" |
|
86 |
#include "qlibrary.h" |
|
87 |
#include <private/qgraphicssystemfactory_p.h> |
|
88 |
#include "qguiplatformplugin_p.h" |
|
89 |
#include "qkde_p.h" |
|
90 |
||
91 |
#if !defined (QT_NO_TABLET) |
|
92 |
extern "C" { |
|
93 |
# define class c_class //XIproto.h has a name member named 'class' which the c++ compiler doesn't like |
|
94 |
# include <wacomcfg.h> |
|
95 |
# undef class |
|
96 |
} |
|
97 |
#endif |
|
98 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
99 |
#ifndef QT_GUI_DOUBLE_CLICK_RADIUS |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
100 |
#define QT_GUI_DOUBLE_CLICK_RADIUS 5 |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
101 |
#endif |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
102 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
103 |
|
0 | 104 |
//#define ALIEN_DEBUG |
105 |
||
106 |
#if !defined(QT_NO_GLIB) |
|
107 |
# include "qguieventdispatcher_glib_p.h" |
|
108 |
#endif |
|
109 |
#include "qeventdispatcher_x11_p.h" |
|
110 |
#include <private/qpaintengine_x11_p.h> |
|
111 |
||
112 |
#include <private/qkeymapper_p.h> |
|
113 |
||
114 |
// Input method stuff |
|
115 |
#ifndef QT_NO_IM |
|
116 |
#include "qinputcontext.h" |
|
117 |
#include "qinputcontextfactory.h" |
|
118 |
#endif // QT_NO_IM |
|
119 |
||
120 |
#ifndef QT_NO_XFIXES |
|
121 |
#include <X11/extensions/Xfixes.h> |
|
122 |
#endif // QT_NO_XFIXES |
|
123 |
||
124 |
#include "qt_x11_p.h" |
|
125 |
#include "qx11info_x11.h" |
|
126 |
||
127 |
#define XK_MISCELLANY |
|
128 |
#include <X11/keysymdef.h> |
|
129 |
#if !defined(QT_NO_XINPUT) |
|
130 |
#include <X11/extensions/XI.h> |
|
131 |
#endif |
|
132 |
||
133 |
#include <stdlib.h> |
|
134 |
#include <string.h> |
|
135 |
#include <ctype.h> |
|
136 |
#include <locale.h> |
|
137 |
||
138 |
#include "qwidget_p.h" |
|
139 |
||
140 |
#include <private/qbackingstore_p.h> |
|
141 |
||
142 |
#ifdef QT_RX71_MULTITOUCH |
|
143 |
# include <qsocketnotifier.h> |
|
144 |
# include <linux/input.h> |
|
145 |
# include <errno.h> |
|
146 |
#endif |
|
147 |
||
148 |
#if _POSIX_VERSION+0 < 200112L && !defined(Q_OS_BSD4) |
|
149 |
# define QT_NO_UNSETENV |
|
150 |
#endif |
|
151 |
||
152 |
QT_BEGIN_NAMESPACE |
|
153 |
||
154 |
//#define X_NOT_BROKEN |
|
155 |
#ifdef X_NOT_BROKEN |
|
156 |
// Some X libraries are built with setlocale #defined to _Xsetlocale, |
|
157 |
// even though library users are then built WITHOUT such a definition. |
|
158 |
// This creates a problem - Qt might setlocale() one value, but then |
|
159 |
// X looks and doesn't see the value Qt set. The solution here is to |
|
160 |
// implement _Xsetlocale just in case X calls it - redirecting it to |
|
161 |
// the real libC version. |
|
162 |
// |
|
163 |
# ifndef setlocale |
|
164 |
extern "C" char *_Xsetlocale(int category, const char *locale); |
|
165 |
char *_Xsetlocale(int category, const char *locale) |
|
166 |
{ |
|
167 |
//qDebug("_Xsetlocale(%d,%s),category,locale"); |
|
168 |
return setlocale(category,locale); |
|
169 |
} |
|
170 |
# endif // setlocale |
|
171 |
#endif // X_NOT_BROKEN |
|
172 |
||
173 |
/* Warning: if you modify this string, modify the list of atoms in qt_x11_p.h as well! */ |
|
174 |
static const char * x11_atomnames = { |
|
175 |
// window-manager <-> client protocols |
|
176 |
"WM_PROTOCOLS\0" |
|
177 |
"WM_DELETE_WINDOW\0" |
|
178 |
"WM_TAKE_FOCUS\0" |
|
179 |
"_NET_WM_PING\0" |
|
180 |
"_NET_WM_CONTEXT_HELP\0" |
|
181 |
"_NET_WM_SYNC_REQUEST\0" |
|
182 |
"_NET_WM_SYNC_REQUEST_COUNTER\0" |
|
183 |
||
184 |
// ICCCM window state |
|
185 |
"WM_STATE\0" |
|
186 |
"WM_CHANGE_STATE\0" |
|
187 |
||
188 |
// Session management |
|
189 |
"WM_CLIENT_LEADER\0" |
|
190 |
"WM_WINDOW_ROLE\0" |
|
191 |
"SM_CLIENT_ID\0" |
|
192 |
||
193 |
// Clipboard |
|
194 |
"CLIPBOARD\0" |
|
195 |
"INCR\0" |
|
196 |
"TARGETS\0" |
|
197 |
"MULTIPLE\0" |
|
198 |
"TIMESTAMP\0" |
|
199 |
"SAVE_TARGETS\0" |
|
200 |
"CLIP_TEMPORARY\0" |
|
201 |
"_QT_SELECTION\0" |
|
202 |
"_QT_CLIPBOARD_SENTINEL\0" |
|
203 |
"_QT_SELECTION_SENTINEL\0" |
|
204 |
"CLIPBOARD_MANAGER\0" |
|
205 |
||
206 |
"RESOURCE_MANAGER\0" |
|
207 |
||
208 |
"_XSETROOT_ID\0" |
|
209 |
||
210 |
"_QT_SCROLL_DONE\0" |
|
211 |
"_QT_INPUT_ENCODING\0" |
|
212 |
||
213 |
"_MOTIF_WM_HINTS\0" |
|
214 |
||
215 |
"DTWM_IS_RUNNING\0" |
|
216 |
"ENLIGHTENMENT_DESKTOP\0" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
217 |
"_DT_SAVE_MODE\0" |
0 | 218 |
"_SGI_DESKS_MANAGER\0" |
219 |
||
220 |
// EWMH (aka NETWM) |
|
221 |
"_NET_SUPPORTED\0" |
|
222 |
"_NET_VIRTUAL_ROOTS\0" |
|
223 |
"_NET_WORKAREA\0" |
|
224 |
||
225 |
"_NET_MOVERESIZE_WINDOW\0" |
|
226 |
"_NET_WM_MOVERESIZE\0" |
|
227 |
||
228 |
"_NET_WM_NAME\0" |
|
229 |
"_NET_WM_ICON_NAME\0" |
|
230 |
"_NET_WM_ICON\0" |
|
231 |
||
232 |
"_NET_WM_PID\0" |
|
233 |
||
234 |
"_NET_WM_WINDOW_OPACITY\0" |
|
235 |
||
236 |
"_NET_WM_STATE\0" |
|
237 |
"_NET_WM_STATE_ABOVE\0" |
|
238 |
"_NET_WM_STATE_BELOW\0" |
|
239 |
"_NET_WM_STATE_FULLSCREEN\0" |
|
240 |
"_NET_WM_STATE_MAXIMIZED_HORZ\0" |
|
241 |
"_NET_WM_STATE_MAXIMIZED_VERT\0" |
|
242 |
"_NET_WM_STATE_MODAL\0" |
|
243 |
"_NET_WM_STATE_STAYS_ON_TOP\0" |
|
244 |
"_NET_WM_STATE_DEMANDS_ATTENTION\0" |
|
245 |
||
246 |
"_NET_WM_USER_TIME\0" |
|
247 |
"_NET_WM_USER_TIME_WINDOW\0" |
|
248 |
"_NET_WM_FULL_PLACEMENT\0" |
|
249 |
||
250 |
"_NET_WM_WINDOW_TYPE\0" |
|
251 |
"_NET_WM_WINDOW_TYPE_DESKTOP\0" |
|
252 |
"_NET_WM_WINDOW_TYPE_DOCK\0" |
|
253 |
"_NET_WM_WINDOW_TYPE_TOOLBAR\0" |
|
254 |
"_NET_WM_WINDOW_TYPE_MENU\0" |
|
255 |
"_NET_WM_WINDOW_TYPE_UTILITY\0" |
|
256 |
"_NET_WM_WINDOW_TYPE_SPLASH\0" |
|
257 |
"_NET_WM_WINDOW_TYPE_DIALOG\0" |
|
258 |
"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0" |
|
259 |
"_NET_WM_WINDOW_TYPE_POPUP_MENU\0" |
|
260 |
"_NET_WM_WINDOW_TYPE_TOOLTIP\0" |
|
261 |
"_NET_WM_WINDOW_TYPE_NOTIFICATION\0" |
|
262 |
"_NET_WM_WINDOW_TYPE_COMBO\0" |
|
263 |
"_NET_WM_WINDOW_TYPE_DND\0" |
|
264 |
"_NET_WM_WINDOW_TYPE_NORMAL\0" |
|
265 |
"_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0" |
|
266 |
||
267 |
"_KDE_NET_WM_FRAME_STRUT\0" |
|
268 |
||
269 |
"_NET_STARTUP_INFO\0" |
|
270 |
"_NET_STARTUP_INFO_BEGIN\0" |
|
271 |
||
272 |
"_NET_SUPPORTING_WM_CHECK\0" |
|
273 |
||
274 |
"_NET_WM_CM_S0\0" |
|
275 |
||
276 |
"_NET_SYSTEM_TRAY_VISUAL\0" |
|
277 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
278 |
"_NET_ACTIVE_WINDOW\0" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
279 |
|
0 | 280 |
// Property formats |
281 |
"COMPOUND_TEXT\0" |
|
282 |
"TEXT\0" |
|
283 |
"UTF8_STRING\0" |
|
284 |
||
285 |
// xdnd |
|
286 |
"XdndEnter\0" |
|
287 |
"XdndPosition\0" |
|
288 |
"XdndStatus\0" |
|
289 |
"XdndLeave\0" |
|
290 |
"XdndDrop\0" |
|
291 |
"XdndFinished\0" |
|
292 |
"XdndTypeList\0" |
|
293 |
"XdndActionList\0" |
|
294 |
||
295 |
"XdndSelection\0" |
|
296 |
||
297 |
"XdndAware\0" |
|
298 |
"XdndProxy\0" |
|
299 |
||
300 |
"XdndActionCopy\0" |
|
301 |
"XdndActionLink\0" |
|
302 |
"XdndActionMove\0" |
|
303 |
"XdndActionPrivate\0" |
|
304 |
||
305 |
// Motif DND |
|
306 |
"_MOTIF_DRAG_AND_DROP_MESSAGE\0" |
|
307 |
"_MOTIF_DRAG_INITIATOR_INFO\0" |
|
308 |
"_MOTIF_DRAG_RECEIVER_INFO\0" |
|
309 |
"_MOTIF_DRAG_WINDOW\0" |
|
310 |
"_MOTIF_DRAG_TARGETS\0" |
|
311 |
||
312 |
"XmTRANSFER_SUCCESS\0" |
|
313 |
"XmTRANSFER_FAILURE\0" |
|
314 |
||
315 |
// Xkb |
|
316 |
"_XKB_RULES_NAMES\0" |
|
317 |
||
318 |
// XEMBED |
|
319 |
"_XEMBED\0" |
|
320 |
"_XEMBED_INFO\0" |
|
321 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
322 |
// Wacom old. (before version 0.10) |
0 | 323 |
"Wacom Stylus\0" |
324 |
"Wacom Cursor\0" |
|
325 |
"Wacom Eraser\0" |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
326 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
327 |
// Tablet |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
328 |
"STYLUS\0" |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
329 |
"ERASER\0" |
0 | 330 |
}; |
331 |
||
332 |
Q_GUI_EXPORT QX11Data *qt_x11Data = 0; |
|
333 |
||
334 |
/***************************************************************************** |
|
335 |
Internal variables and functions |
|
336 |
*****************************************************************************/ |
|
337 |
static const char *appName = 0; // application name |
|
338 |
static const char *appClass = 0; // application class |
|
339 |
static const char *appFont = 0; // application font |
|
340 |
static const char *appBGCol = 0; // application bg color |
|
341 |
static const char *appFGCol = 0; // application fg color |
|
342 |
static const char *appBTNCol = 0; // application btn color |
|
343 |
static const char *mwGeometry = 0; // main widget geometry |
|
344 |
static const char *mwTitle = 0; // main widget title |
|
345 |
char *qt_ximServer = 0; // XIM Server will connect to |
|
346 |
static bool appSync = false; // X11 synchronization |
|
347 |
#if defined(QT_DEBUG) |
|
348 |
static bool appNoGrab = false; // X11 grabbing enabled |
|
349 |
static bool appDoGrab = false; // X11 grabbing override (gdb) |
|
350 |
#endif |
|
351 |
static bool app_save_rootinfo = false; // save root info |
|
352 |
static bool app_do_modal = false; // modal mode |
|
353 |
static Window curWin = 0; // current window |
|
354 |
||
355 |
||
356 |
// function to update the workarea of the screen - in qdesktopwidget_x11.cpp |
|
357 |
extern void qt_desktopwidget_update_workarea(); |
|
358 |
||
359 |
// Function to change the window manager state (from qwidget_x11.cpp) |
|
360 |
extern void qt_change_net_wm_state(const QWidget *w, bool set, Atom one, Atom two = 0); |
|
361 |
||
362 |
// modifier masks for alt, meta, super, hyper, and mode_switch - detected when the application starts |
|
363 |
// and/or keyboard layout changes |
|
364 |
uchar qt_alt_mask = 0; |
|
365 |
uchar qt_meta_mask = 0; |
|
366 |
uchar qt_super_mask = 0; |
|
367 |
uchar qt_hyper_mask = 0; |
|
368 |
uchar qt_mode_switch_mask = 0; |
|
369 |
||
370 |
// flags for extensions for special Languages, currently only for RTL languages |
|
371 |
bool qt_use_rtl_extensions = false; |
|
372 |
||
373 |
static Window mouseActWindow = 0; // window where mouse is |
|
374 |
static Qt::MouseButton mouseButtonPressed = Qt::NoButton; // last mouse button pressed |
|
375 |
static Qt::MouseButtons mouseButtonState = Qt::NoButton; // mouse button state |
|
376 |
static Time mouseButtonPressTime = 0; // when was a button pressed |
|
377 |
static short mouseXPos, mouseYPos; // mouse pres position in act window |
|
378 |
static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position |
|
379 |
||
380 |
extern QWidgetList *qt_modal_stack; // stack of modal widgets |
|
381 |
||
382 |
// window where mouse buttons have been pressed |
|
383 |
static Window pressed_window = XNone; |
|
384 |
||
385 |
// popup control |
|
386 |
static bool replayPopupMouseEvent = false; |
|
387 |
static bool popupGrabOk; |
|
388 |
||
389 |
bool qt_sm_blockUserInput = false; // session management |
|
390 |
||
391 |
Q_GUI_EXPORT int qt_xfocusout_grab_counter = 0; |
|
392 |
||
393 |
#if !defined (QT_NO_TABLET) |
|
394 |
Q_GLOBAL_STATIC(QTabletDeviceDataList, tablet_devices) |
|
395 |
QTabletDeviceDataList *qt_tablet_devices() |
|
396 |
{ |
|
397 |
return tablet_devices(); |
|
398 |
} |
|
399 |
||
400 |
extern bool qt_tabletChokeMouse; |
|
401 |
#endif |
|
402 |
||
403 |
static bool qt_x11EventFilter(XEvent* ev) |
|
404 |
{ |
|
405 |
long unused; |
|
406 |
if (qApp->filterEvent(ev, &unused)) |
|
407 |
return true; |
|
408 |
return qApp->x11EventFilter(ev); |
|
409 |
} |
|
410 |
||
411 |
#if !defined(QT_NO_XIM) |
|
412 |
XIMStyle qt_xim_preferred_style = 0; |
|
413 |
#endif |
|
414 |
int qt_ximComposingKeycode=0; |
|
415 |
QTextCodec * qt_input_mapper = 0; |
|
416 |
||
417 |
extern bool qt_check_clipboard_sentinel(); //def in qclipboard_x11.cpp |
|
418 |
extern bool qt_check_selection_sentinel(); //def in qclipboard_x11.cpp |
|
419 |
extern bool qt_xfixes_clipboard_changed(Window clipboardOwner, Time timestamp); //def in qclipboard_x11.cpp |
|
420 |
extern bool qt_xfixes_selection_changed(Window selectionOwner, Time timestamp); //def in qclipboard_x11.cpp |
|
421 |
||
422 |
static void qt_save_rootinfo(); |
|
423 |
Q_GUI_EXPORT bool qt_try_modal(QWidget *, XEvent *); |
|
424 |
||
425 |
QWidget *qt_button_down = 0; // last widget to be pressed with the mouse |
|
426 |
QPointer<QWidget> qt_last_mouse_receiver = 0; |
|
427 |
static QWidget *qt_popup_down = 0; // popup that contains the pressed widget |
|
428 |
||
429 |
extern bool qt_xdnd_dragging; |
|
430 |
||
431 |
// gui or non-gui from qapplication.cpp |
|
432 |
extern bool qt_is_gui_used; |
|
433 |
||
434 |
/*! |
|
435 |
\internal |
|
436 |
Try to resolve a \a symbol from \a library with the version specified |
|
437 |
by \a vernum. |
|
438 |
||
439 |
Note that, in the case of the Xfixes library, \a vernum is not the same as |
|
440 |
\c XFIXES_MAJOR - it is a part of soname and may differ from the Xfixes |
|
441 |
version. |
|
442 |
*/ |
|
443 |
static void* qt_load_library_runtime(const char *library, int vernum, |
|
444 |
int highestVernum, const char *symbol) |
|
445 |
{ |
|
446 |
QList<int> versions; |
|
447 |
// we try to load in the following order: |
|
448 |
// explicit version -> the default one -> (from the highest (highestVernum) to the lowest (vernum) ) |
|
449 |
if (vernum != -1) |
|
450 |
versions << vernum; |
|
451 |
versions << -1; |
|
452 |
if (vernum != -1) { |
|
453 |
for(int i = highestVernum; i > vernum; --i) |
|
454 |
versions << i; |
|
455 |
} |
|
456 |
Q_FOREACH(int version, versions) { |
|
457 |
QLatin1String libName(library); |
|
458 |
QLibrary xfixesLib(libName, version); |
|
459 |
if (xfixesLib.load()) { |
|
460 |
void *ptr = xfixesLib.resolve(symbol); |
|
461 |
if (ptr) |
|
462 |
return ptr; |
|
463 |
} |
|
464 |
} |
|
465 |
return 0; |
|
466 |
} |
|
467 |
||
468 |
#ifndef QT_NO_XINPUT |
|
469 |
# ifdef QT_RUNTIME_XINPUT |
|
470 |
# define XINPUT_LOAD_RUNTIME(vernum, symbol, symbol_type) \ |
|
471 |
(symbol_type)qt_load_library_runtime("libXi", vernum, 6, #symbol); |
|
472 |
# define XINPUT_LOAD(symbol) \ |
|
473 |
XINPUT_LOAD_RUNTIME(1, symbol, Ptr##symbol) |
|
474 |
# else // not runtime XInput |
|
475 |
# define XINPUT_LOAD(symbol) symbol |
|
476 |
# endif // QT_RUNTIME_XINPUT |
|
477 |
#else // not using Xinput at all |
|
478 |
# define XINPUT_LOAD(symbol) 0 |
|
479 |
#endif // QT_NO_XINPUT |
|
480 |
||
481 |
#ifndef QT_NO_XFIXES |
|
482 |
# ifdef QT_RUNTIME_XFIXES |
|
483 |
# define XFIXES_LOAD_RUNTIME(vernum, symbol, symbol_type) \ |
|
484 |
(symbol_type)qt_load_library_runtime("libXfixes", vernum, 4, #symbol); |
|
485 |
# define XFIXES_LOAD_V1(symbol) \ |
|
486 |
XFIXES_LOAD_RUNTIME(1, symbol, Ptr##symbol) |
|
487 |
# define XFIXES_LOAD_V2(symbol) \ |
|
488 |
XFIXES_LOAD_RUNTIME(2, symbol, Ptr##symbol) |
|
489 |
||
490 |
# else // not runtime Xfixes |
|
491 |
||
492 |
# if XFIXES_MAJOR >= 2 |
|
493 |
# define XFIXES_LOAD_V1(symbol) symbol |
|
494 |
# define XFIXES_LOAD_V2(symbol) symbol |
|
495 |
# elif XFIXES_MAJOR >= 1 |
|
496 |
# define XFIXES_LOAD_V1(symbol) symbol |
|
497 |
# define XFIXES_LOAD_V2(symbol) 0 |
|
498 |
# else |
|
499 |
# error Unsupported version of Xfixes |
|
500 |
# endif |
|
501 |
# endif // QT_RUNTIME_XFIXES |
|
502 |
#else // not using Xfixes at all |
|
503 |
# define XFIXES_LOAD_V1(symbol) 0 |
|
504 |
# define XFIXES_LOAD_V2(symbol) 0 |
|
505 |
#endif // QT_NO_XFIXES |
|
506 |
||
507 |
#ifndef QT_NO_XFIXES |
|
508 |
||
509 |
struct qt_xfixes_selection_event_data |
|
510 |
{ |
|
511 |
// which selection to filter out. |
|
512 |
Atom selection; |
|
513 |
}; |
|
514 |
||
515 |
#if defined(Q_C_CALLBACKS) |
|
516 |
extern "C" { |
|
517 |
#endif |
|
518 |
||
519 |
static Bool qt_xfixes_scanner(Display*, XEvent *event, XPointer arg) |
|
520 |
{ |
|
521 |
qt_xfixes_selection_event_data *data = |
|
522 |
reinterpret_cast<qt_xfixes_selection_event_data*>(arg); |
|
523 |
if (event->type == X11->xfixes_eventbase + XFixesSelectionNotify) { |
|
524 |
XFixesSelectionNotifyEvent *xfixes_event = reinterpret_cast<XFixesSelectionNotifyEvent*>(event); |
|
525 |
if (xfixes_event->selection == data->selection) |
|
526 |
return true; |
|
527 |
} |
|
528 |
return false; |
|
529 |
} |
|
530 |
||
531 |
#if defined(Q_C_CALLBACKS) |
|
532 |
} |
|
533 |
#endif |
|
534 |
||
535 |
#endif // QT_NO_XFIXES |
|
536 |
||
537 |
class QETWidget : public QWidget // event translator widget |
|
538 |
{ |
|
539 |
public: |
|
540 |
QWidgetPrivate* d_func() { return QWidget::d_func(); } |
|
541 |
bool translateMouseEvent(const XEvent *); |
|
542 |
void translatePaintEvent(const XEvent *); |
|
543 |
bool translateConfigEvent(const XEvent *); |
|
544 |
bool translateCloseEvent(const XEvent *); |
|
545 |
bool translateScrollDoneEvent(const XEvent *); |
|
546 |
bool translateWheelEvent(int global_x, int global_y, int delta, Qt::MouseButtons buttons, |
|
547 |
Qt::KeyboardModifiers modifiers, Qt::Orientation orient); |
|
548 |
#if !defined (QT_NO_TABLET) |
|
549 |
bool translateXinputEvent(const XEvent*, QTabletDeviceData *tablet); |
|
550 |
#endif |
|
551 |
bool translatePropertyEvent(const XEvent *); |
|
552 |
||
553 |
void doDeferredMap() |
|
554 |
{ |
|
555 |
Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
556 |
if (!testAttribute(Qt::WA_Resized)) { |
|
557 |
adjustSize(); |
|
558 |
setAttribute(Qt::WA_Resized, false); |
|
559 |
} |
|
560 |
||
561 |
/* |
|
562 |
workaround for WM's that throw away ConfigureRequests from the following: |
|
563 |
||
564 |
window->hide(); |
|
565 |
window->move(x, y); // could also be resize(), move()+resize(), or setGeometry() |
|
566 |
window->show(); |
|
567 |
*/ |
|
568 |
QRect r = geometry(); |
|
569 |
||
570 |
XMoveResizeWindow(X11->display, |
|
571 |
internalWinId(), |
|
572 |
r.x(), |
|
573 |
r.y(), |
|
574 |
r.width(), |
|
575 |
r.height()); |
|
576 |
||
577 |
// static gravity! |
|
578 |
XSizeHints sh; |
|
579 |
long unused; |
|
580 |
XGetWMNormalHints(X11->display, internalWinId(), &sh, &unused); |
|
581 |
sh.flags |= USPosition | PPosition | USSize | PSize | PWinGravity; |
|
582 |
sh.x = r.x(); |
|
583 |
sh.y = r.y(); |
|
584 |
sh.width = r.width(); |
|
585 |
sh.height = r.height(); |
|
586 |
sh.win_gravity = StaticGravity; |
|
587 |
XSetWMNormalHints(X11->display, internalWinId(), &sh); |
|
588 |
||
589 |
setAttribute(Qt::WA_Mapped); |
|
590 |
if (testAttribute(Qt::WA_DontShowOnScreen)) |
|
591 |
return; |
|
592 |
d_func()->topData()->waitingForMapNotify = 1; |
|
593 |
XMapWindow(X11->display, internalWinId()); |
|
594 |
} |
|
595 |
}; |
|
596 |
||
597 |
||
598 |
void QApplicationPrivate::createEventDispatcher() |
|
599 |
{ |
|
600 |
Q_Q(QApplication); |
|
601 |
#if !defined(QT_NO_GLIB) |
|
602 |
if (qgetenv("QT_NO_GLIB").isEmpty() && QEventDispatcherGlib::versionSupported()) |
|
603 |
eventDispatcher = (q->type() != QApplication::Tty |
|
604 |
? new QGuiEventDispatcherGlib(q) |
|
605 |
: new QEventDispatcherGlib(q)); |
|
606 |
else |
|
607 |
#endif |
|
608 |
eventDispatcher = (q->type() != QApplication::Tty |
|
609 |
? new QEventDispatcherX11(q) |
|
610 |
: new QEventDispatcherUNIX(q)); |
|
611 |
} |
|
612 |
||
613 |
/***************************************************************************** |
|
614 |
Default X error handlers |
|
615 |
*****************************************************************************/ |
|
616 |
||
617 |
#if defined(Q_C_CALLBACKS) |
|
618 |
extern "C" { |
|
619 |
#endif |
|
620 |
||
621 |
static int (*original_x_errhandler)(Display *dpy, XErrorEvent *); |
|
622 |
static int (*original_xio_errhandler)(Display *dpy); |
|
623 |
||
624 |
static int qt_x_errhandler(Display *dpy, XErrorEvent *err) |
|
625 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
626 |
if (X11->display != dpy) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
627 |
// only handle X errors for our display |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
628 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
629 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
630 |
|
0 | 631 |
switch (err->error_code) { |
632 |
case BadAtom: |
|
633 |
if (err->request_code == 20 /* X_GetProperty */ |
|
634 |
&& (err->resourceid == XA_RESOURCE_MANAGER |
|
635 |
|| err->resourceid == XA_RGB_DEFAULT_MAP |
|
636 |
|| err->resourceid == ATOM(_NET_SUPPORTED) |
|
637 |
|| err->resourceid == ATOM(_NET_SUPPORTING_WM_CHECK) |
|
638 |
|| err->resourceid == ATOM(XdndProxy) |
|
639 |
|| err->resourceid == ATOM(XdndAware))) { |
|
640 |
// Perhaps we're running under SECURITY reduction? :/ |
|
641 |
return 0; |
|
642 |
} |
|
643 |
break; |
|
644 |
||
645 |
case BadWindow: |
|
646 |
if (err->request_code == 2 /* X_ChangeWindowAttributes */ |
|
647 |
|| err->request_code == 38 /* X_QueryPointer */) { |
|
648 |
for (int i = 0; i < ScreenCount(dpy); ++i) { |
|
649 |
if (err->resourceid == RootWindow(dpy, i)) { |
|
650 |
// Perhaps we're running under SECURITY reduction? :/ |
|
651 |
return 0; |
|
652 |
} |
|
653 |
} |
|
654 |
} |
|
655 |
X11->seen_badwindow = true; |
|
656 |
if (err->request_code == 25 /* X_SendEvent */) { |
|
657 |
for (int i = 0; i < ScreenCount(dpy); ++i) { |
|
658 |
if (err->resourceid == RootWindow(dpy, i)) { |
|
659 |
// Perhaps we're running under SECURITY reduction? :/ |
|
660 |
return 0; |
|
661 |
} |
|
662 |
} |
|
663 |
if (X11->xdndHandleBadwindow()) { |
|
664 |
qDebug("xdndHandleBadwindow returned true"); |
|
665 |
return 0; |
|
666 |
} |
|
667 |
} |
|
668 |
if (X11->ignore_badwindow) |
|
669 |
return 0; |
|
670 |
break; |
|
671 |
||
672 |
default: |
|
673 |
#if !defined(QT_NO_XINPUT) |
|
674 |
if (err->request_code == X11->xinput_major |
|
675 |
&& err->error_code == (X11->xinput_errorbase + XI_BadDevice) |
|
676 |
&& err->minor_code == 3 /* X_OpenDevice */) { |
|
677 |
return 0; |
|
678 |
} |
|
679 |
#endif |
|
680 |
break; |
|
681 |
} |
|
682 |
||
683 |
char errstr[256]; |
|
684 |
XGetErrorText( dpy, err->error_code, errstr, 256 ); |
|
685 |
char buffer[256]; |
|
686 |
char request_str[256]; |
|
687 |
qsnprintf(buffer, 256, "%d", err->request_code); |
|
688 |
XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, 256); |
|
689 |
if (err->request_code < 128) { |
|
690 |
// X error for a normal protocol request |
|
691 |
qWarning( "X Error: %s %d\n" |
|
692 |
" Major opcode: %d (%s)\n" |
|
693 |
" Resource id: 0x%lx", |
|
694 |
errstr, err->error_code, |
|
695 |
err->request_code, |
|
696 |
request_str, |
|
697 |
err->resourceid ); |
|
698 |
} else { |
|
699 |
// X error for an extension request |
|
700 |
const char *extensionName = 0; |
|
701 |
if (err->request_code == X11->xrender_major) |
|
702 |
extensionName = "RENDER"; |
|
703 |
else if (err->request_code == X11->xrandr_major) |
|
704 |
extensionName = "RANDR"; |
|
705 |
else if (err->request_code == X11->xinput_major) |
|
706 |
extensionName = "XInputExtension"; |
|
707 |
else if (err->request_code == X11->mitshm_major) |
|
708 |
extensionName = "MIT-SHM"; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
709 |
#ifndef QT_NO_XKB |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
710 |
else if(err->request_code == X11->xkb_major) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
711 |
extensionName = "XKEYBOARD"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
712 |
#endif |
0 | 713 |
|
714 |
char minor_str[256]; |
|
715 |
if (extensionName) { |
|
716 |
qsnprintf(buffer, 256, "%s.%d", extensionName, err->minor_code); |
|
717 |
XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, 256); |
|
718 |
} else { |
|
719 |
extensionName = "Uknown extension"; |
|
720 |
qsnprintf(minor_str, 256, "Unknown request"); |
|
721 |
} |
|
722 |
qWarning( "X Error: %s %d\n" |
|
723 |
" Extension: %d (%s)\n" |
|
724 |
" Minor opcode: %d (%s)\n" |
|
725 |
" Resource id: 0x%lx", |
|
726 |
errstr, err->error_code, |
|
727 |
err->request_code, |
|
728 |
extensionName, |
|
729 |
err->minor_code, |
|
730 |
minor_str, |
|
731 |
err->resourceid ); |
|
732 |
} |
|
733 |
||
734 |
// ### we really should distinguish between severe, non-severe and |
|
735 |
// ### application specific errors |
|
736 |
||
737 |
return 0; |
|
738 |
} |
|
739 |
||
740 |
||
741 |
static int qt_xio_errhandler(Display *) |
|
742 |
{ |
|
743 |
qWarning("%s: Fatal IO error: client killed", appName); |
|
744 |
QApplicationPrivate::reset_instance_pointer(); |
|
745 |
exit(1); |
|
746 |
//### give the application a chance for a proper shutdown instead, |
|
747 |
//### exit(1) doesn't help. |
|
748 |
return 0; |
|
749 |
} |
|
750 |
||
751 |
#if defined(Q_C_CALLBACKS) |
|
752 |
} |
|
753 |
#endif |
|
754 |
||
755 |
#ifndef QT_NO_XSYNC |
|
756 |
struct qt_sync_request_event_data |
|
757 |
{ |
|
758 |
WId window; |
|
759 |
}; |
|
760 |
||
761 |
#if defined(Q_C_CALLBACKS) |
|
762 |
extern "C" { |
|
763 |
#endif |
|
764 |
||
765 |
static Bool qt_sync_request_scanner(Display*, XEvent *event, XPointer arg) |
|
766 |
{ |
|
767 |
qt_sync_request_event_data *data = |
|
768 |
reinterpret_cast<qt_sync_request_event_data*>(arg); |
|
769 |
if (event->type == ClientMessage && |
|
770 |
event->xany.window == data->window && |
|
771 |
event->xclient.message_type == ATOM(WM_PROTOCOLS) && |
|
772 |
(Atom)event->xclient.data.l[0] == ATOM(_NET_WM_SYNC_REQUEST)) { |
|
773 |
QWidget *w = QWidget::find(event->xany.window); |
|
774 |
if (QTLWExtra *tlw = ((QETWidget*)w)->d_func()->maybeTopData()) { |
|
775 |
const ulong timestamp = (const ulong) event->xclient.data.l[1]; |
|
776 |
if (timestamp > X11->time) |
|
777 |
X11->time = timestamp; |
|
778 |
if (timestamp == CurrentTime || timestamp > tlw->syncRequestTimestamp) { |
|
779 |
tlw->syncRequestTimestamp = timestamp; |
|
780 |
tlw->newCounterValueLo = event->xclient.data.l[2]; |
|
781 |
tlw->newCounterValueHi = event->xclient.data.l[3]; |
|
782 |
} |
|
783 |
} |
|
784 |
return true; |
|
785 |
} |
|
786 |
return false; |
|
787 |
} |
|
788 |
||
789 |
#if defined(Q_C_CALLBACKS) |
|
790 |
} |
|
791 |
#endif |
|
792 |
#endif // QT_NO_XSYNC |
|
793 |
||
794 |
static void qt_x11_create_intern_atoms() |
|
795 |
{ |
|
796 |
const char *names[QX11Data::NAtoms]; |
|
797 |
const char *ptr = x11_atomnames; |
|
798 |
||
799 |
int i = 0; |
|
800 |
while (*ptr) { |
|
801 |
names[i++] = ptr; |
|
802 |
while (*ptr) |
|
803 |
++ptr; |
|
804 |
++ptr; |
|
805 |
} |
|
806 |
||
807 |
Q_ASSERT(i == QX11Data::NPredefinedAtoms); |
|
808 |
||
809 |
QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_"); |
|
810 |
settings_atom_name += XDisplayName(X11->displayName); |
|
811 |
names[i++] = settings_atom_name; |
|
812 |
||
813 |
Q_ASSERT(i == QX11Data::NAtoms); |
|
814 |
#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6) |
|
815 |
XInternAtoms(X11->display, (char **)names, i, False, X11->atoms); |
|
816 |
#else |
|
817 |
for (i = 0; i < QX11Data::NAtoms; ++i) |
|
818 |
X11->atoms[i] = XInternAtom(X11->display, (char *)names[i], False); |
|
819 |
#endif |
|
820 |
} |
|
821 |
||
822 |
Q_GUI_EXPORT void qt_x11_apply_settings_in_all_apps() |
|
823 |
{ |
|
824 |
QByteArray stamp; |
|
825 |
QDataStream s(&stamp, QIODevice::WriteOnly); |
|
826 |
s << QDateTime::currentDateTime(); |
|
827 |
||
828 |
XChangeProperty(QX11Info::display(), QX11Info::appRootWindow(0), |
|
829 |
ATOM(_QT_SETTINGS_TIMESTAMP), ATOM(_QT_SETTINGS_TIMESTAMP), 8, |
|
830 |
PropModeReplace, (unsigned char *)stamp.data(), stamp.size()); |
|
831 |
} |
|
832 |
||
833 |
/*! \internal |
|
834 |
apply the settings to the application |
|
835 |
*/ |
|
836 |
bool QApplicationPrivate::x11_apply_settings() |
|
837 |
{ |
|
838 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); |
|
839 |
||
840 |
settings.beginGroup(QLatin1String("Qt")); |
|
841 |
||
842 |
/* |
|
843 |
Qt settings. This is now they are written into the datastream. |
|
844 |
||
845 |
Palette / * - QPalette |
|
846 |
font - QFont |
|
847 |
libraryPath - QStringList |
|
848 |
style - QString |
|
849 |
doubleClickInterval - int |
|
850 |
keyboardInputInterval - int |
|
851 |
cursorFlashTime - int |
|
852 |
wheelScrollLines - int |
|
853 |
colorSpec - QString |
|
854 |
defaultCodec - QString |
|
855 |
globalStrut/width - int |
|
856 |
globalStrut/height - int |
|
857 |
GUIEffects - QStringList |
|
858 |
Font Substitutions/ * - QStringList |
|
859 |
Font Substitutions/... - QStringList |
|
860 |
*/ |
|
861 |
||
862 |
QStringList strlist; |
|
863 |
int i; |
|
864 |
QPalette pal(Qt::black); |
|
865 |
int groupCount = 0; |
|
866 |
strlist = settings.value(QLatin1String("Palette/active")).toStringList(); |
|
867 |
if (!strlist.isEmpty()) { |
|
868 |
++groupCount; |
|
869 |
for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++) |
|
870 |
pal.setColor(QPalette::Active, (QPalette::ColorRole) i, |
|
871 |
QColor(strlist[i])); |
|
872 |
} |
|
873 |
strlist = settings.value(QLatin1String("Palette/inactive")).toStringList(); |
|
874 |
if (!strlist.isEmpty()) { |
|
875 |
++groupCount; |
|
876 |
for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++) |
|
877 |
pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i, |
|
878 |
QColor(strlist[i])); |
|
879 |
} |
|
880 |
strlist = settings.value(QLatin1String("Palette/disabled")).toStringList(); |
|
881 |
if (!strlist.isEmpty()) { |
|
882 |
++groupCount; |
|
883 |
for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++) |
|
884 |
pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i, |
|
885 |
QColor(strlist[i])); |
|
886 |
} |
|
887 |
||
888 |
// ### Fix properly for 4.6 |
|
889 |
bool usingGtkSettings = QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle"); |
|
890 |
if (!usingGtkSettings) { |
|
891 |
if (groupCount == QPalette::NColorGroups) |
|
892 |
QApplicationPrivate::setSystemPalette(pal); |
|
893 |
} |
|
894 |
||
895 |
if (!appFont) { |
|
896 |
// ### Fix properly for 4.6 |
|
897 |
if (!usingGtkSettings) { |
|
898 |
QFont font(QApplication::font()); |
|
899 |
QString fontDescription; |
|
900 |
// Override Qt font if KDE4 settings can be used |
|
901 |
if (X11->desktopVersion == 4) { |
|
902 |
QSettings kdeSettings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat); |
|
903 |
fontDescription = kdeSettings.value(QLatin1String("font")).toString(); |
|
904 |
if (fontDescription.isEmpty()) { |
|
905 |
// KDE stores fonts without quotes |
|
906 |
fontDescription = kdeSettings.value(QLatin1String("font")).toStringList().join(QLatin1String(",")); |
|
907 |
} |
|
908 |
} |
|
909 |
if (fontDescription.isEmpty()) |
|
910 |
fontDescription = settings.value(QLatin1String("font")).toString(); |
|
911 |
if (!fontDescription .isEmpty()) { |
|
912 |
font.fromString(fontDescription ); |
|
913 |
QApplicationPrivate::setSystemFont(font); |
|
914 |
} |
|
915 |
} |
|
916 |
} |
|
917 |
||
918 |
// read library (ie. plugin) path list |
|
919 |
QString libpathkey = |
|
920 |
QString::fromLatin1("%1.%2/libraryPath") |
|
921 |
.arg(QT_VERSION >> 16) |
|
922 |
.arg((QT_VERSION & 0xff00) >> 8); |
|
923 |
QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':')); |
|
924 |
if (! pathlist.isEmpty()) { |
|
925 |
QStringList::ConstIterator it = pathlist.constBegin(); |
|
926 |
while (it != pathlist.constEnd()) |
|
927 |
QApplication::addLibraryPath(*it++); |
|
928 |
} |
|
929 |
||
930 |
// read new QStyle |
|
931 |
QString stylename = settings.value(QLatin1String("style")).toString(); |
|
932 |
||
933 |
if (stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull() && X11->use_xrender) { |
|
934 |
stylename = qt_guiPlatformPlugin()->styleName(); |
|
935 |
} |
|
936 |
||
937 |
static QString currentStyleName = stylename; |
|
938 |
if (QCoreApplication::startingUp()) { |
|
939 |
if (!stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull()) |
|
940 |
QApplicationPrivate::styleOverride = stylename; |
|
941 |
} else { |
|
942 |
if (currentStyleName != stylename) { |
|
943 |
currentStyleName = stylename; |
|
944 |
QApplication::setStyle(stylename); |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
int num = |
|
949 |
settings.value(QLatin1String("doubleClickInterval"), |
|
950 |
QApplication::doubleClickInterval()).toInt(); |
|
951 |
QApplication::setDoubleClickInterval(num); |
|
952 |
||
953 |
num = |
|
954 |
settings.value(QLatin1String("cursorFlashTime"), |
|
955 |
QApplication::cursorFlashTime()).toInt(); |
|
956 |
QApplication::setCursorFlashTime(num); |
|
957 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
958 |
#ifndef QT_NO_WHEELEVENT |
0 | 959 |
num = |
960 |
settings.value(QLatin1String("wheelScrollLines"), |
|
961 |
QApplication::wheelScrollLines()).toInt(); |
|
962 |
QApplication::setWheelScrollLines(num); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
963 |
#endif |
0 | 964 |
|
965 |
QString colorspec = settings.value(QLatin1String("colorSpec"), |
|
966 |
QVariant(QLatin1String("default"))).toString(); |
|
967 |
if (colorspec == QLatin1String("normal")) |
|
968 |
QApplication::setColorSpec(QApplication::NormalColor); |
|
969 |
else if (colorspec == QLatin1String("custom")) |
|
970 |
QApplication::setColorSpec(QApplication::CustomColor); |
|
971 |
else if (colorspec == QLatin1String("many")) |
|
972 |
QApplication::setColorSpec(QApplication::ManyColor); |
|
973 |
else if (colorspec != QLatin1String("default")) |
|
974 |
colorspec = QLatin1String("default"); |
|
975 |
||
976 |
QString defaultcodec = settings.value(QLatin1String("defaultCodec"), |
|
977 |
QVariant(QLatin1String("none"))).toString(); |
|
978 |
if (defaultcodec != QLatin1String("none")) { |
|
979 |
QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1()); |
|
980 |
if (codec) |
|
981 |
QTextCodec::setCodecForTr(codec); |
|
982 |
} |
|
983 |
||
984 |
int w = settings.value(QLatin1String("globalStrut/width")).toInt(); |
|
985 |
int h = settings.value(QLatin1String("globalStrut/height")).toInt(); |
|
986 |
QSize strut(w, h); |
|
987 |
if (strut.isValid()) |
|
988 |
QApplication::setGlobalStrut(strut); |
|
989 |
||
990 |
QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList(); |
|
991 |
QApplication::setEffectEnabled(Qt::UI_General, |
|
992 |
effects.contains(QLatin1String("general"))); |
|
993 |
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, |
|
994 |
effects.contains(QLatin1String("animatemenu"))); |
|
995 |
QApplication::setEffectEnabled(Qt::UI_FadeMenu, |
|
996 |
effects.contains(QLatin1String("fademenu"))); |
|
997 |
QApplication::setEffectEnabled(Qt::UI_AnimateCombo, |
|
998 |
effects.contains(QLatin1String("animatecombo"))); |
|
999 |
QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, |
|
1000 |
effects.contains(QLatin1String("animatetooltip"))); |
|
1001 |
QApplication::setEffectEnabled(Qt::UI_FadeTooltip, |
|
1002 |
effects.contains(QLatin1String("fadetooltip"))); |
|
1003 |
QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, |
|
1004 |
effects.contains(QLatin1String("animatetoolbox"))); |
|
1005 |
||
1006 |
if (!X11->has_fontconfig) { |
|
1007 |
settings.beginGroup(QLatin1String("Font Substitutions")); |
|
1008 |
QStringList fontsubs = settings.childKeys(); |
|
1009 |
if (!fontsubs.isEmpty()) { |
|
1010 |
QStringList::Iterator it = fontsubs.begin(); |
|
1011 |
for (; it != fontsubs.end(); ++it) { |
|
1012 |
QString fam = *it; |
|
1013 |
QStringList subs = settings.value(fam).toStringList(); |
|
1014 |
QFont::insertSubstitutions(fam, subs); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
settings.endGroup(); |
|
1018 |
} |
|
1019 |
||
1020 |
qt_use_rtl_extensions = |
|
1021 |
settings.value(QLatin1String("useRtlExtensions"), false).toBool(); |
|
1022 |
||
1023 |
#ifndef QT_NO_XIM |
|
1024 |
if (qt_xim_preferred_style == 0) { |
|
1025 |
QString ximInputStyle = settings.value(QLatin1String("XIMInputStyle"), |
|
1026 |
QVariant(QLatin1String("on the spot"))).toString().toLower(); |
|
1027 |
if (ximInputStyle == QLatin1String("on the spot")) |
|
1028 |
qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing; |
|
1029 |
else if (ximInputStyle == QLatin1String("over the spot")) |
|
1030 |
qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing; |
|
1031 |
else if (ximInputStyle == QLatin1String("off the spot")) |
|
1032 |
qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea; |
|
1033 |
else if (ximInputStyle == QLatin1String("root")) |
|
1034 |
qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing; |
|
1035 |
} |
|
1036 |
#endif |
|
1037 |
QStringList inputMethods = QInputContextFactory::keys(); |
|
1038 |
if (inputMethods.size() > 2 && inputMethods.contains(QLatin1String("imsw-multi"))) { |
|
1039 |
X11->default_im = QLatin1String("imsw-multi"); |
|
1040 |
} else { |
|
1041 |
X11->default_im = settings.value(QLatin1String("DefaultInputMethod"), |
|
1042 |
QLatin1String("xim")).toString(); |
|
1043 |
} |
|
1044 |
||
1045 |
settings.endGroup(); // Qt |
|
1046 |
||
1047 |
return true; |
|
1048 |
} |
|
1049 |
||
1050 |
||
1051 |
/*! \internal |
|
1052 |
Resets the QApplication::instance() pointer to zero |
|
1053 |
*/ |
|
1054 |
void QApplicationPrivate::reset_instance_pointer() |
|
1055 |
{ QApplication::self = 0; } |
|
1056 |
||
1057 |
||
1058 |
// read the _QT_INPUT_ENCODING property and apply the settings to |
|
1059 |
// the application |
|
1060 |
static void qt_set_input_encoding() |
|
1061 |
{ |
|
1062 |
Atom type; |
|
1063 |
int format; |
|
1064 |
ulong nitems, after = 1; |
|
1065 |
unsigned char *data = 0; |
|
1066 |
||
1067 |
int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
1068 |
ATOM(_QT_INPUT_ENCODING), 0, 1024, |
|
1069 |
False, XA_STRING, &type, &format, &nitems, |
|
1070 |
&after, &data); |
|
1071 |
if (e != Success || !nitems || type == XNone) { |
|
1072 |
// Always use the locale codec, since we have no examples of non-local |
|
1073 |
// XIMs, and since we cannot get a sensible answer about the encoding |
|
1074 |
// from the XIM. |
|
1075 |
qt_input_mapper = QTextCodec::codecForLocale(); |
|
1076 |
||
1077 |
} else { |
|
1078 |
if (!qstricmp((char *)data, "locale")) |
|
1079 |
qt_input_mapper = QTextCodec::codecForLocale(); |
|
1080 |
else |
|
1081 |
qt_input_mapper = QTextCodec::codecForName((char *)data); |
|
1082 |
// make sure we have an input codec |
|
1083 |
if(!qt_input_mapper) |
|
1084 |
qt_input_mapper = QTextCodec::codecForName("ISO 8859-1"); |
|
1085 |
} |
|
1086 |
if (qt_input_mapper && qt_input_mapper->mibEnum() == 11) // 8859-8 |
|
1087 |
qt_input_mapper = QTextCodec::codecForName("ISO 8859-8-I"); |
|
1088 |
if(data) |
|
1089 |
XFree((char *)data); |
|
1090 |
} |
|
1091 |
||
1092 |
// set font, foreground and background from x11 resources. The |
|
1093 |
// arguments may override the resource settings. |
|
1094 |
static void qt_set_x11_resources(const char* font = 0, const char* fg = 0, |
|
1095 |
const char* bg = 0, const char* button = 0) |
|
1096 |
{ |
|
1097 |
||
1098 |
QString resFont, resFG, resBG, resButton, resEF, sysFont, selectBackground, selectForeground; |
|
1099 |
||
1100 |
QApplication::setEffectEnabled(Qt::UI_General, false); |
|
1101 |
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); |
|
1102 |
QApplication::setEffectEnabled(Qt::UI_FadeMenu, false); |
|
1103 |
QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); |
|
1104 |
QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false); |
|
1105 |
QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false); |
|
1106 |
QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, false); |
|
1107 |
||
1108 |
bool paletteAlreadySet = false; |
|
1109 |
if (QApplication::desktopSettingsAware()) { |
|
1110 |
// first, read from settings |
|
1111 |
QApplicationPrivate::x11_apply_settings(); |
|
1112 |
// the call to QApplication::style() below creates the system |
|
1113 |
// palette, which breaks the logic after the RESOURCE_MANAGER |
|
1114 |
// loop... so I have to save this value to be able to use it later |
|
1115 |
paletteAlreadySet = (QApplicationPrivate::sys_pal != 0); |
|
1116 |
||
1117 |
// second, parse the RESOURCE_MANAGER property |
|
1118 |
int format; |
|
1119 |
ulong nitems, after = 1; |
|
1120 |
QString res; |
|
1121 |
long offset = 0; |
|
1122 |
Atom type = XNone; |
|
1123 |
||
1124 |
while (after > 0) { |
|
1125 |
uchar *data = 0; |
|
1126 |
if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(0), |
|
1127 |
ATOM(RESOURCE_MANAGER), |
|
1128 |
offset, 8192, False, AnyPropertyType, |
|
1129 |
&type, &format, &nitems, &after, |
|
1130 |
&data) != Success) { |
|
1131 |
res = QString(); |
|
1132 |
break; |
|
1133 |
} |
|
1134 |
if (type == XA_STRING) |
|
1135 |
res += QString::fromLatin1((char*)data); |
|
1136 |
else |
|
1137 |
res += QString::fromLocal8Bit((char*)data); |
|
1138 |
offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048 |
|
1139 |
if (data) |
|
1140 |
XFree((char *)data); |
|
1141 |
} |
|
1142 |
||
1143 |
QString key, value; |
|
1144 |
int l = 0, r; |
|
1145 |
QString apn = QString::fromLocal8Bit(appName); |
|
1146 |
QString apc = QString::fromLocal8Bit(appClass); |
|
1147 |
int apnl = apn.length(); |
|
1148 |
int apcl = apc.length(); |
|
1149 |
int resl = res.length(); |
|
1150 |
||
1151 |
while (l < resl) { |
|
1152 |
r = res.indexOf(QLatin1Char('\n'), l); |
|
1153 |
if (r < 0) |
|
1154 |
r = resl; |
|
1155 |
while (res.at(l).isSpace()) |
|
1156 |
l++; |
|
1157 |
bool mine = false; |
|
1158 |
QChar sc = res.at(l + 1); |
|
1159 |
if (res.at(l) == QLatin1Char('*') && |
|
1160 |
(sc == QLatin1Char('f') || sc == QLatin1Char('b') || sc == QLatin1Char('g') || |
|
1161 |
sc == QLatin1Char('F') || sc == QLatin1Char('B') || sc == QLatin1Char('G') || |
|
1162 |
sc == QLatin1Char('s') || sc == QLatin1Char('S') |
|
1163 |
// capital T only, since we're looking for "Text.selectSomething" |
|
1164 |
|| sc == QLatin1Char('T'))) { |
|
1165 |
// OPTIMIZED, since we only want "*[fbgsT].." |
|
1166 |
QString item = res.mid(l, r - l).simplified(); |
|
1167 |
int i = item.indexOf(QLatin1Char(':')); |
|
1168 |
key = item.left(i).trimmed().mid(1).toLower(); |
|
1169 |
value = item.right(item.length() - i - 1).trimmed(); |
|
1170 |
mine = true; |
|
1171 |
} else if ((apnl && res.at(l) == apn.at(0)) || (appClass && apcl && res.at(l) == apc.at(0))) { |
|
1172 |
if (res.mid(l,apnl) == apn && (res.at(l+apnl) == QLatin1Char('.') |
|
1173 |
|| res.at(l+apnl) == QLatin1Char('*'))) { |
|
1174 |
QString item = res.mid(l, r - l).simplified(); |
|
1175 |
int i = item.indexOf(QLatin1Char(':')); |
|
1176 |
key = item.left(i).trimmed().mid(apnl+1).toLower(); |
|
1177 |
value = item.right(item.length() - i - 1).trimmed(); |
|
1178 |
mine = true; |
|
1179 |
} else if (res.mid(l,apcl) == apc && (res.at(l+apcl) == QLatin1Char('.') |
|
1180 |
|| res.at(l+apcl) == QLatin1Char('*'))) { |
|
1181 |
QString item = res.mid(l, r - l).simplified(); |
|
1182 |
int i = item.indexOf(QLatin1Char(':')); |
|
1183 |
key = item.left(i).trimmed().mid(apcl+1).toLower(); |
|
1184 |
value = item.right(item.length() - i - 1).trimmed(); |
|
1185 |
mine = true; |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
if (mine) { |
|
1190 |
if (!font && key == QLatin1String("systemfont")) |
|
1191 |
sysFont = value.left(value.lastIndexOf(QLatin1Char(':'))); |
|
1192 |
if (!font && key == QLatin1String("font")) |
|
1193 |
resFont = value; |
|
1194 |
else if (!fg && !paletteAlreadySet) { |
|
1195 |
if (key == QLatin1String("foreground")) |
|
1196 |
resFG = value; |
|
1197 |
else if (!bg && key == QLatin1String("background")) |
|
1198 |
resBG = value; |
|
1199 |
else if (!bg && !button && key == QLatin1String("button.background")) |
|
1200 |
resButton = value; |
|
1201 |
else if (key == QLatin1String("text.selectbackground")) { |
|
1202 |
selectBackground = value; |
|
1203 |
} else if (key == QLatin1String("text.selectforeground")) { |
|
1204 |
selectForeground = value; |
|
1205 |
} |
|
1206 |
} else if (key == QLatin1String("guieffects")) |
|
1207 |
resEF = value; |
|
1208 |
// NOTE: if you add more, change the [fbg] stuff above |
|
1209 |
} |
|
1210 |
||
1211 |
l = r + 1; |
|
1212 |
} |
|
1213 |
} |
|
1214 |
if (!sysFont.isEmpty()) |
|
1215 |
resFont = sysFont; |
|
1216 |
if (resFont.isEmpty()) |
|
1217 |
resFont = QString::fromLocal8Bit(font); |
|
1218 |
if (resFG.isEmpty()) |
|
1219 |
resFG = QString::fromLocal8Bit(fg); |
|
1220 |
if (resBG.isEmpty()) |
|
1221 |
resBG = QString::fromLocal8Bit(bg); |
|
1222 |
if (resButton.isEmpty()) |
|
1223 |
resButton = QString::fromLocal8Bit(button); |
|
1224 |
if (!resFont.isEmpty() |
|
1225 |
&& !X11->has_fontconfig |
|
1226 |
&& !QApplicationPrivate::sys_font) { |
|
1227 |
// set application font |
|
1228 |
QFont fnt; |
|
1229 |
fnt.setRawName(resFont); |
|
1230 |
||
1231 |
// the font we get may actually be an alias for another font, |
|
1232 |
// so we reset the application font to the real font info. |
|
1233 |
if (! fnt.exactMatch()) { |
|
1234 |
QFontInfo fontinfo(fnt); |
|
1235 |
fnt.setFamily(fontinfo.family()); |
|
1236 |
fnt.setRawMode(fontinfo.rawMode()); |
|
1237 |
||
1238 |
if (! fnt.rawMode()) { |
|
1239 |
fnt.setItalic(fontinfo.italic()); |
|
1240 |
fnt.setWeight(fontinfo.weight()); |
|
1241 |
fnt.setUnderline(fontinfo.underline()); |
|
1242 |
fnt.setStrikeOut(fontinfo.strikeOut()); |
|
1243 |
fnt.setStyleHint(fontinfo.styleHint()); |
|
1244 |
||
1245 |
if (fnt.pointSize() <= 0 && fnt.pixelSize() <= 0) { |
|
1246 |
// size is all wrong... fix it |
|
1247 |
qreal pointSize = fontinfo.pixelSize() * 72. / (float) QX11Info::appDpiY(); |
|
1248 |
if (pointSize <= 0) |
|
1249 |
pointSize = 12; |
|
1250 |
fnt.setPointSize(qRound(pointSize)); |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |
|
1254 |
||
1255 |
QApplicationPrivate::setSystemFont(fnt); |
|
1256 |
} |
|
1257 |
// QGtkStyle sets it's own system palette |
|
1258 |
bool gtkStyle = QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle"); |
|
1259 |
bool kdeColors = (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE); |
|
1260 |
if (!gtkStyle && (kdeColors || (button || !resBG.isEmpty() || !resFG.isEmpty()))) {// set app colors |
|
1261 |
bool allowX11ColorNames = QColor::allowX11ColorNames(); |
|
1262 |
QColor::setAllowX11ColorNames(true); |
|
1263 |
||
1264 |
(void) QApplication::style(); // trigger creation of application style and system palettes |
|
1265 |
QColor btn; |
|
1266 |
QColor bg; |
|
1267 |
QColor fg; |
|
1268 |
QColor bfg; |
|
1269 |
QColor wfg; |
|
1270 |
if (!resBG.isEmpty()) |
|
1271 |
bg = QColor(resBG); |
|
1272 |
if (!bg.isValid()) |
|
1273 |
bg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Window); |
|
1274 |
||
1275 |
if (!resFG.isEmpty()) |
|
1276 |
fg = QColor(resFG); |
|
1277 |
if (!fg.isValid()) |
|
1278 |
fg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::WindowText); |
|
1279 |
||
1280 |
if (!resButton.isEmpty()) |
|
1281 |
btn = QColor(resButton); |
|
1282 |
else if (!resBG.isEmpty()) |
|
1283 |
btn = bg; |
|
1284 |
if (!btn.isValid()) |
|
1285 |
btn = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Button); |
|
1286 |
||
1287 |
int h,s,v; |
|
1288 |
fg.getHsv(&h,&s,&v); |
|
1289 |
QColor base = Qt::white; |
|
1290 |
bool bright_mode = false; |
|
1291 |
if (v >= 255 - 50) { |
|
1292 |
base = btn.darker(150); |
|
1293 |
bright_mode = true; |
|
1294 |
} |
|
1295 |
||
1296 |
QPalette pal(fg, btn, btn.lighter(125), btn.darker(130), btn.darker(120), wfg.isValid() ? wfg : fg, Qt::white, base, bg); |
|
1297 |
QColor disabled((fg.red() + btn.red()) / 2, |
|
1298 |
(fg.green() + btn.green())/ 2, |
|
1299 |
(fg.blue() + btn.blue()) / 2); |
|
1300 |
pal.setColorGroup(QPalette::Disabled, disabled, btn, btn.lighter(125), |
|
1301 |
btn.darker(130), btn.darker(150), disabled, Qt::white, Qt::white, bg); |
|
1302 |
||
1303 |
QColor highlight, highlightText; |
|
1304 |
if (!selectBackground.isEmpty() && !selectForeground.isEmpty()) { |
|
1305 |
highlight = QColor(selectBackground); |
|
1306 |
highlightText = QColor(selectForeground); |
|
1307 |
} |
|
1308 |
||
1309 |
if (highlight.isValid() && highlightText.isValid()) { |
|
1310 |
pal.setColor(QPalette::Highlight, highlight); |
|
1311 |
pal.setColor(QPalette::HighlightedText, highlightText); |
|
1312 |
||
1313 |
// calculate disabled colors by removing saturation |
|
1314 |
highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha()); |
|
1315 |
highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha()); |
|
1316 |
pal.setColor(QPalette::Disabled, QPalette::Highlight, highlight); |
|
1317 |
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText); |
|
1318 |
} else if (bright_mode) { |
|
1319 |
pal.setColor(QPalette::HighlightedText, base); |
|
1320 |
pal.setColor(QPalette::Highlight, Qt::white); |
|
1321 |
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, base); |
|
1322 |
pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::white); |
|
1323 |
} else { |
|
1324 |
pal.setColor(QPalette::HighlightedText, Qt::white); |
|
1325 |
pal.setColor(QPalette::Highlight, Qt::darkBlue); |
|
1326 |
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white); |
|
1327 |
pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); |
|
1328 |
} |
|
1329 |
||
1330 |
pal = qt_guiPlatformPlugin()->palette().resolve(pal); |
|
1331 |
QApplicationPrivate::setSystemPalette(pal); |
|
1332 |
QColor::setAllowX11ColorNames(allowX11ColorNames); |
|
1333 |
} |
|
1334 |
||
1335 |
if (!resEF.isEmpty()) { |
|
1336 |
QStringList effects = resEF.split(QLatin1Char(' ')); |
|
1337 |
QApplication::setEffectEnabled(Qt::UI_General, effects.contains(QLatin1String("general"))); |
|
1338 |
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, |
|
1339 |
effects.contains(QLatin1String("animatemenu"))); |
|
1340 |
QApplication::setEffectEnabled(Qt::UI_FadeMenu, |
|
1341 |
effects.contains(QLatin1String("fademenu"))); |
|
1342 |
QApplication::setEffectEnabled(Qt::UI_AnimateCombo, |
|
1343 |
effects.contains(QLatin1String("animatecombo"))); |
|
1344 |
QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, |
|
1345 |
effects.contains(QLatin1String("animatetooltip"))); |
|
1346 |
QApplication::setEffectEnabled(Qt::UI_FadeTooltip, |
|
1347 |
effects.contains(QLatin1String("fadetooltip"))); |
|
1348 |
QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, |
|
1349 |
effects.contains(QLatin1String("animatetoolbox"))); |
|
1350 |
} |
|
1351 |
||
1352 |
QIconLoader::instance()->updateSystemTheme(); |
|
1353 |
} |
|
1354 |
||
1355 |
||
1356 |
// update the supported array |
|
1357 |
static void qt_get_net_supported() |
|
1358 |
{ |
|
1359 |
Atom type; |
|
1360 |
int format; |
|
1361 |
long offset = 0; |
|
1362 |
unsigned long nitems, after; |
|
1363 |
unsigned char *data = 0; |
|
1364 |
||
1365 |
int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
1366 |
ATOM(_NET_SUPPORTED), 0, 0, |
|
1367 |
False, XA_ATOM, &type, &format, &nitems, &after, &data); |
|
1368 |
if (data) |
|
1369 |
XFree(data); |
|
1370 |
||
1371 |
if (X11->net_supported_list) |
|
1372 |
delete [] X11->net_supported_list; |
|
1373 |
X11->net_supported_list = 0; |
|
1374 |
||
1375 |
if (e == Success && type == XA_ATOM && format == 32) { |
|
1376 |
QBuffer ts; |
|
1377 |
ts.open(QIODevice::WriteOnly); |
|
1378 |
||
1379 |
while (after > 0) { |
|
1380 |
XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
1381 |
ATOM(_NET_SUPPORTED), offset, 1024, |
|
1382 |
False, XA_ATOM, &type, &format, &nitems, &after, &data); |
|
1383 |
||
1384 |
if (type == XA_ATOM && format == 32) { |
|
1385 |
ts.write(reinterpret_cast<char *>(data), nitems * sizeof(long)); |
|
1386 |
offset += nitems; |
|
1387 |
} else |
|
1388 |
after = 0; |
|
1389 |
if (data) |
|
1390 |
XFree(data); |
|
1391 |
} |
|
1392 |
||
1393 |
// compute nitems |
|
1394 |
QByteArray buffer(ts.buffer()); |
|
1395 |
nitems = buffer.size() / sizeof(Atom); |
|
1396 |
X11->net_supported_list = new Atom[nitems + 1]; |
|
1397 |
Atom *a = (Atom *) buffer.data(); |
|
1398 |
uint i; |
|
1399 |
for (i = 0; i < nitems; i++) |
|
1400 |
X11->net_supported_list[i] = a[i]; |
|
1401 |
X11->net_supported_list[nitems] = 0; |
|
1402 |
} |
|
1403 |
} |
|
1404 |
||
1405 |
||
1406 |
bool QX11Data::isSupportedByWM(Atom atom) |
|
1407 |
{ |
|
1408 |
if (!X11->net_supported_list) |
|
1409 |
return false; |
|
1410 |
||
1411 |
bool supported = false; |
|
1412 |
int i = 0; |
|
1413 |
while (X11->net_supported_list[i] != 0) { |
|
1414 |
if (X11->net_supported_list[i++] == atom) { |
|
1415 |
supported = true; |
|
1416 |
break; |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
return supported; |
|
1421 |
} |
|
1422 |
||
1423 |
||
1424 |
// update the virtual roots array |
|
1425 |
static void qt_get_net_virtual_roots() |
|
1426 |
{ |
|
1427 |
if (X11->net_virtual_root_list) |
|
1428 |
delete [] X11->net_virtual_root_list; |
|
1429 |
X11->net_virtual_root_list = 0; |
|
1430 |
||
1431 |
if (!X11->isSupportedByWM(ATOM(_NET_VIRTUAL_ROOTS))) |
|
1432 |
return; |
|
1433 |
||
1434 |
Atom type; |
|
1435 |
int format; |
|
1436 |
long offset = 0; |
|
1437 |
unsigned long nitems, after; |
|
1438 |
unsigned char *data; |
|
1439 |
||
1440 |
int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
1441 |
ATOM(_NET_VIRTUAL_ROOTS), 0, 0, |
|
1442 |
False, XA_ATOM, &type, &format, &nitems, &after, &data); |
|
1443 |
if (data) |
|
1444 |
XFree(data); |
|
1445 |
||
1446 |
if (e == Success && type == XA_ATOM && format == 32) { |
|
1447 |
QBuffer ts; |
|
1448 |
ts.open(QIODevice::WriteOnly); |
|
1449 |
||
1450 |
while (after > 0) { |
|
1451 |
XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
1452 |
ATOM(_NET_VIRTUAL_ROOTS), offset, 1024, |
|
1453 |
False, XA_ATOM, &type, &format, &nitems, &after, &data); |
|
1454 |
||
1455 |
if (type == XA_ATOM && format == 32) { |
|
1456 |
ts.write(reinterpret_cast<char *>(data), nitems * 4); |
|
1457 |
offset += nitems; |
|
1458 |
} else |
|
1459 |
after = 0; |
|
1460 |
if (data) |
|
1461 |
XFree(data); |
|
1462 |
} |
|
1463 |
||
1464 |
// compute nitems |
|
1465 |
QByteArray buffer(ts.buffer()); |
|
1466 |
nitems = buffer.size() / sizeof(Window); |
|
1467 |
X11->net_virtual_root_list = new Window[nitems + 1]; |
|
1468 |
Window *a = (Window *) buffer.data(); |
|
1469 |
uint i; |
|
1470 |
for (i = 0; i < nitems; i++) |
|
1471 |
X11->net_virtual_root_list[i] = a[i]; |
|
1472 |
X11->net_virtual_root_list[nitems] = 0; |
|
1473 |
} |
|
1474 |
} |
|
1475 |
||
1476 |
void qt_net_remove_user_time(QWidget *tlw) |
|
1477 |
{ |
|
1478 |
Q_ASSERT(tlw); |
|
1479 |
QTLWExtra *extra = tlw->d_func()->maybeTopData(); |
|
1480 |
if (extra && extra->userTimeWindow) { |
|
1481 |
Q_ASSERT(tlw->internalWinId()); |
|
1482 |
XDeleteProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME_WINDOW)); |
|
1483 |
XDestroyWindow(X11->display, extra->userTimeWindow); |
|
1484 |
extra->userTimeWindow = 0; |
|
1485 |
} |
|
1486 |
} |
|
1487 |
||
1488 |
void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp) |
|
1489 |
{ |
|
1490 |
Q_ASSERT(tlw); |
|
1491 |
Q_ASSERT(tlw->isWindow()); |
|
1492 |
Q_ASSERT(tlw->testAttribute(Qt::WA_WState_Created)); |
|
1493 |
QTLWExtra *extra = tlw->d_func()->topData(); |
|
1494 |
WId wid = tlw->internalWinId(); |
|
1495 |
const bool isSupportedByWM = X11->isSupportedByWM(ATOM(_NET_WM_USER_TIME_WINDOW)); |
|
1496 |
if (extra->userTimeWindow || isSupportedByWM) { |
|
1497 |
if (!extra->userTimeWindow) { |
|
1498 |
extra->userTimeWindow = XCreateSimpleWindow(X11->display, |
|
1499 |
tlw->internalWinId(), |
|
1500 |
-1, -1, 1, 1, 0, 0, 0); |
|
1501 |
wid = extra->userTimeWindow; |
|
1502 |
XChangeProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME_WINDOW), |
|
1503 |
XA_WINDOW, 32, PropModeReplace, |
|
1504 |
(unsigned char *)&wid, 1); |
|
1505 |
XDeleteProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME)); |
|
1506 |
} else if (!isSupportedByWM) { |
|
1507 |
// WM no longer supports it, then we should remove the |
|
1508 |
// _NET_WM_USER_TIME_WINDOW atom. |
|
1509 |
qt_net_remove_user_time(tlw); |
|
1510 |
} else { |
|
1511 |
wid = extra->userTimeWindow; |
|
1512 |
} |
|
1513 |
} |
|
1514 |
XChangeProperty(X11->display, wid, ATOM(_NET_WM_USER_TIME), |
|
1515 |
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) ×tamp, 1); |
|
1516 |
} |
|
1517 |
||
1518 |
static void qt_check_focus_model() |
|
1519 |
{ |
|
1520 |
Window fw = XNone; |
|
1521 |
int unused; |
|
1522 |
XGetInputFocus(X11->display, &fw, &unused); |
|
1523 |
if (fw == PointerRoot) |
|
1524 |
X11->focus_model = QX11Data::FM_PointerRoot; |
|
1525 |
else |
|
1526 |
X11->focus_model = QX11Data::FM_Other; |
|
1527 |
} |
|
1528 |
||
1529 |
#ifndef QT_NO_TABLET |
|
1530 |
||
1531 |
#if !defined (Q_OS_IRIX) |
|
1532 |
// from include/Xwacom.h |
|
1533 |
# define XWACOM_PARAM_TOOLID 322 |
|
1534 |
# define XWACOM_PARAM_TOOLSERIAL 323 |
|
1535 |
||
1536 |
typedef WACOMCONFIG * (*PtrWacomConfigInit) (Display*, WACOMERRORFUNC); |
|
1537 |
typedef WACOMDEVICE * (*PtrWacomConfigOpenDevice) (WACOMCONFIG*, const char*); |
|
1538 |
typedef int *(*PtrWacomConfigGetRawParam) (WACOMDEVICE*, int, int*, int, unsigned*); |
|
1539 |
typedef int (*PtrWacomConfigCloseDevice) (WACOMDEVICE *); |
|
1540 |
typedef void (*PtrWacomConfigTerm) (WACOMCONFIG *); |
|
1541 |
||
1542 |
static PtrWacomConfigInit ptrWacomConfigInit = 0; |
|
1543 |
static PtrWacomConfigOpenDevice ptrWacomConfigOpenDevice = 0; |
|
1544 |
static PtrWacomConfigGetRawParam ptrWacomConfigGetRawParam = 0; |
|
1545 |
static PtrWacomConfigCloseDevice ptrWacomConfigCloseDevice = 0; |
|
1546 |
static PtrWacomConfigTerm ptrWacomConfigTerm = 0; |
|
1547 |
Q_GLOBAL_STATIC(QByteArray, wacomDeviceName) |
|
1548 |
#endif |
|
1549 |
||
1550 |
#endif |
|
1551 |
||
1552 |
/***************************************************************************** |
|
1553 |
qt_init() - initializes Qt for X11 |
|
1554 |
*****************************************************************************/ |
|
1555 |
||
1556 |
#if !defined(QT_NO_FONTCONFIG) |
|
1557 |
static void getXDefault(const char *group, const char *key, int *val) |
|
1558 |
{ |
|
1559 |
char *str = XGetDefault(X11->display, group, key); |
|
1560 |
if (str) { |
|
1561 |
char *end = 0; |
|
1562 |
int v = strtol(str, &end, 0); |
|
1563 |
if (str != end) |
|
1564 |
*val = v; |
|
1565 |
} |
|
1566 |
} |
|
1567 |
||
1568 |
static void getXDefault(const char *group, const char *key, double *val) |
|
1569 |
{ |
|
1570 |
char *str = XGetDefault(X11->display, group, key); |
|
1571 |
if (str) { |
|
1572 |
bool ok; |
|
1573 |
double v = QByteArray(str).toDouble(&ok); |
|
1574 |
if (ok) |
|
1575 |
*val = v; |
|
1576 |
} |
|
1577 |
} |
|
1578 |
||
1579 |
static void getXDefault(const char *group, const char *key, bool *val) |
|
1580 |
{ |
|
1581 |
char *str = XGetDefault(X11->display, group, key); |
|
1582 |
if (str) { |
|
1583 |
char c = str[0]; |
|
1584 |
if (isupper((int)c)) |
|
1585 |
c = tolower(c); |
|
1586 |
if (c == 't' || c == 'y' || c == '1') |
|
1587 |
*val = true; |
|
1588 |
else if (c == 'f' || c == 'n' || c == '0') |
|
1589 |
*val = false; |
|
1590 |
if (c == 'o') { |
|
1591 |
c = str[1]; |
|
1592 |
if (isupper((int)c)) |
|
1593 |
c = tolower(c); |
|
1594 |
if (c == 'n') |
|
1595 |
*val = true; |
|
1596 |
if (c == 'f') |
|
1597 |
*val = false; |
|
1598 |
} |
|
1599 |
} |
|
1600 |
} |
|
1601 |
#endif |
|
1602 |
||
1603 |
// ### This should be static but it isn't because of the friend declaration |
|
1604 |
// ### in qpaintdevice.h which then should have a static too but can't have |
|
1605 |
// ### it because "storage class specifiers invalid in friend function |
|
1606 |
// ### declarations" :-) Ideas anyone? |
|
1607 |
void qt_init(QApplicationPrivate *priv, int, |
|
1608 |
Display *display, Qt::HANDLE visual, Qt::HANDLE colormap) |
|
1609 |
{ |
|
1610 |
X11 = new QX11Data; |
|
1611 |
X11->display = display; |
|
1612 |
X11->displayName = 0; |
|
1613 |
X11->foreignDisplay = (display != 0); |
|
1614 |
X11->focus_model = -1; |
|
1615 |
||
1616 |
// RANDR |
|
1617 |
X11->use_xrandr = false; |
|
1618 |
X11->xrandr_major = 0; |
|
1619 |
X11->xrandr_eventbase = 0; |
|
1620 |
X11->xrandr_errorbase = 0; |
|
1621 |
||
1622 |
// RENDER |
|
1623 |
X11->use_xrender = false; |
|
1624 |
X11->xrender_major = 0; |
|
1625 |
X11->xrender_version = 0; |
|
1626 |
||
1627 |
// XFIXES |
|
1628 |
X11->use_xfixes = false; |
|
1629 |
X11->xfixes_major = 0; |
|
1630 |
X11->xfixes_eventbase = 0; |
|
1631 |
X11->xfixes_errorbase = 0; |
|
1632 |
||
1633 |
// XInputExtension |
|
1634 |
X11->use_xinput = false; |
|
1635 |
X11->xinput_major = 0; |
|
1636 |
X11->xinput_eventbase = 0; |
|
1637 |
X11->xinput_errorbase = 0; |
|
1638 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1639 |
X11->use_xkb = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1640 |
X11->xkb_major = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1641 |
X11->xkb_eventbase = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1642 |
X11->xkb_errorbase = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1643 |
|
0 | 1644 |
// MIT-SHM |
1645 |
X11->use_mitshm = false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1646 |
X11->use_mitshm_pixmaps = false; |
0 | 1647 |
X11->mitshm_major = 0; |
1648 |
||
1649 |
X11->sip_serial = 0; |
|
1650 |
X11->net_supported_list = 0; |
|
1651 |
X11->net_virtual_root_list = 0; |
|
1652 |
X11->wm_client_leader = 0; |
|
1653 |
X11->screens = 0; |
|
1654 |
X11->argbVisuals = 0; |
|
1655 |
X11->argbColormaps = 0; |
|
1656 |
X11->screenCount = 0; |
|
1657 |
X11->time = CurrentTime; |
|
1658 |
X11->userTime = CurrentTime; |
|
1659 |
X11->ignore_badwindow = false; |
|
1660 |
X11->seen_badwindow = false; |
|
1661 |
||
1662 |
X11->motifdnd_active = false; |
|
1663 |
||
1664 |
X11->default_im = QLatin1String("imsw-multi"); |
|
1665 |
priv->inputContext = 0; |
|
1666 |
||
1667 |
// colormap control |
|
1668 |
X11->visual_class = -1; |
|
1669 |
X11->visual_id = -1; |
|
1670 |
X11->color_count = 0; |
|
1671 |
X11->custom_cmap = false; |
|
1672 |
||
1673 |
// outside visual/colormap |
|
1674 |
X11->visual = reinterpret_cast<Visual *>(visual); |
|
1675 |
X11->colormap = colormap; |
|
1676 |
||
1677 |
// Fontconfig |
|
1678 |
X11->has_fontconfig = false; |
|
1679 |
#if !defined(QT_NO_FONTCONFIG) |
|
1680 |
if (qgetenv("QT_X11_NO_FONTCONFIG").isNull()) |
|
1681 |
X11->has_fontconfig = FcInit(); |
|
1682 |
X11->fc_antialias = true; |
|
1683 |
#endif |
|
1684 |
||
1685 |
#ifndef QT_NO_XRENDER |
|
1686 |
memset(X11->solid_fills, 0, sizeof(X11->solid_fills)); |
|
1687 |
for (int i = 0; i < X11->solid_fill_count; ++i) |
|
1688 |
X11->solid_fills[i].screen = -1; |
|
1689 |
memset(X11->pattern_fills, 0, sizeof(X11->pattern_fills)); |
|
1690 |
for (int i = 0; i < X11->pattern_fill_count; ++i) |
|
1691 |
X11->pattern_fills[i].screen = -1; |
|
1692 |
#endif |
|
1693 |
||
1694 |
X11->startupId = 0; |
|
1695 |
||
1696 |
int argc = priv->argc; |
|
1697 |
char **argv = priv->argv; |
|
1698 |
||
1699 |
if (X11->display) { |
|
1700 |
// Qt part of other application |
|
1701 |
||
1702 |
// Set application name and class |
|
1703 |
appName = qstrdup("Qt-subapplication"); |
|
1704 |
char *app_class = 0; |
|
1705 |
if (argv) { |
|
1706 |
const char* p = strrchr(argv[0], '/'); |
|
1707 |
app_class = qstrdup(p ? p + 1 : argv[0]); |
|
1708 |
if (app_class[0]) |
|
1709 |
app_class[0] = toupper(app_class[0]); |
|
1710 |
} |
|
1711 |
appClass = app_class; |
|
1712 |
} else { |
|
1713 |
// Qt controls everything (default) |
|
1714 |
||
1715 |
// Set application name and class |
|
1716 |
char *app_class = 0; |
|
1717 |
if (argv && argv[0]) { |
|
1718 |
const char *p = strrchr(argv[0], '/'); |
|
1719 |
appName = p ? p + 1 : argv[0]; |
|
1720 |
app_class = qstrdup(appName); |
|
1721 |
if (app_class[0]) |
|
1722 |
app_class[0] = toupper(app_class[0]); |
|
1723 |
} |
|
1724 |
appClass = app_class; |
|
1725 |
} |
|
1726 |
||
1727 |
// Install default error handlers |
|
1728 |
original_x_errhandler = XSetErrorHandler(qt_x_errhandler); |
|
1729 |
original_xio_errhandler = XSetIOErrorHandler(qt_xio_errhandler); |
|
1730 |
||
1731 |
// Get command line params |
|
1732 |
int j = argc ? 1 : 0; |
|
1733 |
for (int i=1; i<argc; i++) { |
|
1734 |
if (argv[i] && *argv[i] != '-') { |
|
1735 |
argv[j++] = argv[i]; |
|
1736 |
continue; |
|
1737 |
} |
|
1738 |
QByteArray arg(argv[i]); |
|
1739 |
if (arg == "-display") { |
|
1740 |
if (++i < argc && !X11->display) |
|
1741 |
X11->displayName = argv[i]; |
|
1742 |
} else if (arg == "-fn" || arg == "-font") { |
|
1743 |
if (++i < argc) |
|
1744 |
appFont = argv[i]; |
|
1745 |
} else if (arg == "-bg" || arg == "-background") { |
|
1746 |
if (++i < argc) |
|
1747 |
appBGCol = argv[i]; |
|
1748 |
} else if (arg == "-btn" || arg == "-button") { |
|
1749 |
if (++i < argc) |
|
1750 |
appBTNCol = argv[i]; |
|
1751 |
} else if (arg == "-fg" || arg == "-foreground") { |
|
1752 |
if (++i < argc) |
|
1753 |
appFGCol = argv[i]; |
|
1754 |
} else if (arg == "-name") { |
|
1755 |
if (++i < argc) |
|
1756 |
appName = argv[i]; |
|
1757 |
} else if (arg == "-title") { |
|
1758 |
if (++i < argc) |
|
1759 |
mwTitle = argv[i]; |
|
1760 |
} else if (arg == "-geometry") { |
|
1761 |
if (++i < argc) |
|
1762 |
mwGeometry = argv[i]; |
|
1763 |
} else if (arg == "-im") { |
|
1764 |
if (++i < argc) |
|
1765 |
qt_ximServer = argv[i]; |
|
1766 |
} else if (arg == "-ncols") { // xv and netscape use this name |
|
1767 |
if (++i < argc) |
|
1768 |
X11->color_count = qMax(0,atoi(argv[i])); |
|
1769 |
} else if (arg == "-visual") { // xv and netscape use this name |
|
1770 |
if (++i < argc && !X11->visual) { |
|
1771 |
QString s = QString::fromLocal8Bit(argv[i]).toLower(); |
|
1772 |
if (s == QLatin1String("staticgray")) |
|
1773 |
X11->visual_class = StaticGray; |
|
1774 |
else if (s == QLatin1String("grayscale")) |
|
1775 |
X11->visual_class = XGrayScale; |
|
1776 |
else if (s == QLatin1String("staticcolor")) |
|
1777 |
X11->visual_class = StaticColor; |
|
1778 |
else if (s == QLatin1String("pseudocolor")) |
|
1779 |
X11->visual_class = PseudoColor; |
|
1780 |
else if (s == QLatin1String("truecolor")) |
|
1781 |
X11->visual_class = TrueColor; |
|
1782 |
else if (s == QLatin1String("directcolor")) |
|
1783 |
X11->visual_class = DirectColor; |
|
1784 |
else |
|
1785 |
X11->visual_id = static_cast<int>(strtol(argv[i], 0, 0)); |
|
1786 |
} |
|
1787 |
#ifndef QT_NO_XIM |
|
1788 |
} else if (arg == "-inputstyle") { |
|
1789 |
if (++i < argc) { |
|
1790 |
QString s = QString::fromLocal8Bit(argv[i]).toLower(); |
|
1791 |
if (s == QLatin1String("onthespot")) |
|
1792 |
qt_xim_preferred_style = XIMPreeditCallbacks | |
|
1793 |
XIMStatusNothing; |
|
1794 |
else if (s == QLatin1String("overthespot")) |
|
1795 |
qt_xim_preferred_style = XIMPreeditPosition | |
|
1796 |
XIMStatusNothing; |
|
1797 |
else if (s == QLatin1String("offthespot")) |
|
1798 |
qt_xim_preferred_style = XIMPreeditArea | |
|
1799 |
XIMStatusArea; |
|
1800 |
else if (s == QLatin1String("root")) |
|
1801 |
qt_xim_preferred_style = XIMPreeditNothing | |
|
1802 |
XIMStatusNothing; |
|
1803 |
} |
|
1804 |
#endif |
|
1805 |
} else if (arg == "-cmap") { // xv uses this name |
|
1806 |
if (!X11->colormap) |
|
1807 |
X11->custom_cmap = true; |
|
1808 |
} |
|
1809 |
else if (arg == "-sync") |
|
1810 |
appSync = !appSync; |
|
1811 |
#if defined(QT_DEBUG) |
|
1812 |
else if (arg == "-nograb") |
|
1813 |
appNoGrab = !appNoGrab; |
|
1814 |
else if (arg == "-dograb") |
|
1815 |
appDoGrab = !appDoGrab; |
|
1816 |
#endif |
|
1817 |
else |
|
1818 |
argv[j++] = argv[i]; |
|
1819 |
} |
|
1820 |
||
1821 |
priv->argc = j; |
|
1822 |
||
1823 |
#if defined(QT_DEBUG) && defined(Q_OS_LINUX) |
|
1824 |
if (!appNoGrab && !appDoGrab) { |
|
1825 |
QString s; |
|
1826 |
s.sprintf("/proc/%d/cmdline", getppid()); |
|
1827 |
QFile f(s); |
|
1828 |
if (f.open(QIODevice::ReadOnly)) { |
|
1829 |
s.clear(); |
|
1830 |
char c; |
|
1831 |
while (f.getChar(&c) && c) { |
|
1832 |
if (c == '/') |
|
1833 |
s.clear(); |
|
1834 |
else |
|
1835 |
s += QLatin1Char(c); |
|
1836 |
} |
|
1837 |
if (s == QLatin1String("gdb")) { |
|
1838 |
appNoGrab = true; |
|
1839 |
qDebug("Qt: gdb: -nograb added to command-line options.\n" |
|
1840 |
"\t Use the -dograb option to enforce grabbing."); |
|
1841 |
} |
|
1842 |
f.close(); |
|
1843 |
} |
|
1844 |
} |
|
1845 |
#endif |
|
1846 |
||
1847 |
// Connect to X server |
|
1848 |
if (qt_is_gui_used && !X11->display) { |
|
1849 |
if ((X11->display = XOpenDisplay(X11->displayName)) == 0) { |
|
1850 |
qWarning("%s: cannot connect to X server %s", appName, |
|
1851 |
XDisplayName(X11->displayName)); |
|
1852 |
QApplicationPrivate::reset_instance_pointer(); |
|
1853 |
exit(1); |
|
1854 |
} |
|
1855 |
||
1856 |
if (appSync) // if "-sync" argument |
|
1857 |
XSynchronize(X11->display, true); |
|
1858 |
} |
|
1859 |
||
1860 |
// Common code, regardless of whether display is foreign. |
|
1861 |
||
1862 |
// Get X parameters |
|
1863 |
||
1864 |
if (qt_is_gui_used) { |
|
1865 |
X11->defaultScreen = DefaultScreen(X11->display); |
|
1866 |
X11->screenCount = ScreenCount(X11->display); |
|
1867 |
||
1868 |
X11->screens = new QX11InfoData[X11->screenCount]; |
|
1869 |
X11->argbVisuals = new Visual *[X11->screenCount]; |
|
1870 |
X11->argbColormaps = new Colormap[X11->screenCount]; |
|
1871 |
||
1872 |
for (int s = 0; s < X11->screenCount; s++) { |
|
1873 |
QX11InfoData *screen = X11->screens + s; |
|
1874 |
screen->ref = 1; // ensures it doesn't get deleted |
|
1875 |
screen->screen = s; |
|
1876 |
||
1877 |
int widthMM = DisplayWidthMM(X11->display, s); |
|
1878 |
if (widthMM != 0) { |
|
1879 |
screen->dpiX = (DisplayWidth(X11->display, s) * 254 + widthMM * 5) / (widthMM * 10); |
|
1880 |
} else { |
|
1881 |
screen->dpiX = 72; |
|
1882 |
} |
|
1883 |
||
1884 |
int heightMM = DisplayHeightMM(X11->display, s); |
|
1885 |
if (heightMM != 0) { |
|
1886 |
screen->dpiY = (DisplayHeight(X11->display, s) * 254 + heightMM * 5) / (heightMM * 10); |
|
1887 |
} else { |
|
1888 |
screen->dpiY = 72; |
|
1889 |
} |
|
1890 |
||
1891 |
X11->argbVisuals[s] = 0; |
|
1892 |
X11->argbColormaps[s] = 0; |
|
1893 |
} |
|
1894 |
||
1895 |
||
1896 |
#ifndef QT_NO_XRENDER |
|
1897 |
int xrender_eventbase, xrender_errorbase; |
|
1898 |
// See if XRender is supported on the connected display |
|
1899 |
if (XQueryExtension(X11->display, "RENDER", &X11->xrender_major, |
|
1900 |
&xrender_eventbase, &xrender_errorbase) |
|
1901 |
&& XRenderQueryExtension(X11->display, &xrender_eventbase, |
|
1902 |
&xrender_errorbase)) { |
|
1903 |
// Check the version as well - we need v0.4 or higher |
|
1904 |
int major = 0; |
|
1905 |
int minor = 0; |
|
1906 |
XRenderQueryVersion(X11->display, &major, &minor); |
|
1907 |
if (qgetenv("QT_X11_NO_XRENDER").isNull()) { |
|
1908 |
X11->use_xrender = (major >= 0 && minor >= 5); |
|
1909 |
X11->xrender_version = major*100+minor; |
|
1910 |
// workaround for broken XServer on Ubuntu Breezy (6.8 compiled with 7.0 |
|
1911 |
// protocol headers) |
|
1912 |
if (X11->xrender_version == 10 |
|
1913 |
&& VendorRelease(X11->display) < 60900000 |
|
1914 |
&& QByteArray(ServerVendor(X11->display)).contains("X.Org")) |
|
1915 |
X11->xrender_version = 9; |
|
1916 |
} |
|
1917 |
} |
|
1918 |
#endif // QT_NO_XRENDER |
|
1919 |
||
1920 |
#ifndef QT_NO_MITSHM |
|
1921 |
int mitshm_minor; |
|
1922 |
int mitshm_major; |
|
1923 |
int mitshm_eventbase; |
|
1924 |
int mitshm_errorbase; |
|
1925 |
int mitshm_pixmaps; |
|
1926 |
if (XQueryExtension(X11->display, "MIT-SHM", &X11->mitshm_major, |
|
1927 |
&mitshm_eventbase, &mitshm_errorbase) |
|
1928 |
&& XShmQueryVersion(X11->display, &mitshm_major, &mitshm_minor, |
|
1929 |
&mitshm_pixmaps)) |
|
1930 |
{ |
|
1931 |
QString displayName = QLatin1String(XDisplayName(NULL)); |
|
1932 |
||
1933 |
// MITSHM only works for local displays, so do a quick check here |
|
1934 |
// to determine whether the display is local or not (not 100 % accurate). |
|
1935 |
// BGR server layouts are not supported either, since it requires the raster |
|
1936 |
// engine to work on a QImage with BGR layout. |
|
1937 |
bool local = displayName.isEmpty() || displayName.lastIndexOf(QLatin1Char(':')) == 0; |
|
1938 |
if (local && (qgetenv("QT_X11_NO_MITSHM").toInt() == 0)) { |
|
1939 |
Visual *defaultVisual = DefaultVisual(X11->display, DefaultScreen(X11->display)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1940 |
X11->use_mitshm = ((defaultVisual->red_mask == 0xff0000 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1941 |
|| defaultVisual->red_mask == 0xf800) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1942 |
&& (defaultVisual->green_mask == 0xff00 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1943 |
|| defaultVisual->green_mask == 0x7e0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1944 |
&& (defaultVisual->blue_mask == 0xff |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1945 |
|| defaultVisual->blue_mask == 0x1f)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1946 |
X11->use_mitshm_pixmaps = X11->use_mitshm && mitshm_pixmaps; |
0 | 1947 |
} |
1948 |
} |
|
1949 |
#endif // QT_NO_MITSHM |
|
1950 |
||
1951 |
// initialize the graphics system - order is imporant here - it must be done before |
|
1952 |
// the QColormap::initialize() call |
|
1953 |
QApplicationPrivate::graphics_system = QGraphicsSystemFactory::create(QApplicationPrivate::graphics_system_name); |
|
1954 |
QColormap::initialize(); |
|
1955 |
||
1956 |
// Support protocols |
|
1957 |
X11->xdndSetup(); |
|
1958 |
||
1959 |
// Finally create all atoms |
|
1960 |
qt_x11_create_intern_atoms(); |
|
1961 |
||
1962 |
// initialize NET lists |
|
1963 |
qt_get_net_supported(); |
|
1964 |
qt_get_net_virtual_roots(); |
|
1965 |
||
1966 |
#ifndef QT_NO_XRANDR |
|
1967 |
// See if XRandR is supported on the connected display |
|
1968 |
if (XQueryExtension(X11->display, "RANDR", &X11->xrandr_major, |
|
1969 |
&X11->xrandr_eventbase, &X11->xrandr_errorbase)) { |
|
1970 |
||
1971 |
# ifdef QT_RUNTIME_XRANDR |
|
1972 |
X11->ptrXRRSelectInput = 0; |
|
1973 |
X11->ptrXRRUpdateConfiguration = 0; |
|
1974 |
X11->ptrXRRRootToScreen = 0; |
|
1975 |
X11->ptrXRRQueryExtension = 0; |
|
1976 |
QLibrary xrandrLib(QLatin1String("Xrandr"), 2); |
|
1977 |
if (!xrandrLib.load()) { // try without the version number |
|
1978 |
xrandrLib.setFileName(QLatin1String("Xrandr")); |
|
1979 |
xrandrLib.load(); |
|
1980 |
} |
|
1981 |
if (xrandrLib.isLoaded()) { |
|
1982 |
X11->ptrXRRSelectInput = |
|
1983 |
(PtrXRRSelectInput) xrandrLib.resolve("XRRSelectInput"); |
|
1984 |
X11->ptrXRRUpdateConfiguration = |
|
1985 |
(PtrXRRUpdateConfiguration) xrandrLib.resolve("XRRUpdateConfiguration"); |
|
1986 |
X11->ptrXRRRootToScreen = |
|
1987 |
(PtrXRRRootToScreen) xrandrLib.resolve("XRRRootToScreen"); |
|
1988 |
X11->ptrXRRQueryExtension = |
|
1989 |
(PtrXRRQueryExtension) xrandrLib.resolve("XRRQueryExtension"); |
|
1990 |
} |
|
1991 |
# else |
|
1992 |
X11->ptrXRRSelectInput = XRRSelectInput; |
|
1993 |
X11->ptrXRRUpdateConfiguration = XRRUpdateConfiguration; |
|
1994 |
X11->ptrXRRRootToScreen = XRRRootToScreen; |
|
1995 |
X11->ptrXRRQueryExtension = XRRQueryExtension; |
|
1996 |
# endif |
|
1997 |
||
1998 |
if (X11->ptrXRRQueryExtension |
|
1999 |
&& X11->ptrXRRQueryExtension(X11->display, &X11->xrandr_eventbase, &X11->xrandr_errorbase)) { |
|
2000 |
// XRandR is supported |
|
2001 |
X11->use_xrandr = true; |
|
2002 |
} |
|
2003 |
} |
|
2004 |
#endif // QT_NO_XRANDR |
|
2005 |
||
2006 |
#ifndef QT_NO_XRENDER |
|
2007 |
if (X11->use_xrender) { |
|
2008 |
// XRender is supported, let's see if we have a PictFormat for the |
|
2009 |
// default visual |
|
2010 |
XRenderPictFormat *format = |
|
2011 |
XRenderFindVisualFormat(X11->display, |
|
2012 |
(Visual *) QX11Info::appVisual(X11->defaultScreen)); |
|
2013 |
||
2014 |
if (!format) { |
|
2015 |
X11->use_xrender = false; |
|
2016 |
} |
|
2017 |
} |
|
2018 |
#endif // QT_NO_XRENDER |
|
2019 |
||
2020 |
#ifndef QT_NO_XFIXES |
|
2021 |
// See if Xfixes is supported on the connected display |
|
2022 |
if (XQueryExtension(X11->display, "XFIXES", &X11->xfixes_major, |
|
2023 |
&X11->xfixes_eventbase, &X11->xfixes_errorbase)) { |
|
2024 |
X11->ptrXFixesQueryExtension = XFIXES_LOAD_V1(XFixesQueryExtension); |
|
2025 |
X11->ptrXFixesQueryVersion = XFIXES_LOAD_V1(XFixesQueryVersion); |
|
2026 |
X11->ptrXFixesSetCursorName = XFIXES_LOAD_V2(XFixesSetCursorName); |
|
2027 |
X11->ptrXFixesSelectSelectionInput = XFIXES_LOAD_V2(XFixesSelectSelectionInput); |
|
2028 |
||
2029 |
if(X11->ptrXFixesQueryExtension && X11->ptrXFixesQueryVersion |
|
2030 |
&& X11->ptrXFixesQueryExtension(X11->display, &X11->xfixes_eventbase, |
|
2031 |
&X11->xfixes_errorbase)) { |
|
2032 |
// Xfixes is supported. |
|
2033 |
// Note: the XFixes protocol version is negotiated using QueryVersion. |
|
2034 |
// We supply the highest version we support, the X server replies with |
|
2035 |
// the highest version it supports, but no higher than the version we |
|
2036 |
// asked for. The version sent back is the protocol version the X server |
|
2037 |
// will use to talk us. If this call is removed, the behavior of the |
|
2038 |
// X server when it receives an XFixes request is undefined. |
|
2039 |
int major = 3; |
|
2040 |
int minor = 0; |
|
2041 |
X11->ptrXFixesQueryVersion(X11->display, &major, &minor); |
|
2042 |
X11->use_xfixes = (major >= 1); |
|
2043 |
X11->xfixes_major = major; |
|
2044 |
} |
|
2045 |
} |
|
2046 |
#endif // QT_NO_XFIXES |
|
2047 |
||
2048 |
#ifndef QT_NO_XCURSOR |
|
2049 |
#ifdef QT_RUNTIME_XCURSOR |
|
2050 |
X11->ptrXcursorLibraryLoadCursor = 0; |
|
2051 |
QLibrary xcursorLib(QLatin1String("Xcursor"), 1); |
|
2052 |
bool xcursorFound = xcursorLib.load(); |
|
2053 |
if (!xcursorFound) { //try without the version number |
|
2054 |
xcursorLib.setFileName(QLatin1String("Xcursor")); |
|
2055 |
xcursorFound = xcursorLib.load(); |
|
2056 |
} |
|
2057 |
if (xcursorFound) { |
|
2058 |
X11->ptrXcursorLibraryLoadCursor = |
|
2059 |
(PtrXcursorLibraryLoadCursor) xcursorLib.resolve("XcursorLibraryLoadCursor"); |
|
2060 |
} |
|
2061 |
#else |
|
2062 |
X11->ptrXcursorLibraryLoadCursor = XcursorLibraryLoadCursor; |
|
2063 |
#endif // QT_RUNTIME_XCURSOR |
|
2064 |
#endif // QT_NO_XCURSOR |
|
2065 |
||
2066 |
#ifndef QT_NO_XSYNC |
|
2067 |
int xsync_evbase, xsync_errbase; |
|
2068 |
int major, minor; |
|
2069 |
if (XSyncQueryExtension(X11->display, &xsync_evbase, &xsync_errbase)) |
|
2070 |
XSyncInitialize(X11->display, &major, &minor); |
|
2071 |
#endif // QT_NO_XSYNC |
|
2072 |
||
2073 |
#ifndef QT_NO_XINERAMA |
|
2074 |
#ifdef QT_RUNTIME_XINERAMA |
|
2075 |
X11->ptrXineramaQueryExtension = 0; |
|
2076 |
X11->ptrXineramaIsActive = 0; |
|
2077 |
X11->ptrXineramaQueryScreens = 0; |
|
2078 |
QLibrary xineramaLib(QLatin1String("Xinerama"), 1); |
|
2079 |
bool xineramaFound = xineramaLib.load(); |
|
2080 |
if (!xineramaFound) { //try without the version number |
|
2081 |
xineramaLib.setFileName(QLatin1String("Xinerama")); |
|
2082 |
xineramaFound = xineramaLib.load(); |
|
2083 |
} |
|
2084 |
if (xineramaFound) { |
|
2085 |
X11->ptrXineramaQueryExtension = |
|
2086 |
(PtrXineramaQueryExtension) xineramaLib.resolve("XineramaQueryExtension"); |
|
2087 |
X11->ptrXineramaIsActive = |
|
2088 |
(PtrXineramaIsActive) xineramaLib.resolve("XineramaIsActive"); |
|
2089 |
X11->ptrXineramaQueryScreens = |
|
2090 |
(PtrXineramaQueryScreens) xineramaLib.resolve("XineramaQueryScreens"); |
|
2091 |
} |
|
2092 |
#else |
|
2093 |
X11->ptrXineramaQueryScreens = XineramaQueryScreens; |
|
2094 |
X11->ptrXineramaIsActive = XineramaIsActive; |
|
2095 |
X11->ptrXineramaQueryExtension = XineramaQueryExtension; |
|
2096 |
#endif // QT_RUNTIME_XINERAMA |
|
2097 |
#endif // QT_NO_XINERAMA |
|
2098 |
||
2099 |
#ifndef QT_NO_XINPUT |
|
2100 |
// See if Xinput is supported on the connected display |
|
2101 |
X11->ptrXCloseDevice = 0; |
|
2102 |
X11->ptrXListInputDevices = 0; |
|
2103 |
X11->ptrXOpenDevice = 0; |
|
2104 |
X11->ptrXFreeDeviceList = 0; |
|
2105 |
X11->ptrXSelectExtensionEvent = 0; |
|
2106 |
X11->use_xinput = XQueryExtension(X11->display, "XInputExtension", &X11->xinput_major, |
|
2107 |
&X11->xinput_eventbase, &X11->xinput_errorbase); |
|
2108 |
if (X11->use_xinput) { |
|
2109 |
X11->ptrXCloseDevice = XINPUT_LOAD(XCloseDevice); |
|
2110 |
X11->ptrXListInputDevices = XINPUT_LOAD(XListInputDevices); |
|
2111 |
X11->ptrXOpenDevice = XINPUT_LOAD(XOpenDevice); |
|
2112 |
X11->ptrXFreeDeviceList = XINPUT_LOAD(XFreeDeviceList); |
|
2113 |
X11->ptrXSelectExtensionEvent = XINPUT_LOAD(XSelectExtensionEvent); |
|
2114 |
} |
|
2115 |
#endif // QT_NO_XINPUT |
|
2116 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2117 |
#ifndef QT_NO_XKB |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2118 |
int xkblibMajor = XkbMajorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2119 |
int xkblibMinor = XkbMinorVersion; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2120 |
X11->use_xkb = XkbQueryExtension(X11->display, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2121 |
&X11->xkb_major, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2122 |
&X11->xkb_eventbase, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2123 |
&X11->xkb_errorbase, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2124 |
&xkblibMajor, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2125 |
&xkblibMinor); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2126 |
if (X11->use_xkb) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2127 |
// If XKB is detected, set the GrabsUseXKBState option so input method |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2128 |
// compositions continue to work (ie. deadkeys) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2129 |
unsigned int state = XkbPCF_GrabsUseXKBStateMask; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2130 |
(void) XkbSetPerClientControls(X11->display, state, &state); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2131 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2132 |
// select for group change events |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2133 |
XkbSelectEventDetails(X11->display, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2134 |
XkbUseCoreKbd, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2135 |
XkbStateNotify, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2136 |
XkbAllStateComponentsMask, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2137 |
XkbGroupStateMask); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2138 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2139 |
// current group state is queried when creating the keymapper, no need to do it here |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2140 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2141 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2142 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2143 |
|
0 | 2144 |
#if !defined(QT_NO_FONTCONFIG) |
2145 |
int dpi = 0; |
|
2146 |
getXDefault("Xft", FC_DPI, &dpi); |
|
2147 |
if (dpi) { |
|
2148 |
for (int s = 0; s < ScreenCount(X11->display); ++s) { |
|
2149 |
QX11Info::setAppDpiX(s, dpi); |
|
2150 |
QX11Info::setAppDpiY(s, dpi); |
|
2151 |
} |
|
2152 |
} |
|
2153 |
double fc_scale = 1.; |
|
2154 |
getXDefault("Xft", FC_SCALE, &fc_scale); |
|
2155 |
X11->fc_scale = fc_scale; |
|
2156 |
for (int s = 0; s < ScreenCount(X11->display); ++s) { |
|
2157 |
int subpixel = FC_RGBA_UNKNOWN; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2158 |
#if !defined(QT_NO_XRENDER) && (RENDER_MAJOR > 0 || RENDER_MINOR >= 6) |
0 | 2159 |
if (X11->use_xrender) { |
2160 |
int rsp = XRenderQuerySubpixelOrder(X11->display, s); |
|
2161 |
switch (rsp) { |
|
2162 |
default: |
|
2163 |
case SubPixelUnknown: |
|
2164 |
subpixel = FC_RGBA_UNKNOWN; |
|
2165 |
break; |
|
2166 |
case SubPixelHorizontalRGB: |
|
2167 |
subpixel = FC_RGBA_RGB; |
|
2168 |
break; |
|
2169 |
case SubPixelHorizontalBGR: |
|
2170 |
subpixel = FC_RGBA_BGR; |
|
2171 |
break; |
|
2172 |
case SubPixelVerticalRGB: |
|
2173 |
subpixel = FC_RGBA_VRGB; |
|
2174 |
break; |
|
2175 |
case SubPixelVerticalBGR: |
|
2176 |
subpixel = FC_RGBA_VBGR; |
|
2177 |
break; |
|
2178 |
case SubPixelNone: |
|
2179 |
subpixel = FC_RGBA_NONE; |
|
2180 |
break; |
|
2181 |
} |
|
2182 |
} |
|
2183 |
#endif |
|
2184 |
||
2185 |
char *rgba = XGetDefault(X11->display, "Xft", FC_RGBA); |
|
2186 |
if (rgba) { |
|
2187 |
char *end = 0; |
|
2188 |
int v = strtol(rgba, &end, 0); |
|
2189 |
if (rgba != end) { |
|
2190 |
subpixel = v; |
|
2191 |
} else if (qstrncmp(rgba, "unknown", 7) == 0) { |
|
2192 |
subpixel = FC_RGBA_UNKNOWN; |
|
2193 |
} else if (qstrncmp(rgba, "rgb", 3) == 0) { |
|
2194 |
subpixel = FC_RGBA_RGB; |
|
2195 |
} else if (qstrncmp(rgba, "bgr", 3) == 0) { |
|
2196 |
subpixel = FC_RGBA_BGR; |
|
2197 |
} else if (qstrncmp(rgba, "vrgb", 4) == 0) { |
|
2198 |
subpixel = FC_RGBA_VRGB; |
|
2199 |
} else if (qstrncmp(rgba, "vbgr", 4) == 0) { |
|
2200 |
subpixel = FC_RGBA_VBGR; |
|
2201 |
} else if (qstrncmp(rgba, "none", 4) == 0) { |
|
2202 |
subpixel = FC_RGBA_NONE; |
|
2203 |
} |
|
2204 |
} |
|
2205 |
X11->screens[s].subpixel = subpixel; |
|
2206 |
} |
|
2207 |
getXDefault("Xft", FC_ANTIALIAS, &X11->fc_antialias); |
|
2208 |
#ifdef FC_HINT_STYLE |
|
2209 |
getXDefault("Xft", FC_HINT_STYLE, &X11->fc_hint_style); |
|
2210 |
#endif |
|
2211 |
#if 0 |
|
2212 |
// ###### these are implemented by Xft, not sure we need them |
|
2213 |
getXDefault("Xft", FC_AUTOHINT, &X11->fc_autohint); |
|
2214 |
getXDefault("Xft", FC_HINTING, &X11->fc_autohint); |
|
2215 |
getXDefault("Xft", FC_MINSPACE, &X11->fc_autohint); |
|
2216 |
#endif |
|
2217 |
#endif // QT_NO_XRENDER |
|
2218 |
||
2219 |
// initialize key mapper |
|
2220 |
QKeyMapper::changeKeyboard(); |
|
2221 |
||
2222 |
// Misc. initialization |
|
2223 |
#if 0 //disabled for now.. |
|
2224 |
QSegfaultHandler::initialize(priv->argv, priv->argc); |
|
2225 |
#endif |
|
2226 |
QCursorData::initialize(); |
|
2227 |
} |
|
2228 |
QFont::initialize(); |
|
2229 |
||
2230 |
if(qt_is_gui_used) { |
|
2231 |
qApp->setObjectName(QString::fromLocal8Bit(appName)); |
|
2232 |
||
2233 |
int screen; |
|
2234 |
for (screen = 0; screen < X11->screenCount; ++screen) { |
|
2235 |
XSelectInput(X11->display, QX11Info::appRootWindow(screen), |
|
2236 |
KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask); |
|
2237 |
||
2238 |
#ifndef QT_NO_XRANDR |
|
2239 |
if (X11->use_xrandr) |
|
2240 |
X11->ptrXRRSelectInput(X11->display, QX11Info::appRootWindow(screen), True); |
|
2241 |
#endif // QT_NO_XRANDR |
|
2242 |
} |
|
2243 |
} |
|
2244 |
||
2245 |
if (qt_is_gui_used) { |
|
2246 |
// Attempt to determine the current running X11 Desktop Enviornment |
|
2247 |
// Use dbus if/when we can, but fall back to using windowManagerName() for now |
|
2248 |
||
2249 |
X11->compositingManagerRunning = XGetSelectionOwner(X11->display, |
|
2250 |
ATOM(_NET_WM_CM_S0)); |
|
2251 |
X11->desktopEnvironment = DE_UNKNOWN; |
|
2252 |
X11->desktopVersion = 0; |
|
2253 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2254 |
Atom type; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2255 |
int format; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2256 |
unsigned long length, after; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2257 |
uchar *data = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2258 |
int rc; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2259 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2260 |
do { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2261 |
if (!qgetenv("KDE_FULL_SESSION").isEmpty()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2262 |
X11->desktopEnvironment = DE_KDE; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2263 |
X11->desktopVersion = qgetenv("KDE_SESSION_VERSION").toInt(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2264 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2265 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2266 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2267 |
if (qgetenv("DESKTOP_SESSION") == "gnome") { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2268 |
X11->desktopEnvironment = DE_GNOME; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2269 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2270 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2271 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2272 |
// GNOME_DESKTOP_SESSION_ID is deprecated for some reason, but still check it |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2273 |
if (!qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2274 |
X11->desktopEnvironment = DE_GNOME; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2275 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2276 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2277 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2278 |
rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_DT_SAVE_MODE), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2279 |
0, 2, False, XA_STRING, &type, &format, &length, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2280 |
&after, &data); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2281 |
if (rc == Success && length) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2282 |
if (!strcmp(reinterpret_cast<char *>(data), "xfce4")) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2283 |
// Pretend that xfce4 is gnome, as it uses the same libraries. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2284 |
// The detection above is stolen from xdg-open. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2285 |
X11->desktopEnvironment = DE_GNOME; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2286 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2287 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2288 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2289 |
// We got the property but it wasn't xfce4. Free data before it gets overwritten. |
0 | 2290 |
XFree(data); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2291 |
data = 0; |
0 | 2292 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2293 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2294 |
rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(DTWM_IS_RUNNING), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2295 |
0, 1, False, AnyPropertyType, &type, &format, &length, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2296 |
&after, &data); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2297 |
if (rc == Success && length) { |
0 | 2298 |
// DTWM is running, meaning most likely CDE is running... |
2299 |
X11->desktopEnvironment = DE_CDE; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2300 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2301 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2302 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2303 |
rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2304 |
ATOM(_SGI_DESKS_MANAGER), 0, 1, False, XA_WINDOW, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2305 |
&type, &format, &length, &after, &data); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2306 |
if (rc == Success && length) { |
0 | 2307 |
X11->desktopEnvironment = DE_4DWM; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2308 |
break; |
0 | 2309 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2310 |
} while(0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2311 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2312 |
if (data) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2313 |
XFree((char *)data); |
0 | 2314 |
|
2315 |
#if !defined(QT_NO_STYLE_GTK) |
|
2316 |
if (X11->desktopEnvironment == DE_GNOME) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2317 |
static bool menusHaveIcons = QGtkStyle::getGConfBool(QLatin1String("/desktop/gnome/interface/menus_have_icons"), true); |
0 | 2318 |
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !menusHaveIcons); |
2319 |
} |
|
2320 |
#endif |
|
2321 |
qt_set_input_encoding(); |
|
2322 |
||
2323 |
qt_set_x11_resources(appFont, appFGCol, appBGCol, appBTNCol); |
|
2324 |
||
2325 |
// be smart about the size of the default font. most X servers have helvetica |
|
2326 |
// 12 point available at 2 resolutions: |
|
2327 |
// 75dpi (12 pixels) and 100dpi (17 pixels). |
|
2328 |
// At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17 |
|
2329 |
// pixel font is a closer match than a 12 pixel font |
|
2330 |
int ptsz = (X11->use_xrender |
|
2331 |
? 9 |
|
2332 |
: (int) (((QX11Info::appDpiY() >= 95 ? 17. : 12.) * |
|
2333 |
72. / (float) QX11Info::appDpiY()) + 0.5)); |
|
2334 |
||
2335 |
if (!QApplicationPrivate::sys_font) { |
|
2336 |
// no font from settings or RESOURCE_MANAGER, provide a fallback |
|
2337 |
QFont f(X11->has_fontconfig ? QLatin1String("Sans Serif") : QLatin1String("Helvetica"), |
|
2338 |
ptsz); |
|
2339 |
QApplicationPrivate::setSystemFont(f); |
|
2340 |
} |
|
2341 |
||
2342 |
#if !defined (QT_NO_TABLET) |
|
2343 |
if (X11->use_xinput) { |
|
2344 |
int ndev, |
|
2345 |
i, |
|
2346 |
j; |
|
2347 |
bool gotStylus, |
|
2348 |
gotEraser; |
|
2349 |
XDeviceInfo *devices = 0, *devs; |
|
2350 |
XInputClassInfo *ip; |
|
2351 |
XAnyClassPtr any; |
|
2352 |
XValuatorInfoPtr v; |
|
2353 |
XAxisInfoPtr a; |
|
2354 |
XDevice *dev = 0; |
|
2355 |
||
2356 |
if (X11->ptrXListInputDevices) { |
|
2357 |
devices = X11->ptrXListInputDevices(X11->display, &ndev); |
|
2358 |
if (!devices) |
|
2359 |
qWarning("QApplication: Failed to get list of tablet devices"); |
|
2360 |
} |
|
2361 |
if (!devices) |
|
2362 |
ndev = -1; |
|
2363 |
QTabletEvent::TabletDevice deviceType; |
|
2364 |
for (devs = devices, i = 0; i < ndev && devs; i++, devs++) { |
|
2365 |
dev = 0; |
|
2366 |
deviceType = QTabletEvent::NoDevice; |
|
2367 |
gotStylus = false; |
|
2368 |
gotEraser = false; |
|
2369 |
||
2370 |
#if defined(Q_OS_IRIX) |
|
2371 |
QString devName = QString::fromLocal8Bit(devs->name).toLower(); |
|
2372 |
if (devName == QLatin1String(WACOM_NAME)) { |
|
2373 |
deviceType = QTabletEvent::Stylus; |
|
2374 |
gotStylus = true; |
|
2375 |
} |
|
2376 |
#else |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2377 |
if (devs->type == ATOM(XWacomStylus) || devs->type == ATOM(XTabletStylus)) { |
0 | 2378 |
deviceType = QTabletEvent::Stylus; |
2379 |
if (wacomDeviceName()->isEmpty()) |
|
2380 |
wacomDeviceName()->append(devs->name); |
|
2381 |
gotStylus = true; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2382 |
} else if (devs->type == ATOM(XWacomEraser) || devs->type == ATOM(XTabletEraser)) { |
0 | 2383 |
deviceType = QTabletEvent::XFreeEraser; |
2384 |
gotEraser = true; |
|
2385 |
} |
|
2386 |
#endif |
|
2387 |
if (deviceType == QTabletEvent::NoDevice) |
|
2388 |
continue; |
|
2389 |
||
2390 |
if (gotStylus || gotEraser) { |
|
2391 |
if (X11->ptrXOpenDevice) |
|
2392 |
dev = X11->ptrXOpenDevice(X11->display, devs->id); |
|
2393 |
||
2394 |
if (!dev) |
|
2395 |
continue; |
|
2396 |
||
2397 |
QTabletDeviceData device_data; |
|
2398 |
device_data.deviceType = deviceType; |
|
2399 |
device_data.eventCount = 0; |
|
2400 |
device_data.device = dev; |
|
2401 |
device_data.xinput_motion = -1; |
|
2402 |
device_data.xinput_key_press = -1; |
|
2403 |
device_data.xinput_key_release = -1; |
|
2404 |
device_data.xinput_button_press = -1; |
|
2405 |
device_data.xinput_button_release = -1; |
|
2406 |
device_data.xinput_proximity_in = -1; |
|
2407 |
device_data.xinput_proximity_out = -1; |
|
2408 |
device_data.widgetToGetPress = 0; |
|
2409 |
||
2410 |
if (dev->num_classes > 0) { |
|
2411 |
for (ip = dev->classes, j = 0; j < dev->num_classes; |
|
2412 |
ip++, j++) { |
|
2413 |
switch (ip->input_class) { |
|
2414 |
case KeyClass: |
|
2415 |
DeviceKeyPress(dev, device_data.xinput_key_press, |
|
2416 |
device_data.eventList[device_data.eventCount]); |
|
2417 |
if (device_data.eventList[device_data.eventCount]) |
|
2418 |
++device_data.eventCount; |
|
2419 |
DeviceKeyRelease(dev, device_data.xinput_key_release, |
|
2420 |
device_data.eventList[device_data.eventCount]); |
|
2421 |
if (device_data.eventList[device_data.eventCount]) |
|
2422 |
++device_data.eventCount; |
|
2423 |
break; |
|
2424 |
case ButtonClass: |
|
2425 |
DeviceButtonPress(dev, device_data.xinput_button_press, |
|
2426 |
device_data.eventList[device_data.eventCount]); |
|
2427 |
if (device_data.eventList[device_data.eventCount]) |
|
2428 |
++device_data.eventCount; |
|
2429 |
DeviceButtonRelease(dev, device_data.xinput_button_release, |
|
2430 |
device_data.eventList[device_data.eventCount]); |
|
2431 |
if (device_data.eventList[device_data.eventCount]) |
|
2432 |
++device_data.eventCount; |
|
2433 |
break; |
|
2434 |
case ValuatorClass: |
|
2435 |
// I'm only going to be interested in motion when the |
|
2436 |
// stylus is already down anyway! |
|
2437 |
DeviceMotionNotify(dev, device_data.xinput_motion, |
|
2438 |
device_data.eventList[device_data.eventCount]); |
|
2439 |
if (device_data.eventList[device_data.eventCount]) |
|
2440 |
++device_data.eventCount; |
|
2441 |
ProximityIn(dev, device_data.xinput_proximity_in, device_data.eventList[device_data.eventCount]); |
|
2442 |
if (device_data.eventList[device_data.eventCount]) |
|
2443 |
++device_data.eventCount; |
|
2444 |
ProximityOut(dev, device_data.xinput_proximity_out, device_data.eventList[device_data.eventCount]); |
|
2445 |
if (device_data.eventList[device_data.eventCount]) |
|
2446 |
++device_data.eventCount; |
|
2447 |
default: |
|
2448 |
break; |
|
2449 |
} |
|
2450 |
} |
|
2451 |
} |
|
2452 |
||
2453 |
// get the min/max value for pressure! |
|
2454 |
any = (XAnyClassPtr) (devs->inputclassinfo); |
|
2455 |
for (j = 0; j < devs->num_classes; j++) { |
|
2456 |
if (any->c_class == ValuatorClass) { |
|
2457 |
v = (XValuatorInfoPtr) any; |
|
2458 |
a = (XAxisInfoPtr) ((char *) v + |
|
2459 |
sizeof (XValuatorInfo)); |
|
2460 |
#if defined (Q_OS_IRIX) |
|
2461 |
// I'm not exaclty wild about this, but the |
|
2462 |
// dimensions of the tablet are more relevant here |
|
2463 |
// than the min and max values from the axis |
|
2464 |
// (actually it seems to be 2/3 or what is in the |
|
2465 |
// axis. So we'll try to parse it from this |
|
2466 |
// string. --tws |
|
2467 |
char returnString[SGIDeviceRtrnLen]; |
|
2468 |
int tmp; |
|
2469 |
if (XSGIMiscQueryExtension(X11->display, &tmp, &tmp) |
|
2470 |
&& XSGIDeviceQuery(X11->display, devs->id, |
|
2471 |
"dimensions", returnString)) { |
|
2472 |
QString str = QLatin1String(returnString); |
|
2473 |
int comma = str.indexOf(','); |
|
2474 |
device_data.minX = 0; |
|
2475 |
device_data.minY = 0; |
|
2476 |
device_data.maxX = str.left(comma).toInt(); |
|
2477 |
device_data.maxY = str.mid(comma + 1).toInt(); |
|
2478 |
} else { |
|
2479 |
device_data.minX = a[WAC_XCOORD_I].min_value; |
|
2480 |
device_data.maxX = a[WAC_XCOORD_I].max_value; |
|
2481 |
device_data.minY = a[WAC_YCOORD_I].min_value; |
|
2482 |
device_data.maxY = a[WAC_YCOORD_I].max_value; |
|
2483 |
} |
|
2484 |
device_data.minPressure = a[WAC_PRESSURE_I].min_value; |
|
2485 |
device_data.maxPressure = a[WAC_PRESSURE_I].max_value; |
|
2486 |
device_data.minTanPressure = a[WAC_TAN_PRESSURE_I].min_value; |
|
2487 |
device_data.maxTanPressure = a[WAC_TAN_PRESSURE_I].max_value; |
|
2488 |
device_data.minZ = a[WAC_ZCOORD_I].min_value; |
|
2489 |
device_data.maxZ = a[WAC_ZCOORD_I].max_value; |
|
2490 |
#else |
|
2491 |
device_data.minX = a[0].min_value; |
|
2492 |
device_data.maxX = a[0].max_value; |
|
2493 |
device_data.minY = a[1].min_value; |
|
2494 |
device_data.maxY = a[1].max_value; |
|
2495 |
device_data.minPressure = a[2].min_value; |
|
2496 |
device_data.maxPressure = a[2].max_value; |
|
2497 |
device_data.minTanPressure = 0; |
|
2498 |
device_data.maxTanPressure = 0; |
|
2499 |
device_data.minZ = 0; |
|
2500 |
device_data.maxZ = 0; |
|
2501 |
#endif |
|
2502 |
||
2503 |
// got the max pressure no need to go further... |
|
2504 |
break; |
|
2505 |
} |
|
2506 |
any = (XAnyClassPtr) ((char *) any + any->length); |
|
2507 |
} // end of for loop |
|
2508 |
||
2509 |
tablet_devices()->append(device_data); |
|
2510 |
} // if (gotStylus || gotEraser) |
|
2511 |
} |
|
2512 |
if (X11->ptrXFreeDeviceList) |
|
2513 |
X11->ptrXFreeDeviceList(devices); |
|
2514 |
} |
|
2515 |
#endif // QT_NO_TABLET |
|
2516 |
||
2517 |
X11->startupId = getenv("DESKTOP_STARTUP_ID"); |
|
2518 |
if (X11->startupId) { |
|
2519 |
#ifndef QT_NO_UNSETENV |
|
2520 |
unsetenv("DESKTOP_STARTUP_ID"); |
|
2521 |
#else |
|
2522 |
// it's a small memory leak, however we won't crash if Qt is |
|
2523 |
// unloaded and someones tries to use the envoriment. |
|
2524 |
putenv(strdup("DESKTOP_STARTUP_ID=")); |
|
2525 |
#endif |
|
2526 |
} |
|
2527 |
} else { |
|
2528 |
// read some non-GUI settings when not using the X server... |
|
2529 |
||
2530 |
if (QApplication::desktopSettingsAware()) { |
|
2531 |
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); |
|
2532 |
settings.beginGroup(QLatin1String("Qt")); |
|
2533 |
||
2534 |
// read library (ie. plugin) path list |
|
2535 |
QString libpathkey = QString::fromLatin1("%1.%2/libraryPath") |
|
2536 |
.arg(QT_VERSION >> 16) |
|
2537 |
.arg((QT_VERSION & 0xff00) >> 8); |
|
2538 |
QStringList pathlist = |
|
2539 |
settings.value(libpathkey).toString().split(QLatin1Char(':')); |
|
2540 |
if (! pathlist.isEmpty()) { |
|
2541 |
QStringList::ConstIterator it = pathlist.constBegin(); |
|
2542 |
while (it != pathlist.constEnd()) |
|
2543 |
QApplication::addLibraryPath(*it++); |
|
2544 |
} |
|
2545 |
||
2546 |
QString defaultcodec = settings.value(QLatin1String("defaultCodec"), |
|
2547 |
QVariant(QLatin1String("none"))).toString(); |
|
2548 |
if (defaultcodec != QLatin1String("none")) { |
|
2549 |
QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1()); |
|
2550 |
if (codec) |
|
2551 |
QTextCodec::setCodecForTr(codec); |
|
2552 |
} |
|
2553 |
||
2554 |
settings.endGroup(); // Qt |
|
2555 |
} |
|
2556 |
} |
|
2557 |
||
2558 |
#if !defined (Q_OS_IRIX) && !defined (QT_NO_TABLET) |
|
2559 |
QLibrary wacom(QString::fromLatin1("wacomcfg"), 0); // version 0 is the latest release at time of writing this. |
|
2560 |
if (wacom.load()) { |
|
2561 |
// NOTE: C casts instead of reinterpret_cast for GCC 3.3.x |
|
2562 |
ptrWacomConfigInit = (PtrWacomConfigInit)wacom.resolve("WacomConfigInit"); |
|
2563 |
ptrWacomConfigOpenDevice = (PtrWacomConfigOpenDevice)wacom.resolve("WacomConfigOpenDevice"); |
|
2564 |
ptrWacomConfigGetRawParam = (PtrWacomConfigGetRawParam)wacom.resolve("WacomConfigGetRawParam"); |
|
2565 |
ptrWacomConfigCloseDevice = (PtrWacomConfigCloseDevice)wacom.resolve("WacomConfigCloseDevice"); |
|
2566 |
ptrWacomConfigTerm = (PtrWacomConfigTerm)wacom.resolve("WacomConfigTerm"); |
|
2567 |
||
2568 |
if (ptrWacomConfigInit == 0 || ptrWacomConfigOpenDevice == 0 || ptrWacomConfigGetRawParam == 0 |
|
2569 |
|| ptrWacomConfigCloseDevice == 0 || ptrWacomConfigTerm == 0) { // either we have all, or we have none. |
|
2570 |
ptrWacomConfigInit = 0; |
|
2571 |
ptrWacomConfigOpenDevice = 0; |
|
2572 |
ptrWacomConfigGetRawParam = 0; |
|
2573 |
ptrWacomConfigCloseDevice = 0; |
|
2574 |
ptrWacomConfigTerm = 0; |
|
2575 |
} |
|
2576 |
} |
|
2577 |
#endif |
|
2578 |
} |
|
2579 |
||
2580 |
void QApplicationPrivate::initializeWidgetPaletteHash() |
|
2581 |
{ |
|
2582 |
} |
|
2583 |
||
2584 |
/***************************************************************************** |
|
2585 |
qt_cleanup() - cleans up when the application is finished |
|
2586 |
*****************************************************************************/ |
|
2587 |
||
2588 |
void qt_cleanup() |
|
2589 |
{ |
|
2590 |
if (app_save_rootinfo) // root window must keep state |
|
2591 |
qt_save_rootinfo(); |
|
2592 |
||
2593 |
if (qt_is_gui_used) { |
|
2594 |
QPixmapCache::clear(); |
|
2595 |
QCursorData::cleanup(); |
|
2596 |
QFont::cleanup(); |
|
2597 |
QColormap::cleanup(); |
|
2598 |
||
2599 |
#if !defined (QT_NO_TABLET) |
|
2600 |
QTabletDeviceDataList *devices = qt_tablet_devices(); |
|
2601 |
if (X11->ptrXCloseDevice) |
|
2602 |
for (int i = 0; i < devices->size(); ++i) |
|
2603 |
X11->ptrXCloseDevice(X11->display, (XDevice*)devices->at(i).device); |
|
2604 |
devices->clear(); |
|
2605 |
#endif |
|
2606 |
} |
|
2607 |
||
2608 |
#ifndef QT_NO_XRENDER |
|
2609 |
for (int i = 0; i < X11->solid_fill_count; ++i) { |
|
2610 |
if (X11->solid_fills[i].picture) |
|
2611 |
XRenderFreePicture(X11->display, X11->solid_fills[i].picture); |
|
2612 |
} |
|
2613 |
for (int i = 0; i < X11->pattern_fill_count; ++i) { |
|
2614 |
if (X11->pattern_fills[i].picture) |
|
2615 |
XRenderFreePicture(X11->display, X11->pattern_fills[i].picture); |
|
2616 |
} |
|
2617 |
#endif |
|
2618 |
||
2619 |
#if !defined(QT_NO_IM) |
|
2620 |
delete QApplicationPrivate::inputContext; |
|
2621 |
QApplicationPrivate::inputContext = 0; |
|
2622 |
#endif |
|
2623 |
||
2624 |
// Reset the error handlers |
|
2625 |
if (qt_is_gui_used) |
|
2626 |
XSync(X11->display, False); // sync first to process all possible errors |
|
2627 |
XSetErrorHandler(original_x_errhandler); |
|
2628 |
XSetIOErrorHandler(original_xio_errhandler); |
|
2629 |
||
2630 |
if (X11->argbColormaps) { |
|
2631 |
for (int s = 0; s < X11->screenCount; s++) { |
|
2632 |
if (X11->argbColormaps[s]) |
|
2633 |
XFreeColormap(X11->display, X11->argbColormaps[s]); |
|
2634 |
} |
|
2635 |
} |
|
2636 |
||
2637 |
if (qt_is_gui_used && !X11->foreignDisplay) |
|
2638 |
XCloseDisplay(X11->display); // close X display |
|
2639 |
X11->display = 0; |
|
2640 |
||
2641 |
delete [] X11->screens; |
|
2642 |
delete [] X11->argbVisuals; |
|
2643 |
delete [] X11->argbColormaps; |
|
2644 |
||
2645 |
if (X11->foreignDisplay) { |
|
2646 |
delete [] (char *)appName; |
|
2647 |
appName = 0; |
|
2648 |
} |
|
2649 |
||
2650 |
delete [] (char *)appClass; |
|
2651 |
appClass = 0; |
|
2652 |
||
2653 |
if (X11->net_supported_list) |
|
2654 |
delete [] X11->net_supported_list; |
|
2655 |
X11->net_supported_list = 0; |
|
2656 |
||
2657 |
if (X11->net_virtual_root_list) |
|
2658 |
delete [] X11->net_virtual_root_list; |
|
2659 |
X11->net_virtual_root_list = 0; |
|
2660 |
||
2661 |
delete X11; |
|
2662 |
X11 = 0; |
|
2663 |
} |
|
2664 |
||
2665 |
||
2666 |
/***************************************************************************** |
|
2667 |
Platform specific global and internal functions |
|
2668 |
*****************************************************************************/ |
|
2669 |
||
2670 |
void qt_save_rootinfo() // save new root info |
|
2671 |
{ |
|
2672 |
Atom type; |
|
2673 |
int format; |
|
2674 |
unsigned long length, after; |
|
2675 |
uchar *data = 0; |
|
2676 |
||
2677 |
if (ATOM(_XSETROOT_ID)) { // kill old pixmap |
|
2678 |
if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(), |
|
2679 |
ATOM(_XSETROOT_ID), 0, 1, |
|
2680 |
True, AnyPropertyType, &type, &format, |
|
2681 |
&length, &after, &data) == Success) { |
|
2682 |
if (type == XA_PIXMAP && format == 32 && length == 1 && |
|
2683 |
after == 0 && data) { |
|
2684 |
XKillClient(X11->display, *((Pixmap*)data)); |
|
2685 |
} |
|
2686 |
Pixmap dummy = XCreatePixmap(X11->display, QX11Info::appRootWindow(), |
|
2687 |
1, 1, 1); |
|
2688 |
XChangeProperty(X11->display, QX11Info::appRootWindow(), |
|
2689 |
ATOM(_XSETROOT_ID), XA_PIXMAP, 32, |
|
2690 |
PropModeReplace, (uchar *)&dummy, 1); |
|
2691 |
XSetCloseDownMode(X11->display, RetainPermanent); |
|
2692 |
} |
|
2693 |
} |
|
2694 |
if (data) |
|
2695 |
XFree((char *)data); |
|
2696 |
} |
|
2697 |
||
2698 |
void qt_updated_rootinfo() |
|
2699 |
{ |
|
2700 |
app_save_rootinfo = true; |
|
2701 |
} |
|
2702 |
||
2703 |
// ### Cleanup, this function is not in use! |
|
2704 |
bool qt_wstate_iconified(WId winid) |
|
2705 |
{ |
|
2706 |
Atom type; |
|
2707 |
int format; |
|
2708 |
unsigned long length, after; |
|
2709 |
uchar *data = 0; |
|
2710 |
int r = XGetWindowProperty(X11->display, winid, ATOM(WM_STATE), 0, 2, |
|
2711 |
False, AnyPropertyType, &type, &format, |
|
2712 |
&length, &after, &data); |
|
2713 |
bool iconic = false; |
|
2714 |
if (r == Success && data && format == 32) { |
|
2715 |
// quint32 *wstate = (quint32*)data; |
|
2716 |
unsigned long *wstate = (unsigned long *) data; |
|
2717 |
iconic = (*wstate == IconicState); |
|
2718 |
XFree((char *)data); |
|
2719 |
} |
|
2720 |
return iconic; |
|
2721 |
} |
|
2722 |
||
2723 |
QString QApplicationPrivate::appName() const |
|
2724 |
{ |
|
2725 |
return QString::fromLocal8Bit(QT_PREPEND_NAMESPACE(appName)); |
|
2726 |
} |
|
2727 |
||
2728 |
const char *QX11Info::appClass() // get application class |
|
2729 |
{ |
|
2730 |
return QT_PREPEND_NAMESPACE(appClass); |
|
2731 |
} |
|
2732 |
||
2733 |
bool qt_nograb() // application no-grab option |
|
2734 |
{ |
|
2735 |
#if defined(QT_DEBUG) |
|
2736 |
return appNoGrab; |
|
2737 |
#else |
|
2738 |
return false; |
|
2739 |
#endif |
|
2740 |
} |
|
2741 |
||
2742 |
||
2743 |
/***************************************************************************** |
|
2744 |
Platform specific QApplication members |
|
2745 |
*****************************************************************************/ |
|
2746 |
||
2747 |
#ifdef QT3_SUPPORT |
|
2748 |
void QApplication::setMainWidget(QWidget *mainWidget) |
|
2749 |
{ |
|
2750 |
#ifndef QT_NO_DEBUG |
|
2751 |
if (mainWidget && mainWidget->parentWidget() && mainWidget->isWindow()) |
|
2752 |
qWarning("QApplication::setMainWidget: New main widget (%s/%s) " |
|
2753 |
"has a parent", |
|
2754 |
mainWidget->metaObject()->className(), mainWidget->objectName().toLocal8Bit().constData()); |
|
2755 |
#endif |
|
2756 |
if (mainWidget) |
|
2757 |
mainWidget->d_func()->createWinId(); |
|
2758 |
QApplicationPrivate::main_widget = mainWidget; |
|
2759 |
if (QApplicationPrivate::main_widget) // give WM command line |
|
2760 |
QApplicationPrivate::applyX11SpecificCommandLineArguments(QApplicationPrivate::main_widget); |
|
2761 |
} |
|
2762 |
#endif |
|
2763 |
||
2764 |
void QApplicationPrivate::applyX11SpecificCommandLineArguments(QWidget *main_widget) |
|
2765 |
{ |
|
2766 |
static bool beenHereDoneThat = false; |
|
2767 |
if (beenHereDoneThat) |
|
2768 |
return; |
|
2769 |
beenHereDoneThat = true; |
|
2770 |
Q_ASSERT(main_widget->testAttribute(Qt::WA_WState_Created)); |
|
2771 |
if (mwTitle) { |
|
2772 |
XStoreName(X11->display, main_widget->effectiveWinId(), (char*)mwTitle); |
|
2773 |
QByteArray net_wm_name = QString::fromLocal8Bit(mwTitle).toUtf8(); |
|
2774 |
XChangeProperty(X11->display, main_widget->effectiveWinId(), ATOM(_NET_WM_NAME), ATOM(UTF8_STRING), 8, |
|
2775 |
PropModeReplace, (unsigned char *)net_wm_name.data(), net_wm_name.size()); |
|
2776 |
} |
|
2777 |
if (mwGeometry) { // parse geometry |
|
2778 |
int x, y; |
|
2779 |
int w, h; |
|
2780 |
int m = XParseGeometry((char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h); |
|
2781 |
QSize minSize = main_widget->minimumSize(); |
|
2782 |
QSize maxSize = main_widget->maximumSize(); |
|
2783 |
if ((m & XValue) == 0) |
|
2784 |
x = main_widget->geometry().x(); |
|
2785 |
if ((m & YValue) == 0) |
|
2786 |
y = main_widget->geometry().y(); |
|
2787 |
if ((m & WidthValue) == 0) |
|
2788 |
w = main_widget->width(); |
|
2789 |
if ((m & HeightValue) == 0) |
|
2790 |
h = main_widget->height(); |
|
2791 |
w = qMin(w,maxSize.width()); |
|
2792 |
h = qMin(h,maxSize.height()); |
|
2793 |
w = qMax(w,minSize.width()); |
|
2794 |
h = qMax(h,minSize.height()); |
|
2795 |
if ((m & XNegative)) { |
|
2796 |
x = QApplication::desktop()->width() + x - w; |
|
2797 |
} |
|
2798 |
if ((m & YNegative)) { |
|
2799 |
y = QApplication::desktop()->height() + y - h; |
|
2800 |
} |
|
2801 |
main_widget->setGeometry(x, y, w, h); |
|
2802 |
} |
|
2803 |
} |
|
2804 |
||
2805 |
#ifndef QT_NO_CURSOR |
|
2806 |
||
2807 |
/***************************************************************************** |
|
2808 |
QApplication cursor stack |
|
2809 |
*****************************************************************************/ |
|
2810 |
||
2811 |
void QApplication::setOverrideCursor(const QCursor &cursor) |
|
2812 |
{ |
|
2813 |
qApp->d_func()->cursor_list.prepend(cursor); |
|
2814 |
||
2815 |
QWidgetList all = allWidgets(); |
|
2816 |
for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { |
|
2817 |
register QWidget *w = *it; |
|
2818 |
if ((w->testAttribute(Qt::WA_SetCursor) || w->isWindow()) && (w->windowType() != Qt::Desktop)) |
|
2819 |
qt_x11_enforce_cursor(w); |
|
2820 |
} |
|
2821 |
XFlush(X11->display); // make X execute it NOW |
|
2822 |
} |
|
2823 |
||
2824 |
void QApplication::restoreOverrideCursor() |
|
2825 |
{ |
|
2826 |
if (qApp->d_func()->cursor_list.isEmpty()) |
|
2827 |
return; |
|
2828 |
qApp->d_func()->cursor_list.removeFirst(); |
|
2829 |
||
2830 |
if (QWidgetPrivate::mapper != 0 && !closingDown()) { |
|
2831 |
QWidgetList all = allWidgets(); |
|
2832 |
for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) { |
|
2833 |
register QWidget *w = *it; |
|
2834 |
if ((w->testAttribute(Qt::WA_SetCursor) || w->isWindow()) && (w->windowType() != Qt::Desktop)) |
|
2835 |
qt_x11_enforce_cursor(w); |
|
2836 |
} |
|
2837 |
XFlush(X11->display); |
|
2838 |
} |
|
2839 |
} |
|
2840 |
||
2841 |
#endif |
|
2842 |
||
2843 |
||
2844 |
/***************************************************************************** |
|
2845 |
Routines to find a Qt widget from a screen position |
|
2846 |
*****************************************************************************/ |
|
2847 |
||
2848 |
Window QX11Data::findClientWindow(Window win, Atom property, bool leaf) |
|
2849 |
{ |
|
2850 |
Atom type = XNone; |
|
2851 |
int format, i; |
|
2852 |
ulong nitems, after; |
|
2853 |
uchar *data = 0; |
|
2854 |
Window root, parent, target=0, *children=0; |
|
2855 |
uint nchildren; |
|
2856 |
if (XGetWindowProperty(X11->display, win, property, 0, 0, false, AnyPropertyType, |
|
2857 |
&type, &format, &nitems, &after, &data) == Success) { |
|
2858 |
if (data) |
|
2859 |
XFree((char *)data); |
|
2860 |
if (type) |
|
2861 |
return win; |
|
2862 |
} |
|
2863 |
if (!XQueryTree(X11->display,win,&root,&parent,&children,&nchildren)) { |
|
2864 |
if (children) |
|
2865 |
XFree((char *)children); |
|
2866 |
return 0; |
|
2867 |
} |
|
2868 |
for (i=nchildren-1; !target && i >= 0; i--) |
|
2869 |
target = X11->findClientWindow(children[i], property, leaf); |
|
2870 |
if (children) |
|
2871 |
XFree((char *)children); |
|
2872 |
return target; |
|
2873 |
} |
|
2874 |
||
2875 |
QWidget *QApplication::topLevelAt(const QPoint &p) |
|
2876 |
{ |
|
2877 |
#ifdef QT_NO_CURSOR |
|
2878 |
Q_UNUSED(p); |
|
2879 |
return 0; |
|
2880 |
#else |
|
2881 |
int screen = QCursor::x11Screen(); |
|
2882 |
int unused; |
|
2883 |
||
2884 |
int x = p.x(); |
|
2885 |
int y = p.y(); |
|
2886 |
Window target; |
|
2887 |
if (!XTranslateCoordinates(X11->display, |
|
2888 |
QX11Info::appRootWindow(screen), |
|
2889 |
QX11Info::appRootWindow(screen), |
|
2890 |
x, y, &unused, &unused, &target)) { |
|
2891 |
return 0; |
|
2892 |
} |
|
2893 |
if (!target || target == QX11Info::appRootWindow(screen)) |
|
2894 |
return 0; |
|
2895 |
QWidget *w; |
|
2896 |
w = QWidget::find((WId)target); |
|
2897 |
||
2898 |
if (!w) { |
|
2899 |
X11->ignoreBadwindow(); |
|
2900 |
target = X11->findClientWindow(target, ATOM(WM_STATE), true); |
|
2901 |
if (X11->badwindow()) |
|
2902 |
return 0; |
|
2903 |
w = QWidget::find((WId)target); |
|
2904 |
if (!w) { |
|
2905 |
// Perhaps the widget at (x,y) is inside a foreign application? |
|
2906 |
// Search all toplevel widgets to see if one is within target |
|
2907 |
QWidgetList list = QApplication::topLevelWidgets(); |
|
2908 |
for (int i = 0; i < list.count(); ++i) { |
|
2909 |
QWidget *widget = list.at(i); |
|
2910 |
Window ctarget = target; |
|
2911 |
if (widget->isVisible() && !(widget->windowType() == Qt::Desktop)) { |
|
2912 |
Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created)); |
|
2913 |
Window wid = widget->internalWinId(); |
|
2914 |
while (ctarget && !w) { |
|
2915 |
X11->ignoreBadwindow(); |
|
2916 |
if (!XTranslateCoordinates(X11->display, |
|
2917 |
QX11Info::appRootWindow(screen), |
|
2918 |
ctarget, x, y, &unused, &unused, &ctarget) |
|
2919 |
|| X11->badwindow()) |
|
2920 |
break; |
|
2921 |
if (ctarget == wid) { |
|
2922 |
// Found! |
|
2923 |
w = widget; |
|
2924 |
break; |
|
2925 |
} |
|
2926 |
} |
|
2927 |
} |
|
2928 |
if (w) |
|
2929 |
break; |
|
2930 |
} |
|
2931 |
} |
|
2932 |
} |
|
2933 |
return w ? w->window() : 0; |
|
2934 |
#endif |
|
2935 |
} |
|
2936 |
||
2937 |
void QApplication::syncX() |
|
2938 |
{ |
|
2939 |
if (X11->display) |
|
2940 |
XSync(X11->display, False); // don't discard events |
|
2941 |
} |
|
2942 |
||
2943 |
||
2944 |
void QApplication::beep() |
|
2945 |
{ |
|
2946 |
if (X11->display) |
|
2947 |
XBell(X11->display, 0); |
|
2948 |
else |
|
2949 |
printf("\7"); |
|
2950 |
} |
|
2951 |
||
2952 |
void QApplication::alert(QWidget *widget, int msec) |
|
2953 |
{ |
|
2954 |
if (!QApplicationPrivate::checkInstance("alert")) |
|
2955 |
return; |
|
2956 |
||
2957 |
QWidgetList windowsToMark; |
|
2958 |
if (!widget) { |
|
2959 |
windowsToMark += topLevelWidgets(); |
|
2960 |
} else { |
|
2961 |
windowsToMark.append(widget->window()); |
|
2962 |
} |
|
2963 |
||
2964 |
for (int i = 0; i < windowsToMark.size(); ++i) { |
|
2965 |
QWidget *window = windowsToMark.at(i); |
|
2966 |
if (!window->isActiveWindow()) { |
|
2967 |
qt_change_net_wm_state(window, true, ATOM(_NET_WM_STATE_DEMANDS_ATTENTION)); |
|
2968 |
if (msec != 0) { |
|
2969 |
QTimer *timer = new QTimer(qApp); |
|
2970 |
timer->setSingleShot(true); |
|
2971 |
connect(timer, SIGNAL(timeout()), qApp, SLOT(_q_alertTimeOut())); |
|
2972 |
if (QTimer *oldTimer = qApp->d_func()->alertTimerHash.value(window)) { |
|
2973 |
qApp->d_func()->alertTimerHash.remove(window); |
|
2974 |
delete oldTimer; |
|
2975 |
} |
|
2976 |
qApp->d_func()->alertTimerHash.insert(window, timer); |
|
2977 |
timer->start(msec); |
|
2978 |
} |
|
2979 |
} |
|
2980 |
} |
|
2981 |
} |
|
2982 |
||
2983 |
void QApplicationPrivate::_q_alertTimeOut() |
|
2984 |
{ |
|
2985 |
if (QTimer *timer = qobject_cast<QTimer *>(q_func()->sender())) { |
|
2986 |
QHash<QWidget *, QTimer *>::iterator it = alertTimerHash.begin(); |
|
2987 |
while (it != alertTimerHash.end()) { |
|
2988 |
if (it.value() == timer) { |
|
2989 |
QWidget *window = it.key(); |
|
2990 |
qt_change_net_wm_state(window, false, ATOM(_NET_WM_STATE_DEMANDS_ATTENTION)); |
|
2991 |
alertTimerHash.erase(it); |
|
2992 |
timer->deleteLater(); |
|
2993 |
break; |
|
2994 |
} |
|
2995 |
++it; |
|
2996 |
} |
|
2997 |
} |
|
2998 |
} |
|
2999 |
||
3000 |
/***************************************************************************** |
|
3001 |
Special lookup functions for windows that have been reparented recently |
|
3002 |
*****************************************************************************/ |
|
3003 |
||
3004 |
static QWidgetMapper *wPRmapper = 0; // alternative widget mapper |
|
3005 |
||
3006 |
void qPRCreate(const QWidget *widget, Window oldwin) |
|
3007 |
{ // QWidget::reparent mechanism |
|
3008 |
if (!wPRmapper) |
|
3009 |
wPRmapper = new QWidgetMapper; |
|
3010 |
||
3011 |
QETWidget *w = static_cast<QETWidget *>(const_cast<QWidget *>(widget)); |
|
3012 |
wPRmapper->insert((int)oldwin, w); // add old window to mapper |
|
3013 |
w->setAttribute(Qt::WA_WState_Reparented); // set reparented flag |
|
3014 |
} |
|
3015 |
||
3016 |
void qPRCleanup(QWidget *widget) |
|
3017 |
{ |
|
3018 |
QETWidget *etw = static_cast<QETWidget *>(const_cast<QWidget *>(widget)); |
|
3019 |
if (!(wPRmapper && widget->testAttribute(Qt::WA_WState_Reparented))) |
|
3020 |
return; // not a reparented widget |
|
3021 |
QWidgetMapper::Iterator it = wPRmapper->begin(); |
|
3022 |
while (it != wPRmapper->constEnd()) { |
|
3023 |
QWidget *w = *it; |
|
3024 |
if (w == etw) { // found widget |
|
3025 |
etw->setAttribute(Qt::WA_WState_Reparented, false); // clear flag |
|
3026 |
it = wPRmapper->erase(it);// old window no longer needed |
|
3027 |
} else { |
|
3028 |
++it; |
|
3029 |
} |
|
3030 |
} |
|
3031 |
if (wPRmapper->size() == 0) { // became empty |
|
3032 |
delete wPRmapper; // then reset alt mapper |
|
3033 |
wPRmapper = 0; |
|
3034 |
} |
|
3035 |
} |
|
3036 |
||
3037 |
static QETWidget *qPRFindWidget(Window oldwin) |
|
3038 |
{ |
|
3039 |
return wPRmapper ? (QETWidget*)wPRmapper->value((int)oldwin, 0) : 0; |
|
3040 |
} |
|
3041 |
||
3042 |
int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only) |
|
3043 |
{ |
|
3044 |
if (w && !w->internalWinId()) |
|
3045 |
return 0; |
|
3046 |
QETWidget *widget = (QETWidget*)w; |
|
3047 |
if (event->xclient.format == 32 && event->xclient.message_type) { |
|
3048 |
if (event->xclient.message_type == ATOM(WM_PROTOCOLS)) { |
|
3049 |
Atom a = event->xclient.data.l[0]; |
|
3050 |
if (a == ATOM(WM_DELETE_WINDOW)) { |
|
3051 |
if (passive_only) return 0; |
|
3052 |
widget->translateCloseEvent(event); |
|
3053 |
} |
|
3054 |
else if (a == ATOM(WM_TAKE_FOCUS)) { |
|
3055 |
if ((ulong) event->xclient.data.l[1] > X11->time) |
|
3056 |
X11->time = event->xclient.data.l[1]; |
|
3057 |
QWidget *amw = activeModalWidget(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3058 |
if (amw && amw->testAttribute(Qt::WA_X11DoNotAcceptFocus)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3059 |
amw = 0; |
0 | 3060 |
if (amw && !QApplicationPrivate::tryModalHelper(widget, 0)) { |
3061 |
QWidget *p = amw->parentWidget(); |
|
3062 |
while (p && p != widget) |
|
3063 |
p = p->parentWidget(); |
|
3064 |
if (!p || !X11->net_supported_list) |
|
3065 |
amw->raise(); // help broken window managers |
|
3066 |
amw->activateWindow(); |
|
3067 |
} |
|
3068 |
#ifndef QT_NO_WHATSTHIS |
|
3069 |
} else if (a == ATOM(_NET_WM_CONTEXT_HELP)) { |
|
3070 |
QWhatsThis::enterWhatsThisMode(); |
|
3071 |
#endif // QT_NO_WHATSTHIS |
|
3072 |
} else if (a == ATOM(_NET_WM_PING)) { |
|
3073 |
// avoid send/reply loops |
|
3074 |
Window root = RootWindow(X11->display, w->x11Info().screen()); |
|
3075 |
if (event->xclient.window != root) { |
|
3076 |
event->xclient.window = root; |
|
3077 |
XSendEvent(event->xclient.display, event->xclient.window, |
|
3078 |
False, SubstructureNotifyMask|SubstructureRedirectMask, event); |
|
3079 |
} |
|
3080 |
#ifndef QT_NO_XSYNC |
|
3081 |
} else if (a == ATOM(_NET_WM_SYNC_REQUEST)) { |
|
3082 |
const ulong timestamp = (const ulong) event->xclient.data.l[1]; |
|
3083 |
if (timestamp > X11->time) |
|
3084 |
X11->time = timestamp; |
|
3085 |
if (QTLWExtra *tlw = w->d_func()->maybeTopData()) { |
|
3086 |
if (timestamp == CurrentTime || timestamp > tlw->syncRequestTimestamp) { |
|
3087 |
tlw->syncRequestTimestamp = timestamp; |
|
3088 |
tlw->newCounterValueLo = event->xclient.data.l[2]; |
|
3089 |
tlw->newCounterValueHi = event->xclient.data.l[3]; |
|
3090 |
} |
|
3091 |
} |
|
3092 |
#endif |
|
3093 |
} |
|
3094 |
} else if (event->xclient.message_type == ATOM(_QT_SCROLL_DONE)) { |
|
3095 |
widget->translateScrollDoneEvent(event); |
|
3096 |
} else if (event->xclient.message_type == ATOM(XdndPosition)) { |
|
3097 |
X11->xdndHandlePosition(widget, event, passive_only); |
|
3098 |
} else if (event->xclient.message_type == ATOM(XdndEnter)) { |
|
3099 |
X11->xdndHandleEnter(widget, event, passive_only); |
|
3100 |
} else if (event->xclient.message_type == ATOM(XdndStatus)) { |
|
3101 |
X11->xdndHandleStatus(widget, event, passive_only); |
|
3102 |
} else if (event->xclient.message_type == ATOM(XdndLeave)) { |
|
3103 |
X11->xdndHandleLeave(widget, event, passive_only); |
|
3104 |
} else if (event->xclient.message_type == ATOM(XdndDrop)) { |
|
3105 |
X11->xdndHandleDrop(widget, event, passive_only); |
|
3106 |
} else if (event->xclient.message_type == ATOM(XdndFinished)) { |
|
3107 |
X11->xdndHandleFinished(widget, event, passive_only); |
|
3108 |
} else { |
|
3109 |
if (passive_only) return 0; |
|
3110 |
// All other are interactions |
|
3111 |
} |
|
3112 |
} else { |
|
3113 |
X11->motifdndHandle(widget, event, passive_only); |
|
3114 |
} |
|
3115 |
||
3116 |
return 0; |
|
3117 |
} |
|
3118 |
||
3119 |
int QApplication::x11ProcessEvent(XEvent* event) |
|
3120 |
{ |
|
3121 |
Q_D(QApplication); |
|
3122 |
QScopedLoopLevelCounter loopLevelCounter(d->threadData); |
|
3123 |
||
3124 |
#ifdef ALIEN_DEBUG |
|
3125 |
//qDebug() << "QApplication::x11ProcessEvent:" << event->type; |
|
3126 |
#endif |
|
3127 |
switch (event->type) { |
|
3128 |
case ButtonPress: |
|
3129 |
pressed_window = event->xbutton.window; |
|
3130 |
X11->userTime = event->xbutton.time; |
|
3131 |
// fallthrough intended |
|
3132 |
case ButtonRelease: |
|
3133 |
X11->time = event->xbutton.time; |
|
3134 |
break; |
|
3135 |
case MotionNotify: |
|
3136 |
X11->time = event->xmotion.time; |
|
3137 |
break; |
|
3138 |
case XKeyPress: |
|
3139 |
X11->userTime = event->xkey.time; |
|
3140 |
// fallthrough intended |
|
3141 |
case XKeyRelease: |
|
3142 |
X11->time = event->xkey.time; |
|
3143 |
break; |
|
3144 |
case PropertyNotify: |
|
3145 |
X11->time = event->xproperty.time; |
|
3146 |
break; |
|
3147 |
case EnterNotify: |
|
3148 |
case LeaveNotify: |
|
3149 |
X11->time = event->xcrossing.time; |
|
3150 |
break; |
|
3151 |
case SelectionClear: |
|
3152 |
X11->time = event->xselectionclear.time; |
|
3153 |
break; |
|
3154 |
default: |
|
3155 |
break; |
|
3156 |
} |
|
3157 |
#ifndef QT_NO_XFIXES |
|
3158 |
if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) { |
|
3159 |
XFixesSelectionNotifyEvent *req = |
|
3160 |
reinterpret_cast<XFixesSelectionNotifyEvent *>(event); |
|
3161 |
X11->time = req->selection_timestamp; |
|
3162 |
} |
|
3163 |
#endif |
|
3164 |
||
3165 |
QETWidget *widget = (QETWidget*)QWidget::find((WId)event->xany.window); |
|
3166 |
||
3167 |
if (wPRmapper) { // just did a widget reparent? |
|
3168 |
if (widget == 0) { // not in std widget mapper |
|
3169 |
switch (event->type) { // only for mouse/key events |
|
3170 |
case ButtonPress: |
|
3171 |
case ButtonRelease: |
|
3172 |
case MotionNotify: |
|
3173 |
case XKeyPress: |
|
3174 |
case XKeyRelease: |
|
3175 |
widget = qPRFindWidget(event->xany.window); |
|
3176 |
break; |
|
3177 |
} |
|
3178 |
} |
|
3179 |
else if (widget->testAttribute(Qt::WA_WState_Reparented)) |
|
3180 |
qPRCleanup(widget); // remove from alt mapper |
|
3181 |
} |
|
3182 |
||
3183 |
QETWidget *keywidget=0; |
|
3184 |
bool grabbed=false; |
|
3185 |
if (event->type==XKeyPress || event->type==XKeyRelease) { |
|
3186 |
keywidget = (QETWidget*)QWidget::keyboardGrabber(); |
|
3187 |
if (keywidget) { |
|
3188 |
grabbed = true; |
|
3189 |
} else if (!keywidget) { |
|
3190 |
if (d->inPopupMode()) // no focus widget, see if we have a popup |
|
3191 |
keywidget = (QETWidget*) (activePopupWidget()->focusWidget() ? activePopupWidget()->focusWidget() : activePopupWidget()); |
|
3192 |
else if (QApplicationPrivate::focus_widget) |
|
3193 |
keywidget = (QETWidget*)QApplicationPrivate::focus_widget; |
|
3194 |
else if (widget) |
|
3195 |
keywidget = (QETWidget*)widget->window(); |
|
3196 |
} |
|
3197 |
} |
|
3198 |
||
3199 |
#ifndef QT_NO_IM |
|
3200 |
// Filtering input events by the input context. It has to be taken |
|
3201 |
// place before any other key event consumers such as eventfilters |
|
3202 |
// and accelerators because some input methods require quite |
|
3203 |
// various key combination and sequences. It often conflicts with |
|
3204 |
// accelerators and so on, so we must give the input context the |
|
3205 |
// filtering opportunity first to ensure all input methods work |
|
3206 |
// properly regardless of application design. |
|
3207 |
||
3208 |
if(keywidget && keywidget->isEnabled() && keywidget->testAttribute(Qt::WA_InputMethodEnabled)) { |
|
3209 |
// block user interaction during session management |
|
3210 |
if((event->type==XKeyPress || event->type==XKeyRelease) && qt_sm_blockUserInput) |
|
3211 |
return true; |
|
3212 |
||
3213 |
// for XIM handling |
|
3214 |
QInputContext *qic = keywidget->inputContext(); |
|
3215 |
if(qic && qic->x11FilterEvent(keywidget, event)) |
|
3216 |
return true; |
|
3217 |
||
3218 |
// filterEvent() accepts QEvent *event rather than preexpanded |
|
3219 |
// key event attribute values. This is intended to pass other |
|
3220 |
// QInputEvent in future. Other non IM-related events should |
|
3221 |
// not be forwarded to input contexts to prevent weird event |
|
3222 |
// handling. |
|
3223 |
if ((event->type == XKeyPress || event->type == XKeyRelease)) { |
|
3224 |
int code = -1; |
|
3225 |
int count = 0; |
|
3226 |
Qt::KeyboardModifiers modifiers; |
|
3227 |
QEvent::Type type; |
|
3228 |
QString text; |
|
3229 |
KeySym keySym; |
|
3230 |
||
3231 |
qt_keymapper_private()->translateKeyEventInternal(keywidget, event, keySym, count, |
|
3232 |
text, modifiers, code, type, false); |
|
3233 |
||
3234 |
// both key press/release is required for some complex |
|
3235 |
// input methods. don't eliminate anything. |
|
3236 |
QKeyEventEx keyevent(type, code, modifiers, text, false, qMax(qMax(count, 1), text.length()), |
|
3237 |
event->xkey.keycode, keySym, event->xkey.state); |
|
3238 |
if(qic && qic->filterEvent(&keyevent)) |
|
3239 |
return true; |
|
3240 |
} |
|
3241 |
} else |
|
3242 |
#endif // QT_NO_IM |
|
3243 |
{ |
|
3244 |
if (XFilterEvent(event, XNone)) |
|
3245 |
return true; |
|
3246 |
} |
|
3247 |
||
3248 |
if (qt_x11EventFilter(event)) // send through app filter |
|
3249 |
return 1; |
|
3250 |
||
3251 |
if (event->type == MappingNotify) { |
|
3252 |
// keyboard mapping changed |
|
3253 |
XRefreshKeyboardMapping(&event->xmapping); |
|
3254 |
||
3255 |
QKeyMapper::changeKeyboard(); |
|
3256 |
return 0; |
|
3257 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3258 |
#ifndef QT_NO_XKB |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3259 |
else if (X11->use_xkb && event->type == X11->xkb_eventbase) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3260 |
XkbAnyEvent *xkbevent = (XkbAnyEvent *) event; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3261 |
switch (xkbevent->xkb_type) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3262 |
case XkbStateNotify: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3263 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3264 |
XkbStateNotifyEvent *xkbstateevent = (XkbStateNotifyEvent *) xkbevent; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3265 |
if ((xkbstateevent->changed & XkbGroupStateMask) != 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3266 |
qt_keymapper_private()->xkb_currentGroup = xkbstateevent->group; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3267 |
QKeyMapper::changeKeyboard(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3268 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3269 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3270 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3271 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3272 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3273 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3274 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3275 |
#endif |
0 | 3276 |
|
3277 |
if (!widget) { // don't know this windows |
|
3278 |
QWidget* popup = QApplication::activePopupWidget(); |
|
3279 |
if (popup) { |
|
3280 |
||
3281 |
/* |
|
3282 |
That is more than suboptimal. The real solution should |
|
3283 |
do some keyevent and buttonevent translation, so that |
|
3284 |
the popup still continues to work as the user expects. |
|
3285 |
Unfortunately this translation is currently only |
|
3286 |
possible with a known widget. I'll change that soon |
|
3287 |
(Matthias). |
|
3288 |
*/ |
|
3289 |
||
3290 |
// Danger - make sure we don't lock the server |
|
3291 |
switch (event->type) { |
|
3292 |
case ButtonPress: |
|
3293 |
case ButtonRelease: |
|
3294 |
case XKeyPress: |
|
3295 |
case XKeyRelease: |
|
3296 |
do { |
|
3297 |
popup->close(); |
|
3298 |
} while ((popup = qApp->activePopupWidget())); |
|
3299 |
return 1; |
|
3300 |
} |
|
3301 |
} |
|
3302 |
return -1; |
|
3303 |
} |
|
3304 |
||
3305 |
if (event->type == XKeyPress || event->type == XKeyRelease) |
|
3306 |
widget = keywidget; // send XKeyEvents through keywidget->x11Event() |
|
3307 |
||
3308 |
if (app_do_modal) // modal event handling |
|
3309 |
if (!qt_try_modal(widget, event)) { |
|
3310 |
if (event->type == ClientMessage && !widget->x11Event(event)) |
|
3311 |
x11ClientMessage(widget, event, true); |
|
3312 |
return 1; |
|
3313 |
} |
|
3314 |
||
3315 |
||
3316 |
if (widget->x11Event(event)) // send through widget filter |
|
3317 |
return 1; |
|
3318 |
#if !defined (QT_NO_TABLET) |
|
3319 |
if (!qt_xdnd_dragging) { |
|
3320 |
QTabletDeviceDataList *tablets = qt_tablet_devices(); |
|
3321 |
for (int i = 0; i < tablets->size(); ++i) { |
|
3322 |
QTabletDeviceData &tab = tablets->operator [](i); |
|
3323 |
if (event->type == tab.xinput_motion |
|
3324 |
|| event->type == tab.xinput_button_release |
|
3325 |
|| event->type == tab.xinput_button_press |
|
3326 |
|| event->type == tab.xinput_proximity_in |
|
3327 |
|| event->type == tab.xinput_proximity_out) { |
|
3328 |
widget->translateXinputEvent(event, &tab); |
|
3329 |
return 0; |
|
3330 |
} |
|
3331 |
} |
|
3332 |
} |
|
3333 |
#endif |
|
3334 |
||
3335 |
#ifndef QT_NO_XRANDR |
|
3336 |
if (X11->use_xrandr && event->type == (X11->xrandr_eventbase + RRScreenChangeNotify)) { |
|
3337 |
// update Xlib internals with the latest screen configuration |
|
3338 |
X11->ptrXRRUpdateConfiguration(event); |
|
3339 |
||
3340 |
// update the size for desktop widget |
|
3341 |
int scr = X11->ptrXRRRootToScreen(X11->display, event->xany.window); |
|
3342 |
QDesktopWidget *desktop = QApplication::desktop(); |
|
3343 |
QWidget *w = desktop->screen(scr); |
|
3344 |
QSize oldSize(w->size()); |
|
3345 |
w->data->crect.setWidth(DisplayWidth(X11->display, scr)); |
|
3346 |
w->data->crect.setHeight(DisplayHeight(X11->display, scr)); |
|
3347 |
QResizeEvent e(w->size(), oldSize); |
|
3348 |
QApplication::sendEvent(w, &e); |
|
3349 |
if (w != desktop) |
|
3350 |
QApplication::sendEvent(desktop, &e); |
|
3351 |
} |
|
3352 |
#endif // QT_NO_XRANDR |
|
3353 |
||
3354 |
#ifndef QT_NO_XFIXES |
|
3355 |
if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) { |
|
3356 |
XFixesSelectionNotifyEvent *req = reinterpret_cast<XFixesSelectionNotifyEvent *>(event); |
|
3357 |
||
3358 |
// compress all XFixes events related to this selection |
|
3359 |
// we don't want to handle old SelectionNotify events. |
|
3360 |
qt_xfixes_selection_event_data xfixes_event; |
|
3361 |
xfixes_event.selection = req->selection; |
|
3362 |
for (XEvent ev;;) { |
|
3363 |
if (!XCheckIfEvent(X11->display, &ev, &qt_xfixes_scanner, (XPointer)&xfixes_event)) |
|
3364 |
break; |
|
3365 |
} |
|
3366 |
||
3367 |
if (req->selection == ATOM(CLIPBOARD)) { |
|
3368 |
if (qt_xfixes_clipboard_changed(req->owner, req->selection_timestamp)) { |
|
3369 |
emit clipboard()->changed(QClipboard::Clipboard); |
|
3370 |
emit clipboard()->dataChanged(); |
|
3371 |
} |
|
3372 |
} else if (req->selection == XA_PRIMARY) { |
|
3373 |
if (qt_xfixes_selection_changed(req->owner, req->selection_timestamp)) { |
|
3374 |
emit clipboard()->changed(QClipboard::Selection); |
|
3375 |
emit clipboard()->selectionChanged(); |
|
3376 |
} |
|
3377 |
} |
|
3378 |
} |
|
3379 |
#endif // QT_NO_XFIXES |
|
3380 |
||
3381 |
switch (event->type) { |
|
3382 |
||
3383 |
case ButtonRelease: // mouse event |
|
3384 |
if (!d->inPopupMode() && !QWidget::mouseGrabber() && pressed_window != widget->internalWinId() |
|
3385 |
&& (widget = (QETWidget*) QWidget::find((WId)pressed_window)) == 0) |
|
3386 |
break; |
|
3387 |
// fall through intended |
|
3388 |
case ButtonPress: |
|
3389 |
if (event->xbutton.root != RootWindow(X11->display, widget->x11Info().screen()) |
|
3390 |
&& ! qt_xdnd_dragging) { |
|
3391 |
while (activePopupWidget()) |
|
3392 |
activePopupWidget()->close(); |
|
3393 |
return 1; |
|
3394 |
} |
|
3395 |
if (event->type == ButtonPress) |
|
3396 |
qt_net_update_user_time(widget->window(), X11->userTime); |
|
3397 |
// fall through intended |
|
3398 |
case MotionNotify: |
|
3399 |
#if !defined(QT_NO_TABLET) |
|
3400 |
if (!qt_tabletChokeMouse) { |
|
3401 |
#endif |
|
3402 |
if (widget->testAttribute(Qt::WA_TransparentForMouseEvents)) { |
|
3403 |
QPoint pos(event->xbutton.x, event->xbutton.y); |
|
3404 |
pos = widget->d_func()->mapFromWS(pos); |
|
3405 |
QWidget *window = widget->window(); |
|
3406 |
pos = widget->mapTo(window, pos); |
|
3407 |
if (QWidget *child = window->childAt(pos)) { |
|
3408 |
widget = static_cast<QETWidget *>(child); |
|
3409 |
pos = child->mapFrom(window, pos); |
|
3410 |
event->xbutton.x = pos.x(); |
|
3411 |
event->xbutton.y = pos.y(); |
|
3412 |
} |
|
3413 |
} |
|
3414 |
widget->translateMouseEvent(event); |
|
3415 |
#if !defined(QT_NO_TABLET) |
|
3416 |
} else { |
|
3417 |
qt_tabletChokeMouse = false; |
|
3418 |
} |
|
3419 |
#endif |
|
3420 |
break; |
|
3421 |
||
3422 |
case XKeyPress: // keyboard event |
|
3423 |
qt_net_update_user_time(widget->window(), X11->userTime); |
|
3424 |
// fallthrough intended |
|
3425 |
case XKeyRelease: |
|
3426 |
{ |
|
3427 |
if (keywidget && keywidget->isEnabled()) { // should always exist |
|
3428 |
// qDebug("sending key event"); |
|
3429 |
qt_keymapper_private()->translateKeyEvent(keywidget, event, grabbed); |
|
3430 |
} |
|
3431 |
break; |
|
3432 |
} |
|
3433 |
||
3434 |
case GraphicsExpose: |
|
3435 |
case Expose: // paint event |
|
3436 |
widget->translatePaintEvent(event); |
|
3437 |
break; |
|
3438 |
||
3439 |
case ConfigureNotify: // window move/resize event |
|
3440 |
if (event->xconfigure.event == event->xconfigure.window) |
|
3441 |
widget->translateConfigEvent(event); |
|
3442 |
break; |
|
3443 |
||
3444 |
case XFocusIn: { // got focus |
|
3445 |
if ((widget->windowType() == Qt::Desktop)) |
|
3446 |
break; |
|
3447 |
if (d->inPopupMode()) // some delayed focus event to ignore |
|
3448 |
break; |
|
3449 |
if (!widget->isWindow()) |
|
3450 |
break; |
|
3451 |
if (event->xfocus.detail != NotifyAncestor && |
|
3452 |
event->xfocus.detail != NotifyInferior && |
|
3453 |
event->xfocus.detail != NotifyNonlinear) |
|
3454 |
break; |
|
3455 |
setActiveWindow(widget); |
|
3456 |
if (X11->focus_model == QX11Data::FM_PointerRoot) { |
|
3457 |
// We got real input focus from somewhere, but we were in PointerRoot |
|
3458 |
// mode, so we don't trust this event. Check the focus model to make |
|
3459 |
// sure we know what focus mode we are using... |
|
3460 |
qt_check_focus_model(); |
|
3461 |
} |
|
3462 |
} |
|
3463 |
break; |
|
3464 |
||
3465 |
case XFocusOut: // lost focus |
|
3466 |
if ((widget->windowType() == Qt::Desktop)) |
|
3467 |
break; |
|
3468 |
if (!widget->isWindow()) |
|
3469 |
break; |
|
3470 |
if (event->xfocus.mode == NotifyGrab) { |
|
3471 |
qt_xfocusout_grab_counter++; |
|
3472 |
break; |
|
3473 |
} |
|
3474 |
if (event->xfocus.detail != NotifyAncestor && |
|
3475 |
event->xfocus.detail != NotifyNonlinearVirtual && |
|
3476 |
event->xfocus.detail != NotifyNonlinear) |
|
3477 |
break; |
|
3478 |
if (!d->inPopupMode() && widget == QApplicationPrivate::active_window) { |
|
3479 |
XEvent ev; |
|
3480 |
bool focus_will_change = false; |
|
3481 |
if (XCheckTypedEvent(X11->display, XFocusIn, &ev)) { |
|
3482 |
// we're about to get an XFocusIn, if we know we will |
|
3483 |
// get a new active window, we don't want to set the |
|
3484 |
// active window to 0 now |
|
3485 |
QWidget *w2 = QWidget::find(ev.xany.window); |
|
3486 |
if (w2 |
|
3487 |
&& w2->windowType() != Qt::Desktop |
|
3488 |
&& !d->inPopupMode() // some delayed focus event to ignore |
|
3489 |
&& w2->isWindow() |
|
3490 |
&& (ev.xfocus.detail == NotifyAncestor |
|
3491 |
|| ev.xfocus.detail == NotifyInferior |
|
3492 |
|| ev.xfocus.detail == NotifyNonlinear)) |
|
3493 |
focus_will_change = true; |
|
3494 |
||
3495 |
XPutBackEvent(X11->display, &ev); |
|
3496 |
} |
|
3497 |
if (!focus_will_change) |
|
3498 |
setActiveWindow(0); |
|
3499 |
} |
|
3500 |
break; |
|
3501 |
||
3502 |
case EnterNotify: { // enter window |
|
3503 |
if (QWidget::mouseGrabber() && (!d->inPopupMode() || widget->window() != activePopupWidget())) |
|
3504 |
break; |
|
3505 |
if ((event->xcrossing.mode != NotifyNormal |
|
3506 |
&& event->xcrossing.mode != NotifyUngrab) |
|
3507 |
|| event->xcrossing.detail == NotifyVirtual |
|
3508 |
|| event->xcrossing.detail == NotifyNonlinearVirtual) |
|
3509 |
break; |
|
3510 |
if (event->xcrossing.focus && |
|
3511 |
!(widget->windowType() == Qt::Desktop) && !widget->isActiveWindow()) { |
|
3512 |
if (X11->focus_model == QX11Data::FM_Unknown) // check focus model |
|
3513 |
qt_check_focus_model(); |
|
3514 |
if (X11->focus_model == QX11Data::FM_PointerRoot) // PointerRoot mode |
|
3515 |
setActiveWindow(widget); |
|
3516 |
} |
|
3517 |
||
3518 |
if (qt_button_down && !d->inPopupMode()) |
|
3519 |
break; |
|
3520 |
||
3521 |
QWidget *alien = widget->childAt(widget->d_func()->mapFromWS(QPoint(event->xcrossing.x, |
|
3522 |
event->xcrossing.y))); |
|
3523 |
QWidget *enter = alien ? alien : widget; |
|
3524 |
QWidget *leave = 0; |
|
3525 |
if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId()) |
|
3526 |
leave = qt_last_mouse_receiver; |
|
3527 |
else |
|
3528 |
leave = QWidget::find(curWin); |
|
3529 |
||
3530 |
// ### Alien: enter/leave might be wrong here with overlapping siblings |
|
3531 |
// if the enter widget is native and stacked under a non-native widget. |
|
3532 |
QApplicationPrivate::dispatchEnterLeave(enter, leave); |
|
3533 |
curWin = widget->internalWinId(); |
|
3534 |
qt_last_mouse_receiver = enter; |
|
3535 |
if (!d->inPopupMode() || widget->window() == activePopupWidget()) |
|
3536 |
widget->translateMouseEvent(event); //we don't get MotionNotify, emulate it |
|
3537 |
} |
|
3538 |
break; |
|
3539 |
case LeaveNotify: { // leave window |
|
3540 |
QWidget *mouseGrabber = QWidget::mouseGrabber(); |
|
3541 |
if (mouseGrabber && !d->inPopupMode()) |
|
3542 |
break; |
|
3543 |
if (curWin && widget->internalWinId() != curWin) |
|
3544 |
break; |
|
3545 |
if ((event->xcrossing.mode != NotifyNormal |
|
3546 |
&& event->xcrossing.mode != NotifyUngrab) |
|
3547 |
|| event->xcrossing.detail == NotifyInferior) |
|
3548 |
break; |
|
3549 |
if (!(widget->windowType() == Qt::Desktop)) |
|
3550 |
widget->translateMouseEvent(event); //we don't get MotionNotify, emulate it |
|
3551 |
||
3552 |
QWidget* enter = 0; |
|
3553 |
QPoint enterPoint; |
|
3554 |
XEvent ev; |
|
3555 |
while (XCheckMaskEvent(X11->display, EnterWindowMask | LeaveWindowMask , &ev) |
|
3556 |
&& !qt_x11EventFilter(&ev)) { |
|
3557 |
QWidget* event_widget = QWidget::find(ev.xcrossing.window); |
|
3558 |
if(event_widget && event_widget->x11Event(&ev)) |
|
3559 |
break; |
|
3560 |
if (ev.type == LeaveNotify |
|
3561 |
|| (ev.xcrossing.mode != NotifyNormal |
|
3562 |
&& ev.xcrossing.mode != NotifyUngrab) |
|
3563 |
|| ev.xcrossing.detail == NotifyVirtual |
|
3564 |
|| ev.xcrossing.detail == NotifyNonlinearVirtual) |
|
3565 |
continue; |
|
3566 |
enter = event_widget; |
|
3567 |
if (enter) |
|
3568 |
enterPoint = enter->d_func()->mapFromWS(QPoint(ev.xcrossing.x, ev.xcrossing.y)); |
|
3569 |
if (ev.xcrossing.focus && |
|
3570 |
enter && !(enter->windowType() == Qt::Desktop) && !enter->isActiveWindow()) { |
|
3571 |
if (X11->focus_model == QX11Data::FM_Unknown) // check focus model |
|
3572 |
qt_check_focus_model(); |
|
3573 |
if (X11->focus_model == QX11Data::FM_PointerRoot) // PointerRoot mode |
|
3574 |
setActiveWindow(enter); |
|
3575 |
} |
|
3576 |
break; |
|
3577 |
} |
|
3578 |
||
3579 |
if ((! enter || (enter->windowType() == Qt::Desktop)) && |
|
3580 |
event->xcrossing.focus && widget == QApplicationPrivate::active_window && |
|
3581 |
X11->focus_model == QX11Data::FM_PointerRoot // PointerRoot mode |
|
3582 |
) { |
|
3583 |
setActiveWindow(0); |
|
3584 |
} |
|
3585 |
||
3586 |
if (qt_button_down && !d->inPopupMode()) |
|
3587 |
break; |
|
3588 |
||
3589 |
if (!curWin) |
|
3590 |
QApplicationPrivate::dispatchEnterLeave(widget, 0); |
|
3591 |
||
3592 |
if (enter) { |
|
3593 |
QWidget *alienEnter = enter->childAt(enterPoint); |
|
3594 |
if (alienEnter) |
|
3595 |
enter = alienEnter; |
|
3596 |
} |
|
3597 |
||
3598 |
QWidget *leave = qt_last_mouse_receiver ? qt_last_mouse_receiver : widget; |
|
3599 |
QWidget *activePopupWidget = qApp->activePopupWidget(); |
|
3600 |
||
3601 |
if (mouseGrabber && activePopupWidget && leave == activePopupWidget) |
|
3602 |
enter = mouseGrabber; |
|
3603 |
else if (enter != widget && mouseGrabber) { |
|
3604 |
if (!widget->rect().contains(widget->d_func()->mapFromWS(QPoint(event->xcrossing.x, |
|
3605 |
event->xcrossing.y)))) |
|
3606 |
break; |
|
3607 |
} |
|
3608 |
||
3609 |
QApplicationPrivate::dispatchEnterLeave(enter, leave); |
|
3610 |
qt_last_mouse_receiver = enter; |
|
3611 |
||
3612 |
if (enter && QApplicationPrivate::tryModalHelper(enter, 0)) { |
|
3613 |
QWidget *nativeEnter = enter->internalWinId() ? enter : enter->nativeParentWidget(); |
|
3614 |
curWin = nativeEnter->internalWinId(); |
|
3615 |
static_cast<QETWidget *>(nativeEnter)->translateMouseEvent(&ev); //we don't get MotionNotify, emulate it |
|
3616 |
} else { |
|
3617 |
curWin = 0; |
|
3618 |
qt_last_mouse_receiver = 0; |
|
3619 |
} |
|
3620 |
} |
|
3621 |
break; |
|
3622 |
||
3623 |
case UnmapNotify: // window hidden |
|
3624 |
if (widget->isWindow()) { |
|
3625 |
Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created)); |
|
3626 |
widget->d_func()->topData()->waitingForMapNotify = 0; |
|
3627 |
||
3628 |
if (widget->windowType() != Qt::Popup && !widget->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
3629 |
widget->setAttribute(Qt::WA_Mapped, false); |
|
3630 |
if (widget->isVisible()) { |
|
3631 |
widget->d_func()->topData()->spont_unmapped = 1; |
|
3632 |
QHideEvent e; |
|
3633 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
3634 |
widget->d_func()->hideChildren(true); |
|
3635 |
} |
|
3636 |
} |
|
3637 |
||
3638 |
if (!widget->d_func()->topData()->validWMState && X11->deferred_map.removeAll(widget)) |
|
3639 |
widget->doDeferredMap(); |
|
3640 |
} |
|
3641 |
break; |
|
3642 |
||
3643 |
case MapNotify: // window shown |
|
3644 |
if (widget->isWindow()) { |
|
3645 |
widget->d_func()->topData()->waitingForMapNotify = 0; |
|
3646 |
||
3647 |
if (widget->windowType() != Qt::Popup) { |
|
3648 |
widget->setAttribute(Qt::WA_Mapped); |
|
3649 |
if (widget->d_func()->topData()->spont_unmapped) { |
|
3650 |
widget->d_func()->topData()->spont_unmapped = 0; |
|
3651 |
widget->d_func()->showChildren(true); |
|
3652 |
QShowEvent e; |
|
3653 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
3654 |
||
3655 |
// show() must have been called on this widget in |
|
3656 |
// order to reach this point, but we could have |
|
3657 |
// cleared these 2 attributes in case something |
|
3658 |
// previously forced us into WithdrawnState |
|
3659 |
// (e.g. kdocker) |
|
3660 |
widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); |
|
3661 |
widget->setAttribute(Qt::WA_WState_Visible, true); |
|
3662 |
} |
|
3663 |
} |
|
3664 |
} |
|
3665 |
break; |
|
3666 |
||
3667 |
case ClientMessage: // client message |
|
3668 |
return x11ClientMessage(widget,event,False); |
|
3669 |
||
3670 |
case ReparentNotify: { // window manager reparents |
|
3671 |
// compress old reparent events to self |
|
3672 |
XEvent ev; |
|
3673 |
while (XCheckTypedWindowEvent(X11->display, |
|
3674 |
widget->effectiveWinId(), |
|
3675 |
ReparentNotify, |
|
3676 |
&ev)) { |
|
3677 |
if (ev.xreparent.window != ev.xreparent.event) { |
|
3678 |
XPutBackEvent(X11->display, &ev); |
|
3679 |
break; |
|
3680 |
} |
|
3681 |
} |
|
3682 |
if (widget->isWindow()) { |
|
3683 |
QTLWExtra *topData = widget->d_func()->topData(); |
|
3684 |
||
3685 |
// store the parent. Useful for many things, embedding for instance. |
|
3686 |
topData->parentWinId = event->xreparent.parent; |
|
3687 |
||
3688 |
// the widget frame strut should also be invalidated |
|
3689 |
widget->data->fstrut_dirty = 1; |
|
3690 |
||
3691 |
// work around broken window managers... if we get a |
|
3692 |
// ReparentNotify before the MapNotify, we assume that |
|
3693 |
// we're being managed by a reparenting window |
|
3694 |
// manager. |
|
3695 |
// |
|
3696 |
// however, the WM_STATE property may not have been set |
|
3697 |
// yet, but we are going to assume that it will |
|
3698 |
// be... otherwise we could try to map again after getting |
|
3699 |
// an UnmapNotify... which could then, in turn, trigger a |
|
3700 |
// race in the window manager which causes the window to |
|
3701 |
// disappear when it really should be hidden. |
|
3702 |
if (topData->waitingForMapNotify && !topData->validWMState) { |
|
3703 |
topData->waitingForMapNotify = 0; |
|
3704 |
topData->validWMState = 1; |
|
3705 |
} |
|
3706 |
||
3707 |
if (X11->focus_model != QX11Data::FM_Unknown) { |
|
3708 |
// toplevel reparented... |
|
3709 |
QWidget *newparent = QWidget::find(event->xreparent.parent); |
|
3710 |
if (! newparent || (newparent->windowType() == Qt::Desktop)) { |
|
3711 |
// we dont' know about the new parent (or we've been |
|
3712 |
// reparented to root), perhaps a window manager |
|
3713 |
// has been (re)started? reset the focus model to unknown |
|
3714 |
X11->focus_model = QX11Data::FM_Unknown; |
|
3715 |
} |
|
3716 |
} |
|
3717 |
} |
|
3718 |
break; |
|
3719 |
} |
|
3720 |
case SelectionRequest: { |
|
3721 |
XSelectionRequestEvent *req = &event->xselectionrequest; |
|
3722 |
if (! req) |
|
3723 |
break; |
|
3724 |
||
3725 |
if (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection)) { |
|
3726 |
X11->xdndHandleSelectionRequest(req); |
|
3727 |
||
3728 |
} else if (qt_clipboard) { |
|
3729 |
QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event)); |
|
3730 |
QApplication::sendSpontaneousEvent(qt_clipboard, &e); |
|
3731 |
} |
|
3732 |
break; |
|
3733 |
} |
|
3734 |
case SelectionClear: { |
|
3735 |
XSelectionClearEvent *req = &event->xselectionclear; |
|
3736 |
// don't deliver dnd events to the clipboard, it gets confused |
|
3737 |
if (! req || (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection))) |
|
3738 |
break; |
|
3739 |
||
3740 |
if (qt_clipboard && !X11->use_xfixes) { |
|
3741 |
QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event)); |
|
3742 |
QApplication::sendSpontaneousEvent(qt_clipboard, &e); |
|
3743 |
} |
|
3744 |
break; |
|
3745 |
} |
|
3746 |
||
3747 |
case SelectionNotify: { |
|
3748 |
XSelectionEvent *req = &event->xselection; |
|
3749 |
// don't deliver dnd events to the clipboard, it gets confused |
|
3750 |
if (! req || (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection))) |
|
3751 |
break; |
|
3752 |
||
3753 |
if (qt_clipboard) { |
|
3754 |
QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event)); |
|
3755 |
QApplication::sendSpontaneousEvent(qt_clipboard, &e); |
|
3756 |
} |
|
3757 |
break; |
|
3758 |
} |
|
3759 |
case PropertyNotify: |
|
3760 |
// some properties changed |
|
3761 |
if (event->xproperty.window == QX11Info::appRootWindow(0)) { |
|
3762 |
// root properties for the first screen |
|
3763 |
if (!X11->use_xfixes && event->xproperty.atom == ATOM(_QT_CLIPBOARD_SENTINEL)) { |
|
3764 |
if (qt_check_clipboard_sentinel()) { |
|
3765 |
emit clipboard()->changed(QClipboard::Clipboard); |
|
3766 |
emit clipboard()->dataChanged(); |
|
3767 |
} |
|
3768 |
} else if (!X11->use_xfixes && event->xproperty.atom == ATOM(_QT_SELECTION_SENTINEL)) { |
|
3769 |
if (qt_check_selection_sentinel()) { |
|
3770 |
emit clipboard()->changed(QClipboard::Selection); |
|
3771 |
emit clipboard()->selectionChanged(); |
|
3772 |
} |
|
3773 |
} else if (QApplicationPrivate::obey_desktop_settings) { |
|
3774 |
if (event->xproperty.atom == ATOM(RESOURCE_MANAGER)) |
|
3775 |
qt_set_x11_resources(); |
|
3776 |
else if (event->xproperty.atom == ATOM(_QT_SETTINGS_TIMESTAMP)) |
|
3777 |
qt_set_x11_resources(); |
|
3778 |
} |
|
3779 |
} |
|
3780 |
if (event->xproperty.window == QX11Info::appRootWindow()) { |
|
3781 |
// root properties for the default screen |
|
3782 |
if (event->xproperty.atom == ATOM(_QT_INPUT_ENCODING)) { |
|
3783 |
qt_set_input_encoding(); |
|
3784 |
} else if (event->xproperty.atom == ATOM(_NET_SUPPORTED)) { |
|
3785 |
qt_get_net_supported(); |
|
3786 |
} else if (event->xproperty.atom == ATOM(_NET_VIRTUAL_ROOTS)) { |
|
3787 |
qt_get_net_virtual_roots(); |
|
3788 |
} else if (event->xproperty.atom == ATOM(_NET_WORKAREA)) { |
|
3789 |
qt_desktopwidget_update_workarea(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3790 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3791 |
// emit the workAreaResized() signal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3792 |
QDesktopWidget *desktop = QApplication::desktop(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3793 |
int numScreens = desktop->numScreens(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3794 |
for (int i = 0; i < numScreens; ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3795 |
emit desktop->workAreaResized(i); |
0 | 3796 |
} |
3797 |
} else if (widget) { |
|
3798 |
widget->translatePropertyEvent(event); |
|
3799 |
} else { |
|
3800 |
return -1; // don't know this window |
|
3801 |
} |
|
3802 |
break; |
|
3803 |
||
3804 |
default: |
|
3805 |
break; |
|
3806 |
} |
|
3807 |
||
3808 |
return 0; |
|
3809 |
} |
|
3810 |
||
3811 |
bool QApplication::x11EventFilter(XEvent *) |
|
3812 |
{ |
|
3813 |
return false; |
|
3814 |
} |
|
3815 |
||
3816 |
||
3817 |
||
3818 |
/***************************************************************************** |
|
3819 |
Modal widgets; Since Xlib has little support for this we roll our own |
|
3820 |
modal widget mechanism. |
|
3821 |
A modal widget without a parent becomes application-modal. |
|
3822 |
A modal widget with a parent becomes modal to its parent and grandparents.. |
|
3823 |
||
3824 |
QApplicationPrivate::enterModal() |
|
3825 |
Enters modal state |
|
3826 |
Arguments: |
|
3827 |
QWidget *widget A modal widget |
|
3828 |
||
3829 |
QApplicationPrivate::leaveModal() |
|
3830 |
Leaves modal state for a widget |
|
3831 |
Arguments: |
|
3832 |
QWidget *widget A modal widget |
|
3833 |
*****************************************************************************/ |
|
3834 |
||
3835 |
bool QApplicationPrivate::modalState() |
|
3836 |
{ |
|
3837 |
return app_do_modal; |
|
3838 |
} |
|
3839 |
||
3840 |
void QApplicationPrivate::enterModal_sys(QWidget *widget) |
|
3841 |
{ |
|
3842 |
if (!qt_modal_stack) |
|
3843 |
qt_modal_stack = new QWidgetList; |
|
3844 |
||
3845 |
QWidget *leave = qt_last_mouse_receiver; |
|
3846 |
if (!leave) |
|
3847 |
leave = QWidget::find((WId)curWin); |
|
3848 |
QApplicationPrivate::dispatchEnterLeave(0, leave); |
|
3849 |
qt_modal_stack->insert(0, widget); |
|
3850 |
app_do_modal = true; |
|
3851 |
curWin = 0; |
|
3852 |
qt_last_mouse_receiver = 0; |
|
3853 |
} |
|
3854 |
||
3855 |
void QApplicationPrivate::leaveModal_sys(QWidget *widget) |
|
3856 |
{ |
|
3857 |
if (qt_modal_stack && qt_modal_stack->removeAll(widget)) { |
|
3858 |
if (qt_modal_stack->isEmpty()) { |
|
3859 |
delete qt_modal_stack; |
|
3860 |
qt_modal_stack = 0; |
|
3861 |
QPoint p(QCursor::pos()); |
|
3862 |
QWidget* w = QApplication::widgetAt(p.x(), p.y()); |
|
3863 |
QWidget *leave = qt_last_mouse_receiver; |
|
3864 |
if (!leave) |
|
3865 |
leave = QWidget::find((WId)curWin); |
|
3866 |
if (QWidget *grabber = QWidget::mouseGrabber()) { |
|
3867 |
w = grabber; |
|
3868 |
if (leave == w) |
|
3869 |
leave = 0; |
|
3870 |
} |
|
3871 |
QApplicationPrivate::dispatchEnterLeave(w, leave); // send synthetic enter event |
|
3872 |
curWin = w ? w->effectiveWinId() : 0; |
|
3873 |
qt_last_mouse_receiver = w; |
|
3874 |
} |
|
3875 |
} |
|
3876 |
app_do_modal = qt_modal_stack != 0; |
|
3877 |
} |
|
3878 |
||
3879 |
bool qt_try_modal(QWidget *widget, XEvent *event) |
|
3880 |
{ |
|
3881 |
if (qt_xdnd_dragging) { |
|
3882 |
// allow mouse events while DnD is active |
|
3883 |
switch (event->type) { |
|
3884 |
case ButtonPress: |
|
3885 |
case ButtonRelease: |
|
3886 |
case MotionNotify: |
|
3887 |
return true; |
|
3888 |
default: |
|
3889 |
break; |
|
3890 |
} |
|
3891 |
} |
|
3892 |
||
3893 |
// allow mouse release events to be sent to widgets that have been pressed |
|
3894 |
if (event->type == ButtonRelease) { |
|
3895 |
QWidget *alienWidget = widget->childAt(widget->mapFromGlobal(QPoint(event->xbutton.x_root, |
|
3896 |
event->xbutton.y_root))); |
|
3897 |
if (widget == qt_button_down || (alienWidget && alienWidget == qt_button_down)) |
|
3898 |
return true; |
|
3899 |
} |
|
3900 |
||
3901 |
if (QApplicationPrivate::tryModalHelper(widget)) |
|
3902 |
return true; |
|
3903 |
||
3904 |
// disallow mouse/key events |
|
3905 |
switch (event->type) { |
|
3906 |
case ButtonPress: |
|
3907 |
case ButtonRelease: |
|
3908 |
case MotionNotify: |
|
3909 |
case XKeyPress: |
|
3910 |
case XKeyRelease: |
|
3911 |
case EnterNotify: |
|
3912 |
case LeaveNotify: |
|
3913 |
case ClientMessage: |
|
3914 |
return false; |
|
3915 |
default: |
|
3916 |
break; |
|
3917 |
} |
|
3918 |
||
3919 |
return true; |
|
3920 |
} |
|
3921 |
||
3922 |
||
3923 |
/***************************************************************************** |
|
3924 |
Popup widget mechanism |
|
3925 |
||
3926 |
openPopup() |
|
3927 |
Adds a widget to the list of popup widgets |
|
3928 |
Arguments: |
|
3929 |
QWidget *widget The popup widget to be added |
|
3930 |
||
3931 |
closePopup() |
|
3932 |
Removes a widget from the list of popup widgets |
|
3933 |
Arguments: |
|
3934 |
QWidget *widget The popup widget to be removed |
|
3935 |
*****************************************************************************/ |
|
3936 |
||
3937 |
||
3938 |
static int openPopupCount = 0; |
|
3939 |
void QApplicationPrivate::openPopup(QWidget *popup) |
|
3940 |
{ |
|
3941 |
Q_Q(QApplication); |
|
3942 |
openPopupCount++; |
|
3943 |
if (!QApplicationPrivate::popupWidgets) { // create list |
|
3944 |
QApplicationPrivate::popupWidgets = new QWidgetList; |
|
3945 |
} |
|
3946 |
QApplicationPrivate::popupWidgets->append(popup); // add to end of list |
|
3947 |
Display *dpy = X11->display; |
|
3948 |
if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()){ // grab mouse/keyboard |
|
3949 |
Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created)); |
|
3950 |
int r = XGrabKeyboard(dpy, popup->effectiveWinId(), false, |
|
3951 |
GrabModeAsync, GrabModeAsync, X11->time); |
|
3952 |
if ((popupGrabOk = (r == GrabSuccess))) { |
|
3953 |
r = XGrabPointer(dpy, popup->effectiveWinId(), true, |
|
3954 |
(ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
|
3955 |
| EnterWindowMask | LeaveWindowMask | PointerMotionMask), |
|
3956 |
GrabModeAsync, GrabModeAsync, XNone, XNone, X11->time); |
|
3957 |
if (!(popupGrabOk = (r == GrabSuccess))) { |
|
3958 |
// transfer grab back to the keyboard grabber if any |
|
3959 |
if (QWidgetPrivate::keyboardGrabber != 0) |
|
3960 |
QWidgetPrivate::keyboardGrabber->grabKeyboard(); |
|
3961 |
else |
|
3962 |
XUngrabKeyboard(dpy, X11->time); |
|
3963 |
} |
|
3964 |
} |
|
3965 |
} |
|
3966 |
||
3967 |
// popups are not focus-handled by the window system (the first |
|
3968 |
// popup grabbed the keyboard), so we have to do that manually: A |
|
3969 |
// new popup gets the focus |
|
3970 |
if (popup->focusWidget()) { |
|
3971 |
popup->focusWidget()->setFocus(Qt::PopupFocusReason); |
|
3972 |
} else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup |
|
3973 |
if (QWidget *fw = QApplication::focusWidget()) { |
|
3974 |
QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason); |
|
3975 |
q->sendEvent(fw, &e); |
|
3976 |
} |
|
3977 |
} |
|
3978 |
} |
|
3979 |
||
3980 |
void QApplicationPrivate::closePopup(QWidget *popup) |
|
3981 |
{ |
|
3982 |
Q_Q(QApplication); |
|
3983 |
if (!QApplicationPrivate::popupWidgets) |
|
3984 |
return; |
|
3985 |
QApplicationPrivate::popupWidgets->removeAll(popup); |
|
3986 |
if (popup == qt_popup_down) { |
|
3987 |
qt_button_down = 0; |
|
3988 |
qt_popup_down = 0; |
|
3989 |
} |
|
3990 |
if (QApplicationPrivate::popupWidgets->count() == 0) { // this was the last popup |
|
3991 |
delete QApplicationPrivate::popupWidgets; |
|
3992 |
QApplicationPrivate::popupWidgets = 0; |
|
3993 |
if (!qt_nograb() && popupGrabOk) { // grabbing not disabled |
|
3994 |
Display *dpy = X11->display; |
|
3995 |
if (popup->geometry().contains(QPoint(mouseGlobalXPos, mouseGlobalYPos)) |
|
3996 |
|| popup->testAttribute(Qt::WA_NoMouseReplay)) { |
|
3997 |
// mouse release event or inside |
|
3998 |
replayPopupMouseEvent = false; |
|
3999 |
} else { // mouse press event |
|
4000 |
mouseButtonPressTime -= 10000; // avoid double click |
|
4001 |
replayPopupMouseEvent = true; |
|
4002 |
} |
|
4003 |
// transfer grab back to mouse grabber if any, otherwise release the grab |
|
4004 |
if (QWidgetPrivate::mouseGrabber != 0) |
|
4005 |
QWidgetPrivate::mouseGrabber->grabMouse(); |
|
4006 |
else |
|
4007 |
XUngrabPointer(dpy, X11->time); |
|
4008 |
||
4009 |
// transfer grab back to keyboard grabber if any, otherwise release the grab |
|
4010 |
if (QWidgetPrivate::keyboardGrabber != 0) |
|
4011 |
QWidgetPrivate::keyboardGrabber->grabKeyboard(); |
|
4012 |
else |
|
4013 |
XUngrabKeyboard(dpy, X11->time); |
|
4014 |
||
4015 |
XFlush(dpy); |
|
4016 |
} |
|
4017 |
if (QApplicationPrivate::active_window) { |
|
4018 |
if (QWidget *fw = QApplicationPrivate::active_window->focusWidget()) { |
|
4019 |
if (fw != QApplication::focusWidget()) { |
|
4020 |
fw->setFocus(Qt::PopupFocusReason); |
|
4021 |
} else { |
|
4022 |
QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason); |
|
4023 |
q->sendEvent(fw, &e); |
|
4024 |
} |
|
4025 |
} |
|
4026 |
} |
|
4027 |
} else { |
|
4028 |
// popups are not focus-handled by the window system (the |
|
4029 |
// first popup grabbed the keyboard), so we have to do that |
|
4030 |
// manually: A popup was closed, so the previous popup gets |
|
4031 |
// the focus. |
|
4032 |
QWidget* aw = QApplicationPrivate::popupWidgets->last(); |
|
4033 |
if (QWidget *fw = aw->focusWidget()) |
|
4034 |
fw->setFocus(Qt::PopupFocusReason); |
|
4035 |
||
4036 |
// regrab the keyboard and mouse in case 'popup' lost the grab |
|
4037 |
if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()){ // grab mouse/keyboard |
|
4038 |
Display *dpy = X11->display; |
|
4039 |
Q_ASSERT(aw->testAttribute(Qt::WA_WState_Created)); |
|
4040 |
int r = XGrabKeyboard(dpy, aw->effectiveWinId(), false, |
|
4041 |
GrabModeAsync, GrabModeAsync, X11->time); |
|
4042 |
if ((popupGrabOk = (r == GrabSuccess))) { |
|
4043 |
r = XGrabPointer(dpy, aw->effectiveWinId(), true, |
|
4044 |
(ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
|
4045 |
| EnterWindowMask | LeaveWindowMask | PointerMotionMask), |
|
4046 |
GrabModeAsync, GrabModeAsync, XNone, XNone, X11->time); |
|
4047 |
if (!(popupGrabOk = (r == GrabSuccess))) { |
|
4048 |
// transfer grab back to keyboard grabber |
|
4049 |
if (QWidgetPrivate::keyboardGrabber != 0) |
|
4050 |
QWidgetPrivate::keyboardGrabber->grabKeyboard(); |
|
4051 |
else |
|
4052 |
XUngrabKeyboard(dpy, X11->time); |
|
4053 |
} |
|
4054 |
} |
|
4055 |
} |
|
4056 |
} |
|
4057 |
} |
|
4058 |
||
4059 |
/***************************************************************************** |
|
4060 |
Event translation; translates X11 events to Qt events |
|
4061 |
*****************************************************************************/ |
|
4062 |
||
4063 |
// |
|
4064 |
// Mouse event translation |
|
4065 |
// |
|
4066 |
// Xlib doesn't give mouse double click events, so we generate them by |
|
4067 |
// comparing window, time and position between two mouse press events. |
|
4068 |
// |
|
4069 |
||
4070 |
static Qt::MouseButtons translateMouseButtons(int s) |
|
4071 |
{ |
|
4072 |
Qt::MouseButtons ret = 0; |
|
4073 |
if (s & Button1Mask) |
|
4074 |
ret |= Qt::LeftButton; |
|
4075 |
if (s & Button2Mask) |
|
4076 |
ret |= Qt::MidButton; |
|
4077 |
if (s & Button3Mask) |
|
4078 |
ret |= Qt::RightButton; |
|
4079 |
return ret; |
|
4080 |
} |
|
4081 |
||
4082 |
Qt::KeyboardModifiers QX11Data::translateModifiers(int s) |
|
4083 |
{ |
|
4084 |
Qt::KeyboardModifiers ret = 0; |
|
4085 |
if (s & ShiftMask) |
|
4086 |
ret |= Qt::ShiftModifier; |
|
4087 |
if (s & ControlMask) |
|
4088 |
ret |= Qt::ControlModifier; |
|
4089 |
if (s & qt_alt_mask) |
|
4090 |
ret |= Qt::AltModifier; |
|
4091 |
if (s & qt_meta_mask) |
|
4092 |
ret |= Qt::MetaModifier; |
|
4093 |
if (s & qt_mode_switch_mask) |
|
4094 |
ret |= Qt::GroupSwitchModifier; |
|
4095 |
return ret; |
|
4096 |
} |
|
4097 |
||
4098 |
bool QETWidget::translateMouseEvent(const XEvent *event) |
|
4099 |
{ |
|
4100 |
if (!isWindow() && testAttribute(Qt::WA_NativeWindow)) |
|
4101 |
Q_ASSERT(internalWinId()); |
|
4102 |
||
4103 |
Q_D(QWidget); |
|
4104 |
QEvent::Type type; // event parameters |
|
4105 |
QPoint pos; |
|
4106 |
QPoint globalPos; |
|
4107 |
Qt::MouseButton button = Qt::NoButton; |
|
4108 |
Qt::MouseButtons buttons; |
|
4109 |
Qt::KeyboardModifiers modifiers; |
|
4110 |
XEvent nextEvent; |
|
4111 |
||
4112 |
if (qt_sm_blockUserInput) // block user interaction during session management |
|
4113 |
return true; |
|
4114 |
||
4115 |
if (event->type == MotionNotify) { // mouse move |
|
4116 |
if (event->xmotion.root != RootWindow(X11->display, x11Info().screen()) && |
|
4117 |
! qt_xdnd_dragging) |
|
4118 |
return false; |
|
4119 |
||
4120 |
XMotionEvent lastMotion = event->xmotion; |
|
4121 |
while(XPending(X11->display)) { // compress mouse moves |
|
4122 |
XNextEvent(X11->display, &nextEvent); |
|
4123 |
if (nextEvent.type == ConfigureNotify |
|
4124 |
|| nextEvent.type == PropertyNotify |
|
4125 |
|| nextEvent.type == Expose |
|
4126 |
|| nextEvent.type == GraphicsExpose |
|
4127 |
|| nextEvent.type == NoExpose |
|
4128 |
|| nextEvent.type == KeymapNotify |
|
4129 |
|| ((nextEvent.type == EnterNotify || nextEvent.type == LeaveNotify) |
|
4130 |
&& qt_button_down == this) |
|
4131 |
|| (nextEvent.type == ClientMessage |
|
4132 |
&& (nextEvent.xclient.message_type == ATOM(_QT_SCROLL_DONE) || |
|
4133 |
(nextEvent.xclient.message_type == ATOM(WM_PROTOCOLS) && |
|
4134 |
(Atom)nextEvent.xclient.data.l[0] == ATOM(_NET_WM_SYNC_REQUEST))))) { |
|
4135 |
qApp->x11ProcessEvent(&nextEvent); |
|
4136 |
continue; |
|
4137 |
} else if (nextEvent.type != MotionNotify || |
|
4138 |
nextEvent.xmotion.window != event->xmotion.window || |
|
4139 |
nextEvent.xmotion.state != event->xmotion.state) { |
|
4140 |
XPutBackEvent(X11->display, &nextEvent); |
|
4141 |
break; |
|
4142 |
} |
|
4143 |
if (!qt_x11EventFilter(&nextEvent) |
|
4144 |
&& !x11Event(&nextEvent)) // send event through filter |
|
4145 |
lastMotion = nextEvent.xmotion; |
|
4146 |
else |
|
4147 |
break; |
|
4148 |
} |
|
4149 |
type = QEvent::MouseMove; |
|
4150 |
pos.rx() = lastMotion.x; |
|
4151 |
pos.ry() = lastMotion.y; |
|
4152 |
pos = d->mapFromWS(pos); |
|
4153 |
globalPos.rx() = lastMotion.x_root; |
|
4154 |
globalPos.ry() = lastMotion.y_root; |
|
4155 |
buttons = translateMouseButtons(lastMotion.state); |
|
4156 |
modifiers = X11->translateModifiers(lastMotion.state); |
|
4157 |
if (qt_button_down && !buttons) |
|
4158 |
qt_button_down = 0; |
|
4159 |
} else if (event->type == EnterNotify || event->type == LeaveNotify) { |
|
4160 |
XEvent *xevent = (XEvent *)event; |
|
4161 |
//unsigned int xstate = event->xcrossing.state; |
|
4162 |
type = QEvent::MouseMove; |
|
4163 |
pos.rx() = xevent->xcrossing.x; |
|
4164 |
pos.ry() = xevent->xcrossing.y; |
|
4165 |
pos = d->mapFromWS(pos); |
|
4166 |
globalPos.rx() = xevent->xcrossing.x_root; |
|
4167 |
globalPos.ry() = xevent->xcrossing.y_root; |
|
4168 |
buttons = translateMouseButtons(xevent->xcrossing.state); |
|
4169 |
modifiers = X11->translateModifiers(xevent->xcrossing.state); |
|
4170 |
if (qt_button_down && !buttons) |
|
4171 |
qt_button_down = 0; |
|
4172 |
if (qt_button_down) |
|
4173 |
return true; |
|
4174 |
} else { // button press or release |
|
4175 |
pos.rx() = event->xbutton.x; |
|
4176 |
pos.ry() = event->xbutton.y; |
|
4177 |
pos = d->mapFromWS(pos); |
|
4178 |
globalPos.rx() = event->xbutton.x_root; |
|
4179 |
globalPos.ry() = event->xbutton.y_root; |
|
4180 |
buttons = translateMouseButtons(event->xbutton.state); |
|
4181 |
modifiers = X11->translateModifiers(event->xbutton.state); |
|
4182 |
switch (event->xbutton.button) { |
|
4183 |
case Button1: button = Qt::LeftButton; break; |
|
4184 |
case Button2: button = Qt::MidButton; break; |
|
4185 |
case Button3: button = Qt::RightButton; break; |
|
4186 |
case Button4: |
|
4187 |
case Button5: |
|
4188 |
case 6: |
|
4189 |
case 7: |
|
4190 |
// the fancy mouse wheel. |
|
4191 |
||
4192 |
// We are only interested in ButtonPress. |
|
4193 |
if (event->type == ButtonPress){ |
|
4194 |
// compress wheel events (the X Server will simply |
|
4195 |
// send a button press for each single notch, |
|
4196 |
// regardless whether the application can catch up |
|
4197 |
// or not) |
|
4198 |
int delta = 1; |
|
4199 |
XEvent xevent; |
|
4200 |
while (XCheckTypedWindowEvent(X11->display, effectiveWinId(), ButtonPress, &xevent)){ |
|
4201 |
if (xevent.xbutton.button != event->xbutton.button){ |
|
4202 |
XPutBackEvent(X11->display, &xevent); |
|
4203 |
break; |
|
4204 |
} |
|
4205 |
delta++; |
|
4206 |
} |
|
4207 |
||
4208 |
// the delta is defined as multiples of |
|
4209 |
// WHEEL_DELTA, which is set to 120. Future wheels |
|
4210 |
// may offer a finer-resolution. A positive delta |
|
4211 |
// indicates forward rotation, a negative one |
|
4212 |
// backward rotation respectively. |
|
4213 |
int btn = event->xbutton.button; |
|
4214 |
delta *= 120 * ((btn == Button4 || btn == 6) ? 1 : -1); |
|
4215 |
bool hor = (((btn == Button4 || btn == Button5) && (modifiers & Qt::AltModifier)) || |
|
4216 |
(btn == 6 || btn == 7)); |
|
4217 |
translateWheelEvent(globalPos.x(), globalPos.y(), delta, buttons, |
|
4218 |
modifiers, (hor) ? Qt::Horizontal: Qt::Vertical); |
|
4219 |
} |
|
4220 |
return true; |
|
4221 |
case 8: button = Qt::XButton1; break; |
|
4222 |
case 9: button = Qt::XButton2; break; |
|
4223 |
} |
|
4224 |
if (event->type == ButtonPress) { // mouse button pressed |
|
4225 |
buttons |= button; |
|
4226 |
#if defined(Q_OS_IRIX) && !defined(QT_NO_TABLET) |
|
4227 |
QTabletDeviceDataList *tablets = qt_tablet_devices(); |
|
4228 |
for (int i = 0; i < tablets->size(); ++i) { |
|
4229 |
QTabletDeviceData &tab = tablets->operator[](i); |
|
4230 |
XEvent myEv; |
|
4231 |
if (XCheckTypedEvent(X11->display, tab.xinput_button_press, &myEv)) { |
|
4232 |
if (translateXinputEvent(&myEv, &tab)) { |
|
4233 |
//Spontaneous event sent. Check if we need to continue. |
|
4234 |
if (qt_tabletChokeMouse) { |
|
4235 |
qt_tabletChokeMouse = false; |
|
4236 |
return false; |
|
4237 |
} |
|
4238 |
} |
|
4239 |
} |
|
4240 |
} |
|
4241 |
#endif |
|
4242 |
if (!qt_button_down) { |
|
4243 |
qt_button_down = childAt(pos); //magic for masked widgets |
|
4244 |
if (!qt_button_down) |
|
4245 |
qt_button_down = this; |
|
4246 |
} |
|
4247 |
if (mouseActWindow == event->xbutton.window && |
|
4248 |
mouseButtonPressed == button && |
|
4249 |
(long)event->xbutton.time -(long)mouseButtonPressTime |
|
4250 |
< QApplication::doubleClickInterval() && |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4251 |
qAbs(event->xbutton.x - mouseXPos) < QT_GUI_DOUBLE_CLICK_RADIUS && |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4252 |
qAbs(event->xbutton.y - mouseYPos) < QT_GUI_DOUBLE_CLICK_RADIUS) { |
0 | 4253 |
type = QEvent::MouseButtonDblClick; |
4254 |
mouseButtonPressTime -= 2000; // no double-click next time |
|
4255 |
} else { |
|
4256 |
type = QEvent::MouseButtonPress; |
|
4257 |
mouseButtonPressTime = event->xbutton.time; |
|
4258 |
} |
|
4259 |
mouseButtonPressed = button; // save event params for |
|
4260 |
mouseXPos = event->xbutton.x; // future double click tests |
|
4261 |
mouseYPos = event->xbutton.y; |
|
4262 |
mouseGlobalXPos = globalPos.x(); |
|
4263 |
mouseGlobalYPos = globalPos.y(); |
|
4264 |
} else { // mouse button released |
|
4265 |
buttons &= ~button; |
|
4266 |
#if defined(Q_OS_IRIX) && !defined(QT_NO_TABLET) |
|
4267 |
QTabletDeviceDataList *tablets = qt_tablet_devices(); |
|
4268 |
for (int i = 0; i < tablets->size(); ++i) { |
|
4269 |
QTabletDeviceData &tab = tablets->operator[](i); |
|
4270 |
XEvent myEv; |
|
4271 |
if (XCheckTypedEvent(X11->display, tab.xinput_button_press, &myEv)) { |
|
4272 |
if (translateXinputEvent(&myEv, &tab)) { |
|
4273 |
//Spontaneous event sent. Check if we need to continue. |
|
4274 |
if (qt_tabletChokeMouse) { |
|
4275 |
qt_tabletChokeMouse = false; |
|
4276 |
return false; |
|
4277 |
} |
|
4278 |
} |
|
4279 |
} |
|
4280 |
} |
|
4281 |
#endif |
|
4282 |
type = QEvent::MouseButtonRelease; |
|
4283 |
} |
|
4284 |
} |
|
4285 |
mouseActWindow = effectiveWinId(); // save some event params |
|
4286 |
mouseButtonState = buttons; |
|
4287 |
if (type == 0) // don't send event |
|
4288 |
return false; |
|
4289 |
||
4290 |
if (qApp->d_func()->inPopupMode()) { // in popup mode |
|
4291 |
QWidget *activePopupWidget = qApp->activePopupWidget(); |
|
4292 |
QWidget *popup = qApp->activePopupWidget(); |
|
4293 |
if (popup != this) { |
|
4294 |
if (event->type == LeaveNotify) |
|
4295 |
return false; |
|
4296 |
if ((windowType() == Qt::Popup) && rect().contains(pos) && 0) |
|
4297 |
popup = this; |
|
4298 |
else // send to last popup |
|
4299 |
pos = popup->mapFromGlobal(globalPos); |
|
4300 |
} |
|
4301 |
bool releaseAfter = false; |
|
4302 |
QWidget *popupChild = popup->childAt(pos); |
|
4303 |
||
4304 |
if (popup != qt_popup_down){ |
|
4305 |
qt_button_down = 0; |
|
4306 |
qt_popup_down = 0; |
|
4307 |
} |
|
4308 |
||
4309 |
switch (type) { |
|
4310 |
case QEvent::MouseButtonPress: |
|
4311 |
case QEvent::MouseButtonDblClick: |
|
4312 |
qt_button_down = popupChild; |
|
4313 |
qt_popup_down = popup; |
|
4314 |
break; |
|
4315 |
case QEvent::MouseButtonRelease: |
|
4316 |
releaseAfter = true; |
|
4317 |
break; |
|
4318 |
default: |
|
4319 |
break; // nothing for mouse move |
|
4320 |
} |
|
4321 |
||
4322 |
int oldOpenPopupCount = openPopupCount; |
|
4323 |
||
4324 |
if (popup->isEnabled()) { |
|
4325 |
// deliver event |
|
4326 |
replayPopupMouseEvent = false; |
|
4327 |
QWidget *receiver = popup; |
|
4328 |
QPoint widgetPos = pos; |
|
4329 |
if (qt_button_down) |
|
4330 |
receiver = qt_button_down; |
|
4331 |
else if (popupChild) |
|
4332 |
receiver = popupChild; |
|
4333 |
if (receiver != popup) |
|
4334 |
widgetPos = receiver->mapFromGlobal(globalPos); |
|
4335 |
QWidget *alien = childAt(mapFromGlobal(globalPos)); |
|
4336 |
QMouseEvent e(type, widgetPos, globalPos, button, buttons, modifiers); |
|
4337 |
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, this, &qt_button_down, qt_last_mouse_receiver); |
|
4338 |
} else { |
|
4339 |
// close disabled popups when a mouse button is pressed or released |
|
4340 |
switch (type) { |
|
4341 |
case QEvent::MouseButtonPress: |
|
4342 |
case QEvent::MouseButtonDblClick: |
|
4343 |
case QEvent::MouseButtonRelease: |
|
4344 |
popup->close(); |
|
4345 |
break; |
|
4346 |
default: |
|
4347 |
break; |
|
4348 |
} |
|
4349 |
} |
|
4350 |
||
4351 |
if (qApp->activePopupWidget() != activePopupWidget |
|
4352 |
&& replayPopupMouseEvent) { |
|
4353 |
// the active popup was closed, replay the mouse event |
|
4354 |
if (!(windowType() == Qt::Popup)) { |
|
4355 |
#if 1 |
|
4356 |
qt_button_down = 0; |
|
4357 |
#else |
|
4358 |
if (buttons == button) |
|
4359 |
qt_button_down = this; |
|
4360 |
QMouseEvent e(type, mapFromGlobal(globalPos), globalPos, button, |
|
4361 |
buttons, modifiers); |
|
4362 |
QApplication::sendSpontaneousEvent(this, &e); |
|
4363 |
||
4364 |
if (type == QEvent::MouseButtonPress |
|
4365 |
&& button == Qt::RightButton |
|
4366 |
&& (openPopupCount == oldOpenPopupCount)) { |
|
4367 |
QContextMenuEvent e(QContextMenuEvent::Mouse, mapFromGlobal(globalPos), |
|
4368 |
globalPos, modifiers); |
|
4369 |
QApplication::sendSpontaneousEvent(this, &e); |
|
4370 |
} |
|
4371 |
#endif |
|
4372 |
} |
|
4373 |
replayPopupMouseEvent = false; |
|
4374 |
} else if (type == QEvent::MouseButtonPress |
|
4375 |
&& button == Qt::RightButton |
|
4376 |
&& (openPopupCount == oldOpenPopupCount)) { |
|
4377 |
QWidget *popupEvent = popup; |
|
4378 |
if (qt_button_down) |
|
4379 |
popupEvent = qt_button_down; |
|
4380 |
else if(popupChild) |
|
4381 |
popupEvent = popupChild; |
|
4382 |
QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, modifiers); |
|
4383 |
QApplication::sendSpontaneousEvent(popupEvent, &e); |
|
4384 |
} |
|
4385 |
||
4386 |
if (releaseAfter) { |
|
4387 |
qt_button_down = 0; |
|
4388 |
qt_popup_down = 0; |
|
4389 |
} |
|
4390 |
} else { |
|
4391 |
QWidget *alienWidget = childAt(pos); |
|
4392 |
QWidget *widget = QApplicationPrivate::pickMouseReceiver(this, globalPos, pos, type, buttons, |
|
4393 |
qt_button_down, alienWidget); |
|
4394 |
if (!widget) { |
|
4395 |
if (type == QEvent::MouseButtonRelease) |
|
4396 |
QApplicationPrivate::mouse_buttons &= ~button; |
|
4397 |
return false; // don't send event |
|
4398 |
} |
|
4399 |
||
4400 |
int oldOpenPopupCount = openPopupCount; |
|
4401 |
QMouseEvent e(type, pos, globalPos, button, buttons, modifiers); |
|
4402 |
QApplicationPrivate::sendMouseEvent(widget, &e, alienWidget, this, &qt_button_down, |
|
4403 |
qt_last_mouse_receiver); |
|
4404 |
if (type == QEvent::MouseButtonPress |
|
4405 |
&& button == Qt::RightButton |
|
4406 |
&& (openPopupCount == oldOpenPopupCount)) { |
|
4407 |
QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, modifiers); |
|
4408 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
4409 |
} |
|
4410 |
} |
|
4411 |
return true; |
|
4412 |
} |
|
4413 |
||
4414 |
||
4415 |
// |
|
4416 |
// Wheel event translation |
|
4417 |
// |
|
4418 |
bool QETWidget::translateWheelEvent(int global_x, int global_y, int delta, |
|
4419 |
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, |
|
4420 |
Qt::Orientation orient) |
|
4421 |
{ |
|
4422 |
const QPoint globalPos = QPoint(global_x, global_y); |
|
4423 |
QPoint pos = mapFromGlobal(globalPos); |
|
4424 |
QWidget *widget = childAt(pos); |
|
4425 |
if (!widget) |
|
4426 |
widget = this; |
|
4427 |
else if (!widget->internalWinId()) |
|
4428 |
pos = widget->mapFromGlobal(globalPos); |
|
4429 |
||
4430 |
#ifdef ALIEN_DEBUG |
|
4431 |
qDebug() << "QETWidget::translateWheelEvent: receiver:" << widget << "pos:" << pos; |
|
4432 |
#endif |
|
4433 |
||
4434 |
// send the event to the widget or its ancestors |
|
4435 |
{ |
|
4436 |
QWidget* popup = qApp->activePopupWidget(); |
|
4437 |
if (popup && window() != popup) |
|
4438 |
popup->close(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4439 |
#ifndef QT_NO_WHEELEVENT |
0 | 4440 |
QWheelEvent e(pos, globalPos, delta, buttons, modifiers, orient); |
4441 |
if (QApplication::sendSpontaneousEvent(widget, &e)) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4442 |
#endif |
0 | 4443 |
return true; |
4444 |
} |
|
4445 |
||
4446 |
// send the event to the widget that has the focus or its ancestors, if different |
|
4447 |
if (widget != qApp->focusWidget() && (widget = qApp->focusWidget())) { |
|
4448 |
if (widget && !widget->internalWinId()) |
|
4449 |
pos = widget->mapFromGlobal(globalPos); |
|
4450 |
QWidget* popup = qApp->activePopupWidget(); |
|
4451 |
if (popup && widget != popup) |
|
4452 |
popup->hide(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4453 |
#ifndef QT_NO_WHEELEVENT |
0 | 4454 |
QWheelEvent e(pos, globalPos, delta, buttons, modifiers, orient); |
4455 |
if (QApplication::sendSpontaneousEvent(widget, &e)) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4456 |
#endif |
0 | 4457 |
return true; |
4458 |
} |
|
4459 |
return false; |
|
4460 |
} |
|
4461 |
||
4462 |
||
4463 |
// |
|
4464 |
// XInput Translation Event |
|
4465 |
// |
|
4466 |
#if !defined (QT_NO_TABLET) |
|
4467 |
||
4468 |
#if !defined (Q_OS_IRIX) |
|
4469 |
void fetchWacomToolId(int &deviceType, qint64 &serialId) |
|
4470 |
{ |
|
4471 |
if (ptrWacomConfigInit == 0) // we actually have the lib |
|
4472 |
return; |
|
4473 |
WACOMCONFIG *config = ptrWacomConfigInit(X11->display, 0); |
|
4474 |
if (config == 0) |
|
4475 |
return; |
|
4476 |
WACOMDEVICE *device = ptrWacomConfigOpenDevice (config, wacomDeviceName()->constData()); |
|
4477 |
if (device == 0) |
|
4478 |
return; |
|
4479 |
unsigned keys[1]; |
|
4480 |
int serialInt; |
|
4481 |
ptrWacomConfigGetRawParam (device, XWACOM_PARAM_TOOLSERIAL, &serialInt, 1, keys); |
|
4482 |
serialId = serialInt; |
|
4483 |
int toolId; |
|
4484 |
ptrWacomConfigGetRawParam (device, XWACOM_PARAM_TOOLID, &toolId, 1, keys); |
|
4485 |
switch(toolId) { |
|
4486 |
case 0x007: /* Mouse 4D and 2D */ |
|
4487 |
case 0x017: /* Intuos3 2D Mouse */ |
|
4488 |
case 0x094: |
|
4489 |
case 0x09c: |
|
4490 |
deviceType = QTabletEvent::FourDMouse; |
|
4491 |
break; |
|
4492 |
case 0x096: /* Lens cursor */ |
|
4493 |
case 0x097: /* Intuos3 Lens cursor */ |
|
4494 |
deviceType = QTabletEvent::Puck; |
|
4495 |
break; |
|
4496 |
case 0x0fa: |
|
4497 |
case 0x81b: /* Intuos3 Classic Pen Eraser */ |
|
4498 |
case 0x82a: /* Eraser */ |
|
4499 |
case 0x82b: /* Intuos3 Grip Pen Eraser */ |
|
4500 |
case 0x85a: |
|
4501 |
case 0x91a: |
|
4502 |
case 0x91b: /* Intuos3 Airbrush Eraser */ |
|
4503 |
case 0xd1a: |
|
4504 |
deviceType = QTabletEvent::XFreeEraser; |
|
4505 |
break; |
|
4506 |
case 0x112: |
|
4507 |
case 0x912: |
|
4508 |
case 0x913: /* Intuos3 Airbrush */ |
|
4509 |
case 0xd12: |
|
4510 |
deviceType = QTabletEvent::Airbrush; |
|
4511 |
break; |
|
4512 |
case 0x012: |
|
4513 |
case 0x022: |
|
4514 |
case 0x032: |
|
4515 |
case 0x801: /* Intuos3 Inking pen */ |
|
4516 |
case 0x812: /* Inking pen */ |
|
4517 |
case 0x813: /* Intuos3 Classic Pen */ |
|
4518 |
case 0x822: /* Pen */ |
|
4519 |
case 0x823: /* Intuos3 Grip Pen */ |
|
4520 |
case 0x832: /* Stroke pen */ |
|
4521 |
case 0x842: |
|
4522 |
case 0x852: |
|
4523 |
case 0x885: /* Intuos3 Marker Pen */ |
|
4524 |
default: /* Unknown tool */ |
|
4525 |
deviceType = QTabletEvent::Stylus; |
|
4526 |
} |
|
4527 |
||
4528 |
/* Close device and return */ |
|
4529 |
ptrWacomConfigCloseDevice (device); |
|
4530 |
ptrWacomConfigTerm(config); |
|
4531 |
} |
|
4532 |
#endif |
|
4533 |
||
4534 |
struct qt_tablet_motion_data |
|
4535 |
{ |
|
4536 |
bool filterByWidget; |
|
4537 |
const QWidget *widget; |
|
4538 |
const QWidget *etWidget; |
|
4539 |
int tabletMotionType; |
|
4540 |
bool error; // found a reason to stop searching |
|
4541 |
}; |
|
4542 |
||
4543 |
static Bool qt_mouseMotion_scanner(Display *, XEvent *event, XPointer arg) |
|
4544 |
{ |
|
4545 |
qt_tablet_motion_data *data = (qt_tablet_motion_data *) arg; |
|
4546 |
if (data->error) |
|
4547 |
return false; |
|
4548 |
||
4549 |
if (event->type == MotionNotify) |
|
4550 |
return true; |
|
4551 |
||
4552 |
data->error = event->type != data->tabletMotionType; // we stop compression when another event gets in between. |
|
4553 |
return false; |
|
4554 |
} |
|
4555 |
||
4556 |
static Bool qt_tabletMotion_scanner(Display *, XEvent *event, XPointer arg) |
|
4557 |
{ |
|
4558 |
qt_tablet_motion_data *data = (qt_tablet_motion_data *) arg; |
|
4559 |
if (data->error) |
|
4560 |
return false; |
|
4561 |
if (event->type == data->tabletMotionType) { |
|
4562 |
const XDeviceMotionEvent *const motion = reinterpret_cast<const XDeviceMotionEvent*>(event); |
|
4563 |
if (data->filterByWidget) { |
|
4564 |
const QPoint curr(motion->x, motion->y); |
|
4565 |
const QWidget *w = data->etWidget; |
|
4566 |
const QWidget *const child = w->childAt(curr); |
|
4567 |
if (child) { |
|
4568 |
w = child; |
|
4569 |
} |
|
4570 |
if (w == data->widget) |
|
4571 |
return true; |
|
4572 |
} else { |
|
4573 |
return true; |
|
4574 |
} |
|
4575 |
} |
|
4576 |
||
4577 |
data->error = event->type != MotionNotify; // we stop compression when another event gets in between. |
|
4578 |
return false; |
|
4579 |
} |
|
4580 |
||
4581 |
bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet) |
|
4582 |
{ |
|
4583 |
#if defined (Q_OS_IRIX) |
|
4584 |
// Wacom has put defines in their wacom.h file so it would be quite wise |
|
4585 |
// to use them, need to think of a decent way of not using |
|
4586 |
// it when it doesn't exist... |
|
4587 |
XDeviceState *s; |
|
4588 |
XInputClass *iClass; |
|
4589 |
XValuatorState *vs; |
|
4590 |
int j; |
|
4591 |
#endif |
|
4592 |
||
4593 |
Q_ASSERT(tablet != 0); |
|
4594 |
||
4595 |
QWidget *w = this; |
|
4596 |
QPoint global, |
|
4597 |
curr; |
|
4598 |
QPointF hiRes; |
|
4599 |
qreal pressure = 0; |
|
4600 |
int xTilt = 0, |
|
4601 |
yTilt = 0, |
|
4602 |
z = 0; |
|
4603 |
qreal tangentialPressure = 0; |
|
4604 |
qreal rotation = 0; |
|
4605 |
int deviceType = QTabletEvent::NoDevice; |
|
4606 |
int pointerType = QTabletEvent::UnknownPointer; |
|
4607 |
const XDeviceMotionEvent *motion = 0; |
|
4608 |
XDeviceButtonEvent *button = 0; |
|
4609 |
const XProximityNotifyEvent *proximity = 0; |
|
4610 |
QEvent::Type t; |
|
4611 |
Qt::KeyboardModifiers modifiers = 0; |
|
4612 |
#if !defined (Q_OS_IRIX) |
|
4613 |
XID device_id; |
|
4614 |
#endif |
|
4615 |
||
4616 |
if (ev->type == tablet->xinput_motion) { |
|
4617 |
motion = reinterpret_cast<const XDeviceMotionEvent*>(ev); |
|
4618 |
t = QEvent::TabletMove; |
|
4619 |
global = QPoint(motion->x_root, motion->y_root); |
|
4620 |
curr = QPoint(motion->x, motion->y); |
|
4621 |
#if !defined (Q_OS_IRIX) |
|
4622 |
device_id = motion->deviceid; |
|
4623 |
#endif |
|
4624 |
} else if (ev->type == tablet->xinput_button_press || ev->type == tablet->xinput_button_release) { |
|
4625 |
if (ev->type == tablet->xinput_button_press) { |
|
4626 |
t = QEvent::TabletPress; |
|
4627 |
} else { |
|
4628 |
t = QEvent::TabletRelease; |
|
4629 |
} |
|
4630 |
button = (XDeviceButtonEvent*)ev; |
|
4631 |
||
4632 |
global = QPoint(button->x_root, button->y_root); |
|
4633 |
curr = QPoint(button->x, button->y); |
|
4634 |
#if !defined (Q_OS_IRIX) |
|
4635 |
device_id = button->deviceid; |
|
4636 |
#endif |
|
4637 |
} else { // Proximity |
|
4638 |
if (ev->type == tablet->xinput_proximity_in) |
|
4639 |
t = QEvent::TabletEnterProximity; |
|
4640 |
else |
|
4641 |
t = QEvent::TabletLeaveProximity; |
|
4642 |
proximity = (const XProximityNotifyEvent*)ev; |
|
4643 |
#if !defined (Q_OS_IRIX) |
|
4644 |
device_id = proximity->deviceid; |
|
4645 |
#endif |
|
4646 |
} |
|
4647 |
||
4648 |
qint64 uid = 0; |
|
4649 |
#if defined (Q_OS_IRIX) |
|
4650 |
QRect screenArea = qApp->desktop()->screenGeometry(this); |
|
4651 |
s = XQueryDeviceState(X11->display, static_cast<XDevice *>(tablet->device)); |
|
4652 |
if (!s) |
|
4653 |
return false; |
|
4654 |
iClass = s->data; |
|
4655 |
for (j = 0; j < s->num_classes; j++) { |
|
4656 |
if (iClass->c_class == ValuatorClass) { |
|
4657 |
vs = reinterpret_cast<XValuatorState *>(iClass); |
|
4658 |
// figure out what device we have, based on bitmasking... |
|
4659 |
if (vs->valuators[WAC_TRANSDUCER_I] |
|
4660 |
& WAC_TRANSDUCER_PROX_MSK) { |
|
4661 |
switch (vs->valuators[WAC_TRANSDUCER_I] |
|
4662 |
& WAC_TRANSDUCER_MSK) { |
|
4663 |
case WAC_PUCK_ID: |
|
4664 |
pointerType = QTabletEvent::Puck; |
|
4665 |
break; |
|
4666 |
case WAC_STYLUS_ID: |
|
4667 |
pointerType = QTabletEvent::Pen; |
|
4668 |
break; |
|
4669 |
case WAC_ERASER_ID: |
|
4670 |
pointerType = QTabletEvent::Eraser; |
|
4671 |
break; |
|
4672 |
} |
|
4673 |
// Get a Unique Id for the device, Wacom gives us this ability |
|
4674 |
uid = vs->valuators[WAC_TRANSDUCER_I] & WAC_TRANSDUCER_ID_MSK; |
|
4675 |
uid = (uid << 24) | vs->valuators[WAC_SERIAL_NUM_I]; |
|
4676 |
switch (WAC_TRANSDUCER_I & 0x0F0600) { |
|
4677 |
case 0x080200: |
|
4678 |
deviceType = QTabletEvent::Stylus; |
|
4679 |
break; |
|
4680 |
case 0x090200: |
|
4681 |
deviceType = QTabletEvent::Airbrush; |
|
4682 |
break; |
|
4683 |
case 0x000400: |
|
4684 |
deviceType = QTabletEvent::FourDMouse; |
|
4685 |
break; |
|
4686 |
case 0x000600: |
|
4687 |
deviceType = QTabletEvent::Puck; |
|
4688 |
break; |
|
4689 |
case 0x080400: |
|
4690 |
deviceType = QTabletEvent::RotationStylus; |
|
4691 |
break; |
|
4692 |
} |
|
4693 |
} else { |
|
4694 |
pointerType = QTabletEvent::UnknownPointer; |
|
4695 |
deviceType = QTabletEvent::NoDevice; |
|
4696 |
uid = 0; |
|
4697 |
} |
|
4698 |
||
4699 |
if (!proximity) { |
|
4700 |
// apparently Wacom needs a cast for the +/- values to make sense |
|
4701 |
xTilt = short(vs->valuators[WAC_XTILT_I]); |
|
4702 |
yTilt = short(vs->valuators[WAC_YTILT_I]); |
|
4703 |
pressure = vs->valuators[WAC_PRESSURE_I]; |
|
4704 |
if (deviceType == QTabletEvent::FourDMouse |
|
4705 |
|| deviceType == QTabletEvent::RotationStylus) { |
|
4706 |
rotation = vs->valuators[WAC_ROTATION_I] / 64.0; |
|
4707 |
if (deviceType == QTabletEvent::FourDMouse) |
|
4708 |
z = vs->valuators[WAC_ZCOORD_I]; |
|
4709 |
} else if (deviceType == QTabletEvent::Airbrush) { |
|
4710 |
tangentialPressure = vs->valuators[WAC_TAN_PRESSURE_I] |
|
4711 |
/ qreal(tablet->maxTanPressure - tablet->minTanPressure); |
|
4712 |
} |
|
4713 |
||
4714 |
hiRes = tablet->scaleCoord(vs->valuators[WAC_XCOORD_I], vs->valuators[WAC_YCOORD_I], |
|
4715 |
screenArea.x(), screenArea.width(), |
|
4716 |
screenArea.y(), screenArea.height()); |
|
4717 |
} |
|
4718 |
break; |
|
4719 |
} |
|
4720 |
iClass = reinterpret_cast<XInputClass*>(reinterpret_cast<char*>(iClass) + iClass->length); |
|
4721 |
} |
|
4722 |
XFreeDeviceState(s); |
|
4723 |
#else |
|
4724 |
QTabletDeviceDataList *tablet_list = qt_tablet_devices(); |
|
4725 |
for (int i = 0; i < tablet_list->size(); ++i) { |
|
4726 |
const QTabletDeviceData &t = tablet_list->at(i); |
|
4727 |
if (device_id == static_cast<XDevice *>(t.device)->device_id) { |
|
4728 |
deviceType = t.deviceType; |
|
4729 |
if (t.deviceType == QTabletEvent::XFreeEraser) { |
|
4730 |
deviceType = QTabletEvent::Stylus; |
|
4731 |
pointerType = QTabletEvent::Eraser; |
|
4732 |
} else if (t.deviceType == QTabletEvent::Stylus) { |
|
4733 |
pointerType = QTabletEvent::Pen; |
|
4734 |
} |
|
4735 |
break; |
|
4736 |
} |
|
4737 |
} |
|
4738 |
||
4739 |
fetchWacomToolId(deviceType, uid); |
|
4740 |
||
4741 |
QRect screenArea = qApp->desktop()->rect(); |
|
4742 |
if (motion) { |
|
4743 |
xTilt = (short) motion->axis_data[3]; |
|
4744 |
yTilt = (short) motion->axis_data[4]; |
|
4745 |
rotation = ((short) motion->axis_data[5]) / 64.0; |
|
4746 |
pressure = (short) motion->axis_data[2]; |
|
4747 |
modifiers = X11->translateModifiers(motion->state); |
|
4748 |
hiRes = tablet->scaleCoord(motion->axis_data[0], motion->axis_data[1], |
|
4749 |
screenArea.x(), screenArea.width(), |
|
4750 |
screenArea.y(), screenArea.height()); |
|
4751 |
} else if (button) { |
|
4752 |
xTilt = (short) button->axis_data[3]; |
|
4753 |
yTilt = (short) button->axis_data[4]; |
|
4754 |
rotation = ((short) button->axis_data[5]) / 64.0; |
|
4755 |
pressure = (short) button->axis_data[2]; |
|
4756 |
modifiers = X11->translateModifiers(button->state); |
|
4757 |
hiRes = tablet->scaleCoord(button->axis_data[0], button->axis_data[1], |
|
4758 |
screenArea.x(), screenArea.width(), |
|
4759 |
screenArea.y(), screenArea.height()); |
|
4760 |
} else if (proximity) { |
|
4761 |
pressure = 0; |
|
4762 |
modifiers = 0; |
|
4763 |
} |
|
4764 |
if (deviceType == QTabletEvent::Airbrush) { |
|
4765 |
tangentialPressure = rotation; |
|
4766 |
rotation = 0.; |
|
4767 |
} |
|
4768 |
#endif |
|
4769 |
||
4770 |
if (tablet->widgetToGetPress) { |
|
4771 |
w = tablet->widgetToGetPress; |
|
4772 |
} else { |
|
4773 |
QWidget *child = w->childAt(curr); |
|
4774 |
if (child) |
|
4775 |
w = child; |
|
4776 |
} |
|
4777 |
curr = w->mapFromGlobal(global); |
|
4778 |
||
4779 |
if (t == QEvent::TabletPress) { |
|
4780 |
tablet->widgetToGetPress = w; |
|
4781 |
} else if (t == QEvent::TabletRelease && tablet->widgetToGetPress) { |
|
4782 |
w = tablet->widgetToGetPress; |
|
4783 |
curr = w->mapFromGlobal(global); |
|
4784 |
tablet->widgetToGetPress = 0; |
|
4785 |
} |
|
4786 |
||
4787 |
QTabletEvent e(t, curr, global, hiRes, |
|
4788 |
deviceType, pointerType, |
|
4789 |
qreal(pressure / qreal(tablet->maxPressure - tablet->minPressure)), |
|
4790 |
xTilt, yTilt, tangentialPressure, rotation, z, modifiers, uid); |
|
4791 |
if (proximity) { |
|
4792 |
QApplication::sendSpontaneousEvent(qApp, &e); |
|
4793 |
} else { |
|
4794 |
QApplication::sendSpontaneousEvent(w, &e); |
|
4795 |
const bool accepted = e.isAccepted(); |
|
4796 |
if (!accepted && ev->type == tablet->xinput_motion) { |
|
4797 |
// If the widget does not accept tablet events, we drop the next ones from the event queue |
|
4798 |
// for this widget so it is not overloaded with the numerous tablet events. |
|
4799 |
qt_tablet_motion_data tabletMotionData; |
|
4800 |
tabletMotionData.tabletMotionType = tablet->xinput_motion; |
|
4801 |
tabletMotionData.widget = w; |
|
4802 |
tabletMotionData.etWidget = this; |
|
4803 |
// if nothing is pressed, the events are filtered by position |
|
4804 |
tabletMotionData.filterByWidget = (tablet->widgetToGetPress == 0); |
|
4805 |
||
4806 |
bool reinsertMouseEvent = false; |
|
4807 |
XEvent mouseMotionEvent; |
|
4808 |
while (true) { |
|
4809 |
// Find first mouse event since we expect them in pairs inside Qt |
|
4810 |
tabletMotionData.error =false; |
|
4811 |
if (XCheckIfEvent(X11->display, &mouseMotionEvent, &qt_mouseMotion_scanner, (XPointer) &tabletMotionData)) { |
|
4812 |
reinsertMouseEvent = true; |
|
4813 |
} else { |
|
4814 |
break; |
|
4815 |
} |
|
4816 |
||
4817 |
// Now discard any duplicate tablet events. |
|
4818 |
tabletMotionData.error = false; |
|
4819 |
XEvent dummy; |
|
4820 |
while (XCheckIfEvent(X11->display, &dummy, &qt_tabletMotion_scanner, (XPointer) &tabletMotionData)) { |
|
4821 |
// just discard the event |
|
4822 |
} |
|
4823 |
} |
|
4824 |
||
4825 |
if (reinsertMouseEvent) { |
|
4826 |
XPutBackEvent(X11->display, &mouseMotionEvent); |
|
4827 |
} |
|
4828 |
} |
|
4829 |
} |
|
4830 |
return true; |
|
4831 |
} |
|
4832 |
#endif |
|
4833 |
||
4834 |
bool QETWidget::translatePropertyEvent(const XEvent *event) |
|
4835 |
{ |
|
4836 |
Q_D(QWidget); |
|
4837 |
if (!isWindow()) return true; |
|
4838 |
||
4839 |
Atom ret; |
|
4840 |
int format, e; |
|
4841 |
unsigned char *data = 0; |
|
4842 |
unsigned long nitems, after; |
|
4843 |
||
4844 |
if (event->xproperty.atom == ATOM(_KDE_NET_WM_FRAME_STRUT)) { |
|
4845 |
this->data->fstrut_dirty = 1; |
|
4846 |
||
4847 |
if (event->xproperty.state == PropertyNewValue) { |
|
4848 |
e = XGetWindowProperty(X11->display, event->xproperty.window, ATOM(_KDE_NET_WM_FRAME_STRUT), |
|
4849 |
0, 4, // struts are 4 longs |
|
4850 |
False, XA_CARDINAL, &ret, &format, &nitems, &after, &data); |
|
4851 |
||
4852 |
if (e == Success && ret == XA_CARDINAL && |
|
4853 |
format == 32 && nitems == 4) { |
|
4854 |
long *strut = (long *) data; |
|
4855 |
d->topData()->frameStrut.setCoords(strut[0], strut[2], strut[1], strut[3]); |
|
4856 |
this->data->fstrut_dirty = 0; |
|
4857 |
} |
|
4858 |
} |
|
4859 |
} else if (event->xproperty.atom == ATOM(_NET_WM_STATE)) { |
|
4860 |
bool max = false; |
|
4861 |
bool full = false; |
|
4862 |
Qt::WindowStates oldState = Qt::WindowStates(this->data->window_state); |
|
4863 |
||
4864 |
if (event->xproperty.state == PropertyNewValue) { |
|
4865 |
// using length of 1024 should be safe for all current and |
|
4866 |
// possible NET states... |
|
4867 |
e = XGetWindowProperty(X11->display, event->xproperty.window, ATOM(_NET_WM_STATE), 0, 1024, |
|
4868 |
False, XA_ATOM, &ret, &format, &nitems, &after, &data); |
|
4869 |
||
4870 |
if (e == Success && ret == XA_ATOM && format == 32 && nitems > 0) { |
|
4871 |
Atom *states = (Atom *) data; |
|
4872 |
||
4873 |
unsigned long i; |
|
4874 |
uint maximized = 0; |
|
4875 |
for (i = 0; i < nitems; i++) { |
|
4876 |
if (states[i] == ATOM(_NET_WM_STATE_MAXIMIZED_VERT)) |
|
4877 |
maximized |= 1; |
|
4878 |
else if (states[i] == ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)) |
|
4879 |
maximized |= 2; |
|
4880 |
else if (states[i] == ATOM(_NET_WM_STATE_FULLSCREEN)) |
|
4881 |
full = true; |
|
4882 |
} |
|
4883 |
if (maximized == 3) { |
|
4884 |
// only set maximized if both horizontal and vertical properties are set |
|
4885 |
max = true; |
|
4886 |
} |
|
4887 |
} |
|
4888 |
} |
|
4889 |
||
4890 |
bool send_event = false; |
|
4891 |
||
4892 |
if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)) |
|
4893 |
&& X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))) { |
|
4894 |
if (max && !isMaximized()) { |
|
4895 |
this->data->window_state = this->data->window_state | Qt::WindowMaximized; |
|
4896 |
send_event = true; |
|
4897 |
} else if (!max && isMaximized()) { |
|
4898 |
this->data->window_state &= ~Qt::WindowMaximized; |
|
4899 |
send_event = true; |
|
4900 |
} |
|
4901 |
} |
|
4902 |
||
4903 |
if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) { |
|
4904 |
if (full && !isFullScreen()) { |
|
4905 |
this->data->window_state = this->data->window_state | Qt::WindowFullScreen; |
|
4906 |
send_event = true; |
|
4907 |
} else if (!full && isFullScreen()) { |
|
4908 |
this->data->window_state &= ~Qt::WindowFullScreen; |
|
4909 |
send_event = true; |
|
4910 |
} |
|
4911 |
} |
|
4912 |
||
4913 |
if (send_event) { |
|
4914 |
QWindowStateChangeEvent e(oldState); |
|
4915 |
QApplication::sendSpontaneousEvent(this, &e); |
|
4916 |
} |
|
4917 |
} else if (event->xproperty.atom == ATOM(WM_STATE)) { |
|
4918 |
// the widget frame strut should also be invalidated |
|
4919 |
this->data->fstrut_dirty = 1; |
|
4920 |
||
4921 |
if (event->xproperty.state == PropertyDelete) { |
|
4922 |
// the window manager has removed the WM State property, |
|
4923 |
// so it is now in the withdrawn state (ICCCM 4.1.3.1) and |
|
4924 |
// we are free to reuse this window |
|
4925 |
d->topData()->parentWinId = 0; |
|
4926 |
d->topData()->validWMState = 0; |
|
4927 |
// map the window if we were waiting for a transition to |
|
4928 |
// withdrawn |
|
4929 |
if (X11->deferred_map.removeAll(this)) { |
|
4930 |
doDeferredMap(); |
|
4931 |
} else if (isVisible() |
|
4932 |
&& !testAttribute(Qt::WA_Mapped) |
|
4933 |
&& !testAttribute(Qt::WA_OutsideWSRange)) { |
|
4934 |
// so that show() will work again. As stated in the |
|
4935 |
// ICCCM section 4.1.4: "Only the client can effect a |
|
4936 |
// transition into or out of the Withdrawn state.", |
|
4937 |
// but apparently this particular window manager |
|
4938 |
// doesn't seem to care |
|
4939 |
setAttribute(Qt::WA_WState_ExplicitShowHide, false); |
|
4940 |
setAttribute(Qt::WA_WState_Visible, false); |
|
4941 |
} |
|
4942 |
} else { |
|
4943 |
// the window manager has changed the WM State property... |
|
4944 |
// we are wanting to see if we are withdrawn so that we |
|
4945 |
// can reuse this window... |
|
4946 |
e = XGetWindowProperty(X11->display, internalWinId(), ATOM(WM_STATE), 0, 2, False, |
|
4947 |
ATOM(WM_STATE), &ret, &format, &nitems, &after, &data); |
|
4948 |
||
4949 |
if (e == Success && ret == ATOM(WM_STATE) && format == 32 && nitems > 0) { |
|
4950 |
long *state = (long *) data; |
|
4951 |
switch (state[0]) { |
|
4952 |
case WithdrawnState: |
|
4953 |
// if we are in the withdrawn state, we are free |
|
4954 |
// to reuse this window provided we remove the |
|
4955 |
// WM_STATE property (ICCCM 4.1.3.1) |
|
4956 |
XDeleteProperty(X11->display, internalWinId(), ATOM(WM_STATE)); |
|
4957 |
||
4958 |
// set the parent id to zero, so that show() will |
|
4959 |
// work again |
|
4960 |
d->topData()->parentWinId = 0; |
|
4961 |
d->topData()->validWMState = 0; |
|
4962 |
// map the window if we were waiting for a |
|
4963 |
// transition to withdrawn |
|
4964 |
if (X11->deferred_map.removeAll(this)) { |
|
4965 |
doDeferredMap(); |
|
4966 |
} else if (isVisible() |
|
4967 |
&& !testAttribute(Qt::WA_Mapped) |
|
4968 |
&& !testAttribute(Qt::WA_OutsideWSRange)) { |
|
4969 |
// so that show() will work again. As stated |
|
4970 |
// in the ICCCM section 4.1.4: "Only the |
|
4971 |
// client can effect a transition into or out |
|
4972 |
// of the Withdrawn state.", but apparently |
|
4973 |
// this particular window manager doesn't seem |
|
4974 |
// to care |
|
4975 |
setAttribute(Qt::WA_WState_ExplicitShowHide, false); |
|
4976 |
setAttribute(Qt::WA_WState_Visible, false); |
|
4977 |
} |
|
4978 |
break; |
|
4979 |
||
4980 |
case IconicState: |
|
4981 |
d->topData()->validWMState = 1; |
|
4982 |
if (!isMinimized()) { |
|
4983 |
// window was minimized |
|
4984 |
this->data->window_state = this->data->window_state | Qt::WindowMinimized; |
|
4985 |
QWindowStateChangeEvent e(Qt::WindowStates(this->data->window_state & ~Qt::WindowMinimized)); |
|
4986 |
QApplication::sendSpontaneousEvent(this, &e); |
|
4987 |
} |
|
4988 |
break; |
|
4989 |
||
4990 |
default: |
|
4991 |
d->topData()->validWMState = 1; |
|
4992 |
if (isMinimized()) { |
|
4993 |
// window was un-minimized |
|
4994 |
this->data->window_state &= ~Qt::WindowMinimized; |
|
4995 |
QWindowStateChangeEvent e(Qt::WindowStates(this->data->window_state | Qt::WindowMinimized)); |
|
4996 |
QApplication::sendSpontaneousEvent(this, &e); |
|
4997 |
} |
|
4998 |
break; |
|
4999 |
} |
|
5000 |
} |
|
5001 |
} |
|
5002 |
} else if (event->xproperty.atom == ATOM(_NET_WM_WINDOW_OPACITY)) { |
|
5003 |
// the window opacity was changed |
|
5004 |
if (event->xproperty.state == PropertyNewValue) { |
|
5005 |
e = XGetWindowProperty(event->xclient.display, |
|
5006 |
event->xclient.window, |
|
5007 |
ATOM(_NET_WM_WINDOW_OPACITY), |
|
5008 |
0, 1, False, XA_CARDINAL, |
|
5009 |
&ret, &format, &nitems, &after, &data); |
|
5010 |
||
5011 |
if (e == Success && ret == XA_CARDINAL && format == 32 && nitems == 1 |
|
5012 |
&& after == 0 && data) { |
|
5013 |
ulong value = *(ulong*)(data); |
|
5014 |
d->topData()->opacity = uint(value >> 24); |
|
5015 |
} |
|
5016 |
} else |
|
5017 |
d->topData()->opacity = 255; |
|
5018 |
} |
|
5019 |
||
5020 |
if (data) |
|
5021 |
XFree(data); |
|
5022 |
||
5023 |
return true; |
|
5024 |
} |
|
5025 |
||
5026 |
||
5027 |
// |
|
5028 |
// Paint event translation |
|
5029 |
// |
|
5030 |
// When receiving many expose events, we compress them (union of all expose |
|
5031 |
// rectangles) into one event which is sent to the widget. |
|
5032 |
||
5033 |
struct PaintEventInfo { |
|
5034 |
Window window; |
|
5035 |
}; |
|
5036 |
||
5037 |
#if defined(Q_C_CALLBACKS) |
|
5038 |
extern "C" { |
|
5039 |
#endif |
|
5040 |
||
5041 |
static Bool isPaintOrScrollDoneEvent(Display *, XEvent *ev, XPointer a) |
|
5042 |
{ |
|
5043 |
PaintEventInfo *info = (PaintEventInfo *)a; |
|
5044 |
if (ev->type == Expose || ev->type == GraphicsExpose |
|
5045 |
|| (ev->type == ClientMessage && ev->xclient.message_type == ATOM(_QT_SCROLL_DONE))) |
|
5046 |
{ |
|
5047 |
if (ev->xexpose.window == info->window) |
|
5048 |
return True; |
|
5049 |
} |
|
5050 |
return False; |
|
5051 |
} |
|
5052 |
||
5053 |
#if defined(Q_C_CALLBACKS) |
|
5054 |
} |
|
5055 |
#endif |
|
5056 |
||
5057 |
||
5058 |
||
5059 |
static |
|
5060 |
bool translateBySips(QWidget* that, QRect& paintRect) |
|
5061 |
{ |
|
5062 |
int dx=0, dy=0; |
|
5063 |
int sips=0; |
|
5064 |
for (int i = 0; i < X11->sip_list.size(); ++i) { |
|
5065 |
const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i); |
|
5066 |
if (sip.scrolled_widget == that) { |
|
5067 |
if (sips) { |
|
5068 |
dx += sip.dx; |
|
5069 |
dy += sip.dy; |
|
5070 |
} |
|
5071 |
sips++; |
|
5072 |
} |
|
5073 |
} |
|
5074 |
if (sips > 1) { |
|
5075 |
paintRect.translate(dx, dy); |
|
5076 |
return true; |
|
5077 |
} |
|
5078 |
return false; |
|
5079 |
} |
|
5080 |
||
5081 |
void QETWidget::translatePaintEvent(const XEvent *event) |
|
5082 |
{ |
|
5083 |
if (!isWindow() && testAttribute(Qt::WA_NativeWindow)) |
|
5084 |
Q_ASSERT(internalWinId()); |
|
5085 |
||
5086 |
Q_D(QWidget); |
|
5087 |
QRect paintRect(event->xexpose.x, event->xexpose.y, |
|
5088 |
event->xexpose.width, event->xexpose.height); |
|
5089 |
XEvent xevent; |
|
5090 |
PaintEventInfo info; |
|
5091 |
info.window = internalWinId(); |
|
5092 |
translateBySips(this, paintRect); |
|
5093 |
paintRect = d->mapFromWS(paintRect); |
|
5094 |
||
5095 |
QRegion paintRegion = paintRect; |
|
5096 |
||
5097 |
// WARNING: this is O(number_of_events * number_of_matching_events) |
|
5098 |
while (XCheckIfEvent(X11->display,&xevent,isPaintOrScrollDoneEvent, |
|
5099 |
(XPointer)&info) && |
|
5100 |
!qt_x11EventFilter(&xevent) && |
|
5101 |
!x11Event(&xevent)) // send event through filter |
|
5102 |
{ |
|
5103 |
if (xevent.type == Expose || xevent.type == GraphicsExpose) { |
|
5104 |
QRect exposure(xevent.xexpose.x, |
|
5105 |
xevent.xexpose.y, |
|
5106 |
xevent.xexpose.width, |
|
5107 |
xevent.xexpose.height); |
|
5108 |
translateBySips(this, exposure); |
|
5109 |
exposure = d->mapFromWS(exposure); |
|
5110 |
paintRegion |= exposure; |
|
5111 |
} else { |
|
5112 |
translateScrollDoneEvent(&xevent); |
|
5113 |
} |
|
5114 |
} |
|
5115 |
||
5116 |
if (!paintRegion.isEmpty() && !testAttribute(Qt::WA_WState_ConfigPending)) |
|
5117 |
d->syncBackingStore(paintRegion); |
|
5118 |
} |
|
5119 |
||
5120 |
// |
|
5121 |
// Scroll-done event translation. |
|
5122 |
// |
|
5123 |
||
5124 |
bool QETWidget::translateScrollDoneEvent(const XEvent *event) |
|
5125 |
{ |
|
5126 |
long id = event->xclient.data.l[0]; |
|
5127 |
||
5128 |
// Remove any scroll-in-progress record for the given id. |
|
5129 |
for (int i = 0; i < X11->sip_list.size(); ++i) { |
|
5130 |
const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i); |
|
5131 |
if (sip.id == id) { |
|
5132 |
X11->sip_list.removeAt(i); |
|
5133 |
return true; |
|
5134 |
} |
|
5135 |
} |
|
5136 |
||
5137 |
return false; |
|
5138 |
} |
|
5139 |
||
5140 |
// |
|
5141 |
// ConfigureNotify (window move and resize) event translation |
|
5142 |
||
5143 |
bool QETWidget::translateConfigEvent(const XEvent *event) |
|
5144 |
{ |
|
5145 |
Q_ASSERT((!isWindow() && !testAttribute(Qt::WA_NativeWindow)) ? internalWinId() : true); |
|
5146 |
||
5147 |
Q_D(QWidget); |
|
5148 |
bool wasResize = testAttribute(Qt::WA_WState_ConfigPending); // set in QWidget::setGeometry_sys() |
|
5149 |
setAttribute(Qt::WA_WState_ConfigPending, false); |
|
5150 |
||
5151 |
if (testAttribute(Qt::WA_OutsideWSRange)) { |
|
5152 |
// discard events for windows that have a geometry X can't handle |
|
5153 |
XEvent xevent; |
|
5154 |
while (XCheckTypedWindowEvent(X11->display,internalWinId(), ConfigureNotify,&xevent) && |
|
5155 |
!qt_x11EventFilter(&xevent) && |
|
5156 |
!x11Event(&xevent)) // send event through filter |
|
5157 |
; |
|
5158 |
return true; |
|
5159 |
} |
|
5160 |
||
5161 |
const QSize oldSize = size(); |
|
5162 |
||
5163 |
if (isWindow()) { |
|
5164 |
QPoint newCPos(geometry().topLeft()); |
|
5165 |
QSize newSize(event->xconfigure.width, event->xconfigure.height); |
|
5166 |
||
5167 |
bool trust = isVisible() |
|
5168 |
&& (d->topData()->parentWinId == XNone || |
|
5169 |
d->topData()->parentWinId == QX11Info::appRootWindow()); |
|
5170 |
||
5171 |
if (event->xconfigure.send_event || trust) { |
|
5172 |
// if a ConfigureNotify comes from a real sendevent request, we can |
|
5173 |
// trust its values. |
|
5174 |
newCPos.rx() = event->xconfigure.x + event->xconfigure.border_width; |
|
5175 |
newCPos.ry() = event->xconfigure.y + event->xconfigure.border_width; |
|
5176 |
} |
|
5177 |
||
5178 |
if (isVisible()) |
|
5179 |
QApplication::syncX(); |
|
5180 |
||
5181 |
if (d->extra->compress_events) { |
|
5182 |
// ConfigureNotify compression for faster opaque resizing |
|
5183 |
XEvent otherEvent; |
|
5184 |
while (XCheckTypedWindowEvent(X11->display, internalWinId(), ConfigureNotify, |
|
5185 |
&otherEvent)) { |
|
5186 |
if (qt_x11EventFilter(&otherEvent)) |
|
5187 |
continue; |
|
5188 |
||
5189 |
if (x11Event(&otherEvent)) |
|
5190 |
continue; |
|
5191 |
||
5192 |
if (otherEvent.xconfigure.event != otherEvent.xconfigure.window) |
|
5193 |
continue; |
|
5194 |
||
5195 |
newSize.setWidth(otherEvent.xconfigure.width); |
|
5196 |
newSize.setHeight(otherEvent.xconfigure.height); |
|
5197 |
||
5198 |
if (otherEvent.xconfigure.send_event || trust) { |
|
5199 |
newCPos.rx() = otherEvent.xconfigure.x + |
|
5200 |
otherEvent.xconfigure.border_width; |
|
5201 |
newCPos.ry() = otherEvent.xconfigure.y + |
|
5202 |
otherEvent.xconfigure.border_width; |
|
5203 |
} |
|
5204 |
} |
|
5205 |
#ifndef QT_NO_XSYNC |
|
5206 |
qt_sync_request_event_data sync_event; |
|
5207 |
sync_event.window = internalWinId(); |
|
5208 |
for (XEvent ev;;) { |
|
5209 |
if (!XCheckIfEvent(X11->display, &ev, &qt_sync_request_scanner, (XPointer)&sync_event)) |
|
5210 |
break; |
|
5211 |
} |
|
5212 |
#endif // QT_NO_XSYNC |
|
5213 |
} |
|
5214 |
||
5215 |
QRect cr (geometry()); |
|
5216 |
if (newCPos != cr.topLeft()) { // compare with cpos (exluding frame) |
|
5217 |
QPoint oldPos = geometry().topLeft(); |
|
5218 |
cr.moveTopLeft(newCPos); |
|
5219 |
data->crect = cr; |
|
5220 |
if (isVisible()) { |
|
5221 |
QMoveEvent e(newCPos, oldPos); // pos (including frame), not cpos |
|
5222 |
QApplication::sendSpontaneousEvent(this, &e); |
|
5223 |
} else { |
|
5224 |
setAttribute(Qt::WA_PendingMoveEvent, true); |
|
5225 |
} |
|
5226 |
} |
|
5227 |
if (newSize != cr.size()) { // size changed |
|
5228 |
cr.setSize(newSize); |
|
5229 |
data->crect = cr; |
|
5230 |
||
5231 |
uint old_state = data->window_state; |
|
5232 |
if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)) |
|
5233 |
&& !X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))) |
|
5234 |
data->window_state &= ~Qt::WindowMaximized; |
|
5235 |
if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) |
|
5236 |
data->window_state &= ~Qt::WindowFullScreen; |
|
5237 |
||
5238 |
if (old_state != data->window_state) { |
|
5239 |
QWindowStateChangeEvent e((Qt::WindowStates) old_state); |
|
5240 |
QApplication::sendEvent(this, &e); |
|
5241 |
} |
|
5242 |
||
5243 |
if (!isVisible()) |
|
5244 |
setAttribute(Qt::WA_PendingResizeEvent, true); |
|
5245 |
wasResize = true; |
|
5246 |
} |
|
5247 |
||
5248 |
} else { |
|
5249 |
XEvent xevent; |
|
5250 |
while (XCheckTypedWindowEvent(X11->display,internalWinId(), ConfigureNotify,&xevent) && |
|
5251 |
!qt_x11EventFilter(&xevent) && |
|
5252 |
!x11Event(&xevent)) // send event through filter |
|
5253 |
; |
|
5254 |
} |
|
5255 |
||
5256 |
if (wasResize) { |
|
5257 |
static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt(); |
|
5258 |
if (d->extra->compress_events && !slowResize && !data->in_show && isVisible()) { |
|
5259 |
QApplication::syncX(); |
|
5260 |
XEvent otherEvent; |
|
5261 |
while (XCheckTypedWindowEvent(X11->display, internalWinId(), ConfigureNotify, &otherEvent) |
|
5262 |
&& !qt_x11EventFilter(&otherEvent) && !x11Event(&otherEvent) |
|
5263 |
&& otherEvent.xconfigure.event == otherEvent.xconfigure.window) { |
|
5264 |
data->crect.setWidth(otherEvent.xconfigure.width); |
|
5265 |
data->crect.setHeight(otherEvent.xconfigure.height); |
|
5266 |
} |
|
5267 |
} |
|
5268 |
||
5269 |
if (isVisible() && data->crect.size() != oldSize) { |
|
5270 |
Q_ASSERT(d->extra->topextra); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5271 |
QWidgetBackingStore *bs = d->extra->topextra->backingStore.data(); |
0 | 5272 |
const bool hasStaticContents = bs && bs->hasStaticContents(); |
5273 |
// If we have a backing store with static contents, we have to disable the top-level |
|
5274 |
// resize optimization in order to get invalidated regions for resized widgets. |
|
5275 |
// The optimization discards all invalidateBuffer() calls since we're going to |
|
5276 |
// repaint everything anyways, but that's not the case with static contents. |
|
5277 |
if (!slowResize && !hasStaticContents) |
|
5278 |
d->extra->topextra->inTopLevelResize = true; |
|
5279 |
QResizeEvent e(data->crect.size(), oldSize); |
|
5280 |
QApplication::sendSpontaneousEvent(this, &e); |
|
5281 |
} |
|
5282 |
||
5283 |
const bool waitingForMapNotify = d->extra->topextra && d->extra->topextra->waitingForMapNotify; |
|
5284 |
if (!waitingForMapNotify) { |
|
5285 |
if (d->paintOnScreen()) { |
|
5286 |
QRegion updateRegion(rect()); |
|
5287 |
if (testAttribute(Qt::WA_StaticContents)) |
|
5288 |
updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height()); |
|
5289 |
d->syncBackingStore(updateRegion); |
|
5290 |
} else { |
|
5291 |
d->syncBackingStore(); |
|
5292 |
} |
|
5293 |
} |
|
5294 |
||
5295 |
if (d->extra && d->extra->topextra) |
|
5296 |
d->extra->topextra->inTopLevelResize = false; |
|
5297 |
} |
|
5298 |
#ifndef QT_NO_XSYNC |
|
5299 |
if (QTLWExtra *tlwExtra = d->maybeTopData()) { |
|
5300 |
if (tlwExtra->newCounterValueLo != 0 || tlwExtra->newCounterValueHi != 0) { |
|
5301 |
XSyncValue value; |
|
5302 |
XSyncIntsToValue(&value, |
|
5303 |
tlwExtra->newCounterValueLo, |
|
5304 |
tlwExtra->newCounterValueHi); |
|
5305 |
||
5306 |
XSyncSetCounter(X11->display, tlwExtra->syncUpdateCounter, value); |
|
5307 |
tlwExtra->newCounterValueHi = 0; |
|
5308 |
tlwExtra->newCounterValueLo = 0; |
|
5309 |
} |
|
5310 |
} |
|
5311 |
#endif |
|
5312 |
return true; |
|
5313 |
} |
|
5314 |
||
5315 |
// |
|
5316 |
// Close window event translation. |
|
5317 |
// |
|
5318 |
bool QETWidget::translateCloseEvent(const XEvent *) |
|
5319 |
{ |
|
5320 |
Q_D(QWidget); |
|
5321 |
return d->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); |
|
5322 |
} |
|
5323 |
||
5324 |
||
5325 |
void QApplication::setCursorFlashTime(int msecs) |
|
5326 |
{ |
|
5327 |
QApplicationPrivate::cursor_flash_time = msecs; |
|
5328 |
} |
|
5329 |
||
5330 |
int QApplication::cursorFlashTime() |
|
5331 |
{ |
|
5332 |
return QApplicationPrivate::cursor_flash_time; |
|
5333 |
} |
|
5334 |
||
5335 |
void QApplication::setDoubleClickInterval(int ms) |
|
5336 |
{ |
|
5337 |
QApplicationPrivate::mouse_double_click_time = ms; |
|
5338 |
} |
|
5339 |
||
5340 |
int QApplication::doubleClickInterval() |
|
5341 |
{ |
|
5342 |
return QApplicationPrivate::mouse_double_click_time; |
|
5343 |
} |
|
5344 |
||
5345 |
void QApplication::setKeyboardInputInterval(int ms) |
|
5346 |
{ |
|
5347 |
QApplicationPrivate::keyboard_input_time = ms; |
|
5348 |
} |
|
5349 |
||
5350 |
int QApplication::keyboardInputInterval() |
|
5351 |
{ |
|
5352 |
return QApplicationPrivate::keyboard_input_time; |
|
5353 |
} |
|
5354 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5355 |
#ifndef QT_NO_WHEELEVENT |
0 | 5356 |
void QApplication::setWheelScrollLines(int n) |
5357 |
{ |
|
5358 |
QApplicationPrivate::wheel_scroll_lines = n; |
|
5359 |
} |
|
5360 |
||
5361 |
int QApplication::wheelScrollLines() |
|
5362 |
{ |
|
5363 |
return QApplicationPrivate::wheel_scroll_lines; |
|
5364 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5365 |
#endif |
0 | 5366 |
|
5367 |
void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) |
|
5368 |
{ |
|
5369 |
switch (effect) { |
|
5370 |
case Qt::UI_AnimateMenu: |
|
5371 |
if (enable) QApplicationPrivate::fade_menu = false; |
|
5372 |
QApplicationPrivate::animate_menu = enable; |
|
5373 |
break; |
|
5374 |
case Qt::UI_FadeMenu: |
|
5375 |
if (enable) |
|
5376 |
QApplicationPrivate::animate_menu = true; |
|
5377 |
QApplicationPrivate::fade_menu = enable; |
|
5378 |
break; |
|
5379 |
case Qt::UI_AnimateCombo: |
|
5380 |
QApplicationPrivate::animate_combo = enable; |
|
5381 |
break; |
|
5382 |
case Qt::UI_AnimateTooltip: |
|
5383 |
if (enable) QApplicationPrivate::fade_tooltip = false; |
|
5384 |
QApplicationPrivate::animate_tooltip = enable; |
|
5385 |
break; |
|
5386 |
case Qt::UI_FadeTooltip: |
|
5387 |
if (enable) |
|
5388 |
QApplicationPrivate::animate_tooltip = true; |
|
5389 |
QApplicationPrivate::fade_tooltip = enable; |
|
5390 |
break; |
|
5391 |
case Qt::UI_AnimateToolBox: |
|
5392 |
QApplicationPrivate::animate_toolbox = enable; |
|
5393 |
break; |
|
5394 |
default: |
|
5395 |
QApplicationPrivate::animate_ui = enable; |
|
5396 |
break; |
|
5397 |
} |
|
5398 |
} |
|
5399 |
||
5400 |
bool QApplication::isEffectEnabled(Qt::UIEffect effect) |
|
5401 |
{ |
|
5402 |
if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui) |
|
5403 |
return false; |
|
5404 |
||
5405 |
switch(effect) { |
|
5406 |
case Qt::UI_AnimateMenu: |
|
5407 |
return QApplicationPrivate::animate_menu; |
|
5408 |
case Qt::UI_FadeMenu: |
|
5409 |
return QApplicationPrivate::fade_menu; |
|
5410 |
case Qt::UI_AnimateCombo: |
|
5411 |
return QApplicationPrivate::animate_combo; |
|
5412 |
case Qt::UI_AnimateTooltip: |
|
5413 |
return QApplicationPrivate::animate_tooltip; |
|
5414 |
case Qt::UI_FadeTooltip: |
|
5415 |
return QApplicationPrivate::fade_tooltip; |
|
5416 |
case Qt::UI_AnimateToolBox: |
|
5417 |
return QApplicationPrivate::animate_toolbox; |
|
5418 |
default: |
|
5419 |
return QApplicationPrivate::animate_ui; |
|
5420 |
} |
|
5421 |
} |
|
5422 |
||
5423 |
/***************************************************************************** |
|
5424 |
Session management support |
|
5425 |
*****************************************************************************/ |
|
5426 |
||
5427 |
#ifndef QT_NO_SESSIONMANAGER |
|
5428 |
||
5429 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
5430 |
#include <X11/SM/SMlib.h> |
|
5431 |
QT_END_INCLUDE_NAMESPACE |
|
5432 |
||
5433 |
class QSessionManagerPrivate : public QObjectPrivate |
|
5434 |
{ |
|
5435 |
public: |
|
5436 |
QSessionManagerPrivate(QSessionManager* mgr, QString& id, QString& key) |
|
5437 |
: QObjectPrivate(), sm(mgr), sessionId(id), sessionKey(key), |
|
5438 |
restartHint(QSessionManager::RestartIfRunning), eventLoop(0) {} |
|
5439 |
QSessionManager* sm; |
|
5440 |
QStringList restartCommand; |
|
5441 |
QStringList discardCommand; |
|
5442 |
QString& sessionId; |
|
5443 |
QString& sessionKey; |
|
5444 |
QSessionManager::RestartHint restartHint; |
|
5445 |
QEventLoop *eventLoop; |
|
5446 |
}; |
|
5447 |
||
5448 |
class QSmSocketReceiver : public QObject |
|
5449 |
{ |
|
5450 |
Q_OBJECT |
|
5451 |
public: |
|
5452 |
QSmSocketReceiver(int socket) |
|
5453 |
{ |
|
5454 |
QSocketNotifier* sn = new QSocketNotifier(socket, QSocketNotifier::Read, this); |
|
5455 |
connect(sn, SIGNAL(activated(int)), this, SLOT(socketActivated(int))); |
|
5456 |
} |
|
5457 |
||
5458 |
public slots: |
|
5459 |
void socketActivated(int); |
|
5460 |
}; |
|
5461 |
||
5462 |
||
5463 |
static SmcConn smcConnection = 0; |
|
5464 |
static bool sm_interactionActive; |
|
5465 |
static bool sm_smActive; |
|
5466 |
static int sm_interactStyle; |
|
5467 |
static int sm_saveType; |
|
5468 |
static bool sm_cancel; |
|
5469 |
// static bool sm_waitingForPhase2; ### never used?!? |
|
5470 |
static bool sm_waitingForInteraction; |
|
5471 |
static bool sm_isshutdown; |
|
5472 |
// static bool sm_shouldbefast; ### never used?!? |
|
5473 |
static bool sm_phase2; |
|
5474 |
static bool sm_in_phase2; |
|
5475 |
||
5476 |
static QSmSocketReceiver* sm_receiver = 0; |
|
5477 |
||
5478 |
static void resetSmState(); |
|
5479 |
static void sm_setProperty(const char* name, const char* type, |
|
5480 |
int num_vals, SmPropValue* vals); |
|
5481 |
static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData, |
|
5482 |
int saveType, Bool shutdown , int interactStyle, Bool fast); |
|
5483 |
static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) ; |
|
5484 |
static void sm_dieCallback(SmcConn smcConn, SmPointer clientData) ; |
|
5485 |
static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData); |
|
5486 |
static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer clientData); |
|
5487 |
static void sm_interactCallback(SmcConn smcConn, SmPointer clientData); |
|
5488 |
static void sm_performSaveYourself(QSessionManagerPrivate*); |
|
5489 |
||
5490 |
static void resetSmState() |
|
5491 |
{ |
|
5492 |
// sm_waitingForPhase2 = false; ### never used?!? |
|
5493 |
sm_waitingForInteraction = false; |
|
5494 |
sm_interactionActive = false; |
|
5495 |
sm_interactStyle = SmInteractStyleNone; |
|
5496 |
sm_smActive = false; |
|
5497 |
qt_sm_blockUserInput = false; |
|
5498 |
sm_isshutdown = false; |
|
5499 |
// sm_shouldbefast = false; ### never used?!? |
|
5500 |
sm_phase2 = false; |
|
5501 |
sm_in_phase2 = false; |
|
5502 |
} |
|
5503 |
||
5504 |
||
5505 |
// theoretically it's possible to set several properties at once. For |
|
5506 |
// simplicity, however, we do just one property at a time |
|
5507 |
static void sm_setProperty(const char* name, const char* type, |
|
5508 |
int num_vals, SmPropValue* vals) |
|
5509 |
{ |
|
5510 |
if (num_vals) { |
|
5511 |
SmProp prop; |
|
5512 |
prop.name = (char*)name; |
|
5513 |
prop.type = (char*)type; |
|
5514 |
prop.num_vals = num_vals; |
|
5515 |
prop.vals = vals; |
|
5516 |
||
5517 |
SmProp* props[1]; |
|
5518 |
props[0] = ∝ |
|
5519 |
SmcSetProperties(smcConnection, 1, props); |
|
5520 |
} |
|
5521 |
else { |
|
5522 |
char* names[1]; |
|
5523 |
names[0] = (char*) name; |
|
5524 |
SmcDeleteProperties(smcConnection, 1, names); |
|
5525 |
} |
|
5526 |
} |
|
5527 |
||
5528 |
static void sm_setProperty(const QString& name, const QString& value) |
|
5529 |
{ |
|
5530 |
QByteArray v = value.toUtf8(); |
|
5531 |
SmPropValue prop; |
|
5532 |
prop.length = v.length(); |
|
5533 |
prop.value = (SmPointer) v.constData(); |
|
5534 |
sm_setProperty(name.toLatin1().data(), SmARRAY8, 1, &prop); |
|
5535 |
} |
|
5536 |
||
5537 |
static void sm_setProperty(const QString& name, const QStringList& value) |
|
5538 |
{ |
|
5539 |
SmPropValue *prop = new SmPropValue[value.count()]; |
|
5540 |
int count = 0; |
|
5541 |
QList<QByteArray> vl; |
|
5542 |
for (QStringList::ConstIterator it = value.begin(); it != value.end(); ++it) { |
|
5543 |
prop[count].length = (*it).length(); |
|
5544 |
vl.append((*it).toUtf8()); |
|
5545 |
prop[count].value = (char*)vl.last().data(); |
|
5546 |
++count; |
|
5547 |
} |
|
5548 |
sm_setProperty(name.toLatin1().data(), SmLISTofARRAY8, count, prop); |
|
5549 |
delete [] prop; |
|
5550 |
} |
|
5551 |
||
5552 |
||
5553 |
// workaround for broken libsm, see below |
|
5554 |
struct QT_smcConn { |
|
5555 |
unsigned int save_yourself_in_progress : 1; |
|
5556 |
unsigned int shutdown_in_progress : 1; |
|
5557 |
}; |
|
5558 |
||
5559 |
static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData, |
|
5560 |
int saveType, Bool shutdown , int interactStyle, Bool /*fast*/) |
|
5561 |
{ |
|
5562 |
if (smcConn != smcConnection) |
|
5563 |
return; |
|
5564 |
sm_cancel = false; |
|
5565 |
sm_smActive = true; |
|
5566 |
sm_isshutdown = shutdown; |
|
5567 |
sm_saveType = saveType; |
|
5568 |
sm_interactStyle = interactStyle; |
|
5569 |
// sm_shouldbefast = fast; ### never used?!? |
|
5570 |
||
5571 |
// ugly workaround for broken libSM. libSM should do that _before_ |
|
5572 |
// actually invoking the callback in sm_process.c |
|
5573 |
((QT_smcConn*)smcConn)->save_yourself_in_progress = true; |
|
5574 |
if (sm_isshutdown) |
|
5575 |
((QT_smcConn*)smcConn)->shutdown_in_progress = true; |
|
5576 |
||
5577 |
sm_performSaveYourself((QSessionManagerPrivate*) clientData); |
|
5578 |
if (!sm_isshutdown) // we cannot expect a confirmation message in that case |
|
5579 |
resetSmState(); |
|
5580 |
} |
|
5581 |
||
5582 |
static void sm_performSaveYourself(QSessionManagerPrivate* smd) |
|
5583 |
{ |
|
5584 |
if (sm_isshutdown) |
|
5585 |
qt_sm_blockUserInput = true; |
|
5586 |
||
5587 |
QSessionManager* sm = smd->sm; |
|
5588 |
||
5589 |
// generate a new session key |
|
5590 |
timeval tv; |
|
5591 |
gettimeofday(&tv, 0); |
|
5592 |
smd->sessionKey = QString::number(qulonglong(tv.tv_sec)) + QLatin1Char('_') + QString::number(qulonglong(tv.tv_usec)); |
|
5593 |
||
5594 |
QStringList arguments = qApp->arguments(); |
|
5595 |
QString argument0 = arguments.isEmpty() ? qApp->applicationFilePath() : arguments.at(0); |
|
5596 |
||
5597 |
// tell the session manager about our program in best POSIX style |
|
5598 |
sm_setProperty(QString::fromLatin1(SmProgram), argument0); |
|
5599 |
// tell the session manager about our user as well. |
|
5600 |
struct passwd *entryPtr = 0; |
|
5601 |
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) |
|
5602 |
QVarLengthArray<char, 1024> buf(sysconf(_SC_GETPW_R_SIZE_MAX)); |
|
5603 |
struct passwd entry; |
|
5604 |
getpwuid_r(geteuid(), &entry, buf.data(), buf.size(), &entryPtr); |
|
5605 |
#else |
|
5606 |
entryPtr = getpwuid(geteuid()); |
|
5607 |
#endif |
|
5608 |
if (entryPtr) |
|
5609 |
sm_setProperty(QString::fromLatin1(SmUserID), QString::fromLatin1(entryPtr->pw_name)); |
|
5610 |
||
5611 |
// generate a restart and discard command that makes sense |
|
5612 |
QStringList restart; |
|
5613 |
restart << argument0 << QLatin1String("-session") |
|
5614 |
<< smd->sessionId + QLatin1Char('_') + smd->sessionKey; |
|
5615 |
if (qstricmp(appName, QX11Info::appClass()) != 0) |
|
5616 |
restart << QLatin1String("-name") << qAppName(); |
|
5617 |
sm->setRestartCommand(restart); |
|
5618 |
QStringList discard; |
|
5619 |
sm->setDiscardCommand(discard); |
|
5620 |
||
5621 |
switch (sm_saveType) { |
|
5622 |
case SmSaveBoth: |
|
5623 |
qApp->commitData(*sm); |
|
5624 |
if (sm_isshutdown && sm_cancel) |
|
5625 |
break; // we cancelled the shutdown, no need to save state |
|
5626 |
// fall through |
|
5627 |
case SmSaveLocal: |
|
5628 |
qApp->saveState(*sm); |
|
5629 |
break; |
|
5630 |
case SmSaveGlobal: |
|
5631 |
qApp->commitData(*sm); |
|
5632 |
break; |
|
5633 |
default: |
|
5634 |
break; |
|
5635 |
} |
|
5636 |
||
5637 |
if (sm_phase2 && !sm_in_phase2) { |
|
5638 |
SmcRequestSaveYourselfPhase2(smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd); |
|
5639 |
qt_sm_blockUserInput = false; |
|
5640 |
} |
|
5641 |
else { |
|
5642 |
// close eventual interaction monitors and cancel the |
|
5643 |
// shutdown, if required. Note that we can only cancel when |
|
5644 |
// performing a shutdown, it does not work for checkpoints |
|
5645 |
if (sm_interactionActive) { |
|
5646 |
SmcInteractDone(smcConnection, sm_isshutdown && sm_cancel); |
|
5647 |
sm_interactionActive = false; |
|
5648 |
} |
|
5649 |
else if (sm_cancel && sm_isshutdown) { |
|
5650 |
if (sm->allowsErrorInteraction()) { |
|
5651 |
SmcInteractDone(smcConnection, True); |
|
5652 |
sm_interactionActive = false; |
|
5653 |
} |
|
5654 |
} |
|
5655 |
||
5656 |
// set restart and discard command in session manager |
|
5657 |
sm_setProperty(QString::fromLatin1(SmRestartCommand), sm->restartCommand()); |
|
5658 |
sm_setProperty(QString::fromLatin1(SmDiscardCommand), sm->discardCommand()); |
|
5659 |
||
5660 |
// set the restart hint |
|
5661 |
SmPropValue prop; |
|
5662 |
prop.length = sizeof(int); |
|
5663 |
int value = sm->restartHint(); |
|
5664 |
prop.value = (SmPointer) &value; |
|
5665 |
sm_setProperty(SmRestartStyleHint, SmCARD8, 1, &prop); |
|
5666 |
||
5667 |
// we are done |
|
5668 |
SmcSaveYourselfDone(smcConnection, !sm_cancel); |
|
5669 |
} |
|
5670 |
} |
|
5671 |
||
5672 |
static void sm_dieCallback(SmcConn smcConn, SmPointer /* clientData */) |
|
5673 |
{ |
|
5674 |
if (smcConn != smcConnection) |
|
5675 |
return; |
|
5676 |
resetSmState(); |
|
5677 |
QEvent quitEvent(QEvent::Quit); |
|
5678 |
QApplication::sendEvent(qApp, &quitEvent); |
|
5679 |
} |
|
5680 |
||
5681 |
static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData) |
|
5682 |
{ |
|
5683 |
if (smcConn != smcConnection) |
|
5684 |
return; |
|
5685 |
if (sm_waitingForInteraction) |
|
5686 |
((QSessionManagerPrivate *) clientData)->eventLoop->exit(); |
|
5687 |
resetSmState(); |
|
5688 |
} |
|
5689 |
||
5690 |
static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer /*clientData */) |
|
5691 |
{ |
|
5692 |
if (smcConn != smcConnection) |
|
5693 |
return; |
|
5694 |
resetSmState(); |
|
5695 |
} |
|
5696 |
||
5697 |
static void sm_interactCallback(SmcConn smcConn, SmPointer clientData) |
|
5698 |
{ |
|
5699 |
if (smcConn != smcConnection) |
|
5700 |
return; |
|
5701 |
if (sm_waitingForInteraction) |
|
5702 |
((QSessionManagerPrivate *) clientData)->eventLoop->exit(); |
|
5703 |
} |
|
5704 |
||
5705 |
static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) |
|
5706 |
{ |
|
5707 |
if (smcConn != smcConnection) |
|
5708 |
return; |
|
5709 |
sm_in_phase2 = true; |
|
5710 |
sm_performSaveYourself((QSessionManagerPrivate*) clientData); |
|
5711 |
} |
|
5712 |
||
5713 |
||
5714 |
void QSmSocketReceiver::socketActivated(int) |
|
5715 |
{ |
|
5716 |
IceProcessMessages(SmcGetIceConnection(smcConnection), 0, 0); |
|
5717 |
} |
|
5718 |
||
5719 |
||
5720 |
#undef Bool |
|
5721 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
5722 |
#include "qapplication_x11.moc" |
|
5723 |
QT_END_INCLUDE_NAMESPACE |
|
5724 |
||
5725 |
QSessionManager::QSessionManager(QApplication * app, QString &id, QString& key) |
|
5726 |
: QObject(*new QSessionManagerPrivate(this, id, key), app) |
|
5727 |
{ |
|
5728 |
Q_D(QSessionManager); |
|
5729 |
d->restartHint = RestartIfRunning; |
|
5730 |
||
5731 |
resetSmState(); |
|
5732 |
char cerror[256]; |
|
5733 |
char* myId = 0; |
|
5734 |
QByteArray b_id = id.toLatin1(); |
|
5735 |
char* prevId = b_id.data(); |
|
5736 |
||
5737 |
SmcCallbacks cb; |
|
5738 |
cb.save_yourself.callback = sm_saveYourselfCallback; |
|
5739 |
cb.save_yourself.client_data = (SmPointer) d; |
|
5740 |
cb.die.callback = sm_dieCallback; |
|
5741 |
cb.die.client_data = (SmPointer) d; |
|
5742 |
cb.save_complete.callback = sm_saveCompleteCallback; |
|
5743 |
cb.save_complete.client_data = (SmPointer) d; |
|
5744 |
cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback; |
|
5745 |
cb.shutdown_cancelled.client_data = (SmPointer) d; |
|
5746 |
||
5747 |
// avoid showing a warning message below |
|
5748 |
if (qgetenv("SESSION_MANAGER").isEmpty()) |
|
5749 |
return; |
|
5750 |
||
5751 |
smcConnection = SmcOpenConnection(0, 0, 1, 0, |
|
5752 |
SmcSaveYourselfProcMask | |
|
5753 |
SmcDieProcMask | |
|
5754 |
SmcSaveCompleteProcMask | |
|
5755 |
SmcShutdownCancelledProcMask, |
|
5756 |
&cb, |
|
5757 |
prevId, |
|
5758 |
&myId, |
|
5759 |
256, cerror); |
|
5760 |
||
5761 |
id = QString::fromLatin1(myId); |
|
5762 |
::free(myId); // it was allocated by C |
|
5763 |
||
5764 |
QString error = QString::fromLocal8Bit(cerror); |
|
5765 |
if (!smcConnection) { |
|
5766 |
qWarning("Qt: Session management error: %s", qPrintable(error)); |
|
5767 |
} |
|
5768 |
else { |
|
5769 |
sm_receiver = new QSmSocketReceiver(IceConnectionNumber(SmcGetIceConnection(smcConnection))); |
|
5770 |
} |
|
5771 |
} |
|
5772 |
||
5773 |
QSessionManager::~QSessionManager() |
|
5774 |
{ |
|
5775 |
if (smcConnection) |
|
5776 |
SmcCloseConnection(smcConnection, 0, 0); |
|
5777 |
smcConnection = 0; |
|
5778 |
delete sm_receiver; |
|
5779 |
} |
|
5780 |
||
5781 |
QString QSessionManager::sessionId() const |
|
5782 |
{ |
|
5783 |
Q_D(const QSessionManager); |
|
5784 |
return d->sessionId; |
|
5785 |
} |
|
5786 |
||
5787 |
QString QSessionManager::sessionKey() const |
|
5788 |
{ |
|
5789 |
Q_D(const QSessionManager); |
|
5790 |
return d->sessionKey; |
|
5791 |
} |
|
5792 |
||
5793 |
||
5794 |
void* QSessionManager::handle() const |
|
5795 |
{ |
|
5796 |
return (void*) smcConnection; |
|
5797 |
} |
|
5798 |
||
5799 |
||
5800 |
bool QSessionManager::allowsInteraction() |
|
5801 |
{ |
|
5802 |
Q_D(QSessionManager); |
|
5803 |
if (sm_interactionActive) |
|
5804 |
return true; |
|
5805 |
||
5806 |
if (sm_waitingForInteraction) |
|
5807 |
return false; |
|
5808 |
||
5809 |
if (sm_interactStyle == SmInteractStyleAny) { |
|
5810 |
sm_waitingForInteraction = SmcInteractRequest(smcConnection, SmDialogNormal, |
|
5811 |
sm_interactCallback, (SmPointer*) d); |
|
5812 |
} |
|
5813 |
if (sm_waitingForInteraction) { |
|
5814 |
QEventLoop eventLoop; |
|
5815 |
d->eventLoop = &eventLoop; |
|
5816 |
(void) eventLoop.exec(); |
|
5817 |
d->eventLoop = 0; |
|
5818 |
||
5819 |
sm_waitingForInteraction = false; |
|
5820 |
if (sm_smActive) { // not cancelled |
|
5821 |
sm_interactionActive = true; |
|
5822 |
qt_sm_blockUserInput = false; |
|
5823 |
return true; |
|
5824 |
} |
|
5825 |
} |
|
5826 |
return false; |
|
5827 |
} |
|
5828 |
||
5829 |
bool QSessionManager::allowsErrorInteraction() |
|
5830 |
{ |
|
5831 |
Q_D(QSessionManager); |
|
5832 |
if (sm_interactionActive) |
|
5833 |
return true; |
|
5834 |
||
5835 |
if (sm_waitingForInteraction) |
|
5836 |
return false; |
|
5837 |
||
5838 |
if (sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors) { |
|
5839 |
sm_waitingForInteraction = SmcInteractRequest(smcConnection, SmDialogError, |
|
5840 |
sm_interactCallback, (SmPointer*) d); |
|
5841 |
} |
|
5842 |
if (sm_waitingForInteraction) { |
|
5843 |
QEventLoop eventLoop; |
|
5844 |
d->eventLoop = &eventLoop; |
|
5845 |
(void) eventLoop.exec(); |
|
5846 |
d->eventLoop = 0; |
|
5847 |
||
5848 |
sm_waitingForInteraction = false; |
|
5849 |
if (sm_smActive) { // not cancelled |
|
5850 |
sm_interactionActive = true; |
|
5851 |
qt_sm_blockUserInput = false; |
|
5852 |
return true; |
|
5853 |
} |
|
5854 |
} |
|
5855 |
return false; |
|
5856 |
} |
|
5857 |
||
5858 |
void QSessionManager::release() |
|
5859 |
{ |
|
5860 |
if (sm_interactionActive) { |
|
5861 |
SmcInteractDone(smcConnection, False); |
|
5862 |
sm_interactionActive = false; |
|
5863 |
if (sm_smActive && sm_isshutdown) |
|
5864 |
qt_sm_blockUserInput = true; |
|
5865 |
} |
|
5866 |
} |
|
5867 |
||
5868 |
void QSessionManager::cancel() |
|
5869 |
{ |
|
5870 |
sm_cancel = true; |
|
5871 |
} |
|
5872 |
||
5873 |
void QSessionManager::setRestartHint(QSessionManager::RestartHint hint) |
|
5874 |
{ |
|
5875 |
Q_D(QSessionManager); |
|
5876 |
d->restartHint = hint; |
|
5877 |
} |
|
5878 |
||
5879 |
QSessionManager::RestartHint QSessionManager::restartHint() const |
|
5880 |
{ |
|
5881 |
Q_D(const QSessionManager); |
|
5882 |
return d->restartHint; |
|
5883 |
} |
|
5884 |
||
5885 |
void QSessionManager::setRestartCommand(const QStringList& command) |
|
5886 |
{ |
|
5887 |
Q_D(QSessionManager); |
|
5888 |
d->restartCommand = command; |
|
5889 |
} |
|
5890 |
||
5891 |
QStringList QSessionManager::restartCommand() const |
|
5892 |
{ |
|
5893 |
Q_D(const QSessionManager); |
|
5894 |
return d->restartCommand; |
|
5895 |
} |
|
5896 |
||
5897 |
void QSessionManager::setDiscardCommand(const QStringList& command) |
|
5898 |
{ |
|
5899 |
Q_D(QSessionManager); |
|
5900 |
d->discardCommand = command; |
|
5901 |
} |
|
5902 |
||
5903 |
QStringList QSessionManager::discardCommand() const |
|
5904 |
{ |
|
5905 |
Q_D(const QSessionManager); |
|
5906 |
return d->discardCommand; |
|
5907 |
} |
|
5908 |
||
5909 |
void QSessionManager::setManagerProperty(const QString& name, const QString& value) |
|
5910 |
{ |
|
5911 |
sm_setProperty(name, value); |
|
5912 |
} |
|
5913 |
||
5914 |
void QSessionManager::setManagerProperty(const QString& name, const QStringList& value) |
|
5915 |
{ |
|
5916 |
sm_setProperty(name, value); |
|
5917 |
} |
|
5918 |
||
5919 |
bool QSessionManager::isPhase2() const |
|
5920 |
{ |
|
5921 |
return sm_in_phase2; |
|
5922 |
} |
|
5923 |
||
5924 |
void QSessionManager::requestPhase2() |
|
5925 |
{ |
|
5926 |
sm_phase2 = true; |
|
5927 |
} |
|
5928 |
||
5929 |
#endif // QT_NO_SESSIONMANAGER |
|
5930 |
||
5931 |
#if defined(QT_RX71_MULTITOUCH) |
|
5932 |
||
5933 |
static inline int testBit(const char *array, int bit) |
|
5934 |
{ |
|
5935 |
return (array[bit/8] & (1<<(bit%8))); |
|
5936 |
} |
|
5937 |
||
5938 |
static int openRX71Device(const QByteArray &deviceName) |
|
5939 |
{ |
|
5940 |
int fd = open(deviceName, O_RDONLY | O_NONBLOCK); |
|
5941 |
if (fd == -1) { |
|
5942 |
fd = -errno; |
|
5943 |
return fd; |
|
5944 |
} |
|
5945 |
||
5946 |
// fetch the event type mask and check that the device reports absolute coordinates |
|
5947 |
char eventTypeMask[(EV_MAX + sizeof(char) - 1) * sizeof(char) + 1]; |
|
5948 |
memset(eventTypeMask, 0, sizeof(eventTypeMask)); |
|
5949 |
if (ioctl(fd, EVIOCGBIT(0, sizeof(eventTypeMask)), eventTypeMask) < 0) { |
|
5950 |
close(fd); |
|
5951 |
return -1; |
|
5952 |
} |
|
5953 |
if (!testBit(eventTypeMask, EV_ABS)) { |
|
5954 |
close(fd); |
|
5955 |
return -1; |
|
5956 |
} |
|
5957 |
||
5958 |
// make sure that we can get the absolute X and Y positions from the device |
|
5959 |
char absMask[(ABS_MAX + sizeof(char) - 1) * sizeof(char) + 1]; |
|
5960 |
memset(absMask, 0, sizeof(absMask)); |
|
5961 |
if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absMask)), absMask) < 0) { |
|
5962 |
close(fd); |
|
5963 |
return -1; |
|
5964 |
} |
|
5965 |
if (!testBit(absMask, ABS_X) || !testBit(absMask, ABS_Y)) { |
|
5966 |
close(fd); |
|
5967 |
return -1; |
|
5968 |
} |
|
5969 |
||
5970 |
return fd; |
|
5971 |
} |
|
5972 |
||
5973 |
void QApplicationPrivate::initializeMultitouch_sys() |
|
5974 |
{ |
|
5975 |
Q_Q(QApplication); |
|
5976 |
||
5977 |
QByteArray deviceName = QByteArray("/dev/input/event"); |
|
5978 |
int currentDeviceNumber = 0; |
|
5979 |
for (;;) { |
|
5980 |
int fd = openRX71Device(QByteArray(deviceName + QByteArray::number(currentDeviceNumber++))); |
|
5981 |
if (fd == -ENOENT) { |
|
5982 |
// no more devices |
|
5983 |
break; |
|
5984 |
} |
|
5985 |
if (fd < 0) { |
|
5986 |
// not a touch device |
|
5987 |
continue; |
|
5988 |
} |
|
5989 |
||
5990 |
struct input_absinfo abs_x, abs_y, abs_z; |
|
5991 |
ioctl(fd, EVIOCGABS(ABS_X), &abs_x); |
|
5992 |
ioctl(fd, EVIOCGABS(ABS_Y), &abs_y); |
|
5993 |
ioctl(fd, EVIOCGABS(ABS_Z), &abs_z); |
|
5994 |
||
5995 |
int deviceNumber = allRX71TouchPoints.count(); |
|
5996 |
||
5997 |
QSocketNotifier *socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, q); |
|
5998 |
QObject::connect(socketNotifier, SIGNAL(activated(int)), q, SLOT(_q_readRX71MultiTouchEvents())); |
|
5999 |
||
6000 |
RX71TouchPointState touchPointState = { |
|
6001 |
socketNotifier, |
|
6002 |
QTouchEvent::TouchPoint(deviceNumber), |
|
6003 |
||
6004 |
abs_x.minimum, abs_x.maximum, q->desktop()->screenGeometry().width(), |
|
6005 |
abs_y.minimum, abs_y.maximum, q->desktop()->screenGeometry().height(), |
|
6006 |
abs_z.minimum, abs_z.maximum |
|
6007 |
}; |
|
6008 |
allRX71TouchPoints.append(touchPointState); |
|
6009 |
} |
|
6010 |
||
6011 |
hasRX71MultiTouch = allRX71TouchPoints.count() > 1; |
|
6012 |
if (!hasRX71MultiTouch) { |
|
6013 |
for (int i = 0; i < allRX71TouchPoints.count(); ++i) { |
|
6014 |
QSocketNotifier *socketNotifier = allRX71TouchPoints.at(i).socketNotifier; |
|
6015 |
close(socketNotifier->socket()); |
|
6016 |
delete socketNotifier; |
|
6017 |
} |
|
6018 |
allRX71TouchPoints.clear(); |
|
6019 |
} |
|
6020 |
} |
|
6021 |
||
6022 |
void QApplicationPrivate::cleanupMultitouch_sys() |
|
6023 |
{ |
|
6024 |
hasRX71MultiTouch = false; |
|
6025 |
for (int i = 0; i < allRX71TouchPoints.count(); ++i) { |
|
6026 |
QSocketNotifier *socketNotifier = allRX71TouchPoints.at(i).socketNotifier; |
|
6027 |
close(socketNotifier->socket()); |
|
6028 |
delete socketNotifier; |
|
6029 |
} |
|
6030 |
allRX71TouchPoints.clear(); |
|
6031 |
} |
|
6032 |
||
6033 |
bool QApplicationPrivate::readRX71MultiTouchEvents(int deviceNumber) |
|
6034 |
{ |
|
6035 |
RX71TouchPointState &touchPointState = allRX71TouchPoints[deviceNumber]; |
|
6036 |
QSocketNotifier *socketNotifier = touchPointState.socketNotifier; |
|
6037 |
int fd = socketNotifier->socket(); |
|
6038 |
||
6039 |
QTouchEvent::TouchPoint &touchPoint = touchPointState.touchPoint; |
|
6040 |
||
6041 |
bool down = touchPoint.state() != Qt::TouchPointReleased; |
|
6042 |
if (down) |
|
6043 |
touchPoint.setState(Qt::TouchPointStationary); |
|
6044 |
||
6045 |
bool changed = false; |
|
6046 |
for (;;) { |
|
6047 |
struct input_event inputEvent; |
|
6048 |
int bytesRead = read(fd, &inputEvent, sizeof(inputEvent)); |
|
6049 |
if (bytesRead <= 0) |
|
6050 |
break; |
|
6051 |
if (bytesRead != sizeof(inputEvent)) { |
|
6052 |
qWarning("Qt: INTERNAL ERROR: short read in readRX71MultiTouchEvents()"); |
|
6053 |
return false; |
|
6054 |
} |
|
6055 |
||
6056 |
switch (inputEvent.type) { |
|
6057 |
case EV_SYN: |
|
6058 |
changed = true; |
|
6059 |
switch (touchPoint.state()) { |
|
6060 |
case Qt::TouchPointPressed: |
|
6061 |
case Qt::TouchPointReleased: |
|
6062 |
// make sure we don't compress pressed and releases with any other events |
|
6063 |
return changed; |
|
6064 |
default: |
|
6065 |
break; |
|
6066 |
} |
|
6067 |
continue; |
|
6068 |
case EV_KEY: |
|
6069 |
case EV_ABS: |
|
6070 |
break; |
|
6071 |
default: |
|
6072 |
qWarning("Qt: WARNING: unknown event type %d on multitouch device", inputEvent.type); |
|
6073 |
continue; |
|
6074 |
} |
|
6075 |
||
6076 |
QPointF screenPos = touchPoint.screenPos(); |
|
6077 |
switch (inputEvent.code) { |
|
6078 |
case BTN_TOUCH: |
|
6079 |
if (!down && inputEvent.value != 0) |
|
6080 |
touchPoint.setState(Qt::TouchPointPressed); |
|
6081 |
else if (down && inputEvent.value == 0) |
|
6082 |
touchPoint.setState(Qt::TouchPointReleased); |
|
6083 |
break; |
|
6084 |
case ABS_TOOL_WIDTH: |
|
6085 |
case ABS_VOLUME: |
|
6086 |
case ABS_PRESSURE: |
|
6087 |
// ignore for now |
|
6088 |
break; |
|
6089 |
case ABS_X: |
|
6090 |
{ |
|
6091 |
qreal newValue = ((qreal(inputEvent.value - touchPointState.minX) |
|
6092 |
/ qreal(touchPointState.maxX - touchPointState.minX)) |
|
6093 |
* touchPointState.scaleX); |
|
6094 |
screenPos.rx() = newValue; |
|
6095 |
touchPoint.setScreenPos(screenPos); |
|
6096 |
break; |
|
6097 |
} |
|
6098 |
case ABS_Y: |
|
6099 |
{ |
|
6100 |
qreal newValue = ((qreal(inputEvent.value - touchPointState.minY) |
|
6101 |
/ qreal(touchPointState.maxY - touchPointState.minY)) |
|
6102 |
* touchPointState.scaleY); |
|
6103 |
screenPos.ry() = newValue; |
|
6104 |
touchPoint.setScreenPos(screenPos); |
|
6105 |
break; |
|
6106 |
} |
|
6107 |
case ABS_Z: |
|
6108 |
{ |
|
6109 |
// map Z (signal strength) to pressure for now |
|
6110 |
qreal newValue = (qreal(inputEvent.value - touchPointState.minZ) |
|
6111 |
/ qreal(touchPointState.maxZ - touchPointState.minZ)); |
|
6112 |
touchPoint.setPressure(newValue); |
|
6113 |
break; |
|
6114 |
} |
|
6115 |
default: |
|
6116 |
qWarning("Qt: WARNING: unknown event code %d on multitouch device", inputEvent.code); |
|
6117 |
continue; |
|
6118 |
} |
|
6119 |
} |
|
6120 |
||
6121 |
if (down && touchPoint.state() != Qt::TouchPointReleased) |
|
6122 |
touchPoint.setState(changed ? Qt::TouchPointMoved : Qt::TouchPointStationary); |
|
6123 |
||
6124 |
return changed; |
|
6125 |
} |
|
6126 |
||
6127 |
void QApplicationPrivate::_q_readRX71MultiTouchEvents() |
|
6128 |
{ |
|
6129 |
// read touch events from all devices |
|
6130 |
bool changed = false; |
|
6131 |
for (int i = 0; i < allRX71TouchPoints.count(); ++i) |
|
6132 |
changed = readRX71MultiTouchEvents(i) || changed; |
|
6133 |
if (!changed) |
|
6134 |
return; |
|
6135 |
||
6136 |
QList<QTouchEvent::TouchPoint> touchPoints; |
|
6137 |
for (int i = 0; i < allRX71TouchPoints.count(); ++i) |
|
6138 |
touchPoints.append(allRX71TouchPoints.at(i).touchPoint); |
|
6139 |
||
6140 |
translateRawTouchEvent(0, QTouchEvent::TouchScreen, touchPoints); |
|
6141 |
} |
|
6142 |
||
6143 |
#else // !QT_RX71_MULTITOUCH |
|
6144 |
||
6145 |
void QApplicationPrivate::initializeMultitouch_sys() |
|
6146 |
{ } |
|
6147 |
void QApplicationPrivate::cleanupMultitouch_sys() |
|
6148 |
{ } |
|
6149 |
||
6150 |
#endif // QT_RX71_MULTITOUCH |
|
6151 |
||
6152 |
QT_END_NAMESPACE |