File indexing completed on 2024-05-05 17:45:24
0001 /* 0002 SPDX-FileCopyrightText: 2012, 2013 Martin Graesslin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2015 David Edmudson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <xcb/composite.h> 0011 #include <xcb/damage.h> 0012 #include <xcb/randr.h> 0013 #include <xcb/shm.h> 0014 #include <xcb/xcb.h> 0015 #include <xcb/xcb_atom.h> 0016 #include <xcb/xcb_event.h> 0017 0018 #include <QVector> 0019 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0020 #include <private/qtx11extras_p.h> 0021 #else 0022 #include <QX11Info> 0023 #endif 0024 0025 #include "../c_ptr.h" 0026 0027 /** XEMBED messages */ 0028 #define XEMBED_EMBEDDED_NOTIFY 0 0029 #define XEMBED_WINDOW_ACTIVATE 1 0030 #define XEMBED_WINDOW_DEACTIVATE 2 0031 #define XEMBED_REQUEST_FOCUS 3 0032 #define XEMBED_FOCUS_IN 4 0033 #define XEMBED_FOCUS_OUT 5 0034 #define XEMBED_FOCUS_NEXT 6 0035 #define XEMBED_FOCUS_PREV 7 0036 0037 namespace Xcb 0038 { 0039 typedef xcb_window_t WindowId; 0040 0041 class Atom 0042 { 0043 public: 0044 explicit Atom(const QByteArray &name, bool onlyIfExists = false, xcb_connection_t *c = QX11Info::connection()) 0045 : m_connection(c) 0046 , m_retrieved(false) 0047 , m_cookie(xcb_intern_atom_unchecked(m_connection, onlyIfExists, name.length(), name.constData())) 0048 , m_atom(XCB_ATOM_NONE) 0049 , m_name(name) 0050 { 0051 } 0052 Atom() = delete; 0053 Atom(const Atom &) = delete; 0054 0055 ~Atom() 0056 { 0057 if (!m_retrieved && m_cookie.sequence) { 0058 xcb_discard_reply(m_connection, m_cookie.sequence); 0059 } 0060 } 0061 0062 operator xcb_atom_t() const 0063 { 0064 (const_cast<Atom *>(this))->getReply(); 0065 return m_atom; 0066 } 0067 bool isValid() 0068 { 0069 getReply(); 0070 return m_atom != XCB_ATOM_NONE; 0071 } 0072 bool isValid() const 0073 { 0074 (const_cast<Atom *>(this))->getReply(); 0075 return m_atom != XCB_ATOM_NONE; 0076 } 0077 0078 inline const QByteArray &name() const 0079 { 0080 return m_name; 0081 } 0082 0083 private: 0084 void getReply() 0085 { 0086 if (m_retrieved || !m_cookie.sequence) { 0087 return; 0088 } 0089 UniqueCPointer<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr)); 0090 if (reply) { 0091 m_atom = reply->atom; 0092 } 0093 m_retrieved = true; 0094 } 0095 xcb_connection_t *m_connection; 0096 bool m_retrieved; 0097 xcb_intern_atom_cookie_t m_cookie; 0098 xcb_atom_t m_atom; 0099 QByteArray m_name; 0100 }; 0101 0102 class Atoms 0103 { 0104 public: 0105 Atoms() 0106 : xembedAtom("_XEMBED") 0107 , selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen())) 0108 , opcodeAtom("_NET_SYSTEM_TRAY_OPCODE") 0109 , messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA") 0110 , visualAtom("_NET_SYSTEM_TRAY_VISUAL") 0111 { 0112 } 0113 0114 Atom xembedAtom; 0115 Atom selectionAtom; 0116 Atom opcodeAtom; 0117 Atom messageData; 0118 Atom visualAtom; 0119 }; 0120 0121 extern Atoms *atoms; 0122 0123 } // namespace Xcb