| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 |
|
| 5 |
#ifndef QXCBWINDOW_H |
| 6 |
#define QXCBWINDOW_H |
| 7 |
|
| 8 |
#include <qpa/qplatformwindow.h> |
| 9 |
#include <QtGui/QSurfaceFormat> |
| 10 |
#include <QtGui/QImage> |
| 11 |
|
| 12 |
#include <xcb/xcb.h> |
| 13 |
#include <xcb/sync.h> |
| 14 |
|
| 15 |
#include "qxcbobject.h" |
| 16 |
|
| 17 |
#include <QtPlatformHeaders/qxcbwindowfunctions.h> |
| 18 |
|
| 19 |
QT_BEGIN_NAMESPACE |
| 20 |
|
| 21 |
class QXcbScreen; |
| 22 |
class QXcbSyncWindowRequest; |
| 23 |
class QIcon; |
| 24 |
|
| 25 |
class Q_XCB_EXPORT QXcbWindow : public QXcbObject, public QXcbWindowEventListener, public QPlatformWindow |
| 26 |
{ |
| 27 |
public: |
| 28 |
enum NetWmState { |
| 29 |
NetWmStateAbove = 0x1, |
| 30 |
NetWmStateBelow = 0x2, |
| 31 |
NetWmStateFullScreen = 0x4, |
| 32 |
NetWmStateMaximizedHorz = 0x8, |
| 33 |
NetWmStateMaximizedVert = 0x10, |
| 34 |
NetWmStateModal = 0x20, |
| 35 |
NetWmStateStaysOnTop = 0x40, |
| 36 |
NetWmStateDemandsAttention = 0x80 |
| 37 |
}; |
| 38 |
|
| 39 |
Q_DECLARE_FLAGS(NetWmStates, NetWmState) |
| 40 |
|
| 41 |
QXcbWindow(QWindow *window); |
| 42 |
~QXcbWindow(); |
| 43 |
|
| 44 |
void setGeometry(const QRect &rect) Q_DECL_OVERRIDE; |
| 45 |
|
| 46 |
QMargins frameMargins() const Q_DECL_OVERRIDE; |
| 47 |
|
| 48 |
void setVisible(bool visible) Q_DECL_OVERRIDE; |
| 49 |
void setWindowFlags(Qt::WindowFlags flags) Q_DECL_OVERRIDE; |
| 50 |
void setWindowState(Qt::WindowState state) Q_DECL_OVERRIDE; |
| 51 |
WId winId() const Q_DECL_OVERRIDE; |
| 52 |
void setParent(const QPlatformWindow *window) Q_DECL_OVERRIDE; |
| 53 |
|
| 54 |
bool isExposed() const Q_DECL_OVERRIDE; |
| 55 |
bool isEmbedded(const QPlatformWindow *parentWindow = 0) const Q_DECL_OVERRIDE; |
| 56 |
QPoint mapToGlobal(const QPoint &pos) const Q_DECL_OVERRIDE; |
| 57 |
QPoint mapFromGlobal(const QPoint &pos) const Q_DECL_OVERRIDE; |
| 58 |
|
| 59 |
void setWindowTitle(const QString &title) Q_DECL_OVERRIDE; |
| 60 |
void setWindowIconText(const QString &title); |
| 61 |
void setWindowIcon(const QIcon &icon) Q_DECL_OVERRIDE; |
| 62 |
void raise() Q_DECL_OVERRIDE; |
| 63 |
void lower() Q_DECL_OVERRIDE; |
| 64 |
void propagateSizeHints() Q_DECL_OVERRIDE; |
| 65 |
|
| 66 |
void requestActivateWindow() Q_DECL_OVERRIDE; |
| 67 |
|
| 68 |
bool setKeyboardGrabEnabled(bool grab) Q_DECL_OVERRIDE; |
| 69 |
bool setMouseGrabEnabled(bool grab) Q_DECL_OVERRIDE; |
| 70 |
|
| 71 |
void setCursor(xcb_cursor_t cursor, bool isBitmapCursor); |
| 72 |
|
| 73 |
QSurfaceFormat format() const Q_DECL_OVERRIDE; |
| 74 |
|
| 75 |
void windowEvent(QEvent *event) Q_DECL_OVERRIDE; |
| 76 |
|
| 77 |
bool startSystemResize(const QPoint &pos, Qt::Corner corner) Q_DECL_OVERRIDE; |
| 78 |
|
| 79 |
void setOpacity(qreal level) Q_DECL_OVERRIDE; |
| 80 |
void setMask(const QRegion ®ion) Q_DECL_OVERRIDE; |
| 81 |
|
| 82 |
void setAlertState(bool enabled) Q_DECL_OVERRIDE; |
| 83 |
bool isAlertState() const Q_DECL_OVERRIDE { return m_alertState; } |
| 84 |
|
| 85 |
xcb_window_t xcb_window() const { return m_window; } |
| 86 |
uint depth() const { return m_depth; } |
| 87 |
QImage::Format imageFormat() const { return m_imageFormat; } |
| 88 |
bool imageNeedsRgbSwap() const { return m_imageRgbSwap; } |
| 89 |
|
| 90 |
bool handleGenericEvent(xcb_generic_event_t *event, long *result) Q_DECL_OVERRIDE; |
| 91 |
|
| 92 |
void handleExposeEvent(const xcb_expose_event_t *event) Q_DECL_OVERRIDE; |
| 93 |
void handleClientMessageEvent(const xcb_client_message_event_t *event) Q_DECL_OVERRIDE; |
| 94 |
void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) Q_DECL_OVERRIDE; |
| 95 |
void handleMapNotifyEvent(const xcb_map_notify_event_t *event) Q_DECL_OVERRIDE; |
| 96 |
void handleUnmapNotifyEvent(const xcb_unmap_notify_event_t *event) Q_DECL_OVERRIDE; |
| 97 |
void handleButtonPressEvent(const xcb_button_press_event_t *event) Q_DECL_OVERRIDE; |
| 98 |
void handleButtonReleaseEvent(const xcb_button_release_event_t *event) Q_DECL_OVERRIDE; |
| 99 |
void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event) Q_DECL_OVERRIDE; |
| 100 |
|
| 101 |
void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) Q_DECL_OVERRIDE; |
| 102 |
void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event) Q_DECL_OVERRIDE; |
| 103 |
void handleFocusInEvent(const xcb_focus_in_event_t *event) Q_DECL_OVERRIDE; |
| 104 |
void handleFocusOutEvent(const xcb_focus_out_event_t *event) Q_DECL_OVERRIDE; |
| 105 |
void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) Q_DECL_OVERRIDE; |
| 106 |
#ifdef XCB_USE_XINPUT22 |
| 107 |
void handleXIMouseButtonState(const xcb_ge_event_t *); |
| 108 |
void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) Q_DECL_OVERRIDE; |
| 109 |
void handleXIEnterLeave(xcb_ge_event_t *) Q_DECL_OVERRIDE; |
| 110 |
#endif |
| 111 |
|
| 112 |
QXcbWindow *toWindow() Q_DECL_OVERRIDE; |
| 113 |
|
| 114 |
void handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global, |
| 115 |
Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source); |
| 116 |
|
| 117 |
void updateNetWmUserTime(xcb_timestamp_t timestamp); |
| 118 |
|
| 119 |
static void setWmWindowTypeStatic(QWindow *window, QXcbWindowFunctions::WmWindowTypes windowTypes); |
| 120 |
static void setWmWindowRoleStatic(QWindow *window, const QByteArray &role); |
| 121 |
static uint visualIdStatic(QWindow *window); |
| 122 |
|
| 123 |
QXcbWindowFunctions::WmWindowTypes wmWindowTypes() const; |
| 124 |
void setWmWindowType(QXcbWindowFunctions::WmWindowTypes types, Qt::WindowFlags flags); |
| 125 |
void setWmWindowRole(const QByteArray &role); |
| 126 |
|
| 127 |
static void setWindowIconTextStatic(QWindow *window, const QString &text); |
| 128 |
|
| 129 |
static void setParentRelativeBackPixmapStatic(QWindow *window); |
| 130 |
void setParentRelativeBackPixmap(); |
| 131 |
|
| 132 |
static bool requestSystemTrayWindowDockStatic(const QWindow *window); |
| 133 |
bool requestSystemTrayWindowDock() const; |
| 134 |
|
| 135 |
static QRect systemTrayWindowGlobalGeometryStatic(const QWindow *window); |
| 136 |
QRect systemTrayWindowGlobalGeometry() const; |
| 137 |
uint visualId() const; |
| 138 |
|
| 139 |
bool needsSync() const; |
| 140 |
|
| 141 |
void postSyncWindowRequest(); |
| 142 |
void clearSyncWindowRequest() { m_pendingSyncRequest = 0; } |
| 143 |
|
| 144 |
QXcbScreen *xcbScreen() const; |
| 145 |
|
| 146 |
virtual void create(); |
| 147 |
virtual void destroy(); |
| 148 |
|
| 149 |
public Q_SLOTS: |
| 150 |
void updateSyncRequestCounter(); |
| 151 |
|
| 152 |
protected: |
| 153 |
virtual void resolveFormat(const QSurfaceFormat &format) { m_format = format; } |
| 154 |
virtual const xcb_visualtype_t *createVisual(); |
| 155 |
|
| 156 |
QXcbScreen *parentScreen(); |
| 157 |
|
| 158 |
void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0); |
| 159 |
NetWmStates netWmStates(); |
| 160 |
void setNetWmStates(NetWmStates); |
| 161 |
|
| 162 |
void setMotifWindowFlags(Qt::WindowFlags flags); |
| 163 |
void setNetWmStateWindowFlags(Qt::WindowFlags flags); |
| 164 |
|
| 165 |
void updateMotifWmHintsBeforeMap(); |
| 166 |
void updateNetWmStateBeforeMap(); |
| 167 |
|
| 168 |
void setTransparentForMouseEvents(bool transparent); |
| 169 |
void updateDoesNotAcceptFocus(bool doesNotAcceptFocus); |
| 170 |
|
| 171 |
QRect windowToWmGeometry(QRect r) const; |
| 172 |
void sendXEmbedMessage(xcb_window_t window, quint32 message, |
| 173 |
quint32 detail = 0, quint32 data1 = 0, quint32 data2 = 0); |
| 174 |
void handleXEmbedMessage(const xcb_client_message_event_t *event); |
| 175 |
|
| 176 |
void show(); |
| 177 |
void hide(); |
| 178 |
|
| 179 |
bool relayFocusToModalWindow() const; |
| 180 |
void doFocusIn(); |
| 181 |
void doFocusOut(); |
| 182 |
|
| 183 |
bool compressExposeEvent(QRegion &exposeRegion); |
| 184 |
|
| 185 |
void handleButtonPressEvent(int event_x, int event_y, int root_x, int root_y, |
| 186 |
int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
| 187 |
|
| 188 |
void handleButtonReleaseEvent(int event_x, int event_y, int root_x, int root_y, |
| 189 |
int detail, Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
| 190 |
|
| 191 |
void handleMotionNotifyEvent(int event_x, int event_y, int root_x, int root_y, |
| 192 |
Qt::KeyboardModifiers modifiers, xcb_timestamp_t timestamp, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized); |
| 193 |
|
| 194 |
void handleEnterNotifyEvent(int event_x, int event_y, int root_x, int root_y, |
| 195 |
quint8 mode, quint8 detail, xcb_timestamp_t timestamp); |
| 196 |
|
| 197 |
void handleLeaveNotifyEvent(int root_x, int root_y, |
| 198 |
quint8 mode, quint8 detail, xcb_timestamp_t timestamp); |
| 199 |
|
| 200 |
xcb_window_t m_window; |
| 201 |
|
| 202 |
uint m_depth; |
| 203 |
QImage::Format m_imageFormat; |
| 204 |
bool m_imageRgbSwap; |
| 205 |
|
| 206 |
xcb_sync_int64_t m_syncValue; |
| 207 |
xcb_sync_counter_t m_syncCounter; |
| 208 |
|
| 209 |
Qt::WindowState m_windowState; |
| 210 |
|
| 211 |
xcb_gravity_t m_gravity; |
| 212 |
|
| 213 |
bool m_mapped; |
| 214 |
bool m_transparent; |
| 215 |
bool m_usingSyncProtocol; |
| 216 |
bool m_deferredActivation; |
| 217 |
bool m_embedded; |
| 218 |
bool m_alertState; |
| 219 |
xcb_window_t m_netWmUserTimeWindow; |
| 220 |
|
| 221 |
QSurfaceFormat m_format; |
| 222 |
|
| 223 |
mutable bool m_dirtyFrameMargins; |
| 224 |
mutable QMargins m_frameMargins; |
| 225 |
|
| 226 |
QRegion m_exposeRegion; |
| 227 |
QSize m_oldWindowSize; |
| 228 |
|
| 229 |
xcb_visualid_t m_visualId; |
| 230 |
int m_lastWindowStateEvent; |
| 231 |
|
| 232 |
enum SyncState { |
| 233 |
NoSyncNeeded, |
| 234 |
SyncReceived, |
| 235 |
SyncAndConfigureReceived |
| 236 |
}; |
| 237 |
SyncState m_syncState; |
| 238 |
|
| 239 |
QXcbSyncWindowRequest *m_pendingSyncRequest; |
| 240 |
xcb_cursor_t m_currentBitmapCursor; |
| 241 |
}; |
| 242 |
|
| 243 |
QT_END_NAMESPACE |
| 244 |
|
| 245 |
Q_DECLARE_METATYPE(QXcbWindow*) |
| 246 |
|
| 247 |
#endif |