Qt 4.8
Public Functions | Protected Functions | Private Functions | Properties | List of all members
QXlibWindow Class Reference

#include <qxlibwindow.h>

Inheritance diagram for QXlibWindow:
QPlatformWindow

Public Functions

uint depth () const
 
QImage::Format format () const
 
QPlatformGLContextglContext () const
 Reimplement to return the glContext associated with the window. More...
 
GC graphicsContext () const
 
void handleCloseEvent ()
 
void handleEnterEvent ()
 
void handleFocusInEvent ()
 
void handleFocusOutEvent ()
 
void handleLeaveEvent ()
 
void handleMouseEvent (QEvent::Type, XButtonEvent *ev)
 
void lower ()
 Reimplement to be able to let Qt lower windows to the bottom of the desktop. More...
 
void mousePressEvent (XButtonEvent *)
 
void paintEvent ()
 
 QXlibWindow (QWidget *window)
 
void raise ()
 Reimplement to be able to let Qt rais windows to the top of the desktop. More...
 
void requestActivateWindow ()
 Reimplement to let Qt be able to request activation/focus for a window. More...
 
void resizeEvent (XConfigureEvent *configure_event)
 
void setCursor (const Cursor &cursor)
 
void setGeometry (const QRect &rect)
 This function is called by Qt whenever a window is moved or the window is resized. More...
 
void setParent (const QPlatformWindow *window)
 This function is called to enable native child widgets in QPA. More...
 
void setVisible (bool visible)
 Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false. More...
 
Qt::WindowFlags setWindowFlags (Qt::WindowFlags type)
 Requests setting the window flags of this surface to type. More...
 
void setWindowTitle (const QString &title)
 Reimplement to set the window title to title. More...
 
Visual * visual () const
 
Qt::WindowFlags windowFlags () const
 Returns the effective window flags for this surface. More...
 
WId winId () const
 Reimplement in subclasses to return a handle to the native window. More...
 
Window xWindow () const
 
 ~QXlibWindow ()
 
- Public Functions inherited from QPlatformWindow
virtual QRect geometry () const
 Returnes the current geometry of a window. More...
 
 QPlatformWindow (QWidget *tlw)
 Constructs a platform window with the given top level widget. More...
 
virtual void setOpacity (qreal level)
 Reimplement to be able to let Qt set the opacity level of a window. More...
 
QWidgetwidget () const
 Returnes the widget which belongs to the QPlatformWindow. More...
 
virtual ~QPlatformWindow ()
 Virtual destructor does not delete its top level widget. More...
 

Protected Functions

void doSizeHints ()
 
QXlibMWMHints getMWMHints () const
 
QVector< Atom > getNetWmState () const
 
void setMWMHints (const QXlibMWMHints &mwmhints)
 

Private Functions

QPlatformWindowFormat correctColorBuffers (const QPlatformWindowFormat &windowFormat) const
 
GC createGC ()
 

Properties

GC gc
 
uint mDepth
 
QImage::Format mFormat
 
QPlatformGLContextmGLContext
 
QXlibScreenmScreen
 
Visual * mVisual
 
Qt::WindowFlags mWindowFlags
 
Window x_window
 

Additional Inherited Members

- Protected Variables inherited from QPlatformWindow
QScopedPointer< QPlatformWindowPrivated_ptr
 

Detailed Description

Definition at line 86 of file qxlibwindow.h.

Constructors and Destructors

◆ QXlibWindow()

QXlibWindow::QXlibWindow ( QWidget window)

defined(QT_OPENGL_ES_2)

defined(QT_NO_OPENGL)

Definition at line 74 of file qxlibwindow.cpp.

