disabled auto start
[platform/adaptation/emulator/spice-vdagent.git] / src / vdagent-x11-priv.h
1 #ifndef VDAGENT_X11_PRIV
2 #define VDAGENT_X11_PRIV
3
4 #include <stdint.h>
5 #include <stdio.h>
6
7 #include <spice/vd_agent.h>
8
9 #include <X11/extensions/Xrandr.h>
10
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__)
15
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)
23
24 #define MAX_SCREENS 16
25 /* Same as qxl_dev.h client_monitors_config.heads count */
26 #define MONITOR_SIZE_COUNT 64
27
28 enum { owner_none, owner_guest, owner_client };
29
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;
38 };
39
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;
48 };
49
50 struct clipboard_format_tmpl {
51     uint32_t type;
52     const char *atom_names[16];
53 };
54
55 struct clipboard_format_info {
56     uint32_t type;
57     Atom atoms[16];
58     int atom_count;
59 };
60
61 struct monitor_size {
62     int width;
63     int height;
64 };
65
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 }, },
74 };
75
76 #define clipboard_format_count (sizeof(clipboard_format_templates)/sizeof(clipboard_format_templates[0]))
77
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     Window root_window[MAX_SCREENS];
87     Window selection_window;
88     struct udscs_connection *vdagentd;
89     char *net_wm_name;
90     int debug;
91     int fd;
92     int screen_count;
93     int width[MAX_SCREENS];
94     int height[MAX_SCREENS];
95     int has_xfixes;
96     int xfixes_event_base;
97     int max_prop_size;
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 */
116     struct {
117         XRRScreenResources *res;
118         XRROutputInfo **outputs;
119         XRRCrtcInfo **crtcs;
120         int min_width;
121         int max_width;
122         int min_height;
123         int max_height;
124         int num_monitors;
125         struct monitor_size monitor_sizes[MONITOR_SIZE_COUNT];
126         VDAgentMonitorsConfig *failed_conf;
127     } randr;
128
129     /* NB: we cache this assuming the driver isn't changed under our feet */
130     int set_crtc_config_not_functional;
131
132     int has_xrandr;
133     int xrandr_major;
134     int xrandr_minor;
135     int has_xinerama;
136     int dont_send_guest_xorg_res;
137 };
138
139 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
140 extern int vdagent_x11_caught_error;
141
142 void vdagent_x11_randr_init(struct vdagent_x11 *x11);
143 void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
144                                             int update);
145 void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
146                                             int screen, int width, int height);
147
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);
151
152 #endif // VDAGENT_X11_PRIV