1 | /** @file
|
---|
2 | * Shared Clipboard - Common X11 code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2022 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/thread.h>
|
---|
45 |
|
---|
46 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
47 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
48 | # include <VBox/GuestHost/SharedClipboard-transfers.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * The maximum number of simultaneous connections to shared clipboard service.
|
---|
53 | * This constant limits amount of GUEST -> HOST connections to shared clipboard host service
|
---|
54 | * for X11 host only. Once amount of connections reaches this number, all the
|
---|
55 | * further attempts to CONNECT will be dropped on an early stage. Possibility to connect
|
---|
56 | * is available again after one of existing connections is closed by DISCONNECT call.
|
---|
57 | */
|
---|
58 | #define VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX (20)
|
---|
59 |
|
---|
60 | /** Enables the Xt busy / update handling. */
|
---|
61 | #define VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY 1
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Enumeration for all clipboard formats which we support on X11.
|
---|
65 | */
|
---|
66 | typedef enum _SHCLX11FMT
|
---|
67 | {
|
---|
68 | SHCLX11FMT_INVALID = 0,
|
---|
69 | SHCLX11FMT_TARGETS,
|
---|
70 | SHCLX11FMT_TEXT, /* Treat this as UTF-8, but it may really be ascii */
|
---|
71 | SHCLX11FMT_UTF8,
|
---|
72 | SHCLX11FMT_BMP,
|
---|
73 | SHCLX11FMT_HTML
|
---|
74 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
75 | , SHCLX11FMT_URI_LIST
|
---|
76 | #endif
|
---|
77 | } SHCLX11FMT;
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * The table maps X11 names to data formats
|
---|
81 | * and to the corresponding VBox clipboard formats.
|
---|
82 | */
|
---|
83 | typedef struct SHCLX11FMTTABLE
|
---|
84 | {
|
---|
85 | /** The X11 atom name of the format (several names can match one format). */
|
---|
86 | const char *pcszAtom;
|
---|
87 | /** The format corresponding to the name. */
|
---|
88 | SHCLX11FMT enmFmtX11;
|
---|
89 | /** The corresponding VBox clipboard format. */
|
---|
90 | SHCLFORMAT uFmtVBox;
|
---|
91 | } SHCLX11FMTTABLE;
|
---|
92 |
|
---|
93 | #define NIL_CLIPX11FORMAT 0
|
---|
94 |
|
---|
95 | /** Defines an index of the X11 clipboad format table. */
|
---|
96 | typedef unsigned SHCLX11FMTIDX;
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Structure for maintaining a Shared Clipboard context on X11 platforms.
|
---|
100 | */
|
---|
101 | typedef struct _SHCLX11CTX
|
---|
102 | {
|
---|
103 | /** Opaque data structure describing the front-end. */
|
---|
104 | PSHCLCONTEXT pFrontend;
|
---|
105 | /** Our callback table to use. */
|
---|
106 | SHCLCALLBACKS Callbacks;
|
---|
107 | /** Is an X server actually available? */
|
---|
108 | bool fHaveX11;
|
---|
109 | /** The X Toolkit application context structure. */
|
---|
110 | XtAppContext pAppContext;
|
---|
111 | /** We have a separate thread to wait for window and clipboard events. */
|
---|
112 | RTTHREAD Thread;
|
---|
113 | /** Flag indicating that the thread is in a started state. */
|
---|
114 | bool fThreadStarted;
|
---|
115 | /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
|
---|
116 | Widget pWidget;
|
---|
117 | /** Should we try to grab the clipboard on startup? */
|
---|
118 | bool fGrabClipboardOnStart;
|
---|
119 | /** The best text format X11 has to offer, as an index into the formats table. */
|
---|
120 | SHCLX11FMTIDX idxFmtText;
|
---|
121 | /** The best bitmap format X11 has to offer, as an index into the formats table. */
|
---|
122 | SHCLX11FMTIDX idxFmtBmp;
|
---|
123 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
124 | SHCLX11FMTIDX idxFmtHTML;
|
---|
125 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
126 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
127 | SHCLX11FMTIDX idxFmtURI;
|
---|
128 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
|
---|
129 | /** HTTP transfer context data. */
|
---|
130 | SHCLHTTPCONTEXT HttpCtx;
|
---|
131 | # endif
|
---|
132 | #endif
|
---|
133 | /** What kind of formats does VBox have to offer? */
|
---|
134 | SHCLFORMATS vboxFormats;
|
---|
135 | /** Cache of the last unicode data that we received. */
|
---|
136 | void *pvUnicodeCache;
|
---|
137 | /** Size of the unicode data in the cache. */
|
---|
138 | uint32_t cbUnicodeCache;
|
---|
139 | /** When we wish the clipboard to exit, we have to wake up the event
|
---|
140 | * loop. We do this by writing into a pipe. This end of the pipe is
|
---|
141 | * the end that another thread can write to. */
|
---|
142 | int wakeupPipeWrite;
|
---|
143 | /** The reader end of the pipe. */
|
---|
144 | int wakeupPipeRead;
|
---|
145 | /** A pointer to the XFixesSelectSelectionInput function. */
|
---|
146 | void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
|
---|
147 | /** The first XFixes event number. */
|
---|
148 | int fixesEventBase;
|
---|
149 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
|
---|
150 | /** XtGetSelectionValue on some versions of libXt isn't re-entrant
|
---|
151 | * so block overlapping requests on this flag. */
|
---|
152 | bool fXtBusy;
|
---|
153 | /** If a request is blocked on the previous flag, set this flag to request
|
---|
154 | * an update later - the first callback should check and clear this flag
|
---|
155 | * before processing the callback event. */
|
---|
156 | bool fXtNeedsUpdate;
|
---|
157 | #endif
|
---|
158 | } SHCLX11CTX, *PSHCLX11CTX;
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Structure for keeping a X11 read data request.
|
---|
162 | */
|
---|
163 | typedef struct _SHCLX11READDATAREQ
|
---|
164 | {
|
---|
165 | /** Actual read request to handle. */
|
---|
166 | CLIPREADCBREQ *pReq;
|
---|
167 | /** Result code of the operation on completion. */
|
---|
168 | int rcCompletion;
|
---|
169 | } SHCLX11READDATAREQ;
|
---|
170 | /** Pointer to a send data request. */
|
---|
171 | typedef SHCLX11READDATAREQ *PSHCLX11READDATAREQ;
|
---|
172 |
|
---|
173 | /** @name Shared Clipboard APIs for X11.
|
---|
174 | * @{
|
---|
175 | */
|
---|
176 | int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks, PSHCLCONTEXT pParent, bool fHeadless);
|
---|
177 | void ShClX11Destroy(PSHCLX11CTX pCtx);
|
---|
178 | int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
|
---|
179 | int ShClX11ThreadStartEx(PSHCLX11CTX pCtx, const char *pszName, bool fGrab);
|
---|
180 | int ShClX11ThreadStop(PSHCLX11CTX pCtx);
|
---|
181 | int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
|
---|
182 | int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
|
---|
183 | void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
|
---|
184 | /** @} */
|
---|
185 |
|
---|
186 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
|
---|
187 |
|
---|