build-sys: move user/system to respective dir
[vd_agent.git] / src / vdagent / vdagent-x11-priv.h
blobd60cc07d85b334edd90eec408d4148015bdd37e8
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", "text/plain;charset=UTF-8",
68 "text/plain;charset=utf-8", "STRING", 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 xrandr_event_base;
99 int max_prop_size;
100 int expected_targets_notifies[256];
101 int clipboard_owner[256];
102 int clipboard_type_count[256];
103 uint32_t clipboard_agent_types[256][256];
104 Atom clipboard_x11_targets[256][256];
105 /* Data for conversion_req which is currently being processed */
106 struct vdagent_x11_conversion_request *conversion_req;
107 int expect_property_notify;
108 uint8_t *clipboard_data;
109 uint32_t clipboard_data_size;
110 uint32_t clipboard_data_space;
111 /* Data for selection_req which is currently being processed */
112 struct vdagent_x11_selection_request *selection_req;
113 uint8_t *selection_req_data;
114 uint32_t selection_req_data_pos;
115 uint32_t selection_req_data_size;
116 Atom selection_req_atom;
117 /* resolution change state */
118 struct {
119 XRRScreenResources *res;
120 XRROutputInfo **outputs;
121 XRRCrtcInfo **crtcs;
122 int min_width;
123 int max_width;
124 int min_height;
125 int max_height;
126 int num_monitors;
127 struct monitor_size monitor_sizes[MONITOR_SIZE_COUNT];
128 VDAgentMonitorsConfig *failed_conf;
129 } randr;
131 /* NB: we cache this assuming the driver isn't changed under our feet */
132 int set_crtc_config_not_functional;
134 int has_xrandr;
135 int xrandr_major;
136 int xrandr_minor;
137 int has_xinerama;
138 int dont_send_guest_xorg_res;
141 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
142 extern int vdagent_x11_caught_error;
144 void vdagent_x11_randr_init(struct vdagent_x11 *x11);
145 void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
146 int update);
147 void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
148 int screen, int width, int height);
149 int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
150 XEvent event);
151 void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
152 int (*handler)(Display *, XErrorEvent *));
153 int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
155 #endif // VDAGENT_X11_PRIV