1 /*
2    Copyright (C) 2002-2010 Karl J. Runge <runge@karlrunge.com>
3    All rights reserved.
4 
5 This file is part of x11vnc.
6 
7 x11vnc is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or (at
10 your option) any later version.
11 
12 x11vnc is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with x11vnc; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
20 or see <http://www.gnu.org/licenses/>.
21 
22 In addition, as a special exception, Karl J. Runge
23 gives permission to link the code of its release of x11vnc with the
24 OpenSSL project's "OpenSSL" library (or with modified versions of it
25 that use the same license as the "OpenSSL" library), and distribute
26 the linked executables.  You must obey the GNU General Public License
27 in all respects for all of the code used other than "OpenSSL".  If you
28 modify this file, you may extend this exception to your version of the
29 file, but you are not obligated to do so.  If you do not wish to do
30 so, delete this exception statement from your version.
31 */
32 
33 /* -- x11vnc_defs.c -- */
34 
35 #include "x11vnc.h"
36 
37 int overlay_present = 0;
38 int xcomposite_present = 0;
39 int use_xcomposite = 1;
40 
41 int xrandr_base_event_type = 0;
42 
43 int xfixes_base_event_type = 0;
44 int xtest_base_event_type = 0;
45 #if HAVE_LIBXTRAP
46 XETC *trap_ctx = NULL;
47 #endif
48 int xtrap_base_event_type = 0;
49 int xdamage_base_event_type = 0;
50 
51 /*               date +'lastmod: %Y-%m-%d' */
52 char lastmod[] = VERSION " lastmod: 2019-01-05";
53 
54 /* X display info */
55 
56 Display *dpy = NULL;		/* the single display screen we connect to */
57 int scr = 0;
58 char *xauth_raw_data = NULL;
59 int xauth_raw_len = 0;
60 Window window = None, rootwin = None;	/* polled window, root window (usu. same) */
61 Visual *default_visual = NULL;	/* the default visual (unless -visual) */
62 int bpp = 0, depth = 0;
63 int indexed_color = 0;
64 int dpy_x = 0, dpy_y = 0;		/* size of display */
65 int fb_x = 0, fb_y = 0, fb_b = 0;	/* fb size and bpp guesses at display */
66 int off_x, off_y;		/* offsets for -sid */
67 int wdpy_x, wdpy_y;		/* for actual sizes in case of -clip */
68 int cdpy_x, cdpy_y, coff_x, coff_y;	/* the -clip params */
69 int button_mask = 0;		/* button state and info */
70 int button_mask_prev = 0;
71 int num_buttons = -1;
72 
73 int is_wayland_session = 0; /* set to 1 if we're running under a wayland session */
74 
75 long xselectinput_rootwin = 0;
76 
77 unsigned int display_button_mask = 0;
78 unsigned int display_mod_mask = 0;
79 
80 /* image structures */
81 XImage *scanline = NULL;
82 XImage *fullscreen = NULL;
83 XImage **tile_row = NULL;	/* for all possible row runs */
84 XImage *snaprect = NULL;	/* for XShmGetImage (fs_factor) */
85 XImage *snap = NULL;		/* the full snap fb */
86 XImage *raw_fb_image = NULL;	/* the raw fb */
87 
88 /* corresponding shm structures */
89 XShmSegmentInfo scanline_shm;
90 XShmSegmentInfo fullscreen_shm;
91 XShmSegmentInfo *tile_row_shm;	/* for all possible row runs */
92 XShmSegmentInfo snaprect_shm;
93 
94 /* rfb screen info */
95 rfbScreenInfoPtr screen = NULL;
96 char *rfb_desktop_name = NULL;
97 char *http_dir = NULL;
98 char vnc_desktop_name[256];
99 char *main_fb = NULL;		/* our copy of the X11 fb */
100 char *rfb_fb = NULL;		/* same as main_fb unless transformation */
101 char *fake_fb = NULL;		/* used under -padgeom */
102 char *snap_fb = NULL;		/* used under -snapfb */
103 char *cmap8to24_fb = NULL;	/* used under -8to24 */
104 char *rot_fb = NULL;
105 char *raw_fb = NULL;		/* when used should be main_fb */
106 char *raw_fb_addr = NULL;
107 int raw_fb_offset = 0;
108 int raw_fb_shm = 0;
109 int raw_fb_mmap = 0;
110 int raw_fb_seek = 0;
111 int raw_fb_fd = -1;
112 int raw_fb_back_to_X = 0;	/* kludge for testing rawfb -> X */
113 
114 int raw_fb_native_bpp = 0;
115 int raw_fb_expand_bytes = 1;
116 unsigned long  raw_fb_native_red_mask = 0,  raw_fb_native_green_mask = 0,  raw_fb_native_blue_mask = 0;
117 unsigned short raw_fb_native_red_max = 0,   raw_fb_native_green_max = 0,   raw_fb_native_blue_max = 0;
118 unsigned short raw_fb_native_red_shift = 0, raw_fb_native_green_shift = 0, raw_fb_native_blue_shift = 0;
119 
120 int rfb_bytes_per_line = 0;
121 int main_bytes_per_line = 0;
122 int rot_bytes_per_line = 0;
123 unsigned long  main_red_mask = 0,  main_green_mask = 0,  main_blue_mask = 0;
124 unsigned short main_red_max = 0,   main_green_max = 0,   main_blue_max = 0;
125 unsigned short main_red_shift = 0, main_green_shift = 0, main_blue_shift = 0;
126 
127 int raw_fb_bytes_per_line = 0;
128 
129 /* scaling parameters */
130 char *scale_str = NULL;
131 double scale_fac_x = 1.0;
132 double scale_fac_y = 1.0;
133 int scaling = 0;
134 int scaling_blend = 1;		/* for no blending option (very course) */
135 int scaling_nomult4 = 0;	/* do not require width = n * 4 */
136 int scaling_pad = 0;		/* pad out scaled sizes to fit denominator */
137 int scaling_interpolate = 0;	/* use interpolation scheme when shrinking */
138 int scaled_x = 0, scaled_y = 0;	/* dimensions of scaled display */
139 int scale_numer = 0, scale_denom = 0;	/* n/m */
140 char *rotating_str = NULL;
141 int rotating = 0;
142 int rotating_same = 0;
143 int rotating_cursors = 0;
144 
145 /* scale cursor */
146 char *scale_cursor_str = NULL;
147 double scale_cursor_fac_x = 1.0;
148 double scale_cursor_fac_y = 1.0;
149 int scaling_cursor = 0;
150 int scaling_cursor_blend = 1;
151 int scaling_cursor_interpolate = 0;
152 int scale_cursor_numer = 0, scale_cursor_denom = 0;
153 
154 /* size of the basic tile unit that is polled for changes: */
155 int tile_x = 32;
156 int tile_y = 32;
157 int ntiles, ntiles_x = 0, ntiles_y = 0;
158 
159 /* arrays that indicate changed or checked tiles. */
160 unsigned char *tile_has_diff = NULL, *tile_tried = NULL, *tile_copied = NULL;
161 unsigned char *tile_has_xdamage_diff = NULL, *tile_row_has_xdamage_diff = NULL;
162 
163 /* times of recent events */
164 time_t last_event = 0, last_input = 0, last_client = 0, last_open_xdisplay = 0;
165 time_t last_local_input = 0;
166 time_t last_keyboard_input = 0, last_pointer_input = 0;
167 time_t last_fb_bytes_sent = 0;
168 double last_keyboard_time = 0.0;
169 double last_pointer_time = 0.0;
170 double last_pointer_click_time = 0.0;
171 double last_pointer_motion_time = 0.0;
172 double last_key_to_button_remap_time = 0.0;
173 double last_copyrect = 0.0;
174 double last_copyrect_fix = 0.0;
175 double last_wireframe = 0.0;
176 double servertime_diff = 0.0;
177 double x11vnc_start = 0.0;
178 double x11vnc_current = 0.0;
179 double g_now = 0.0;
180 
181 double last_get_wm_frame_time = 0.0;
182 Window last_get_wm_frame = None;
183 double last_bs_restore = 0.0;
184 double last_su_restore = 0.0;
185 double last_bs_save = 0.0;
186 double last_su_save = 0.0;
187 
188 int hack_val = 0;
189 
190 /* last client to move pointer */
191 rfbClientPtr last_pointer_client = NULL;
192 rfbClientPtr latest_client = NULL;
193 double last_client_gone = 0.0;
194 double last_new_client = 0.0;
195 
196 int waited_for_client = 0;
197 int findcreatedisplay = 0;
198 char *terminal_services_daemon = NULL;
199 
200 int client_count = 0;
201 int clients_served = 0;
202 int client_normal_count = 0;
203 
204 /* more transient kludge variables: */
205 int cursor_x = 0, cursor_y = 0;		/* x and y from the viewer(s) */
206 int button_change_x = 0, button_change_y = 0;
207 int got_user_input = 0;
208 int got_pointer_input = 0;
209 int got_local_pointer_input = 0;
210 int got_pointer_calls = 0;
211 int got_keyboard_input = 0;
212 int got_keyboard_calls = 0;
213 int urgent_update = 0;
214 int last_keyboard_keycode = 0;
215 rfbBool last_rfb_down = FALSE;
216 rfbBool last_rfb_key_accepted = FALSE;
217 rfbKeySym last_rfb_keysym = 0;
218 double last_rfb_keytime = 0.0;
219 double last_rfb_key_injected = 0.0;
220 double last_rfb_ptr_injected = 0.0;
221 int fb_copy_in_progress = 0;
222 int drag_in_progress = 0;
223 int shut_down = 0;
224 int do_copy_screen = 0;
225 time_t damage_time = 0;
226 int damage_delay = 0;
227 
228 int program_pid = 0;
229 char *program_name = NULL;
230 char *program_cmdline = NULL;
231 
232 struct utsname UT;
233 
234 
235