VirtualBox

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

Last change on this file since 101598 was 100684, checked in by vboxsync, 17 months ago

Shared Clipboard: Added ShClX11ReadDataFromX11(), useful for enabling the X11 testcases (again). bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.5 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 /** Is an X server actually available? */
119 bool fHaveX11;
120 /** The X Toolkit application context structure. */
121 XtAppContext pAppContext;
122 /** We have a separate thread to wait for window and clipboard events. */
123 RTTHREAD Thread;
124 /** Flag indicating that the thread is in a started state. */
125 bool fThreadStarted;
126 /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
127 Widget pWidget;
128 /** Should we try to grab the clipboard on startup? */
129 bool fGrabClipboardOnStart;
130 /** The best text format X11 has to offer, as an index into the formats table. */
131 SHCLX11FMTIDX idxFmtText;
132 /** The best bitmap format X11 has to offer, as an index into the formats table. */
133 SHCLX11FMTIDX idxFmtBmp;
134 /** The best HTML format X11 has to offer, as an index into the formats table. */
135 SHCLX11FMTIDX idxFmtHTML;
136#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
137 /** The best HTML format X11 has to offer, as an index into the formats table. */
138 SHCLX11FMTIDX idxFmtURI;
139# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
140 /** HTTP transfer context data. */
141 SHCLHTTPCONTEXT HttpCtx;
142# endif
143#endif
144 /** What kind of formats does VBox have to offer? */
145 SHCLFORMATS vboxFormats;
146 /** Internval cache of VBox clipboard formats. */
147 SHCLCACHE Cache;
148 /** When we wish the clipboard to exit, we have to wake up the event
149 * loop. We do this by writing into a pipe. This end of the pipe is
150 * the end that another thread can write to. */
151 int wakeupPipeWrite;
152 /** The reader end of the pipe. */
153 int wakeupPipeRead;
154 /** A pointer to the XFixesSelectSelectionInput function. */
155 void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
156 /** The first XFixes event number. */
157 int fixesEventBase;
158#ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
159 /** XtGetSelectionValue on some versions of libXt isn't re-entrant
160 * so block overlapping requests on this flag. */
161 bool fXtBusy;
162 /** If a request is blocked on the previous flag, set this flag to request
163 * an update later - the first callback should check and clear this flag
164 * before processing the callback event. */
165 bool fXtNeedsUpdate;
166#endif
167} SHCLX11CTX, *PSHCLX11CTX;
168
169/**
170 * Structure describing an X11 clipboard request.
171 */
172typedef struct _SHCLX11REQUEST
173{
174 /** The clipboard context this request is associated with. */
175 SHCLX11CTX *pCtx;
176 /** Event associated to this request. */
177 PSHCLEVENT pEvent;
178 union
179 {
180 /** Format announcement to X. */
181 struct
182 {
183 /** VBox formats to announce. */
184 SHCLFORMATS fFormats;
185 } Formats;
186 /** Read request. */
187 struct
188 {
189 /** The format VBox would like the data in. */
190 SHCLFORMAT uFmtVBox;
191 /** The format we requested from X11. */
192 SHCLX11FMTIDX idxFmtX11;
193 /** How much bytes to read at max. */
194 uint32_t cbMax;
195 } Read;
196 };
197} SHCLX11REQUEST;
198/** Pointer to an X11 clipboard request. */
199typedef SHCLX11REQUEST *PSHCLX11REQUEST;
200
201/**
202 * Structure describing an X11 clipboard response to an X11 clipboard request.
203 */
204typedef struct _SHCLX11RESPONSE
205{
206 int rc;
207 struct
208 {
209 void *pvData;
210 uint32_t cbData;
211 } Read;
212} SHCLX11RESPONSE;
213/** Pointer to an X11 clipboard response. */
214typedef SHCLX11RESPONSE *PSHCLX11RESPONSE;
215
216/** @name Shared Clipboard APIs for X11.
217 * @{
218 */
219int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks, PSHCLCONTEXT pParent, bool fHeadless);
220void ShClX11Destroy(PSHCLX11CTX pCtx);
221int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
222int ShClX11ThreadStartEx(PSHCLX11CTX pCtx, const char *pszName, bool fGrab);
223int ShClX11ThreadStop(PSHCLX11CTX pCtx);
224int ShClX11ReportFormatsToX11Async(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
225int ShClX11ReadDataFromX11Async(PSHCLX11CTX pCtx, SHCLFORMAT uFmt, uint32_t cbMax, PSHCLEVENT pEvent);
226int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, PSHCLEVENTSOURCE pEventSource, RTMSINTERVAL msTimeout, SHCLFORMAT uFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcbBuf);
227void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
228/** @} */
229
230#endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
231
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