75  : QPlatformWindow(window)
76  , mGLContext(0)
78 {
79  int x = window->x();
80  int y = window->y();
81  int w = window->width();
82  int h = window->height();
83 
84 #if !defined(QT_NO_OPENGL)
85  if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL
86  && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
87  || window->platformWindowFormat().alpha()) {
88 #if !defined(QT_OPENGL_ES_2)
89  XVisualInfo *visualInfo = qglx_findVisualInfo(mScreen->display()->nativeDisplay(),mScreen->xScreenNumber(),window->platformWindowFormat());
90 #else
91  QPlatformWindowFormat windowFormat = correctColorBuffers(window->platformWindowFormat());
92 
93  EGLDisplay eglDisplay = mScreen->eglDisplay();
94  EGLConfig eglConfig = q_configFromQPlatformWindowFormat(eglDisplay,windowFormat);
95  VisualID id = QXlibEglIntegration::getCompatibleVisualId(mScreen->display()->nativeDisplay(), eglDisplay, eglConfig);
96 
97  XVisualInfo visualInfoTemplate;
98  memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
99  visualInfoTemplate.visualid = id;
100 
101  XVisualInfo *visualInfo;
102  int matchingCount = 0;
103  visualInfo = XGetVisualInfo(mScreen->display()->nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount);
104 #endif
105  if (visualInfo) {
106  mDepth = visualInfo->depth;
108  mVisual = visualInfo->visual;
109  Colormap cmap = XCreateColormap(mScreen->display()->nativeDisplay(), mScreen->rootWindow(), visualInfo->visual, AllocNone);
110 
111  XSetWindowAttributes a;
112  a.background_pixel = WhitePixel(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber());
113  a.border_pixel = BlackPixel(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber());
114  a.colormap = cmap;
115  x_window = XCreateWindow(mScreen->display()->nativeDisplay(), mScreen->rootWindow(),x, y, w, h,
116  0, visualInfo->depth, InputOutput, visualInfo->visual,
117  CWBackPixel|CWBorderPixel|CWColormap, &a);
118  } else {
119  qFatal("no window!");
120  }
121  } else
122 #endif
123  {
124  mDepth = mScreen->depth();
127 
128  x_window = XCreateSimpleWindow(mScreen->display()->nativeDisplay(), mScreen->rootWindow(),
129  x, y, w, h, 0 /*border_width*/,
131  }
132 
133 #ifdef MYX11_DEBUG
134  qDebug() << "QTestLiteWindow::QTestLiteWindow creating" << hex << x_window << window;
135 #endif
136 
137  XSetWindowBackgroundPixmap(mScreen->display()->nativeDisplay(), x_window, XNone);
138 
139  XSelectInput(mScreen->display()->nativeDisplay(), x_window,
140  ExposureMask | KeyPressMask | KeyReleaseMask |
141  EnterWindowMask | LeaveWindowMask | FocusChangeMask |
142  PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
143  ButtonMotionMask | PropertyChangeMask |
144  StructureNotifyMask);
145 
146  gc = createGC();
147 
148  Atom protocols[5];
149  int n = 0;
150  protocols[n++] = QXlibStatic::atom(QXlibStatic::WM_DELETE_WINDOW); // support del window protocol
151  protocols[n++] = QXlibStatic::atom(QXlibStatic::WM_TAKE_FOCUS); // support take focus window protocol
152 // protocols[n++] = QXlibStatic::atom(QXlibStatic::_NET_WM_PING); // support _NET_WM_PING protocol
153 #ifndef QT_NO_XSYNC
154  protocols[n++] = QXlibStatic::atom(QXlibStatic::_NET_WM_SYNC_REQUEST); // support _NET_WM_SYNC_REQUEST protocol
155 #endif // QT_NO_XSYNC
156  if (window->windowFlags() & Qt::WindowContextHelpButtonHint)
158  XSetWMProtocols(mScreen->display()->nativeDisplay(), x_window, protocols, n);
159 }
unsigned long whitePixel()
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
Window rootWindow()
QImage::Format mFormat
Definition: qxlibwindow.h:143
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
Display * nativeDisplay() const
QPlatformGLContext * mGLContext
Definition: qxlibwindow.h:148
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
static QColor cmap[256]
Definition: qgl_mac.mm:760
long ASN1_INTEGER_get ASN1_INTEGER * a
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
QPlatformWindow(QWidget *tlw)
Constructs a platform window with the given top level widget.
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
static QXlibScreen * testLiteScreenForWidget(QWidget *widget)
NSWindow * window
Visual * mVisual
Definition: qxlibwindow.h:144
static VisualID getCompatibleVisualId(Display *display, EGLDisplay eglDisplay, EGLConfig config)
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
QPlatformWindowFormat correctColorBuffers(const QPlatformWindowFormat &windowFormat) const
static Atom atom(X11Atom atom)
Q_CORE_EXPORT void qFatal(const char *,...)
int depth() const
Reimplement in subclass to return current depth of the screen.
Definition: qxlibscreen.h:63
Window x_window
Definition: qxlibwindow.h:139
int xScreenNumber() const
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
Visual * defaultVisual() const
XVisualInfo * qglx_findVisualInfo(Display *display, int screen, const QPlatformWindowFormat &format)
QXlibDisplay * display() const
unsigned long blackPixel()

◆ ~QXlibWindow()

QXlibWindow::~QXlibWindow ( )

Definition at line 163 of file qxlibwindow.cpp.

164 {
165 #ifdef MYX11_DEBUG
166  qDebug() << "~QTestLiteWindow" << hex << x_window;
167 #endif
168  delete mGLContext;
169  XFreeGC(mScreen->display()->nativeDisplay(), gc);
170  XDestroyWindow(mScreen->display()->nativeDisplay(), x_window);
171 }
Display * nativeDisplay() const
QPlatformGLContext * mGLContext
Definition: qxlibwindow.h:148
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

Functions

◆ correctColorBuffers()

QPlatformWindowFormat QXlibWindow::correctColorBuffers ( const QPlatformWindowFormat windowFormat) const
private

Definition at line 726 of file qxlibwindow.cpp.

Referenced by glContext(), and QXlibWindow().

