/[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 867 by stargo, Wed Mar 23 12:25:54 2005 UTC revision 1302 by ossman_, Thu Oct 26 09:47:17 2006 UTC
# Line 28  Line 28 
28  #include "rdesktop.h"  #include "rdesktop.h"
29  #include "xproto.h"  #include "xproto.h"
30    
31    /* We can't include Xproto.h because of conflicting defines for BOOL */
32    #define X_ConfigureWindow              12
33    
34  extern int g_width;  extern int g_width;
35  extern int g_height;  extern int g_height;
36  extern int g_xpos;  extern int g_xpos;
# Line 38  extern BOOL g_fullscreen; Line 41  extern BOOL g_fullscreen;
41  extern BOOL g_grab_keyboard;  extern BOOL g_grab_keyboard;
42  extern BOOL g_hide_decorations;  extern BOOL g_hide_decorations;
43  extern char g_title[];  extern char g_title[];
44  extern int g_server_bpp;  /* Color depth of the RDP session.
45       As of RDP 5.1, it may be 8, 15, 16 or 24. */
46    extern int g_server_depth;
47  extern int g_win_button_size;  extern int g_win_button_size;
48    
49  Display *g_display;  Display *g_display;
# Line 46  Time g_last_gesturetime; Line 51  Time g_last_gesturetime;
51  static int g_x_socket;  static int g_x_socket;
52  static Screen *g_screen;  static Screen *g_screen;
53  Window g_wnd;  Window g_wnd;
54    
55    /* SeamlessRDP support */
56    typedef struct _seamless_group
57    {
58            Window wnd;
59            unsigned long id;
60            unsigned int refcnt;
61    } seamless_group;
62    typedef struct _seamless_window
63    {
64            Window wnd;
65            unsigned long id;
66            unsigned long behind;
67            seamless_group *group;
68            int xoffset, yoffset;
69            int width, height;
70            int state;              /* normal/minimized/maximized. */
71            unsigned int desktop;
72            struct timeval *position_timer;
73    
74            BOOL outstanding_position;
75            unsigned int outpos_serial;
76            int outpos_xoffset, outpos_yoffset;
77            int outpos_width, outpos_height;
78    
79            struct _seamless_window *next;
80    } seamless_window;
81    static seamless_window *g_seamless_windows = NULL;
82    static unsigned long g_seamless_focused = 0;
83    static BOOL g_seamless_started = False; /* Server end is up and running */
84    static BOOL g_seamless_active = False;  /* We are currently in seamless mode */
85    static BOOL g_seamless_hidden = False;  /* Desktop is hidden on server */
86    extern BOOL g_seamless_rdp;
87    
88  extern uint32 g_embed_wnd;  extern uint32 g_embed_wnd;
89  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
90  BOOL g_Unobscured;              /* used for screenblt */  BOOL g_Unobscured;              /* used for screenblt */
91  static GC g_gc = NULL;  static GC g_gc = NULL;
92  static GC g_create_bitmap_gc = NULL;  static GC g_create_bitmap_gc = NULL;
93  static GC g_create_glyph_gc = NULL;  static GC g_create_glyph_gc = NULL;
94    static XRectangle g_clip_rectangle;
95  static Visual *g_visual;  static Visual *g_visual;
96    /* Color depth of the X11 visual of our window (e.g. 24 for True Color R8G8B visual).
97       This may be 32 for R8G8B8 visuals, and then the rest of the bits are undefined
98       as far as we're concerned. */
99  static int g_depth;  static int g_depth;
100    /* Bits-per-Pixel of the pixmaps we'll be using to draw on our window.
101       This may be larger than g_depth, in which case some of the bits would
102       be kept solely for alignment (e.g. 32bpp pixmaps on a 24bpp visual). */
103  static int g_bpp;  static int g_bpp;
104  static XIM g_IM;  static XIM g_IM;
105  static XIC g_IC;  static XIC g_IC;
# Line 61  static XModifierKeymap *g_mod_map; Line 107  static XModifierKeymap *g_mod_map;
107  static Cursor g_current_cursor;  static Cursor g_current_cursor;
108  static HCURSOR g_null_cursor = NULL;  static HCURSOR g_null_cursor = NULL;
109  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
110    extern Atom g_net_wm_state_atom;
111    extern Atom g_net_wm_desktop_atom;
112  static BOOL g_focused;  static BOOL g_focused;
113  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
114  static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */  /* Indicates that:
115       1) visual has 15, 16 or 24 depth and the same color channel masks
116          as its RDP equivalent (implies X server is LE),
117       2) host is LE
118       This will trigger an optimization whose real value is questionable.
119    */
120    static BOOL g_compatible_arch;
121    /* Indicates whether RDP's bitmaps and our XImages have the same
122       binary format. If so, we can avoid an expensive translation.
123       Note that this can be true when g_compatible_arch is false,
124       e.g.:
125      
126         RDP(LE) <-> host(BE) <-> X-Server(LE)
127        
128       ('host' is the machine running rdesktop; the host simply memcpy's
129        so its endianess doesn't matter)
130     */
131    static BOOL g_no_translate_image = False;
132    
133  /* endianness */  /* endianness */
134  static BOOL g_host_be;  static BOOL g_host_be;
# Line 79  static Pixmap g_backstore = 0; Line 144  static Pixmap g_backstore = 0;
144  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
145  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
146  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
147    static BOOL g_using_full_workarea = False;
148    
149  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
150  extern int g_dsp_fd;  extern int g_dsp_fd;
# Line 91  extern BOOL g_rdpsnd; Line 157  extern BOOL g_rdpsnd;
157  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
158  typedef struct  typedef struct
159  {  {
160          uint32 flags;          unsigned long flags;
161          uint32 functions;          unsigned long functions;
162          uint32 decorations;          unsigned long decorations;
163          sint32 inputMode;          long inputMode;
164          uint32 status;          unsigned long status;
165  }  }
166  PropMotifWmHints;  PropMotifWmHints;
167    
# Line 107  typedef struct Line 173  typedef struct
173  }  }
174  PixelColour;  PixelColour;
175    
176    #define ON_ALL_SEAMLESS_WINDOWS(func, args) \
177            do { \
178                    seamless_window *sw; \
179                    XRectangle rect; \
180                    if (!g_seamless_windows) break; \
181                    for (sw = g_seamless_windows; sw; sw = sw->next) { \
182                        rect.x = g_clip_rectangle.x - sw->xoffset; \
183                        rect.y = g_clip_rectangle.y - sw->yoffset; \
184                        rect.width = g_clip_rectangle.width; \
185                        rect.height = g_clip_rectangle.height; \
186                        XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded); \
187                        func args; \
188                    } \
189                    XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded); \
190            } while (0)
191    
192    static void
193    seamless_XFillPolygon(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset)
194    {
195            points[0].x -= xoffset;
196            points[0].y -= yoffset;
197            XFillPolygon(g_display, d, g_gc, points, npoints, Complex, CoordModePrevious);
198            points[0].x += xoffset;
199            points[0].y += yoffset;
200    }
201    
202    static void
203    seamless_XDrawLines(Drawable d, XPoint * points, int npoints, int xoffset, int yoffset)
204    {
205            points[0].x -= xoffset;
206            points[0].y -= yoffset;
207            XDrawLines(g_display, d, g_gc, points, npoints, CoordModePrevious);
208            points[0].x += xoffset;
209            points[0].y += yoffset;
210    }
211    
212  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
213  { \  { \
214          XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \          XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \
215            ON_ALL_SEAMLESS_WINDOWS(XFillRectangle, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy)); \
216          if (g_ownbackstore) \          if (g_ownbackstore) \
217                  XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \                  XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \
218  }  }
# Line 125  PixelColour; Line 227  PixelColour;
227          XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \          XFillPolygon(g_display, g_wnd, g_gc, p, np, Complex, CoordModePrevious); \
228          if (g_ownbackstore) \          if (g_ownbackstore) \
229                  XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \                  XFillPolygon(g_display, g_backstore, g_gc, p, np, Complex, CoordModePrevious); \
230            ON_ALL_SEAMLESS_WINDOWS(seamless_XFillPolygon, (sw->wnd, p, np, sw->xoffset, sw->yoffset)); \
231  }  }
232    
233  #define DRAW_ELLIPSE(x,y,cx,cy,m)\  #define DRAW_ELLIPSE(x,y,cx,cy,m)\
# Line 133  PixelColour; Line 236  PixelColour;
236          { \          { \
237                  case 0: /* Outline */ \                  case 0: /* Outline */ \
238                          XDrawArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \                          XDrawArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \
239                            ON_ALL_SEAMLESS_WINDOWS(XDrawArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \
240                          if (g_ownbackstore) \                          if (g_ownbackstore) \
241                                  XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \                                  XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
242                          break; \                          break; \
243                  case 1: /* Filled */ \                  case 1: /* Filled */ \
244                          XFillArc(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, \                          XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \
245                                   cx, cy, 0, 360*64); \                          ON_ALL_SEAMLESS_WINDOWS(XFillArc, (g_display, sw->wnd, g_gc, x-sw->xoffset, y-sw->yoffset, cx, cy, 0, 360*64)); \
246                          if (g_ownbackstore) \                          if (g_ownbackstore) \
247                                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); \                                  XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \
248                          break; \                          break; \
249          } \          } \
250  }  }
# Line 150  extern BOOL g_owncolmap; Line 254  extern BOOL g_owncolmap;
254  static Colormap g_xcolmap;  static Colormap g_xcolmap;
255  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
256    
257  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )  #define TRANSLATE(col)          ( g_server_depth != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
258  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
259  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
260    
# Line 176  static int rop2_map[] = { Line 280  static int rop2_map[] = {
280  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, rop2_map[rop2]); }  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, rop2_map[rop2]); }
281  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, GXcopy); }
282    
283    static seamless_window *
284    sw_get_window_by_id(unsigned long id)
285    {
286            seamless_window *sw;
287            for (sw = g_seamless_windows; sw; sw = sw->next)
288            {
289                    if (sw->id == id)
290                            return sw;
291            }
292            return NULL;
293    }
294    
295    
296    static seamless_window *
297    sw_get_window_by_wnd(Window wnd)
298    {
299            seamless_window *sw;
300            for (sw = g_seamless_windows; sw; sw = sw->next)
301            {
302                    if (sw->wnd == wnd)
303                            return sw;
304            }
305            return NULL;
306    }
307    
308    
309  static void  static void
310  mwm_hide_decorations(void)  sw_remove_window(seamless_window * win)
311    {
312            seamless_window *sw, **prevnext = &g_seamless_windows;
313            for (sw = g_seamless_windows; sw; sw = sw->next)
314            {
315                    if (sw == win)
316                    {
317                            *prevnext = sw->next;
318                            sw->group->refcnt--;
319                            if (sw->group->refcnt == 0)
320                            {
321                                    XDestroyWindow(g_display, sw->group->wnd);
322                                    xfree(sw->group);
323                            }
324                            xfree(sw->position_timer);
325                            xfree(sw);
326                            return;
327                    }
328                    prevnext = &sw->next;
329            }
330            return;
331    }
332    
333    
334    /* Move all windows except wnd to new desktop */
335    static void
336    sw_all_to_desktop(Window wnd, unsigned int desktop)
337    {
338            seamless_window *sw;
339            for (sw = g_seamless_windows; sw; sw = sw->next)
340            {
341                    if (sw->wnd == wnd)
342                            continue;
343                    if (sw->desktop != desktop)
344                    {
345                            ewmh_move_to_desktop(sw->wnd, desktop);
346                            sw->desktop = desktop;
347                    }
348            }
349    }
350    
351    
352    /* Send our position */
353    static void
354    sw_update_position(seamless_window * sw)
355    {
356            XWindowAttributes wa;
357            int x, y;
358            Window child_return;
359            unsigned int serial;
360    
361            XGetWindowAttributes(g_display, sw->wnd, &wa);
362            XTranslateCoordinates(g_display, sw->wnd, wa.root,
363                                  -wa.border_width, -wa.border_width, &x, &y, &child_return);
364    
365            serial = seamless_send_position(sw->id, x, y, wa.width, wa.height, 0);
366    
367            sw->outstanding_position = True;
368            sw->outpos_serial = serial;
369    
370            sw->outpos_xoffset = x;
371            sw->outpos_yoffset = y;
372            sw->outpos_width = wa.width;
373            sw->outpos_height = wa.height;
374    }
375    
376    
377    /* Check if it's time to send our position */
378    static void
379    sw_check_timers()
380    {
381            seamless_window *sw;
382            struct timeval now;
383    
384            gettimeofday(&now, NULL);
385            for (sw = g_seamless_windows; sw; sw = sw->next)
386            {
387                    if (timerisset(sw->position_timer) && timercmp(sw->position_timer, &now, <))
388                    {
389                            timerclear(sw->position_timer);
390                            sw_update_position(sw);
391                    }
392            }
393    }
394    
395    
396    static void
397    sw_restack_window(seamless_window * sw, unsigned long behind)
398    {
399            seamless_window *sw_above;
400    
401            /* Remove window from stack */
402            for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next)
403            {
404                    if (sw_above->behind == sw->id)
405                            break;
406            }
407    
408            if (sw_above)
409                    sw_above->behind = sw->behind;
410    
411            /* And then add it at the new position */
412            for (sw_above = g_seamless_windows; sw_above; sw_above = sw_above->next)
413            {
414                    if (sw_above->behind == behind)
415                            break;
416            }
417    
418            if (sw_above)
419                    sw_above->behind = sw->id;
420    
421            sw->behind = behind;
422    }
423    
424    
425    static void
426    sw_handle_restack(seamless_window * sw)
427    {
428            Status status;
429            Window root, parent, *children;
430            unsigned int nchildren, i;
431            seamless_window *sw_below;
432    
433            status = XQueryTree(g_display, RootWindowOfScreen(g_screen),
434                                &root, &parent, &children, &nchildren);
435            if (!status || !nchildren)
436                    return;
437    
438            sw_below = NULL;
439    
440            i = 0;
441            while (children[i] != sw->wnd)
442            {
443                    i++;
444                    if (i >= nchildren)
445                            goto end;
446            }
447    
448            for (i++; i < nchildren; i++)
449            {
450                    sw_below = sw_get_window_by_wnd(children[i]);
451                    if (sw_below)
452                            break;
453            }
454    
455            if (!sw_below && !sw->behind)
456                    goto end;
457            if (sw_below && (sw_below->id == sw->behind))
458                    goto end;
459    
460            if (sw_below)
461            {
462                    seamless_send_zchange(sw->id, sw_below->id, 0);
463                    sw_restack_window(sw, sw_below->id);
464            }
465            else
466            {
467                    seamless_send_zchange(sw->id, 0, 0);
468                    sw_restack_window(sw, 0);
469            }
470    
471          end:
472            XFree(children);
473    }
474    
475    
476    static seamless_group *
477    sw_find_group(unsigned long id, BOOL dont_create)
478    {
479            seamless_window *sw;
480            seamless_group *sg;
481            XSetWindowAttributes attribs;
482    
483            for (sw = g_seamless_windows; sw; sw = sw->next)
484            {
485                    if (sw->group->id == id)
486                            return sw->group;
487            }
488    
489            if (dont_create)
490                    return NULL;
491    
492            sg = xmalloc(sizeof(seamless_group));
493    
494            sg->wnd =
495                    XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0,
496                                  CopyFromParent, CopyFromParent, CopyFromParent, 0, &attribs);
497    
498            sg->id = id;
499            sg->refcnt = 0;
500    
501            return sg;
502    }
503    
504    
505    static void
506    mwm_hide_decorations(Window wnd)
507  {  {
508          PropMotifWmHints motif_hints;          PropMotifWmHints motif_hints;
509          Atom hintsatom;          Atom hintsatom;
# Line 194  mwm_hide_decorations(void) Line 520  mwm_hide_decorations(void)
520                  return;                  return;
521          }          }
522    
523          XChangeProperty(g_display, g_wnd, hintsatom, hintsatom, 32, PropModeReplace,          XChangeProperty(g_display, wnd, hintsatom, hintsatom, 32, PropModeReplace,
524                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
525    
526  }  }
527    
528  #define SPLITCOLOUR15(colour, rv) \  #define SPLITCOLOUR15(colour, rv) \
# Line 229  mwm_hide_decorations(void) Line 556  mwm_hide_decorations(void)
556  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
557                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
558    
559    /* The following macros output the same octet sequences
560       on both BE and LE hosts: */
561    
562  #define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; }  #define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; }
563  #define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }  #define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
564  #define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }  #define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
# Line 240  static uint32 Line 570  static uint32
570  translate_colour(uint32 colour)  translate_colour(uint32 colour)
571  {  {
572          PixelColour pc;          PixelColour pc;
573          switch (g_server_bpp)          switch (g_server_depth)
574          {          {
575                  case 15:                  case 15:
576                          SPLITCOLOUR15(colour, pc);                          SPLITCOLOUR15(colour, pc);
# Line 251  translate_colour(uint32 colour) Line 581  translate_colour(uint32 colour)
581                  case 24:                  case 24:
582                          SPLITCOLOUR24(colour, pc);                          SPLITCOLOUR24(colour, pc);
583                          break;                          break;
584                    default:
585                            /* Avoid warning */
586                            pc.red = 0;
587                            pc.green = 0;
588                            pc.blue = 0;
589                            break;
590          }          }
591          return MAKECOLOUR(pc);          return MAKECOLOUR(pc);
592  }  }
# Line 302  translate8to16(const uint8 * data, uint8 Line 638  translate8to16(const uint8 * data, uint8
638  {  {
639          uint16 value;          uint16 value;
640    
641          if (g_arch_match)          if (g_compatible_arch)
642          {          {
643                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
644                  REPEAT2                  REPEAT2
# Line 336  translate8to24(const uint8 * data, uint8 Line 672  translate8to24(const uint8 * data, uint8
672  {  {
673          uint32 value;          uint32 value;
674    
675          if (g_xserver_be)          if (g_compatible_arch)
676          {          {
677                  while (out < end)                  while (out < end)
678                  {                  {
# Line 359  translate8to32(const uint8 * data, uint8 Line 695  translate8to32(const uint8 * data, uint8
695  {  {
696          uint32 value;          uint32 value;
697    
698          if (g_arch_match)          if (g_compatible_arch)
699          {          {
700                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
701                  REPEAT4                  REPEAT4
# Line 431  translate15to24(const uint16 * data, uin Line 767  translate15to24(const uint16 * data, uin
767          uint16 pixel;          uint16 pixel;
768          PixelColour pc;          PixelColour pc;
769    
770          if (g_arch_match)          if (g_compatible_arch)
771          {          {
772                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
773                  REPEAT3                  REPEAT3
# Line 481  translate15to32(const uint16 * data, uin Line 817  translate15to32(const uint16 * data, uin
817          uint32 value;          uint32 value;
818          PixelColour pc;          PixelColour pc;
819    
820          if (g_arch_match)          if (g_compatible_arch)
821          {          {
822                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
823                  REPEAT4                  REPEAT4
# Line 589  translate16to24(const uint16 * data, uin Line 925  translate16to24(const uint16 * data, uin
925          uint16 pixel;          uint16 pixel;
926          PixelColour pc;          PixelColour pc;
927    
928          if (g_arch_match)          if (g_compatible_arch)
929          {          {
930                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
931                  REPEAT3                  REPEAT3
# Line 659  translate16to32(const uint16 * data, uin Line 995  translate16to32(const uint16 * data, uin
995          uint32 value;          uint32 value;
996          PixelColour pc;          PixelColour pc;
997    
998          if (g_arch_match)          if (g_compatible_arch)
999          {          {
1000                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
1001                  REPEAT4                  REPEAT4
# Line 788  translate24to32(const uint8 * data, uint Line 1124  translate24to32(const uint8 * data, uint
1124          uint32 value;          uint32 value;
1125          PixelColour pc;          PixelColour pc;
1126    
1127          if (g_arch_match)          if (g_compatible_arch)
1128          {          {
1129                  /* *INDENT-OFF* */                  /* *INDENT-OFF* */
1130  #ifdef NEED_ALIGN  #ifdef NEED_ALIGN
# Line 802  translate24to32(const uint8 * data, uint Line 1138  translate24to32(const uint8 * data, uint
1138  #else  #else
1139                  REPEAT4                  REPEAT4
1140                  (                  (
1141                          *((uint32 *) out) = *((uint32 *) data);                   /* Only read 3 bytes. Reading 4 bytes means reading beyond buffer. */
1142                          out += 4;                   *((uint32 *) out) = *((uint16 *) data) + (*((uint8 *) data + 2) << 16);
1143                          data += 3;                   out += 4;
1144                     data += 3;
1145                  )                  )
1146  #endif  #endif
1147                  /* *INDENT-ON* */                  /* *INDENT-ON* */
# Line 842  translate_image(int width, int height, u Line 1179  translate_image(int width, int height, u
1179          uint8 *out;          uint8 *out;
1180          uint8 *end;          uint8 *end;
1181    
1182          /* if server and xserver bpp match, */          /*
1183          /* and arch(endian) matches, no need to translate */             If RDP depth and X Visual depths match,
1184          /* just return data */             and arch(endian) matches, no need to translate:
1185          if (g_arch_match)             just return data.
1186               Note: select_visual should've already ensured g_no_translate
1187               is only set for compatible depths, but the RDP depth might've
1188               changed during connection negotiations.
1189             */
1190            if (g_no_translate_image)
1191          {          {
1192                  if (g_depth == 15 && g_server_bpp == 15)                  if ((g_depth == 15 && g_server_depth == 15) ||
1193                          return data;                      (g_depth == 16 && g_server_depth == 16) ||
1194                  if (g_depth == 16 && g_server_bpp == 16)                      (g_depth == 24 && g_server_depth == 24))
                         return data;  
                 if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24)  
1195                          return data;                          return data;
1196          }          }
1197    
# Line 859  translate_image(int width, int height, u Line 1199  translate_image(int width, int height, u
1199          out = (uint8 *) xmalloc(size);          out = (uint8 *) xmalloc(size);
1200          end = out + size;          end = out + size;
1201    
1202          switch (g_server_bpp)          switch (g_server_depth)
1203          {          {
1204                  case 24:                  case 24:
1205                          switch (g_bpp)                          switch (g_bpp)
# Line 957  calculate_shifts(uint32 mask, int *shift Line 1297  calculate_shifts(uint32 mask, int *shift
1297          *shift_r = 8 - ffs(mask & ~(mask >> 1));          *shift_r = 8 - ffs(mask & ~(mask >> 1));
1298  }  }
1299    
1300  BOOL  /* Given a mask of a colour channel (e.g. XVisualInfo.red_mask),
1301  ui_init(void)     calculates the bits-per-pixel of this channel (a.k.a. colour weight).
1302     */
1303    static unsigned
1304    calculate_mask_weight(uint32 mask)
1305    {
1306            unsigned weight = 0;
1307            do
1308            {
1309                    weight += (mask & 1);
1310            }
1311            while (mask >>= 1);
1312            return weight;
1313    }
1314    
1315    static BOOL
1316    select_visual(int screen_num)
1317  {  {
         XVisualInfo vi;  
1318          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
1319          uint16 test;          int pixmap_formats_count, visuals_count;
         int i, screen_num, nvisuals;  
1320          XVisualInfo *vmatches = NULL;          XVisualInfo *vmatches = NULL;
1321          XVisualInfo template;          XVisualInfo template;
1322          Bool TrueColorVisual = False;          int i;
1323            unsigned red_weight, blue_weight, green_weight;
1324    
1325          g_display = XOpenDisplay(NULL);          red_weight = blue_weight = green_weight = 0;
1326          if (g_display == NULL)  
1327            if (g_server_depth == -1)
1328          {          {
1329                  error("Failed to open display: %s\n", XDisplayName(NULL));                  g_server_depth = DisplayPlanes(g_display, DefaultScreen(g_display));
                 return False;  
1330          }          }
1331    
1332          screen_num = DefaultScreen(g_display);          pfm = XListPixmapFormats(g_display, &pixmap_formats_count);
1333          g_x_socket = ConnectionNumber(g_display);          if (pfm == NULL)
1334          g_screen = ScreenOfDisplay(g_display, screen_num);          {
1335          g_depth = DefaultDepthOfScreen(g_screen);                  error("Unable to get list of pixmap formats from display.\n");
1336                    XCloseDisplay(g_display);
1337                    return False;
1338            }
1339    
1340          /* Search for best TrueColor depth */          /* Search for best TrueColor visual */
1341          template.class = TrueColor;          template.class = TrueColor;
1342          vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);          template.screen = screen_num;
1343            vmatches =
1344                    XGetVisualInfo(g_display, VisualClassMask | VisualScreenMask, &template,
1345                                   &visuals_count);
1346            g_visual = NULL;
1347            g_no_translate_image = False;
1348            g_compatible_arch = False;
1349            if (vmatches != NULL)
1350            {
1351                    for (i = 0; i < visuals_count; ++i)
1352                    {
1353                            XVisualInfo *visual_info = &vmatches[i];
1354                            BOOL can_translate_to_bpp = False;
1355                            int j;
1356    
1357                            /* Try to find a no-translation visual that'll
1358                               allow us to use RDP bitmaps directly as ZPixmaps. */
1359                            if (!g_xserver_be && (((visual_info->depth == 15) &&
1360                                                   /* R5G5B5 */
1361                                                   (visual_info->red_mask == 0x7c00) &&
1362                                                   (visual_info->green_mask == 0x3e0) &&
1363                                                   (visual_info->blue_mask == 0x1f)) ||
1364                                                  ((visual_info->depth == 16) &&
1365                                                   /* R5G6B5 */
1366                                                   (visual_info->red_mask == 0xf800) &&
1367                                                   (visual_info->green_mask == 0x7e0) &&
1368                                                   (visual_info->blue_mask == 0x1f)) ||
1369                                                  ((visual_info->depth == 24) &&
1370                                                   /* R8G8B8 */
1371                                                   (visual_info->red_mask == 0xff0000) &&
1372                                                   (visual_info->green_mask == 0xff00) &&
1373                                                   (visual_info->blue_mask == 0xff))))
1374                            {
1375                                    g_visual = visual_info->visual;
1376                                    g_depth = visual_info->depth;
1377                                    g_compatible_arch = !g_host_be;
1378                                    g_no_translate_image = (visual_info->depth == g_server_depth);
1379                                    if (g_no_translate_image)
1380                                            /* We found the best visual */
1381                                            break;
1382                            }
1383                            else
1384                            {
1385                                    g_compatible_arch = False;
1386                            }
1387    
1388                            if (visual_info->depth > 24)
1389                            {
1390                                    /* Avoid 32-bit visuals and likes like the plague.
1391                                       They're either untested or proven to work bad
1392                                       (e.g. nvidia's Composite 32-bit visual).
1393                                       Most implementation offer a 24-bit visual anyway. */
1394                                    continue;
1395                            }
1396    
1397          nvisuals--;                          /* Only care for visuals, for whose BPPs (not depths!)
1398          while (nvisuals >= 0)                             we have a translateXtoY function. */
1399          {                          for (j = 0; j < pixmap_formats_count; ++j)
1400                  if ((vmatches + nvisuals)->depth > g_depth)                          {
1401                  {                                  if (pfm[j].depth == visual_info->depth)
1402                          g_depth = (vmatches + nvisuals)->depth;                                  {
1403                                            if ((pfm[j].bits_per_pixel == 16) ||
1404                                                (pfm[j].bits_per_pixel == 24) ||
1405                                                (pfm[j].bits_per_pixel == 32))
1406                                            {
1407                                                    can_translate_to_bpp = True;
1408                                            }
1409                                            break;
1410                                    }
1411                            }
1412    
1413                            /* Prefer formats which have the most colour depth.
1414                               We're being truly aristocratic here, minding each
1415                               weight on its own. */
1416                            if (can_translate_to_bpp)
1417                            {
1418                                    unsigned vis_red_weight =
1419                                            calculate_mask_weight(visual_info->red_mask);
1420                                    unsigned vis_green_weight =
1421                                            calculate_mask_weight(visual_info->green_mask);
1422                                    unsigned vis_blue_weight =
1423                                            calculate_mask_weight(visual_info->blue_mask);
1424                                    if ((vis_red_weight >= red_weight)
1425                                        && (vis_green_weight >= green_weight)
1426                                        && (vis_blue_weight >= blue_weight))
1427                                    {
1428                                            red_weight = vis_red_weight;
1429                                            green_weight = vis_green_weight;
1430                                            blue_weight = vis_blue_weight;
1431                                            g_visual = visual_info->visual;
1432                                            g_depth = visual_info->depth;
1433                                    }
1434                            }
1435                  }                  }
1436                  nvisuals--;                  XFree(vmatches);
                 TrueColorVisual = True;  
1437          }          }
1438    
1439          test = 1;          if (g_visual != NULL)
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
   
         if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))  
1440          {          {
1441                  /* we use a colourmap, so the default visual should do */                  g_owncolmap = False;
1442                  g_visual = DefaultVisualOfScreen(g_screen);                  calculate_shifts(g_visual->red_mask, &g_red_shift_r, &g_red_shift_l);
1443                  g_depth = DefaultDepthOfScreen(g_screen);                  calculate_shifts(g_visual->green_mask, &g_green_shift_r, &g_green_shift_l);
1444                    calculate_shifts(g_visual->blue_mask, &g_blue_shift_r, &g_blue_shift_l);
                 /* Do not allocate colours on a TrueColor visual */  
                 if (g_visual->class == TrueColor)  
                 {  
                         g_owncolmap = False;  
                 }  
1445          }          }
1446          else          else
1447          {          {
1448                  /* need a truecolour visual */                  template.class = PseudoColor;
1449                  if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))                  template.depth = 8;
1450                  {                  template.colormap_size = 256;
1451                          error("The display does not support true colour - high colour support unavailable.\n");                  vmatches =
1452                            XGetVisualInfo(g_display,
1453                                           VisualClassMask | VisualDepthMask | VisualColormapSizeMask,
1454                                           &template, &visuals_count);
1455                    if (vmatches == NULL)
1456                    {
1457                            error("No usable TrueColor or PseudoColor visuals on this display.\n");
1458                            XCloseDisplay(g_display);
1459                            XFree(pfm);
1460                          return False;                          return False;
1461                  }                  }
1462    
1463                  g_visual = vi.visual;                  /* we use a colourmap, so the default visual should do */
1464                  g_owncolmap = False;                  g_owncolmap = True;
1465                  calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);                  g_visual = vmatches[0].visual;
1466                  calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);                  g_depth = vmatches[0].depth;
1467                  calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);          }
1468    
1469                  /* if RGB video and everything is little endian */          g_bpp = 0;
1470                  if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) &&          for (i = 0; i < pixmap_formats_count; ++i)
1471                      !g_xserver_be && !g_host_be)          {
1472                    XPixmapFormatValues *pf = &pfm[i];
1473                    if (pf->depth == g_depth)
1474                  {                  {
1475                          if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 &&                          g_bpp = pf->bits_per_pixel;
1476                                                g_blue_shift_l == 0))  
1477                            if (g_no_translate_image)
1478                          {                          {
1479                                  g_arch_match = True;                                  switch (g_server_depth)
1480                                    {
1481                                            case 15:
1482                                            case 16:
1483                                                    if (g_bpp != 16)
1484                                                            g_no_translate_image = False;
1485                                                    break;
1486                                            case 24:
1487                                                    /* Yes, this will force image translation
1488                                                       on most modern servers which use 32 bits
1489                                                       for R8G8B8. */
1490                                                    if (g_bpp != 24)
1491                                                            g_no_translate_image = False;
1492                                                    break;
1493                                            default:
1494                                                    g_no_translate_image = False;
1495                                                    break;
1496                                    }
1497                          }                          }
                 }  
1498    
1499                  if (g_arch_match)                          /* Pixmap formats list is a depth-to-bpp mapping --
1500                  {                             there's just a single entry for every depth,
1501                          DEBUG(("Architectures match, enabling little endian optimisations.\n"));                             so we can safely break here */
1502                            break;
1503                  }                  }
1504          }          }
1505            XFree(pfm);
1506            pfm = NULL;
1507            return True;
1508    }
1509    
1510          pfm = XListPixmapFormats(g_display, &i);  static XErrorHandler g_old_error_handler;
1511          if (pfm != NULL)  
1512    static int
1513    error_handler(Display * dpy, XErrorEvent * eev)
1514    {
1515            if ((eev->error_code == BadMatch) && (eev->request_code == X_ConfigureWindow))
1516          {          {
1517                  /* Use maximum bpp for this depth - this is generally                  fprintf(stderr, "Got \"BadMatch\" when trying to restack windows.\n");
1518                     desirable, e.g. 24 bits->32 bits. */                  fprintf(stderr,
1519                  while (i--)                          "This is most likely caused by a broken window manager (commonly KWin).\n");
1520                  {                  return 0;
                         if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp))  
                         {  
                                 g_bpp = pfm[i].bits_per_pixel;  
                         }  
                 }  
                 XFree(pfm);  
1521          }          }
1522    
1523          if (g_bpp < 8)          return g_old_error_handler(dpy, eev);
1524    }
1525    
1526    BOOL
1527    ui_init(void)
1528    {
1529            int screen_num;
1530    
1531            g_display = XOpenDisplay(NULL);
1532            if (g_display == NULL)
1533          {          {
1534                  error("Less than 8 bpp not currently supported.\n");                  error("Failed to open display: %s\n", XDisplayName(NULL));
1535                  XCloseDisplay(g_display);                  return False;
1536            }
1537    
1538            {
1539                    uint16 endianess_test = 1;
1540                    g_host_be = !(BOOL) (*(uint8 *) (&endianess_test));
1541            }
1542    
1543            g_old_error_handler = XSetErrorHandler(error_handler);
1544            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
1545            screen_num = DefaultScreen(g_display);
1546            g_x_socket = ConnectionNumber(g_display);
1547            g_screen = ScreenOfDisplay(g_display, screen_num);
1548            g_depth = DefaultDepthOfScreen(g_screen);
1549    
1550            if (!select_visual(screen_num))
1551                  return False;                  return False;
1552    
1553            if (g_no_translate_image)
1554            {
1555                    DEBUG(("Performance optimization possible: avoiding image translation (colour depth conversion).\n"));
1556          }          }
1557    
1558            if (g_server_depth > g_bpp)
1559            {
1560                    warning("Remote desktop colour depth %d higher than display colour depth %d.\n",
1561                            g_server_depth, g_bpp);
1562            }
1563    
1564            DEBUG(("RDP depth: %d, display depth: %d, display bpp: %d, X server BE: %d, host BE: %d\n",
1565                   g_server_depth, g_depth, g_bpp, g_xserver_be, g_host_be));
1566    
1567          if (!g_owncolmap)          if (!g_owncolmap)
1568          {          {
1569                  g_xcolmap =                  g_xcolmap =
1570                          XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,                          XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
1571                                          AllocNone);                                          AllocNone);
1572                  if (g_depth <= 8)                  if (g_depth <= 8)
1573                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");                          warning("Display colour depth is %d bit: you may want to use -C for a private colourmap.\n", g_depth);
1574          }          }
1575    
1576          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
1577          {          {
1578                  warning("External BackingStore not available, using internal\n");                  warning("External BackingStore not available. Using internal.\n");
1579                  g_ownbackstore = True;                  g_ownbackstore = True;
1580          }          }
1581    
# Line 1087  ui_init(void) Line 1586  ui_init(void)
1586          {          {
1587                  g_width = WidthOfScreen(g_screen);                  g_width = WidthOfScreen(g_screen);
1588                  g_height = HeightOfScreen(g_screen);                  g_height = HeightOfScreen(g_screen);
1589                    g_using_full_workarea = True;
1590          }          }
1591          else if (g_width < 0)          else if (g_width < 0)
1592          {          {
1593                  /* Percent of screen */                  /* Percent of screen */
1594                    if (-g_width >= 100)
1595                            g_using_full_workarea = True;
1596                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;                  g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
1597                  g_width = WidthOfScreen(g_screen) * (-g_width) / 100;                  g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
1598          }          }
# Line 1098  ui_init(void) Line 1600  ui_init(void)
1600          {          {
1601                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
1602                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
   
1603                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
1604                  {                  {
1605                          g_width = cx;                          g_width = cx;
1606                          g_height = cy;                          g_height = cy;
1607                            g_using_full_workarea = True;
1608                  }                  }
1609                  else                  else
1610                  {                  {
1611                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");
1612                          g_width = 800;                          g_width = WidthOfScreen(g_screen);
1613                          g_height = 600;                          g_height = HeightOfScreen(g_screen);
1614                  }                  }
1615          }          }
1616    
# Line 1123  ui_init(void) Line 1625  ui_init(void)
1625                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
1626    
1627          xclip_init();          xclip_init();
1628            ewmh_init();
1629            if (g_seamless_rdp)
1630                    seamless_init();
1631    
1632          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_depth, g_bpp, g_depth));
1633    
1634          return True;          return True;
1635  }  }
# Line 1132  ui_init(void) Line 1637  ui_init(void)
1637  void  void
1638  ui_deinit(void)  ui_deinit(void)
1639  {  {
1640            while (g_seamless_windows)
1641            {
1642                    XDestroyWindow(g_display, g_seamless_windows->wnd);
1643                    sw_remove_window(g_seamless_windows);
1644            }
1645    
1646            xclip_deinit();
1647    
1648          if (g_IM != NULL)          if (g_IM != NULL)
1649                  XCloseIM(g_IM);                  XCloseIM(g_IM);
1650    
# Line 1148  ui_deinit(void) Line 1661  ui_deinit(void)
1661          g_display = NULL;          g_display = NULL;
1662  }  }
1663    
1664    
1665    static void
1666    get_window_attribs(XSetWindowAttributes * attribs)
1667    {
1668            attribs->background_pixel = BlackPixelOfScreen(g_screen);
1669            attribs->background_pixel = WhitePixelOfScreen(g_screen);
1670            attribs->border_pixel = WhitePixelOfScreen(g_screen);
1671            attribs->backing_store = g_ownbackstore ? NotUseful : Always;
1672            attribs->override_redirect = g_fullscreen;
1673            attribs->colormap = g_xcolmap;
1674    }
1675    
1676    static void
1677    get_input_mask(long *input_mask)
1678    {
1679            *input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1680                    VisibilityChangeMask | FocusChangeMask | StructureNotifyMask;
1681    
1682            if (g_sendmotion)
1683                    *input_mask |= PointerMotionMask;
1684            if (g_ownbackstore)
1685                    *input_mask |= ExposureMask;
1686            if (g_fullscreen || g_grab_keyboard)
1687                    *input_mask |= EnterWindowMask;
1688            if (g_grab_keyboard)
1689                    *input_mask |= LeaveWindowMask;
1690    }
1691    
1692  BOOL  BOOL
1693  ui_create_window(void)  ui_create_window(void)
1694  {  {
# Line 1170  ui_create_window(void) Line 1711  ui_create_window(void)
1711          if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4)))          if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4)))
1712                  g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height;                  g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height;
1713    
1714          attribs.background_pixel = BlackPixelOfScreen(g_screen);          get_window_attribs(&attribs);
         attribs.border_pixel = WhitePixelOfScreen(g_screen);  
         attribs.backing_store = g_ownbackstore ? NotUseful : Always;  
         attribs.override_redirect = g_fullscreen;  
         attribs.colormap = g_xcolmap;  
