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