Home | History | Annotate | Download | only in x11vnc
      1 /*
      2    Copyright (C) 2002-2010 Karl J. Runge <runge (at) 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 
     39 int xrandr_base_event_type = 0;
     40 
     41 int xfixes_base_event_type = 0;
     42 int xtest_base_event_type = 0;
     43 #if LIBVNCSERVER_HAVE_LIBXTRAP
     44 XETC *trap_ctx = NULL;
     45 #endif
     46 int xtrap_base_event_type = 0;
     47 int xdamage_base_event_type = 0;
     48 
     49 /*               date +'lastmod: %Y-%m-%d' */
     50 char lastmod[] = "0.9.13 lastmod: 2010-12-27";
     51 
     52 /* X display info */
     53 
     54 Display *dpy = NULL;		/* the single display screen we connect to */
     55 int scr = 0;
     56 char *xauth_raw_data = NULL;
     57 int xauth_raw_len = 0;
     58 Window window = None, rootwin = None;	/* polled window, root window (usu. same) */
     59 Visual *default_visual = NULL;	/* the default visual (unless -visual) */
     60 int bpp = 0, depth = 0;
     61 int indexed_color = 0;
     62 int dpy_x = 0, dpy_y = 0;		/* size of display */
     63 int fb_x = 0, fb_y = 0, fb_b = 0;	/* fb size and bpp guesses at display */
     64 int off_x, off_y;		/* offsets for -sid */
     65 int wdpy_x, wdpy_y;		/* for actual sizes in case of -clip */
     66 int cdpy_x, cdpy_y, coff_x, coff_y;	/* the -clip params */
     67 int button_mask = 0;		/* button state and info */
     68 int button_mask_prev = 0;
     69 int num_buttons = -1;
     70 
     71 long xselectinput_rootwin = 0;
     72 
     73 unsigned int display_button_mask = 0;
     74 unsigned int display_mod_mask = 0;
     75 
     76 /* image structures */
     77 XImage *scanline = NULL;
     78 XImage *fullscreen = NULL;
     79 XImage **tile_row = NULL;	/* for all possible row runs */
     80 XImage *snaprect = NULL;	/* for XShmGetImage (fs_factor) */
     81 XImage *snap = NULL;		/* the full snap fb */
     82 XImage *raw_fb_image = NULL;	/* the raw fb */
     83 
     84 /* corresponding shm structures */
     85 XShmSegmentInfo scanline_shm;
     86 XShmSegmentInfo fullscreen_shm;
     87 XShmSegmentInfo *tile_row_shm;	/* for all possible row runs */
     88 XShmSegmentInfo snaprect_shm;
     89 
     90 /* rfb screen info */
     91 rfbScreenInfoPtr screen = NULL;
     92 char *rfb_desktop_name = NULL;
     93 char *http_dir = NULL;
     94 char vnc_desktop_name[256];
     95 char *main_fb = NULL;		/* our copy of the X11 fb */
     96 char *rfb_fb = NULL;		/* same as main_fb unless transformation */
     97 char *fake_fb = NULL;		/* used under -padgeom */
     98 char *snap_fb = NULL;		/* used under -snapfb */
     99 char *cmap8to24_fb = NULL;	/* used under -8to24 */
    100 char *rot_fb = NULL;
    101 char *raw_fb = NULL;		/* when used should be main_fb */
    102 char *raw_fb_addr = NULL;
    103 int raw_fb_offset = 0;
    104 int raw_fb_shm = 0;
    105 int raw_fb_mmap = 0;
    106 int raw_fb_seek = 0;
    107 int raw_fb_fd = -1;
    108 int raw_fb_back_to_X = 0;	/* kludge for testing rawfb -> X */
    109 
    110 int raw_fb_native_bpp = 0;
    111 int raw_fb_expand_bytes = 1;
    112 unsigned long  raw_fb_native_red_mask = 0,  raw_fb_native_green_mask = 0,  raw_fb_native_blue_mask = 0;
    113 unsigned short raw_fb_native_red_max = 0,   raw_fb_native_green_max = 0,   raw_fb_native_blue_max = 0;
    114 unsigned short raw_fb_native_red_shift = 0, raw_fb_native_green_shift = 0, raw_fb_native_blue_shift = 0;
    115 
    116 int rfb_bytes_per_line = 0;
    117 int main_bytes_per_line = 0;
    118 int rot_bytes_per_line = 0;
    119 unsigned long  main_red_mask = 0,  main_green_mask = 0,  main_blue_mask = 0;
    120 unsigned short main_red_max = 0,   main_green_max = 0,   main_blue_max = 0;
    121 unsigned short main_red_shift = 0, main_green_shift = 0, main_blue_shift = 0;
    122 
    123 int raw_fb_bytes_per_line = 0;
    124 
    125 /* scaling parameters */
    126 char *scale_str = NULL;
    127 double scale_fac_x = 1.0;
    128 double scale_fac_y = 1.0;
    129 int scaling = 0;
    130 int scaling_blend = 1;		/* for no blending option (very course) */
    131 int scaling_nomult4 = 0;	/* do not require width = n * 4 */
    132 int scaling_pad = 0;		/* pad out scaled sizes to fit denominator */
    133 int scaling_interpolate = 0;	/* use interpolation scheme when shrinking */
    134 int scaled_x = 0, scaled_y = 0;	/* dimensions of scaled display */
    135 int scale_numer = 0, scale_denom = 0;	/* n/m */
    136 char *rotating_str = NULL;
    137 int rotating = 0;
    138 int rotating_same = 0;
    139 int rotating_cursors = 0;
    140 
    141 /* scale cursor */
    142 char *scale_cursor_str = NULL;
    143 double scale_cursor_fac_x = 1.0;
    144 double scale_cursor_fac_y = 1.0;
    145 int scaling_cursor = 0;
    146 int scaling_cursor_blend = 1;
    147 int scaling_cursor_interpolate = 0;
    148 int scale_cursor_numer = 0, scale_cursor_denom = 0;
    149 
    150 /* size of the basic tile unit that is polled for changes: */
    151 int tile_x = 32;
    152 int tile_y = 32;
    153 int ntiles, ntiles_x = 0, ntiles_y = 0;
    154 
    155 /* arrays that indicate changed or checked tiles. */
    156 unsigned char *tile_has_diff = NULL, *tile_tried = NULL, *tile_copied = NULL;
    157 unsigned char *tile_has_xdamage_diff = NULL, *tile_row_has_xdamage_diff = NULL;
    158 
    159 /* times of recent events */
    160 time_t last_event = 0, last_input = 0, last_client = 0, last_open_xdisplay = 0;
    161 time_t last_local_input = 0;
    162 time_t last_keyboard_input = 0, last_pointer_input = 0;
    163 time_t last_fb_bytes_sent = 0;
    164 double last_keyboard_time = 0.0;
    165 double last_pointer_time = 0.0;
    166 double last_pointer_click_time = 0.0;
    167 double last_pointer_motion_time = 0.0;
    168 double last_key_to_button_remap_time = 0.0;
    169 double last_copyrect = 0.0;
    170 double last_copyrect_fix = 0.0;
    171 double last_wireframe = 0.0;
    172 double servertime_diff = 0.0;
    173 double x11vnc_start = 0.0;
    174 double x11vnc_current = 0.0;
    175 double g_now = 0.0;
    176 
    177 double last_get_wm_frame_time = 0.0;
    178 Window last_get_wm_frame = None;
    179 double last_bs_restore = 0.0;
    180 double last_su_restore = 0.0;
    181 double last_bs_save = 0.0;
    182 double last_su_save = 0.0;
    183 
    184 int hack_val = 0;
    185 
    186 /* last client to move pointer */
    187 rfbClientPtr last_pointer_client = NULL;
    188 rfbClientPtr latest_client = NULL;
    189 double last_client_gone = 0.0;
    190 double last_new_client = 0.0;
    191 
    192 int waited_for_client = 0;
    193 int findcreatedisplay = 0;
    194 char *terminal_services_daemon = NULL;
    195 
    196 int client_count = 0;
    197 int clients_served = 0;
    198 int client_normal_count = 0;
    199 
    200 /* more transient kludge variables: */
    201 int cursor_x = 0, cursor_y = 0;		/* x and y from the viewer(s) */
    202 int button_change_x = 0, button_change_y = 0;
    203 int got_user_input = 0;
    204 int got_pointer_input = 0;
    205 int got_local_pointer_input = 0;
    206 int got_pointer_calls = 0;
    207 int got_keyboard_input = 0;
    208 int got_keyboard_calls = 0;
    209 int urgent_update = 0;
    210 int last_keyboard_keycode = 0;
    211 rfbBool last_rfb_down = FALSE;
    212 rfbBool last_rfb_key_accepted = FALSE;
    213 rfbKeySym last_rfb_keysym = 0;
    214 double last_rfb_keytime = 0.0;
    215 double last_rfb_key_injected = 0.0;
    216 double last_rfb_ptr_injected = 0.0;
    217 int fb_copy_in_progress = 0;
    218 int drag_in_progress = 0;
    219 int shut_down = 0;
    220 int do_copy_screen = 0;
    221 time_t damage_time = 0;
    222 int damage_delay = 0;
    223 
    224 int program_pid = 0;
    225 char *program_name = NULL;
    226 char *program_cmdline = NULL;
    227 
    228 struct utsname UT;
    229 
    230 
    231