KWin
Loading...
Searching...
No Matches
selection.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include <QList>
12#include <QObject>
13
14#include <xcb/xcb.h>
15
16struct xcb_xfixes_selection_notify_event_t;
17
18class QTimer;
19
20namespace KWin
21{
22namespace Xwl
23{
24class TransferWltoX;
25class TransferXtoWl;
26class WlSource;
27class X11Source;
28
44class Selection : public QObject
45{
46 Q_OBJECT
47
48public:
49 static xcb_atom_t mimeTypeToAtom(const QString &mimeType);
50 static xcb_atom_t mimeTypeToAtomLiteral(const QString &mimeType);
51 static QStringList atomToMimeTypes(xcb_atom_t atom);
52 static QString atomName(xcb_atom_t atom);
53 static void sendSelectionNotify(xcb_selection_request_event_t *event, bool success);
54
55 // on selection owner changes by X clients (Xwl -> Wl)
56 bool handleXfixesNotify(xcb_xfixes_selection_notify_event_t *event);
57 bool filterEvent(xcb_generic_event_t *event);
58
59 xcb_atom_t atom() const
60 {
61 return m_atom;
62 }
63 xcb_window_t window() const
64 {
65 return m_window;
66 }
67 void overwriteRequestorWindow(xcb_window_t window);
68
69Q_SIGNALS:
70 void transferFinished(xcb_timestamp_t eventTime);
71
72protected:
73 Selection(xcb_atom_t atom, QObject *parent);
74 void registerXfixes();
75
76 virtual void doHandleXfixesNotify(xcb_xfixes_selection_notify_event_t *event) = 0;
77 virtual void x11OfferLost() = 0;
78 virtual void x11OffersChanged(const QStringList &added, const QStringList &removed) = 0;
79
80 virtual bool handleClientMessage(xcb_client_message_event_t *event)
81 {
82 return false;
83 }
84 // sets the current provider of the selection
85 void setWlSource(WlSource *source);
87 {
88 return m_waylandSource;
89 }
90 void createX11Source(xcb_xfixes_selection_notify_event_t *event);
92 {
93 return m_xSource;
94 }
95 // must be called in order to provide data from Wl to X
96 void ownSelection(bool own);
97 void setWindow(xcb_window_t window)
98 {
99 m_window = window;
100 }
101
102private:
103 bool handleSelectionRequest(xcb_selection_request_event_t *event);
104 bool handleSelectionNotify(xcb_selection_notify_event_t *event);
105 bool handlePropertyNotify(xcb_property_notify_event_t *event);
106
107 void startTransferToWayland(xcb_atom_t target, qint32 fd);
108 void startTransferToX(xcb_selection_request_event_t *event, qint32 fd);
109
110 // Timeout transfers, which have become inactive due to client errors.
111 void timeoutTransfers();
112 void startTimeoutTransfersTimer();
113 void endTimeoutTransfersTimer();
114
115 xcb_atom_t m_atom = XCB_ATOM_NONE;
116 xcb_window_t m_window = XCB_WINDOW_NONE;
117 xcb_window_t m_requestorWindow = XCB_WINDOW_NONE;
118 xcb_timestamp_t m_timestamp;
119
120 // Active source, if any. Only one of them at max can exist
121 // at the same time.
122 WlSource *m_waylandSource = nullptr;
123 X11Source *m_xSource = nullptr;
124
125 // active transfers
126 QList<TransferWltoX *> m_wlToXTransfers;
127 QList<TransferXtoWl *> m_xToWlTransfers;
128 QTimer *m_timeoutTransfers = nullptr;
129
130 bool m_disownPending = false;
131
132 Q_DISABLE_COPY(Selection)
133};
134
135} // namespace Xwl
136} // namespace KWin
virtual void x11OffersChanged(const QStringList &added, const QStringList &removed)=0
xcb_atom_t atom() const
Definition selection.h:59
bool handleXfixesNotify(xcb_xfixes_selection_notify_event_t *event)
Definition selection.cpp:90
void overwriteRequestorWindow(xcb_window_t window)
static void sendSelectionNotify(xcb_selection_request_event_t *event, bool success)
void transferFinished(xcb_timestamp_t eventTime)
static QStringList atomToMimeTypes(xcb_atom_t atom)
Definition selection.cpp:63
void createX11Source(xcb_xfixes_selection_notify_event_t *event)
static QString atomName(xcb_atom_t atom)
Definition selection.cpp:48
Selection(xcb_atom_t atom, QObject *parent)
Definition selection.cpp:80
static xcb_atom_t mimeTypeToAtomLiteral(const QString &mimeType)
Definition selection.cpp:43
void setWlSource(WlSource *source)
void ownSelection(bool own)
xcb_window_t window() const
Definition selection.h:63
virtual void x11OfferLost()=0
void setWindow(xcb_window_t window)
Definition selection.h:97
WlSource * wlSource() const
Definition selection.h:86
virtual void doHandleXfixesNotify(xcb_xfixes_selection_notify_event_t *event)=0
virtual bool handleClientMessage(xcb_client_message_event_t *event)
Definition selection.h:80
X11Source * x11Source() const
Definition selection.h:91
static xcb_atom_t mimeTypeToAtom(const QString &mimeType)
Definition selection.cpp:29
bool filterEvent(xcb_generic_event_t *event)