/[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 342 by astrand, Fri Mar 14 12:00:17 2003 UTC revision 504 by stargo, Sun Oct 19 11:59:41 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X Window System     User interface services - X Window System
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2002
# Line 23  Line 23 
23  #include <time.h>  #include <time.h>
24  #include <errno.h>  #include <errno.h>
25  #include "rdesktop.h"  #include "rdesktop.h"
26    #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  static int x_socket;  Window g_wnd;
43  static Screen *screen;  BOOL g_enable_compose = False;
44  static Window wnd;  static GC g_gc;
45  static GC gc;  static Visual *g_visual;
46  static Visual *visual;  static int g_depth;
47  static int depth;  static int g_bpp;
48  static int bpp;  static XIM g_IM;
49  static XIM IM;  static XIC g_IC;
50  static XIC IC;  static XModifierKeymap *g_mod_map;
51  static XModifierKeymap *mod_map;  static Cursor g_current_cursor;
52  static Cursor current_cursor;  static Atom g_protocol_atom, g_kill_atom;
53  static Atom protocol_atom, kill_atom;  static BOOL g_focused;
54    static BOOL g_mouse_in_wnd;
55    
56  /* endianness */  /* endianness */
57  static BOOL host_be;  static BOOL g_host_be;
58  static BOOL xserver_be;  static BOOL g_xserver_be;
59    
60  /* software backing store */  /* software backing store */
61  static BOOL ownbackstore;  static BOOL g_ownbackstore;
62  static Pixmap backstore;  static Pixmap g_backstore;
63    
64  /* Moving in single app mode */  /* Moving in single app mode */
65  static BOOL moving_wnd;  static BOOL g_moving_wnd;
66  static int move_x_offset = 0;  static int g_move_x_offset = 0;
67  static int move_y_offset = 0;  static int g_move_y_offset = 0;
68    
69    #ifdef WITH_RDPSND
70    extern int g_dsp_fd;
71    extern BOOL g_dsp_busy;
72    extern BOOL g_rdpsnd;
73    #endif
74    
75  /* MWM decorations */  /* MWM decorations */
76  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
# Line 85  typedef struct Line 93  typedef struct
93  }  }
94  PixelColour;  PixelColour;
95    
96    
97  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
98  { \  { \
99          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(g_display, g_wnd, g_gc, x, y, cx, cy); \
100          if (ownbackstore) \          if (g_ownbackstore) \
101                  XFillRectangle(display, backstore, gc, x, y, cx, cy); \                  XFillRectangle(g_display, g_backstore, g_gc, x, y, cx, cy); \
102  }  }
103    
104  #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\  #define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\
105  { \  { \
106          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); \
107  }  }
108    
109  /* colour maps */  /* colour maps */
110  BOOL owncolmap = False;  BOOL g_owncolmap = False;
111  static Colormap xcolmap;  static Colormap g_xcolmap;
112  static uint32 *colmap;  static uint32 *g_colmap = NULL;
113    
114  #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]) )
115  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
116  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
117    
118  static int rop2_map[] = {  static int rop2_map[] = {
119          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 125  static int rop2_map[] = { Line 134  static int rop2_map[] = {
134          GXset                   /* 1 */          GXset                   /* 1 */
135  };  };
136    
137  #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]); }
138  #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); }
139    
140  static void  static void
141  mwm_hide_decorations(void)  mwm_hide_decorations(void)
# Line 139  mwm_hide_decorations(void) Line 148  mwm_hide_decorations(void)
148          motif_hints.decorations = 0;          motif_hints.decorations = 0;
149    
150          /* get the atom for the property */          /* get the atom for the property */
151          hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);          hintsatom = XInternAtom(g_display, "_MOTIF_WM_HINTS", False);
152          if (!hintsatom)          if (!hintsatom)
153          {          {
154                  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");
155                  return;                  return;
156          }          }
157    
158          XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace,          XChangeProperty(g_display, g_wnd, hintsatom, hintsatom, 32, PropModeReplace,
159                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
160  }  }
161    
# Line 198  make_colour16(PixelColour pc) Line 207  make_colour16(PixelColour pc)
207  static uint32  static uint32
208  make_colour24(PixelColour pc)  make_colour24(PixelColour pc)
209  {  {
210          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
211            {
212                    return pc.red | (pc.green << 8) | (pc.blue << 16);
213            }
214            else
215            {
216                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
217            }
218  }  }
219    
220  static uint32  static uint32
221  make_colour32(PixelColour pc)  make_colour32(PixelColour pc)
222  {  {
223          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
224            {
225                    return pc.red | (pc.green << 8) | (pc.blue << 16);
226            }
227            else
228            {
229                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
230            }
231  }  }
232    
233  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 215  make_colour32(PixelColour pc) Line 238  make_colour32(PixelColour pc)
238  static uint32  static uint32
239  translate_colour(uint32 colour)  translate_colour(uint32 colour)
240  {  {
241          switch (server_bpp)          switch (g_server_bpp)
242          {          {
243                  case 15:                  case 15:
244                          switch (bpp)                          switch (g_bpp)
245                          {                          {
246                                  case 16:                                  case 16:
247                                          colour = make_colour16(split_colour15(colour));                                          colour = make_colour16(split_colour15(colour));
# Line 232  translate_colour(uint32 colour) Line 255  translate_colour(uint32 colour)
255                          }                          }
256                          break;                          break;
257                  case 16:                  case 16:
258                          switch (bpp)                          switch (g_bpp)
259                          {                          {
260                                  case 16:                                  case 16:
261                                          break;                                          break;
# Line 245  translate_colour(uint32 colour) Line 268  translate_colour(uint32 colour)
268                          }                          }
269                          break;                          break;
270                  case 24:                  case 24:
271                          switch (bpp)                          switch (g_bpp)
272                          {                          {
273                                  case 16:                                  case 16:
274                                          colour = make_colour16(split_colour24(colour));                                          colour = make_colour16(split_colour24(colour));
# Line 258  translate_colour(uint32 colour) Line 281  translate_colour(uint32 colour)
281                          }                          }
282                          break;                          break;
283          }          }
         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;  
         }  
   
284          return colour;          return colour;
285  }  }
286    
# Line 283  static void Line 288  static void
288  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
289  {  {
290          while (out < end)          while (out < end)
291                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) g_colmap[*(data++)];
292  }  }
293    
294  static void  static void
295  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
296  {  {
297          while (out < end)          while (out < end)
298                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) g_colmap[*(data++)];
299  }  }
300    
301  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 301  translate8to24(uint8 * data, uint8 * out Line 306  translate8to24(uint8 * data, uint8 * out
306    
307          while (out < end)          while (out < end)
308          {          {
309                  value = colmap[*(data++)];                  value = g_colmap[*(data++)];
310                  *(out++) = value;                  *(out++) = value;
311                  *(out++) = value >> 8;                  *(out++) = value >> 8;
312                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 312  static void Line 317  static void
317  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
318  {  {
319          while (out < end)          while (out < end)
320                  *(out++) = colmap[*(data++)];                  *(out++) = g_colmap[*(data++)];
321  }  }
322    
323  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
324    
325  static void  static void
326  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
327  {  {
328            uint16 pixel;
329            uint16 value;
330    
331          while (out < end)          while (out < end)
332                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
333                    pixel = *(data++);
334    
335                    if (g_host_be)
336                    {
337                    BSWAP16(pixel)}
338    
339                    value = make_colour16(split_colour15(pixel));
340    
341                    if (g_xserver_be)
342                    {
343                            *(out++) = value >> 8;
344                            *(out++) = value;
345                    }
346                    else
347                    {
348                            *(out++) = value;
349                            *(out++) = value >> 8;
350                    }
351            }
352  }  }
353    
354  static void  static void
355  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
356  {  {
357          uint32 value;          uint32 value;
358            uint16 pixel;
359    
360          while (out < end)          while (out < end)
361          {          {
362                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
363                  *(out++) = value;  
364                  *(out++) = value >> 8;                  if (g_host_be)
365                  *(out++) = value >> 16;                  {
366                    BSWAP16(pixel)}
367    
368                    value = make_colour24(split_colour15(pixel));
369                    if (g_xserver_be)
370                    {
371                            *(out++) = value >> 16;
372                            *(out++) = value >> 8;
373                            *(out++) = value;
374                    }
375                    else
376                    {
377                            *(out++) = value;
378                            *(out++) = value >> 8;
379                            *(out++) = value >> 16;
380                    }
381          }          }
382  }  }
383    
384  static void  static void
385  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
386  {  {
387            uint16 pixel;
388            uint32 value;
389    
390          while (out < end)          while (out < end)
391                  *(out++) = make_colour32(split_colour15(*(data++)));          {
392                    pixel = *(data++);
393    
394                    if (g_host_be)
395                    {
396                            BSWAP16(pixel);
397                    }
398    
399                    value = make_colour32(split_colour15(pixel));
400    
401                    if (g_xserver_be)
402                    {
403                            *(out++) = value >> 24;
404                            *(out++) = value >> 16;
405                            *(out++) = value >> 8;
406                            *(out++) = value;
407                    }
408                    else
409                    {
410                            *(out++) = value;
411                            *(out++) = value >> 8;
412                            *(out++) = value >> 16;
413                            *(out++) = value >> 24;
414                    }
415            }
416  }  }
417    
418  static void  static void
419  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint16 * out, uint16 * end)
420  {  {
421          while (out < end)          uint16 value;
422                  *(out++) = (uint16) (*(data++));  
423            if (g_xserver_be)
424            {
425                    while (out < end)
426                    {
427                            value = *data;
428                            BSWAP16(value);
429                            *out = value;
430                            data++;
431                            out++;
432                    }
433    
434            }
435            else
436            {
437                    while (out < end)
438                    {
439                            *out = *data;
440                            out++;
441                            data++;
442                    }
443            }
444  }  }
445    
446    
# Line 357  static void Line 448  static void
448  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
449  {  {
450          uint32 value;          uint32 value;
451            uint16 pixel;
452    
453          while (out < end)          while (out < end)
454          {          {
455                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
456                  *(out++) = value;  
457                  *(out++) = value >> 8;                  if (g_host_be)
458                  *(out++) = value >> 16;                  {
459                    BSWAP16(pixel)}
460    
461                    value = make_colour24(split_colour16(pixel));
462    
463                    if (g_xserver_be)
464                    {
465                            *(out++) = value >> 16;
466                            *(out++) = value >> 8;
467                            *(out++) = value;
468                    }
469                    else
470                    {
471                            *(out++) = value;
472                            *(out++) = value >> 8;
473                            *(out++) = value >> 16;
474                    }
475          }          }
476  }  }
477    
478  static void  static void
479  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
480  {  {
481            uint16 pixel;
482            uint32 value;
483    
484          while (out < end)          while (out < end)
485                  *(out++) = make_colour32(split_colour16(*(data++)));          {
486                    pixel = *(data++);
487    
488                    if (g_host_be)
489                    {
490                    BSWAP16(pixel)}
491    
492                    value = make_colour32(split_colour16(pixel));
493    
494                    if (g_xserver_be)
495                    {
496                            *(out++) = value >> 24;
497                            *(out++) = value >> 16;
498                            *(out++) = value >> 8;
499                            *(out++) = value;
500                    }
501                    else
502                    {
503                            *(out++) = value;
504                            *(out++) = value >> 8;
505                            *(out++) = value >> 16;
506                            *(out++) = value >> 24;
507                    }
508            }
509  }  }
510    
511  static void  static void
512  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
513  {  {
514          uint32 pixel = 0;          uint32 pixel = 0;
515            uint16 value;
516          while (out < end)          while (out < end)
517          {          {
518                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
519                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
520                  pixel |= *(data++);                  pixel |= *(data++);
521                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
522                    value = (uint16) make_colour16(split_colour24(pixel));
523    
524                    if (g_xserver_be)
525                    {
526                            *(out++) = value >> 8;
527                            *(out++) = value;
528                    }
529                    else
530                    {
531                            *(out++) = value;
532                            *(out++) = value >> 8;
533                    }
534          }          }
535  }  }
536    
# Line 397  translate24to24(uint8 * data, uint8 * ou Line 544  translate24to24(uint8 * data, uint8 * ou
544  }  }
545    
546  static void  static void
547  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
548  {  {
         uint32 pixel = 0;  
549          while (out < end)          while (out < end)
550          {          {
551                  memcpy(&pixel, data, 3);                  if (g_xserver_be)
552                  data += 3;                  {
553                  *(out++) = pixel;                          *(out++) = 0x00;
554                            *(out++) = *(data++);
555                            *(out++) = *(data++);
556                            *(out++) = *(data++);
557                    }
558                    else
559                    {
560                            *(out++) = *(data++);
561                            *(out++) = *(data++);
562                            *(out++) = *(data++);
563                            *(out++) = 0x00;
564                    }
565          }          }
566  }  }
567    
568  static uint8 *  static uint8 *
569  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
570  {  {
571          int size = width * height * bpp / 8;          int size = width * height * g_bpp / 8;
572          uint8 *out = xmalloc(size);          uint8 *out = (uint8 *) xmalloc(size);
573          uint8 *end = out + size;          uint8 *end = out + size;
574    
575          switch (server_bpp)          switch (g_server_bpp)
576          {          {
577                  case 24:                  case 24:
578                          switch (bpp)                          switch (g_bpp)
579                          {                          {
580                                  case 32:                                  case 32:
581                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
582                                          break;                                          break;
583                                  case 24:                                  case 24:
584                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
585                                          break;                                          break;
586                                  case 16:                                  case 16:
587                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
588                                          break;                                          break;
589                          }                          }
590                          break;                          break;
591                  case 16:                  case 16:
592                          switch (bpp)                          switch (g_bpp)
593                          {                          {
594                                  case 32:                                  case 32:
595                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
596                                          break;                                          break;
597                                  case 24:                                  case 24:
598                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
# Line 448  translate_image(int width, int height, u Line 604  translate_image(int width, int height, u
604                          }                          }
605                          break;                          break;
606                  case 15:                  case 15:
607                          switch (bpp)                          switch (g_bpp)
608                          {                          {
609                                  case 32:                                  case 32:
610                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
611                                          break;                                          break;
612                                  case 24:                                  case 24:
613                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
614                                          break;                                          break;
615                                  case 16:                                  case 16:
616                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
617                                          break;                                          break;
618                          }                          }
619                          break;                          break;
620                  case 8:                  case 8:
621                          switch (bpp)                          switch (g_bpp)
622                          {                          {
623                                  case 8:                                  case 8:
624                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
# Line 490  get_key_state(unsigned int state, uint32 Line 644  get_key_state(unsigned int state, uint32
644          int modifierpos, key, keysymMask = 0;          int modifierpos, key, keysymMask = 0;
645          int offset;          int offset;
646    
647          KeyCode keycode = XKeysymToKeycode(display, keysym);          KeyCode keycode = XKeysymToKeycode(g_display, keysym);
648    
649          if (keycode == NoSymbol)          if (keycode == NoSymbol)
650                  return False;                  return False;
651    
652          for (modifierpos = 0; modifierpos < 8; modifierpos++)          for (modifierpos = 0; modifierpos < 8; modifierpos++)
653          {          {
654                  offset = mod_map->max_keypermod * modifierpos;                  offset = g_mod_map->max_keypermod * modifierpos;
655    
656                  for (key = 0; key < mod_map->max_keypermod; key++)                  for (key = 0; key < g_mod_map->max_keypermod; key++)
657                  {                  {
658                          if (mod_map->modifiermap[offset + key] == keycode)                          if (g_mod_map->modifiermap[offset + key] == keycode)
659                                  keysymMask |= 1 << modifierpos;                                  keysymMask |= 1 << modifierpos;
660                  }                  }
661          }          }
# Line 516  ui_init(void) Line 670  ui_init(void)
670          uint16 test;          uint16 test;
671          int i;          int i;
672    
673          display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
674          if (display == NULL)          if (g_display == NULL)
675          {          {
676                  error("Failed to open display: %s\n", XDisplayName(NULL));                  error("Failed to open display: %s\n", XDisplayName(NULL));
677                  return False;                  return False;
678          }          }
679    
680          x_socket = ConnectionNumber(display);          g_x_socket = ConnectionNumber(g_display);
681          screen = DefaultScreenOfDisplay(display);          g_screen = DefaultScreenOfDisplay(g_display);
682          visual = DefaultVisualOfScreen(screen);          g_visual = DefaultVisualOfScreen(g_screen);
683          depth = DefaultDepthOfScreen(screen);          g_depth = DefaultDepthOfScreen(g_screen);
684    
685          pfm = XListPixmapFormats(display, &i);          pfm = XListPixmapFormats(g_display, &i);
686          if (pfm != NULL)          if (pfm != NULL)
687          {          {
688                  /* Use maximum bpp for this depth - this is generally                  /* Use maximum bpp for this depth - this is generally
689                     desirable, e.g. 24 bits->32 bits. */                     desirable, e.g. 24 bits->32 bits. */
690                  while (i--)                  while (i--)
691                  {                  {
692                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))                          if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp))
693                          {                          {
694                                  bpp = pfm[i].bits_per_pixel;                                  g_bpp = pfm[i].bits_per_pixel;
695                          }                          }
696                  }                  }
697                  XFree(pfm);                  XFree(pfm);
698          }          }
699    
700          if (bpp < 8)          if (g_bpp < 8)
701          {          {
702                  error("Less than 8 bpp not currently supported.\n");                  error("Less than 8 bpp not currently supported.\n");
703                  XCloseDisplay(display);                  XCloseDisplay(g_display);
704                  return False;                  return False;
705          }          }
706    
707          if (owncolmap != True)          if (g_owncolmap != True)
708          {          {
709                  xcolmap = DefaultColormapOfScreen(screen);                  g_xcolmap = DefaultColormapOfScreen(g_screen);
710                  if (depth <= 8)                  if (g_depth <= 8)
711                          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");
712          }          }
713    
714          gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);
715    
716          if (DoesBackingStore(screen) != Always)          if (DoesBackingStore(g_screen) != Always)
717                  ownbackstore = True;                  g_ownbackstore = True;
718    
719          test = 1;          test = 1;
720          host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
721          xserver_be = (ImageByteOrder(display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
722    
723          if ((width == 0) || (height == 0))          /*
724             * Determine desktop size
725             */
726            if (g_width < 0)
727            {
728                    /* Percent of screen */
729                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
730                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
731            }
732            else if (g_width == 0)
733          {          {
734                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
735                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
736    
737                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
738                  {                  {
739                          width = cx;                          g_width = cx;
740                          height = cy;                          g_height = cy;
741                  }                  }
742                  else                  else
743                  {                  {
744                          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");
745                          width = 800;                          g_width = 800;
746                          height = 600;                          g_height = 600;
747                  }                  }
748          }          }
749            else if (g_fullscreen)
         if (fullscreen)  
750          {          {
751                  width = WidthOfScreen(screen);                  g_width = WidthOfScreen(g_screen);
752                  height = HeightOfScreen(screen);                  g_height = HeightOfScreen(g_screen);
753          }          }
754    
755          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
756          width = (width + 3) & ~3;          g_width = (g_width + 3) & ~3;
757    
758          if (ownbackstore)          if (g_ownbackstore)
759          {          {
760                  backstore =                  g_backstore =
761                          XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);                          XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,
762                                          g_depth);
763    
764                  /* clear to prevent rubbish being exposed at startup */                  /* clear to prevent rubbish being exposed at startup */
765                  XSetForeground(display, gc, BlackPixelOfScreen(screen));                  XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
766                  XFillRectangle(display, backstore, gc, 0, 0, width, height);                  XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
767          }          }
768    
769          mod_map = XGetModifierMapping(display);          g_mod_map = XGetModifierMapping(g_display);
   
         if (enable_compose)  
                 IM = XOpenIM(display, NULL, NULL, NULL);  
770    
771          xkeymap_init();          xkeymap_init();
772    
773            if (g_enable_compose)
774                    g_IM = XOpenIM(g_display, NULL, NULL, NULL);
775    
776            xclip_init();
777    
778          /* todo take this out when high colour is done */          /* todo take this out when high colour is done */
779          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);
780    
781          return True;          return True;
782  }  }
# Line 619  ui_init(void) Line 784  ui_init(void)
784  void  void
785  ui_deinit(void)  ui_deinit(void)
786  {  {
787          if (IM != NULL)          if (g_IM != NULL)
788                  XCloseIM(IM);                  XCloseIM(g_IM);
789    
790          XFreeModifiermap(mod_map);          XFreeModifiermap(g_mod_map);
791    
792          if (ownbackstore)          if (g_ownbackstore)
793                  XFreePixmap(display, backstore);                  XFreePixmap(g_display, g_backstore);
794    
795          XFreeGC(display, gc);          XFreeGC(g_display, g_gc);
796          XCloseDisplay(display);          XCloseDisplay(g_display);
797          display = NULL;          g_display = NULL;
798  }  }
799    
800  BOOL  BOOL
# Line 642  ui_create_window(void) Line 807  ui_create_window(void)
807          long input_mask, ic_input_mask;          long input_mask, ic_input_mask;
808          XEvent xevent;          XEvent xevent;
809    
810          wndwidth = fullscreen ? WidthOfScreen(screen) : width;          wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width;
811          wndheight = fullscreen ? HeightOfScreen(screen) : height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
812    
813          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
814          attribs.backing_store = ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
815          attribs.override_redirect = fullscreen;          attribs.override_redirect = g_fullscreen;
816    
817          wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
818                              0, CopyFromParent, InputOutput, CopyFromParent,                                0, CopyFromParent, InputOutput, CopyFromParent,
819                              CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
820    
821          XStoreName(display, wnd, title);          XStoreName(g_display, g_wnd, g_title);
822    
823          if (hide_decorations)          if (g_hide_decorations)
824                  mwm_hide_decorations();                  mwm_hide_decorations();
825    
826          classhints = XAllocClassHint();          classhints = XAllocClassHint();
827          if (classhints != NULL)          if (classhints != NULL)
828          {          {
829                  classhints->res_name = classhints->res_class = "rdesktop";                  classhints->res_name = classhints->res_class = "rdesktop";
830                  XSetClassHint(display, wnd, classhints);                  XSetClassHint(g_display, g_wnd, classhints);
831                  XFree(classhints);                  XFree(classhints);
832          }          }
833    
# Line 670  ui_create_window(void) Line 835  ui_create_window(void)
835          if (sizehints)          if (sizehints)
836          {          {
837                  sizehints->flags = PMinSize | PMaxSize;                  sizehints->flags = PMinSize | PMaxSize;
838                  sizehints->min_width = sizehints->max_width = width;                  sizehints->min_width = sizehints->max_width = g_width;
839                  sizehints->min_height = sizehints->max_height = height;                  sizehints->min_height = sizehints->max_height = g_height;
840                  XSetWMNormalHints(display, wnd, sizehints);                  XSetWMNormalHints(g_display, g_wnd, sizehints);
841                  XFree(sizehints);                  XFree(sizehints);
842          }          }
843    
844          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
845                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
846    
847          if (sendmotion)          if (g_sendmotion)
848                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
849          if (ownbackstore)          if (g_ownbackstore)
850                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
851          if (fullscreen || grab_keyboard)          if (g_fullscreen || g_grab_keyboard)
852                  input_mask |= EnterWindowMask;                  input_mask |= EnterWindowMask;
853          if (grab_keyboard)          if (g_grab_keyboard)
854                  input_mask |= LeaveWindowMask;                  input_mask |= LeaveWindowMask;
855    
856          if (IM != NULL)          if (g_IM != NULL)
857          {          {
858                  IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),                  g_IC = XCreateIC(g_IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
859                                 XNClientWindow, wnd, XNFocusWindow, wnd, NULL);                                   XNClientWindow, g_wnd, XNFocusWindow, g_wnd, NULL);
860    
861                  if ((IC != NULL)                  if ((g_IC != NULL)
862                      && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))                      && (XGetICValues(g_IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))
863                          input_mask |= ic_input_mask;                          input_mask |= ic_input_mask;
864          }          }
865    
866          XSelectInput(display, wnd, input_mask);          XSelectInput(g_display, g_wnd, input_mask);
867          XMapWindow(display, wnd);          XMapWindow(g_display, g_wnd);
868    
869          /* wait for VisibilityNotify */          /* wait for VisibilityNotify */
870          do          do
871          {          {
872                  XMaskEvent(display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
873          }          }
874          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
875    
876          focused = False;          g_focused = False;
877          mouse_in_wnd = False;          g_mouse_in_wnd = False;
878    
879          /* handle the WM_DELETE_WINDOW protocol */          /* handle the WM_DELETE_WINDOW protocol */
880          protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);          g_protocol_atom = XInternAtom(g_display, "WM_PROTOCOLS", True);
881          kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
882          XSetWMProtocols(display, wnd, &kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
883    
884          return True;          return True;
885  }  }
# Line 722  ui_create_window(void) Line 887  ui_create_window(void)
887  void  void
888  ui_destroy_window(void)  ui_destroy_window(void)
889  {  {
890          if (IC != NULL)          if (g_IC != NULL)
891                  XDestroyIC(IC);                  XDestroyIC(g_IC);
892    
893          XDestroyWindow(display, wnd);          XDestroyWindow(g_display, g_wnd);
894  }  }
895    
896  void  void
# Line 733  xwin_toggle_fullscreen(void) Line 898  xwin_toggle_fullscreen(void)
898  {  {
899          Pixmap contents = 0;          Pixmap contents = 0;
900    
901          if (!ownbackstore)          if (!g_ownbackstore)
902          {          {
903                  /* need to save contents of window */                  /* need to save contents of window */
904                  contents = XCreatePixmap(display, wnd, width, height, depth);                  contents = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
905                  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);
906          }          }
907    
908          ui_destroy_window();          ui_destroy_window();
909          fullscreen = !fullscreen;          g_fullscreen = !g_fullscreen;
910          ui_create_window();          ui_create_window();
911    
912          XDefineCursor(display, wnd, current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
913    
914          if (!ownbackstore)          if (!g_ownbackstore)
915          {          {
916                  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);
917                  XFreePixmap(display, contents);                  XFreePixmap(g_display, contents);
918          }          }
919  }  }
920    
921  /* Process all events in Xlib queue  /* Process all events in Xlib queue
922     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
923  static int  static int
924  xwin_process_events(void)  xwin_process_events(void)
# Line 769  xwin_process_events(void) Line 934  xwin_process_events(void)
934          Window wdummy;          Window wdummy;
935          int dummy;          int dummy;
936    
937          while (XPending(display) > 0)          while (XPending(g_display) > 0)
938          {          {
939                  XNextEvent(display, &xevent);                  XNextEvent(g_display, &xevent);
940    
941                  if ((IC != NULL) && (XFilterEvent(&xevent, None) == True))                  if ((g_IC != NULL) && (XFilterEvent(&xevent, None) == True))
942                  {                  {
943                          DEBUG_KBD(("Filtering event\n"));                          DEBUG_KBD(("Filtering event\n"));
944                          continue;                          continue;
# Line 785  xwin_process_events(void) Line 950  xwin_process_events(void)
950                  {                  {
951                          case ClientMessage:                          case ClientMessage:
952                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
953                                  if ((xevent.xclient.message_type == protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
954                                      && (xevent.xclient.data.l[0] == kill_atom))                                      && ((Atom) xevent.xclient.data.l[0] == g_kill_atom))
955                                          /* Quit */                                          /* Quit */
956                                          return 0;                                          return 0;
957                                  break;                                  break;
958    
959                          case KeyPress:                          case KeyPress:
960                                  if (IC != NULL)                                  g_last_gesturetime = xevent.xkey.time;
961                                    if (g_IC != NULL)
962                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
963                                  {                                  {
964                                          XmbLookupString(IC,                                          XmbLookupString(g_IC,
965                                                          (XKeyPressedEvent *) &                                                          &xevent.xkey, str, sizeof(str), &keysym,
966                                                          xevent, str, sizeof(str), &keysym, &status);                                                          &status);
967                                          if (!((status == XLookupKeySym) || (status == XLookupBoth)))                                          if (!((status == XLookupKeySym) || (status == XLookupBoth)))
968                                          {                                          {
969                                                  error("XmbLookupString failed with status 0x%x\n",                                                  error("XmbLookupString failed with status 0x%x\n",
# Line 826  xwin_process_events(void) Line 992  xwin_process_events(void)
992                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
993                                          break;                                          break;
994    
995                                    save_remote_modifiers(tr.scancode);
996                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
   
997                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
998                                    restore_remote_modifiers(ev_time, tr.scancode);
999    
1000                                  break;                                  break;
1001    
1002                          case KeyRelease:                          case KeyRelease:
1003                                    g_last_gesturetime = xevent.xkey.time;
1004                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
1005                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
1006    
# Line 856  xwin_process_events(void) Line 1025  xwin_process_events(void)
1025                                  /* fall through */                                  /* fall through */
1026    
1027                          case ButtonRelease:                          case ButtonRelease:
1028                                    g_last_gesturetime = xevent.xbutton.time;
1029                                  button = xkeymap_translate_button(xevent.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
1030                                  if (button == 0)                                  if (button == 0)
1031                                          break;                                          break;
1032    
1033                                  /* If win_button_size is nonzero, enable single app mode */                                  /* If win_button_size is nonzero, enable single app mode */
1034                                  if (xevent.xbutton.y < win_button_size)                                  if (xevent.xbutton.y < g_win_button_size)
1035                                  {                                  {
1036                                          /* Stop moving window when button is released, regardless of cursor position */                                          /* Stop moving window when button is released, regardless of cursor position */
1037                                          if (moving_wnd && (xevent.type == ButtonRelease))                                          if (g_moving_wnd && (xevent.type == ButtonRelease))
1038                                                  moving_wnd = False;                                                  g_moving_wnd = False;
1039    
1040                                          /*  Check from right to left: */                                          /*  Check from right to left: */
1041    
1042                                          if (xevent.xbutton.x >= width - win_button_size)                                          if (xevent.xbutton.x >= g_width - g_win_button_size)
1043                                          {                                          {
1044                                                  /* The close button, continue */                                                  /* The close button, continue */
1045                                                  ;                                                  ;
1046                                          }                                          }
1047                                          else if (xevent.xbutton.x >= width - win_button_size * 2)                                          else if (xevent.xbutton.x >=
1048                                                     g_width - g_win_button_size * 2)
1049                                          {                                          {
1050                                                  /* The maximize/restore button. Do not send to                                                  /* The maximize/restore button. Do not send to
1051                                                     server.  It might be a good idea to change the                                                     server.  It might be a good idea to change the
1052                                                     cursor or give some other visible indication                                                     cursor or give some other visible indication
1053                                                     that rdesktop inhibited this click */                                                     that rdesktop inhibited this click */
1054                                                  break;                                                  break;
1055                                          }                                          }
1056                                          else if (xevent.xbutton.x >= width - win_button_size * 3)                                          else if (xevent.xbutton.x >=
1057                                                     g_width - g_win_button_size * 3)
1058                                          {                                          {
1059                                                  /* The minimize button. Iconify window. */                                                  /* The minimize button. Iconify window. */
1060                                                  XIconifyWindow(display, wnd,                                                  XIconifyWindow(g_display, g_wnd,
1061                                                                 DefaultScreen(display));                                                                 DefaultScreen(g_display));
1062                                                  break;                                                  break;
1063                                          }                                          }
1064                                          else if (xevent.xbutton.x <= win_button_size)                                          else if (xevent.xbutton.x <= g_win_button_size)
1065                                          {                                          {
1066                                                  /* The system menu. Ignore. */                                                  /* The system menu. Ignore. */
1067                                                  break;                                                  break;
# Line 897  xwin_process_events(void) Line 1069  xwin_process_events(void)
1069                                          else                                          else
1070                                          {                                          {
1071                                                  /* The title bar. */                                                  /* The title bar. */
1072                                                  if ((xevent.type == ButtonPress) && !fullscreen                                                  if ((xevent.type == ButtonPress) && !g_fullscreen
1073                                                      && hide_decorations)                                                      && g_hide_decorations)
1074                                                  {                                                  {
1075                                                          moving_wnd = True;                                                          g_moving_wnd = True;
1076                                                          move_x_offset = xevent.xbutton.x;                                                          g_move_x_offset = xevent.xbutton.x;
1077                                                          move_y_offset = xevent.xbutton.y;                                                          g_move_y_offset = xevent.xbutton.y;
1078                                                  }                                                  }
1079                                                  break;                                                  break;
1080    
# Line 914  xwin_process_events(void) Line 1086  xwin_process_events(void)
1086                                  break;                                  break;
1087    
1088                          case MotionNotify:                          case MotionNotify:
1089                                  if (moving_wnd)                                  if (g_moving_wnd)
1090                                  {                                  {
1091                                          XMoveWindow(display, wnd,                                          XMoveWindow(g_display, g_wnd,
1092                                                      xevent.xmotion.x_root - move_x_offset,                                                      xevent.xmotion.x_root - g_move_x_offset,
1093                                                      xevent.xmotion.y_root - move_y_offset);                                                      xevent.xmotion.y_root - g_move_y_offset);
1094                                          break;                                          break;
1095                                  }                                  }
1096    
1097                                  if (fullscreen && !focused)                                  if (g_fullscreen && !g_focused)
1098                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,
1099                                                         CurrentTime);                                                         CurrentTime);
1100                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
1101                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
# Line 932  xwin_process_events(void) Line 1104  xwin_process_events(void)
1104                          case FocusIn:                          case FocusIn:
1105                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1106                                          break;                                          break;
1107                                  focused = True;                                  g_focused = True;
1108                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy,                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,
1109                                                &dummy, &dummy, &state);                                                &dummy, &dummy, &state);
1110                                  reset_modifier_keys(state);                                  reset_modifier_keys(state);
1111                                  if (grab_keyboard && mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1112                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1113                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
1114                                  break;                                  break;
1115    
1116                          case FocusOut:                          case FocusOut:
1117                                  if (xevent.xfocus.mode == NotifyUngrab)                                  if (xevent.xfocus.mode == NotifyUngrab)
1118                                          break;                                          break;
1119                                  focused = False;                                  g_focused = False;
1120                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)
1121                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(g_display, CurrentTime);
1122                                  break;                                  break;
1123    
1124                          case EnterNotify:                          case EnterNotify:
1125                                  /* we only register for this event when in fullscreen mode */                                  /* we only register for this event when in fullscreen mode */
1126                                  /* or grab_keyboard */                                  /* or grab_keyboard */
1127                                  mouse_in_wnd = True;                                  g_mouse_in_wnd = True;
1128                                  if (fullscreen)                                  if (g_fullscreen)
1129                                  {                                  {
1130                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(g_display, g_wnd, RevertToPointerRoot,
1131                                                         CurrentTime);                                                         CurrentTime);
1132                                          break;                                          break;
1133                                  }                                  }
1134                                  if (focused)                                  if (g_focused)
1135                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1136                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
1137                                  break;                                  break;
1138    
1139                          case LeaveNotify:                          case LeaveNotify:
1140                                  /* we only register for this event when grab_keyboard */                                  /* we only register for this event when grab_keyboard */
1141                                  mouse_in_wnd = False;                                  g_mouse_in_wnd = False;
1142                                  XUngrabKeyboard(display, CurrentTime);                                  XUngrabKeyboard(g_display, CurrentTime);
1143                                  break;                                  break;
1144    
1145                          case Expose:                          case Expose:
1146                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(g_display, g_backstore, g_wnd, g_gc,
1147                                            xevent.xexpose.x, xevent.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
1148                                            xevent.xexpose.width,                                            xevent.xexpose.width,
1149                                            xevent.xexpose.height,                                            xevent.xexpose.height,
# Line 987  xwin_process_events(void) Line 1159  xwin_process_events(void)
1159    
1160                                  if (xevent.xmapping.request == MappingModifier)                                  if (xevent.xmapping.request == MappingModifier)
1161                                  {                                  {
1162                                          XFreeModifiermap(mod_map);                                          XFreeModifiermap(g_mod_map);
1163                                          mod_map = XGetModifierMapping(display);                                          g_mod_map = XGetModifierMapping(g_display);
1164                                  }                                  }
1165                                  break;                                  break;
1166    
1167                                    /* clipboard stuff */
1168                            case SelectionNotify:
1169                                    xclip_handle_SelectionNotify(&xevent.xselection);
1170                                    break;
1171                            case SelectionRequest:
1172                                    xclip_handle_SelectionRequest(&xevent.xselectionrequest);
1173                                    break;
1174                            case SelectionClear:
1175                                    xclip_handle_SelectionClear();
1176                                    break;
1177                            case PropertyNotify:
1178                                    xclip_handle_PropertyNotify(&xevent.xproperty);
1179                                    break;
1180                  }                  }
1181          }          }
1182          /* Keep going */          /* Keep going */
# Line 1002  xwin_process_events(void) Line 1187  xwin_process_events(void)
1187  int  int
1188  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1189  {  {
1190          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;
1191          fd_set rfds;          fd_set rfds, wfds;
   
         FD_ZERO(&rfds);  
1192    
1193          while (True)          while (True)
1194          {          {
# Line 1015  ui_select(int rdp_socket) Line 1198  ui_select(int rdp_socket)
1198                          return 0;                          return 0;
1199    
1200                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1201                    FD_ZERO(&wfds);
1202                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1203                  FD_SET(x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1204    
1205    #ifdef WITH_RDPSND
1206                    /* FIXME: there should be an API for registering fds */
1207                    if (g_dsp_busy)
1208                    {
1209                            FD_SET(g_dsp_fd, &wfds);
1210                            n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1211                    }
1212    #endif
1213    
1214                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, NULL))
1215                  {                  {
1216                          case -1:                          case -1:
1217                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
# Line 1029  ui_select(int rdp_socket) Line 1222  ui_select(int rdp_socket)
1222    
1223                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1224                          return 1;                          return 1;
1225    
1226    #ifdef WITH_RDPSND
1227                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1228                            wave_out_play();
1229    #endif
1230          }          }
1231  }  }
1232    
1233  void  void
1234  ui_move_pointer(int x, int y)  ui_move_pointer(int x, int y)
1235  {  {
1236          XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);          XWarpPointer(g_display, g_wnd, g_wnd, 0, 0, 0, 0, x, y);
1237  }  }
1238    
1239  HBITMAP  HBITMAP
# Line 1045  ui_create_bitmap(int width, int height, Line 1243  ui_create_bitmap(int width, int height,
1243          Pixmap bitmap;          Pixmap bitmap;
1244          uint8 *tdata;          uint8 *tdata;
1245    
1246          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1247          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1248          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1249                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);
1250    
1251          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1252    
1253          XFree(image);          XFree(image);
1254          if (!owncolmap)          if (!g_owncolmap)
1255                  xfree(tdata);                  xfree(tdata);
1256          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1257  }  }
# Line 1063  ui_paint_bitmap(int x, int y, int cx, in Line 1261  ui_paint_bitmap(int x, int y, int cx, in
1261  {  {
1262          XImage *image;          XImage *image;
1263          uint8 *tdata;          uint8 *tdata;
1264          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1265          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1266                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);
1267    
1268          if (ownbackstore)          if (g_ownbackstore)
1269          {          {
1270                  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);
1271                  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);
1272          }          }
1273          else          else
1274          {          {
1275                  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);
1276          }          }
1277    
1278          XFree(image);          XFree(image);
1279          if (!owncolmap)          if (!g_owncolmap)
1280                  xfree(tdata);                  xfree(tdata);
1281  }  }
1282    
1283  void  void
1284  ui_destroy_bitmap(HBITMAP bmp)  ui_destroy_bitmap(HBITMAP bmp)
1285  {  {
1286          XFreePixmap(display, (Pixmap) bmp);          XFreePixmap(g_display, (Pixmap) bmp);
1287  }  }
1288    
1289  HGLYPH  HGLYPH
# Line 1098  ui_create_glyph(int width, int height, u Line 1296  ui_create_glyph(int width, int height, u
1296    
1297          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1298    
1299          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);
1300          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(g_display, bitmap, 0, NULL);
1301    
1302          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,
1303                               width, height, 8, scanline);                               width, height, 8, scanline);
1304          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
1305          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
1306          XInitImage(image);          XInitImage(image);
1307    
1308          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, gc, image, 0, 0, 0, 0, width, height);
1309    
1310          XFree(image);          XFree(image);
1311          XFreeGC(display, gc);          XFreeGC(g_display, gc);
1312          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
1313  }  }
1314    
1315  void  void
1316  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(HGLYPH glyph)
1317  {  {
1318          XFreePixmap(display, (Pixmap) glyph);          XFreePixmap(g_display, (Pixmap) glyph);
1319  }  }
1320    
1321  HCURSOR  HCURSOR
# Line 1136  ui_create_cursor(unsigned int x, unsigne Line 1334  ui_create_cursor(unsigned int x, unsigne
1334          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1335          offset = scanline * height;          offset = scanline * height;
1336    
1337          cursor = xmalloc(offset);          cursor = (uint8 *) xmalloc(offset);
1338          memset(cursor, 0, offset);          memset(cursor, 0, offset);
1339    
1340          mask = xmalloc(offset);          mask = (uint8 *) xmalloc(offset);
1341          memset(mask, 0, offset);          memset(mask, 0, offset);
1342    
1343          /* approximate AND and XOR masks with a monochrome X pointer */          /* approximate AND and XOR masks with a monochrome X pointer */
# Line 1181  ui_create_cursor(unsigned int x, unsigne Line 1379  ui_create_cursor(unsigned int x, unsigne
1379          maskglyph = ui_create_glyph(width, height, mask);          maskglyph = ui_create_glyph(width, height, mask);
1380    
1381          xcursor =          xcursor =
1382                  XCreatePixmapCursor(display, (Pixmap) cursorglyph,                  XCreatePixmapCursor(g_display, (Pixmap) cursorglyph,
1383                                      (Pixmap) maskglyph, &fg, &bg, x, y);                                      (Pixmap) maskglyph, &fg, &bg, x, y);
1384    
1385          ui_destroy_glyph(maskglyph);          ui_destroy_glyph(maskglyph);
# Line 1194  ui_create_cursor(unsigned int x, unsigne Line 1392  ui_create_cursor(unsigned int x, unsigne
1392  void  void
1393  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(HCURSOR cursor)
1394  {  {
1395          current_cursor = (Cursor) cursor;          g_current_cursor = (Cursor) cursor;
1396          XDefineCursor(display, wnd, current_cursor);          XDefineCursor(g_display, g_wnd, g_current_cursor);
1397  }  }
1398    
1399  void  void
1400  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_cursor(HCURSOR cursor)
1401  {  {
1402          XFreeCursor(display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1403  }  }
1404    
1405  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
# Line 1216  ui_create_colourmap(COLOURMAP * colours) Line 1414  ui_create_colourmap(COLOURMAP * colours)
1414  {  {
1415          COLOURENTRY *entry;          COLOURENTRY *entry;
1416          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
1417          if (!owncolmap)          if (!g_owncolmap)
1418          {          {
1419                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);                  uint32 *map = (uint32 *) xmalloc(sizeof(*g_colmap) * ncolours);
1420                  XColor xentry;                  XColor xentry;
1421                  XColor xc_cache[256];                  XColor xc_cache[256];
1422                  uint32 colour;                  uint32 colour;
# Line 1228  ui_create_colourmap(COLOURMAP * colours) Line 1426  ui_create_colourmap(COLOURMAP * colours)
1426                          entry = &colours->colours[i];                          entry = &colours->colours[i];
1427                          MAKE_XCOLOR(&xentry, entry);                          MAKE_XCOLOR(&xentry, entry);
1428    
1429                          if (XAllocColor(display, xcolmap, &xentry) == 0)                          if (XAllocColor(g_display, g_xcolmap, &xentry) == 0)
1430                          {                          {
1431                                  /* Allocation failed, find closest match. */                                  /* Allocation failed, find closest match. */
1432                                  int j = 256;                                  int j = 256;
# Line 1242  ui_create_colourmap(COLOURMAP * colours) Line 1440  ui_create_colourmap(COLOURMAP * colours)
1440                                          xc_cache[colLookup].red = xc_cache[colLookup].green =                                          xc_cache[colLookup].red = xc_cache[colLookup].green =
1441                                                  xc_cache[colLookup].blue = 0;                                                  xc_cache[colLookup].blue = 0;
1442                                          xc_cache[colLookup].flags = 0;                                          xc_cache[colLookup].flags = 0;
1443                                          XQueryColor(display,                                          XQueryColor(g_display,
1444                                                      DefaultColormap(display,                                                      DefaultColormap(g_display,
1445                                                                      DefaultScreen(display)),                                                                      DefaultScreen(g_display)),
1446                                                      &xc_cache[colLookup]);                                                      &xc_cache[colLookup]);
1447                                  }                                  }
1448                                  colLookup = 0;                                  colLookup = 0;
# Line 1296  ui_create_colourmap(COLOURMAP * colours) Line 1494  ui_create_colourmap(COLOURMAP * colours)
1494                  XColor *xcolours, *xentry;                  XColor *xcolours, *xentry;
1495                  Colormap map;                  Colormap map;
1496    
1497                  xcolours = xmalloc(sizeof(XColor) * ncolours);                  xcolours = (XColor *) xmalloc(sizeof(XColor) * ncolours);
1498                  for (i = 0; i < ncolours; i++)                  for (i = 0; i < ncolours; i++)
1499                  {                  {
1500                          entry = &colours->colours[i];                          entry = &colours->colours[i];
# Line 1305  ui_create_colourmap(COLOURMAP * colours) Line 1503  ui_create_colourmap(COLOURMAP * colours)
1503                          MAKE_XCOLOR(xentry, entry);                          MAKE_XCOLOR(xentry, entry);
1504                  }                  }
1505    
1506                  map = XCreateColormap(display, wnd, visual, AllocAll);                  map = XCreateColormap(g_display, g_wnd, g_visual, AllocAll);
1507                  XStoreColors(display, map, xcolours, ncolours);                  XStoreColors(g_display, map, xcolours, ncolours);
1508    
1509                  xfree(xcolours);                  xfree(xcolours);
1510                  return (HCOLOURMAP) map;                  return (HCOLOURMAP) map;
# Line 1316  ui_create_colourmap(COLOURMAP * colours) Line 1514  ui_create_colourmap(COLOURMAP * colours)
1514  void  void
1515  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
1516  {  {
1517          if (!owncolmap)          if (!g_owncolmap)
1518                  xfree(map);                  xfree(map);
1519          else          else
1520                  XFreeColormap(display, (Colormap) map);                  XFreeColormap(g_display, (Colormap) map);
1521  }  }
1522    
1523  void  void
1524  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
1525  {  {
1526          if (!owncolmap)          if (!g_owncolmap)
1527                  colmap = map;          {
1528                    if (g_colmap)
1529                            xfree(g_colmap);
1530    
1531                    g_colmap = (uint32 *) map;
1532            }
1533          else          else
1534                  XSetWindowColormap(display, wnd, (Colormap) map);                  XSetWindowColormap(g_display, g_wnd, (Colormap) map);
1535  }  }
1536    
1537  void  void
# Line 1340  ui_set_clip(int x, int y, int cx, int cy Line 1543  ui_set_clip(int x, int y, int cx, int cy
1543          rect.y = y;          rect.y = y;
1544          rect.width = cx;          rect.width = cx;
1545          rect.height = cy;          rect.height = cy;
1546          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);          XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);
1547  }  }
1548    
1549  void  void
# Line 1350  ui_reset_clip(void) Line 1553  ui_reset_clip(void)
1553    
1554          rect.x = 0;          rect.x = 0;
1555          rect.y = 0;          rect.y = 0;
1556          rect.width = width;          rect.width = g_width;
1557          rect.height = height;          rect.height = g_height;
1558          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);          XSetClipRectangles(g_display, g_gc, 0, 0, &rect, 1, YXBanded);
1559  }  }
1560    
1561  void  void
1562  ui_bell(void)  ui_bell(void)
1563  {  {
1564          XBell(display, 0);          XBell(g_display, 0);
1565  }  }
1566    
1567  void  void
# Line 1370  ui_destblt(uint8 opcode, Line 1573  ui_destblt(uint8 opcode,
1573          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1574  }  }
1575    
1576    static uint8 hatch_patterns[] = {
1577            0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0 - bsHorizontal */
1578            0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 1 - bsVertical */
1579            0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, /* 2 - bsFDiagonal */
1580            0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, /* 3 - bsBDiagonal */
1581            0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, /* 4 - bsCross */
1582            0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81  /* 5 - bsDiagCross */
1583    };
1584    
1585  void  void
1586  ui_patblt(uint8 opcode,  ui_patblt(uint8 opcode,
1587            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
# Line 1387  ui_patblt(uint8 opcode, Line 1599  ui_patblt(uint8 opcode,
1599                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
1600                          break;                          break;
1601    
1602                    case 2: /* Hatch */
1603                            fill = (Pixmap) ui_create_glyph(8, 8,
1604                                                            hatch_patterns + brush->pattern[0] * 8);
1605                            SET_FOREGROUND(fgcolour);
1606                            SET_BACKGROUND(bgcolour);
1607                            XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1608                            XSetStipple(g_display, g_gc, fill);
1609                            XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1610                            FILL_RECTANGLE(x, y, cx, cy);
1611                            XSetFillStyle(g_display, g_gc, FillSolid);
1612                            XSetTSOrigin(g_display, g_gc, 0, 0);
1613                            ui_destroy_glyph((HGLYPH) fill);
1614                            break;
1615    
1616                  case 3: /* Pattern */                  case 3: /* Pattern */
1617                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1618                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
# Line 1394  ui_patblt(uint8 opcode, Line 1620  ui_patblt(uint8 opcode,
1620    
1621                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1622                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1623                          XSetFillStyle(display, gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1624                          XSetStipple(display, gc, fill);                          XSetStipple(g_display, g_gc, fill);
1625                          XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1626    
1627                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
1628    
1629                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1630                          XSetTSOrigin(display, gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1631                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
1632                          break;                          break;
1633    
# Line 1418  ui_screenblt(uint8 opcode, Line 1644  ui_screenblt(uint8 opcode,
1644               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1645  {  {
1646          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1647          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);
1648          if (ownbackstore)          if (g_ownbackstore)
1649                  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);
1650          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1651  }  }
1652    
# Line 1430  ui_memblt(uint8 opcode, Line 1656  ui_memblt(uint8 opcode,
1656            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
1657  {  {
1658          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1659          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);
1660          if (ownbackstore)          if (g_ownbackstore)
1661                  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);
1662          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1663  }  }
1664    
# Line 1476  ui_line(uint8 opcode, Line 1702  ui_line(uint8 opcode,
1702  {  {
1703          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1704          SET_FOREGROUND(pen->colour);          SET_FOREGROUND(pen->colour);
1705          XDrawLine(display, wnd, gc, startx, starty, endx, endy);          XDrawLine(g_display, g_wnd, g_gc, startx, starty, endx, endy);
1706          if (ownbackstore)          if (g_ownbackstore)
1707                  XDrawLine(display, backstore, gc, startx, starty, endx, endy);                  XDrawLine(g_display, g_backstore, g_gc, startx, starty, endx, endy);
1708          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1709  }  }
1710    
# Line 1501  ui_draw_glyph(int mixmode, Line 1727  ui_draw_glyph(int mixmode,
1727          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
1728          SET_BACKGROUND(bgcolour);          SET_BACKGROUND(bgcolour);
1729    
1730          XSetFillStyle(display, gc,          XSetFillStyle(g_display, g_gc,
1731                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1732          XSetStipple(display, gc, (Pixmap) glyph);          XSetStipple(g_display, g_gc, (Pixmap) glyph);
1733          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(g_display, g_gc, x, y);
1734    
1735          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1736    
1737          XSetFillStyle(display, gc, FillSolid);          XSetFillStyle(g_display, g_gc, FillSolid);
1738  }  }
1739    
1740  #define DO_GLYPH(ttext,idx) \  #define DO_GLYPH(ttext,idx) \
# Line 1615  ui_draw_text(uint8 font, uint8 flags, in Line 1841  ui_draw_text(uint8 font, uint8 flags, in
1841                                  break;                                  break;
1842                  }                  }
1843          }          }
1844          if (ownbackstore)          if (g_ownbackstore)
1845          {          {
1846                  if (boxcx > 1)                  if (boxcx > 1)
1847                          XCopyArea(display, backstore, wnd, gc, boxx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, boxx,
1848                                    boxy, boxcx, boxcy, boxx, boxy);                                    boxy, boxcx, boxcy, boxx, boxy);
1849                  else                  else
1850                          XCopyArea(display, backstore, wnd, gc, clipx,                          XCopyArea(g_display, g_backstore, g_wnd, g_gc, clipx,
1851                                    clipy, clipcx, clipcy, clipx, clipy);                                    clipy, clipcx, clipcy, clipx, clipy);
1852          }          }
1853  }  }
# Line 1632  ui_desktop_save(uint32 offset, int x, in Line 1858  ui_desktop_save(uint32 offset, int x, in
1858          Pixmap pix;          Pixmap pix;
1859          XImage *image;          XImage *image;
1860    
1861          if (ownbackstore)          if (g_ownbackstore)
1862          {          {
1863                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, g_backstore, x, y, cx, cy, AllPlanes, ZPixmap);
1864          }          }
1865          else          else
1866          {          {
1867                  pix = XCreatePixmap(display, wnd, cx, cy, depth);                  pix = XCreatePixmap(g_display, g_wnd, cx, cy, g_depth);
1868                  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);
1869                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);                  image = XGetImage(g_display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
1870                  XFreePixmap(display, pix);                  XFreePixmap(g_display, pix);
1871          }          }
1872    
1873          offset *= bpp / 8;          offset *= g_bpp / 8;
1874          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);
1875    
1876          XDestroyImage(image);          XDestroyImage(image);
1877  }  }
# Line 1656  ui_desktop_restore(uint32 offset, int x, Line 1882  ui_desktop_restore(uint32 offset, int x,
1882          XImage *image;          XImage *image;
1883          uint8 *data;          uint8 *data;
1884    
1885          offset *= bpp / 8;          offset *= g_bpp / 8;
1886          data = cache_get_desktop(offset, cx, cy, bpp / 8);          data = cache_get_desktop(offset, cx, cy, g_bpp / 8);
1887          if (data == NULL)          if (data == NULL)
1888                  return;                  return;
1889    
1890          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1891                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);                               (char *) data, cx, cy, BitmapPad(g_display), cx * g_bpp / 8);
1892    
1893          if (ownbackstore)          if (g_ownbackstore)
1894          {          {
1895                  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);
1896                  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);
1897          }          }
1898          else          else
1899          {          {
1900                  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);
1901          }          }
1902    
1903          XFree(image);          XFree(image);

Legend:
Removed from v.342  
changed lines
  Added in v.504

  ViewVC Help
Powered by ViewVC 1.1.26