1 | /* $Id: wayland.cpp 100248 2023-06-22 12:51:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Guest Additions - Wayland Desktop Environment assistant.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.alldomusa.eu.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include "VBoxClient.h"
|
---|
29 | #include "wayland-helper.h"
|
---|
30 |
|
---|
31 | /** List of available Wayland Desktop Environment helpers. Sorted in order of preference. */
|
---|
32 | static const VBCLWAYLANDHELPER *g_apWaylandHelpers[] =
|
---|
33 | {
|
---|
34 | &g_WaylandHelperGtk, /* GTK helper. */
|
---|
35 | &g_WaylandHelperDcp, /* Device Control Protocol helper. */
|
---|
36 | NULL, /* Terminate list. */
|
---|
37 | };
|
---|
38 |
|
---|
39 | /** Selected helpers for Clipboard and Drag-and-Drop. */
|
---|
40 | static const VBCLWAYLANDHELPER *g_pWaylandHelperHelperClipboard = NULL;
|
---|
41 | static const VBCLWAYLANDHELPER *g_pWaylandHelperHelperDnd = NULL;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @interface_method_impl{VBCLSERVICE,pfnInit}
|
---|
45 | */
|
---|
46 | static DECLCALLBACK(int) vbclWaylandInit(void)
|
---|
47 | {
|
---|
48 | int rc = VERR_NOT_SUPPORTED;
|
---|
49 | int idxHelper = 0;
|
---|
50 |
|
---|
51 | /** Custom log prefix to be used for logger instance of this process. */
|
---|
52 | static const char *pszLogPrefix = "VBoxClient Wayland:";
|
---|
53 |
|
---|
54 | VBClLogSetLogPrefix(pszLogPrefix);
|
---|
55 |
|
---|
56 | /* Go through list of available helpers and try to pick up one. */
|
---|
57 | while (g_apWaylandHelpers[idxHelper])
|
---|
58 | {
|
---|
59 | if (RT_VALID_PTR(g_apWaylandHelpers[idxHelper]->pfnProbe))
|
---|
60 | {
|
---|
61 | int fCaps = VBOX_WAYLAND_HELPER_CAP_NONE;
|
---|
62 |
|
---|
63 | VBClLogInfo("probing Wayland helper '%s'\n",
|
---|
64 | g_apWaylandHelpers[idxHelper]->pszName);
|
---|
65 |
|
---|
66 | fCaps = g_apWaylandHelpers[idxHelper]->pfnProbe();
|
---|
67 |
|
---|
68 | /* Try Clipboard helper. */
|
---|
69 | if ( fCaps & VBOX_WAYLAND_HELPER_CAP_CLIPBOARD
|
---|
70 | && !RT_VALID_PTR(g_pWaylandHelperHelperClipboard))
|
---|
71 | {
|
---|
72 | if (RT_VALID_PTR(g_apWaylandHelpers[idxHelper]->pfnInit))
|
---|
73 | {
|
---|
74 | rc = g_apWaylandHelpers[idxHelper]->pfnInit();
|
---|
75 | if (RT_SUCCESS(rc))
|
---|
76 | g_pWaylandHelperHelperClipboard = g_apWaylandHelpers[idxHelper];
|
---|
77 | else
|
---|
78 | VBClLogError("Wayland helper '%s' cannot be initialized, skipping");
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | /* Try DnD helper. */
|
---|
83 | if ( fCaps & VBOX_WAYLAND_HELPER_CAP_DND
|
---|
84 | && !RT_VALID_PTR(g_pWaylandHelperHelperDnd))
|
---|
85 | {
|
---|
86 | if (RT_VALID_PTR(g_apWaylandHelpers[idxHelper]->pfnInit))
|
---|
87 | {
|
---|
88 | rc = g_apWaylandHelpers[idxHelper]->pfnInit();
|
---|
89 | if (RT_SUCCESS(rc))
|
---|
90 | g_pWaylandHelperHelperDnd = g_apWaylandHelpers[idxHelper];
|
---|
91 | else
|
---|
92 | VBClLogError("Wayland helper '%s' cannot be initialized, skipping");
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* See if we found all the needed helpers. */
|
---|
98 | if ( RT_VALID_PTR(g_pWaylandHelperHelperClipboard)
|
---|
99 | && RT_VALID_PTR(g_pWaylandHelperHelperDnd))
|
---|
100 | break;
|
---|
101 |
|
---|
102 | idxHelper++;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* Check result. */
|
---|
106 | if (RT_VALID_PTR(g_pWaylandHelperHelperClipboard))
|
---|
107 | VBClLogInfo("found Wayland Shared Clipboard helper '%s'\n", g_pWaylandHelperHelperClipboard->pszName);
|
---|
108 | else
|
---|
109 | VBClLogError("Wayland Shared Clipboard helper not found, clipboard sharing not possible\n");
|
---|
110 |
|
---|
111 | /* Check result. */
|
---|
112 | if (RT_VALID_PTR(g_pWaylandHelperHelperDnd))
|
---|
113 | VBClLogInfo("found Wayland Drag-and-Drop helper '%s'\n", g_pWaylandHelperHelperDnd->pszName);
|
---|
114 | else
|
---|
115 | VBClLogError("Wayland Drag-and-Drop helper not found, drag-and-drop not possible\n");
|
---|
116 |
|
---|
117 | return rc;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * @interface_method_impl{VBCLSERVICE,pfnWorker}
|
---|
122 | */
|
---|
123 | static DECLCALLBACK(int) vbclWaylandWorker(bool volatile *pfShutdown)
|
---|
124 | {
|
---|
125 | RT_NOREF(pfShutdown);
|
---|
126 | return VERR_NOT_SUPPORTED;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * @interface_method_impl{VBCLSERVICE,pfnStop}
|
---|
131 | */
|
---|
132 | static DECLCALLBACK(void) vbclWaylandStop(void)
|
---|
133 | {
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * @interface_method_impl{VBCLSERVICE,pfnTerm}
|
---|
138 | */
|
---|
139 | static DECLCALLBACK(int) vbclWaylandTerm(void)
|
---|
140 | {
|
---|
141 | return VERR_NOT_SUPPORTED;
|
---|
142 | }
|
---|
143 |
|
---|
144 | VBCLSERVICE g_SvcWayland =
|
---|
145 | {
|
---|
146 | "wayland", /* szName */
|
---|
147 | "Wayland assistant", /* pszDescription */
|
---|
148 | ".vboxclient-wayland", /* pszPidFilePathTemplate */
|
---|
149 | NULL, /* pszUsage */
|
---|
150 | NULL, /* pszOptions */
|
---|
151 | NULL, /* pfnOption */
|
---|
152 | vbclWaylandInit, /* pfnInit */
|
---|
153 | vbclWaylandWorker, /* pfnWorker */
|
---|
154 | vbclWaylandStop, /* pfnStop */
|
---|
155 | vbclWaylandTerm, /* pfnTerm */
|
---|
156 | };
|
---|