1 #ifndef VDAGENT_X11_PRIV
2 #define VDAGENT_X11_PRIV
7 #include <spice/vd_agent.h>
9 #include <X11/extensions/Xrandr.h>
11 /* Macros to print a message to the logfile prefixed by the selection */
12 #define SELPRINTF(format, ...) \
13 syslog(LOG_ERR, "%s: " format, \
14 vdagent_x11_sel_to_str(selection), ##__VA_ARGS__)
16 #define VSELPRINTF(format, ...) \
19 syslog(LOG_DEBUG, "%s: " format, \
20 vdagent_x11_sel_to_str(selection), ##__VA_ARGS__); \
24 #define MAX_SCREENS 16
25 /* Same as qxl_dev.h client_monitors_config.heads count */
26 #define MONITOR_SIZE_COUNT 64
28 enum { owner_none, owner_guest, owner_client };
30 /* X11 terminology is confusing a selection request is a request from an
31 app to get clipboard data from us, so iow from the spice client through
32 the vdagent channel. We handle these one at a time and queue any which
33 come in while we are still handling the current one. */
34 struct vdagent_x11_selection_request {
37 struct vdagent_x11_selection_request *next;
40 /* A conversion request is X11 speak for asking an other app to give its
41 clipboard data to us, we do these on behalf of the spice client to copy
42 data from the guest to the client. Like selection requests we process
43 these one at a time. */
44 struct vdagent_x11_conversion_request {
47 struct vdagent_x11_conversion_request *next;
50 struct clipboard_format_tmpl {
52 const char *atom_names[16];
55 struct clipboard_format_info {
66 static const struct clipboard_format_tmpl clipboard_format_templates[] = {
67 { VD_AGENT_CLIPBOARD_UTF8_TEXT, { "UTF8_STRING",
68 "text/plain;charset=UTF-8", "text/plain;charset=utf-8", NULL }, },
69 { VD_AGENT_CLIPBOARD_IMAGE_PNG, { "image/png", NULL }, },
70 { VD_AGENT_CLIPBOARD_IMAGE_BMP, { "image/bmp", "image/x-bmp",
71 "image/x-MS-bmp", "image/x-win-bitmap", NULL }, },
72 { VD_AGENT_CLIPBOARD_IMAGE_TIFF, { "image/tiff", NULL }, },
73 { VD_AGENT_CLIPBOARD_IMAGE_JPG, { "image/jpeg", NULL }, },
76 #define clipboard_format_count (sizeof(clipboard_format_templates)/sizeof(clipboard_format_templates[0]))
79 struct clipboard_format_info clipboard_formats[clipboard_format_count];
82 Atom clipboard_primary_atom;
86 Window root_window[MAX_SCREENS];
87 Window selection_window;
88 struct udscs_connection *vdagentd;
93 int width[MAX_SCREENS];
94 int height[MAX_SCREENS];
96 int xfixes_event_base;
98 int expected_targets_notifies[256];
99 int clipboard_owner[256];
100 int clipboard_type_count[256];
101 uint32_t clipboard_agent_types[256][256];
102 Atom clipboard_x11_targets[256][256];
103 /* Data for conversion_req which is currently being processed */
104 struct vdagent_x11_conversion_request *conversion_req;
105 int expect_property_notify;
106 uint8_t *clipboard_data;
107 uint32_t clipboard_data_size;
108 uint32_t clipboard_data_space;
109 /* Data for selection_req which is currently being processed */
110 struct vdagent_x11_selection_request *selection_req;
111 uint8_t *selection_req_data;
112 uint32_t selection_req_data_pos;
113 uint32_t selection_req_data_size;
114 Atom selection_req_atom;
115 /* resolution change state */
117 XRRScreenResources *res;
118 XRROutputInfo **outputs;
125 struct monitor_size monitor_sizes[MONITOR_SIZE_COUNT];
126 VDAgentMonitorsConfig *failed_conf;
129 /* NB: we cache this assuming the driver isn't changed under our feet */
130 int set_crtc_config_not_functional;
136 int dont_send_guest_xorg_res;
139 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
140 extern int vdagent_x11_caught_error;
142 void vdagent_x11_randr_init(struct vdagent_x11 *x11);
143 void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
145 void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
146 int screen, int width, int height);
148 void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
149 int (*handler)(Display *, XErrorEvent *));
150 int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
152 #endif // VDAGENT_X11_PRIV