KWin
Loading...
Searching...
No Matches
selection_source.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
16class QSocketNotifier;
17
18struct xcb_selection_request_event_t;
19struct xcb_xfixes_selection_notify_event_t;
20
21namespace KWin
22{
23class DataDeviceInterface;
24class DataSourceInterface;
25class AbstractDataSource;
26
27namespace Xwl
28{
29class Selection;
30
34class SelectionSource : public QObject
35{
36 Q_OBJECT
37
38public:
40
41 xcb_timestamp_t timestamp() const
42 {
43 return m_timestamp;
44 }
45 void setTimestamp(xcb_timestamp_t time)
46 {
47 m_timestamp = time;
48 }
49
50protected:
52 {
53 return m_selection;
54 }
55 void setWindow(xcb_window_t window)
56 {
57 m_window = window;
58 }
59 xcb_window_t window() const
60 {
61 return m_window;
62 }
63
64private:
65 xcb_timestamp_t m_timestamp = XCB_CURRENT_TIME;
66 Selection *m_selection;
67 xcb_window_t m_window;
68
69 Q_DISABLE_COPY(SelectionSource)
70};
71
76{
77 Q_OBJECT
78
79public:
82
83 bool handleSelectionRequest(xcb_selection_request_event_t *event);
84 void sendTargets(xcb_selection_request_event_t *event);
85 void sendTimestamp(xcb_selection_request_event_t *event);
86
87 void receiveOffer(const QString &mime);
88 void sendSelectionNotify(xcb_selection_request_event_t *event, bool success);
89
90Q_SIGNALS:
91 void transferReady(xcb_selection_request_event_t *event, qint32 fd);
92
93private:
94 bool checkStartTransfer(xcb_selection_request_event_t *event);
95
96 AbstractDataSource *m_dsi = nullptr;
97
98 QList<QString> m_offers;
99 QMetaObject::Connection m_offerConnection;
100
101 Q_DISABLE_COPY(WlSource)
102};
103
104using Mimes = QList<QPair<QString, xcb_atom_t>>;
105
110{
111 Q_OBJECT
112
113public:
114 X11Source(Selection *selection, xcb_xfixes_selection_notify_event_t *event);
115
116 void getTargets();
117
118 Mimes offers() const
119 {
120 return m_offers;
121 }
122 void setOffers(const Mimes &offers);
123
124 bool handleSelectionNotify(xcb_selection_notify_event_t *event);
125
126 void setRequestor(xcb_window_t window)
127 {
129 }
130
131 void startTransfer(const QString &mimeName, qint32 fd);
132Q_SIGNALS:
133 void offersChanged(const QStringList &added, const QStringList &removed);
134 void transferReady(xcb_atom_t target, qint32 fd);
135
136private:
137 void handleTargets();
138
139 Mimes m_offers;
140
141 Q_DISABLE_COPY(X11Source)
142};
143
144} // namespace Xwl
145} // namespace KWin
The AbstractDataSource class abstracts the data that can be transferred to another client.
xcb_timestamp_t timestamp() const
SelectionSource(Selection *selection)
void setWindow(xcb_window_t window)
void setTimestamp(xcb_timestamp_t time)
xcb_window_t window() const
Selection * selection() const
WlSource(Selection *selection)
bool handleSelectionRequest(xcb_selection_request_event_t *event)
void sendTargets(xcb_selection_request_event_t *event)
void transferReady(xcb_selection_request_event_t *event, qint32 fd)
void sendSelectionNotify(xcb_selection_request_event_t *event, bool success)
void receiveOffer(const QString &mime)
void sendTimestamp(xcb_selection_request_event_t *event)
void setDataSourceIface(AbstractDataSource *dsi)
bool handleSelectionNotify(xcb_selection_notify_event_t *event)
void offersChanged(const QStringList &added, const QStringList &removed)
X11Source(Selection *selection, xcb_xfixes_selection_notify_event_t *event)
void transferReady(xcb_atom_t target, qint32 fd)
void startTransfer(const QString &mimeName, qint32 fd)
void setRequestor(xcb_window_t window)
void setOffers(const Mimes &offers)
QList< QPair< QString, xcb_atom_t > > Mimes
Definition drag_x.h:31