src/gui/kernel/qwidget_x11.cpp File Reference

#include "qevent.h"
#include "qwidget.h"
#include "qdesktopwidget.h"
#include "qapplication.h"
#include "qapplication_p.h"
#include "qnamespace.h"
#include "qpainter.h"
#include "qbitmap.h"
#include "qlayout.h"
#include "qtextcodec.h"
#include "qdatetime.h"
#include "qcursor.h"
#include "qstack.h"
#include "qcolormap.h"
#include "qdebug.h"
#include "private/qbackingstore_p.h"
#include <private/qpixmap_p.h>
#include <private/qpaintengine_x11_p.h>
#include "qt_x11_p.h"
#include "qx11info_x11.h"
#include <stdlib.h>
#include "qinputcontext.h"
#include "qinputcontextfactory.h"
#include "qwidget_p.h"

Include dependency graph for qwidget_x11.cpp:

Go to the source code of this file.

Classes

struct  QtMWMHints

Defines

#define XCOORD_MAX   16383
#define WRECT_MAX   8191

Enumerations

enum  

Functions

bool qt_sendSpontaneousEvent (QObject *, QEvent *)
bool qt_wstate_iconified (WId)
void qt_updated_rootinfo ()
bool qt_nograb ()
static QtMWMHints GetMWMHints (Display *display, Window window)
static void SetMWMHints (Display *display, Window window, const QtMWMHints &mwmhints)
static bool isTransient (const QWidget *w)
static void do_size_hints (QWidget *widget, QWExtra *x)
bool qt_net_supports (Atom)
Window qt_XCreateWindow (const QWidget *creator, Display *display, Window parent, int x, int y, uint w, uint h, int borderwidth, int depth, uint windowclass, Visual *visual, ulong valuemask, XSetWindowAttributes *attributes)
Window qt_XCreateSimpleWindow (const QWidget *creator, Display *display, Window parent, int x, int y, uint w, uint h, int borderwidth, ulong border, ulong background)
void qt_XDestroyWindow (const QWidget *destroyer, Display *display, Window window)
static void qt_insert_sip (QWidget *scrolled_widget, int dx, int dy)
static int qt_sip_count (QWidget *scrolled_widget)
static void create_wm_client_leader ()
Q_GUI_EXPORT void qt_x11_enforce_cursor (QWidget *w)
Q_GUI_EXPORT void qt_x11_wait_for_window_manager (QWidget *w)
static void qt_change_net_wm_state (const QWidget *w, bool set, Atom one, Atom two=0)
static XTextProperty * qstring_to_xtp (const QString &s)

Variables

bool qt_reuse_double_buffer
static QWidgetmouseGrb = 0
static QWidgetkeyboardGrb = 0
int qt_x11_create_desktop_on_screen = -1
bool qt_broken_wm
const uint stdWidgetEventMask
const uint stdDesktopEventMask


Define Documentation

#define WRECT_MAX   8191

Definition at line 64 of file qwidget_x11.cpp.

#define XCOORD_MAX   16383

Definition at line 63 of file qwidget_x11.cpp.

Referenced by QWidgetPrivate::create_sys(), and do_size_hints().


Enumeration Type Documentation

anonymous enum

Definition at line 82 of file qwidget_x11.cpp.

00082      {
00083     MWM_HINTS_FUNCTIONS   = (1L << 0),
00084 
00085     MWM_FUNC_ALL      = (1L << 0),
00086     MWM_FUNC_RESIZE   = (1L << 1),
00087     MWM_FUNC_MOVE     = (1L << 2),
00088     MWM_FUNC_MINIMIZE = (1L << 3),
00089     MWM_FUNC_MAXIMIZE = (1L << 4),
00090     MWM_FUNC_CLOSE    = (1L << 5),
00091 
00092     MWM_HINTS_DECORATIONS = (1L << 1),
00093 
00094     MWM_DECOR_ALL      = (1L << 0),
00095     MWM_DECOR_BORDER   = (1L << 1),
00096     MWM_DECOR_RESIZEH  = (1L << 2),
00097     MWM_DECOR_TITLE    = (1L << 3),
00098     MWM_DECOR_MENU     = (1L << 4),
00099     MWM_DECOR_MINIMIZE = (1L << 5),
00100     MWM_DECOR_MAXIMIZE = (1L << 6),
00101 
00102     MWM_HINTS_INPUT_MODE = (1L << 2),
00103 
00104     MWM_INPUT_MODELESS                  = 0L,
00105     MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
00106     MWM_INPUT_FULL_APPLICATION_MODAL    = 3L
00107 };