1715    
1716          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,
1717                                wndheight, 0, g_depth, InputOutput, g_visual,                                wndheight, 0, g_depth, InputOutput, g_visual,
# Line 1182  ui_create_window(void) Line 1719  ui_create_window(void)
1719                                CWBorderPixel, &attribs);                                CWBorderPixel, &attribs);
1720    
1721          if (g_gc == NULL)          if (g_gc == NULL)
1722            {
1723                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
1724                    ui_reset_clip();
1725            }
1726    
1727          if (g_create_bitmap_gc == NULL)          if (g_create_bitmap_gc == NULL)
1728                  g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);                  g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);
# Line 1199  ui_create_window(void) Line 1739  ui_create_window(void)
1739          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
1740    
1741          if (g_hide_decorations)          if (g_hide_decorations)
1742                  mwm_hide_decorations();                  mwm_hide_decorations(g_wnd);
1743    
1744          classhints = XAllocClassHint();          classhints = XAllocClassHint();
1745          if (classhints != NULL)          if (classhints != NULL)
# Line 1226  ui_create_window(void) Line 1766  ui_create_window(void)
1766                  XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);                  XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1767          }          }
1768    
1769          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          get_input_mask(&input_mask);
                 VisibilityChangeMask | FocusChangeMask;  
   
         if (g_sendmotion)  
                 input_mask |= PointerMotionMask;  
         if (g_ownbackstore)  
                 input_mask |= ExposureMask;  
         if (g_fullscreen || g_grab_keyboard)  
                 input_mask |= EnterWindowMask;  
         if (g_grab_keyboard)  
                 input_mask |= LeaveWindowMask;  