727 {
728  // I have only tested this setup on a dodgy intel setup, where I didn't use standard libs,
729  // so this might be not what we want to do :)
730  if ( !(platformWindowFormat.redBufferSize() == -1 &&
731  platformWindowFormat.greenBufferSize() == -1 &&
732  platformWindowFormat.blueBufferSize() == -1))
733  return platformWindowFormat;
734 
735  QPlatformWindowFormat windowFormat = platformWindowFormat;
736  if (mScreen->depth() == 16) {
737  windowFormat.setRedBufferSize(5);
738  windowFormat.setGreenBufferSize(6);
739  windowFormat.setBlueBufferSize(5);
740  } else {
741  windowFormat.setRedBufferSize(8);
742  windowFormat.setGreenBufferSize(8);
743  windowFormat.setBlueBufferSize(8);
744  }
745 
746  return windowFormat;
747 }
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
void setBlueBufferSize(int size)
Set the preferred blue buffer size to size.
int depth() const
Reimplement in subclass to return current depth of the screen.
Definition: qxlibscreen.h:63
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
void setRedBufferSize(int size)
Set the preferred red buffer size to size.
void setGreenBufferSize(int size)
Set the preferred green buffer size to size.

◆ createGC()

GC QXlibWindow::createGC ( )
private

Definition at line 305 of file qxlibwindow.cpp.

Referenced by QXlibWindow().

306 {
307  GC gc;
308 
309  gc = XCreateGC(mScreen->display()->nativeDisplay(), x_window, 0, 0);
310  if (gc < 0) {
311  qWarning("QTestLiteWindow::createGC() could not create GC");
312  }
313  return gc;
314 }
Display * nativeDisplay() const
Q_CORE_EXPORT void qWarning(const char *,...)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
struct _XGC * GC
Definition: qwindowdefs.h:117
QXlibDisplay * display() const

◆ depth()

uint QXlibWindow::depth ( ) const
inline

Definition at line 125 of file qxlibwindow.h.

Referenced by QXlibWindowSurface::flush(), and QXlibWindowSurface::resizeShmImage().

125 { return mDepth; }

◆ doSizeHints()

void QXlibWindow::doSizeHints ( )
protected

Definition at line 707 of file qxlibwindow.cpp.

Referenced by setVisible().

708 {
709  Q_ASSERT(widget()->testAttribute(Qt::WA_WState_Created));
710  XSizeHints s;
711  s.flags = 0;
712  QRect g = geometry();
713  s.x = g.x();
714  s.y = g.y();
715  s.width = g.width();
716  s.height = g.height();
717  s.flags |= USPosition;
718  s.flags |= PPosition;
719  s.flags |= USSize;
720  s.flags |= PSize;
721  s.flags |= PWinGravity;
722  s.win_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity;
723  XSetWMNormalHints(mScreen->display()->nativeDisplay(), x_window, &s);
724 }
virtual QRect geometry() const
Returnes the current geometry of a window.
Display * nativeDisplay() const
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Window x_window
Definition: qxlibwindow.h:139
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QXlibDisplay * display() const
static bool isRightToLeft()
Returns true if the application&#39;s layout direction is Qt::RightToLeft; otherwise returns false...
Definition: qapplication.h:233
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ format()

QImage::Format QXlibWindow::format ( ) const
inline

Definition at line 126 of file qxlibwindow.h.

Referenced by getMWMHints(), and QXlibWindowSurface::resizeShmImage().

126 { return mFormat; }
QImage::Format mFormat
Definition: qxlibwindow.h:143

◆ getMWMHints()

QXlibMWMHints QXlibWindow::getMWMHints ( ) const
protected

Definition at line 373 of file qxlibwindow.cpp.

374 {
375  QXlibMWMHints mwmhints;
376 
377  Atom type;
378  int format;
379  ulong nitems, bytesLeft;
380  uchar *data = 0;
381  Atom atomForMotifWmHints = QXlibStatic::atom(QXlibStatic::_MOTIF_WM_HINTS);
382  if ((XGetWindowProperty(mScreen->display()->nativeDisplay(), x_window, atomForMotifWmHints, 0, 5, false,
383  atomForMotifWmHints, &type, &format, &nitems, &bytesLeft,
384  &data) == Success)
385  && (type == atomForMotifWmHints
386  && format == 32
387  && nitems >= 5)) {
388  mwmhints = *(reinterpret_cast<QXlibMWMHints *>(data));
389  } else {
390  mwmhints.flags = 0L;
391  mwmhints.functions = MWM_FUNC_ALL;
392  mwmhints.decorations = MWM_DECOR_ALL;
393  mwmhints.input_mode = 0L;
394  mwmhints.status = 0L;
395  }
396 
397  if (data)
398  XFree(data);
399 
400  return mwmhints;
401 }
int type
Definition: qmetatype.cpp:239
Display * nativeDisplay() const
ulong decorations
Definition: qxlibwindow.h:54
unsigned char uchar
Definition: qglobal.h:994
ulong functions
Definition: qxlibwindow.h:54
static const char * data(const QByteArray &arr)
unsigned long ulong
Definition: qglobal.h:997
static Atom atom(X11Atom atom)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QImage::Format format() const
Definition: qxlibwindow.h:126
QXlibDisplay * display() const