Function Documentation

static void create_wm_client_leader (  )  [static]

Definition at line 240 of file qwidget_x11.cpp.

References QX11Info::appRootWindow(), ATOM, QByteArray::data(), QByteArray::isEmpty(), qApp, QByteArray::size(), and X11.

Referenced by QWidgetPrivate::create_sys().

00241 {
00242     if (X11->wm_client_leader) return;
00243 
00244     X11->wm_client_leader =
00245         XCreateSimpleWindow(X11->display,
00246                              QX11Info::appRootWindow(),
00247                              0, 0, 1, 1, 0, 0, 0);
00248 
00249     // set client leader property to itself
00250     XChangeProperty(X11->display,
00251                      X11->wm_client_leader, ATOM(WM_CLIENT_LEADER),
00252                      XA_WINDOW, 32, PropModeReplace,
00253                      (unsigned char *)&X11->wm_client_leader, 1);
00254 
00255 #ifndef QT_NO_SESSIONMANAGER
00256     // If we are session managed, inform the window manager about it
00257     QByteArray session = qApp->sessionId().toLatin1();
00258     if (!session.isEmpty()) {
00259         XChangeProperty(X11->display,
00260                          X11->wm_client_leader, ATOM(SM_CLIENT_ID),
00261                          XA_STRING, 8, PropModeReplace,
00262                          (unsigned char *)session.data(), session.size());
00263     }
00264 #endif
00265 }

Here is the call graph for this function:

static void do_size_hints ( QWidget widget,
QWExtra x 
) [static]

Definition at line 1807 of file qwidget_x11.cpp.

References g, QWidget::geometry(), QWidget::internalWinId(), QApplication::isRightToLeft(), qMin(), QWIDGETSIZE_MAX, s, QWidget::testAttribute(), Qt::WA_Moved, Qt::WA_Resized, Qt::WA_WState_Created, QRect::x(), x, X11, and XCOORD_MAX.

Referenced by QWidgetPrivate::setConstraints_sys(), QWidgetPrivate::setGeometry_sys(), and QWidgetPrivate::show_sys().

01808 {
01809     Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
01810     XSizeHints s;
01811     s.flags = 0;
01812     if (x) {
01813         QRect g = widget->geometry();
01814         s.x = g.x();
01815         s.y = g.y();
01816         s.width = g.width();
01817         s.height = g.height();
01818         if (x->minw > 0 || x->minh > 0) {
01819             // add minimum size hints
01820             s.flags |= PMinSize;
01821             s.min_width  = qMin(XCOORD_MAX, x->minw);
01822             s.min_height = qMin(XCOORD_MAX, x->minh);
01823         }
01824         if (x->maxw < QWIDGETSIZE_MAX || x->maxh < QWIDGETSIZE_MAX) {
01825             // add maximum size hints
01826             s.flags |= PMaxSize;
01827             s.max_width  = qMin(XCOORD_MAX, x->maxw);
01828             s.max_height = qMin(XCOORD_MAX, x->maxh);
01829         }
01830         if (x->topextra &&
01831             (x->topextra->incw > 0 || x->topextra->inch > 0)) {
01832             // add resize increment hints
01833             s.flags |= PResizeInc | PBaseSize;
01834             s.width_inc = x->topextra->incw;
01835             s.height_inc = x->topextra->inch;
01836             s.base_width = x->topextra->basew;
01837             s.base_height = x->topextra->baseh;
01838         }
01839     }
01840     if (widget->testAttribute(Qt::WA_Moved)) {
01841         // user (i.e. command-line) specified position
01842         s.flags |= USPosition;
01843         s.flags |= PPosition;
01844     }
01845     if (widget->testAttribute(Qt::WA_Resized)) {
01846         // user (i.e. command-line) specified size
01847         s.flags |= USSize;
01848         s.flags |= PSize;
01849     }
01850     s.flags |= PWinGravity;
01851     s.win_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity;
01852     XSetWMNormalHints(X11->display, widget->internalWinId(), &s);
01853 }

