1 | /** @file
|
---|
2 | * Shared Clipboard - Common X11 code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
|
---|
27 | #define VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <X11/Intrinsic.h>
|
---|
33 |
|
---|
34 | #include <iprt/thread.h>
|
---|
35 |
|
---|
36 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
37 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
38 | # include <VBox/GuestHost/SharedClipboard-transfers.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The maximum number of simultaneous connections to shared clipboard service.
|
---|
43 | * This constant limits amount of GUEST -> HOST connections to shared clipboard host service
|
---|
44 | * for X11 host only. Once amount of connections reaches this number, all the
|
---|
45 | * further attempts to CONNECT will be dropped on an early stage. Possibility to connect
|
---|
46 | * is available again after one of existing connections is closed by DISCONNECT call.
|
---|
47 | */
|
---|
48 | #define VBOX_SHARED_CLIPBOARD_X11_CONNECTIONS_MAX (20)
|
---|
49 |
|
---|
50 | /** Enables the Xt busy / update handling. */
|
---|
51 | #define VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY 1
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Enumeration for all clipboard formats which we support on X11.
|
---|
55 | */
|
---|
56 | typedef enum _SHCLX11FMT
|
---|
57 | {
|
---|
58 | SHCLX11FMT_INVALID = 0,
|
---|
59 | SHCLX11FMT_TARGETS,
|
---|
60 | SHCLX11FMT_TEXT, /* Treat this as UTF-8, but it may really be ascii */
|
---|
61 | SHCLX11FMT_UTF8,
|
---|
62 | SHCLX11FMT_BMP,
|
---|
63 | SHCLX11FMT_HTML
|
---|
64 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
65 | , SHCLX11FMT_URI_LIST
|
---|
66 | #endif
|
---|
67 | } SHCLX11FMT;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * The table maps X11 names to data formats
|
---|
71 | * and to the corresponding VBox clipboard formats.
|
---|
72 | */
|
---|
73 | typedef struct SHCLX11FMTTABLE
|
---|
74 | {
|
---|
75 | /** The X11 atom name of the format (several names can match one format). */
|
---|
76 | const char *pcszAtom;
|
---|
77 | /** The format corresponding to the name. */
|
---|
78 | SHCLX11FMT enmFmtX11;
|
---|
79 | /** The corresponding VBox clipboard format. */
|
---|
80 | SHCLFORMAT uFmtVBox;
|
---|
81 | } SHCLX11FMTTABLE;
|
---|
82 |
|
---|
83 | #define NIL_CLIPX11FORMAT 0
|
---|
84 |
|
---|
85 | /** Defines an index of the X11 clipboad format table. */
|
---|
86 | typedef unsigned SHCLX11FMTIDX;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Structure for maintaining a Shared Clipboard context on X11 platforms.
|
---|
90 | */
|
---|
91 | typedef struct _SHCLX11CTX
|
---|
92 | {
|
---|
93 | /** Opaque data structure describing the front-end. */
|
---|
94 | PSHCLCONTEXT pFrontend;
|
---|
95 | /** Our callback table to use. */
|
---|
96 | SHCLCALLBACKS Callbacks;
|
---|
97 | /** Is an X server actually available? */
|
---|
98 | bool fHaveX11;
|
---|
99 | /** The X Toolkit application context structure. */
|
---|
100 | XtAppContext pAppContext;
|
---|
101 | /** We have a separate thread to wait for window and clipboard events. */
|
---|
102 | RTTHREAD Thread;
|
---|
103 | /** Flag indicating that the thread is in a started state. */
|
---|
104 | bool fThreadStarted;
|
---|
105 | /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
|
---|
106 | Widget pWidget;
|
---|
107 | /** Should we try to grab the clipboard on startup? */
|
---|
108 | bool fGrabClipboardOnStart;
|
---|
109 | /** The best text format X11 has to offer, as an index into the formats table. */
|
---|
110 | SHCLX11FMTIDX idxFmtText;
|
---|
111 | /** The best bitmap format X11 has to offer, as an index into the formats table. */
|
---|
112 | SHCLX11FMTIDX idxFmtBmp;
|
---|
113 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
114 | SHCLX11FMTIDX idxFmtHTML;
|
---|
115 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
116 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
117 | SHCLX11FMTIDX idxFmtURI;
|
---|
118 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
|
---|
119 | /** HTTP transfer context data. */
|
---|
120 | SHCLHTTPCONTEXT HttpCtx;
|
---|
121 | # endif
|
---|
122 | #endif
|
---|
123 | /** What kind of formats does VBox have to offer? */
|
---|
124 | SHCLFORMATS vboxFormats;
|
---|
125 | /** Cache of the last unicode data that we received. */
|
---|
126 | void *pvUnicodeCache;
|
---|
127 | /** Size of the unicode data in the cache. */
|
---|
128 | uint32_t cbUnicodeCache;
|
---|
129 | /** When we wish the clipboard to exit, we have to wake up the event
|
---|
130 | * loop. We do this by writing into a pipe. This end of the pipe is
|
---|
131 | * the end that another thread can write to. */
|
---|
132 | int wakeupPipeWrite;
|
---|
133 | /** The reader end of the pipe. */
|
---|
134 | int wakeupPipeRead;
|
---|
135 | /** A pointer to the XFixesSelectSelectionInput function. */
|
---|
136 | void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
|
---|
137 | /** The first XFixes event number. */
|
---|
138 | int fixesEventBase;
|
---|
139 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
|
---|
140 | /** XtGetSelectionValue on some versions of libXt isn't re-entrant
|
---|
141 | * so block overlapping requests on this flag. */
|
---|
142 | bool fXtBusy;
|
---|
143 | /** If a request is blocked on the previous flag, set this flag to request
|
---|
144 | * an update later - the first callback should check and clear this flag
|
---|
145 | * before processing the callback event. */
|
---|
146 | bool fXtNeedsUpdate;
|
---|
147 | #endif
|
---|
148 | } SHCLX11CTX, *PSHCLX11CTX;
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Structure for keeping a X11 read data request.
|
---|
152 | */
|
---|
153 | typedef struct _SHCLX11READDATAREQ
|
---|
154 | {
|
---|
155 | /** Actual read request to handle. */
|
---|
156 | CLIPREADCBREQ *pReq;
|
---|
157 | /** Result code of the operation on completion. */
|
---|
158 | int rcCompletion;
|
---|
159 | } SHCLX11READDATAREQ;
|
---|
160 | /** Pointer to a send data request. */
|
---|
161 | typedef SHCLX11READDATAREQ *PSHCLX11READDATAREQ;
|
---|
162 |
|
---|
163 | /** @name Shared Clipboard APIs for X11.
|
---|
164 | * @{
|
---|
165 | */
|
---|
166 | int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks, PSHCLCONTEXT pParent, bool fHeadless);
|
---|
167 | void ShClX11Destroy(PSHCLX11CTX pCtx);
|
---|
168 | int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
|
---|
169 | int ShClX11ThreadStartEx(PSHCLX11CTX pCtx, const char *pszName, bool fGrab);
|
---|
170 | int ShClX11ThreadStop(PSHCLX11CTX pCtx);
|
---|
171 | int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
|
---|
172 | int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
|
---|
173 | void ShClX11SetCallbacks(PSHCLX11CTX pCtx, PSHCLCALLBACKS pCallbacks);
|
---|
174 | /** @} */
|
---|
175 |
|
---|
176 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
|
---|
177 |
|
---|