◆ getNetWmState()

QVector< Atom > QXlibWindow::getNetWmState ( ) const
protected

Definition at line 428 of file qxlibwindow.cpp.

Referenced by setWindowFlags().

429 {
430  QVector<Atom> returnValue;
431 
432  // Don't read anything, just get the size of the property data
433  Atom actualType;
434  int actualFormat;
435  ulong propertyLength;
436  ulong bytesLeft;
437  uchar *propertyData = 0;
439  False, XA_ATOM, &actualType, &actualFormat,
440  &propertyLength, &bytesLeft, &propertyData) == Success
441  && actualType == XA_ATOM && actualFormat == 32) {
442  returnValue.resize(bytesLeft / 4);
443  XFree((char*) propertyData);
444 
445  // fetch all data
447  returnValue.size(), False, XA_ATOM, &actualType, &actualFormat,
448  &propertyLength, &bytesLeft, &propertyData) != Success) {
449  returnValue.clear();
450  } else if (propertyLength != (ulong)returnValue.size()) {
451  returnValue.resize(propertyLength);
452  }
453 
454  // put it into netWmState
455  if (!returnValue.isEmpty()) {
456  memcpy(returnValue.data(), propertyData, returnValue.size() * sizeof(Atom));
457  }
458  XFree((char*) propertyData);
459  }
460 
461  return returnValue;
462 }
Display * nativeDisplay() const
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned char uchar
Definition: qglobal.h:994
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
unsigned long ulong
Definition: qglobal.h:997
static Atom atom(X11Atom atom)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QXlibDisplay * display() const
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ glContext()

QPlatformGLContext * QXlibWindow::glContext ( ) const
virtual

Reimplement to return the glContext associated with the window.

Reimplemented from QPlatformWindow.

Definition at line 669 of file qxlibwindow.cpp.

670 {
671  if (!QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
672  return 0;
673  if (!mGLContext) {
674  QXlibWindow *that = const_cast<QXlibWindow *>(this);
675 #if !defined(QT_NO_OPENGL)
676 #if !defined(QT_OPENGL_ES_2)
677  that->mGLContext = new QGLXContext(x_window, mScreen,widget()->platformWindowFormat());
678 #else
679  EGLDisplay display = mScreen->eglDisplay();
680 
681  QPlatformWindowFormat windowFormat = correctColorBuffers(widget()->platformWindowFormat());
682 
683  EGLConfig config = q_configFromQPlatformWindowFormat(display,windowFormat);
684  QVector<EGLint> eglContextAttrs;
685  eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
686  eglContextAttrs.append(2);
687  eglContextAttrs.append(EGL_NONE);
688 
689  EGLSurface eglSurface = eglCreateWindowSurface(display,config,(EGLNativeWindowType)x_window,0);
690  that->mGLContext = new QEGLPlatformContext(display, config, eglContextAttrs.data(), eglSurface, EGL_OPENGL_ES_API, static_cast<QEGLPlatformContext *>(windowFormat.sharedGLContext()));
691 #endif
692 #endif
693  }
694  return mGLContext;
695 }
EGLConfig q_configFromQPlatformWindowFormat(EGLDisplay display, const QPlatformWindowFormat &format, bool highestPixelFormat, int surfaceType)
QPlatformGLContext * mGLContext
Definition: qxlibwindow.h:148
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
NativeWindowType EGLNativeWindowType
Definition: qegl_p.h:116
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QPlatformGLContext * sharedGLContext() const
QPlatformWindowFormat correctColorBuffers(const QPlatformWindowFormat &windowFormat) const
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ graphicsContext()

GC QXlibWindow::graphicsContext ( ) const

Definition at line 702 of file qxlibwindow.cpp.

Referenced by QXlibWindowSurface::flush().

703 {
704  return gc;
705 }

◆ handleCloseEvent()

void QXlibWindow::handleCloseEvent ( )

Definition at line 232 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

233 {
235 }
static void handleCloseEvent(QWidget *w)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ handleEnterEvent()

void QXlibWindow::handleEnterEvent ( )

Definition at line 238 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

239 {
241 }
static void handleEnterEvent(QWidget *w)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ handleFocusInEvent()

void QXlibWindow::handleFocusInEvent ( )

Definition at line 248 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

249 {
251 }
static void handleWindowActivated(QWidget *w)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ handleFocusOutEvent()

void QXlibWindow::handleFocusOutEvent ( )

Definition at line 253 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

254 {
256 }
static void handleWindowActivated(QWidget *w)

◆ handleLeaveEvent()

void QXlibWindow::handleLeaveEvent ( )

Definition at line 243 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

244 {
246 }
static void handleLeaveEvent(QWidget *w)
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ handleMouseEvent()

void QXlibWindow::handleMouseEvent ( QEvent::Type  type,
XButtonEvent *  ev 
)

Definition at line 189 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent(), and mousePressEvent().

190 {
191  static QPoint mousePoint;
192 
193  Qt::MouseButton button = Qt::NoButton;
194  Qt::MouseButtons buttons = translateMouseButtons(e->state);
195  Qt::KeyboardModifiers modifiers = mScreen->keyboard()->translateModifiers(e->state);
196  if (type != QEvent::MouseMove) {
197  switch (e->button) {
198  case Button1: button = Qt::LeftButton; break;
199  case Button2: button = Qt::MidButton; break;
200  case Button3: button = Qt::RightButton; break;
201  case Button4:
202  case Button5:
203  case 6:
204  case 7: {
205  //mouse wheel
207  //logic borrowed from qapplication_x11.cpp
208  int delta = 120 * ((e->button == Button4 || e->button == 6) ? 1 : -1);
209  bool hor = (((e->button == Button4 || e->button == Button5)
210  && (modifiers & Qt::AltModifier))
211  || (e->button == 6 || e->button == 7));
213  QPoint(e->x, e->y),
214  QPoint(e->x_root, e->y_root),
215  delta, hor ? Qt::Horizontal : Qt::Vertical);
216  }
217  return;
218  }
219  default: break;
220  }
221  }
222 
223  buttons ^= button; // X event uses state *before*, Qt uses state *after*
224 
226  QPoint(e->x_root, e->y_root),
227  buttons);
228 
229  mousePoint = QPoint(e->x_root, e->y_root);
230 }
int type
Definition: qmetatype.cpp:239
static void handleWheelEvent(QWidget *w, const QPoint &local, const QPoint &global, int d, Qt::Orientation o)
Qt::KeyboardModifiers translateModifiers(int s)
static Qt::MouseButtons buttons
static Qt::MouseButtons translateMouseButtons(int s)
QXlibKeyboard * keyboard() const
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.
MouseButton
Definition: qnamespace.h:150