Here is the call graph for this function:

static QtMWMHints GetMWMHints ( Display display,
Window  window 
) [static]

Definition at line 110 of file qwidget_x11.cpp.

References ATOM, data, QtMWMHints::decorations, QtMWMHints::flags, QtMWMHints::functions, QtMWMHints::input_mode, L, MWM_DECOR_ALL, MWM_FUNC_ALL, QtMWMHints::status, Success, and type.

Referenced by QWidgetPrivate::show_sys().

00111 {
00112     QtMWMHints mwmhints;
00113 
00114     Atom type;
00115     int format;
00116     ulong nitems, bytesLeft;
00117     uchar *data = 0;
00118     if ((XGetWindowProperty(display, window, ATOM(_MOTIF_WM_HINTS), 0, 5, false,
00119                             ATOM(_MOTIF_WM_HINTS), &type, &format, &nitems, &bytesLeft,
00120                             &data) == Success)
00121         && (type == ATOM(_MOTIF_WM_HINTS)
00122             && format == 32
00123             && nitems >= 5)) {
00124         mwmhints = *(reinterpret_cast<QtMWMHints *>(data));
00125     } else {
00126         mwmhints.flags = 0L;
00127         mwmhints.functions = MWM_FUNC_ALL;
00128         mwmhints.decorations = MWM_DECOR_ALL;
00129         mwmhints.input_mode = 0L;
00130         mwmhints.status = 0L;
00131     }
00132 
00133     if (data)
00134         XFree(data);
00135 
00136     return mwmhints;
00137 }

static bool isTransient ( const QWidget w  )  [inline, static]

Definition at line 150 of file qwidget_x11.cpp.

References Qt::Dialog, Qt::Drawer, Qt::MSWindowsFixedSizeDialogHint, Qt::Sheet, Qt::SplashScreen, Qt::Tool, Qt::ToolTip, and w.

Referenced by QWidgetPrivate::setParent_sys(), and QWidgetPrivate::show_sys().

00151 {
00152     return ((w->windowType() == Qt::Dialog)
00153             || (w->windowType() == Qt::Sheet)
00154             || (w->windowFlags() & Qt::MSWindowsFixedSizeDialogHint)
00155             || (w->windowType() == Qt::Tool)
00156             || (w->windowType() == Qt::SplashScreen)
00157             || (w->windowType() == Qt::ToolTip)
00158             || (w->windowType() == Qt::Drawer));
00159 }

static XTextProperty* qstring_to_xtp ( const QString s  )  [static]

Definition at line 1001 of file qwidget_x11.cpp.

References QTextCodec::codecForLocale(), QByteArray::data(), QTextCodec::fromUnicode(), QByteArray::length(), qDebug(), s, tp, and X11.

Referenced by QWidgetPrivate::setWindowIconText_sys(), and QWidgetPrivate::setWindowTitle_sys().

01002 {
01003     static XTextProperty tp = { 0, 0, 0, 0 };
01004     static bool free_prop = true; // we can't free tp.value in case it references
01005     // the data of the static QCString below.
01006     if (tp.value) {
01007         if (free_prop)
01008             XFree(tp.value);
01009         tp.value = 0;
01010         free_prop = true;
01011     }
01012 
01013     static const QTextCodec* mapper = QTextCodec::codecForLocale();
01014     int errCode = 0;
01015     if (mapper) {
01016         QByteArray mapped = mapper->fromUnicode(s);
01017         char* tl[2];
01018         tl[0] = mapped.data();
01019         tl[1] = 0;
01020         errCode = XmbTextListToTextProperty(X11->display, tl, 1, XStdICCTextStyle, &tp);
01021 #if defined(QT_DEBUG)
01022         if (errCode < 0)
01023             qDebug("qstring_to_xtp result code %d", errCode);
01024 #endif
01025     }
01026     if (!mapper || errCode < 0) {
01027         static QByteArray qcs;
01028         qcs = s.toAscii();
01029         tp.value = (uchar*)qcs.data();
01030         tp.encoding = XA_STRING;
01031         tp.format = 8;
01032         tp.nitems = qcs.length();
01033         free_prop = false;
01034     }
01035 
01036     // ### If we knew WM could understand unicode, we could use
01037     // ### a much simpler, cheaper encoding...
01038     /*
01039         tp.value = (XChar2b*)s.unicode();
01040         tp.encoding = XA_UNICODE; // wish
01041         tp.format = 16;
01042         tp.nitems = s.length();
01043     */
01044 
01045     return &tp;
01046 }