1770    
1771          if (g_IM != NULL)          if (g_IM != NULL)
1772          {          {
# Line 1321  xwin_toggle_fullscreen(void) Line 1851  xwin_toggle_fullscreen(void)
1851  {  {
1852          Pixmap contents = 0;          Pixmap contents = 0;
1853    
1854            if (g_seamless_active)
1855                    /* Turn off SeamlessRDP mode */
1856                    ui_seamless_toggle();
1857    
1858          if (!g_ownbackstore)          if (!g_ownbackstore)
1859          {          {
1860                  /* need to save contents of window */                  /* need to save contents of window */
# Line 1341  xwin_toggle_fullscreen(void) Line 1875  xwin_toggle_fullscreen(void)
1875          }          }
1876  }  }
1877    
1878  /* Process all events in Xlib queue  static void
1879    handle_button_event(XEvent xevent, BOOL down)
1880    {
1881            uint16 button, flags = 0;
1882            g_last_gesturetime = xevent.xbutton.time;
1883            button = xkeymap_translate_button(xevent.xbutton.button);
1884            if (button == 0)
1885                    return;
1886    
1887            if (down)
1888                    flags = MOUSE_FLAG_DOWN;
1889    
1890            /* Stop moving window when button is released, regardless of cursor position */
1891            if (g_moving_wnd && (xevent.type == ButtonRelease))
1892                    g_moving_wnd = False;
1893    
1894            /* If win_button_size is nonzero, enable single app mode */
1895            if (xevent.xbutton.y < g_win_button_size)
1896            {
1897                    /*  Check from right to left: */
1898                    if (xevent.xbutton.x >= g_width - g_win_button_size)
1899                    {
1900                            /* The close button, continue */
1901                            ;
1902                    }
1903                    else if (xevent.xbutton.x >= g_width - g_win_button_size * 2)
1904                    {
1905                            /* The maximize/restore button. Do not send to
1906                               server.  It might be a good idea to change the
1907                               cursor or give some other visible indication
1908                               that rdesktop inhibited this click */
1909                            if (xevent.type == ButtonPress)
1910                                    return;
1911                    }
1912                    else if (xevent.xbutton.x >= g_width - g_win_button_size * 3)
1913                    {
1914                            /* The minimize button. Iconify window. */
1915                            if (xevent.type == ButtonRelease)
1916                            {
1917                                    /* Release the mouse button outside the minimize button, to prevent the
1918                                       actual minimazation to happen */
1919                                    rdp_send_input(time(NULL), RDP_INPUT_MOUSE, button, 1, 1);
1920                                    XIconifyWindow(g_display, g_wnd, DefaultScreen(g_display));
1921                                    return;
1922                            }
1923                    }
1924                    else if (xevent.xbutton.x <= g_win_button_size)
1925                    {
1926                            /* The system menu. Ignore. */
1927                            if (xevent.type == ButtonPress)
1928                                    return;
1929                    }
1930                    else
1931                    {
1932                            /* The title bar. */
1933                            if (xevent.type == ButtonPress)
1934                            {
1935                                    if (!g_fullscreen && g_hide_decorations && !g_using_full_workarea)
1936                                    {
1937                                            g_moving_wnd = True;
1938                                            g_move_x_offset = xevent.xbutton.x;
1939                                            g_move_y_offset = xevent.xbutton.y;
1940                                    }
1941                                    return;
1942                            }
1943                    }
1944            }
1945    
1946            if (xevent.xmotion.window == g_wnd)
1947            {
1948                    rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
1949                                   flags | button, xevent.xbutton.x, xevent.xbutton.y);
1950            }
1951            else
1952            {
1953                    /* SeamlessRDP */
1954                    rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
1955                                   flags | button, xevent.xbutton.x_root, xevent.xbutton.y_root);
1956            }
1957    }
1958    
1959    
1960    /* Process events in Xlib queue
1961     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
1962  static int  static int
1963  xwin_process_events(void)  xwin_process_events(void)
1964  {  {
1965          XEvent xevent;          XEvent xevent;
1966          KeySym keysym;          KeySym keysym;
         uint16 button, flags;  
1967          uint32 ev_time;          uint32 ev_time;
         key_translation tr;  
1968          char str[256];          char str[256];
1969          Status status;          Status status;
1970            int events = 0;
1971            seamless_window *sw;
1972    
1973          while (XPending(g_display) > 0)          while ((XPending(g_display) > 0) && events++ < 20)
1974          {          {
1975                  XNextEvent(g_display, &xevent);                  XNextEvent(g_display, &xevent);
1976    
# Line 1364  xwin_process_events(void) Line 1980  xwin_process_events(void)
1980                          continue;                          continue;
1981                  }                  }
1982    
                 flags = 0;  
   
1983                  switch (xevent.type)                  switch (xevent.type)
1984                  {                  {
1985                          case VisibilityNotify:                          case VisibilityNotify:
1986                                  g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;                                  if (xevent.xvisibility.window == g_wnd)
1987                                            g_Unobscured =
1988                                                    xevent.xvisibility.state == VisibilityUnobscured;
1989    
1990                                  break;                                  break;
1991                          case ClientMessage:                          case ClientMessage:
1992                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
# Line 1402  xwin_process_events(void) Line 2019  xwin_process_events(void)
2019                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
2020                                  }                                  }
2021    
2022                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym,                                  DEBUG_KBD(("KeyPress for keysym (0x%lx, %s)\n", keysym,
2023                                             get_ksname(keysym)));                                             get_ksname(keysym)));
2024    
2025                                  ev_time = time(NULL);                                  ev_time = time(NULL);
2026                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))
2027                                          break;                                          break;
2028    
2029                                  tr = xkeymap_translate_key(keysym,                                  xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state,
2030                                                             xevent.xkey.keycode, xevent.xkey.state);                                                    ev_time, True, 0);
   
                                 if (tr.scancode == 0)  
                                         break;  
   
                                 save_remote_modifiers(tr.scancode);  
                                 ensure_remote_modifiers(ev_time, tr);  
                                 rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);  
                                 restore_remote_modifiers(ev_time, tr.scancode);  
   
2031                                  break;                                  break;
2032    
2033                          case KeyRelease:                          case KeyRelease:
# Line 1427  xwin_process_events(void) Line 2035  xwin_process_events(void)
2035                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
2036                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
2037    
2038                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,                                  DEBUG_KBD(("\nKeyRelease for keysym (0x%lx, %s)\n", keysym,
2039                                             get_ksname(keysym)));                                             get_ksname(keysym)));
2040    
2041                                  ev_time = time(NULL);                                  ev_time = time(NULL);
2042                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False))                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False))
2043                                          break;                                          break;
2044    
2045                                  tr = xkeymap_translate_key(keysym,                                  xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state,
2046                                                             xevent.xkey.keycode, xevent.xkey.state);                                                    ev_time, False, 0);
   
                                 if (tr.scancode == 0)  
                                         break;  
   
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);  
2047                                  break;                                  break;
2048    
2049                          case ButtonPress:                          case ButtonPress:
2050                                  flags = MOUSE_FLAG_DOWN;                                  handle_button_event(xevent, True);
2051                                  /* fall through */                                  break;
2052    
2053                          case ButtonRelease:                          case ButtonRelease:
2054                                  g_last_gesturetime = xevent.xbutton.time;                                  handle_button_event(xevent, False);
                                 button = xkeymap_translate_button(xevent.xbutton.button);  
                                 if (button == 0)  
                                         break;  
   
                                 /* If win_button_size is nonzero, enable single app mode */  
                                 if (xevent.xbutton.y < g_win_button_size)  
                                 {  
                                         /* Stop moving window when button is released, regardless of cursor position */  
                                         if (g_moving_wnd && (xevent.type == ButtonRelease))  
                                                 g_moving_wnd = False;  
   
                                         /*  Check from right to left: */  
   
                                         if (xevent.xbutton.x >= g_width - g_win_button_size)  
                                         {  
                                                 /* The close button, continue */  
                                                 ;  
                                         }  
                                         else if (xevent.xbutton.x >=  
                                                  g_width - g_win_button_size * 2)  
                                         {  
                                                 /* The maximize/restore button. Do not send to  
                                                    server.  It might be a good idea to change the  
                                                    cursor or give some other visible indication  
                                                    that rdesktop inhibited this click */  
                                                 break;  
                                         }  
                                         else if (xevent.xbutton.x >=  
                                                  g_width - g_win_button_size * 3)  
                                         {  
                                                 /* The minimize button. Iconify window. */  
                                                 XIconifyWindow(g_display, g_wnd,  
                                                                DefaultScreen(g_display));  
                                                 break;  
                                         }  
                                         else if (xevent.xbutton.x <= g_win_button_size)  
                                         {  
                                                 /* The system menu. Ignore. */  
                                                 break;  
                                         }  
                                         else  
                                         {  
                                                 /* The title bar. */  
                                                 if ((xevent.type == ButtonPress) && !g_fullscreen  
                                                     && g_hide_decorations)  
                                                 {  
                                                         g_moving_wnd = True;  
                                                         g_move_x_offset = xevent.xbutton.x;  
                                                         g_move_y_offset = xevent.xbutton.y;  
                                                 }  
                                                 break;  
   
                                         }  
                                 }  
   
                                 rdp_send_input(time(NULL), RDP_INPUT_MOUSE,  
                                                flags | button, xevent.xbutton.x, xevent.xbutton.y);  