◆ lower()

void QXlibWindow::lower ( )
virtual

Reimplement to be able to let Qt lower windows to the bottom of the desktop.

Reimplemented from QPlatformWindow.

Definition at line 288 of file qxlibwindow.cpp.

289 {
290  XLowerWindow(mScreen->display()->nativeDisplay(), x_window);
291 }
Display * nativeDisplay() const
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

◆ mousePressEvent()

void QXlibWindow::mousePressEvent ( XButtonEvent *  e)

Definition at line 350 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

351 {
352  static long prevTime = 0;
353  static Window prevWindow;
354  static int prevX = -999;
355  static int prevY = -999;
356 
358 
359  if (e->window == prevWindow && long(e->time) - prevTime < QApplication::doubleClickInterval()
360  && qAbs(e->x - prevX) < 5 && qAbs(e->y - prevY) < 5) {
362  prevTime = e->time - QApplication::doubleClickInterval(); //no double click next time
363  } else {
364  prevTime = e->time;
365  }
366  prevWindow = e->window;
367  prevX = e->x;
368  prevY = e->y;
369 
370  handleMouseEvent(type, e);
371 }
int type
Definition: qmetatype.cpp:239
void handleMouseEvent(QEvent::Type, XButtonEvent *ev)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
static int doubleClickInterval()

◆ paintEvent()

void QXlibWindow::paintEvent ( )

Definition at line 316 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

317 {
318 #ifdef MYX11_DEBUG
319 // qDebug() << "QTestLiteWindow::paintEvent" << shm_img.size() << painted;
320 #endif
321 
322  if (QWindowSurface *surface = widget()->windowSurface())
323  surface->flush(widget(), widget()->geometry(), QPoint());
324 }
virtual QRect geometry() const
Returnes the current geometry of a window.
The QWindowSurface class provides the drawing area for top-level windows.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ raise()

void QXlibWindow::raise ( )
virtual

Reimplement to be able to let Qt rais windows to the top of the desktop.

Reimplemented from QPlatformWindow.

Definition at line 283 of file qxlibwindow.cpp.

284 {
285  XRaiseWindow(mScreen->display()->nativeDisplay(), x_window);
286 }
Display * nativeDisplay() const
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

◆ requestActivateWindow()

void QXlibWindow::requestActivateWindow ( )
virtual

Reimplement to let Qt be able to request activation/focus for a window.

Some window systems will probably not have callbacks for this functionality, and then calling QWindowSystemInterface::handleWindowActivated(QWidget *w) would be sufficient.

If the window system has some event handling/callbacks then call QWindowSystemInterface::handleWindowActivated(QWidget *w) when the window system gives the notification.

Default implementation calls QWindowSystem::handleWindowActivated(QWidget *w)

Reimplemented from QPlatformWindow.

Definition at line 326 of file qxlibwindow.cpp.

327 {
328  XSetInputFocus(mScreen->display()->nativeDisplay(), x_window, XRevertToParent, CurrentTime);
329 }
Display * nativeDisplay() const
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

◆ resizeEvent()

void QXlibWindow::resizeEvent ( XConfigureEvent *  configure_event)

Definition at line 331 of file qxlibwindow.cpp.

Referenced by QXlibScreen::handleEvent().