Here is the call graph for this function:

static void qt_change_net_wm_state ( const QWidget w,
bool  set,
Atom  one,
Atom  two = 0 
) [static]

Definition at line 307 of file qwidget_x11.cpp.

References ATOM, w, and X11.

Referenced by QWidget::setWindowState().

00308 {
00309     if (!w->isVisible()) // not managed by the window manager
00310         return;
00311 
00312     XEvent e;
00313     e.xclient.type = ClientMessage;
00314     e.xclient.message_type = ATOM(_NET_WM_STATE);
00315     e.xclient.display = X11->display;
00316     e.xclient.window = w->internalWinId();
00317     e.xclient.format = 32;
00318     e.xclient.data.l[0] = set ? 1 : 0;
00319     e.xclient.data.l[1] = one;
00320     e.xclient.data.l[2] = two;
00321     e.xclient.data.l[3] = 0;
00322     e.xclient.data.l[4] = 0;
00323     XSendEvent(X11->display, RootWindow(X11->display, w->x11Info().screen()),
00324                false, (SubstructureNotifyMask | SubstructureRedirectMask), &e);
00325 }

static void qt_insert_sip ( QWidget scrolled_widget,
int  dx,
int  dy 
) [static]

Definition at line 211 of file qwidget_x11.cpp.

References ATOM, QX11Data::ScrollInProgress::id, QWidget::internalWinId(), and X11.

Referenced by QWidget::scroll().

00212 {
00213     QX11Data::ScrollInProgress sip = { X11->sip_serial++, scrolled_widget, dx, dy };
00214     X11->sip_list.append(sip);
00215 
00216     XClientMessageEvent client_message;
00217     client_message.type = ClientMessage;
00218     client_message.window = scrolled_widget->internalWinId();
00219     client_message.format = 32;
00220     client_message.message_type = ATOM(_QT_SCROLL_DONE);
00221     client_message.data.l[0] = sip.id;
00222 
00223     XSendEvent(X11->display, scrolled_widget->internalWinId(), False, NoEventMask,
00224         (XEvent*)&client_message);
00225 }

Here is the call graph for this function:

bool qt_net_supports ( Atom   ) 

Definition at line 1068 of file qapplication_x11.cpp.

References X11.

Referenced by QDialog::adjustPosition(), QDesktopWidget::availableGeometry(), QWidgetPrivate::create_sys(), qt_get_net_virtual_roots(), QWidgetPrivate::setGeometry_sys(), QWidget::setWindowState(), QWidgetPrivate::show_sys(), QETWidget::translateConfigEvent(), QETWidget::translatePropertyEvent(), and QWidgetPrivate::updateFrameStrut().

01069 {
01070     if (! X11->net_supported_list)
01071         return false;
01072 
01073     bool supported = false;
01074     int i = 0;
01075     while (X11->net_supported_list[i] != 0) {
01076         if (X11->net_supported_list[i++] == atom) {
01077             supported = true;
01078             break;
01079         }
01080     }
01081 
01082     return supported;
01083 }

bool qt_nograb (  ) 

Definition at line 2121 of file qapplication_x11.cpp.

Referenced by QApplicationPrivate::closePopup(), QWidget::grabKeyboard(), QWidget::grabMouse(), QApplicationPrivate::openPopup(), QWidget::releaseKeyboard(), and QWidget::releaseMouse().

02122 {
02123 #if defined(QT_DEBUG)
02124     return appNoGrab;
02125 #else
02126     return false;
02127 #endif
02128 }

