/[rdesktop]/sourceforge.net/trunk/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1199 by astrand, Mon Mar 27 08:17:34 2006 UTC revision 1443 by astrand, Thu Mar 6 15:39:21 2008 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X Window System     User interface services - X Window System
4     Copyright (C) Matthew Chapman 1999-2005     Copyright (C) Matthew Chapman 1999-2007
5       Copyright 2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
6    
7     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 20  Line 21 
21    
22  #include <X11/Xlib.h>  #include <X11/Xlib.h>
23  #include <X11/Xutil.h>  #include <X11/Xutil.h>
24    #include <X11/Xproto.h>
25  #include <unistd.h>  #include <unistd.h>
26  #include <sys/time.h>  #include <sys/time.h>
27  #include <time.h>  #include <time.h>
# Line 28  Line 30 
30  #include "rdesktop.h"  #include "rdesktop.h"
31  #include "xproto.h"  #include "xproto.h"
32    
 /* We can't include Xproto.h because of conflicting defines for BOOL */  
 #define X_ConfigureWindow              12  
   
33  extern int g_width;  extern int g_width;
34  extern int g_height;  extern int g_height;
35  extern int g_xpos;  extern int g_xpos;
36  extern int g_ypos;  extern int g_ypos;
37  extern int g_pos;  extern int g_pos;
38  extern BOOL g_sendmotion;  extern RD_BOOL g_sendmotion;
39  extern BOOL g_fullscreen;  extern RD_BOOL g_fullscreen;
40  extern BOOL g_grab_keyboard;  extern RD_BOOL g_grab_keyboard;
41  extern BOOL g_hide_decorations;  extern RD_BOOL g_hide_decorations;
42  extern char g_title[];  extern char g_title[];
43  /* Color depth of the RDP session.  /* Color depth of the RDP session.
44     As of RDP 5.1, it may be 8, 15, 16 or 24. */     As of RDP 5.1, it may be 8, 15, 16 or 24. */
# Line 71  typedef struct _seamless_window Line 70  typedef struct _seamless_window
70          unsigned int desktop;          unsigned int desktop;
71          struct timeval *position_timer;          struct timeval *position_timer;
72    
73          BOOL outstanding_position;          RD_BOOL outstanding_position;
74          unsigned int outpos_serial;          unsigned int outpos_serial;
75          int outpos_xoffset, outpos_yoffset;          int outpos_xoffset, outpos_yoffset;
76          int outpos_width, outpos_height;          int outpos_width, outpos_height;
77    
78            unsigned int icon_size;
79            unsigned int icon_offset;
80            char icon_buffer[32 * 32 * 4];
81    
82          struct _seamless_window *next;          struct _seamless_window *next;
83  } seamless_window;  } seamless_window;
84  static seamless_window *g_seamless_windows = NULL;  static seamless_window *g_seamless_windows = NULL;
85  static unsigned long g_seamless_focused = 0;  static unsigned long g_seamless_focused = 0;
86  static BOOL g_seamless_started = False; /* Server end is up and running */  static RD_BOOL g_seamless_started = False;      /* Server end is up and running */
87  static BOOL g_seamless_active = False;  /* We are currently in seamless mode */  static RD_BOOL g_seamless_active = False;       /* We are currently in seamless mode */
88  static BOOL g_seamless_hidden = False;  /* Desktop is hidden on server */  static RD_BOOL g_seamless_hidden = False;       /* Desktop is hidden on server */
89  extern BOOL g_seamless_rdp;  extern RD_BOOL g_seamless_rdp;
90    
91  extern uint32 g_embed_wnd;  extern uint32 g_embed_wnd;
92  BOOL g_enable_compose = False;  RD_BOOL g_enable_compose = False;
93  BOOL g_Unobscured;              /* used for screenblt */  RD_BOOL g_Unobscured;           /* used for screenblt */
94  static GC g_gc = NULL;  static GC g_gc = NULL;
95  static GC g_create_bitmap_gc = NULL;  static GC g_create_bitmap_gc = NULL;
96  static GC g_create_glyph_gc = NULL;  static GC g_create_glyph_gc = NULL;
# Line 104  static int g_bpp; Line 107  static int g_bpp;
107  static XIM g_IM;  static XIM g_IM;
108  static XIC g_IC;  static XIC g_IC;
109  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
110    /* Maps logical (xmodmap -pp) pointing device buttons (0-based) back
111       to physical (1-based) indices. */
112    static unsigned char g_pointer_log_to_phys_map[16];
113  static Cursor g_current_cursor;  static Cursor g_current_cursor;
114  static HCURSOR g_null_cursor = NULL;  static RD_HCURSOR g_null_cursor = NULL;
115  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
116  extern Atom g_net_wm_state_atom;  extern Atom g_net_wm_state_atom;
117  extern Atom g_net_wm_desktop_atom;  extern Atom g_net_wm_desktop_atom;
118  static BOOL g_focused;  static RD_BOOL g_focused;
119  static BOOL g_mouse_in_wnd;  static RD_BOOL g_mouse_in_wnd;
120  /* Indicates that:  /* Indicates that:
121     1) visual has 15, 16 or 24 depth and the same color channel masks     1) visual has 15, 16 or 24 depth and the same color channel masks
122        as its RDP equivalent (implies X server is LE),        as its RDP equivalent (implies X server is LE),
123     2) host is LE     2) host is LE
124     This will trigger an optimization whose real value is questionable.     This will trigger an optimization whose real value is questionable.
125  */  */
126  static BOOL g_compatible_arch;  static RD_BOOL g_compatible_arch;
127  /* Indicates whether RDP's bitmaps and our XImages have the same  /* Indicates whether RDP's bitmaps and our XImages have the same
128     binary format. If so, we can avoid an expensive translation.     binary format. If so, we can avoid an expensive translation.
129     Note that this can be true when g_compatible_arch is false,     Note that this can be true when g_compatible_arch is false,
# Line 128  static BOOL g_compatible_arch; Line 134  static BOOL g_compatible_arch;
134     ('host' is the machine running rdesktop; the host simply memcpy's     ('host' is the machine running rdesktop; the host simply memcpy's
135      so its endianess doesn't matter)      so its endianess doesn't matter)
136   */   */
137  static BOOL g_no_translate_image = False;  static RD_BOOL g_no_translate_image = False;
138    
139  /* endianness */  /* endianness */
140  static BOOL g_host_be;  static RD_BOOL g_host_be;
141  static BOOL g_xserver_be;  static RD_BOOL g_xserver_be;
142  static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;  static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
143  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
144    
145  /* software backing store */  /* software backing store */
146  extern BOOL g_ownbackstore;  extern RD_BOOL g_ownbackstore;
147  static Pixmap g_backstore = 0;  static Pixmap g_backstore = 0;
148    
149  /* Moving in single app mode */  /* Moving in single app mode */
150  static BOOL g_moving_wnd;  static RD_BOOL g_moving_wnd;
151  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
152  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
153  static BOOL g_using_full_workarea = False;  static RD_BOOL g_using_full_workarea = False;
154    
155  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
156  extern int g_dsp_fd;  extern RD_BOOL g_rdpsnd;
 extern BOOL g_dsp_busy;  
 extern BOOL g_rdpsnd;  
