1 | /** @file
|
---|
2 | * Shared Clipboard - Common X11 code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2020 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 |
|
---|
38 | /** Enables the Xt busy / update handling. */
|
---|
39 | #define VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY 1
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Enumeration for all clipboard formats which we support on X11.
|
---|
43 | */
|
---|
44 | typedef enum _SHCLX11FMT
|
---|
45 | {
|
---|
46 | SHCLX11FMT_INVALID = 0,
|
---|
47 | SHCLX11FMT_TARGETS,
|
---|
48 | SHCLX11FMT_TEXT, /* Treat this as UTF-8, but it may really be ascii */
|
---|
49 | SHCLX11FMT_UTF8,
|
---|
50 | SHCLX11FMT_BMP,
|
---|
51 | SHCLX11FMT_HTML
|
---|
52 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
53 | , SHCLX11FMT_URI_LIST
|
---|
54 | #endif
|
---|
55 | } SHCLX11FMT;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * The table maps X11 names to data formats
|
---|
59 | * and to the corresponding VBox clipboard formats.
|
---|
60 | */
|
---|
61 | typedef struct SHCLX11FMTTABLE
|
---|
62 | {
|
---|
63 | /** The X11 atom name of the format (several names can match one format). */
|
---|
64 | const char *pcszAtom;
|
---|
65 | /** The format corresponding to the name. */
|
---|
66 | SHCLX11FMT enmFmtX11;
|
---|
67 | /** The corresponding VBox clipboard format. */
|
---|
68 | SHCLFORMAT uFmtVBox;
|
---|
69 | } SHCLX11FMTTABLE;
|
---|
70 |
|
---|
71 | #define NIL_CLIPX11FORMAT 0
|
---|
72 |
|
---|
73 | /** Defines an index of the X11 clipboad format table. */
|
---|
74 | typedef unsigned SHCLX11FMTIDX;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Structure for maintaining a Shared Clipboard context on X11 platforms.
|
---|
78 | */
|
---|
79 | typedef struct _SHCLX11CTX
|
---|
80 | {
|
---|
81 | /** Opaque data structure describing the front-end. */
|
---|
82 | PSHCLCONTEXT pFrontend;
|
---|
83 | /** Is an X server actually available? */
|
---|
84 | bool fHaveX11;
|
---|
85 | /** The X Toolkit application context structure. */
|
---|
86 | XtAppContext pAppContext;
|
---|
87 |
|
---|
88 | /** We have a separate thread to wait for window and clipboard events. */
|
---|
89 | RTTHREAD Thread;
|
---|
90 | /** Flag indicating that the thread is in a started state. */
|
---|
91 | bool fThreadStarted;
|
---|
92 |
|
---|
93 | /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
|
---|
94 | Widget pWidget;
|
---|
95 |
|
---|
96 | /** Should we try to grab the clipboard on startup? */
|
---|
97 | bool fGrabClipboardOnStart;
|
---|
98 |
|
---|
99 | /** The best text format X11 has to offer, as an index into the formats table. */
|
---|
100 | SHCLX11FMTIDX idxFmtText;
|
---|
101 | /** The best bitmap format X11 has to offer, as an index into the formats table. */
|
---|
102 | SHCLX11FMTIDX idxFmtBmp;
|
---|
103 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
104 | SHCLX11FMTIDX idxFmtHTML;
|
---|
105 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
106 | /** The best HTML format X11 has to offer, as an index into the formats table. */
|
---|
107 | SHCLX11FMTIDX idxFmtURI;
|
---|
108 | #endif
|
---|
109 | /** What kind of formats does VBox have to offer? */
|
---|
110 | SHCLFORMATS vboxFormats;
|
---|
111 | /** Cache of the last unicode data that we received. */
|
---|
112 | void *pvUnicodeCache;
|
---|
113 | /** Size of the unicode data in the cache. */
|
---|
114 | uint32_t cbUnicodeCache;
|
---|
115 | /** When we wish the clipboard to exit, we have to wake up the event
|
---|
116 | * loop. We do this by writing into a pipe. This end of the pipe is
|
---|
117 | * the end that another thread can write to. */
|
---|
118 | int wakeupPipeWrite;
|
---|
119 | /** The reader end of the pipe. */
|
---|
120 | int wakeupPipeRead;
|
---|
121 | /** A pointer to the XFixesSelectSelectionInput function. */
|
---|
122 | void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
|
---|
123 | /** The first XFixes event number. */
|
---|
124 | int fixesEventBase;
|
---|
125 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_XT_BUSY
|
---|
126 | /** XtGetSelectionValue on some versions of libXt isn't re-entrant
|
---|
127 | * so block overlapping requests on this flag. */
|
---|
128 | bool fXtBusy;
|
---|
129 | /** If a request is blocked on the previous flag, set this flag to request
|
---|
130 | * an update later - the first callback should check and clear this flag
|
---|
131 | * before processing the callback event. */
|
---|
132 | bool fXtNeedsUpdate;
|
---|
133 | #endif
|
---|
134 | } SHCLX11CTX, *PSHCLX11CTX;
|
---|
135 |
|
---|
136 | /** @name Shared Clipboard APIs for X11.
|
---|
137 | * @{
|
---|
138 | */
|
---|
139 | int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCONTEXT pParent, bool fHeadless);
|
---|
140 | void ShClX11Destroy(PSHCLX11CTX pCtx);
|
---|
141 | int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
|
---|
142 | int ShClX11ThreadStop(PSHCLX11CTX pCtx);
|
---|
143 | int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
|
---|
144 | int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
|
---|
145 | /** @} */
|
---|
146 |
|
---|
147 | /** @name Shared Clipboard callbacks which have to be implemented the X11 backend and host service.
|
---|
148 | * @{
|
---|
149 | */
|
---|
150 | DECLCALLBACK(int) ShClX11RequestDataForX11Callback(SHCLCONTEXT *pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb);
|
---|
151 | DECLCALLBACK(void) ShClX11ReportFormatsCallback(SHCLCONTEXT *pCtx, SHCLFORMATS fFormats);
|
---|
152 | DECLCALLBACK(void) ShClX11RequestFromX11CompleteCallback(SHCLCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
|
---|
153 | /** @} */
|
---|
154 |
|
---|
155 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_x11_h */
|
---|
156 |
|
---|