1 | /** @file
|
---|
2 | * Shared Clipboard - Common X11 code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
|
---|
37 | #define VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <X11/Intrinsic.h>
|
---|
43 |
|
---|
44 | #include <iprt/req.h>
|
---|
45 | #include <iprt/thread.h>
|
---|
46 |
|
---|
47 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
48 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
49 | # include <VBox/GuestHost/SharedClipboard-transfers.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * The maximum number of simultaneous connections to shared clipboard service.
|
---|
54 | * This constant limits amount of GUEST -> HOST connections to shared clipboard host service
|
---|
55 | * for X11 host only. Once amount of connections reaches this number, all the
|
---|
56 | * further attempts to CONNECT will be dropped on an early stage. Possibility to connect
|
---|
57 | * is available again after one of existing connections is closed by DISCONNECT call.
|
---|
58 | */
|
---|
59 | #define VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX (20)
|
---|
60 |
|
---|
61 | /** Enables the Xt busy / update handling. */
|
---|
62 | #define VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY 1
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Enumeration for all clipboard formats which we support on X11.
|
---|
66 | */
|
---|
67 | typedef enum _SHCLX11FMT
|
---|
68 | {
|
---|
69 | SHCLX11FMT_INVALID = 0,
|
---|
70 | SHCLX11FMT_TARGETS,
|
---|
71 | SHCLX11FMT_TEXT, /* Treat this as UTF-8, but it may really be ascii */
|
---|
72 | SHCLX11FMT_UTF8,
|
---|
73 | SHCLX11FMT_BMP,
|
---|
74 | SHCLX11FMT_HTML
|
---|
75 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
76 | , SHCLX11FMT_URI_LIST
|
---|
77 | #endif
|
---|
78 | } SHCLX11FMT;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * The table maps X11 names to data formats
|
---|
82 | * and to the corresponding VBox clipboard formats.
|
---|
83 | */
|
---|
84 | typedef struct SHCLX11FMTTABLE
|
---|
85 | {
|
---|
86 | /** The X11 atom name of the format (several names can match one format). */
|
---|
87 | const char *pcszAtom;
|
---|
88 | /** The format corresponding to the name. */
|
---|
89 | SHCLX11FMT enmFmtX11;
|
---|
90 | /** The corresponding VBox clipboard format. */
|
---|
91 | SHCLFORMAT uFmtVBox;
|
---|
92 | } SHCLX11FMTTABLE;
|
---|
93 |
|
---|
94 | #define NIL_CLIPX11FORMAT 0
|
---|
95 |
|
---|
96 | /** Defines an index of the X11 clipboad format table. */
|
---|
97 | typedef unsigned SHCLX11FMTIDX;
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Structure for maintaining a Shared Clipboard context on X11 platforms.
|
---|
101 | */
|
---|
102 | typedef struct _SHCLX11CTX
|
---|
103 | {
|
---|
104 | /** Opaque data structure describing the front-end. */
|
---|
105 | PSHCLCONTEXT pFrontend;
|
---|
106 | /** Our callback table to use. */
|
---|
107 | SHCLCALLBACKS Callbacks;
|
---|
108 | /** Is an X server actually available? */
|
---|
109 | bool fHaveX11;
|
---|
110 | /** The X Toolkit application context structure. */
|
---|
111 | XtAppContext pAppContext;
|
---|
112 | /** We have a separate thread to wait for window and clipboard events. */
|
---|
113 | RTTHREAD Thread;
|
---|
114 | /** Flag indicating that the thread is in a started state. */
|
---|
115 | bool fThreadStarted;
|
---|
116 | /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
|
---|
117 | Widget pWidget;
|
---|
118 | /** Should we try to grab the clipboard on startup? */
|
---|
119 | bool fGrabClipboardOnStart;
|
---|
120 | /** The best text format X11 has to offer, as an index into the formats table. */
|
---|
121 | SHCLX11FMTIDX idxFmtText;
|
---|
122 | /** The best bitmap format X11 has to offer, as an index into the formats table. */
|
---|
123 | SHCLX11FMTIDX idxFmtBmp;
|
---|
124 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
125 | SHCLX11FMTIDX idxFmtHTML;
|
---|
126 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
127 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
128 | SHCLX11FMTIDX idxFmtURI;
|
---|
129 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
|
---|
130 | /** HTTP transfer context data. */
|
---|
131 | SHCLHTTPCONTEXT HttpCtx;
|
---|
132 | # endif
|
---|
133 | #endif
|
---|
134 | /** What kind of formats does VBox have to offer? */
|
---|
135 | SHCLFORMATS vboxFormats;
|
---|
136 | /** Cache of the last unicode data that we received. */
|
---|
137 | void *pvUnicodeCache;
|
---|
138 | /** Size of the unicode data in the cache. */
|
---|
139 | uint32_t cbUnicodeCache;
|
---|
140 | /** When we wish the clipboard to exit, we have to wake up the event
|
---|
141 | * loop. We do this by writing into a pipe. This end of the pipe is
|
---|
142 | * the end that another thread can write to. */
|
---|
143 | int wakeupPipeWrite;
|
---|
144 | /** The reader end of the pipe. */
|
---|
145 | int wakeupPipeRead;
|
---|
146 | /** A pointer to the XFixesSelectSelectionInput function. */
|
---|
147 | void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
|
---|
148 | /** The first XFixes event number. */
|
---|
149 | int fixesEventBase;
|
---|
150 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
|
---|
151 | /** XtGetSelectionValue on some versions of libXt isn't re-entrant
|
---|
152 | * so block overlapping requests on this flag. */
|
---|
153 | bool fXtBusy;
|
---|
154 | /** If a request is blocked on the previous flag, set this flag to request
|
---|
155 | * an update later - the first callback should check and clear this flag
|
---|
156 | * before processing the callback event. */
|
---|
157 | bool fXtNeedsUpdate;
|
---|
158 | #endif
|
---|
159 | } SHCLX11CTX, *PSHCLX11CTX;
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Structure describing an X11 clipboard request.
|
---|
163 | */
|
---|
164 | typedef struct _SHCLX11REQUEST
|
---|
165 | {
|
---|
166 | /** The clipboard context this request is associated with. */
|
---|
167 | SHCLX11CTX *pCtx;
|
---|
168 | /** Event associated to this request. */
|
---|
169 | PSHCLEVENT pEvent;
|
---|
170 | union
|
---|
171 | {
|
---|
172 | /** Format announcement to X. */
|
---|
173 | struct
|
---|
174 | {
|
---|
175 | /** VBox formats to announce. */
|
---|
176 | SHCLFORMATS fFormats;
|
---|
177 | } Formats;
|
---|
178 | /** Read request. */
|
---|
179 | struct
|
---|
180 | {
|
---|
181 | /** The format VBox would like the data in. */
|
---|
182 | SHCLFORMAT uFmtVBox;
|
---|
183 | /** The format we requested from X11. */
|
---|
184 | SHCLX11FMTIDX idxFmtX11;
|
---|
185 | /** How much bytes to read at max. */
|
---|
186 | uint32_t cbMax;
|
---|
187 | } Read;
|
---|
188 | };
|
---|
189 | } SHCLX11REQUEST;
|
---|
190 | /** Pointer to an X11 clipboard request. */
|
---|
191 | typedef SHCLX11REQUEST *PSHCLX11REQUEST;
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Structure describing an X11 clipboard response to an X11 clipboard request.
|
---|
195 | */
|
---|
196 | typedef struct _SHCLX11RESPONSE
|
---|
197 | {
|
---|
198 | int rc;
|
---|
199 | struct
|
---|
200 | {
|
---|
201 | void *pvData;
|
---|
202 | uint32_t cbData;
|
---|
203 | } Read;
|
---|
204 | } SHCLX11RESPONSE;
|
---|
205 | /** Pointer to an X11 clipboard response. */
|
---|
206 | typedef SHCLX11RESPONSE *PSHCLX11RESPONSE;
|
---|
207 |
|
---|
208 | /** @name Shared Clipboard APIs for X11.
|
---|
209 | * @{
|
---|
210 | */
|
---|
211 | int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks, PSHCLCONTEXT pParent, bool fHeadless);
|
---|
212 | void ShClX11Destroy(PSHCLX11CTX pCtx);
|
---|
213 | int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
|
---|
214 | int ShClX11ThreadStartEx(PSHCLX11CTX pCtx, const char *pszName, bool fGrab);
|
---|
215 | int ShClX11ThreadStop(PSHCLX11CTX pCtx);
|
---|
216 | int ShClX11ReportFormatsToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
|
---|
217 | int ShClX11ReadDataFromX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, uint32_t cbData, PSHCLEVENT pEvent);
|
---|
218 | void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
|
---|
219 | /** @} */
|
---|
220 |
|
---|
221 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
|
---|
222 |
|
---|