/[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 704 by stargo, Thu May 27 10:19:41 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;  extern uint32 g_embed_wnd;
47    BOOL g_enable_compose = False;
48    BOOL g_Unobscured;              /* used for screenblt */
49    static GC g_gc = NULL;
50  static Visual *g_visual;  static Visual *g_visual;
51  static int g_depth;  static int g_depth;
52  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 54  static XIM g_IM;
54  static XIC g_IC;  static XIC g_IC;
55  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
56  static Cursor g_current_cursor;  static Cursor g_current_cursor;
57    static HCURSOR g_null_cursor = NULL;
58  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
59    static BOOL g_focused;
60    static BOOL g_mouse_in_wnd;
61    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
62    
63  /* endianness */  /* endianness */
64  static BOOL g_host_be;  static BOOL g_host_be;
65  static BOOL g_xserver_be;  static BOOL g_xserver_be;
66    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
67    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
68    
69  /* software backing store */  /* software backing store */
70  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
71  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
72    
73  /* Moving in single app mode */  /* Moving in single app mode */
74  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
75  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
76  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
77    
78    #ifdef WITH_RDPSND
79    extern int g_dsp_fd;
80    extern BOOL g_dsp_busy;
81    extern BOOL g_rdpsnd;
82    #endif
83    
84  /* MWM decorations */  /* MWM decorations */
85  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
86  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 101  PixelColour; Line 116  PixelColour;
116  }  }
117    
118  /* colour maps */  /* colour maps */
119  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
120  static Colormap g_xcolmap;  static Colormap g_xcolmap;
121  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
122    
123  #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] )
124  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
125  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
126    
# Line 157  static PixelColour Line 172  static PixelColour
172  split_colour15(uint32 colour)  split_colour15(uint32 colour)
173  {  {
174          PixelColour rv;          PixelColour rv;
175          rv.red = (colour & 0x7c00) >> 10;          rv.red = ((colour >> 7 ) & 0xf8) | ((colour >> 12) & 0x7);
176          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7);
177          rv.green = (colour & 0x03e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2)  & 0x7);
         rv.green = (rv.green * 0xff) / 0x1f;  
         rv.blue = (colour & 0x1f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
178          return rv;          return rv;
179  }  }
180    
# Line 170  static PixelColour Line 182  static PixelColour
182  split_colour16(uint32 colour)  split_colour16(uint32 colour)
183  {  {
184          PixelColour rv;          PixelColour rv;
185          rv.red = (colour & 0xf800) >> 11;          rv.red = ((colour >> 8 ) & 0xf8) | ((colour >> 13) & 0x7);
186          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
187          rv.green = (colour & 0x07e0) >> 5;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2)  & 0x7);
         rv.green = (rv.green * 0xff) / 0x3f;  
         rv.blue = (colour & 0x001f);  
         rv.blue = (rv.blue * 0xff) / 0x1f;  
188          return rv;          return rv;
189  }  }
190    
# Line 184  split_colour24(uint32 colour) Line 193  split_colour24(uint32 colour)
193  {  {
194          PixelColour rv;          PixelColour rv;
195          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
196          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
197          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
198          return rv;          return rv;
199  }  }
200    
201  static uint32  static uint32
202  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)  
 {  
         return (pc.red << 16) | (pc.green << 8) | pc.blue;  
 }  
   
 static uint32  
 make_colour32(PixelColour pc)  
203  {  {
204          return (pc.red << 16) | (pc.green << 8) | pc.blue;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
205                    | ((pc.green >> g_green_shift_r) << g_green_shift_l)
206                    | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
207  }  }
208    
209  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
210  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
211  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
212                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
213    
214  static uint32  static uint32
215  translate_colour(uint32 colour)  translate_colour(uint32 colour)
216  {  {
217            PixelColour pc;
218          switch (g_server_bpp)          switch (g_server_bpp)
219          {          {
220                  case 15:                  case 15:
221                          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;  
                         }  
222                          break;                          break;
223                  case 16:                  case 16:
224                          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;  
                         }  
                         break;  
                 case 24:  
                         switch (g_bpp)  
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
225                          break;                          break;
         }  
         switch (g_bpp)  
         {  
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
                         break;  
   
226                  case 24:                  case 24:
227                          if (g_xserver_be)                          pc = split_colour24(colour);
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP32(colour);  
228                          break;                          break;
229          }          }
230            return make_colour(pc);
231    }
232    
233          return colour;  #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
234    #define REPEAT(stm) \
235    { \
236            while (out <= end - 8 * 4) \
237                    UNROLL8(stm) \
238            while (out < end) \
239                    { stm } \
240  }  }
241    
242  static void  static void
# Line 290  translate8to8(uint8 * data, uint8 * out, Line 247  translate8to8(uint8 * data, uint8 * out,
247  }  }
248    
249  static void  static void
250  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
251    {
252            uint16 value;
253    
254            if (g_arch_match)
255                    REPEAT(*((uint16 *) out) = g_colmap[*(data++)]; out += 2;
256                    )
257            else
258    if (g_xserver_be)
259  {  {
260          while (out < end)          while (out < end)
261                  *(out++) = (uint16) g_colmap[*(data++)];          {
262                    value = (uint16) g_colmap[*(data++)];
263                    *(out++) = value >> 8;
264                    *(out++) = value;
265            }
266    }
267    else
268    {
269            while (out < end)
270            {
271                    value = (uint16) g_colmap[*(data++)];
272                    *(out++) = value;
273                    *(out++) = value >> 8;
274            }
275    }
276  }  }
277    
278  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 302  translate8to24(uint8 * data, uint8 * out Line 281  translate8to24(uint8 * data, uint8 * out
281  {  {
282          uint32 value;          uint32 value;
283    
284            if (g_xserver_be)
285            {
286                    while (out < end)
287                    {
288                            value = g_colmap[*(data++)];
289                            *(out++) = value >> 16;
290                            *(out++) = value >> 8;
291                            *(out++) = value;
292                    }
293            }
294            else
295            {
296                    while (out < end)
297                    {
298                            value = g_colmap[*(data++)];
299                            *(out++) = value;
300                            *(out++) = value >> 8;
301                            *(out++) = value >> 16;
302                    }
303            }
304    }
305    
306    static void
307    translate8to32(uint8 * data, uint8 * out, uint8 * end)
308    {
309            uint32 value;
310    
311            if (g_arch_match)
312                    REPEAT(*((uint32 *) out) = g_colmap[*(data++)]; out += 4;
313                    )
314            else
315    if (g_xserver_be)
316    {
317            while (out < end)
318            {
319                    value = g_colmap[*(data++)];
320                    *(out++) = value >> 24;
321                    *(out++) = value >> 16;
322                    *(out++) = value >> 8;
323                    *(out++) = value;
324            }
325    }
326    else
327    {
328          while (out < end)          while (out < end)
329          {          {
330                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
331                  *(out++) = value;                  *(out++) = value;
332                  *(out++) = value >> 8;                  *(out++) = value >> 8;
333                  *(out++) = value >> 16;                  *(out++) = value >> 16;
334                    *(out++) = value >> 24;
335          }          }
336  }  }
337    }
338    
339  static void  static void
340  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
341  {  {
342            uint16 pixel;
343            uint16 value;
344    
345          while (out < end)          while (out < end)
346                  *(out++) = g_colmap[*(data++)];          {
347  }                  pixel = *(data++);
348    
349                    if (g_host_be)
350                    {
351                            BSWAP16(pixel);
352                    }
353    
354  /* todo the remaining translate function might need some big endian check ?? */                  value = make_colour(split_colour15(pixel));
355    
356  static void                  if (g_xserver_be)
357  translate15to16(uint16 * data, uint16 * out, uint16 * end)                  {
358  {                          *(out++) = value >> 8;
359          while (out < end)                          *(out++) = value;
360                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));                  }
361                    else
362                    {
363                            *(out++) = value;
364                            *(out++) = value >> 8;
365                    }
366            }
367  }  }
368    
369  static void  static void
370  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
371  {  {
372          uint32 value;          uint32 value;
373            uint16 pixel;
374    
375          while (out < end)          while (out < end)
376          {          {
377                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
378                  *(out++) = value;  
379                  *(out++) = value >> 8;                  if (g_host_be)
380                  *(out++) = value >> 16;                  {
381                            BSWAP16(pixel);
382                    }
383    
384                    value = make_colour(split_colour15(pixel));
385                    if (g_xserver_be)
386                    {
387                            *(out++) = value >> 16;
388                            *(out++) = value >> 8;
389                            *(out++) = value;
390                    }
391                    else
392                    {
393                            *(out++) = value;
394                            *(out++) = value >> 8;
395                            *(out++) = value >> 16;
396                    }
397          }          }
398  }  }
399    
400  static void  static void
401  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
402  {  {
403            uint16 pixel;
404            uint32 value;
405    
406          while (out < end)          while (out < end)
407                  *(out++) = make_colour32(split_colour15(*(data++)));          {
408                    pixel = *(data++);
409    
410                    if (g_host_be)
411                    {
412                            BSWAP16(pixel);
413                    }
414    
415                    value = make_colour(split_colour15(pixel));
416    
417                    if (g_xserver_be)
418                    {
419                            *(out++) = value >> 24;
420                            *(out++) = value >> 16;
421                            *(out++) = value >> 8;
422                            *(out++) = value;
423                    }
424                    else
425                    {
426                            *(out++) = value;
427                            *(out++) = value >> 8;
428                            *(out++) = value >> 16;
429                            *(out++) = value >> 24;
430                    }
431            }
432  }  }
433    
434  static void  static void
435  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
436  {  {
437            uint16 pixel;
438            uint16 value;
439    
440          while (out < end)          while (out < end)
441                  *(out++) = (uint16) (*(data++));          {
442  }                  pixel = *(data++);
443    
444                    if (g_host_be)
445                    {
446                            BSWAP16(pixel);
447                    }
448    
449                    value = make_colour(split_colour16(pixel));
450    
451                    if (g_xserver_be)
452                    {
453                            *(out++) = value >> 8;
454                            *(out++) = value;
455                    }
456                    else
457                    {
458                            *(out++) = value;
459                            *(out++) = value >> 8;
460                    }
461            }
462    }
463    
464  static void  static void
465  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
466  {  {
467          uint32 value;          uint32 value;
468            uint16 pixel;
469    
470          while (out < end)          while (out < end)
471          {          {
472                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
473                  *(out++) = value;  
474                  *(out++) = value >> 8;                  if (g_host_be)
475                  *(out++) = value >> 16;                  {
476                            BSWAP16(pixel);
477                    }
478    
479                    value = make_colour(split_colour16(pixel));
480    
481                    if (g_xserver_be)
482                    {
483                            *(out++) = value >> 16;
484                            *(out++) = value >> 8;
485                            *(out++) = value;
486                    }
487                    else
488                    {
489                            *(out++) = value;
490                            *(out++) = value >> 8;
491                            *(out++) = value >> 16;
492                    }
493          }          }
494  }  }
495    
496  static void  static void
497  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
498  {  {
499            uint16 pixel;
500            uint32 value;
501    
502          while (out < end)          while (out < end)
503                  *(out++) = make_colour32(split_colour16(*(data++)));          {
504                    pixel = *(data++);
505    
506                    if (g_host_be)
507                    {
508                            BSWAP16(pixel);
509                    }
510    
511                    value = make_colour(split_colour16(pixel));
512    
513                    if (g_xserver_be)
514                    {
515                            *(out++) = value >> 24;
516                            *(out++) = value >> 16;
517                            *(out++) = value >> 8;
518                            *(out++) = value;
519                    }
520                    else
521                    {
522                            *(out++) = value;
523                            *(out++) = value >> 8;
524                            *(out++) = value >> 16;
525                            *(out++) = value >> 24;
526                    }
527            }
528  }  }
529    
530  static void  static void
531  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
532  {  {
533          uint32 pixel = 0;          uint32 pixel = 0;
534            uint16 value;
535          while (out < end)          while (out < end)
536          {          {
537                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
538                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
539                  pixel |= *(data++);                  pixel |= *(data++);
540                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
541                    value = (uint16) make_colour(split_colour24(pixel));
542    
543                    if (g_xserver_be)
544                    {
545                            *(out++) = value >> 8;
546                            *(out++) = value;
547                    }
548                    else
549                    {
550                            *(out++) = value;
551                            *(out++) = value >> 8;
552                    }
553          }          }
554  }  }
555    
556  static void  static void
557  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
558  {  {
559            uint32 pixel;
560            uint32 value;
561    
562          while (out < end)          while (out < end)
563          {          {
564                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
565                    pixel |= *(data++) << 8;
566                    pixel |= *(data++);
567    
568                    value = make_colour(split_colour24(pixel));
569    
570                    if (g_xserver_be)
571                    {
572                            *(out++) = value >> 16;
573                            *(out++) = value >> 8;
574                            *(out++) = value;
575                    }
576                    else
577                    {
578                            *(out++) = value;
579                            *(out++) = value >> 8;
580                            *(out++) = value >> 16;
581                    }
582          }          }
583  }  }
584    
585  static void  static void
586  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
587  {  {
588          uint32 pixel = 0;          uint32 pixel;
589            uint32 value;
590    
591          while (out < end)          while (out < end)
592          {          {
593                  pixel = *(data++);                  pixel = *(data++) << 16;
594                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
595                  pixel |= *(data++) << 16;                  pixel |= *(data++);
596                  *(out++) = pixel;  
597                    value = make_colour(split_colour24(pixel));
598    
599                    if (g_xserver_be)
600                    {
601                            *(out++) = value >> 24;
602                            *(out++) = value >> 16;
603                            *(out++) = value >> 8;
604                            *(out++) = value;
605                    }
606                    else
607                    {
608                            *(out++) = value;
609                            *(out++) = value >> 8;
610                            *(out++) = value >> 16;
611                            *(out++) = value >> 24;
612                    }
613          }          }
614  }  }
615    
616  static uint8 *  static uint8 *
617  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
618  {  {
619          int size = width * height * g_bpp / 8;          int size;
620          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
621          uint8 *end = out + size;          uint8 *end;
622    
623            /* if server and xserver bpp match, */
624            /* and arch(endian) matches, no need to translate */
625            /* just return data */
626            if (g_arch_match)
627            {
628                    if (g_depth == 15 && g_server_bpp == 15)
629                            return data;
630                    if (g_depth == 16 && g_server_bpp == 16)
631                            return data;
632            }
633    
634            size = width * height * (g_bpp / 8);
635            out = (uint8 *) xmalloc(size);
636            end = out + size;
637    
638          switch (g_server_bpp)          switch (g_server_bpp)
639          {          {
# Line 425  translate_image(int width, int height, u Line 641  translate_image(int width, int height, u
641                          switch (g_bpp)                          switch (g_bpp)
642                          {                          {
643                                  case 32:                                  case 32:
644                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
645                                          break;                                          break;
646                                  case 24:                                  case 24:
647                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
648                                          break;                                          break;
649                                  case 16:                                  case 16:
650                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
651                                          break;                                          break;
652                          }                          }
653                          break;                          break;
# Line 439  translate_image(int width, int height, u Line 655  translate_image(int width, int height, u
655                          switch (g_bpp)                          switch (g_bpp)
656                          {                          {
657                                  case 32:                                  case 32:
658                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
659                                          break;                                          break;
660                                  case 24:                                  case 24:
661                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
662                                          break;                                          break;
663                                  case 16:                                  case 16:
664                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
665                                          break;                                          break;
666                          }                          }
667                          break;                          break;
# Line 455  translate_image(int width, int height, u Line 669  translate_image(int width, int height, u
669                          switch (g_bpp)                          switch (g_bpp)
670                          {                          {
671                                  case 32:                                  case 32:
672                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
673                                          break;                                          break;
674                                  case 24:                                  case 24:
675                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
676                                          break;                                          break;
677                                  case 16:                                  case 16:
678                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
679                                          break;                                          break;
680                          }                          }
681                          break;                          break;
# Line 474  translate_image(int width, int height, u Line 686  translate_image(int width, int height, u
686                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
687                                          break;                                          break;
688                                  case 16:                                  case 16:
689                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
690                                          break;                                          break;
691                                  case 24:                                  case 24:
692                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
693                                          break;                                          break;
694                                  case 32:                                  case 32:
695                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
696                                          break;                                          break;
697                          }                          }
698                          break;                          break;
# Line 513  get_key_state(unsigned int state, uint32 Line 725  get_key_state(unsigned int state, uint32
725          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
726  }  }
727    
728    static void
729    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
730    {
731            *shift_l = ffs(mask) - 1;
732            mask >>= *shift_l;
733            *shift_r = 8 - ffs(mask & ~(mask >> 1));
734    }
735    
736  BOOL  BOOL
737  ui_init(void)  ui_init(void)
738  {  {
739            XVisualInfo vi;
740          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
741          uint16 test;          uint16 test;
742          int i;          int i, screen_num, nvisuals;
743            XVisualInfo *vmatches = NULL;
744            XVisualInfo template;
745            Bool TrueColorVisual = False;
746    
747          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
748          if (g_display == NULL)          if (g_display == NULL)
# Line 527  ui_init(void) Line 751  ui_init(void)
751                  return False;                  return False;
752          }          }
753    
754            screen_num = DefaultScreen(g_display);
755          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
756          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
757          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
758    
759            /* Search for best TrueColor depth */
760            template.class = TrueColor;
761            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
762    
763            nvisuals--;
764            while (nvisuals >= 0)
765            {
766                    if ((vmatches + nvisuals)->depth > g_depth)
767                    {
768                            g_depth = (vmatches + nvisuals)->depth;
769                    }
770                    nvisuals--;
771                    TrueColorVisual = True;
772            }
773    
774            test = 1;
775            g_host_be = !(BOOL) (*(uint8 *) (&test));
776            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
777    
778            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
779            {
780                    /* we use a colourmap, so the default visual should do */
781                    g_visual = DefaultVisualOfScreen(g_screen);
782                    g_depth = DefaultDepthOfScreen(g_screen);
783    
784                    /* Do not allocate colours on a TrueColor visual */
785                    if (g_visual->class == TrueColor)
786                    {
787                            g_owncolmap = False;
788                    }
789            }
790            else
791            {
792                    /* need a truecolour visual */
793                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
794                    {
795                            error("The display does not support true colour - high colour support unavailable.\n");
796                            return False;
797                    }
798    
799                    g_visual = vi.visual;
800                    g_owncolmap = False;
801                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
802                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
803                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
804    
805                    /* if RGB video and averything is little endian */
806                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
807                            if (!g_xserver_be && !g_host_be)
808                                    g_arch_match = True;
809            }
810    
811          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
812          if (pfm != NULL)          if (pfm != NULL)
813          {          {
# Line 554  ui_init(void) Line 830  ui_init(void)
830                  return False;                  return False;
831          }          }
832    
833          if (g_owncolmap != True)          if (!g_owncolmap)
834          {          {
835                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
836                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
837                                            AllocNone);
838                  if (g_depth <= 8)                  if (g_depth <= 8)
839                          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");
840          }          }
841    
842          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
843            {
844          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
845                  g_ownbackstore = True;                  g_ownbackstore = True;
846            }
847    
848          test = 1;          /*
849          g_host_be = !(BOOL) (*(uint8 *) (&test));           * Determine desktop size
850          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);           */
851            if (g_fullscreen)
852          if ((g_width == 0) || (g_height == 0))          {
853                    g_width = WidthOfScreen(g_screen);
854                    g_height = HeightOfScreen(g_screen);
855            }
856            else if (g_width < 0)
857            {
858                    /* Percent of screen */
859                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
860                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
861            }
862            else if (g_width == 0)
863          {          {
864                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
865                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 588  ui_init(void) Line 877  ui_init(void)
877                  }                  }
878          }          }
879    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
880          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
881          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
882    
         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);  
         }  
   