2055                                  break;                                  break;
2056    
2057                          case MotionNotify:                          case MotionNotify:
# Line 1520  xwin_process_events(void) Line 2066  xwin_process_events(void)
2066                                  if (g_fullscreen && !g_focused)                                  if (g_fullscreen && !g_focused)
2067                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,
2068                                                         CurrentTime);                                                         CurrentTime);
2069                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,  
2070                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                  if (xevent.xmotion.window == g_wnd)
2071                                    {
2072                                            rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE,
2073                                                           xevent.xmotion.x, xevent.xmotion.y);
2074                                    }
2075                                    else
2076                                    {
2077                                            /* SeamlessRDP */
2078                                            rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE,
2079                                                           xevent.xmotion.x_root,
2080                                                           xevent.xmotion.y_root);
2081                                    }
2082                                  break;                                  break;
2083    
2084                          case FocusIn:                          case FocusIn:
# Line 1532  xwin_process_events(void) Line 2089  xwin_process_events(void)
2089                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
2090                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
2091                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
2092    
2093                                    sw = sw_get_window_by_wnd(xevent.xfocus.window);
2094                                    if (!sw)
2095                                            break;
2096    
2097                                    if (sw->id != g_seamless_focused)
2098                                    {
2099                                            seamless_send_focus(sw->id, 0);
2100                                            g_seamless_focused = sw->id;
2101                                    }
2102                                  break;                                  break;
2103    
2104                          case FocusOut:                          case FocusOut:
# Line 1564  xwin_process_events(void) Line 2131  xwin_process_events(void)
2131                                  break;                                  break;
2132    
2133                          case Expose:                          case Expose:
2134                                  XCopyArea(g_display, g_backstore, g_wnd, g_gc,                                  if (xevent.xexpose.window == g_wnd)
2135                                            xevent.xexpose.x, xevent.xexpose.y,                                  {
2136                                            xevent.xexpose.width,                                          XCopyArea(g_display, g_backstore, xevent.xexpose.window,
2137                                            xevent.xexpose.height,                                                    g_gc,
2138                                            xevent.xexpose.x, xevent.xexpose.y);                                                    xevent.xexpose.x, xevent.xexpose.y,
2139                                                      xevent.xexpose.width, xevent.xexpose.height,
2140                                                      xevent.xexpose.x, xevent.xexpose.y);
2141                                    }
2142                                    else
2143                                    {
2144                                            sw = sw_get_window_by_wnd(xevent.xexpose.window);
2145                                            if (!sw)
2146                                                    break;
2147                                            XCopyArea(g_display, g_backstore,
2148                                                      xevent.xexpose.window, g_gc,
2149                                                      xevent.xexpose.x + sw->xoffset,
2150                                                      xevent.xexpose.y + sw->yoffset,
2151                                                      xevent.xexpose.width,
2152                                                      xevent.xexpose.height, xevent.xexpose.x,
2153                                                      xevent.xexpose.y);
2154                                    }
2155    
2156                                  break;                                  break;
2157    
2158                          case MappingNotify:                          case MappingNotify:
# Line 1597  xwin_process_events(void) Line 2181  xwin_process_events(void)
2181                                  break;                                  break;
2182                          case PropertyNotify:                          case PropertyNotify:
2183                                  xclip_handle_PropertyNotify(&xevent.xproperty);                                  xclip_handle_PropertyNotify(&xevent.xproperty);
2184                                    if (xevent.xproperty.window == g_wnd)
2185                                            break;
2186                                    if (xevent.xproperty.window == DefaultRootWindow(g_display))
2187                                            break;
2188    
2189                                    /* seamless */
2190                                    sw = sw_get_window_by_wnd(xevent.xproperty.window);
2191                                    if (!sw)
2192                                            break;
2193    
2194                                    if ((xevent.xproperty.atom == g_net_wm_state_atom)
2195                                        && (xevent.xproperty.state == PropertyNewValue))
2196                                    {
2197                                            sw->state = ewmh_get_window_state(sw->wnd);
2198                                            seamless_send_state(sw->id, sw->state, 0);
2199                                    }
2200    
2201                                    if ((xevent.xproperty.atom == g_net_wm_desktop_atom)
2202                                        && (xevent.xproperty.state == PropertyNewValue))
2203                                    {
2204                                            sw->desktop = ewmh_get_window_desktop(sw->wnd);
2205                                            sw_all_to_desktop(sw->wnd, sw->desktop);
2206                                    }
2207    
2208                                    break;
2209                            case MapNotify:
2210                                    if (!g_seamless_active)
2211                                            rdp_send_client_window_status(1);
2212                                    break;
2213                            case UnmapNotify:
2214                                    if (!g_seamless_active)
2215                                            rdp_send_client_window_status(0);
2216                                    break;
2217                            case ConfigureNotify:
2218                                    if (!g_seamless_active)
2219                                            break;
2220    
2221                                    sw = sw_get_window_by_wnd(xevent.xconfigure.window);
2222                                    if (!sw)
2223                                            break;
2224    
2225                                    gettimeofday(sw->position_timer, NULL);
2226                                    if (sw->position_timer->tv_usec + SEAMLESSRDP_POSITION_TIMER >=
2227                                        1000000)
2228                                    {
2229                                            sw->position_timer->tv_usec +=
2230                                                    SEAMLESSRDP_POSITION_TIMER - 1000000;
2231                                            sw->position_timer->tv_sec += 1;
2232                                    }
2233                                    else
2234                                    {
2235                                            sw->position_timer->tv_usec += SEAMLESSRDP_POSITION_TIMER;
2236                                    }
2237    
2238                                    sw_handle_restack(sw);
2239                                  break;                                  break;
2240                  }                  }
2241          }          }
# Line 1621  ui_select(int rdp_socket) Line 2260  ui_select(int rdp_socket)
2260                          /* User quit */                          /* User quit */
2261                          return 0;                          return 0;
2262    
2263                    if (g_seamless_active)
2264                            sw_check_timers();
2265    
2266                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
2267                  FD_ZERO(&wfds);                  FD_ZERO(&wfds);
2268                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
2269                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
2270    
 #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  