332 {
333  int xpos = geometry().x();
334  int ypos = geometry().y();
335  if ((e->width != geometry().width() || e->height != geometry().height()) && e->x == 0 && e->y == 0) {
336  //qDebug() << "resize with bogus pos" << e->x << e->y << e->width << e->height << "window"<< hex << window;
337  } else {
338  //qDebug() << "geometry change" << e->x << e->y << e->width << e->height << "window"<< hex << window;
339  xpos = e->x;
340  ypos = e->y;
341  }
342 #ifdef MYX11_DEBUG
343  qDebug() << hex << x_window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height;
344 #endif
345 
346  QRect newRect(xpos, ypos, e->width, e->height);
348 }
virtual QRect geometry() const
Returnes the current geometry of a window.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
Window x_window
Definition: qxlibwindow.h:139
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
static void handleGeometryChange(QWidget *w, const QRect &newRect)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ setCursor()

void QXlibWindow::setCursor ( const Cursor &  cursor)

Definition at line 663 of file qxlibwindow.cpp.

Referenced by QXlibCursor::changeCursor().

664 {
665  XDefineCursor(mScreen->display()->nativeDisplay(), x_window, cursor);
666  mScreen->display()->flush();
667 }
Display * nativeDisplay() const
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const
void flush() const

◆ setGeometry()

void QXlibWindow::setGeometry ( const QRect rect)
virtual

This function is called by Qt whenever a window is moved or the window is resized.

The resize can happen programatically(from ie. user application) or by the window manager. This means that there is no need to call this function specifically from the window manager callback, instead call QWindowSystemInterface::handleGeometryChange(QWidget *w, const QRect &newRect);

Reimplemented from QPlatformWindow.

Definition at line 260 of file qxlibwindow.cpp.

261 {
262  XMoveResizeWindow(mScreen->display()->nativeDisplay(), x_window, rect.x(), rect.y(), rect.width(), rect.height());
264 }
virtual void setGeometry(const QRect &rect)
This function is called by Qt whenever a window is moved or the window is resized.
Display * nativeDisplay() const
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Window x_window
Definition: qxlibwindow.h:139
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

◆ setMWMHints()

void QXlibWindow::setMWMHints ( const QXlibMWMHints mwmhints)
protected

Definition at line 403 of file qxlibwindow.cpp.

Referenced by setWindowFlags().

404 {
405  Atom atomForMotifWmHints = QXlibStatic::atom(QXlibStatic::_MOTIF_WM_HINTS);
406  if (mwmhints.flags != 0l) {
407  XChangeProperty(mScreen->display()->nativeDisplay(), x_window,
408  atomForMotifWmHints, atomForMotifWmHints, 32,
409  PropModeReplace, (unsigned char *) &mwmhints, 5);
410  } else {
411  XDeleteProperty(mScreen->display()->nativeDisplay(), x_window, atomForMotifWmHints);
412  }
413 }
Display * nativeDisplay() const
static Atom atom(X11Atom atom)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QFactoryLoader * l
QXlibDisplay * display() const

◆ setParent()

void QXlibWindow::setParent ( const QPlatformWindow parent)
virtual

This function is called to enable native child widgets in QPA.

It is common not to support this feature in Window systems, but can be faked. When this function is called all geometry of this platform window will be relative to the parent.

Reimplemented from QPlatformWindow.

Definition at line 277 of file qxlibwindow.cpp.

278 {
279  QPoint topLeft = geometry().topLeft();
280  XReparentWindow(mScreen->display()->nativeDisplay(),x_window,window->winId(),topLeft.x(),topLeft.y());
281 }
virtual QRect geometry() const
Returnes the current geometry of a window.
Display * nativeDisplay() const
NSWindow * window
Window x_window
Definition: qxlibwindow.h:139
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QXlibDisplay * display() const
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ setVisible()

void QXlibWindow::setVisible ( bool  visible)
virtual

Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.

Reimplemented from QPlatformWindow.

Definition at line 637 of file qxlibwindow.cpp.

