1 | /** @file
|
---|
2 | * Shared Clipboard - Common X11 code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2019 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 | /** The different clipboard formats which we support. */
|
---|
39 | enum CLIPFORMAT
|
---|
40 | {
|
---|
41 | INVALID = 0,
|
---|
42 | TARGETS,
|
---|
43 | TEXT, /* Treat this as UTF-8, but it may really be ascii */
|
---|
44 | UTF8,
|
---|
45 | BMP,
|
---|
46 | HTML
|
---|
47 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
48 | , URI_LIST
|
---|
49 | #endif
|
---|
50 | };
|
---|
51 |
|
---|
52 | /** Defines a single X11 clipboad format. */
|
---|
53 | typedef unsigned CLIPX11FORMAT;
|
---|
54 |
|
---|
55 | /** Prototype for the implementation-specfic Shared Clipboard context. */
|
---|
56 | struct _SHCLCONTEXT;
|
---|
57 | typedef SHCLCONTEXT _SHCLCONTEXT;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Structure for maintaining a Shared Clipboard context on X11 platforms.
|
---|
61 | */
|
---|
62 | typedef struct _SHCLX11CTX
|
---|
63 | {
|
---|
64 | /** Opaque data structure describing the front-end. */
|
---|
65 | SHCLCONTEXT *pFrontend;
|
---|
66 | /** Is an X server actually available? */
|
---|
67 | bool fHaveX11;
|
---|
68 | /** The X Toolkit application context structure */
|
---|
69 | XtAppContext appContext;
|
---|
70 |
|
---|
71 | /** We have a separate thread to wait for Window and Clipboard events */
|
---|
72 | RTTHREAD thread;
|
---|
73 | /** The X Toolkit widget which we use as our clipboard client. It is never made visible. */
|
---|
74 | Widget widget;
|
---|
75 |
|
---|
76 | /** Should we try to grab the clipboard on startup? */
|
---|
77 | bool fGrabClipboardOnStart;
|
---|
78 |
|
---|
79 | /** The best text format X11 has to offer, as an index into the formats
|
---|
80 | * table */
|
---|
81 | CLIPX11FORMAT X11TextFormat;
|
---|
82 | /** The best bitmap format X11 has to offer, as an index into the formats
|
---|
83 | * table */
|
---|
84 | CLIPX11FORMAT X11BitmapFormat;
|
---|
85 | /** The best HTML format X11 has to offer, as an index into the formats
|
---|
86 | * table */
|
---|
87 | CLIPX11FORMAT X11HTMLFormat;
|
---|
88 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
89 | /** The best HTML format X11 has to offer, as an index into the formats
|
---|
90 | * table */
|
---|
91 | CLIPX11FORMAT X11URIListFormat;
|
---|
92 | #endif
|
---|
93 | /** What kind of formats does VBox have to offer? */
|
---|
94 | SHCLFORMATS vboxFormats;
|
---|
95 | /** Cache of the last unicode data that we received */
|
---|
96 | void *pvUnicodeCache;
|
---|
97 | /** Size of the unicode data in the cache */
|
---|
98 | uint32_t cbUnicodeCache;
|
---|
99 | /** When we wish the clipboard to exit, we have to wake up the event
|
---|
100 | * loop. We do this by writing into a pipe. This end of the pipe is
|
---|
101 | * the end that another thread can write to. */
|
---|
102 | int wakeupPipeWrite;
|
---|
103 | /** The reader end of the pipe */
|
---|
104 | int wakeupPipeRead;
|
---|
105 | /** A pointer to the XFixesSelectSelectionInput function */
|
---|
106 | void (*fixesSelectInput)(Display *, Window, Atom, unsigned long);
|
---|
107 | /** The first XFixes event number */
|
---|
108 | int fixesEventBase;
|
---|
109 | } SHCLX11CTX, *PSHCLX11CTX;
|
---|
110 |
|
---|
111 | /** @name Shared Clipboard APIs for X11.
|
---|
112 | * @{
|
---|
113 | */
|
---|
114 | int ShClX11Init(PSHCLX11CTX pCtx, PSHCLCONTEXT pParent, bool fHeadless);
|
---|
115 | void ShClX11Destroy(PSHCLX11CTX pCtx);
|
---|
116 | int ShClX11ThreadStart(PSHCLX11CTX pCtx, bool grab);
|
---|
117 | int ShClX11ThreadStop(PSHCLX11CTX pCtx);
|
---|
118 | int ShClX11ReportFormatsToX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormats);
|
---|
119 | int ShClX11ReadDataFromX11(PSHCLX11CTX pCtx, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
|
---|
120 | /** @} */
|
---|
121 |
|
---|
122 | /** @name Shared Clipboard callbacks exported by the X11 APIs.
|
---|
123 | * @{
|
---|
124 | */
|
---|
125 | DECLCALLBACK(int) ShClX11RequestDataForX11Callback(SHCLCONTEXT *pCtx, SHCLFORMAT Format, void **ppv, uint32_t *pcb);
|
---|
126 | DECLCALLBACK(void) ShClX11ReportFormatsCallback(SHCLCONTEXT *pCtx, SHCLFORMATS Formats);
|
---|
127 | DECLCALLBACK(void) ShClRequestFromX11CompleteCallback(SHCLCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
|
---|
128 | /** @} */
|
---|
129 |
|
---|
130 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_X11_h */
|
---|
131 |
|
---|