Debian Codegraph @

panel/backends/wayland/wayfire/wayfire-common.h

raw
1 /* BEGIN_COMMON_COPYRIGHT_HEADER (c)LGPL2+
2 *
3 * LXQt - a lightweight, Qt based, desktop toolset https://lxqt.org
4 *
5 * Copyright: 2023 LXQt team Authors:
6 * Filippo Gentile <[email protected]>
7 *
8 * This program or library is free software; you can redistribute it and/or modify it under the terms of the
9 * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the
10 * License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License along with this library; if not,
17 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * END_COMMON_COPYRIGHT_HEADER */
20
21 #pragma once
22
23 /** For struct pollfd */
24 #include <poll.h>
25
26 /* For QString, QThread, QTimer, etc.. */
27 #include <QtCore>
28
29 #include "../../lxqttaskbartypes.h"
30
31 namespace LXQt
32 {
33 namespace Panel
34 {
35 class Wayfire;
36 class WayfireImpl;
37 }
38 }
39
40 // Strongly-typed wrapper for Wayland IDs
41 struct WaylandId
42 {
43 uint32_t id;
44 explicit WaylandId(uint32_t id_ = 0) : id(id_)
45 {}
46 operator WId() const
47 {
48 return static_cast<WId>(id);
49 }
50 };
51
52
53 class LXQt::Panel::WayfireImpl : public QThread
54 {
55 Q_OBJECT
56
57 public:
58 WayfireImpl(QObject *parent = nullptr);
59 ~WayfireImpl();
60
61 /** Stop polling This will terminate the thread and delete this object
62 */
63 void stop();
64
65 /** Request the compositor something */
66 uint32_t request(QJsonDocument req);
67
68 /** One FD for reading, one for writing */
69 struct pollfd wfSock;
70
71 /** The socket address */
72 QString wfSockPath;
73
74 /** Stop the loop flag */
75 volatile bool mTerminate = false;
76
77 /** Flag to check if we're connected or not */
78 volatile bool mConnected = false;
79
80 /** Function to write the json to wayfire socket. */
81 bool writeJson(QJsonDocument j);
82
83 /** Function to read the data from wayfire socket and parse it into json */
84 QJsonDocument readJson();
85
86 private:
87 QList<uint> mPendingRequests;
88 QMutex mutex; // Add a mutex for thread safety
89
90 /** Function to read the json from wayfire socket into a buffer. */
91 bool readExact(char *buf, uint size);
92
93 protected:
94 void run() override;
95
96 Q_SIGNALS:
97 /** We recieved an event from Wayfire */
98 void wayfireEvent(QJsonDocument);
99
100 /** Relay the message received from the server */
101 void response(uint32_t, QJsonDocument);
102
103 /** Inform the rest that polling has started */
104 void started();
105 };
106
107
108 class LXQt::Panel::Wayfire : public QObject
109 {
110 Q_OBJECT
111
112 public:
113 Wayfire(const QString &wfSock = QString());
114
115 /** Connect to Wayfire */
116 bool connectToServer() const;
117
118 /* ========== Specific requests ========== */
119
120 /** Request the compositor to send us the outputs information */
121 QJsonArray listOutputs() const;
122
123 /** Request the compositor to send us the outputs information */
124 WaylandId getActiveOutput() const;
125
126 /** Request the compositor to send us information of a given output */
127 QJsonObject getOutputInfo(WaylandId opId) const;
128
129 /** Request the compositor to focus a given output */
130 bool focusOutput(WaylandId opId) const;
131
132 /** Request the compositor to trigger show-desktop a given output */
133 bool showDesktop(WaylandId opId) const;
134
135 /** Request the compositor to send us the wsets information */
136 QJsonArray getWorkspaceSetsInfo() const;
137
138 /** Request the compositor to send us the wsets information */
139 QString getWorkspaceName(int, const QString &outputName = QString()) const;
140 bool setWorkspaceName(int, const QString&) const;
141
142 /** Request the compositor to change the current workspace */
143 bool switchToWorkspace(WaylandId opId, int64_t nth, WaylandId viewId = WaylandId()) const;
144
145 /** Request the compositor to send us the list of views */
146 QJsonArray listViews() const;
147
148 /** Request the compositor to send us the info of the given view */
149 WaylandId getActiveView() const;
150
151 /** Request the compositor to send us the info of the given view */
152 QJsonObject getViewInfo(WaylandId viewId) const;
153
154 /** Request the compositor to focus a given view */
155 bool focusView(WaylandId viewId) const;
156
157 /** Request the compositor to minimize/restore a given view */
158 bool minimizeView(WaylandId viewId, bool) const;
159
160 /** Request the compositor to maximize/restore a given view */
161 bool maximizeView(WaylandId viewId, int edges) const;
162
163 /** Request the compositor to fullscreen a given view */
164 bool fullscreenView(WaylandId viewId, bool) const;
165
166 /** Request the compositor to focus a given view */
167 bool restoreView(WaylandId viewId) const;
168
169 /** Request the compositor to focus a given view */
170 bool sendViewToWorkspace(WaylandId viewId, int nth) const;
171
172 /** Request the compositor to focus a given view */
173 bool closeView(WaylandId viewId) const;
174
175 /** This is a generic request */
176 QJsonDocument genericRequest(QJsonDocument) const;
177
178 /* ========== WAYFIRE EVENTS ========== */
179
180 /**
181 * A new output was added.
182 */
183 Q_SIGNAL void outputAdded(QJsonDocument);
184
185 /**
186 * An existing output was removed.
187 */
188 Q_SIGNAL void outputRemoved(QJsonDocument);
189
190 /**
191 * A particular output has gained focus. Only one output can have focus at any given time. This outupt can
192 * be used to calculate the focused view.
193 */
194 Q_SIGNAL void outputFocused(QJsonDocument);
195
196 /**
197 * Current workspace set of a given output was changed When the wset of an output changes, always query
198 * the workspace
199 */
200 Q_SIGNAL void workspaceSetChanged(QJsonDocument);
201
202 /**
203 * The active workspace of a given wset changed. Because wsets of different outputs are independent,
204 * workspace change on one output will not affect the other.
205 */
206 Q_SIGNAL void workspaceChanged(QJsonDocument);
207
208 /**
209 * A view was just mapped. This view does not have an output nor a wset. Even the title and app-id will be
210 * unset. Only the view id is valid.
211 */
212 Q_SIGNAL void viewMapped(QJsonDocument);
213
214 /**
215 * A view on a particular outupt gained focus Since wayfire supports independent outputs, each output can
216 * have a view with focus. The focused view of the active outupt will be the one with keyboard focus.
217 */
218 Q_SIGNAL void viewFocused(QJsonDocument);
219
220 /**
221 * The title of a view changed. The title can be "nil" or null. In such cases, the user can safely ignore
222 * it.
223 */
224 Q_SIGNAL void viewTitleChanged(QJsonDocument);
225
226 /**
227 * The app-id of a view changed. The app-id can be "nil" or null. In such cases, the user can safely
228 * ignore it.
229 */
230 Q_SIGNAL void viewAppIdChanged(QJsonDocument);
231
232 /**
233 * The geometry of a view changed.
234 */
235 Q_SIGNAL void viewGeometryChanged(QJsonDocument);
236
237 /**
238 * The tiled status of a view has changed.
239 */
240 Q_SIGNAL void viewTiled(QJsonDocument);
241
242 /**
243 * A view was minimized.
244 */
245 Q_SIGNAL void viewMinimized(QJsonDocument);
246
247 /**
248 * The output of a view changed. When the view gets mapped, the output will be null.
249 */
250 Q_SIGNAL void viewOutputChanged(QJsonDocument);
251
252 /**
253 * The workspace of a view changed.
254 */
255 Q_SIGNAL void viewWorkspaceChanged(QJsonDocument);
256
257 /**
258 * An existing view was unmapped. The output, wset etc of this view are invalid as of now.
259 */
260 Q_SIGNAL void viewUnmapped(QJsonDocument);
261
262 /**
263 * A generic wayfire event. This signal is always emitted for all events. Specific signals are emitted by
264 * parsing this event.
265 */
266 Q_SIGNAL void genericEvent(QJsonDocument);
267
268 /**
269 * Inform the user tha there was an error. Currently used to indicate failure in watching for wayfire
270 * events.
271 */
272 Q_SIGNAL void error();
273
274 private:
275 /** Implementation class pointer */
276 QPointer<WayfireImpl> impl;
277
278 /** Partially parse the events to emit the correct signals */
279 void parseEvents(QJsonDocument);
280 };