bool qt_sendSpontaneousEvent ( QObject ,
QEvent  
)

Definition at line 4185 of file qapplication_x11.cpp.

04186 {
04187     return QCoreApplication::sendSpontaneousEvent(receiver, event);
04188 }

static int qt_sip_count ( QWidget scrolled_widget  )  [static]

Definition at line 227 of file qwidget_x11.cpp.

References i, and X11.

Referenced by QWidget::scroll().

00228 {
00229     int sips=0;
00230 
00231     for (int i = 0; i < X11->sip_list.size(); ++i) {
00232         const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i);
00233         if (sip.scrolled_widget == scrolled_widget)
00234             sips++;
00235     }
00236 
00237     return sips;
00238 }

void qt_updated_rootinfo (  ) 

Definition at line 2087 of file qapplication_x11.cpp.

References app_save_rootinfo.

02088 {
02089     app_save_rootinfo = true;
02090 }

bool qt_wstate_iconified ( WId   ) 

Definition at line 2092 of file qapplication_x11.cpp.

References ATOM, Success, and X11.

02093 {
02094     Atom type;
02095     int format;
02096     unsigned long length, after;
02097     uchar *data = 0;
02098     int r = XGetWindowProperty(X11->display, winid, ATOM(WM_STATE), 0, 2,
02099                                  False, AnyPropertyType, &type, &format,
02100                                  &length, &after, &data);
02101     bool iconic = false;
02102     if (r == Success && data && format == 32) {
02103         // quint32 *wstate = (quint32*)data;
02104         unsigned long *wstate = (unsigned long *) data;
02105         iconic = (*wstate == IconicState);
02106         XFree((char *)data);
02107     }
02108     return iconic;
02109 }

Q_GUI_EXPORT void qt_x11_enforce_cursor ( QWidget w  ) 

Definition at line 268 of file qwidget_x11.cpp.

References QApplication::overrideCursor(), w, Qt::WA_SetCursor, Qt::WA_WState_Created, X11, and XNone.

Referenced by QWidgetPrivate::create_sys(), QApplication::restoreOverrideCursor(), QWidgetPrivate::setCursor_sys(), QWidgetPrivate::setEnabled_helper(), QApplication::setOverrideCursor(), and QWidgetPrivate::unsetCursor_sys().

00269 {
00270     if (!w->testAttribute(Qt::WA_WState_Created))
00271         return;
00272     if (w->testAttribute(Qt::WA_SetCursor)) {
00273         QCursor *oc = QApplication::overrideCursor();
00274         if (oc) {
00275             XDefineCursor(X11->display, w->internalWinId(), oc->handle());
00276         } else if (w->isEnabled()) {
00277             XDefineCursor(X11->display, w->internalWinId(), w->cursor().handle());
00278         } else {
00279             // enforce the windows behavior of clearing the cursor on
00280             // disabled widgets
00281             XDefineCursor(X11->display, w->internalWinId(), XNone);
00282         }
00283     } else {
00284         XDefineCursor(X11->display, w->internalWinId(), XNone);
00285     }
00286 }

Here is the call graph for this function:

Q_GUI_EXPORT void qt_x11_wait_for_window_manager ( QWidget w  ) 

Definition at line 288 of file qwidget_x11.cpp.

References QCoreApplication::flush(), qApp, t, w, Qt::WA_WState_Created, and X11.

Referenced by QSplashScreen::finish(), and QWidgetPrivate::show_sys().

00289 {
00290     QApplication::flush();
00291     XEvent ev;
00292     QTime t;
00293     t.start();
00294     Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
00295     while (!XCheckTypedWindowEvent(X11->display, w->internalWinId(), ReparentNotify, &ev)) {
00296         if (XCheckTypedWindowEvent(X11->display, w->internalWinId(), MapNotify, &ev))
00297             break;
00298         if (t.elapsed() > 500)
00299             return; // give up, no event available
00300         qApp->syncX(); // non-busy wait
00301     }
00302     qApp->x11ProcessEvent(&ev);
00303     if (XCheckTypedWindowEvent(X11->display, w->internalWinId(), ConfigureNotify, &ev))
00304         qApp->x11ProcessEvent(&ev);
00305 }

