VirtualBox

source: vbox/trunk/include/VBox/GuestHost/SharedClipboard-x11.h@ 105381

Last change on this file since 105381 was 103323, checked in by vboxsync, 10 months ago

Shared Clipboard: Condensed the X11 clipboard reading code even more (also removes duplicate code); added ShClX11ReadDataFromX11Ex() for that.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.7 KB
Line 
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 */
67typedef 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 /** URI list as (UTF-8) text. */
77 , SHCLX11FMT_URI_LIST
78 /** URI list as a representation for copying files for GNOME-based applications. */
79 , SHCLX11FMT_URI_LIST_GNOME_COPIED_FILES
80 /** URI list as a representation for copying files for MATE-based applications. */
81 , SHCLX11FMT_URI_LIST_MATE_COPIED_FILES
82 /** URI list as representation for copying files for the Nautilus file manager (GNOME). */
83 , SHCLX11FMT_URI_LIST_NAUTILUS_CLIPBOARD
84 /** URI list as a representation for copying files for KDE-based applications.
85 * Also being used for Dolphin (KDE). */
86 , SHCLX11FMT_URI_LIST_KDE_CUTSELECTION
87#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
88} SHCLX11FMT;
89
90/**
91 * The table maps X11 names to data formats
92 * and to the corresponding VBox clipboard formats.
93 */
94typedef struct SHCLX11FMTTABLE
95{
96 /** The X11 atom name of the format (several names can match one format). */
97 const char *pcszAtom;
98 /** The format corresponding to the name. */
99 SHCLX11FMT enmFmtX11;
100 /** The corresponding VBox clipboard format. */
101 SHCLFORMAT uFmtVBox;
102} SHCLX11FMTTABLE;
103
104#define NIL_CLIPX11FORMAT 0
105
106/** Defines an index of the X11 clipboad format table. */
107typedef unsigned SHCLX11FMTIDX;
108
109/**
110 * Structure for maintaining a Shared Clipboard context on X11 platforms.
111 */
112typedef struct _SHCLX11CTX
113{
114 /** Opaque data structure describing the front-end. */
115 PSHCLCONTEXT pFrontend;
116 /** Our callback table to use. */
117 SHCLCALLBACKS Callbacks;
118 /**
119 * Are we running in headless mode?
120 *
121 * This is a special situation for running on UNIX-y environments, where an
122 * X server could not be available when running on a server without any
123 * desktop environment available, for example.
124 */
125 bool fHeadless;
126 /** The X Toolkit application context structure. */
127 XtAppContext pAppContext;
128 /** We have a separate thread to wait for window and clipboard events. */
129 RTTHREAD Thread;
130 /** Flag indicating that the thread is in a started state. */
131 bool fThreadStarted;
132 /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
133 Widget pWidget;
134 /** Should we try to grab the clipboard on startup? */
135 bool fGrabClipboardOnStart;
136 /** The best text format X11 has to offer, as an index into the formats table. */
137 SHCLX11FMTIDX idxFmtText;
138 /** The best bitmap format X11 has to offer, as an index into the formats table. */
139 SHCLX11FMTIDX idxFmtBmp;
140 /** The best HTML format X11 has to offer, as an index into the formats table. */
141 SHCLX11FMTIDX idxFmtHTML;
142#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
143 /** The best HTML format X11 has to offer, as an index into the formats table. */
144 SHCLX11FMTIDX idxFmtURI;
145# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
146 /** HTTP transfer context data. */
147 SHCLHTTPCONTEXT HttpCtx;
148# endif
149#endif
150 /** What kind of formats does VBox have to offer? */
151 SHCLFORMATS vboxFormats;
152 /** Internval cache of VBox clipboard formats. */
153 SHCLCACHE Cache;
154 /** When we wish the clipboard to exit, we have to wake up the event
155 * loop. We do this by writing into a pipe. This end of the pipe is
156 * the end that another thread can write to. */
157 int wakeupPipeWrite;
158 /** The reader end of the pipe. */
159 int wakeupPipeRead;
160 /** A pointer to the XFixesSelectSelectionInput function. */
161 void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
162 /** The first XFixes event number. */
163 int fixesEventBase;
164#ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
165 /** XtGetSelectionValue on some versions of libXt isn't re-entrant
166 * so block overlapping requests on this flag. */
167 bool fXtBusy;
168 /** If a request is blocked on the previous flag, set this flag to request
169 * an update later - the first callback should check and clear this flag
170 * before processing the callback event. */
171 bool fXtNeedsUpdate;
172#endif
173} SHCLX11CTX, *PSHCLX11CTX;
174
175/**
176 * Enumeration for an X11 event type.
177 */
178typedef enum _SHCLX11EVENTTYPE
179{
180 /** Invalid event type. */
181 SHCLX11EVENTTYPE_INVALID = 0,
182 /** Reports formats to X11. */
183 SHCLX11EVENTTYPE_REPORT_FORMATS,
184 /** Reads clipboard from X11. */
185 SHCLX11EVENTTYPE_READ,
186 /** Writes clipboard to X11. */
187 SHCLX11EVENTTYPE_WRITE
188} SHCLX11EVENTTYPE;
189/** Pointer to an enumeration for an X11 event type. */
190typedef SHCLX11EVENTTYPE *PSHCLX11EVENTTYPE;
191
192/**
193 * Structure describing an X11 clipboard request.
194 */
195typedef struct _SHCLX11REQUEST
196{
197 /** The clipboard context this request is associated with. */
198 SHCLX11CTX *pCtx;
199 /** Event associated to this request. */
200 PSHCLEVENT pEvent;
201 /** Request type for the union below. */
202 SHCLX11EVENTTYPE enmType;
203 union
204 {
205 /** Format announcement to X. */
206 struct
207 {
208 /** VBox formats to announce. */
209 SHCLFORMATS fFormats;
210 } Formats;
211 /** Read request. */
212 struct
213 {
214 /** The format VBox would like the data in. */
215 SHCLFORMAT uFmtVBox;
216 /** The format we requested from X11. */
217 SHCLX11FMTIDX idxFmtX11;
218 /** How much bytes to read at max. */
219 uint32_t cbMax;
220 } Read;
221 /** Write request. */
222 struct
223 {
224 /** The format of the data to write. */
225 SHCLFORMAT uFmtVBox;
226 /** The format to write to X11. */
227 SHCLX11FMTIDX idxFmtX11;
228 /** Data to write. */
229 void *pvData;
230 /** How much bytes to write. */
231 uint32_t cbData;
232 } Write;
233 };
234} SHCLX11REQUEST;
235/** Pointer to an X11 clipboard request. */
236typedef SHCLX11REQUEST *PSHCLX11REQUEST;
237
238/**
239 * Structure describing an X11 clipboard response to an X11 clipboard request.
240 */
241typedef struct _SHCLX11RESPONSE
242{
243 /** Response type for the union below. */
244 SHCLX11EVENTTYPE enmType;
245 /** rc (IPRT-style) of the operation performed as part of the X event thread. */
246 int rc;
247 union
248 {
249 struct
250 {
251 void *pvData;
252 uint32_t cbData;
253 } Read;
254 struct
255 {
256 const void *pvData;
257 uint32_t cbData;
258 } Write;
259 };
260} SHCLX11RESPONSE;
261/** Pointer to an X11 clipboard response. */
262typedef SHCLX11RESPONSE *PSHCLX11RESPONSE;
263
264/** @name Shared Clipboard APIs for X11.
265 * @{
266 */
267int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks, PSHCLCONTEXT pParent, bool fHeadless);
268int ShClX11Destroy(PSHCLX11CTX pCtx);
269int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
270int ShClX11ThreadStartEx(PSHCLX11CTX pCtx, const char *pszName, bool fGrab);
271int ShClX11ThreadStop(PSHCLX11CTX pCtx);
272int ShClX11ReportFormatsToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
273int ShClX11ReadDataFromX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, uint32_t cbMax, PSHCLEVENT pEvent);
274int ShClX11ReadDataFromX11Ex(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, void **ppvBuf, uint32_t *pcbBuf);
275int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcbBuf);
276int ShClX11WriteDataToX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, const void *pvBuf, uint32_t cbBuf, PSHCLEVENT pEvent);
277int ShClX11WriteDataToX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
278void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
279#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
280int ShClX11TransferConvertToX11(const char *pszSrc, size_t cbSrc, SHCLX11FMT enmFmtX11, void **ppvDst, size_t *pcbDst);
281int ShClX11TransferConvertFromX11(const char *pvData, size_t cbData, char **ppszList, size_t *pcbList);
282#endif
283/** @} */
284
285#endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
286
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette