/[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 461 by astrand, Tue Sep 2 09:40:07 2003 UTC revision 643 by jsorg71, Wed Mar 24 18:16:58 2004 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
23    #include <unistd.h>
24    #include <sys/time.h>
25  #include <time.h>  #include <time.h>
26  #include <errno.h>  #include <errno.h>
27    #include <strings.h>
28  #include "rdesktop.h"  #include "rdesktop.h"
29  #include "xproto.h"  #include "xproto.h"
30    
# Line 34  extern BOOL g_hide_decorations; Line 37  extern BOOL g_hide_decorations;
37  extern char g_title[];  extern char g_title[];
38  extern int g_server_bpp;  extern int g_server_bpp;
39  extern int g_win_button_size;  extern int g_win_button_size;
 BOOL g_enable_compose = False;  
 BOOL g_focused;  
 BOOL g_mouse_in_wnd;  
40    
41  Display *g_display;  Display *g_display;
42  Time g_last_gesturetime;  Time g_last_gesturetime;
43  static int g_x_socket;  static int g_x_socket;
44  static Screen *g_screen;  static Screen *g_screen;
45  Window g_wnd;  Window g_wnd;
46  static GC g_gc;  uint32 g_embed_wnd;
47    BOOL g_enable_compose = False;
48    static GC g_gc = NULL;
49  static Visual *g_visual;  static Visual *g_visual;
50  static int g_depth;  static int g_depth;
51  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 53  static XIM g_IM;
53  static XIC g_IC;  static XIC g_IC;
54  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
55  static Cursor g_current_cursor;  static Cursor g_current_cursor;
56    static HCURSOR g_null_cursor = NULL;
57  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
58    static BOOL g_focused;
59    static BOOL g_mouse_in_wnd;
60    
61  /* endianness */  /* endianness */
62  static BOOL g_host_be;  static BOOL g_host_be;
63  static BOOL g_xserver_be;  static BOOL g_xserver_be;
64    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
65    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
66    
67  /* software backing store */  /* software backing store */
68  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
69  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
70    
71  /* Moving in single app mode */  /* Moving in single app mode */
72  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
73  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
74  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
75    
76    #ifdef WITH_RDPSND
77    extern int g_dsp_fd;
78    extern BOOL g_dsp_busy;
79    extern BOOL g_rdpsnd;
80    #endif
81    
82  /* MWM decorations */  /* MWM decorations */
83  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
84  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 105  BOOL g_owncolmap = False; Line 118  BOOL g_owncolmap = False;
118  static Colormap g_xcolmap;  static Colormap g_xcolmap;
119  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
120    
121  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) )  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
122  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
123  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
124    
# Line 157  static PixelColour Line 170  static PixelColour
170  split_colour15(uint32 colour)  split_colour15(uint32 colour)
171  {  {
172          PixelColour rv;          PixelColour rv;
173          rv.red = (colour & 0x7c00) >> 10;          rv.red = (colour & 0x7c00) >> 7;
174          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x03e0) >> 2;
175          rv.green = (colour & 0x03e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
176          return rv;          return rv;
177  }  }
178    
# Line 170  static PixelColour Line 180  static PixelColour
180  split_colour16(uint32 colour)  split_colour16(uint32 colour)
181  {  {
182          PixelColour rv;          PixelColour rv;
183          rv.red = (colour & 0xf800) >> 11;          rv.red = (colour & 0xf800) >> 8;
184          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = (colour & 0x07e0) >> 3;
185          rv.green = (colour & 0x07e0) >> 5;          rv.blue = (colour & 0x001f) << 3;
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
186          return rv;          return rv;
187  }  }
188    
# Line 184  split_colour24(uint32 colour) Line 191  split_colour24(uint32 colour)
191  {  {
192          PixelColour rv;          PixelColour rv;
193          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
194          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
195          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
196          return rv;          return rv;
197  }  }
198    
199  static uint32  static uint32
200  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
 {  
         pc.red = (pc.red * 0x1f) / 0xff;  
         pc.green = (pc.green * 0x3f) / 0xff;  
         pc.blue = (pc.blue * 0x1f) / 0xff;  
         return (pc.red << 11) | (pc.green << 5) | pc.blue;  
 }  
   
 static uint32  
 make_colour24(PixelColour pc)  
