File indexing completed on 2024-04-28 03:59:24
0001 /* 0002 SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KSELECTIONWATCHER_H 0008 #define KSELECTIONWATCHER_H 0009 0010 #include <QObject> 0011 #include <kwindowsystem_export.h> 0012 0013 #include <xcb/xcb.h> 0014 #include <xcb/xproto.h> 0015 0016 /** 0017 This class implements watching manager selections, as described in the ICCCM 0018 section 2.8. It emits signal newOwner() when a new owner claim the selection, 0019 and emits lostOwner() when the selection ownership is given up. To find 0020 out current owner of the selection, owner() can be used. 0021 @short ICCCM manager selection watching 0022 0023 This class is only useful on the xcb platform. On other platforms the code is only 0024 functional if the constructor overloads taking an xcb_connection_t are used. In case 0025 you inherit from this class ensure that you don't use xcb and/or XLib without verifying 0026 the platform. 0027 */ 0028 class KWINDOWSYSTEM_EXPORT KSelectionWatcher : public QObject 0029 { 0030 Q_OBJECT 0031 public: 0032 /** 0033 * This constructor initializes the object, but doesn't perform any 0034 * operation on the selection. 0035 * 0036 * @param selection atom representing the manager selection 0037 * @param screen X screen, or -1 for default 0038 * @param parent parent object, or nullptr if there is none 0039 */ 0040 explicit KSelectionWatcher(xcb_atom_t selection, int screen = -1, QObject *parent = nullptr); 0041 /** 0042 * @overload 0043 * This constructor accepts the selection name and creates the appropriate atom 0044 * for it automatically. 0045 * 0046 * @param selection name of the manager selection 0047 * @param screen X screen, or -1 for default 0048 * @param parent parent object, or nullptr if there is none 0049 */ 0050 explicit KSelectionWatcher(const char *selection, int screen = -1, QObject *parent = nullptr); 0051 /** 0052 * @overload 0053 * This constructor accepts the xcb_connection_t and root window and doesn't depend on 0054 * running on the xcb platform. Otherwise this constructor behaves like the similar one 0055 * without the xcb_connection_t. 0056 * 0057 * @param selection atom representing the manager selection 0058 * @param c the xcb connection this KSelectionWatcher should use 0059 * @param root the root window this KSelectionWatcher should use 0060 * @since 5.8 0061 **/ 0062 explicit KSelectionWatcher(xcb_atom_t selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr); 0063 /** 0064 * @overload 0065 * This constructor accepts the xcb_connection_t and root window and doesn't depend on 0066 * running on the xcb platform. Otherwise this constructor behaves like the similar one 0067 * without the xcb_connection_t. 0068 * 0069 * @param selection name of the manager selection 0070 * @param c the xcb connection this KSelectionWatcher should use 0071 * @param root the root window this KSelectionWatcher should use 0072 * @since 5.8 0073 **/ 0074 explicit KSelectionWatcher(const char *selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr); 0075 ~KSelectionWatcher() override; 0076 /** 0077 * Return the current owner of the manager selection, if any. Note that if the event 0078 * informing about the owner change is still in the input queue, newOwner() might 0079 * have been emitted yet. 0080 */ 0081 xcb_window_t owner(); 0082 /** 0083 * @internal 0084 */ 0085 void filterEvent(void *ev_P); // internal 0086 Q_SIGNALS: 0087 /** 0088 * This signal is emitted when the selection is successfully claimed by a new 0089 * owner. 0090 * @param owner the new owner of the selection 0091 */ 0092 void newOwner(xcb_window_t owner); 0093 /** 0094 * This signal is emitted when the selection is given up, i.e. there's no 0095 * owner. Note that the selection may be immediately claimed again, 0096 * so the newOwner() signal may be emitted right after this one. 0097 * It's safe to delete the instance in a slot connected to this signal. 0098 */ 0099 void lostOwner(); 0100 0101 private: 0102 void init(); 0103 0104 class Private; 0105 Private *const d; 0106 }; 0107 0108 Q_DECLARE_METATYPE(xcb_window_t) 0109 0110 #endif