2271                  /* default timeout */                  /* default timeout */
2272                  tv.tv_sec = 60;                  tv.tv_sec = 60;
2273                  tv.tv_usec = 0;                  tv.tv_usec = 0;
2274    
2275    #ifdef WITH_RDPSND
2276                    rdpsnd_add_fds(&n, &rfds, &wfds, &tv);
2277    #endif
2278    
2279                  /* add redirection handles */                  /* add redirection handles */
2280                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);                  rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
2281                    seamless_select_timeout(&tv);
2282    
2283                  n++;                  n++;
2284    
# Line 1649  ui_select(int rdp_socket) Line 2288  ui_select(int rdp_socket)
2288                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
2289    
2290                          case 0:                          case 0:
2291    #ifdef WITH_RDPSND
2292                                    rdpsnd_check_fds(&rfds, &wfds);
2293    #endif
2294    
2295                                  /* Abort serial read calls */                                  /* Abort serial read calls */
2296                                  if (s_timeout)                                  if (s_timeout)
2297                                          rdpdr_check_fds(&rfds, &wfds, (BOOL) True);                                          rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
2298                                  continue;                                  continue;
2299                  }                  }
2300    
2301    #ifdef WITH_RDPSND
2302                    rdpsnd_check_fds(&rfds, &wfds);
2303    #endif
2304    
2305                  rdpdr_check_fds(&rfds, &wfds, (BOOL) False);                  rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
2306    
2307                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
2308                          return 1;                          return 1;
2309    
 #ifdef WITH_RDPSND  
                 if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))  
                         wave_out_play();  
 #endif  
