/[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 432 by matthewc, Tue Jul 1 09:31:25 2003 UTC revision 508 by astrand, Wed Oct 22 10:55:11 2003 UTC
# Line 25  Line 25 
25  #include "rdesktop.h"  #include "rdesktop.h"
26  #include "xproto.h"  #include "xproto.h"
27    
28  extern int width;  extern int g_width;
29  extern int height;  extern int g_height;
30  extern BOOL sendmotion;  extern BOOL g_sendmotion;
31  extern BOOL fullscreen;  extern BOOL g_fullscreen;
32  extern BOOL grab_keyboard;  extern BOOL g_grab_keyboard;
33  extern BOOL hide_decorations;  extern BOOL g_hide_decorations;
34  extern char title[];  extern char g_title[];
35  extern int server_bpp;  extern int g_server_bpp;
36  extern int win_button_size;  extern int g_win_button_size;
37  BOOL enable_compose = False;  
38  BOOL focused;  Display *g_display;
39  BOOL mouse_in_wnd;  Time g_last_gesturetime;
40    static int g_x_socket;
41  Display *display;  static Screen *g_screen;
42  Time last_gesturetime;  Window g_wnd;
43  static int x_socket;  BOOL g_enable_compose = False;
44  static Screen *screen;  static GC g_gc;
45  Window wnd;  static Visual *g_visual;
46  static GC gc;  static int g_depth;
47  static Visual *visual;  static int g_bpp;
48  static int depth;  static XIM g_IM;
49  static int bpp;  static XIC g_IC;
50  static XIM IM;  static XModifierKeymap *g_mod_map;
51  static XIC IC;  static Cursor g_current_cursor;
52  static XModifierKeymap *mod_map;  static HCURSOR g_null_cursor;
53  static Cursor current_cursor;  static Atom g_protocol_atom, g_kill_atom;
54  static Atom protocol_atom, kill_atom;  static BOOL g_focused;
55    static BOOL g_mouse_in_wnd;
56    
57  /* endianness */  /* endianness */
58  static BOOL host_be;  static BOOL g_host_be;
59  static BOOL xserver_be;  static BOOL g_xserver_be;
60    
61  /* software backing store */  /* software backing store */
62  static BOOL ownbackstore;  static BOOL g_ownbackstore;
63  static Pixmap backstore;  static Pixmap g_backstore;
64    
65  /* Moving in single app mode */  /* Moving in single app mode */
66  static BOOL moving_wnd;  static BOOL g_moving_wnd;
67  static int move_x_offset = 0;  static int g_move_x_offset = 0;
68  static int move_y_offset = 0;  static int g_move_y_offset = 0;
69    
70    #ifdef WITH_RDPSND
71    extern int g_dsp_fd;
72    extern BOOL g_dsp_busy;
73    extern BOOL g_rdpsnd;
74    #endif
75    
76  /* MWM decorations */  /* MWM decorations */
77  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
# Line 90  PixelColour; Line 97  PixelColour;
97    
98  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
99  { \  { \
100          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \
101          if (ownbackstore) \          if (g_ownbackstore) \
102                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \                  XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \
103  }  }
104    
105  #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\  #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\
106  { \  { \
107          XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \          XFillRectangle(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, cx, cy); \
108  }  }
109    
110  /* colour maps */  /* colour maps */
111  BOOL owncolmap = False;  BOOL g_owncolmap = False;
112  static Colormap xcolmap;  static Colormap g_xcolmap;
113  static uint32 *colmap;  static uint32 *g_colmap = NULL;
114    
115  #define TRANSLATE(col)          ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) )
116  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
117  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
118    
119  static int rop2_map[] = {  static int rop2_map[] = {
120          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 128  static int rop2_map[] = { Line 135  static int rop2_map[] = {
135          GXset                   /* 1 */          GXset                   /* 1 */
136  };  };
137    
138  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, rop2_map[rop2]); }
139  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(g_display, g_gc, GXcopy); }
140    
141  static void  static void
142  mwm_hide_decorations(void)  mwm_hide_decorations(void)
# Line 142  mwm_hide_decorations(void) Line 149  mwm_hide_decorations(void)
149          motif_hints.decorations = 0;          motif_hints.decorations = 0;
150    
151          /* get the atom for the property */          /* get the atom for the property */
152          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);          hintsatom = XInternAtom(g_display, "_MOTIF_WM_HINTS", False);
153          if (!hintsatom)          if (!hintsatom)
154          {          {
155                  warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n");                  warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n");
156                  return;                  return;
157          }          }
158    
159          XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace,          XChangeProperty(g_display, g_wnd, hintsatom, hintsatom, 32, PropModeReplace,
160                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
161  }  }
162    
# Line 201  make_colour16(PixelColour pc) Line 208  make_colour16(PixelColour pc)
208  static uint32  static uint32
209  make_colour24(PixelColour pc)  make_colour24(PixelColour pc)
210  {  {
211          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
212            {
213                    return pc.red | (pc.green << 8) | (pc.blue << 16);
214            }
215            else
216            {
217                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
218            }
219  }  }
220    
221  static uint32  static uint32
222  make_colour32(PixelColour pc)  make_colour32(PixelColour pc)
223  {  {
224          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
225            {
226                    return pc.red | (pc.green << 8) | (pc.blue << 16);
227            }
228            else
229            {
230                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
231            }
232  }  }
233    
234  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 218  make_colour32(PixelColour pc) Line 239  make_colour32(PixelColour pc)
239  static uint32  static uint32
240  translate_colour(uint32 colour)  translate_colour(uint32 colour)
241  {  {
242          switch (server_bpp)          switch (g_server_bpp)
243          {          {
244                  case 15:                  case 15:
245                          switch (bpp)                          switch (g_bpp)
246                          {                          {
247                                  case 16:                                  case 16:
248                                          colour = make_colour16(split_colour15(colour));                                          colour = make_colour16(split_colour15(colour));
# Line 235  translate_colour(uint32 colour) Line 256  translate_colour(uint32 colour)
256                          }                          }
257                          break;                          break;
258                  case 16:                  case 16:
259                          switch (bpp)                          switch (g_bpp)
260                          {                          {
261                                  case 16:                                  case 16:
262                                          break;                                          break;
# Line 248  translate_colour(uint32 colour) Line 269  translate_colour(uint32 colour)
269                          }                          }
270                          break;                          break;
271                  case 24:                  case 24:
272                          switch (bpp)                          switch (g_bpp)
273                          {                          {
274                                  case 16:                                  case 16:
275                                          colour = make_colour16(split_colour24(colour));                                          colour = make_colour16(split_colour24(colour));
# Line 261  translate_colour(uint32 colour) Line 282  translate_colour(uint32 colour)
282                          }                          }
283                          break;                          break;
284          }          }
         switch (bpp)  
         {  
                 case 16:  
                         if (host_be != xserver_be)  
                                 BSWAP16(colour);  
                         break;  
   
                 case 24:  
                         if (xserver_be)  
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (host_be != xserver_be)  
                                 BSWAP32(colour);  
                         break;  
         }  
   
285          return colour;          return colour;
286  }  }
287    
# Line 286  static void Line 289  static void
289  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
290  {  {
291          while (out < end)          while (out < end)
292                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) g_colmap[*(data++)];
293  }  }
294    
295  static void  static void
296  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
297  {  {
298          while (out < end)          while (out < end)
299                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) g_colmap[*(data++)];
300  }  }
301    
302  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 304  translate8to24(uint8 * data, uint8 * out Line 307  translate8to24(uint8 * data, uint8 * out
307    
308          while (out < end)          while (out < end)
309          {          {
310                  value = colmap[*(data++)];                  value = g_colmap[*(data++)];
311                  *(out++) = value;                  *(out++) = value;
312                  *(out++) = value >> 8;                  *(out++) = value >> 8;
313                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 315  static void Line 318  static void
318  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
319  {  {
320          while (out < end)          while (out < end)
321                  *(out++) = colmap[*(data++)];                  *(out++) = g_colmap[*(data++)];
322  }  }
323    
324  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
325    
326  static void  static void
327  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
328  {  {
329            uint16 pixel;
330            uint16 value;
331    
332          while (out < end)          while (out < end)
333                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
334                    pixel = *(data++);
335    
336                    if (g_host_be)
337                    {
338                    BSWAP16(pixel)}
339    
340                    value = make_colour16(split_colour15(pixel));
341    
342                    if (g_xserver_be)
343                    {
344                            *(out++) = value >> 8;
345                            *(out++) = value;
346                    }
347                    else
348                    {
349                            *(out++) = value;
350                            *(out++) = value >> 8;
351                    }
352            }
353  }  }
354    
355  static void  static void
356  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
357  {  {
358          uint32 value;          uint32 value;
359            uint16 pixel;
360    
361          while (out < end)          while (out < end)
362          {          {
363                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
364                  *(out++) = value;  
365                  *(out++) = value >> 8;                  if (g_host_be)
366                  *(out++) = value >> 16;                  {
367                    BSWAP16(pixel)}
368    
369                    value = make_colour24(split_colour15(pixel));
370                    if (g_xserver_be)
371                    {
372                            *(out++) = value >> 16;
373                            *(out++) = value >> 8;
374                            *(out++) = value;
375                    }
376                    else
377                    {
378                            *(out++) = value;
379                            *(out++) = value >> 8;
380                            *(out++) = value >> 16;
381                    }
382          }          }
383  }  }
384    
385  static void  static void
386  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
387  {  {
388            uint16 pixel;
389            uint32 value;
390    
391          while (out < end)          while (out < end)
392                  *(out++) = make_colour32(split_colour15(*(data++)));          {
393                    pixel = *(data++);
394    
395                    if (g_host_be)
396                    {
397                            BSWAP16(pixel);
398                    }
399    
400                    value = make_colour32(split_colour15(pixel));
401    
402                    if (g_xserver_be)
403                    {
404                            *(out++) = value >> 24;
405                            *(out++) = value >> 16;
406                            *(out++) = value >> 8;
407                            *(out++) = value;
408                    }
409                    else
410                    {
411                            *(out++) = value;
412                            *(out++) = value >> 8;
413                            *(out++) = value >> 16;
414                            *(out++) = value >> 24;
415                    }
416            }
417  }  }
418    
419  static void  static void
420  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint16 * out, uint16 * end)
421  {  {
422          while (out < end)          uint16 value;
423                  *(out++) = (uint16) (*(data++));  
424            if (g_xserver_be)
425            {
426                    while (out < end)
427                    {
428                            value = *data;
429                            BSWAP16(value);
430                            *out = value;
431                            data++;
432                            out++;
433                    }
434    
435            }
436            else
437            {
438                    while (out < end)
439                    {
440                            *out = *data;
441                            out++;
442                            data++;
443                    }
444            }
445  }  }
446    
447    
# Line 360  static void Line 449  static void
449  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
450  {  {
451          uint32 value;          uint32 value;
452            uint16 pixel;
453    
454          while (out < end)          while (out < end)
455          {          {
456                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
457                  *(out++) = value;  
458                  *(out++) = value >> 8;                  if (g_host_be)
459                  *(out++) = value >> 16;                  {
460                    BSWAP16(pixel)}
461    
462                    value = make_colour24(split_colour16(pixel));
463    
464                    if (g_xserver_be)
465                    {
466                            *(out++) = value >> 16;
467                            *(out++) = value >> 8;
468                            *(out++) = value;
469                    }
470                    else
471                    {
472                            *(out++) = value;
473                            *(out++) = value >> 8;
474                            *(out++) = value >> 16;
475                    }
476          }          }
477  }  }
478    
479  static void  static void
480  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
481  {  {
482            uint16 pixel;
483            uint32 value;
484    
485          while (out < end)          while (out < end)
486                  *(out++) = make_colour32(split_colour16(*(data++)));          {
487                    pixel = *(data++);
488    
489                    if (g_host_be)
490                    {
491                    BSWAP16(pixel)}
492    
493                    value = make_colour32(split_colour16(pixel));
494    
495                    if (g_xserver_be)
496                    {
497                            *(out++) = value >> 24;
498                            *(out++) = value >> 16;
499                            *(out++) = value >> 8;
500                            *(out++) = value;
501                    }
502                    else
503                    {
504                            *(out++) = value;
505                            *(out++) = value >> 8;
506                            *(out++) = value >> 16;
507                            *(out++) = value >> 24;
508                    }
509            }
510  }  }
511    
512  static void  static void
513  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
514  {  {
515          uint32 pixel = 0;          uint32 pixel = 0;
516            uint16 value;
517          while (out < end)          while (out < end)
518          {          {
519                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
520                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
521                  pixel |= *(data++);                  pixel |= *(data++);
522                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
523                    value = (uint16) make_colour16(split_colour24(pixel));
524    
525                    if (g_xserver_be)
526                    {
527                            *(out++) = value >> 8;
528                            *(out++) = value;
529                    }
530                    else
531                    {
532                            *(out++) = value;
533                            *(out++) = value >> 8;
534                    }
535          }          }
536  }  }
537    
# Line 400  translate24to24(uint8 * data, uint8 * ou Line 545  translate24to24(uint8 * data, uint8 * ou
545  }  }
546    
547  static void  static void
548  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
549  {  {
         uint32 pixel = 0;  
550          while (out < end)          while (out < end)
551          {          {
552                  pixel = *(data++);                  if (g_xserver_be)
553                  pixel |= *(data++) << 8;                  {
554                  pixel |= *(data++) << 16;                          *(out++) = 0x00;
555                  *(out++) = pixel;                          *(out++) = *(data++);
556                            *(out++) = *(data++);
557                            *(out++) = *(data++);
558                    }
559                    else
560                    {
561                            *(out++) = *(data++);
562                            *(out++) = *(data++);
563                            *(out++) = *(data++);
564                            *(out++) = 0x00;
565                    }
566          }          }
567  }  }
568    
569  static uint8 *  static uint8 *
570  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
571  {  {
572          int size = width * height * bpp / 8;          int size = width * height * g_bpp / 8;
573          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out = (uint8 *) xmalloc(size);
574          uint8 *end = out + size;          uint8 *end = out + size;
575    
576          switch (server_bpp)          switch (g_server_bpp)
577          {          {
578                  case 24:                  case 24:
579                          switch (bpp)                          switch (g_bpp)
580                          {                          {
581                                  case 32:                                  case 32:
582                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
583                                          break;                                          break;
584                                  case 24:                                  case 24:
585                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
586                                          break;                                          break;
587                                  case 16:                                  case 16:
588                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
589                                          break;                                          break;
590                          }                          }
591                          break;                          break;
592                  case 16:                  case 16:
593                          switch (bpp)                          switch (g_bpp)
594                          {                          {
595                                  case 32:                                  case 32:
596                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
597                                          break;                                          break;
598                                  case 24:                                  case 24:
599                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
# Line 452  translate_image(int width, int height, u Line 605  translate_image(int width, int height, u
605                          }                          }
606                          break;                          break;
607                  case 15:                  case 15:
608                          switch (bpp)                          switch (g_bpp)
609                          {                          {
610                                  case 32:                                  case 32:
611                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
612                                          break;                                          break;
613                                  case 24:                                  case 24:
614                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
615                                          break;                                          break;
616                                  case 16:                                  case 16:
617                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
618                                          break;                                          break;
619                          }                          }
620                          break;                          break;
621                  case 8:                  case 8:
622                          switch (bpp)                          switch (g_bpp)
623                          {                          {
624                                  case 8:                                  case 8:
625                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
# Line 494  get_key_state(unsigned int state, uint32 Line 645  get_key_state(unsigned int state, uint32
645          int modifierpos, key, keysymMask = 0;          int modifierpos, key, keysymMask = 0;
646          int offset;          int offset;
647    
648          KeyCode keycode = XKeysymToKeycode(display, keysym);          KeyCode keycode = XKeysymToKeycode(g_display, keysym);
649    
650          if (keycode == NoSymbol)          if (keycode == NoSymbol)
651                  return False;                  return False;
652    
653          for (modifierpos = 0; modifierpos < 8; modifierpos++)          for (modifierpos = 0; modifierpos < 8; modifierpos++)
654          {          {
655                  offset = mod_map->max_keypermod * modifierpos;                  offset = g_mod_map->max_keypermod * modifierpos;
656    
657                  for (key = 0; key < mod_map->max_keypermod; key++)                  for (key = 0; key < g_mod_map->max_keypermod; key++)
658                  {                  {
659                          if (mod_map->modifiermap[offset + key] == keycode)                          if (g_mod_map->modifiermap[offset + key] == keycode)
660                                  keysymMask |= 1 << modifierpos;                                  keysymMask |= 1 << modifierpos;
661                  }                  }
662          }          }
# Line 520  ui_init(void) Line 671  ui_init(void)
671          uint16 test;          uint16 test;
672          int i;          int i;
673    
674          display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
675          if (display == NULL)          if (g_display == NULL)
676          {          {
677                  error("Failed to open display: %s\n", XDisplayName(NULL));                  error("Failed to open display: %s\n", XDisplayName(NULL));
678                  return False;                  return False;
679          }          }
680    
681          x_socket = ConnectionNumber(display);          g_x_socket = ConnectionNumber(g_display);
682          screen = DefaultScreenOfDisplay(display);          g_screen = DefaultScreenOfDisplay(g_display);
683          visual = DefaultVisualOfScreen(screen);          g_visual = DefaultVisualOfScreen(g_screen);
684          depth = DefaultDepthOfScreen(screen);          g_depth = DefaultDepthOfScreen(g_screen);
685    
686          pfm = XListPixmapFormats(display, &i);          pfm = XListPixmapFormats(g_display, &i);
687          if (pfm != NULL)          if (pfm != NULL)
688          {          {
689                  /* Use maximum bpp for this depth - this is generally                  /* Use maximum bpp for this depth - this is generally
690                     desirable, e.g. 24 bits->32 bits. */                     desirable, e.g. 24 bits->32 bits. */
691                  while (i--)                  while (i--)
692                  {                  {
693                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))                          if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp))
694                          {                          {
695                                  bpp = pfm[i].bits_per_pixel;                                  g_bpp = pfm[i].bits_per_pixel;
696                          }                          }
697                  }                  }
698                  XFree(pfm);                  XFree(pfm);
699          }          }
700    
701          if (bpp < 8)          if (g_bpp < 8)
702          {          {
703                  error("Less than 8 bpp not currently supported.\n");                  error("Less than 8 bpp not currently supported.\n");
704                  XCloseDisplay(display);                  XCloseDisplay(g_display);
705                  return False;                  return False;
706          }          }
707    
708          if (owncolmap != True)          if (g_owncolmap != True)
709          {          {
710                  xcolmap = DefaultColormapOfScreen(screen);                  g_xcolmap = DefaultColormapOfScreen(g_screen);
711                  if (depth <= 8)                  if (g_depth <= 8)
712                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");                          warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
713          }          }
714    
715          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);
716    
717          if (DoesBackingStore(screen) != Always)          if (DoesBackingStore(g_screen) != Always)
718                  ownbackstore = True;                  g_ownbackstore = True;
719    
720          test = 1;          test = 1;
721          host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
722          xserver_be = (ImageByteOrder(display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
723    
724          if ((width == 0) || (height == 0))          /*
725             * Determine desktop size
726             */
727            if (g_width < 0)
728            {
729                    /* Percent of screen */
730                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
731                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
732            }
733            else if (g_width == 0)
734          {          {
735                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
736                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
737    
738                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
739                  {                  {
740                          width = cx;                          g_width = cx;
741                          height = cy;                          g_height = cy;
742                  }                  }
743                  else                  else
744                  {                  {
745                          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");
746                          width = 800;                          g_width = 800;
747                          height = 600;                          g_height = 600;
748                  }                  }
749          }          }
750            else if (g_fullscreen)
         if (fullscreen)  
751          {          {
752                  width = WidthOfScreen(screen);                  g_width = WidthOfScreen(g_screen);
753                  height = HeightOfScreen(screen);                  g_height = HeightOfScreen(g_screen);
754          }          }
755    
756          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
757          width = (width + 3) & ~3;          g_width = (g_width + 3) & ~3;
758    
759          if (ownbackstore)          if (g_ownbackstore)
760          {          {
761                  backstore =                  g_backstore =
762                          XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);                          XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,
763                                          g_depth);
764    
765                  /* clear to prevent rubbish being exposed at startup */                  /* clear to prevent rubbish being exposed at startup */
766                  XSetForeground(display, gc, BlackPixelOfScreen(screen));                  XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
767                  XFillRectangle(display, backstore, gc, 0, 0, width, height);                  XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
768          }          }
769    
770          mod_map = XGetModifierMapping(display);          g_mod_map = XGetModifierMapping(g_display);
   
         if (enable_compose)  
                 IM = XOpenIM(display, NULL, NULL, NULL);  
771    
772          xkeymap_init();          xkeymap_init();
773    
774            if (g_enable_compose)
775                    g_IM = XOpenIM(g_display, NULL, NULL, NULL);
776    
777          xclip_init();          xclip_init();
778    
779          /* todo take this out when high colour is done */          /* todo take this out when high colour is done */
780          printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);          printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth);
781    
782          return True;          return True;
783  }  }
# Line 624  ui_init(void) Line 785  ui_init(void)
785  void  void
786  ui_deinit(void)  ui_deinit(void)
787  {  {
788          if (IM != NULL)          if (g_IM != NULL)
789                  XCloseIM(IM);                  XCloseIM(g_IM);
790    
791          XFreeModifiermap(mod_map);          XFreeModifiermap(g_mod_map);
792    
793          if (ownbackstore)          if (g_ownbackstore)
794                  XFreePixmap(display, backstore);                  XFreePixmap(g_display, g_backstore);
795    
796          XFreeGC(display, gc);          XFreeGC(g_display, g_gc);
797          XCloseDisplay(display);          XCloseDisplay(g_display);
798          display = NULL;          g_display = NULL;
799  }  }
800    
801    #define NULL_POINTER_MASK       "\x80"
802    #define NULL_POINTER_DATA       "\x0\x0\x0"
803            
804  BOOL  BOOL
805  ui_create_window(void)  ui_create_window(void)
806  {  {
# Line 647  ui_create_window(void) Line 811  ui_create_window(void)
811          long input_mask, ic_input_mask;          long input_mask, ic_input_mask;
812          XEvent xevent;          XEvent xevent;
813    
814          wndwidth = fullscreen ? WidthOfScreen(screen) : width;          wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width;
815          wndheight = fullscreen ? HeightOfScreen(screen) : height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
816    
817          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
818          attribs.backing_store = ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
819          attribs.override_redirect = fullscreen;          attribs.override_redirect = g_fullscreen;
820    
821          wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
822                              0, CopyFromParent, InputOutput, CopyFromParent,                                0, CopyFromParent, InputOutput, CopyFromParent,
823                              CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
824    
825          XStoreName(display, wnd, title);          XStoreName(g_display, g_wnd, g_title);
826    
827          if (hide_decorations)          if (g_hide_decorations)
828                  mwm_hide_decorations();                  mwm_hide_decorations();
829    
830          classhints = XAllocClassHint();          classhints = XAllocClassHint();
831          if (classhints != NULL)          if (classhints != NULL)
832          {          {
833                  classhints->res_name = classhints->res_class = "rdesktop";                  classhints->res_name = classhints->res_class = "rdesktop";
834                  XSetClassHint(display, wnd, classhints);                  XSetClassHint(g_display, g_wnd, classhints);
835                  XFree(classhints);                  XFree(classhints);
836          }          }
837    
# Line 675  ui_create_window(void) Line 839  ui_create_window(void)
839          if (sizehints)          if (sizehints)
840          {          {
841                  sizehints->flags = PMinSize | PMaxSize;                  sizehints->flags = PMinSize | PMaxSize;
842                  sizehints->min_width = sizehints->max_width = width;                  sizehints->min_width = sizehints->max_width = g_width;
843                  sizehints->min_height = sizehints->max_height = height;                  sizehints->min_height = sizehints->max_height = g_height;
844                  XSetWMNormalHints(display, wnd, sizehints);                  XSetWMNormalHints(g_display, g_wnd, sizehints);
845                  XFree(sizehints);                  XFree(sizehints);
846          }          }
847    
848          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
849                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
850    
851          if (sendmotion)          if (g_sendmotion)
852                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
853          if (ownbackstore)          if (g_ownbackstore)
854                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
855          if (fullscreen || grab_keyboard)          if (g_fullscreen || g_grab_keyboard)
856                  input_mask |= EnterWindowMask;                  input_mask |= EnterWindowMask;
857          if (grab_keyboard)          if (g_grab_keyboard)
858                  input_mask |= LeaveWindowMask;                  input_mask |= LeaveWindowMask;
859    
860          if (IM != NULL)          if (g_IM != NULL)
861          {          {
862                  IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),                  g_IC = XCreateIC(g_IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
863                                 XNClientWindow, wnd, XNFocusWindow, wnd, NULL);                                   XNClientWindow, g_wnd, XNFocusWindow, g_wnd, NULL);
864    
865                  if ((IC != NULL)                  if ((g_IC != NULL)
866                      && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))                      && (XGetICValues(g_IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))
867                          input_mask |= ic_input_mask;                          input_mask |= ic_input_mask;
868          }          }
869    
870          XSelectInput(display, wnd, input_mask);          XSelectInput(g_display, g_wnd, input_mask);
871          XMapWindow(display, wnd);          XMapWindow(g_display, g_wnd);
872    
873          /* wait for VisibilityNotify */          /* wait for VisibilityNotify */
874          do          do
875          {          {
876                  XMaskEvent(display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
877          }          }
878          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
879    
880          focused = False;          g_focused = False;
881          mouse_in_wnd = False;          g_mouse_in_wnd = False;
882    
883          /* handle the WM_DELETE_WINDOW protocol */          /* handle the WM_DELETE_WINDOW protocol */
884          protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);          g_protocol_atom = XInternAtom(g_display, "WM_PROTOCOLS", True);
885          kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
886          XSetWMProtocols(display, wnd, &kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
887    
888            /* create invisible 1x1 cursor to be used as null cursor */
889            g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);
890    
891          return True;          return True;
892  }  }
# Line 727  ui_create_window(void) Line 894  ui_create_window(void)
894  void  void
895  ui_destroy_window(void)  ui_destroy_window(void)
896  {  {
897          if (IC != NULL)          ui_destroy_cursor(g_null_cursor);
898                  XDestroyIC(IC);          
899            if (g_IC != NULL)
900                    XDestroyIC(g_IC);
901    
902          XDestroyWindow(display, wnd);          XDestroyWindow(g_display, g_wnd);
903  }  }
904    
905  void  void
# Line 738  xwin_toggle_fullscreen(void) Line 907  xwin_toggle_fullscreen(void)
907  {  {
908          Pixmap contents = 0;          Pixmap contents = 0;
909    
910          if (!ownbackstore)          if (!g_ownbackstore)
911          {          {
912                  /* need to save contents of window */                  /* need to save contents of window */
913                  contents = XCreatePixmap(display, wnd, width, height, depth);                  contents = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
914                  XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0);                  XCopyArea(g_display, g_wnd, contents, g_gc, 0, 0, g_width, g_height, 0, 0);
915          }          }
916    
917          ui_destroy_window();          ui_destroy_window();
918          fullscreen = !fullscreen;          g_fullscreen = !g_fullscreen;
919          ui_create_window();          ui_create_window();
920    
921          XDefineCursor(display, wnd, current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
922    
923          if (!ownbackstore)          if (!g_ownbackstore)
924          {          {
925                  XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0);                  XCopyArea(g_display, contents, g_wnd, g_gc, 0, 0, g_width, g_height, 0, 0);
926                  XFreePixmap(display, contents);                  XFreePixmap(g_display, contents);
927          }          }
928  }  }
929    
930  /* Process all events in Xlib queue  /* Process all events in Xlib queue
931     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
932  static int  static int
933  xwin_process_events(void)  xwin_process_events(void)
# Line 774  xwin_process_events(void) Line 943  xwin_process_events(void)
943          Window wdummy;          Window wdummy;
944          int dummy;          int dummy;
945    
946          while (XPending(display) > 0)          while (XPending(g_display) > 0)
947          {          {
948                  XNextEvent(display, &xevent);                  XNextEvent(g_display, &xevent);
949    
950                  if ((IC != NULL) && (XFilterEvent(&xevent, None) == True))                  if ((g_IC != NULL) && (XFilterEvent(&xevent, None) == True))
951                  {                  {
952                          DEBUG_KBD(("Filtering event\n"));                          DEBUG_KBD(("Filtering event\n"));
953                          continue;                          continue;
# Line 790  xwin_process_events(void) Line 959  xwin_process_events(void)
959                  {                  {
960                          case ClientMessage:                          case ClientMessage:
961                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
962                                  if ((xevent.xclient.message_type == protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
963                                      && ((Atom) xevent.xclient.data.l[0] == kill_atom))                                      && ((Atom) xevent.xclient.data.l[0] == g_kill_atom))
964                                          /* Quit */                                          /* Quit */
965                                          return 0;                                          return 0;
966                                  break;                                  break;
967    
968                          case KeyPress:                          case KeyPress:
969                                  last_gesturetime = xevent.xkey.time;                                  g_last_gesturetime = xevent.xkey.time;
970                                  if (IC != NULL)                                  if (g_IC != NULL)
971                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
972                                  {                                  {
973                                          XmbLookupString(IC,                                          XmbLookupString(g_IC,
974                                                          &xevent.xkey, str, sizeof(str), &keysym, &status);                                                          &xevent.xkey, str, sizeof(str), &keysym,
975                                                            &status);
976                                          if (!((status == XLookupKeySym) || (status == XLookupBoth)))                                          if (!((status == XLookupKeySym) || (status == XLookupBoth)))
977                                          {                                          {
978                                                  error("XmbLookupString failed with status 0x%x\n",                                                  error("XmbLookupString failed with status 0x%x\n",
# Line 831  xwin_process_events(void) Line 1001  xwin_process_events(void)
1001                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1002                                          break;                                          break;
1003    
1004                                    save_remote_modifiers(tr.scancode);
1005                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
   
1006                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1007                                    restore_remote_modifiers(ev_time, tr.scancode);
1008    
1009                                  break;                                  break;
1010    
1011                          case KeyRelease:                          case KeyRelease:
1012                                  last_gesturetime = xevent.xkey.time;                                  g_last_gesturetime = xevent.xkey.time;
1013                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
1014                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
1015    
# Line 862  xwin_process_events(void) Line 1034  xwin_process_events(void)
1034                                  /* fall through */                                  /* fall through */
1035    
1036                          case ButtonRelease:                          case ButtonRelease:
1037                                  last_gesturetime = xevent.xbutton.time;                                  g_last_gesturetime = xevent.xbutton.time;
1038                                  button = xkeymap_translate_button(xevent.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
1039                                  if (button == 0)                                  if (button == 0)
1040                                          break;                                          break;
1041    
1042                                  /* If win_button_size is nonzero, enable single app mode */                                  /* If win_button_size is nonzero, enable single app mode */
1043                                  if (xevent.xbutton.y < win_button_size)                                  if (xevent.xbutton.y < g_win_button_size)
1044                                  {                                  {
1045                                          /* Stop moving window when button is released, regardless of cursor position */                                          /* Stop moving window when button is released, regardless of cursor position */
1046                                          if (moving_wnd && (xevent.type == ButtonRelease))                                          if (g_moving_wnd && (xevent.type == ButtonRelease))
1047                                                  moving_wnd = False;                                                  g_moving_wnd = False;
1048    
1049                                          /*  Check from right to left: */                                          /*  Check from right to left: */
1050    
1051                                          if (xevent.xbutton.x >= width - win_button_size)                                          if (xevent.xbutton.x >= g_width - g_win_button_size)
1052                                          {                                          {
1053                                                  /* The close button, continue */                                                  /* The close button, continue */
1054                                                  ;                                                  ;
1055                                          }                                          }
1056                                          else if (xevent.xbutton.x >= width - win_button_size * 2)                                          else if (xevent.xbutton.x >=
1057                                                     g_width - g_win_button_size * 2)
1058                                          {                                          {
1059                                                  /* The maximize/restore button. Do not send to                                                  /* The maximize/restore button. Do not send to
1060                                                     server.  It might be a good idea to change the                                                     server.  It might be a good idea to change the
1061                                                     cursor or give some other visible indication                                                     cursor or give some other visible indication
1062                                                     that rdesktop inhibited this click */                                                     that rdesktop inhibited this click */
1063                                                  break;                                                  break;
1064                                          }                                          }
1065                                          else if (xevent.xbutton.x >= width - win_button_size * 3)                                          else if (xevent.xbutton.x >=
1066                                                     g_width - g_win_button_size * 3)
1067                                          {                                          {
1068                                                  /* The minimize button. Iconify window. */                                                  /* The minimize button. Iconify window. */
1069                                                  XIconifyWindow(display, wnd,                                                  XIconifyWindow(g_display, g_wnd,
1070                                                                 DefaultScreen(display));                                                                 DefaultScreen(g_display));
1071                                                  break;                                                  break;
1072                                          }                                          }
1073                                          else if (xevent.xbutton.x <= win_button_size)                                          else if (xevent.xbutton.x <= g_win_button_size)
1074                                          {                                          {
1075                                                  /* The system menu. Ignore. */                                                  /* The system menu. Ignore. */
1076                                                  break;                                                  break;
# Line 904  xwin_process_events(void) Line 1078  xwin_process_events(void)
1078                                          else                                          else
1079                                          {                                          {
1080                                                  /* The title bar. */                                                  /* The title bar. */
1081                                                  if ((xevent.type == ButtonPress) && !fullscreen                                                  if ((xevent.type == ButtonPress) && !g_fullscreen
1082                                                      && hide_decorations)                                                      && g_hide_decorations)
1083                                                  {                                                  {
1084                                                          moving_wnd = True;                                                          g_moving_wnd = True;
1085                                                          move_x_offset = xevent.xbutton.x;                                                          g_move_x_offset = xevent.xbutton.x;
1086                                                          move_y_offset = xevent.xbutton.y;                                                          g_move_y_offset = xevent.xbutton.y;
1087                                                  }                                                  }
1088                                                  break;                                                  break;
1089    
# Line 921  xwin_process_events(void) Line 1095  xwin_process_events(void)
1095                                  break;                                  break;
1096    
1097                          case MotionNotify:                          case MotionNotify:
1098                                  if (moving_wnd)                                  if (g_moving_wnd)
1099                                  {                                  {
1100                                          XMoveWindow(display, wnd,                                          XMoveWindow(g_display, g_wnd,
1101                                                      xevent.xmotion.x_root - move_x_offset,                                                      xevent.xmotion.x_root - g_move_x_offset,
1102                                                      xevent.xmotion.y_root - move_y_offset);                                                      xevent.xmotion.y_root - g_move_y_offset);
1103                                          break;                                          break;
1104                                  }                                  }
1105    
1106                                  if (fullscreen && !focused)                                  if (g_fullscreen && !g_focused)
1107                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,
1108                                                         CurrentTime);                                                         CurrentTime);
1109                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
1110                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
# Line 939  xwin_process_events(void) Line 1113  xwin_process_events(void)
1113                          case FocusIn:                          case FocusIn:
1114                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1115                                          break;                                          break;
1116                                  focused = True;                                  g_focused = True;
1117                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy,                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,
1118                                                &dummy, &dummy, &state);                                                &dummy, &dummy, &state);
1119                                  reset_modifier_keys(state);                                  reset_modifier_keys(state);
1120                                  if (grab_keyboard && mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1121                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1122                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
1123                                  break;                                  break;
1124    
1125                          case FocusOut:                          case FocusOut:
1126                                  if (xevent.xfocus.mode == NotifyUngrab)                                  if (xevent.xfocus.mode == NotifyUngrab)
1127                                          break;                                          break;
1128                                  focused = False;                                  g_focused = False;
1129                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)
1130                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(g_display, CurrentTime);
1131                                  break;                                  break;
1132    
1133                          case EnterNotify:                          case EnterNotify:
1134                                  /* we only register for this event when in fullscreen mode */                                  /* we only register for this event when in fullscreen mode */
1135                                  /* or grab_keyboard */                                  /* or grab_keyboard */
1136                                  mouse_in_wnd = True;                                  g_mouse_in_wnd = True;
1137                                  if (fullscreen)                                  if (g_fullscreen)
1138                                  {                                  {
1139                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,
1140                                                         CurrentTime);                                                         CurrentTime);
1141                                          break;                                          break;
1142                                  }                                  }
1143                                  if (focused)                                  if (g_focused)
1144                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1145                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
1146                                  break;                                  break;
1147    
1148                          case LeaveNotify:                          case LeaveNotify:
1149                                  /* we only register for this event when grab_keyboard */                                  /* we only register for this event when grab_keyboard */
1150                                  mouse_in_wnd = False;                                  g_mouse_in_wnd = False;
1151                                  XUngrabKeyboard(display, CurrentTime);                                  XUngrabKeyboard(g_display, CurrentTime);
1152                                  break;                                  break;
1153    
1154                          case Expose:                          case Expose:
1155                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(g_display, g_backstore, g_wnd, g_gc,
1156                                            xevent.xexpose.x, xevent.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
1157                                            xevent.xexpose.width,                                            xevent.xexpose.width,
1158                                            xevent.xexpose.height,                                            xevent.xexpose.height,
# Line 994  xwin_process_events(void) Line 1168  xwin_process_events(void)
1168    
1169                                  if (xevent.xmapping.request == MappingModifier)                                  if (xevent.xmapping.request == MappingModifier)
1170                                  {                                  {
1171                                          XFreeModifiermap(mod_map);                                          XFreeModifiermap(g_mod_map);
1172                                          mod_map = XGetModifierMapping(display);                                          g_mod_map = XGetModifierMapping(g_display);
1173                                  }                                  }
1174                                  break;                                  break;
1175    
1176                          /* clipboard stuff */                                  /* clipboard stuff */
1177                          case SelectionNotify:                          case SelectionNotify:
1178                                  xclip_handle_SelectionNotify(&xevent.xselection);                                  xclip_handle_SelectionNotify(&xevent.xselection);
1179                                  break;                                  break;
# Line 1022  xwin_process_events(void) Line 1196  xwin_process_events(void)
1196  int  int
1197  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1198  {  {
1199          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;
1200          fd_set rfds;          fd_set rfds, wfds;
   
         FD_ZERO(&rfds);  
1201    
1202          while (True)          while (True)
1203          {          {
# Line 1035  ui_select(int rdp_socket) Line 1207  ui_select(int rdp_socket)
1207                          return 0;                          return 0;
1208    
1209                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1210                    FD_ZERO(&wfds);
1211                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1212                  FD_SET(x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1213    
1214    #ifdef WITH_RDPSND
1215                    /* FIXME: there should be an API for registering fds */
1216                    if (g_dsp_busy)
1217                    {
1218                            FD_SET(g_dsp_fd, &wfds);
1219                            n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1220                    }
1221    #endif
1222    
1223                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, NULL))
1224                  {                  {
1225                          case -1:                          case -1:
1226                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
# Line 1049  ui_select(int rdp_socket) Line 1231  ui_select(int rdp_socket)
1231    
1232                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1233                          return 1;                          return 1;
1234    
1235    #ifdef WITH_RDPSND
1236                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1237                            wave_out_play();
1238    #endif
1239          }          }
1240  }  }
1241    
1242  void  void
1243  ui_move_pointer(int x, int y)  ui_move_pointer(int x, int y)
1244  {  {
1245          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);          XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y);
1246  }  }
1247    
1248  HBITMAP  HBITMAP
# Line 1065  ui_create_bitmap(int width, int height, Line 1252  ui_create_bitmap(int width, int height,
1252          Pixmap bitmap;          Pixmap bitmap;
1253          uint8 *tdata;          uint8 *tdata;
1254    
1255          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1256          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1257          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1258                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);
1259    
1260          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1261    
1262          XFree(image);          XFree(image);
1263          if (!owncolmap)          if (!g_owncolmap)
1264                  xfree(tdata);                  xfree(tdata);
1265          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1266  }  }
# Line 1083  ui_paint_bitmap(int x, int y, int cx, in Line 1270  ui_paint_bitmap(int x, int y, int cx, in
1270  {  {
1271          XImage *image;          XImage *image;
1272          uint8 *tdata;          uint8 *tdata;
1273          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1274          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1275                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);
1276    
1277          if (ownbackstore)          if (g_ownbackstore)
1278          {          {
1279                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);
1280                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1281          }          }
1282          else          else
1283          {          {
1284                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);
1285          }          }
1286    
1287          XFree(image);          XFree(image);
1288          if (!owncolmap)          if (!g_owncolmap)
1289                  xfree(tdata);                  xfree(tdata);
1290  }  }
1291    
1292  void  void
1293  ui_destroy_bitmap(HBITMAP bmp)  ui_destroy_bitmap(HBITMAP bmp)
1294  {  {
1295          XFreePixmap(display, (Pixmap) bmp);          XFreePixmap(g_display, (Pixmap) bmp);
1296  }  }
1297    
1298  HGLYPH  HGLYPH
# Line 1118  ui_create_glyph(int width, int height, u Line 1305  ui_create_glyph(int width, int height, u
1305    
1306          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1307    
1308          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);
1309          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(g_display, bitmap, 0, NULL);
1310    
1311          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,
1312                               width, height, 8, scanline);                               width, height, 8, scanline);
1313          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
1314          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
1315          XInitImage(image);          XInitImage(image);
1316    
1317          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, gc, image, 0, 0, 0, 0, width, height);
1318    
1319          XFree(image);          XFree(image);
1320          XFreeGC(display, gc);          XFreeGC(g_display, gc);
1321          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
1322  }  }
1323    
1324  void  void
1325  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(HGLYPH glyph)
1326  {  {
1327          XFreePixmap(display, (Pixmap) glyph);          XFreePixmap(g_display, (Pixmap) glyph);
1328  }  }
1329    
1330  HCURSOR  HCURSOR
# Line 1201  ui_create_cursor(unsigned int x, unsigne Line 1388  ui_create_cursor(unsigned int x, unsigne
1388          maskglyph = ui_create_glyph(width, height, mask);          maskglyph = ui_create_glyph(width, height, mask);
1389    
1390          xcursor =          xcursor =
1391                  XCreatePixmapCursor(display, (Pixmap) cursorglyph,                  XCreatePixmapCursor(g_display, (Pixmap) cursorglyph,
1392                                      (Pixmap) maskglyph, &fg, &bg, x, y);                                      (Pixmap) maskglyph, &fg, &bg, x, y);
1393    
1394          ui_destroy_glyph(maskglyph);          ui_destroy_glyph(maskglyph);
# Line 1214  ui_create_cursor(unsigned int x, unsigne Line 1401  ui_create_cursor(unsigned int x, unsigne
1401  void  void
1402  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(HCURSOR cursor)
1403  {  {
1404          current_cursor = (Cursor) cursor;          g_current_cursor = (Cursor) cursor;
1405          XDefineCursor(display, wnd, current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
1406  }  }
1407    
1408  void  void
1409  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_cursor(HCURSOR cursor)
1410  {  {
1411          XFreeCursor(display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1412    }
1413    
1414    void
1415    ui_set_null_cursor(void)
1416    {
1417            ui_set_cursor(g_null_cursor);
1418  }  }
1419    
1420  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
# Line 1236  ui_create_colourmap(COLOURMAP * colours) Line 1429  ui_create_colourmap(COLOURMAP * colours)
1429  {  {
1430          COLOURENTRY *entry;          COLOURENTRY *entry;
1431          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
1432          if (!owncolmap)          if (!g_owncolmap)
1433          {          {
1434                  uint32 *map = (uint32 *) xmalloc(sizeof(*colmap) * ncolours);                  uint32 *map = (uint32 *) xmalloc(sizeof(*g_colmap) * ncolours);
1435                  XColor xentry;                  XColor xentry;
1436                  XColor xc_cache[256];                  XColor xc_cache[256];
1437                  uint32 colour;                  uint32 colour;
# Line 1248  ui_create_colourmap(COLOURMAP * colours) Line 1441  ui_create_colourmap(COLOURMAP * colours)
1441                          entry = &colours->colours[i];                          entry = &colours->colours[i];
1442                          MAKE_XCOLOR(&xentry, entry);                          MAKE_XCOLOR(&xentry, entry);
1443    
1444                          if (XAllocColor(display, xcolmap, &xentry) == 0)                          if (XAllocColor(g_display, g_xcolmap, &xentry) == 0)
1445                          {                          {
1446                                  /* Allocation failed, find closest match. */                                  /* Allocation failed, find closest match. */
1447                                  int j = 256;                                  int j = 256;
# Line 1262  ui_create_colourmap(COLOURMAP * colours) Line 1455  ui_create_colourmap(COLOURMAP * colours)
1455                                          xc_cache[colLookup].red = xc_cache[colLookup].green =                                          xc_cache[colLookup].red = xc_cache[colLookup].green =
1456                                                  xc_cache[colLookup].blue = 0;                                                  xc_cache[colLookup].blue = 0;
1457                                          xc_cache[colLookup].flags = 0;                                          xc_cache[colLookup].flags = 0;
1458                                          XQueryColor(display,                                          XQueryColor(g_display,
1459                                                      DefaultColormap(display,                                                      DefaultColormap(g_display,
1460                                                                      DefaultScreen(display)),                                                                      DefaultScreen(g_display)),
1461                                                      &xc_cache[colLookup]);                                                      &xc_cache[colLookup]);
1462                                  }                                  }
1463                                  colLookup = 0;                                  colLookup = 0;
# Line 1325  ui_create_colourmap(COLOURMAP * colours) Line 1518  ui_create_colourmap(COLOURMAP * colours)
1518                          MAKE_XCOLOR(xentry, entry);                          MAKE_XCOLOR(xentry, entry);
1519                  }                  }
1520    
1521                  map = XCreateColormap(display, wnd, visual, AllocAll);                  map = XCreateColormap(g_display, g_wnd, g_visual, AllocAll);
1522                  XStoreColors(display, map, xcolours, ncolours);                  XStoreColors(g_display, map, xcolours, ncolours);
1523    
1524                  xfree(xcolours);                  xfree(xcolours);
1525                  return (HCOLOURMAP) map;                  return (HCOLOURMAP) map;
# Line 1336  ui_create_colourmap(COLOURMAP * colours) Line 1529  ui_create_colourmap(COLOURMAP * colours)
1529  void  void
1530  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
1531  {  {
1532          if (!owncolmap)          if (!g_owncolmap)
1533                  xfree(map);                  xfree(map);
1534          else          else
1535                  XFreeColormap(display, (Colormap) map);                  XFreeColormap(g_display, (Colormap) map);
1536  }  }
1537    
1538  void  void
1539  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
1540  {  {
1541          if (!owncolmap)          if (!g_owncolmap)
1542                  colmap = (uint32 *) map;          {
1543                    if (g_colmap)
1544                            xfree(g_colmap);
1545    
1546                    g_colmap = (uint32 *) map;
1547            }
1548          else          else
1549                  XSetWindowColormap(display, wnd, (Colormap) map);                  XSetWindowColormap(g_display, g_wnd, (Colormap) map);
1550  }  }
1551    
1552  void  void
# Line 1360  ui_set_clip(int x, int y, int cx, int cy Line 1558  ui_set_clip(int x, int y, int cx, int cy
1558          rect.y = y;          rect.y = y;
1559          rect.width = cx;          rect.width = cx;
1560          rect.height = cy;          rect.height = cy;
1561          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);          XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);
1562  }  }
1563    
1564  void  void
# Line 1370  ui_reset_clip(void) Line 1568  ui_reset_clip(void)
1568    
1569          rect.x = 0;          rect.x = 0;
1570          rect.y = 0;          rect.y = 0;
1571          rect.width = width;          rect.width = g_width;
1572          rect.height = height;          rect.height = g_height;
1573          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);          XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);
1574  }  }
1575    
1576  void  void
1577  ui_bell(void)  ui_bell(void)
1578  {  {
1579          XBell(display, 0);          XBell(g_display, 0);
1580  }  }
1581    
1582  void  void
# Line 1419  ui_patblt(uint8 opcode, Line 1617  ui_patblt(uint8 opcode,
1617                  case 2: /* Hatch */                  case 2: /* Hatch */
1618                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1619                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1620                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1621                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1622                          XSetFillStyle(display, gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1623                          XSetStipple(display, gc, fill);                          XSetStipple(g_display, g_gc, fill);
1624                          XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1625                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
1626                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1627                          XSetTSOrigin(display, gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1628                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
1629                          break;                          break;
1630    
# Line 1437  ui_patblt(uint8 opcode, Line 1635  ui_patblt(uint8 opcode,
1635    
1636                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1637                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1638                          XSetFillStyle(display, gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1639                          XSetStipple(display, gc, fill);                          XSetStipple(g_display, g_gc, fill);
1640                          XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1641    
1642                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
1643    
1644                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1645                          XSetTSOrigin(display, gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1646                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
1647                          break;                          break;
1648    
# Line 1461  ui_screenblt(uint8 opcode, Line 1659  ui_screenblt(uint8 opcode,
1659               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1660  {  {
1661          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1662          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1663          if (ownbackstore)          if (g_ownbackstore)
1664                  XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1665          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1666  }  }
1667    
# Line 1473  ui_memblt(uint8 opcode, Line 1671  ui_memblt(uint8 opcode,
1671            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
1672  {  {
1673          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1674          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(g_display, (Pixmap) src, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1675          if (ownbackstore)          if (g_ownbackstore)
1676                  XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, (Pixmap) src, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1677          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1678  }  }
1679    
# Line 1519  ui_line(uint8 opcode, Line 1717  ui_line(uint8 opcode,
1717  {  {
1718          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1719          SET_FOREGROUND(pen->colour);          SET_FOREGROUND(pen->colour);
1720          XDrawLine(display, wnd, gc, startx, starty, endx, endy);          XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy);
1721          if (ownbackstore)          if (g_ownbackstore)
1722                  XDrawLine(display, backstore, gc, startx, starty, endx, endy);                  XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy);
1723          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1724  }  }
1725    
# Line 1544  ui_draw_glyph(int mixmode, Line 1742  ui_draw_glyph(int mixmode,
1742          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
1743          SET_BACKGROUND(bgcolour);          SET_BACKGROUND(bgcolour);
1744    
1745          XSetFillStyle(display, gc,          XSetFillStyle(g_display, g_gc,
1746                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1747          XSetStipple(display, gc, (Pixmap) glyph);          XSetStipple(g_display, g_gc, (Pixmap) glyph);
1748          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(g_display, g_gc, x, y);
1749    
1750          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1751    
1752          XSetFillStyle(display, gc, FillSolid);          XSetFillStyle(g_display, g_gc, FillSolid);
1753  }  }
1754    
1755  #define DO_GLYPH(ttext,idx) \  #define DO_GLYPH(ttext,idx) \
# Line 1658  ui_draw_text(uint8 font, uint8 flags, in Line 1856  ui_draw_text(uint8 font, uint8 flags, in
1856                                  break;                                  break;
1857                  }                  }
1858          }          }
1859          if (ownbackstore)          if (g_ownbackstore)
1860          {          {
1861                  if (boxcx > 1)                  if (boxcx > 1)
1862                          XCopyArea(display, backstore, wnd, gc, boxx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx,
1863                                    boxy, boxcx, boxcy, boxx, boxy);                                    boxy, boxcx, boxcy, boxx, boxy);
1864                  else                  else
1865                          XCopyArea(display, backstore, wnd, gc, clipx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx,
1866                                    clipy, clipcx, clipcy, clipx, clipy);                                    clipy, clipcx, clipcy, clipx, clipy);
1867          }          }
1868  }  }
# Line 1675  ui_desktop_save(uint32 offset, int x, in Line 1873  ui_desktop_save(uint32 offset, int x, in
1873          Pixmap pix;          Pixmap pix;
1874          XImage *image;          XImage *image;
1875    
1876          if (ownbackstore)          if (g_ownbackstore)
1877          {          {
1878                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap);
1879          }          }
1880          else          else
1881          {          {
1882                  pix = XCreatePixmap(display, wnd, cx, cy, depth);                  pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth);
1883                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);                  XCopyArea(g_display, g_wnd, pix, g_gc, x, y, cx, cy, 0, 0);
1884                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
1885                  XFreePixmap(display, pix);                  XFreePixmap(g_display, pix);
1886          }          }
1887    
1888          offset *= bpp / 8;          offset *= g_bpp / 8;
1889          cache_put_desktop(offset, cx, cy, image->bytes_per_line, bpp / 8, (uint8 *) image->data);          cache_put_desktop(offset, cx, cy, image->bytes_per_line, g_bpp / 8, (uint8 *) image->data);
1890    
1891          XDestroyImage(image);          XDestroyImage(image);
1892  }  }
# Line 1699  ui_desktop_restore(uint32 offset, int x, Line 1897  ui_desktop_restore(uint32 offset, int x,
1897          XImage *image;          XImage *image;
1898          uint8 *data;          uint8 *data;
1899    
1900          offset *= bpp / 8;          offset *= g_bpp / 8;
1901          data = cache_get_desktop(offset, cx, cy, bpp / 8);          data = cache_get_desktop(offset, cx, cy, g_bpp / 8);
1902          if (data == NULL)          if (data == NULL)
1903                  return;                  return;
1904    
1905          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1906                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);                               (char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8);
1907    
1908          if (ownbackstore)          if (g_ownbackstore)
1909          {          {
1910                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_backstore, g_gc, image, 0, 0, x, y, cx, cy);
1911                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1912          }          }
1913          else          else
1914          {          {
1915                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);                  XPutImage(g_display, g_wnd, g_gc, image, 0, 0, x, y, cx, cy);
1916          }          }
1917    
1918          XFree(image);          XFree(image);
1919  }  }
   

Legend:
Removed from v.432  
changed lines
  Added in v.508

  ViewVC Help
Powered by ViewVC 1.1.26