201  {  {
202          return (pc.red << 16) | (pc.green << 8) | pc.blue;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
203  }                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
204                    | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
 static uint32  
 make_colour32(PixelColour pc)  
 {  
         return (pc.red << 16) | (pc.green << 8) | pc.blue;  
205  }  }
206    
207  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
208  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
209  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
210                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
211    
212  static uint32  static uint32
213  translate_colour(uint32 colour)  translate_colour(uint32 colour)
214  {  {
215            PixelColour pc;
216          switch (g_server_bpp)          switch (g_server_bpp)
217          {          {
218                  case 15:                  case 15:
219                          switch (g_bpp)                          pc = split_colour15(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour15(colour));  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour15(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour15(colour));  
                                         break;  
                         }  
220                          break;                          break;
221                  case 16:                  case 16:
222                          switch (g_bpp)                          pc = split_colour16(colour);
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
223                          break;                          break;
224                  case 24:                  case 24:
225                          switch (g_bpp)                          pc = split_colour24(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
226                          break;                          break;
227          }          }
228          switch (g_bpp)          return make_colour(pc);
         {  
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
                         break;  
   
                 case 24:  
                         if (g_xserver_be)  
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP32(colour);  
                         break;  
         }  
   
         return colour;  
229  }  }
230    
231  static void  static void
# Line 290  translate8to8(uint8 * data, uint8 * out, Line 236  translate8to8(uint8 * data, uint8 * out,
236  }  }
237    
238  static void  static void
239  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
240  {  {
241          while (out < end)          uint16 value;
242                  *(out++) = (uint16) g_colmap[*(data++)];  
243            if (g_xserver_be)
244            {
245                    while (out < end)
246                    {
247                            value = (uint16) g_colmap[*(data++)];
248                            *(out++) = value >> 8;
249                            *(out++) = value;
250                    }
251            }
252            else
253            {
254                    while (out < end)
255                    {
256                            value = (uint16) g_colmap[*(data++)];
257                            *(out++) = value;
258                            *(out++) = value >> 8;
259                    }
260            }
261  }  }
262    
263  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 302  translate8to24(uint8 * data, uint8 * out Line 266  translate8to24(uint8 * data, uint8 * out
266  {  {
267          uint32 value;          uint32 value;
268    
269          while (out < end)          if (g_xserver_be)
270          {          {
271                  value = g_colmap[*(data++)];                  while (out < end)
272                  *(out++) = value;                  {
273                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
274                  *(out++) = value >> 16;                          *(out++) = value >> 16;
275                            *(out++) = value >> 8;
276                            *(out++) = value;
277                    }
278            }
279            else
280            {
281                    while (out < end)
282                    {
283                            value = g_colmap[*(data++)];
284                            *(out++) = value;
285                            *(out++) = value >> 8;
286                            *(out++) = value >> 16;
287                    }
288          }          }
289  }  }
290    
291  static void  static void
292  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
293  {  {
294          while (out < end)          uint32 value;
                 *(out++) = g_colmap[*(data++)];  
 }  
295    
296  /* todo the remaining translate function might need some big endian check ?? */          if (g_xserver_be)
297            {
298                    while (out < end)
299                    {
300                            value = g_colmap[*(data++)];
301                            *(out++) = value >> 24;
302                            *(out++) = value >> 16;
303                            *(out++) = value >> 8;
304                            *(out++) = value;
305                    }
306            }
307            else
308            {
309                    while (out < end)
310                    {
311                            value = g_colmap[*(data++)];
312                            *(out++) = value;
313                            *(out++) = value >> 8;
314                            *(out++) = value >> 16;
315                            *(out++) = value >> 24;
316                    }
317            }
318    }
319    
320  static void  static void
321  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
322  {  {
323            uint16 pixel;
324            uint16 value;
325    
326          while (out < end)          while (out < end)
327                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
328                    pixel = *(data++);
329    
330                    if (g_host_be)
331                    {
332                            BSWAP16(pixel);
333                    }
334    
335                    value = make_colour(split_colour15(pixel));
336    
337                    if (g_xserver_be)
338                    {
339                            *(out++) = value >> 8;
340                            *(out++) = value;
341                    }
342                    else
343                    {
344                            *(out++) = value;
345                            *(out++) = value >> 8;
346                    }
347            }
348  }  }
349    
350  static void  static void
351  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
352  {  {
353          uint32 value;          uint32 value;
354            uint16 pixel;
355    
356          while (out < end)          while (out < end)
357          {          {
358                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
359                  *(out++) = value;  
360                  *(out++) = value >> 8;                  if (g_host_be)
361                  *(out++) = value >> 16;                  {
362                            BSWAP16(pixel);
363                    }
364    
365                    value = make_colour(split_colour15(pixel));
366                    if (g_xserver_be)
367                    {
368                            *(out++) = value >> 16;
369                            *(out++) = value >> 8;
370                            *(out++) = value;
371                    }
372                    else
373                    {
374                            *(out++) = value;
375                            *(out++) = value >> 8;
376                            *(out++) = value >> 16;
377                    }
378          }          }
379  }  }
380    
381  static void  static void
382  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
383  {  {
384            uint16 pixel;
385            uint32 value;
386    
387          while (out < end)          while (out < end)
388                  *(out++) = make_colour32(split_colour15(*(data++)));          {
389                    pixel = *(data++);
390    
391                    if (g_host_be)
392                    {
393                            BSWAP16(pixel);
394                    }
395    
396                    value = make_colour(split_colour15(pixel));
397    
398                    if (g_xserver_be)
399                    {
400                            *(out++) = value >> 24;
401                            *(out++) = value >> 16;
402                            *(out++) = value >> 8;
403                            *(out++) = value;
404                    }
405                    else
406                    {
407                            *(out++) = value;
408                            *(out++) = value >> 8;
409                            *(out++) = value >> 16;
410                            *(out++) = value >> 24;
411                    }
412            }
413  }  }
414    
415  static void  static void
416  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
417  {  {
418            uint16 pixel;
419            uint16 value;
420    
421          while (out < end)          while (out < end)
422                  *(out++) = (uint16) (*(data++));          {
423  }                  pixel = *(data++);
424    
425                    if (g_host_be)
426                    {
427                            BSWAP16(pixel);
428                    }
429    
430                    value = make_colour(split_colour16(pixel));
431    
432                    if (g_xserver_be)
433                    {
434                            *(out++) = value >> 8;
435                            *(out++) = value;
436                    }
437                    else
438                    {
439                            *(out++) = value;
440                            *(out++) = value >> 8;
441                    }
442            }
443    }
444    
445  static void  static void
446  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
447  {  {
448          uint32 value;          uint32 value;
449            uint16 pixel;
450    
451          while (out < end)          while (out < end)
452          {          {
453                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
454                  *(out++) = value;  
455                  *(out++) = value >> 8;                  if (g_host_be)
456                  *(out++) = value >> 16;                  {
457                            BSWAP16(pixel);
458                    }
459    
460                    value = make_colour(split_colour16(pixel));
461    
462                    if (g_xserver_be)
463                    {
464                            *(out++) = value >> 16;
465                            *(out++) = value >> 8;
466                            *(out++) = value;
467                    }
468                    else
469                    {
470                            *(out++) = value;
471                            *(out++) = value >> 8;
472                            *(out++) = value >> 16;
473                    }
474          }          }
475  }  }
476    
477  static void  static void
478  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
479  {  {
480            uint16 pixel;
481            uint32 value;
482    
483          while (out < end)          while (out < end)
484                  *(out++) = make_colour32(split_colour16(*(data++)));          {
485                    pixel = *(data++);
486    
487                    if (g_host_be)
488                    {
489                            BSWAP16(pixel);
490                    }
491    
492                    value = make_colour(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_colour(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    
537  static void  static void
538  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
539  {  {
540            uint32 pixel;
541            uint32 value;
542    
543          while (out < end)          while (out < end)
544          {          {
545                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
546                    pixel |= *(data++) << 8;
547                    pixel |= *(data++);
548    
549                    value = make_colour(split_colour24(pixel));
550    
551                    if (g_xserver_be)
552                    {
553                            *(out++) = value >> 16;
554                            *(out++) = value >> 8;
555                            *(out++) = value;
556                    }
557                    else
558                    {
559                            *(out++) = value;
560                            *(out++) = value >> 8;
561                            *(out++) = value >> 16;
562                    }
563          }          }
564  }  }
565    
566  static void  static void
567  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
568  {  {
569          uint32 pixel = 0;          uint32 pixel;
570            uint32 value;
571    
572          while (out < end)          while (out < end)
573          {          {
574                  pixel = *(data++);                  pixel = *(data++) << 16;
575                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
576                  pixel |= *(data++) << 16;                  pixel |= *(data++);
577                  *(out++) = pixel;  
578                    value = make_colour(split_colour24(pixel));
579    
580                    if (g_xserver_be)
581                    {
582                            *(out++) = value >> 24;
583                            *(out++) = value >> 16;
584                            *(out++) = value >> 8;
585                            *(out++) = value;
586                    }
587                    else
588                    {
589                            *(out++) = value;
590                            *(out++) = value >> 8;
591                            *(out++) = value >> 16;
592                            *(out++) = value >> 24;
593                    }
594          }          }
595  }  }
596    
# Line 425  translate_image(int width, int height, u Line 607  translate_image(int width, int height, u
607                          switch (g_bpp)                          switch (g_bpp)
608                          {                          {
609                                  case 32:                                  case 32:
610                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
611                                          break;                                          break;
612                                  case 24:                                  case 24:
613                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
614                                          break;                                          break;
615                                  case 16:                                  case 16:
616                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
617                                          break;                                          break;
618                          }                          }
619                          break;                          break;
# Line 439  translate_image(int width, int height, u Line 621  translate_image(int width, int height, u
621                          switch (g_bpp)                          switch (g_bpp)
622                          {                          {
623                                  case 32:                                  case 32:
624                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
625                                          break;                                          break;
626                                  case 24:                                  case 24:
627                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
628                                          break;                                          break;
629                                  case 16:                                  case 16:
630                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
631                                          break;                                          break;
632                          }                          }
633                          break;                          break;
# Line 455  translate_image(int width, int height, u Line 635  translate_image(int width, int height, u
635                          switch (g_bpp)                          switch (g_bpp)
636                          {                          {
637                                  case 32:                                  case 32:
638                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
639                                          break;                                          break;
640                                  case 24:                                  case 24:
641                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
642                                          break;                                          break;
643                                  case 16:                                  case 16:
644                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
645                                          break;                                          break;
646                          }                          }
647                          break;                          break;
# Line 474  translate_image(int width, int height, u Line 652  translate_image(int width, int height, u
652                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
653                                          break;                                          break;
654                                  case 16:                                  case 16:
655                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
656                                          break;                                          break;
657                                  case 24:                                  case 24:
658                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
659                                          break;                                          break;
660                                  case 32:                                  case 32:
661                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
662                                          break;                                          break;
663                          }                          }
664                          break;                          break;
# Line 513  get_key_state(unsigned int state, uint32 Line 691  get_key_state(unsigned int state, uint32
691          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
692  }  }
693    
694    static void
695    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
696    {
697            *shift_l = ffs(mask) - 1;
698            mask >>= *shift_l;
699            *shift_r = 8 - ffs(mask & ~(mask >> 1));
700    }
701    
702  BOOL  BOOL
703  ui_init(void)  ui_init(void)
704  {  {
705            XVisualInfo vi;
706          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
707          uint16 test;          uint16 test;
708          int i;          int i, screen_num, nvisuals;
709            XVisualInfo *vmatches = NULL;
710            XVisualInfo template;
711            Bool TrueColorVisual = False;
712    
713          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
714          if (g_display == NULL)          if (g_display == NULL)
# Line 527  ui_init(void) Line 717  ui_init(void)
717                  return False;                  return False;
718          }          }
719    
720            screen_num = DefaultScreen(g_display);
721          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
722          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
723          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
724    
725            /* Search for best TrueColor depth */
726            template.class = TrueColor;
727            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
728    
729            nvisuals--;
730            while (nvisuals >= 0)
731            {
732                    if ((vmatches + nvisuals)->depth > g_depth)
733                    {
734                            g_depth = (vmatches + nvisuals)->depth;
735                    }
736                    nvisuals--;
737                    TrueColorVisual = True;
738            }
739    
740            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
741            {
742                    /* we use a colourmap, so the default visual should do */
743                    g_visual = DefaultVisualOfScreen(g_screen);
744                    g_depth = DefaultDepthOfScreen(g_screen);
745    
746                    /* Do not allocate colours on a TrueColor visual */
747                    if (g_visual->class == TrueColor)
748                    {
749                            g_owncolmap = False;
750                    }
751            }
752            else
753            {
754                    /* need a truecolour visual */
755                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
756                    {
757                            error("The display does not support true colour - high colour support unavailable.\n");
758                            return False;
759                    }
760    
761                    g_visual = vi.visual;
762                    g_owncolmap = False;
763                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
764                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
765                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
766            }
767    
768          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
769          if (pfm != NULL)          if (pfm != NULL)
770          {          {
# Line 554  ui_init(void) Line 787  ui_init(void)
787                  return False;                  return False;
788          }          }
789    
790          if (g_owncolmap != True)          if (!g_owncolmap)
791          {          {
792                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
793                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
794                                            AllocNone);
795                  if (g_depth <= 8)                  if (g_depth <= 8)
796                          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");
797          }          }
798    
799          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
800            {
801          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
802                  g_ownbackstore = True;                  g_ownbackstore = True;
803            }
804    
805          test = 1;          test = 1;
806          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
807          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
808    
809          if ((g_width == 0) || (g_height == 0))          /*
810             * Determine desktop size
811             */
812            if (g_fullscreen)
813            {
814                    g_width = WidthOfScreen(g_screen);
815                    g_height = HeightOfScreen(g_screen);
816            }
817            else if (g_width < 0)
818            {
819                    /* Percent of screen */
820                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
821                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
822            }
823            else if (g_width == 0)
824          {          {
825                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
826                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 588  ui_init(void) Line 838  ui_init(void)
838                  }                  }
839          }          }
840    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
841          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
842          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
843    
         if (g_ownbackstore)  
         {  
                 g_backstore =  
                         XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height,  
                                       g_depth);  
   
                 /* clear to prevent rubbish being exposed at startup */  
                 XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));  
                 XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);  
         }  
   
