1/*
2 SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef KSELECTIONWATCHER_H
8#define KSELECTIONWATCHER_H
9
10#include <QObject>
11#include <kwindowsystem_export.h>
12
13#include <xcb/xcb.h>
14#include <xcb/xproto.h>
15
16/*!
17 \class KSelectionWatcher
18 \inmodule KWindowSystem
19
20 \brief ICCCM manager selection watching.
21
22 This class implements watching manager selections, as described in the ICCCM
23 section 2.8. It emits signal newOwner() when a new owner claim the selection,
24 and emits lostOwner() when the selection ownership is given up. To find
25 out current owner of the selection, owner() can be used.
26
27 This class is only useful on the xcb platform. On other platforms the code is only
28 functional if the constructor overloads taking an xcb_connection_t are used. In case
29 you inherit from this class ensure that you don't use xcb and/or XLib without verifying
30 the platform.
31*/
32class KWINDOWSYSTEM_EXPORT KSelectionWatcher : public QObject
33{
34 Q_OBJECT
35public:
36 /*!
37 * This constructor initializes the object, but doesn't perform any
38 * operation on the selection.
39 *
40 * \a selection atom representing the manager selection
41 *
42 * \a screen X screen, or -1 for default
43 *
44 * \a parent parent object, or nullptr if there is none
45 */
46 explicit KSelectionWatcher(xcb_atom_t selection, int screen = -1, QObject *parent = nullptr);
47 /*!
48 * \overload
49 * This constructor accepts the selection name and creates the appropriate atom
50 * for it automatically.
51 *
52 * \a selection name of the manager selection
53 *
54 * \a screen X screen, or -1 for default
55 *
56 * \a parent parent object, or nullptr if there is none
57 */
58 explicit KSelectionWatcher(const char *selection, int screen = -1, QObject *parent = nullptr);
59 /*!
60 * \overload
61 * This constructor accepts the xcb_connection_t and root window and doesn't depend on
62 * running on the xcb platform. Otherwise this constructor behaves like the similar one
63 * without the xcb_connection_t.
64 *
65 * \a selection atom representing the manager selection
66 *
67 * \a c the xcb connection this KSelectionWatcher should use
68 *
69 * \a root the root window this KSelectionWatcher should use
70 *
71 * \since 5.8
72 **/
73 explicit KSelectionWatcher(xcb_atom_t selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr);
74 /*!
75 * \overload
76 * This constructor accepts the xcb_connection_t and root window and doesn't depend on
77 * running on the xcb platform. Otherwise this constructor behaves like the similar one
78 * without the xcb_connection_t.
79 *
80 * \a selection name of the manager selection
81 *
82 * \a c the xcb connection this KSelectionWatcher should use
83 *
84 * \a root the root window this KSelectionWatcher should use
85 *
86 * \since 5.8
87 **/
88 explicit KSelectionWatcher(const char *selection, xcb_connection_t *c, xcb_window_t root, QObject *parent = nullptr);
89 ~KSelectionWatcher() override;
90 /*!
91 * Return the current owner of the manager selection, if any. Note that if the event
92 * informing about the owner change is still in the input queue, newOwner() might
93 * have been emitted yet.
94 */
95 xcb_window_t owner();
96 void filterEvent(void *ev_P); // internal
97Q_SIGNALS:
98 /*!
99 * This signal is emitted when the selection is successfully claimed by a new
100 * owner.
101 *
102 * \a owner the new owner of the selection
103 */
104 void newOwner(xcb_window_t owner);
105 /*!
106 * This signal is emitted when the selection is given up, i.e. there's no
107 * owner. Note that the selection may be immediately claimed again,
108 * so the newOwner() signal may be emitted right after this one.
109 * It's safe to delete the instance in a slot connected to this signal.
110 */
111 void lostOwner();
112
113private:
114 void init();
115
116 class Private;
117 Private *const d;
118};
119
120Q_DECLARE_METATYPE(xcb_window_t)
121
122#endif
123

source code of kwindowsystem/src/platforms/xcb/kselectionwatcher.h