2310          }          }
2311  }  }
2312    
# Line 1681  ui_create_bitmap(int width, int height, Line 2324  ui_create_bitmap(int width, int height,
2324          uint8 *tdata;          uint8 *tdata;
2325          int bitmap_pad;          int bitmap_pad;
2326    
2327          if (g_server_bpp == 8)          if (g_server_depth == 8)
2328          {          {
2329                  bitmap_pad = 8;                  bitmap_pad = 8;
2330          }          }
# Line 1713  ui_paint_bitmap(int x, int y, int cx, in Line 2356  ui_paint_bitmap(int x, int y, int cx, in
2356          uint8 *tdata;          uint8 *tdata;
2357          int bitmap_pad;          int bitmap_pad;
2358    
2359          if (g_server_bpp == 8)          if (g_server_depth == 8)
2360          {          {
2361                  bitmap_pad = 8;                  bitmap_pad = 8;
2362          }          }
# Line 1733  ui_paint_bitmap(int x, int y, int cx, in Line 2376  ui_paint_bitmap(int x, int y, int cx, in
2376          {          {
2377                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);
2378                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
2379                    ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
2380                                            (g_display, g_backstore, sw->wnd, g_gc, x, y, cx, cy,
2381                                             x - sw->xoffset, y - sw->yoffset));
2382          }          }
2383          else          else
2384          {          {
2385                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);
2386                    ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
2387                                            (g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy,
2388                                             x - sw->xoffset, y - sw->yoffset));
2389          }          }
2390    
2391          XFree(image);          XFree(image);
# Line 1857  ui_set_cursor(HCURSOR cursor) Line 2506  ui_set_cursor(HCURSOR cursor)
2506  {  {
2507          g_current_cursor = (Cursor) cursor;          g_current_cursor = (Cursor) cursor;
2508          XDefineCursor(g_display, g_wnd, g_current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
2509            ON_ALL_SEAMLESS_WINDOWS(XDefineCursor, (g_display, sw->wnd, g_current_cursor));
2510  }  }
2511    
2512  void  void
# Line 1998  ui_set_colourmap(HCOLOURMAP map) Line 2648  ui_set_colourmap(HCOLOURMAP map)
2648                  g_colmap = (uint32 *) map;                  g_colmap = (uint32 *) map;
2649          }          }
2650          else          else
2651            {
2652                  XSetWindowColormap(g_display, g_wnd, (Colormap) map);                  XSetWindowColormap(g_display, g_wnd, (Colormap) map);
2653                    ON_ALL_SEAMLESS_WINDOWS(XSetWindowColormap, (g_display, sw->wnd, (Colormap) map));
2654            }
2655  }  }
2656    
2657  void  void
2658  ui_set_clip(int x, int y, int cx, int cy)  ui_set_clip(int x, int y, int cx, int cy)
2659  {  {
2660          XRectangle rect;          g_clip_rectangle.x = x;
2661            g_clip_rectangle.y = y;
2662          rect.x = x;          g_clip_rectangle.width = cx;
2663          rect.y = y;          g_clip_rectangle.height = cy;
2664          rect.width = cx;          XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded);
         rect.height = cy;  
         XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);  
