Reply to TIMESTAMP requests
[vd_agent.git] / src / vdagent-x11-priv.h
blob4a5729b487f3328bc0e5d5513b18a5c30f6a05ef
1 #ifndef VDAGENT_X11_PRIV
2 #define VDAGENT_X11_PRIV
4 #include <stdint.h>
5 #include <stdio.h>
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, ...) \
17 do { \
18 if (x11->debug) { \
19 syslog(LOG_DEBUG, "%s: " format, \
20 vdagent_x11_sel_to_str(selection), ##__VA_ARGS__); \
21 } \
22 } while (0)
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 {
35 XEvent event;
36 uint8_t selection;
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 {
45 Atom target;
46 uint8_t selection;
47 struct vdagent_x11_conversion_request *next;
50 struct clipboard_format_tmpl {
51 uint32_t type;
52 const char *atom_names[16];
55 struct clipboard_format_info {
56 uint32_t type;
57 Atom atoms[16];
58 int atom_count;
61 struct monitor_size {
62 int width;
63 int height;
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]))
78 struct vdagent_x11 {
79 struct clipboard_format_info clipboard_formats[clipboard_format_count];
80 Display *display;
81 Atom clipboard_atom;
82 Atom clipboard_primary_atom;
83 Atom targets_atom;
84 Atom incr_atom;
85 Atom multiple_atom;
86 Atom timestamp_atom;
87 Window root_window[MAX_SCREENS];
88 Window selection_window;
89 struct udscs_connection *vdagentd;
90 char *net_wm_name;
91 int debug;
92 int fd;
93 int screen_count;
94 int width[MAX_SCREENS];
95 int height[MAX_SCREENS];
96 int has_xfixes;
97 int xfixes_event_base;
98 int max_prop_size;
99 int expected_targets_notifies[256];
100 int clipboard_owner[256];
101 int clipboard_type_count[256];
102 uint32_t clipboard_agent_types[256][256];
103 Atom clipboard_x11_targets[256][256];
104 /* Data for conversion_req which is currently being processed */
105 struct vdagent_x11_conversion_request *conversion_req;
106 int expect_property_notify;
107 uint8_t *clipboard_data;
108 uint32_t clipboard_data_size;
109 uint32_t clipboard_data_space;
110 /* Data for selection_req which is currently being processed */
111 struct vdagent_x11_selection_request *selection_req;
112 uint8_t *selection_req_data;
113 uint32_t selection_req_data_pos;
114 uint32_t selection_req_data_size;
115 Atom selection_req_atom;
116 /* resolution change state */
117 struct {
118 XRRScreenResources *res;
119 XRROutputInfo **outputs;
120 XRRCrtcInfo **crtcs;
121 int min_width;
122 int max_width;
123 int min_height;
124 int max_height;
125 int num_monitors;
126 struct monitor_size monitor_sizes[MONITOR_SIZE_COUNT];
127 VDAgentMonitorsConfig *failed_conf;
128 } randr;
130 /* NB: we cache this assuming the driver isn't changed under our feet */
131 int set_crtc_config_not_functional;
133 int has_xrandr;
134 int xrandr_major;
135 int xrandr_minor;
136 int has_xinerama;
137 int dont_send_guest_xorg_res;
140 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
141 extern int vdagent_x11_caught_error;
143 void vdagent_x11_randr_init(struct vdagent_x11 *x11);
144 void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
145 int update);
146 void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
147 int screen, int width, int height);
149 void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
150 int (*handler)(Display *, XErrorEvent *));
151 int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
153 #endif // VDAGENT_X11_PRIV