Debian Codegraph @

src/server/frontend_xwayland/xwayland_connector.h

raw symbols SCIP
1 /*
2 * Copyright (C) Marius Gripsgard <[email protected]>
3 * Copyright (C) Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 or 3,
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 #ifndef MIR_FRONTEND_XWAYLAND_CONNECTOR_H
20 #define MIR_FRONTEND_XWAYLAND_CONNECTOR_H
21
22 #include <mir/frontend/connector.h>
23
24 #include <memory>
25 #include <mutex>
26
27 namespace mir
28 {
29 class Executor;
30 namespace dispatch
31 {
32 class ReadableFd;
33 class ThreadedDispatcher;
34 }
35 namespace frontend
36 {
37 class WaylandConnector;
38 class XWaylandServer;
39 class XWaylandSpawner;
40 class XWaylandWM;
41 class XWaylandConnector : public Connector, public std::enable_shared_from_this<XWaylandConnector>
42 {
43 public:
44 /// Scale is a little complicated. It controls how big apps appear but *probably* not the scale they render at
45 /// (unless they respect the X11 DPI, which most don't). For sharp, correctly sized apps the output scale, XWayland
46 /// scale and the scale the application uses should all match. Application scale needs to be configured on a per-app
47 /// or even per-toolkit basis. GDK_SCALE is used by default for XWayland scale because many apps respect it, so it's
48 /// generally as correct as anything.
49 XWaylandConnector(
50 std::shared_ptr<Executor> const& main_loop,
51 std::shared_ptr<WaylandConnector> const& wayland_connector,
52 std::string const& xwayland_path,
53 float scale);
54 ~XWaylandConnector();
55
56 void start() override;
57 void stop() override;
58
59 int client_socket_fd() const override;
60 int client_socket_fd(
61 std::function<void(std::shared_ptr<scene::Session> const& session)> const& connect_handler) const override;
62
63 auto socket_name() const -> std::optional<std::string> override;
64
65 private:
66 std::shared_ptr<Executor> const main_loop;
67 std::shared_ptr<WaylandConnector> const wayland_connector;
68 std::string const xwayland_path;
69 float const scale;
70
71 /// Creates the spawner if it doesn't already exist and is_started is true, given lock must be locked
72 void maybe_create_spawner(std::unique_lock<std::mutex> const& lock);
73 /// Destroyes all objects including the spawner, given lock must be locked
74 void clean_up(std::unique_lock<std::mutex> lock);
75 /// Called the first time a client attempts to connect. Creates the server (which forks the XWayland process), wm
76 /// and wm_event_thread.
77 void spawn();
78
79 std::mutex mutable mutex;
80 /// Set in start() and stop(), should always reflect the state Mir has requested this object to be in
81 bool is_started{false};
82 std::unique_ptr<XWaylandSpawner> spawner;
83 std::unique_ptr<XWaylandServer> server;
84 std::unique_ptr<XWaylandWM> wm;
85 std::unique_ptr<dispatch::ThreadedDispatcher> wm_event_thread;
86 };
87 } /* frontend */
88 } /* mir */
89
90 #endif /* end of include guard: MIR_FRONTEND_XWAYLAND_CONNECTOR_H */