157  #endif  #endif
158    
159  /* MWM decorations */  /* MWM decorations */
# Line 242  seamless_XDrawLines(Drawable d, XPoint * Line 246  seamless_XDrawLines(Drawable d, XPoint *
246                          break; \                          break; \
247                  case 1: /* Filled */ \                  case 1: /* Filled */ \
248                          XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \                          XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \
249                          ON_ALL_SEAMLESS_WINDOWS(XCopyArea, (g_display, g_ownbackstore ? g_backstore : g_wnd, sw->wnd, g_gc, \                          ON_ALL_SEAMLESS_WINDOWS(XFillArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \
                                                             x, y, cx, cy, x-sw->xoffset, y-sw->yoffset)); \  
250                          if (g_ownbackstore) \                          if (g_ownbackstore) \
251                                  XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \                                  XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
252                          break; \                          break; \
# Line 251  seamless_XDrawLines(Drawable d, XPoint * Line 254  seamless_XDrawLines(Drawable d, XPoint *
254  }  }
255    
256  /* colour maps */  /* colour maps */
257  extern BOOL g_owncolmap;  extern RD_BOOL g_owncolmap;
258  static Colormap g_xcolmap;  static Colormap g_xcolmap;
259  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
260    
# Line 475  sw_handle_restack(seamless_window * sw) Line 478  sw_handle_restack(seamless_window * sw)
478    
479    
480  static seamless_group *  static seamless_group *
481  sw_find_group(unsigned long id, BOOL dont_create)  sw_find_group(unsigned long id, RD_BOOL dont_create)
482  {  {
483          seamless_window *sw;          seamless_window *sw;
484          seamless_group *sg;          seamless_group *sg;
# Line 580  translate_colour(uint32 colour) Line 583  translate_colour(uint32 colour)
583                          SPLITCOLOUR16(colour, pc);                          SPLITCOLOUR16(colour, pc);
584                          break;                          break;
585                  case 24:                  case 24:
586                    case 32:
587                          SPLITCOLOUR24(colour, pc);                          SPLITCOLOUR24(colour, pc);
588                          break;                          break;
589                  default:                  default:
# Line 1188  translate_image(int width, int height, u Line 1192  translate_image(int width, int height, u
1192             is only set for compatible depths, but the RDP depth might've             is only set for compatible depths, but the RDP depth might've
1193             changed during connection negotiations.             changed during connection negotiations.
1194           */           */
1195    
1196            /* todo */
1197            if (g_server_depth == 32 && g_depth == 24)
1198            {
1199                    return data;
1200            }
1201    
1202          if (g_no_translate_image)          if (g_no_translate_image)
1203          {          {
1204                  if ((g_depth == 15 && g_server_depth == 15) ||                  if ((g_depth == 15 && g_server_depth == 15) ||
# Line 1265  translate_image(int width, int height, u Line 1276  translate_image(int width, int height, u
1276          return out;          return out;
1277  }  }
1278    
1279  BOOL  static void
1280    xwin_refresh_pointer_map(void)
1281    {
1282            unsigned char phys_to_log_map[sizeof(g_pointer_log_to_phys_map)];
1283            int i, pointer_buttons;
1284    
1285            pointer_buttons = XGetPointerMapping(g_display, phys_to_log_map, sizeof(phys_to_log_map));
1286            for (i = 0; i < pointer_buttons; ++i)
1287            {
1288                    /* This might produce multiple logical buttons mapping
1289                       to a single physical one, but hey, that's
1290                       life... */
1291                    g_pointer_log_to_phys_map[phys_to_log_map[i] - 1] = i + 1;
1292            }
1293    }
1294    
1295    RD_BOOL
1296  get_key_state(unsigned int state, uint32 keysym)  get_key_state(unsigned int state, uint32 keysym)
1297  {  {
1298          int modifierpos, key, keysymMask = 0;          int modifierpos, key, keysymMask = 0;
# Line 1313  calculate_mask_weight(uint32 mask) Line 1340  calculate_mask_weight(uint32 mask)
1340          return weight;          return weight;
1341  }  }
1342    
1343  static BOOL  static RD_BOOL
1344  select_visual()  select_visual(int screen_num)
1345  {  {
1346          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
1347          int pixmap_formats_count, visuals_count;          int pixmap_formats_count, visuals_count;
# Line 1325  select_visual() Line 1352  select_visual()
1352    
1353          red_weight = blue_weight = green_weight = 0;          red_weight = blue_weight = green_weight = 0;
1354    
1355            if (g_server_depth == -1)
1356            {
1357                    g_server_depth = DisplayPlanes(g_display, DefaultScreen(g_display));
1358            }
1359    
1360          pfm = XListPixmapFormats(g_display, &pixmap_formats_count);          pfm = XListPixmapFormats(g_display, &pixmap_formats_count);
1361          if (pfm == NULL)          if (pfm == NULL)
1362          {          {
# Line 1335  select_visual() Line 1367  select_visual()
1367    
1368          /* Search for best TrueColor visual */          /* Search for best TrueColor visual */
1369          template.class = TrueColor;          template.class = TrueColor;
1370          vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &visuals_count);          template.screen = screen_num;
1371            vmatches =
1372                    XGetVisualInfo(g_display, VisualClassMask | VisualScreenMask, &template,
1373                                   &visuals_count);
1374          g_visual = NULL;          g_visual = NULL;
1375          g_no_translate_image = False;          g_no_translate_image = False;
1376          g_compatible_arch = False;          g_compatible_arch = False;
# Line 1344  select_visual() Line 1379  select_visual()
1379                  for (i = 0; i < visuals_count; ++i)                  for (i = 0; i < visuals_count; ++i)
1380                  {                  {
1381                          XVisualInfo *visual_info = &vmatches[i];                          XVisualInfo *visual_info = &vmatches[i];
1382                            RD_BOOL can_translate_to_bpp = False;
1383                            int j;
1384    
1385                          /* Try to find a no-translation visual that'll                          /* Try to find a no-translation visual that'll
1386                             allow us to use RDP bitmaps directly as ZPixmaps. */                             allow us to use RDP bitmaps directly as ZPixmaps. */
# Line 1387  select_visual() Line 1424  select_visual()
1424    
1425                          /* Only care for visuals, for whose BPPs (not depths!)                          /* Only care for visuals, for whose BPPs (not depths!)
1426                             we have a translateXtoY function. */                             we have a translateXtoY function. */
                         BOOL can_translate_to_bpp = False;  
                         int j;  
1427                          for (j = 0; j < pixmap_formats_count; ++j)                          for (j = 0; j < pixmap_formats_count; ++j)
1428                          {                          {
1429                                  if (pfm[j].depth == visual_info->depth)                                  if (pfm[j].depth == visual_info->depth)
# Line 1516  error_handler(Display * dpy, XErrorEvent Line 1551  error_handler(Display * dpy, XErrorEvent
1551          return g_old_error_handler(dpy, eev);          return g_old_error_handler(dpy, eev);
1552  }  }
1553    
1554  BOOL  RD_BOOL
1555  ui_init(void)  ui_init(void)
1556  {  {
1557          int screen_num;          int screen_num;
# Line 1530  ui_init(void) Line 1565  ui_init(void)
1565    
1566          {          {
1567                  uint16 endianess_test = 1;                  uint16 endianess_test = 1;
1568                  g_host_be = !(BOOL) (*(uint8 *) (&endianess_test));                  g_host_be = !(RD_BOOL) (*(uint8 *) (&endianess_test));
1569          }          }
1570    
1571          g_old_error_handler = XSetErrorHandler(error_handler);          g_old_error_handler = XSetErrorHandler(error_handler);
# Line 1540  ui_init(void) Line 1575  ui_init(void)
1575          g_screen = ScreenOfDisplay(g_display, screen_num);          g_screen = ScreenOfDisplay(g_display, screen_num);
1576          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
1577    
1578          if (!select_visual())          if (!select_visual(screen_num))
1579                  return False;                  return False;
1580    
1581          if (g_no_translate_image)          if (g_no_translate_image)
# Line 1611  ui_init(void) Line 1646  ui_init(void)
1646          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
1647    
1648          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
1649            xwin_refresh_pointer_map();
1650    
1651          xkeymap_init();          xkeymap_init();
1652    
# Line 1636  ui_deinit(void) Line 1672  ui_deinit(void)
1672                  sw_remove_window(g_seamless_windows);                  sw_remove_window(g_seamless_windows);
1673          }          }
1674    
1675            xclip_deinit();
1676    
1677          if (g_IM != NULL)          if (g_IM != NULL)
1678                  XCloseIM(g_IM);                  XCloseIM(g_IM);
1679    
# Line 1680  get_input_mask(long *input_mask) Line 1718  get_input_mask(long *input_mask)
1718                  *input_mask |= LeaveWindowMask;                  *input_mask |= LeaveWindowMask;
1719  }  }
1720    
1721  BOOL  RD_BOOL
1722  ui_create_window(void)  ui_create_window(void)
1723  {  {
1724          uint8 null_pointer_mask[1] = { 0x80 };          uint8 null_pointer_mask[1] = { 0x80 };
# Line 1728  ui_create_window(void) Line 1766  ui_create_window(void)
1766          }          }
1767    
1768          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
1769            ewmh_set_wm_name(g_wnd, g_title);
1770    
1771          if (g_hide_decorations)          if (g_hide_decorations)
1772                  mwm_hide_decorations(g_wnd);                  mwm_hide_decorations(g_wnd);
# Line 1867  xwin_toggle_fullscreen(void) Line 1906  xwin_toggle_fullscreen(void)
1906  }  }
1907    
1908  static void  static void
1909  handle_button_event(XEvent xevent, BOOL down)  handle_button_event(XEvent xevent, RD_BOOL down)
1910  {  {
1911          uint16 button, flags = 0;          uint16 button, flags = 0;
1912          g_last_gesturetime = xevent.xbutton.time;          g_last_gesturetime = xevent.xbutton.time;
1913            /* Reverse the pointer button mapping, e.g. in the case of
1914               "left-handed mouse mode"; the RDP session expects to
1915               receive physical buttons (true in mstsc as well) and
1916               logical button behavior depends on the remote desktop's own
1917               mouse settings */
1918            xevent.xbutton.button = g_pointer_log_to_phys_map[xevent.xbutton.button - 1];
1919          button = xkeymap_translate_button(xevent.xbutton.button);          button = xkeymap_translate_button(xevent.xbutton.button);
1920          if (button == 0)          if (button == 0)
1921                  return;                  return;
# Line 2158  xwin_process_events(void) Line 2203  xwin_process_events(void)
2203                                          XFreeModifiermap(g_mod_map);                                          XFreeModifiermap(g_mod_map);
2204                                          g_mod_map = XGetModifierMapping(g_display);                                          g_mod_map = XGetModifierMapping(g_display);
2205                                  }                                  }
2206    
2207                                    if (xevent.xmapping.request == MappingPointer)
2208                                    {
2209                                            xwin_refresh_pointer_map();
2210                                    }
2211    
2212                                  break;                                  break;
2213    
2214                                  /* clipboard stuff */                                  /* clipboard stuff */
# Line 2241  ui_select(int rdp_socket) Line 2292  ui_select(int rdp_socket)
2292          int n;          int n;
2293          fd_set rfds, wfds;          fd_set rfds, wfds;
2294          struct timeval tv;          struct timeval tv;
2295          BOOL s_timeout = False;          RD_BOOL s_timeout = False;
2296    
2297          while (True)          while (True)
2298          {          {
# Line 2259  ui_select(int rdp_socket) Line 2310  ui_select(int rdp_socket)
2310                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
2311                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
2312    
 #ifdef WITH_RDPSND  
                 /* FIXME: there should be an API for registering fds */  
                 if (g_dsp_busy)  
                 {  
                         FD_SET(g_dsp_fd, &wfds);  
                         n = (g_dsp_fd > n) ? g_dsp_fd : n;  
                 }  
 #endif  
2313                  /* default timeout */                  /* default timeout */
2314                  tv.tv_sec = 60;                  tv.tv_sec = 60;
2315                  tv.tv_usec = 0;                  tv.tv_usec = 0;
2316    
2317    #ifdef WITH_RDPSND
2318                    rdpsnd_add_fds(&n, &rfds, &wfds, &tv);
2319    #endif
2320    
2321                  /* add redirection handles */                  /* add redirection handles */
2322                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
2323                  seamless_select_timeout(&tv);                  seamless_select_timeout(&tv);
# Line 2283  ui_select(int rdp_socket) Line 2330  ui_select(int rdp_socket)
2330                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
2331    
2332                          case 0:                          case 0:
2333    #ifdef WITH_RDPSND
2334                                    rdpsnd_check_fds(&rfds, &wfds);
2335    #endif
2336    
2337                                  /* Abort serial read calls */                                  /* Abort serial read calls */
2338                                  if (s_timeout)                                  if (s_timeout)
2339                                          rdpdr_check_fds(&rfds, &wfds, (BOOL) True);                                          rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) True);
2340                                  continue;                                  continue;
2341                  }                  }
2342    
2343                  rdpdr_check_fds(&rfds, &wfds, (BOOL) False);  #ifdef WITH_RDPSND
2344                    rdpsnd_check_fds(&rfds, &wfds);
2345    #endif
2346    
2347                    rdpdr_check_fds(&rfds, &wfds, (RD_BOOL) False);
2348    
2349                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
2350                          return 1;                          return 1;
2351    
 #ifdef WITH_RDPSND  
                 if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))  
                         wave_out_play();  
 #endif  
2352          }          }
2353  }  }
2354    
# Line 2307  ui_move_pointer(int x, int y) Line 2358  ui_move_pointer(int x, int y)
2358          XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y);          XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y);
2359  }  }
2360    
2361  HBITMAP  RD_HBITMAP
2362  ui_create_bitmap(int width, int height, uint8 * data)  ui_create_bitmap(int width, int height, uint8 * data)
2363  {  {
2364          XImage *image;          XImage *image;
# Line 2337  ui_create_bitmap(int width, int height, Line 2388  ui_create_bitmap(int width, int height,
2388          XFree(image);          XFree(image);
2389          if (tdata != data)          if (tdata != data)
2390                  xfree(tdata);                  xfree(tdata);
2391          return (HBITMAP) bitmap;          return (RD_HBITMAP) bitmap;
2392  }  }
2393    
2394  void  void
# Line 2385  ui_paint_bitmap(int x, int y, int cx, in Line 2436  ui_paint_bitmap(int x, int y, int cx, in
2436  }  }
2437    
2438  void  void
2439  ui_destroy_bitmap(HBITMAP bmp)  ui_destroy_bitmap(RD_HBITMAP bmp)
2440  {  {
2441          XFreePixmap(g_display, (Pixmap) bmp);          XFreePixmap(g_display, (Pixmap) bmp);
2442  }  }
2443    
2444  HGLYPH  RD_HGLYPH
2445  ui_create_glyph(int width, int height, uint8 * data)  ui_create_glyph(int width, int height, uint8 * data)
2446  {  {
2447          XImage *image;          XImage *image;
# Line 2412  ui_create_glyph(int width, int height, u Line 2463  ui_create_glyph(int width, int height, u
2463          XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height);
2464    
2465          XFree(image);          XFree(image);
2466          return (HGLYPH) bitmap;          return (RD_HGLYPH) bitmap;
2467  }  }
2468    
2469  void  void
2470  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(RD_HGLYPH glyph)
2471  {  {
2472          XFreePixmap(g_display, (Pixmap) glyph);          XFreePixmap(g_display, (Pixmap) glyph);
2473  }  }
2474    
2475  HCURSOR  RD_HCURSOR
2476  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,
2477                   uint8 * andmask, uint8 * xormask)                   uint8 * andmask, uint8 * xormask)
2478  {  {
2479          HGLYPH maskglyph, cursorglyph;          RD_HGLYPH maskglyph, cursorglyph;
2480          XColor bg, fg;          XColor bg, fg;
2481          Cursor xcursor;          Cursor xcursor;
2482          uint8 *cursor, *pcursor;          uint8 *cursor, *pcursor;
# Line 2489  ui_create_cursor(unsigned int x, unsigne Line 2540  ui_create_cursor(unsigned int x, unsigne
2540          ui_destroy_glyph(cursorglyph);          ui_destroy_glyph(cursorglyph);
2541          xfree(mask);          xfree(mask);
2542          xfree(cursor);          xfree(cursor);
2543          return (HCURSOR) xcursor;          return (RD_HCURSOR) xcursor;
2544  }  }
2545    
2546  void  void
2547  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(RD_HCURSOR cursor)
2548  {  {
2549          g_current_cursor = (Cursor) cursor;          g_current_cursor = (Cursor) cursor;
2550          XDefineCursor(g_display, g_wnd, g_current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
# Line 2501  ui_set_cursor(HCURSOR cursor) Line 2552  ui_set_cursor(HCURSOR cursor)
2552  }  }
2553    
2554  void  void
2555  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_cursor(RD_HCURSOR cursor)
2556  {  {
2557          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
2558  }  }
# Line 2519  ui_set_null_cursor(void) Line 2570  ui_set_null_cursor(void)
2570                  (xc)->flags = DoRed | DoGreen | DoBlue;                  (xc)->flags = DoRed | DoGreen | DoBlue;
2571    
2572    
2573  HCOLOURMAP  RD_HCOLOURMAP
2574  ui_create_colourmap(COLOURMAP * colours)  ui_create_colourmap(COLOURMAP * colours)
2575  {  {
2576          COLOURENTRY *entry;          COLOURENTRY *entry;
# Line 2615  ui_create_colourmap(COLOURMAP * colours) Line 2666  ui_create_colourmap(COLOURMAP * colours)
2666                  XStoreColors(g_display, map, xcolours, ncolours);                  XStoreColors(g_display, map, xcolours, ncolours);
2667    
2668                  xfree(xcolours);                  xfree(xcolours);
2669                  return (HCOLOURMAP) map;                  return (RD_HCOLOURMAP) map;
2670          }          }
2671  }  }
2672    
2673  void  void
2674  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(RD_HCOLOURMAP map)
2675  {  {
2676          if (!g_owncolmap)          if (!g_owncolmap)
2677                  xfree(map);                  xfree(map);
# Line 2629  ui_destroy_colourmap(HCOLOURMAP map) Line 2680  ui_destroy_colourmap(HCOLOURMAP map)
2680  }  }
2681    
2682  void  void
2683  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(RD_HCOLOURMAP map)
2684  {  {
2685          if (!g_owncolmap)          if (!g_owncolmap)
2686          {          {
# Line 2717  ui_patblt(uint8 opcode, Line 2768  ui_patblt(uint8 opcode,
2768                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2769                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2770                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2771                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
2772                          break;                          break;
2773    
2774                  case 3: /* Pattern */                  case 3: /* Pattern */
# Line 2732  ui_patblt(uint8 opcode, Line 2783  ui_patblt(uint8 opcode,
2783                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2784                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2785                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2786                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
2787                          break;                          break;
2788    
2789                  default:                  default:
# Line 2775  ui_screenblt(uint8 opcode, Line 2826  ui_screenblt(uint8 opcode,
2826  void  void
2827  ui_memblt(uint8 opcode,  ui_memblt(uint8 opcode,
2828            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
2829            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ RD_HBITMAP src, int srcx, int srcy)
2830  {  {
2831          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
2832          XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);          XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
# Line 2790  ui_memblt(uint8 opcode, Line 2841  ui_memblt(uint8 opcode,
2841  void  void
2842  ui_triblt(uint8 opcode,  ui_triblt(uint8 opcode,
2843            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
2844            /* src */ HBITMAP src, int srcx, int srcy,            /* src */ RD_HBITMAP src, int srcx, int srcy,
2845            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
2846  {  {
2847          /* This is potentially difficult to do in general. Until someone          /* This is potentially difficult to do in general. Until someone
# Line 2848  ui_rect( Line 2899  ui_rect(
2899  void  void
2900  ui_polygon(uint8 opcode,  ui_polygon(uint8 opcode,
2901             /* mode */ uint8 fillmode,             /* mode */ uint8 fillmode,
2902             /* dest */ POINT * point, int npoints,             /* dest */ RD_POINT * point, int npoints,
2903             /* brush */ BRUSH * brush, int bgcolour, int fgcolour)             /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
2904  {  {
2905          uint8 style, i, ipattern[8];          uint8 style, i, ipattern[8];
# Line 2891  ui_polygon(uint8 opcode, Line 2942  ui_polygon(uint8 opcode,
2942                          FILL_POLYGON((XPoint *) point, npoints);                          FILL_POLYGON((XPoint *) point, npoints);
2943                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2944                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2945                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
2946                          break;                          break;
2947    
2948                  case 3: /* Pattern */                  case 3: /* Pattern */
# Line 2906  ui_polygon(uint8 opcode, Line 2957  ui_polygon(uint8 opcode,
2957                          FILL_POLYGON((XPoint *) point, npoints);                          FILL_POLYGON((XPoint *) point, npoints);
2958                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2959                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2960                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
2961                          break;                          break;
2962    
2963                  default:                  default:
# Line 2918  ui_polygon(uint8 opcode, Line 2969  ui_polygon(uint8 opcode,
2969    
2970  void  void
2971  ui_polyline(uint8 opcode,  ui_polyline(uint8 opcode,
2972              /* dest */ POINT * points, int npoints,              /* dest */ RD_POINT * points, int npoints,
2973              /* pen */ PEN * pen)              /* pen */ PEN * pen)
2974  {  {
2975          /* TODO: set join style */          /* TODO: set join style */
# Line 2969  ui_ellipse(uint8 opcode, Line 3020  ui_ellipse(uint8 opcode,
3020                          DRAW_ELLIPSE(x, y, cx, cy, fillmode);                          DRAW_ELLIPSE(x, y, cx, cy, fillmode);
3021                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
3022                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
3023                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
3024                          break;                          break;
3025    
3026                  case 3: /* Pattern */                  case 3: /* Pattern */
# Line 2984  ui_ellipse(uint8 opcode, Line 3035  ui_ellipse(uint8 opcode,
3035                          DRAW_ELLIPSE(x, y, cx, cy, fillmode);                          DRAW_ELLIPSE(x, y, cx, cy, fillmode);
3036                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
3037                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
3038                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((RD_HGLYPH) fill);
3039                          break;                          break;
3040    
3041                  default:                  default:
# Line 2998  ui_ellipse(uint8 opcode, Line 3049  ui_ellipse(uint8 opcode,
3049  void  void
3050  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
3051                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
3052                /* src */ HGLYPH glyph, int srcx, int srcy,                /* src */ RD_HGLYPH glyph, int srcx, int srcy,
3053                int bgcolour, int fgcolour)                int bgcolour, int fgcolour)
3054  {  {
3055          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
# Line 3183  ui_desktop_save(uint32 offset, int x, in Line 3234  ui_desktop_save(uint32 offset, int x, in
3234          if (g_ownbackstore)          if (g_ownbackstore)
3235          {          {
3236                  image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap);
3237                    exit_if_null(image);
3238          }          }
3239          else          else
3240          {          {
3241                  pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth);                  pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth);
3242                  XCopyArea(g_display, g_wnd, pix, g_gc, x, y, cx, cy, 0, 0);                  XCopyArea(g_display, g_wnd, pix, g_gc, x, y, cx, cy, 0, 0);
3243                  image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
3244                    exit_if_null(image);
3245                  XFreePixmap(g_display, pix);                  XFreePixmap(g_display, pix);
3246          }          }
3247    
# Line 3210  ui_desktop_restore(uint32 offset, int x, Line 3263  ui_desktop_restore(uint32 offset, int x,
3263                  return;                  return;
3264    
3265          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
3266                               (char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8);                               (char *) data, cx, cy, g_bpp, 0);
3267    
3268          if (g_ownbackstore)          if (g_ownbackstore)
3269          {          {
# Line 3244  ui_end_update(void) Line 3297  ui_end_update(void)
3297    
3298    
3299  void  void
3300  ui_seamless_begin(BOOL hidden)  ui_seamless_begin(RD_BOOL hidden)
3301  {  {
3302          if (!g_seamless_rdp)          if (!g_seamless_rdp)
3303                  return;                  return;
# Line 3399  ui_seamless_create_window(unsigned long Line 3452  ui_seamless_create_window(unsigned long
3452                  ewmh_set_window_modal(wnd);                  ewmh_set_window_modal(wnd);
3453          }          }
3454    
3455            if (flags & SEAMLESSRDP_CREATE_TOPMOST)
3456            {
3457                    /* Make window always-on-top */
3458                    ewmh_set_window_above(wnd);
3459            }
3460    
3461          /* FIXME: Support for Input Context:s */          /* FIXME: Support for Input Context:s */
3462    
3463          get_input_mask(&input_mask);          get_input_mask(&input_mask);
# Line 3412  ui_seamless_create_window(unsigned long Line 3471  ui_seamless_create_window(unsigned long
3471          XSetWMProtocols(g_display, wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, wnd, &g_kill_atom, 1);
3472    
3473          sw = xmalloc(sizeof(seamless_window));          sw = xmalloc(sizeof(seamless_window));
3474    
3475            memset(sw, 0, sizeof(seamless_window));
3476    
3477          sw->wnd = wnd;          sw->wnd = wnd;
3478          sw->id = id;          sw->id = id;
         sw->behind = 0;  
3479          sw->group = sw_find_group(group, False);          sw->group = sw_find_group(group, False);
3480          sw->group->refcnt++;          sw->group->refcnt++;
         sw->xoffset = 0;  
         sw->yoffset = 0;  
         sw->width = 0;  
         sw->height = 0;  
3481          sw->state = SEAMLESSRDP_NOTYETMAPPED;          sw->state = SEAMLESSRDP_NOTYETMAPPED;
3482          sw->desktop = 0;          sw->desktop = 0;
3483          sw->position_timer = xmalloc(sizeof(struct timeval));          sw->position_timer = xmalloc(sizeof(struct timeval));
# Line 3467  ui_seamless_destroy_window(unsigned long Line 3524  ui_seamless_destroy_window(unsigned long
3524    
3525    
3526  void  void
3527    ui_seamless_destroy_group(unsigned long id, unsigned long flags)
3528    {
3529            seamless_window *sw, *sw_next;
3530    
3531            if (!g_seamless_active)
3532                    return;
3533    
3534            for (sw = g_seamless_windows; sw; sw = sw_next)
3535            {
3536                    sw_next = sw->next;
3537    
3538                    if (sw->group->id == id)
3539                    {
3540                            XDestroyWindow(g_display, sw->wnd);
3541                            sw_remove_window(sw);
3542                    }
3543            }
3544    }
3545    
3546    
3547    void
3548    ui_seamless_seticon(unsigned long id, const char *format, int width, int height, int chunk,
3549                        const char *data, int chunk_len)
3550    {
3551            seamless_window *sw;
3552    
3553            if (!g_seamless_active)
3554                    return;
3555    
3556            sw = sw_get_window_by_id(id);
3557            if (!sw)
3558            {
3559                    warning("ui_seamless_seticon: No information for window 0x%lx\n", id);
3560                    return;
3561            }
3562    
3563            if (chunk == 0)
3564            {
3565                    if (sw->icon_size)
3566                            warning("ui_seamless_seticon: New icon started before previous completed\n");
3567    
3568                    if (strcmp(format, "RGBA") != 0)
3569                    {
3570                            warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format);
3571                            return;
3572                    }
3573    
3574                    sw->icon_size = width * height * 4;
3575                    if (sw->icon_size > 32 * 32 * 4)
3576                    {
3577                            warning("ui_seamless_seticon: Icon too large (%d bytes)\n", sw->icon_size);
3578                            sw->icon_size = 0;
3579                            return;
3580                    }
3581    
3582                    sw->icon_offset = 0;
3583            }
3584            else
3585            {
3586                    if (!sw->icon_size)
3587                            return;
3588            }
3589    
3590            if (chunk_len > (sw->icon_size - sw->icon_offset))
3591            {
3592                    warning("ui_seamless_seticon: Too large chunk received (%d bytes > %d bytes)\n",
3593                            chunk_len, sw->icon_size - sw->icon_offset);
3594                    sw->icon_size = 0;
3595                    return;
3596            }
3597    
3598            memcpy(sw->icon_buffer + sw->icon_offset, data, chunk_len);
3599            sw->icon_offset += chunk_len;
3600    
3601            if (sw->icon_offset == sw->icon_size)
3602            {
3603                    ewmh_set_icon(sw->wnd, width, height, sw->icon_buffer);
3604                    sw->icon_size = 0;
3605            }
3606    }
3607    
3608    
3609    void
3610    ui_seamless_delicon(unsigned long id, const char *format, int width, int height)
3611    {
3612            seamless_window *sw;
3613    
3614            if (!g_seamless_active)
3615                    return;
3616    
3617            sw = sw_get_window_by_id(id);
3618            if (!sw)
3619            {
3620                    warning("ui_seamless_seticon: No information for window 0x%lx\n", id);
3621                    return;
3622            }
3623    
3624            if (strcmp(format, "RGBA") != 0)
3625            {
3626                    warning("ui_seamless_seticon: Uknown icon format \"%s\"\n", format);
3627                    return;
3628            }
3629    
3630            ewmh_del_icon(sw->wnd, width, height);
3631    }
3632    
3633    
3634    void
3635  ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags)  ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags)
3636  {  {
3637          seamless_window *sw;          seamless_window *sw;
# Line 3547  ui_seamless_restack_window(unsigned long Line 3712  ui_seamless_restack_window(unsigned long
3712          }          }
3713    
3714          sw_restack_window(sw, behind);          sw_restack_window(sw, behind);
3715    
3716            if (flags & SEAMLESSRDP_CREATE_TOPMOST)
3717            {
3718                    /* Make window always-on-top */
3719                    ewmh_set_window_above(sw->wnd);
3720            }
3721  }  }
3722    
3723    

Legend:
Removed from v.1199  
changed lines
  Added in v.1443

  ViewVC Help
Powered by ViewVC 1.1.26