844          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
845    
846            xkeymap_init();
847    
848          if (g_enable_compose)          if (g_enable_compose)
849                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
850    
         xkeymap_init();  
851          xclip_init();          xclip_init();
852    
853          /* todo take this out when high colour is done */          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));
         printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth);  
854    
855          return True;          return True;
856  }  }
# Line 628  ui_deinit(void) Line 861  ui_deinit(void)
861          if (g_IM != NULL)          if (g_IM != NULL)
862                  XCloseIM(g_IM);                  XCloseIM(g_IM);
863    
864            if (g_null_cursor != NULL)
865                    ui_destroy_cursor(g_null_cursor);
866    
867          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
868    
869          if (g_ownbackstore)          if (g_ownbackstore)
# Line 641  ui_deinit(void) Line 877  ui_deinit(void)
877  BOOL  BOOL
878  ui_create_window(void)  ui_create_window(void)
879  {  {
880            uint8 null_pointer_mask[1] = { 0x80 };
881            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
882          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
883          XClassHint *classhints;          XClassHint *classhints;
884          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 652  ui_create_window(void) Line 890  ui_create_window(void)
890          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
891    
892          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
893            attribs.border_pixel = WhitePixelOfScreen(g_screen);
894          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
895          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
896            attribs.colormap = g_xcolmap;
897    
898          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
899                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
900                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
901                                  CWColormap | CWBorderPixel, &attribs);
902    
903            if (g_gc == NULL)
904                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
905    
906            if ((g_ownbackstore) && (g_backstore == 0))
907            {
908                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
909    
910                    /* clear to prevent rubbish being exposed at startup */
911                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
912                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
913            }
914    
915          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
916    
# Line 682  ui_create_window(void) Line 935  ui_create_window(void)
935                  XFree(sizehints);                  XFree(sizehints);
936          }          }
937    
938            if ( g_embed_wnd )
939            {
940                    XReparentWindow(g_display, g_wnd, (Window)g_embed_wnd, 0, 0);
941            }
942    
943          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
944                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
945    
# Line 722  ui_create_window(void) Line 980  ui_create_window(void)
980          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
981          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
982    
983            /* create invisible 1x1 cursor to be used as null cursor */
984            if (g_null_cursor == NULL)
985                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
986    
987          return True;          return True;
988  }  }
989    
# Line 771  xwin_process_events(void) Line 1033  xwin_process_events(void)
1033          key_translation tr;          key_translation tr;
1034          char str[256];          char str[256];
1035          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1036    
1037          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1038          {          {
# Line 833  xwin_process_events(void) Line 1092  xwin_process_events(void)
1092                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1093                                          break;                                          break;
1094    
1095                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
1096                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
1097                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1098                                  restore_remote_modifiers(ev_time);                                  restore_remote_modifiers(ev_time, tr.scancode);
1099    
1100                                  break;                                  break;
1101    
# Line 946  xwin_process_events(void) Line 1205  xwin_process_events(void)
1205                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1206                                          break;                                          break;
1207                                  g_focused = True;                                  g_focused = True;
1208                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1209                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1210                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1211                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1028  xwin_process_events(void) Line 1285  xwin_process_events(void)
1285  int  int
1286  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1287  {  {
1288          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1289          fd_set rfds;          fd_set rfds, wfds;
1290            struct timeval tv;
1291          FD_ZERO(&rfds);          BOOL s_timeout = False;
1292    
1293          while (True)          while (True)
1294          {          {
1295                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1296                  /* Process any events already waiting */                  /* Process any events already waiting */
1297                  if (!xwin_process_events())                  if (!xwin_process_events())
1298                          /* User quit */                          /* User quit */
1299                          return 0;                          return 0;
1300    
1301                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1302                    FD_ZERO(&wfds);
1303                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1304                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1305    
1306                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1307                    /* FIXME: there should be an API for registering fds */
1308                    if (g_dsp_busy)
1309                    {
1310                            FD_SET(g_dsp_fd, &wfds);
1311                            n = (g_dsp_fd > n) ? g_dsp_fd : n;
1312                    }
1313    #endif
1314                    /* default timeout */
1315                    tv.tv_sec = 60;
1316                    tv.tv_usec = 0;
1317    
1318                    /* add redirection handles */
1319                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1320    
1321                    n++;
1322    
1323                    switch (select(n, &rfds, &wfds, NULL, &tv))
1324                  {                  {
1325                          case -1:                          case -1:
1326                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1327    
1328                          case 0:                          case 0:
1329                                    /* TODO: if tv.tv_sec just times out
1330                                     * we will segfault.
1331                                     * FIXME:
1332                                     */
1333                                    //s_timeout = True;
1334                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1335                                  continue;                                  continue;
1336                  }                  }
1337    
1338                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1339    
1340                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1341                          return 1;                          return 1;
1342    
1343    #ifdef WITH_RDPSND
1344                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1345                            wave_out_play();
1346    #endif
1347          }          }
1348  }  }
1349    
# Line 1070  ui_create_bitmap(int width, int height, Line 1359  ui_create_bitmap(int width, int height,
1359          XImage *image;          XImage *image;
1360          Pixmap bitmap;          Pixmap bitmap;
1361          uint8 *tdata;          uint8 *tdata;
1362            int bitmap_pad;
1363    
1364            if (g_server_bpp == 8)
1365            {
1366                    bitmap_pad = 8;
1367            }
1368            else
1369            {
1370                    bitmap_pad = g_bpp;
1371    
1372                    if (g_bpp == 24)
1373                            bitmap_pad = 32;
1374            }
1375    
1376          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1377          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1378          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1379                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1380    
1381          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1382    
# Line 1089  ui_paint_bitmap(int x, int y, int cx, in Line 1391  ui_paint_bitmap(int x, int y, int cx, in
1391  {  {
1392          XImage *image;          XImage *image;
1393          uint8 *tdata;          uint8 *tdata;
1394            int bitmap_pad;
1395    
1396            if (g_server_bpp == 8)
1397            {
1398                    bitmap_pad = 8;
1399            }
1400            else
1401            {
1402                    bitmap_pad = g_bpp;
1403    
1404                    if (g_bpp == 24)
1405                            bitmap_pad = 32;
1406            }
1407    
1408          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1409          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1410                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1411    
1412          if (g_ownbackstore)          if (g_ownbackstore)
1413          {          {
# Line 1230  ui_destroy_cursor(HCURSOR cursor) Line 1546  ui_destroy_cursor(HCURSOR cursor)
1546          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1547  }  }
1548    
1549    void
1550    ui_set_null_cursor(void)
1551    {
1552            ui_set_cursor(g_null_cursor);
1553    }
1554    
1555  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1556                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1557                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1311  ui_create_colourmap(COLOURMAP * colours) Line 1633  ui_create_colourmap(COLOURMAP * colours)
1633    
1634                          }                          }
1635    
1636                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1637                  }                  }
1638                  return map;                  return map;
1639          }          }
# Line 1430  ui_patblt(uint8 opcode, Line 1750  ui_patblt(uint8 opcode,
1750                  case 2: /* Hatch */                  case 2: /* Hatch */
1751                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1752                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1753                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1754                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1755                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1756                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1757                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
# Line 1472  ui_screenblt(uint8 opcode, Line 1792  ui_screenblt(uint8 opcode,
1792               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1793  {  {
1794          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1795          if (g_ownbackstore)          if (g_ownbackstore)
1796            {
1797                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1798                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1799            }
1800            else
1801            {
1802                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1803            }
1804          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1805  }  }
1806    
# Line 1569  ui_draw_glyph(int mixmode, Line 1895  ui_draw_glyph(int mixmode,
1895  {\  {\
1896    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1897    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1898      {\
1899        xyoffset = ttext[++idx];\
1900        if ((xyoffset & 0x80))\
1901      {\      {\
1902        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1903        if ((xyoffset & 0x80))\          y += ttext[idx+1] | (ttext[idx+2] << 8);\
         {\  
           if (flags & TEXT2_VERTICAL) \  
             y += ttext[idx+1] | (ttext[idx+2] << 8);\  
           else\  
             x += ttext[idx+1] | (ttext[idx+2] << 8);\  
           idx += 2;\  
         }\  
1904        else\        else\
1905          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1906            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1907      }\      }\
1908    if (glyph != NULL)\      else\
1909      {\      {\
1910        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1911                       y + glyph->baseline,\          y += xyoffset;\
1912                       glyph->width, glyph->height,\        else\
1913                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1914      }\      }\
1915      }\
1916      if (glyph != NULL)\
1917      {\
1918        x1 = x + glyph->offset;\
1919        y1 = y + glyph->baseline;\
1920        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1921        XSetTSOrigin(g_display, g_gc, x1, y1);\
1922        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1923        if (flags & TEXT2_IMPLICIT_X)\
1924          x += glyph->width;\
1925      }\
1926  }  }
1927    
1928  void  void
# Line 1605  ui_draw_text(uint8 font, uint8 flags, in Line 1932  ui_draw_text(uint8 font, uint8 flags, in
1932               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1933  {  {
1934          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1935          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1936          DATABLOB *entry;          DATABLOB *entry;
1937    
1938          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
1939    
1940            /* Sometimes, the boxcx value is something really large, like
1941               32691. This makes XCopyArea fail with Xvnc. The code below
1942               is a quick fix. */
1943            if (boxx + boxcx > g_width)
1944                    boxcx = g_width - boxx;
1945    
1946          if (boxcx > 1)          if (boxcx > 1)
1947          {          {
1948                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1619  ui_draw_text(uint8 font, uint8 flags, in Line 1952  ui_draw_text(uint8 font, uint8 flags, in
1952                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1953          }          }
1954    
1955            SET_FOREGROUND(fgcolour);
1956            SET_BACKGROUND(bgcolour);
1957            XSetFillStyle(g_display, g_gc, FillStippled);
1958    
1959          /* Paint text, character by character */          /* Paint text, character by character */
1960          for (i = 0; i < length;)          for (i = 0; i < length;)
1961          {          {
# Line 1669  ui_draw_text(uint8 font, uint8 flags, in Line 2006  ui_draw_text(uint8 font, uint8 flags, in
2006                                  break;                                  break;
2007                  }                  }
2008          }          }
2009    
2010            XSetFillStyle(g_display, g_gc, FillSolid);
2011    
2012          if (g_ownbackstore)          if (g_ownbackstore)
2013          {          {
2014                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.461  
changed lines
  Added in v.643

  ViewVC Help
Powered by ViewVC 1.1.26