VirtualBox

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

最後變更 在這個檔案從93460是 93321,由 vboxsync 提交於 3 年 前

Shared Clipboard/X11: Renamed mandatory (own) X11 callbacks to better point out the data flow, added some docs.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.9 KB
 
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.alldomusa.eu.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 */
56typedef 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 */
73typedef 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. */
86typedef unsigned SHCLX11FMTIDX;
87
88/**
89 * Structure for maintaining a Shared Clipboard context on X11 platforms.
90 */
91typedef struct _SHCLX11CTX
92{
93 /** Opaque data structure describing the front-end. */
94 PSHCLCONTEXT pFrontend;
95 /** Is an X server actually available? */
96 bool fHaveX11;
97 /** The X Toolkit application context structure. */
98 XtAppContext pAppContext;
99
100 /** We have a separate thread to wait for window and clipboard events. */
101 RTTHREAD Thread;
102 /** Flag indicating that the thread is in a started state. */
103 bool fThreadStarted;
104
105 /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
106 Widget pWidget;
107
108 /** Should we try to grab the clipboard on startup? */
109 bool fGrabClipboardOnStart;
110
111 /** The best text format X11 has to offer, as an index into the formats table. */
112 SHCLX11FMTIDX idxFmtText;
113 /** The best bitmap format X11 has to offer, as an index into the formats table. */
114 SHCLX11FMTIDX idxFmtBmp;
115 /** The best HTML format X11 has to offer, as an index into the formats table. */
116 SHCLX11FMTIDX idxFmtHTML;
117#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
118 /** The best HTML format X11 has to offer, as an index into the formats table. */
119 SHCLX11FMTIDX idxFmtURI;
120# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
121 /** HTTP transfer context data. */
122 SHCLHTTPCONTEXT HttpCtx;
123# endif
124#endif
125 /** What kind of formats does VBox have to offer? */
126 SHCLFORMATS vboxFormats;
127 /** Cache of the last unicode data that we received. */
128 void *pvUnicodeCache;
129 /** Size of the unicode data in the cache. */
130 uint32_t cbUnicodeCache;
131 /** When we wish the clipboard to exit, we have to wake up the event
132 * loop. We do this by writing into a pipe. This end of the pipe is
133 * the end that another thread can write to. */
134 int wakeupPipeWrite;
135 /** The reader end of the pipe. */
136 int wakeupPipeRead;
137 /** A pointer to the XFixesSelectSelectionInput function. */
138 void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
139 /** The first XFixes event number. */
140 int fixesEventBase;
141#ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
142 /** XtGetSelectionValue on some versions of libXt isn't re-entrant
143 * so block overlapping requests on this flag. */
144 bool fXtBusy;
145 /** If a request is blocked on the previous flag, set this flag to request
146 * an update later - the first callback should check and clear this flag
147 * before processing the callback event. */
148 bool fXtNeedsUpdate;
149#endif
150} SHCLX11CTX, *PSHCLX11CTX;
151
152/** @name Shared Clipboard APIs for X11.
153 * @{
154 */
155int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCONTEXT pParent, bool fHeadless);
156void ShClX11Destroy(PSHCLX11CTX pCtx);
157int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
158int ShClX11ThreadStop(PSHCLX11CTX pCtx);
159int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
160int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
161/** @} */
162
163/** @name Shared Clipboard callbacks which have to be implemented by tools using the X11
164 * clipboard, e.g. VBoxClient (on guest side) or the X11 host service backend.
165 * @{
166 */
167/**
168 * Callback for reporting supported formats of current clipboard data from X11 to VBox.
169 *
170 * @note Runs in Xt event thread.
171 *
172 * @param pCtx Opaque context pointer for the glue code.
173 * @param fFormats The formats available.
174 */
175DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats);
176
177/**
178 * Callback for requesting clipboard data for X11.
179 * The function will be invoked for every single target the clipboard requests.
180 *
181 * @note Runs in Xt event thread.
182 *
183 * @returns VBox status code. VERR_NO_DATA if no data available.
184 * @param pCtx Pointer to the host clipboard structure.
185 * @param uFmt The format in which the data should be transferred
186 * (VBOX_SHCL_FMT_XXX).
187 * @param ppv Returns an allocated buffer with data read from the guest on success.
188 * Needs to be free'd with RTMemFree() by the caller.
189 * @param pcb Returns the amount of data read (in bytes) on success.
190 */
191DECLCALLBACK(int) ShClX11RequestDataCallback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb);
192
193/**
194 * Callback for reporting that clipboard data from X11 is available.
195 *
196 * @param pCtx Our context information.
197 * @param rcCompletion The completion status of the request.
198 * @param pReq The request structure that we passed in when we started
199 * the request. We RTMemFree() this in this function.
200 * @param pv The clipboard data returned from X11 if the request succeeded (see @a rcCompletion).
201 * @param cb The size of the data in @a pv.
202 */
203DECLCALLBACK(void) ShClX11ReportDataCallback(PSHCLCONTEXT pCtx, int rcCompletion,
204 CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
205/** @} */
206
207#endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
208
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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