Changeset View
Changeset View
Standalone View
Standalone View
xwl/databridge.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #include "databridge.h" | ||||
21 | #include "xwayland.h" | ||||
22 | #include "selection.h" | ||||
23 | #include "clipboard.h" | ||||
24 | | ||||
25 | #include "atoms.h" | ||||
26 | #include "wayland_server.h" | ||||
27 | #include "workspace.h" | ||||
28 | #include "abstract_client.h" | ||||
29 | | ||||
30 | // KWayland | ||||
31 | #include <KWayland/Client/seat.h> | ||||
32 | #include <KWayland/Client/datadevicemanager.h> | ||||
33 | | ||||
34 | #include <KWayland/Server/seat_interface.h> | ||||
35 | #include <KWayland/Server/datadevicemanager_interface.h> | ||||
36 | #include <KWayland/Server/datadevice_interface.h> | ||||
37 | | ||||
38 | namespace KWin { | ||||
39 | namespace Xwl { | ||||
40 | | ||||
41 | static DataBridge *s_self = nullptr; | ||||
42 | DataBridge* DataBridge::self() | ||||
43 | { | ||||
44 | return s_self; | ||||
45 | } | ||||
46 | | ||||
47 | DataBridge::DataBridge(QObject *parent) | ||||
48 | : QObject(parent) | ||||
49 | { | ||||
50 | s_self = this; | ||||
51 | auto *ddm = waylandServer()->internalDataDeviceManager(); | ||||
52 | auto *seat = waylandServer()->internalSeat(); | ||||
53 | m_dd = ddm->getDataDevice(seat, this); | ||||
54 | waylandServer()->dispatch(); | ||||
55 | | ||||
56 | const auto *ddmi = waylandServer()->dataDeviceManager(); | ||||
57 | auto *dc = new QMetaObject::Connection(); | ||||
58 | *dc = connect(ddmi, &KWayland::Server::DataDeviceManagerInterface::dataDeviceCreated, this, | ||||
59 | [this, dc](KWayland::Server::DataDeviceInterface *ddi) { | ||||
60 | if (m_ddi || ddi->client() != waylandServer()->internalConnection()) { | ||||
61 | return; | ||||
62 | } | ||||
63 | QObject::disconnect(*dc); | ||||
64 | delete dc; | ||||
65 | m_ddi = ddi; | ||||
66 | init(); | ||||
67 | } | ||||
68 | ); | ||||
69 | } | ||||
70 | | ||||
71 | DataBridge::~DataBridge() | ||||
72 | { | ||||
73 | s_self = nullptr; | ||||
74 | } | ||||
75 | | ||||
76 | void DataBridge::init() | ||||
77 | { | ||||
78 | m_clipboard = new Clipboard(atoms->clipboard, this); | ||||
79 | waylandServer()->dispatch(); | ||||
80 | } | ||||
81 | | ||||
82 | bool DataBridge::filterEvent(xcb_generic_event_t *event) | ||||
83 | { | ||||
84 | if (m_clipboard->filterEvent(event)) { | ||||
85 | return true; | ||||
86 | } | ||||
87 | if (event->response_type - Xwayland::self()->xfixes()->first_event == XCB_XFIXES_SELECTION_NOTIFY) { | ||||
88 | return handleXfixesNotify((xcb_xfixes_selection_notify_event_t *)event); | ||||
89 | } | ||||
90 | return false; | ||||
91 | } | ||||
92 | | ||||
93 | bool DataBridge::handleXfixesNotify(xcb_xfixes_selection_notify_event_t *event) | ||||
94 | { | ||||
95 | auto getSelection = [this](xcb_atom_t atom) -> Selection* { | ||||
96 | if (atom == atoms->clipboard) { | ||||
97 | return m_clipboard; | ||||
98 | } | ||||
99 | return nullptr; | ||||
100 | }; | ||||
101 | auto *sel = getSelection(event->selection); | ||||
102 | return sel && sel->handleXfixesNotify(event); | ||||
zzag: The lambda is superfluous. | |||||
See D15627 romangg: See D15627 | |||||
zzag: What exactly is the issue? | |||||
103 | } | ||||
104 | | ||||
105 | } | ||||
106 | } |
The lambda is superfluous.