2665  }  }
2666    
2667  void  void
2668  ui_reset_clip(void)  ui_reset_clip(void)
2669  {  {
2670          XRectangle rect;          g_clip_rectangle.x = 0;
2671            g_clip_rectangle.y = 0;
2672          rect.x = 0;          g_clip_rectangle.width = g_width;
2673          rect.y = 0;          g_clip_rectangle.height = g_height;
2674          rect.width = g_width;          XSetClipRectangles(g_display, g_gc, 0, 0, &g_clip_rectangle, 1, YXBanded);
         rect.height = g_height;  
         XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);  
2675  }  }
2676    
2677  void  void
# Line 2103  ui_patblt(uint8 opcode, Line 2752  ui_patblt(uint8 opcode,
2752    
2753          if (g_ownbackstore)          if (g_ownbackstore)
2754                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
2755            ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
2756                                    (g_display, g_ownbackstore ? g_backstore : g_wnd, sw->wnd, g_gc,
2757                                     x, y, cx, cy, x - sw->xoffset, y - sw->yoffset));
2758  }  }
2759    
2760  void  void
# Line 2113  ui_screenblt(uint8 opcode, Line 2765  ui_screenblt(uint8 opcode,
2765          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
2766          if (g_ownbackstore)          if (g_ownbackstore)
2767          {          {
2768                  if (g_Unobscured)                  XCopyArea(g_display, g_Unobscured ? g_wnd : g_backstore,
2769                  {                            g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2770                          XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
                         XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,  
                                   y);  
                 }  
                 else  
                 {  
                         XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
                         XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,  
                                   y);  
                 }  
2771          }          }
2772          else          else
2773          {          {
2774                  XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2775          }          }
2776    
2777            ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
2778                                    (g_display, g_ownbackstore ? g_backstore : g_wnd,
2779                                     sw->wnd, g_gc, x, y, cx, cy, x - sw->xoffset, y - sw->yoffset));
2780    
2781          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
2782  }  }
2783    
# Line 2140  ui_memblt(uint8 opcode, Line 2788  ui_memblt(uint8 opcode,
2788  {  {
2789          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
2790          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);
2791            ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
2792                                    (g_display, (Pixmap) src, sw->wnd, g_gc,
2793                                     srcx, srcy, cx, cy, x - sw->xoffset, y - sw->yoffset));
2794          if (g_ownbackstore)          if (g_ownbackstore)
2795                  XCopyArea(g_display, (Pixmap) src, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, (Pixmap) src, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
2796          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
# Line 2186  ui_line(uint8 opcode, Line 2837  ui_line(uint8 opcode,
2837          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
2838          SET_FOREGROUND(pen->colour);          SET_FOREGROUND(pen->colour);
2839          XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy);          XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy);
2840            ON_ALL_SEAMLESS_WINDOWS(XDrawLine, (g_display, sw->wnd, g_gc,
2841                                                startx - sw->xoffset, starty - sw->yoffset,
2842                                                endx - sw->xoffset, endy - sw->yoffset));
2843          if (g_ownbackstore)          if (g_ownbackstore)
2844                  XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy);                  XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy);
2845          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
# Line 2283  ui_polyline(uint8 opcode, Line 2937  ui_polyline(uint8 opcode,
2937          if (g_ownbackstore)          if (g_ownbackstore)
2938                  XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints,                  XDrawLines(g_display, g_backstore, g_gc, (XPoint *) points, npoints,
2939                             CoordModePrevious);                             CoordModePrevious);
2940    
2941            ON_ALL_SEAMLESS_WINDOWS(seamless_XDrawLines,
2942                                    (sw->wnd, (XPoint *) points, npoints, sw->xoffset, sw->yoffset));
2943    
2944          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
2945  }  }
2946    
# Line 2438  ui_draw_text(uint8 font, uint8 flags, ui Line 3096  ui_draw_text(uint8 font, uint8 flags, ui
3096                  switch (text[i])                  switch (text[i])
3097                  {                  {
3098                          case 0xff:                          case 0xff:
3099                                  if (i + 2 < length)                                  /* At least two bytes needs to follow */
3100                                          cache_put_text(text[i + 1], text, text[i + 2]);                                  if (i + 3 > length)
                                 else  
3101                                  {                                  {
3102                                          error("this shouldn't be happening\n");                                          warning("Skipping short 0xff command:");
3103                                          exit(1);                                          for (j = 0; j < length; j++)
3104                                                    fprintf(stderr, "%02x ", text[j]);
3105                                            fprintf(stderr, "\n");
3106                                            i = length = 0;
3107                                            break;
3108                                  }                                  }
3109                                    cache_put_text(text[i + 1], text, text[i + 2]);
3110                                    i += 3;
3111                                    length -= i;
3112                                  /* this will move pointer from start to first character after FF command */                                  /* this will move pointer from start to first character after FF command */
3113                                  length -= i + 3;                                  text = &(text[i]);
                                 text = &(text[i + 3]);  
3114                                  i = 0;                                  i = 0;
3115                                  break;                                  break;
3116    
3117                          case 0xfe:                          case 0xfe:
3118                                    /* At least one byte needs to follow */
3119                                    if (i + 2 > length)
3120                                    {
3121                                            warning("Skipping short 0xfe command:");
3122                                            for (j = 0; j < length; j++)
3123                                                    fprintf(stderr, "%02x ", text[j]);
3124                                            fprintf(stderr, "\n");
3125                                            i = length = 0;
3126                                            break;
3127                                    }
3128                                  entry = cache_get_text(text[i + 1]);                                  entry = cache_get_text(text[i + 1]);
3129                                  if (entry != NULL)                                  if (entry->data != NULL)
3130                                  {                                  {
3131                                          if ((((uint8 *) (entry->data))[1] ==                                          if ((((uint8 *) (entry->data))[1] == 0)
3132                                               0) && (!(flags & TEXT2_IMPLICIT_X)))                                              && (!(flags & TEXT2_IMPLICIT_X)) && (i + 2 < length))
3133                                          {                                          {
3134                                                  if (flags & TEXT2_VERTICAL)                                                  if (flags & TEXT2_VERTICAL)
3135                                                          y += text[i + 2];                                                          y += text[i + 2];
# Line 2488  ui_draw_text(uint8 font, uint8 flags, ui Line 3161  ui_draw_text(uint8 font, uint8 flags, ui
3161          if (g_ownbackstore)          if (g_ownbackstore)
3162          {          {
3163                  if (boxcx > 1)                  if (boxcx > 1)
3164                    {
3165                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx,
3166                                    boxy, boxcx, boxcy, boxx, boxy);                                    boxy, boxcx, boxcy, boxx, boxy);
3167                            ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
3168                                                    (g_display, g_backstore, sw->wnd, g_gc,
3169                                                     boxx, boxy,
3170                                                     boxcx, boxcy,
3171                                                     boxx - sw->xoffset, boxy - sw->yoffset));
3172                    }
3173                  else                  else
3174                    {
3175                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx,
3176                                    clipy, clipcx, clipcy, clipx, clipy);                                    clipy, clipcx, clipcy, clipx, clipy);
3177                            ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
3178                                                    (g_display, g_backstore, sw->wnd, g_gc,
3179                                                     clipx, clipy,
3180                                                     clipcx, clipcy, clipx - sw->xoffset,
3181                                                     clipy - sw->yoffset));
3182                    }
3183          }          }
3184  }  }
3185    
# Line 2538  ui_desktop_restore(uint32 offset, int x, Line 3225  ui_desktop_restore(uint32 offset, int x,
3225          {          {
3226                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);
3227                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
3228                    ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
3229                                            (g_display, g_backstore, sw->wnd, g_gc,
3230                                             x, y, cx, cy, x - sw->xoffset, y - sw->yoffset));
3231          }          }
3232          else          else
3233          {          {
3234                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);
3235                    ON_ALL_SEAMLESS_WINDOWS(XCopyArea,
3236                                            (g_display, g_wnd, sw->wnd, g_gc, x, y, cx, cy,
3237                                             x - sw->xoffset, y - sw->yoffset));
3238          }          }
3239    
3240          XFree(image);          XFree(image);
# Line 2557  void Line 3250  void
3250  ui_end_update(void)  ui_end_update(void)
3251  {  {
3252  }  }
3253    
3254    
3255    void
3256    ui_seamless_begin(BOOL hidden)
3257    {
3258            if (!g_seamless_rdp)
3259                    return;
3260    
3261            if (g_seamless_started)
3262                    return;
3263    
3264            g_seamless_started = True;
3265            g_seamless_hidden = hidden;
3266    
3267            if (!hidden)
3268                    ui_seamless_toggle();
3269    }
3270    
3271    
3272    void
3273    ui_seamless_hide_desktop()
3274    {
3275            if (!g_seamless_rdp)
3276                    return;
3277    
3278            if (!g_seamless_started)
3279                    return;
3280    
3281            if (g_seamless_active)
3282                    ui_seamless_toggle();
3283    
3284            g_seamless_hidden = True;
3285    }
3286    
3287    
3288    void
3289    ui_seamless_unhide_desktop()
3290    {
3291            if (!g_seamless_rdp)
3292                    return;
3293    
3294            if (!g_seamless_started)
3295                    return;
3296    
3297            g_seamless_hidden = False;
3298    
3299            ui_seamless_toggle();
3300    }
3301    
3302    
3303    void
3304    ui_seamless_toggle()
3305    {
3306            if (!g_seamless_rdp)
3307                    return;
3308    
3309            if (!g_seamless_started)
3310                    return;
3311    
3312            if (g_seamless_hidden)
3313                    return;
3314    
3315            if (g_seamless_active)
3316            {
3317                    /* Deactivate */
3318                    while (g_seamless_windows)
3319                    {
3320                            XDestroyWindow(g_display, g_seamless_windows->wnd);
3321                            sw_remove_window(g_seamless_windows);
3322                    }
3323                    XMapWindow(g_display, g_wnd);
3324            }
3325            else
3326            {
3327                    /* Activate */
3328                    XUnmapWindow(g_display, g_wnd);
3329                    seamless_send_sync();
3330            }
3331    
3332            g_seamless_active = !g_seamless_active;
3333    }
3334    
3335    
3336    void
3337    ui_seamless_create_window(unsigned long id, unsigned long group, unsigned long parent,
3338                              unsigned long flags)
3339    {
3340            Window wnd;
3341            XSetWindowAttributes attribs;
3342            XClassHint *classhints;
3343            XSizeHints *sizehints;
3344            XWMHints *wmhints;
3345            long input_mask;
3346            seamless_window *sw, *sw_parent;
3347    
3348            if (!g_seamless_active)
3349                    return;
3350    
3351            /* Ignore CREATEs for existing windows */
3352            sw = sw_get_window_by_id(id);
3353            if (sw)
3354                    return;
3355    
3356            get_window_attribs(&attribs);
3357            wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, g_depth,
3358                                InputOutput, g_visual,
3359                                CWBackPixel | CWBackingStore | CWColormap | CWBorderPixel, &attribs);
3360    
3361            XStoreName(g_display, wnd, "SeamlessRDP");
3362            ewmh_set_wm_name(wnd, "SeamlessRDP");
3363    
3364            mwm_hide_decorations(wnd);
3365    
3366            classhints = XAllocClassHint();
3367            if (classhints != NULL)
3368            {
3369                    classhints->res_name = "rdesktop";
3370                    classhints->res_class = "SeamlessRDP";
3371                    XSetClassHint(g_display, wnd, classhints);
3372                    XFree(classhints);
3373            }
3374    
3375            /* WM_NORMAL_HINTS */
3376            sizehints = XAllocSizeHints();
3377            if (sizehints != NULL)
3378            {
3379                    sizehints->flags = USPosition;
3380                    XSetWMNormalHints(g_display, wnd, sizehints);
3381                    XFree(sizehints);
3382            }
3383    
3384            /* Parent-less transient windows */
3385            if (parent == 0xFFFFFFFF)
3386            {
3387                    XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen));
3388                    /* Some buggy wm:s (kwin) do not handle the above, so fake it
3389                       using some other hints. */
3390                    ewmh_set_window_popup(wnd);
3391            }
3392            /* Normal transient windows */
3393            else if (parent != 0x00000000)
3394            {
3395                    sw_parent = sw_get_window_by_id(parent);
3396                    if (sw_parent)
3397                            XSetTransientForHint(g_display, wnd, sw_parent->wnd);
3398                    else
3399                            warning("ui_seamless_create_window: No parent window 0x%lx\n", parent);
3400            }
3401    
3402            if (flags & SEAMLESSRDP_CREATE_MODAL)
3403            {
3404                    /* We do this to support buggy wm:s (*cough* metacity *cough*)
3405                       somewhat at least */
3406                    if (parent == 0x00000000)
3407                            XSetTransientForHint(g_display, wnd, RootWindowOfScreen(g_screen));
3408                    ewmh_set_window_modal(wnd);
3409            }
3410    
3411            /* FIXME: Support for Input Context:s */
3412    
3413            get_input_mask(&input_mask);
3414            input_mask |= PropertyChangeMask;
3415    
3416            XSelectInput(g_display, wnd, input_mask);
3417    
3418            /* handle the WM_DELETE_WINDOW protocol. FIXME: When killing a
3419               seamless window, we could try to close the window on the
3420               serverside, instead of terminating rdesktop */
3421            XSetWMProtocols(g_display, wnd, &g_kill_atom, 1);
3422    
3423            sw = xmalloc(sizeof(seamless_window));
3424            sw->wnd = wnd;
3425            sw->id = id;
3426            sw->behind = 0;
3427            sw->group = sw_find_group(group, False);
3428            sw->group->refcnt++;
3429            sw->xoffset = 0;
3430            sw->yoffset = 0;
3431            sw->width = 0;
3432            sw->height = 0;
3433            sw->state = SEAMLESSRDP_NOTYETMAPPED;
3434            sw->desktop = 0;
3435            sw->position_timer = xmalloc(sizeof(struct timeval));
3436            timerclear(sw->position_timer);
3437    
3438            sw->outstanding_position = False;
3439            sw->outpos_serial = 0;
3440            sw->outpos_xoffset = sw->outpos_yoffset = 0;
3441            sw->outpos_width = sw->outpos_height = 0;
3442    
3443            sw->next = g_seamless_windows;
3444            g_seamless_windows = sw;
3445    
3446            /* WM_HINTS */
3447            wmhints = XAllocWMHints();
3448            if (wmhints)
3449            {
3450                    wmhints->flags = WindowGroupHint;
3451                    wmhints->window_group = sw->group->wnd;
3452                    XSetWMHints(g_display, sw->wnd, wmhints);
3453                    XFree(wmhints);
3454            }
3455    }
3456    
3457    
3458    void
3459    ui_seamless_destroy_window(unsigned long id, unsigned long flags)
3460    {
3461            seamless_window *sw;
3462    
3463            if (!g_seamless_active)
3464                    return;
3465    
3466            sw = sw_get_window_by_id(id);
3467            if (!sw)
3468            {
3469                    warning("ui_seamless_destroy_window: No information for window 0x%lx\n", id);
3470                    return;
3471            }
3472    
3473            XDestroyWindow(g_display, sw->wnd);
3474            sw_remove_window(sw);
3475    }
3476    
3477    
3478    void
3479    ui_seamless_destroy_group(unsigned long id, unsigned long flags)
3480    {
3481            seamless_window *sw, *sw_next;
3482    
3483            if (!g_seamless_active)
3484                    return;
3485    
3486            for (sw = g_seamless_windows; sw; sw = sw_next)
3487            {
3488                    sw_next = sw->next;
3489    
3490                    if (sw->group->id == id)
3491                    {
3492                            XDestroyWindow(g_display, sw->wnd);
3493                            sw_remove_window(sw);
3494                    }
3495            }
3496    }
3497    
3498    
3499    void
3500    ui_seamless_move_window(unsigned long id, int x, int y, int width, int height, unsigned long flags)
3501    {
3502            seamless_window *sw;
3503    
3504            if (!g_seamless_active)
3505                    return;
3506    
3507            sw = sw_get_window_by_id(id);
3508            if (!sw)
3509            {
3510                    warning("ui_seamless_move_window: No information for window 0x%lx\n", id);
3511                    return;
3512            }
3513    
3514            /* We ignore server updates until it has handled our request. */
3515            if (sw->outstanding_position)
3516                    return;
3517    
3518            if (!width || !height)
3519                    /* X11 windows must be at least 1x1 */
3520                    return;
3521    
3522            sw->xoffset = x;
3523            sw->yoffset = y;
3524            sw->width = width;
3525            sw->height = height;
3526    
3527            /* If we move the window in a maximized state, then KDE won't
3528               accept restoration */
3529            switch (sw->state)
3530            {
3531                    case SEAMLESSRDP_MINIMIZED:
3532                    case SEAMLESSRDP_MAXIMIZED:
3533                            return;
3534            }
3535    
3536            /* FIXME: Perhaps use ewmh_net_moveresize_window instead */
3537            XMoveResizeWindow(g_display, sw->wnd, sw->xoffset, sw->yoffset, sw->width, sw->height);
3538    }
3539    
3540    
3541    void
3542    ui_seamless_restack_window(unsigned long id, unsigned long behind, unsigned long flags)
3543    {
3544            seamless_window *sw;
3545    
3546            if (!g_seamless_active)
3547                    return;
3548    
3549            sw = sw_get_window_by_id(id);
3550            if (!sw)
3551            {
3552                    warning("ui_seamless_restack_window: No information for window 0x%lx\n", id);
3553                    return;
3554            }
3555    
3556            if (behind)
3557            {
3558                    seamless_window *sw_behind;
3559                    Window wnds[2];
3560    
3561                    sw_behind = sw_get_window_by_id(behind);
3562                    if (!sw_behind)
3563                    {
3564                            warning("ui_seamless_restack_window: No information for window 0x%lx\n",
3565                                    behind);
3566                            return;
3567                    }
3568    
3569                    wnds[1] = sw_behind->wnd;
3570                    wnds[0] = sw->wnd;
3571    
3572                    XRestackWindows(g_display, wnds, 2);
3573            }
3574            else
3575            {
3576                    XRaiseWindow(g_display, sw->wnd);
3577            }
3578    
3579            sw_restack_window(sw, behind);
3580    }
3581    
3582    
3583    void
3584    ui_seamless_settitle(unsigned long id, const char *title, unsigned long flags)
3585    {
3586            seamless_window *sw;
3587    
3588            if (!g_seamless_active)
3589                    return;
3590    
3591            sw = sw_get_window_by_id(id);
3592            if (!sw)
3593            {
3594                    warning("ui_seamless_settitle: No information for window 0x%lx\n", id);
3595                    return;
3596            }
3597    
3598            /* FIXME: Might want to convert the name for non-EWMH WMs */
3599            XStoreName(g_display, sw->wnd, title);
3600            ewmh_set_wm_name(sw->wnd, title);
3601    }
3602    
3603    
3604    void
3605    ui_seamless_setstate(unsigned long id, unsigned int state, unsigned long flags)
3606    {
3607            seamless_window *sw;
3608    
3609            if (!g_seamless_active)
3610                    return;
3611    
3612            sw = sw_get_window_by_id(id);
3613            if (!sw)
3614            {
3615                    warning("ui_seamless_setstate: No information for window 0x%lx\n", id);
3616                    return;
3617            }
3618    
3619            switch (state)
3620            {
3621                    case SEAMLESSRDP_NORMAL:
3622                    case SEAMLESSRDP_MAXIMIZED:
3623                            ewmh_change_state(sw->wnd, state);
3624                            XMapWindow(g_display, sw->wnd);
3625                            break;
3626                    case SEAMLESSRDP_MINIMIZED:
3627                            /* EWMH says: "if an Application asks to toggle _NET_WM_STATE_HIDDEN
3628                               the Window Manager should probably just ignore the request, since
3629                               _NET_WM_STATE_HIDDEN is a function of some other aspect of the window
3630                               such as minimization, rather than an independent state." Besides,
3631                               XIconifyWindow is easier. */
3632                            if (sw->state == SEAMLESSRDP_NOTYETMAPPED)
3633                            {
3634                                    XWMHints *hints;
3635                                    hints = XGetWMHints(g_display, sw->wnd);
3636                                    if (hints)
3637                                    {
3638                                            hints->flags |= StateHint;
3639                                            hints->initial_state = IconicState;
3640                                            XSetWMHints(g_display, sw->wnd, hints);
3641                                            XFree(hints);
3642                                    }
3643                                    XMapWindow(g_display, sw->wnd);
3644                            }
3645                            else
3646                                    XIconifyWindow(g_display, sw->wnd, DefaultScreen(g_display));
3647                            break;
3648                    default:
3649                            warning("SeamlessRDP: Invalid state %d\n", state);
3650                            break;
3651            }
3652    
3653            sw->state = state;
3654    }
3655    
3656    
3657    void
3658    ui_seamless_syncbegin(unsigned long flags)
3659    {
3660            if (!g_seamless_active)
3661                    return;
3662    
3663            /* Destroy all seamless windows */
3664            while (g_seamless_windows)
3665            {
3666                    XDestroyWindow(g_display, g_seamless_windows->wnd);
3667                    sw_remove_window(g_seamless_windows);
3668            }
3669    }
3670    
3671    
3672    void
3673    ui_seamless_ack(unsigned int serial)
3674    {
3675            seamless_window *sw;
3676            for (sw = g_seamless_windows; sw; sw = sw->next)
3677            {
3678                    if (sw->outstanding_position && (sw->outpos_serial == serial))
3679                    {
3680                            sw->xoffset = sw->outpos_xoffset;
3681                            sw->yoffset = sw->outpos_yoffset;
3682                            sw->width = sw->outpos_width;
3683                            sw->height = sw->outpos_height;
3684                            sw->outstanding_position = False;
3685    
3686                            /* Do a complete redraw of the window as part of the
3687                               completion of the move. This is to remove any
3688                               artifacts caused by our lack of synchronization. */
3689                            XCopyArea(g_display, g_backstore,
3690                                      sw->wnd, g_gc,
3691                                      sw->xoffset, sw->yoffset, sw->width, sw->height, 0, 0);
3692    
3693                            break;
3694                    }
3695            }
3696    }

Legend:
Removed from v.867  
changed lines
  Added in v.1302

  ViewVC Help
Powered by ViewVC 1.1.26