Here is the call graph for this function:

Window qt_XCreateSimpleWindow ( const QWidget creator,
Display display,
Window  parent,
int  x,
int  y,
uint  w,
uint  h,
int  borderwidth,
ulong  border,
ulong  background 
)

Definition at line 45 of file qwidgetcreate_x11.cpp.

Referenced by QWidgetPrivate::create_sys().

00048 {
00049     return XCreateSimpleWindow(display, parent, x, y, w, h, borderwidth,
00050                                 border, background);
00051 }

Window qt_XCreateWindow ( const QWidget creator,
Display display,
Window  parent,
int  x,
int  y,
uint  w,
uint  h,
int  borderwidth,
int  depth,
uint  windowclass,
Visual *  visual,
ulong  valuemask,
XSetWindowAttributes *  attributes 
)

Definition at line 34 of file qwidgetcreate_x11.cpp.

Referenced by QWidgetPrivate::create_sys().

00039 {
00040     return XCreateWindow(display, parent, x, y, w, h, borderwidth, depth,
00041                           windowclass, visual, valuemask, attributes);
00042 }

void qt_XDestroyWindow ( const QWidget destroyer,
Display display,
Window  window 
)

Definition at line 54 of file qwidgetcreate_x11.cpp.

Referenced by QWidgetPrivate::create_sys(), QWidget::destroy(), and QWidgetPrivate::setParent_sys().

00055 {
00056     XDestroyWindow(display, window);
00057 }

static void SetMWMHints ( Display display,
Window  window,
const QtMWMHints mwmhints 
) [static]

Definition at line 139 of file qwidget_x11.cpp.

References ATOM, QtMWMHints::flags, and l.

Referenced by QWidgetPrivate::create_sys(), and QWidgetPrivate::show_sys().

00140 {
00141     if (mwmhints.flags != 0l) {
00142         XChangeProperty(display, window, ATOM(_MOTIF_WM_HINTS), ATOM(_MOTIF_WM_HINTS), 32,
00143                         PropModeReplace, (unsigned char *) &mwmhints, 5);
00144     } else {
00145         XDeleteProperty(display, window, ATOM(_MOTIF_WM_HINTS));
00146     }
00147 }


Variable Documentation

QWidget* keyboardGrb = 0 [static]

Definition at line 69 of file qwidget_x11.cpp.

Referenced by QWidget::destroy(), QWidget::grabKeyboard(), QWidget::keyboardGrabber(), and QWidget::releaseKeyboard().

QWidget* mouseGrb = 0 [static]

Definition at line 68 of file qwidget_x11.cpp.

Referenced by QWidget::destroy(), QWidget::grabMouse(), QWidget::mouseGrabber(), and QWidget::releaseMouse().

bool qt_broken_wm

Definition at line 271 of file qapplication_x11.cpp.

Referenced by qt_detect_broken_window_manager(), and QWidgetPrivate::setGeometry_sys().

bool qt_reuse_double_buffer

Definition at line 308 of file qapplication_x11.cpp.

int qt_x11_create_desktop_on_screen = -1

Definition at line 72 of file qwidget_x11.cpp.

Referenced by QWidgetPrivate::create_sys(), and QDesktopWidget::screen().

const uint stdDesktopEventMask

Initial value:

                        
       (uint)(
           KeymapStateMask |
           EnterWindowMask | LeaveWindowMask |
           PropertyChangeMask
      )

Definition at line 185 of file qwidget_x11.cpp.

const uint stdWidgetEventMask

Initial value:

                        
        (uint)(
            KeyPressMask | KeyReleaseMask |
            ButtonPressMask | ButtonReleaseMask |
            KeymapStateMask |
            ButtonMotionMask | PointerMotionMask |
            EnterWindowMask | LeaveWindowMask |
            FocusChangeMask |
            ExposureMask |
            PropertyChangeMask |
            StructureNotifyMask
       )

Definition at line 172 of file qwidget_x11.cpp.

Referenced by QWidgetPrivate::create_sys().


Generated on Thu Mar 15 13:29:53 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1