883          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
884    
885            xkeymap_init();
886    
887          if (g_enable_compose)          if (g_enable_compose)
888                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
889    
         xkeymap_init();  
890          xclip_init();          xclip_init();
891    
892          /* 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);  
893    
894          return True;          return True;
895  }  }
# Line 628  ui_deinit(void) Line 900  ui_deinit(void)
900          if (g_IM != NULL)          if (g_IM != NULL)
901                  XCloseIM(g_IM);                  XCloseIM(g_IM);
902    
903            if (g_null_cursor != NULL)
904                    ui_destroy_cursor(g_null_cursor);
905    
906          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
907    
908          if (g_ownbackstore)          if (g_ownbackstore)
# Line 641  ui_deinit(void) Line 916  ui_deinit(void)
916  BOOL  BOOL
917  ui_create_window(void)  ui_create_window(void)
918  {  {
919            uint8 null_pointer_mask[1] = { 0x80 };
920            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
921          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
922          XClassHint *classhints;          XClassHint *classhints;
923          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 652  ui_create_window(void) Line 929  ui_create_window(void)
929          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
930    
931          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
932            attribs.border_pixel = WhitePixelOfScreen(g_screen);
933          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
934          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
935            attribs.colormap = g_xcolmap;
936    
937          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
938                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
939                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
940                                  CWColormap | CWBorderPixel, &attribs);
941    
942            if (g_gc == NULL)
943                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
944    
945            if ((g_ownbackstore) && (g_backstore == 0))
946            {
947                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
948    
949                    /* clear to prevent rubbish being exposed at startup */
950                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
951                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
952            }
953    
954          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
955    
# Line 682  ui_create_window(void) Line 974  ui_create_window(void)
974                  XFree(sizehints);                  XFree(sizehints);
975          }          }
976    
977            if (g_embed_wnd)
978            {
979                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
980            }
981    
982          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
983                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
984    
# Line 713  ui_create_window(void) Line 1010  ui_create_window(void)
1010                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1011          }          }
1012          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1013            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1014    
1015          g_focused = False;          g_focused = False;
1016          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 722  ui_create_window(void) Line 1020  ui_create_window(void)
1020          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1021          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1022    
1023            /* create invisible 1x1 cursor to be used as null cursor */
1024            if (g_null_cursor == NULL)
1025                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1026    
1027          return True;          return True;
1028  }  }
1029    
1030  void  void
1031    ui_resize_window()
1032    {
1033            XSizeHints *sizehints;
1034    
1035            sizehints = XAllocSizeHints();
1036            if (sizehints)
1037            {
1038                    sizehints->flags = PMinSize | PMaxSize;
1039                    sizehints->min_width = sizehints->max_width = g_width;
1040                    sizehints->min_height = sizehints->max_height = g_height;
1041                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1042                    XFree(sizehints);
1043            }
1044    
1045            if (!(g_fullscreen || g_embed_wnd))
1046            {
1047                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1048            }
1049    }
1050    
1051    void
1052  ui_destroy_window(void)  ui_destroy_window(void)
1053  {  {
1054          if (g_IC != NULL)          if (g_IC != NULL)
# Line 771  xwin_process_events(void) Line 1094  xwin_process_events(void)
1094          key_translation tr;          key_translation tr;
1095          char str[256];          char str[256];
1096          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1097    
1098          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1099          {          {
# Line 789  xwin_process_events(void) Line 1109  xwin_process_events(void)
1109    
1110                  switch (xevent.type)                  switch (xevent.type)
1111                  {                  {
1112                            case VisibilityNotify:
1113                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1114                                    break;
1115                          case ClientMessage:                          case ClientMessage:
1116                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1117                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 833  xwin_process_events(void) Line 1156  xwin_process_events(void)
1156                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1157                                          break;                                          break;
1158    
1159                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
1160                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
1161                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1162                                  restore_remote_modifiers(ev_time);                                  restore_remote_modifiers(ev_time, tr.scancode);
1163    
1164                                  break;                                  break;
1165    
# Line 946  xwin_process_events(void) Line 1269  xwin_process_events(void)
1269                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1270                                          break;                                          break;
1271                                  g_focused = True;                                  g_focused = True;
1272                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1273                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1274                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1275                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1028  xwin_process_events(void) Line 1349  xwin_process_events(void)
1349  int  int
1350  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1351  {  {
1352          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1353          fd_set rfds;          fd_set rfds, wfds;
1354            struct timeval tv;
1355          FD_ZERO(&rfds);          BOOL s_timeout = False;
1356    
1357          while (True)          while (True)
1358          {          {
1359                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1360                  /* Process any events already waiting */                  /* Process any events already waiting */
1361                  if (!xwin_process_events())                  if (!xwin_process_events())
1362                          /* User quit */                          /* User quit */
1363                          return 0;                          return 0;
1364    
1365                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1366                    FD_ZERO(&wfds);
1367                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1368                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1369    
1370                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1371                    /* FIXME: there should be an API for registering fds */
1372                    if (g_dsp_busy)
1373                    {
1374                            FD_SET(g_dsp_fd, &wfds);
1375                            n = (g_dsp_fd > n) ? g_dsp_fd : n;
1376                    }
1377    #endif
1378                    /* default timeout */
1379                    tv.tv_sec = 60;
1380                    tv.tv_usec = 0;
1381    
1382                    /* add redirection handles */
1383                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1384    
1385                    n++;
1386    
1387                    switch (select(n, &rfds, &wfds, NULL, &tv))
1388                  {                  {
1389                          case -1:                          case -1:
1390                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1391    
1392                          case 0:                          case 0:
1393                                    /* TODO: if tv.tv_sec just times out
1394                                     * we will segfault.
1395                                     * FIXME:
1396                                     */
1397                                    //s_timeout = True;
1398                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1399                                  continue;                                  continue;
1400                  }                  }
1401    
1402                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1403    
1404                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1405                          return 1;                          return 1;
1406    
1407    #ifdef WITH_RDPSND
1408                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1409                            wave_out_play();
1410    #endif
1411          }          }
1412  }  }
1413    
# Line 1070  ui_create_bitmap(int width, int height, Line 1423  ui_create_bitmap(int width, int height,
1423          XImage *image;          XImage *image;
1424          Pixmap bitmap;          Pixmap bitmap;
1425          uint8 *tdata;          uint8 *tdata;
1426            int bitmap_pad;
1427    
1428            if (g_server_bpp == 8)
1429            {
1430                    bitmap_pad = 8;
1431            }
1432            else
1433            {
1434                    bitmap_pad = g_bpp;
1435    
1436                    if (g_bpp == 24)
1437                            bitmap_pad = 32;
1438            }
1439    
1440          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1441          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1442          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1443                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1444    
1445          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);
1446    
1447          XFree(image);          XFree(image);
1448          if (!g_owncolmap)          if (tdata != data)
1449                  xfree(tdata);                  xfree(tdata);
1450          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1451  }  }
# Line 1089  ui_paint_bitmap(int x, int y, int cx, in Line 1455  ui_paint_bitmap(int x, int y, int cx, in
1455  {  {
1456          XImage *image;          XImage *image;
1457          uint8 *tdata;          uint8 *tdata;
1458            int bitmap_pad;
1459    
1460            if (g_server_bpp == 8)
1461            {
1462                    bitmap_pad = 8;
1463            }
1464            else
1465            {
1466                    bitmap_pad = g_bpp;
1467    
1468                    if (g_bpp == 24)
1469                            bitmap_pad = 32;
1470            }
1471    
1472          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1473          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1474                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1475    
1476          if (g_ownbackstore)          if (g_ownbackstore)
1477          {          {
# Line 1104  ui_paint_bitmap(int x, int y, int cx, in Line 1484  ui_paint_bitmap(int x, int y, int cx, in
1484          }          }
1485    
1486          XFree(image);          XFree(image);
1487          if (!g_owncolmap)          if (tdata != data)
1488                  xfree(tdata);                  xfree(tdata);
1489  }  }
1490    
# Line 1230  ui_destroy_cursor(HCURSOR cursor) Line 1610  ui_destroy_cursor(HCURSOR cursor)
1610          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1611  }  }
1612    
1613    void
1614    ui_set_null_cursor(void)
1615    {
1616            ui_set_cursor(g_null_cursor);
1617    }
1618    
1619  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1620                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1621                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1311  ui_create_colourmap(COLOURMAP * colours) Line 1697  ui_create_colourmap(COLOURMAP * colours)
1697    
1698                          }                          }
1699    
1700                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1701                  }                  }
1702                  return map;                  return map;
1703          }          }
# Line 1424  ui_patblt(uint8 opcode, Line 1808  ui_patblt(uint8 opcode,
1808          {          {
1809                  case 0: /* Solid */                  case 0: /* Solid */
1810                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1811                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1812                          break;                          break;
1813    
1814                  case 2: /* Hatch */                  case 2: /* Hatch */
1815                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1816                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1817                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1818                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1819                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1820                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1821                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1822                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1823                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1824                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1825                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1445  ui_patblt(uint8 opcode, Line 1829  ui_patblt(uint8 opcode,
1829                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1830                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1831                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1832                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1833                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1834                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1835                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1836                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1837                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1838                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1839                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1840                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1464  ui_patblt(uint8 opcode, Line 1845  ui_patblt(uint8 opcode,
1845          }          }
1846    
1847          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1848    
1849            if (g_ownbackstore)
1850                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1851  }  }
1852    
1853  void  void
# Line 1472  ui_screenblt(uint8 opcode, Line 1856  ui_screenblt(uint8 opcode,
1856               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1857  {  {
1858          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1859          if (g_ownbackstore)          if (g_ownbackstore)
1860                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1861                    if (g_Unobscured)
1862                    {
1863                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1864                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1865                                      y);
1866                    }
1867                    else
1868                    {
1869                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1870                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1871                                      y);
1872                    }
1873            }
1874            else
1875            {
1876                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1877            }
1878          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1879  }  }
1880    
# Line 1569  ui_draw_glyph(int mixmode, Line 1969  ui_draw_glyph(int mixmode,
1969  {\  {\
1970    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1971    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1972      {\
1973        xyoffset = ttext[++idx];\
1974        if ((xyoffset & 0x80))\
1975      {\      {\
1976        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1977        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;\  
         }\  
1978        else\        else\
1979          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1980            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1981      }\      }\
1982    if (glyph != NULL)\      else\
1983      {\      {\
1984        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1985                       y + glyph->baseline,\          y += xyoffset;\
1986                       glyph->width, glyph->height,\        else\
1987                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1988      }\      }\
1989      }\
1990      if (glyph != NULL)\
1991      {\
1992        x1 = x + glyph->offset;\
1993        y1 = y + glyph->baseline;\
1994        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1995        XSetTSOrigin(g_display, g_gc, x1, y1);\
1996        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1997        if (flags & TEXT2_IMPLICIT_X)\
1998          x += glyph->width;\
1999      }\
2000  }  }
2001    
2002  void  void
# Line 1605  ui_draw_text(uint8 font, uint8 flags, in Line 2006  ui_draw_text(uint8 font, uint8 flags, in
2006               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2007  {  {
2008          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2009          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2010          DATABLOB *entry;          DATABLOB *entry;
2011    
2012          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2013    
2014            /* Sometimes, the boxcx value is something really large, like
2015               32691. This makes XCopyArea fail with Xvnc. The code below
2016               is a quick fix. */
2017            if (boxx + boxcx > g_width)
2018                    boxcx = g_width - boxx;
2019    
2020          if (boxcx > 1)          if (boxcx > 1)
2021          {          {
2022                  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 2026  ui_draw_text(uint8 font, uint8 flags, in
2026                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2027          }          }
2028    
2029            SET_FOREGROUND(fgcolour);
2030            SET_BACKGROUND(bgcolour);
2031            XSetFillStyle(g_display, g_gc, FillStippled);
2032    
2033          /* Paint text, character by character */          /* Paint text, character by character */
2034          for (i = 0; i < length;)          for (i = 0; i < length;)
2035          {          {
# Line 1669  ui_draw_text(uint8 font, uint8 flags, in Line 2080  ui_draw_text(uint8 font, uint8 flags, in
2080                                  break;                                  break;
2081                  }                  }
2082          }          }
2083    
2084            XSetFillStyle(g_display, g_gc, FillSolid);
2085    
2086          if (g_ownbackstore)          if (g_ownbackstore)
2087          {          {
2088                  if (boxcx > 1)                  if (boxcx > 1)

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

  ViewVC Help
Powered by ViewVC 1.1.26