638 {
639 #ifdef MYX11_DEBUG
640  qDebug() << "QTestLiteWindow::setVisible" << visible << hex << x_window;
641 #endif
642  if (isTransient(widget())) {
643  Window parentXWindow = x_window;
644  if (widget()->parentWidget()) {
645  QWidget *widgetParent = widget()->parentWidget()->window();
646  if (widgetParent && widgetParent->platformWindow()) {
647  QXlibWindow *parentWidnow = static_cast<QXlibWindow *>(widgetParent->platformWindow());
648  parentXWindow = parentWidnow->x_window;
649  }
650  }
651  XSetTransientForHint(mScreen->display()->nativeDisplay(),x_window,parentXWindow);
652  }
653 
654  if (visible) {
655  //ensure that the window is viewed in correct position.
656  doSizeHints();
657  XMapWindow(mScreen->display()->nativeDisplay(), x_window);
658  } else {
659  XUnmapWindow(mScreen->display()->nativeDisplay(), x_window);
660  }
661 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
static bool isTransient(const QWidget *w)
Display * nativeDisplay() const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
static QWidget * parentWidget(const QWidget *w)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
void doSizeHints()
QXlibDisplay * display() const
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ setWindowFlags()

Qt::WindowFlags QXlibWindow::setWindowFlags ( Qt::WindowFlags  flags)
virtual

Requests setting the window flags of this surface to type.

Returns the actual flags set.

Reimplemented from QPlatformWindow.

Definition at line 464 of file qxlibwindow.cpp.

465 {
466 // Q_ASSERT(flags & Qt::Window);
467  mWindowFlags = flags;
468 
469 #ifdef MYX11_DEBUG
470  qDebug() << "QTestLiteWindow::setWindowFlags" << hex << x_window << "flags" << flags;
471 #endif
472  Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
473 
474  if (type == Qt::ToolTip)
476  if (type == Qt::Popup)
478 
479  bool topLevel = (flags & Qt::Window);
480  bool popup = (type == Qt::Popup);
481  bool dialog = (type == Qt::Dialog
482  || type == Qt::Sheet);
483  bool desktop = (type == Qt::Desktop);
484  bool tool = (type == Qt::Tool || type == Qt::SplashScreen
485  || type == Qt::ToolTip || type == Qt::Drawer);
486 
487  Q_UNUSED(topLevel);
488  Q_UNUSED(dialog);
489  Q_UNUSED(desktop);
490 
491  bool tooltip = (type == Qt::ToolTip);
492 
493  XSetWindowAttributes wsa;
494 
495  QXlibMWMHints mwmhints;
496  mwmhints.flags = 0L;
497  mwmhints.functions = 0L;
498  mwmhints.decorations = 0;
499  mwmhints.input_mode = 0L;
500  mwmhints.status = 0L;
501 
502 
503  ulong wsa_mask = 0;
504  if (type != Qt::SplashScreen) { // && customize) {
505  mwmhints.flags |= MWM_HINTS_DECORATIONS;
506 
507  bool customize = flags & Qt::CustomizeWindowHint;
508  if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
509  mwmhints.decorations |= MWM_DECOR_BORDER;
510  mwmhints.decorations |= MWM_DECOR_RESIZEH;
511 
512  if (flags & Qt::WindowTitleHint)
513  mwmhints.decorations |= MWM_DECOR_TITLE;
514 
515  if (flags & Qt::WindowSystemMenuHint)
516  mwmhints.decorations |= MWM_DECOR_MENU;
517 
518  if (flags & Qt::WindowMinimizeButtonHint) {
519  mwmhints.decorations |= MWM_DECOR_MINIMIZE;
520  mwmhints.functions |= MWM_FUNC_MINIMIZE;
521  }
522 
523  if (flags & Qt::WindowMaximizeButtonHint) {
524  mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
525  mwmhints.functions |= MWM_FUNC_MAXIMIZE;
526  }
527 
528  if (flags & Qt::WindowCloseButtonHint)
529  mwmhints.functions |= MWM_FUNC_CLOSE;
530  }
531  } else {
532  // if type == Qt::SplashScreen
533  mwmhints.decorations = MWM_DECOR_ALL;
534  }
535 
536  if (tool) {
537  wsa.save_under = True;
538  wsa_mask |= CWSaveUnder;
539  }
540 
541  if (flags & Qt::X11BypassWindowManagerHint) {
542  wsa.override_redirect = True;
543  wsa_mask |= CWOverrideRedirect;
544  }
545 #if 0
546  if (wsa_mask && initializeWindow) {
547  Q_ASSERT(id);
548  XChangeWindowAttributes(dpy, id, wsa_mask, &wsa);
549  }
550 #endif
551  if (mwmhints.functions != 0) {
552  mwmhints.flags |= MWM_HINTS_FUNCTIONS;
554  } else {
555  mwmhints.functions = MWM_FUNC_ALL;
556  }
557 
558  if (!(flags & Qt::FramelessWindowHint)
559  && flags & Qt::CustomizeWindowHint
560  && flags & Qt::WindowTitleHint
561  && !(flags &
562  (Qt::WindowMinimizeButtonHint
565  // a special case - only the titlebar without any button
566  mwmhints.flags = MWM_HINTS_FUNCTIONS;
568  mwmhints.decorations = 0;
569  }
570 
571  if (widget()->windowModality() == Qt::WindowModal) {
573  } else if (widget()->windowModality() == Qt::ApplicationModal) {
575  }
576 
577  setMWMHints(mwmhints);
578 
579  QVector<Atom> netWmState = getNetWmState();
580 
581  if (flags & Qt::WindowStaysOnTopHint) {
582  if (flags & Qt::WindowStaysOnBottomHint)
583  qWarning() << "QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time";
588  } else if (flags & Qt::WindowStaysOnBottomHint) {
591  }
592  if (widget()->isFullScreen()) {
595  }
596  if (widget()->isMaximized()) {
601  }
602  if (widget()->windowModality() != Qt::NonModal) {
605  }
606 
607  if (!netWmState.isEmpty()) {
608  XChangeProperty(mScreen->display()->nativeDisplay(), x_window,
609  QXlibStatic::atom(QXlibStatic::_NET_WM_STATE), XA_ATOM, 32, PropModeReplace,
610  (unsigned char *) netWmState.data(), netWmState.size());
611  } else {
613  }
614 
615 //##### only if initializeWindow???
616 
617  if (popup || tooltip) { // popup widget
618 #ifdef MYX11_DEBUG
619  qDebug() << "Doing XChangeWindowAttributes for popup" << wsa.override_redirect;
620 #endif
621  // set EWMH window types
622  // setNetWmWindowTypes();
623 
624  wsa.override_redirect = True;
625  wsa.save_under = True;
626  XChangeWindowAttributes(mScreen->display()->nativeDisplay(), x_window, CWOverrideRedirect | CWSaveUnder,
627  &wsa);
628  } else {
629 #ifdef MYX11_DEBUG
630  qDebug() << "Doing XChangeWindowAttributes for non-popup";
631 #endif
632  }
633 
634  return flags;
635 }
int type
Definition: qmetatype.cpp:239
void setMWMHints(const QXlibMWMHints &mwmhints)
Display * nativeDisplay() const
WindowType
Definition: qnamespace.h:270
ulong decorations
Definition: qxlibwindow.h:54
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
ulong functions
Definition: qxlibwindow.h:54
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::WindowFlags mWindowFlags
Definition: qxlibwindow.h:150
unsigned long ulong
Definition: qglobal.h:997
static Atom atom(X11Atom atom)
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QVector< Atom > getNetWmState() const
QXlibDisplay * display() const
#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
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QWidget * widget() const
Returnes the widget which belongs to the QPlatformWindow.

◆ setWindowTitle()

void QXlibWindow::setWindowTitle ( const QString title)
virtual

Reimplement to set the window title to title.

Reimplemented from QPlatformWindow.

Definition at line 293 of file qxlibwindow.cpp.

294 {
295  QByteArray ba = title.toLatin1(); //We're not making a general solution here...
296  XTextProperty windowName;
297  windowName.value = (unsigned char *)ba.constData();
298  windowName.encoding = XA_STRING;
299  windowName.format = 8;
300  windowName.nitems = ba.length();
301 
302  XSetWMName(mScreen->display()->nativeDisplay(), x_window, &windowName);
303 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Display * nativeDisplay() const
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Window x_window
Definition: qxlibwindow.h:139
QXlibScreen * mScreen
Definition: qxlibwindow.h:149
QXlibDisplay * display() const

◆ visual()

Visual* QXlibWindow::visual ( ) const
inline

Definition at line 127 of file qxlibwindow.h.

Referenced by QXlibWindowSurface::flush(), and QXlibWindowSurface::resizeShmImage().

127 { return mVisual; }
Visual * mVisual
Definition: qxlibwindow.h:144

◆ windowFlags()

Qt::WindowFlags QXlibWindow::windowFlags ( ) const
virtual

Returns the effective window flags for this surface.

Reimplemented from QPlatformWindow.

Definition at line 267 of file qxlibwindow.cpp.

268 {
269  return mWindowFlags;
270 }
Qt::WindowFlags mWindowFlags
Definition: qxlibwindow.h:150

◆ winId()

WId QXlibWindow::winId ( ) const
virtual

Reimplement in subclasses to return a handle to the native window.

Reimplemented from QPlatformWindow.

Definition at line 272 of file qxlibwindow.cpp.

273 {
274  return x_window;
275 }
Window x_window
Definition: qxlibwindow.h:139

◆ xWindow()

Window QXlibWindow::xWindow ( ) const

Definition at line 697 of file qxlibwindow.cpp.

Referenced by QXlibWindowSurface::flush().

698 {
699  return x_window;
700 }
Window x_window
Definition: qxlibwindow.h:139

Properties

◆ gc

GC QXlibWindow::gc
private

Definition at line 140 of file qxlibwindow.h.

Referenced by createGC(), graphicsContext(), QXlibWindow(), and ~QXlibWindow().

◆ mDepth

uint QXlibWindow::mDepth
private

Definition at line 142 of file qxlibwindow.h.

Referenced by QXlibWindow().

◆ mFormat

QImage::Format QXlibWindow::mFormat
private

Definition at line 143 of file qxlibwindow.h.

Referenced by QXlibWindow().

◆ mGLContext

QPlatformGLContext* QXlibWindow::mGLContext
private

Definition at line 148 of file qxlibwindow.h.

Referenced by glContext(), and ~QXlibWindow().

◆ mScreen

QXlibScreen* QXlibWindow::mScreen
private

◆ mVisual

Visual* QXlibWindow::mVisual
private

Definition at line 144 of file qxlibwindow.h.

Referenced by QXlibWindow().

◆ mWindowFlags

Qt::WindowFlags QXlibWindow::mWindowFlags
private

Definition at line 150 of file qxlibwindow.h.

Referenced by setWindowFlags(), and windowFlags().

◆ x_window

Window QXlibWindow::x_window
private

The documentation for this class was generated from the following files: