/[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 450 by jsorg71, Wed Aug 27 22:51:33 2003 UTC revision 801 by astrand, Tue Nov 23 13:29:12 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    
31  extern int g_width;  extern int g_width;
32  extern int g_height;  extern int g_height;
33    extern int g_xpos;
34    extern int g_ypos;
35  extern BOOL g_sendmotion;  extern BOOL g_sendmotion;
36  extern BOOL g_fullscreen;  extern BOOL g_fullscreen;
37  extern BOOL g_grab_keyboard;  extern BOOL g_grab_keyboard;
# Line 34  extern BOOL g_hide_decorations; Line 39  extern BOOL g_hide_decorations;
39  extern char g_title[];  extern char g_title[];
40  extern int g_server_bpp;  extern int g_server_bpp;
41  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;  
42    
43  Display *g_display;  Display *g_display;
44  Time g_last_gesturetime;  Time g_last_gesturetime;
45  static int g_x_socket;  static int g_x_socket;
46  static Screen *g_screen;  static Screen *g_screen;
47  Window g_wnd;  Window g_wnd;
48  static GC g_gc;  extern uint32 g_embed_wnd;
49    BOOL g_enable_compose = False;
50    BOOL g_Unobscured;              /* used for screenblt */
51    static GC g_gc = NULL;
52    static GC g_create_bitmap_gc = NULL;
53    static GC g_create_glyph_gc = NULL;
54  static Visual *g_visual;  static Visual *g_visual;
55  static int g_depth;  static int g_depth;
56  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 58  static XIM g_IM;
58  static XIC g_IC;  static XIC g_IC;
59  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
60  static Cursor g_current_cursor;  static Cursor g_current_cursor;
61    static HCURSOR g_null_cursor = NULL;
62  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
63    static BOOL g_focused;
64    static BOOL g_mouse_in_wnd;
65    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
66    
67  /* endianness */  /* endianness */
68  static BOOL g_host_be;  static BOOL g_host_be;
69  static BOOL g_xserver_be;  static BOOL g_xserver_be;
70    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
71    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
72    
73  /* software backing store */  /* software backing store */
74  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
75  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
76    
77  /* Moving in single app mode */  /* Moving in single app mode */
78  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
79  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
80  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
81    
82    #ifdef WITH_RDPSND
83    extern int g_dsp_fd;
84    extern BOOL g_dsp_busy;
85    extern BOOL g_rdpsnd;
86    #endif
87    
88  /* MWM decorations */  /* MWM decorations */
89  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
90  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 101  PixelColour; Line 120  PixelColour;
120  }  }
121    
122  /* colour maps */  /* colour maps */
123  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
124  static Colormap g_xcolmap;  static Colormap g_xcolmap;
125  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
126    
127  #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] )
128  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
129  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
130    
# Line 157  static PixelColour Line 176  static PixelColour
176  split_colour15(uint32 colour)  split_colour15(uint32 colour)
177  {  {
178          PixelColour rv;          PixelColour rv;
179          rv.red = (colour & 0x7c00) >> 10;          rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7);
180          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7);
181          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;  
182          return rv;          return rv;
183  }  }
184    
# Line 170  static PixelColour Line 186  static PixelColour
186  split_colour16(uint32 colour)  split_colour16(uint32 colour)
187  {  {
188          PixelColour rv;          PixelColour rv;
189          rv.red = (colour & 0xf800) >> 11;          rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7);
190          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
191          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;  
192          return rv;          return rv;
193  }  }
194    
# Line 184  split_colour24(uint32 colour) Line 197  split_colour24(uint32 colour)
197  {  {
198          PixelColour rv;          PixelColour rv;
199          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
200          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
201          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
202          return rv;          return rv;
203  }  }
204    
205  static uint32  static uint32
206  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)  
207  {  {
208          return (pc.red << 16) | (pc.green << 8) | pc.blue;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
209                    | ((pc.green >> g_green_shift_r) << g_green_shift_l)
210                    | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
211  }  }
212    
213  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
214  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
215  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
216                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
217    
218  static uint32  static uint32
219  translate_colour(uint32 colour)  translate_colour(uint32 colour)
220  {  {
221            PixelColour pc;
222          switch (g_server_bpp)          switch (g_server_bpp)
223          {          {
224                  case 15:                  case 15:
225                          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;  
                         }  
226                          break;                          break;
227                  case 16:                  case 16:
228                          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;  
                         }  
229                          break;                          break;
230                  case 24:                  case 24:
231                          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;  
                         }  
232                          break;                          break;
233          }          }
234          switch (g_bpp)          return make_colour(pc);
235          {  }
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
                         break;  
236    
237                  case 24:  /* indent is confused by UNROLL8 */
238                          if (g_xserver_be)  /* *INDENT-OFF* */
                                 BSWAP24(colour);  
                         break;  
239    
240                  case 32:  /* repeat and unroll, similar to bitmap.c */
241                          if (g_host_be != g_xserver_be)  /* potentialy any of the following translate */
242                                  BSWAP32(colour);  /* functions can use repeat but just doing */
243                          break;  /* the most common ones */
         }  
244    
245          return colour;  #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
246    /* 2 byte output repeat */
247    #define REPEAT2(stm) \
248    { \
249            while (out <= end - 8 * 2) \
250                    UNROLL8(stm) \
251            while (out < end) \
252                    { stm } \
253    }
254    /* 4 byte output repeat */
255    #define REPEAT4(stm) \
256    { \
257            while (out <= end - 8 * 4) \
258                    UNROLL8(stm) \
259            while (out < end) \
260                    { stm } \
261  }  }
262    
263  static void  static void
# Line 290  translate8to8(uint8 * data, uint8 * out, Line 268  translate8to8(uint8 * data, uint8 * out,
268  }  }
269    
270  static void  static void
271  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
272  {  {
273          while (out < end)          uint16 value;
274                  *(out++) = (uint16) g_colmap[*(data++)];  
275            if (g_arch_match)
276            {
277                    REPEAT2
278                    (
279                            *((uint16 *) out) = g_colmap[*(data++)];
280                            out += 2;
281                    )
282            }
283            else if (g_xserver_be)
284            {
285                    while (out < end)
286                    {
287                            value = (uint16) g_colmap[*(data++)];
288                            *(out++) = value >> 8;
289                            *(out++) = value;
290                    }
291            }
292            else
293            {
294                    while (out < end)
295                    {
296                            value = (uint16) g_colmap[*(data++)];
297                            *(out++) = value;
298                            *(out++) = value >> 8;
299                    }
300            }
301  }  }
302    
303  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 302  translate8to24(uint8 * data, uint8 * out Line 306  translate8to24(uint8 * data, uint8 * out
306  {  {
307          uint32 value;          uint32 value;
308    
309          while (out < end)          if (g_xserver_be)
310          {          {
311                  value = g_colmap[*(data++)];                  while (out < end)
312                  *(out++) = value;                  {
313                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
314                  *(out++) = value >> 16;                          *(out++) = value >> 16;
315                            *(out++) = value >> 8;
316                            *(out++) = value;
317                    }
318            }
319            else
320            {
321                    while (out < end)
322                    {
323                            value = g_colmap[*(data++)];
324                            *(out++) = value;
325                            *(out++) = value >> 8;
326                            *(out++) = value >> 16;
327                    }
328          }          }
329  }  }
330    
331  static void  static void
332  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
333  {  {
334          while (out < end)          uint32 value;
335                  *(out++) = g_colmap[*(data++)];  
336            if (g_arch_match)
337            {
338                    REPEAT4
339                    (
340                            *((uint32 *) out) = g_colmap[*(data++)];
341                            out += 4;
342                    )
343            }
344            else if (g_xserver_be)
345            {
346                    while (out < end)
347                    {
348                            value = g_colmap[*(data++)];
349                            *(out++) = value >> 24;
350                            *(out++) = value >> 16;
351                            *(out++) = value >> 8;
352                            *(out++) = value;
353                    }
354            }
355            else
356            {
357                    while (out < end)
358                    {
359                            value = g_colmap[*(data++)];
360                            *(out++) = value;
361                            *(out++) = value >> 8;
362                            *(out++) = value >> 16;
363                            *(out++) = value >> 24;
364                    }
365            }
366  }  }
367    
368  /* todo the remaining translate function might need some big endian check ?? */  /* *INDENT-ON* */
369    
370  static void  static void
371  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
372  {  {
373            uint16 pixel;
374            uint16 value;
375    
376          while (out < end)          while (out < end)
377                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
378                    pixel = *(data++);
379    
380                    if (g_host_be)
381                    {
382                            BSWAP16(pixel);
383                    }
384    
385                    value = make_colour(split_colour15(pixel));
386    
387                    if (g_xserver_be)
388                    {
389                            *(out++) = value >> 8;
390                            *(out++) = value;
391                    }
392                    else
393                    {
394                            *(out++) = value;
395                            *(out++) = value >> 8;
396                    }
397            }
398  }  }
399    
400  static void  static void
401  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
402  {  {
403          uint32 value;          uint32 value;
404            uint16 pixel;
405    
406          while (out < end)          while (out < end)
407          {          {
408                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
409                  *(out++) = value;  
410                  *(out++) = value >> 8;                  if (g_host_be)
411                  *(out++) = value >> 16;                  {
412                            BSWAP16(pixel);
413                    }
414    
415                    value = make_colour(split_colour15(pixel));
416                    if (g_xserver_be)
417                    {
418                            *(out++) = value >> 16;
419                            *(out++) = value >> 8;
420                            *(out++) = value;
421                    }
422                    else
423                    {
424                            *(out++) = value;
425                            *(out++) = value >> 8;
426                            *(out++) = value >> 16;
427                    }
428          }          }
429  }  }
430    
431  static void  static void
432  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
433  {  {
434            uint16 pixel;
435            uint32 value;
436    
437          while (out < end)          while (out < end)
438                  *(out++) = make_colour32(split_colour15(*(data++)));          {
439                    pixel = *(data++);
440    
441                    if (g_host_be)
442                    {
443                            BSWAP16(pixel);
444                    }
445    
446                    value = make_colour(split_colour15(pixel));
447    
448                    if (g_xserver_be)
449                    {
450                            *(out++) = value >> 24;
451                            *(out++) = value >> 16;
452                            *(out++) = value >> 8;
453                            *(out++) = value;
454                    }
455                    else
456                    {
457                            *(out++) = value;
458                            *(out++) = value >> 8;
459                            *(out++) = value >> 16;
460                            *(out++) = value >> 24;
461                    }
462            }
463  }  }
464    
465  static void  static void
466  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
467  {  {
468            uint16 pixel;
469            uint16 value;
470    
471          while (out < end)          while (out < end)
472                  *(out++) = (uint16) (*(data++));          {
473  }                  pixel = *(data++);
474    
475                    if (g_host_be)
476                    {
477                            BSWAP16(pixel);
478                    }
479    
480                    value = make_colour(split_colour16(pixel));
481    
482                    if (g_xserver_be)
483                    {
484                            *(out++) = value >> 8;
485                            *(out++) = value;
486                    }
487                    else
488                    {
489                            *(out++) = value;
490                            *(out++) = value >> 8;
491                    }
492            }
493    }
494    
495  static void  static void
496  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
497  {  {
498          uint32 value;          uint32 value;
499            uint16 pixel;
500    
501          while (out < end)          while (out < end)
502          {          {
503                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
504                  *(out++) = value;  
505                  *(out++) = value >> 8;                  if (g_host_be)
506                  *(out++) = value >> 16;                  {
507                            BSWAP16(pixel);
508                    }
509    
510                    value = make_colour(split_colour16(pixel));
511    
512                    if (g_xserver_be)
513                    {
514                            *(out++) = value >> 16;
515                            *(out++) = value >> 8;
516                            *(out++) = value;
517                    }
518                    else
519                    {
520                            *(out++) = value;
521                            *(out++) = value >> 8;
522                            *(out++) = value >> 16;
523                    }
524          }          }
525  }  }
526    
527  static void  static void
528  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
529  {  {
530            uint16 pixel;
531            uint32 value;
532    
533          while (out < end)          while (out < end)
534                  *(out++) = make_colour32(split_colour16(*(data++)));          {
535                    pixel = *(data++);
536    
537                    if (g_host_be)
538                    {
539                            BSWAP16(pixel);
540                    }
541    
542                    value = make_colour(split_colour16(pixel));
543    
544                    if (g_xserver_be)
545                    {
546                            *(out++) = value >> 24;
547                            *(out++) = value >> 16;
548                            *(out++) = value >> 8;
549                            *(out++) = value;
550                    }
551                    else
552                    {
553                            *(out++) = value;
554                            *(out++) = value >> 8;
555                            *(out++) = value >> 16;
556                            *(out++) = value >> 24;
557                    }
558            }
559  }  }
560    
561  static void  static void
562  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
563  {  {
564          uint32 pixel = 0;          uint32 pixel = 0;
565            uint16 value;
566          while (out < end)          while (out < end)
567          {          {
568                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
569                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
570                  pixel |= *(data++);                  pixel |= *(data++);
571                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
572                    value = (uint16) make_colour(split_colour24(pixel));
573    
574                    if (g_xserver_be)
575                    {
576                            *(out++) = value >> 8;
577                            *(out++) = value;
578                    }
579                    else
580                    {
581                            *(out++) = value;
582                            *(out++) = value >> 8;
583                    }
584          }          }
585  }  }
586    
587  static void  static void
588  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
589  {  {
590            uint32 pixel;
591            uint32 value;
592    
593          while (out < end)          while (out < end)
594          {          {
595                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
596                    pixel |= *(data++) << 8;
597                    pixel |= *(data++);
598    
599                    value = make_colour(split_colour24(pixel));
600    
601                    if (g_xserver_be)
602                    {
603                            *(out++) = value >> 16;
604                            *(out++) = value >> 8;
605                            *(out++) = value;
606                    }
607                    else
608                    {
609                            *(out++) = value;
610                            *(out++) = value >> 8;
611                            *(out++) = value >> 16;
612                    }
613          }          }
614  }  }
615    
616  static void  static void
617  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
618  {  {
619          uint32 pixel = 0;          uint32 pixel;
620            uint32 value;
621    
622          while (out < end)          while (out < end)
623          {          {
624                  pixel = *(data++);                  pixel = *(data++) << 16;
625                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
626                  pixel |= *(data++) << 16;                  pixel |= *(data++);
627                  *(out++) = pixel;  
628                    value = make_colour(split_colour24(pixel));
629    
630                    if (g_xserver_be)
631                    {
632                            *(out++) = value >> 24;
633                            *(out++) = value >> 16;
634                            *(out++) = value >> 8;
635                            *(out++) = value;
636                    }
637                    else
638                    {
639                            *(out++) = value;
640                            *(out++) = value >> 8;
641                            *(out++) = value >> 16;
642                            *(out++) = value >> 24;
643                    }
644          }          }
645  }  }
646    
647  static uint8 *  static uint8 *
648  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
649  {  {
650          int size = width * height * g_bpp / 8;          int size;
651          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
652          uint8 *end = out + size;          uint8 *end;
653    
654            /* if server and xserver bpp match, */
655            /* and arch(endian) matches, no need to translate */
656            /* just return data */
657            if (g_arch_match)
658            {
659                    if (g_depth == 15 && g_server_bpp == 15)
660                            return data;
661                    if (g_depth == 16 && g_server_bpp == 16)
662                            return data;
663            }
664    
665            size = width * height * (g_bpp / 8);
666            out = (uint8 *) xmalloc(size);
667            end = out + size;
668    
669          switch (g_server_bpp)          switch (g_server_bpp)
670          {          {
# Line 425  translate_image(int width, int height, u Line 672  translate_image(int width, int height, u
672                          switch (g_bpp)                          switch (g_bpp)
673                          {                          {
674                                  case 32:                                  case 32:
675                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
676                                          break;                                          break;
677                                  case 24:                                  case 24:
678                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
679                                          break;                                          break;
680                                  case 16:                                  case 16:
681                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
682                                          break;                                          break;
683                          }                          }
684                          break;                          break;
# Line 439  translate_image(int width, int height, u Line 686  translate_image(int width, int height, u
686                          switch (g_bpp)                          switch (g_bpp)
687                          {                          {
688                                  case 32:                                  case 32:
689                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
690                                          break;                                          break;
691                                  case 24:                                  case 24:
692                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
693                                          break;                                          break;
694                                  case 16:                                  case 16:
695                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
696                                          break;                                          break;
697                          }                          }
698                          break;                          break;
# Line 455  translate_image(int width, int height, u Line 700  translate_image(int width, int height, u
700                          switch (g_bpp)                          switch (g_bpp)
701                          {                          {
702                                  case 32:                                  case 32:
703                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
704                                          break;                                          break;
705                                  case 24:                                  case 24:
706                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
707                                          break;                                          break;
708                                  case 16:                                  case 16:
709                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
710                                          break;                                          break;
711                          }                          }
712                          break;                          break;
# Line 474  translate_image(int width, int height, u Line 717  translate_image(int width, int height, u
717                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
718                                          break;                                          break;
719                                  case 16:                                  case 16:
720                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
721                                          break;                                          break;
722                                  case 24:                                  case 24:
723                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
724                                          break;                                          break;
725                                  case 32:                                  case 32:
726                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
727                                          break;                                          break;
728                          }                          }
729                          break;                          break;
# Line 513  get_key_state(unsigned int state, uint32 Line 756  get_key_state(unsigned int state, uint32
756          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
757  }  }
758    
759    static void
760    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
761    {
762            *shift_l = ffs(mask) - 1;
763            mask >>= *shift_l;
764            *shift_r = 8 - ffs(mask & ~(mask >> 1));
765    }
766    
767  BOOL  BOOL
768  ui_init(void)  ui_init(void)
769  {  {
770            XVisualInfo vi;
771          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
772          uint16 test;          uint16 test;
773          int i;          int i, screen_num, nvisuals;
774            XVisualInfo *vmatches = NULL;
775            XVisualInfo template;
776            Bool TrueColorVisual = False;
777    
778          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
779          if (g_display == NULL)          if (g_display == NULL)
# Line 527  ui_init(void) Line 782  ui_init(void)
782                  return False;                  return False;
783          }          }
784    
785            screen_num = DefaultScreen(g_display);
786          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
787          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
788          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
789    
790            /* Search for best TrueColor depth */
791            template.class = TrueColor;
792            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
793    
794            nvisuals--;
795            while (nvisuals >= 0)
796            {
797                    if ((vmatches + nvisuals)->depth > g_depth)
798                    {
799                            g_depth = (vmatches + nvisuals)->depth;
800                    }
801                    nvisuals--;
802                    TrueColorVisual = True;
803            }
804    
805            test = 1;
806            g_host_be = !(BOOL) (*(uint8 *) (&test));
807            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
808    
809            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
810            {
811                    /* we use a colourmap, so the default visual should do */
812                    g_visual = DefaultVisualOfScreen(g_screen);
813                    g_depth = DefaultDepthOfScreen(g_screen);
814    
815                    /* Do not allocate colours on a TrueColor visual */
816                    if (g_visual->class == TrueColor)
817                    {
818                            g_owncolmap = False;
819                    }
820            }
821            else
822            {
823                    /* need a truecolour visual */
824                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
825                    {
826                            error("The display does not support true colour - high colour support unavailable.\n");
827                            return False;
828                    }
829    
830                    g_visual = vi.visual;
831                    g_owncolmap = False;
832                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
833                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
834                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
835    
836                    /* if RGB video and averything is little endian */
837                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
838                            if (!g_xserver_be && !g_host_be)
839                                    g_arch_match = True;
840            }
841    
842          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
843          if (pfm != NULL)          if (pfm != NULL)
844          {          {
# Line 554  ui_init(void) Line 861  ui_init(void)
861                  return False;                  return False;
862          }          }
863    
864          if (g_owncolmap != True)          if (!g_owncolmap)
865          {          {
866                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
867                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
868                                            AllocNone);
869                  if (g_depth <= 8)                  if (g_depth <= 8)
870                          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");
871          }          }
872    
873          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
874            {
875          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
876                  g_ownbackstore = True;                  g_ownbackstore = True;
877            }
878    
879          test = 1;          /*
880          g_host_be = !(BOOL) (*(uint8 *) (&test));           * Determine desktop size
881          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);           */
882            if (g_fullscreen)
883          if ((g_width == 0) || (g_height == 0))          {
884                    g_width = WidthOfScreen(g_screen);
885                    g_height = HeightOfScreen(g_screen);
886            }
887            else if (g_width < 0)
888            {
889                    /* Percent of screen */
890                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
891                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
892            }
893            else if (g_width == 0)
894          {          {
895                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
896                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 588  ui_init(void) Line 908  ui_init(void)
908                  }                  }
909          }          }
910    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
911          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
912          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
913    
         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);  
         }  
   
914          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
915    
916            xkeymap_init();
917    
918          if (g_enable_compose)          if (g_enable_compose)
919                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
920    
         xkeymap_init();  
921          xclip_init();          xclip_init();
922    
923          /* 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);  
924    
925          return True;          return True;
926  }  }
# Line 628  ui_deinit(void) Line 931  ui_deinit(void)
931          if (g_IM != NULL)          if (g_IM != NULL)
932                  XCloseIM(g_IM);                  XCloseIM(g_IM);
933    
934            if (g_null_cursor != NULL)
935                    ui_destroy_cursor(g_null_cursor);
936    
937          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
938    
939          if (g_ownbackstore)          if (g_ownbackstore)
# Line 641  ui_deinit(void) Line 947  ui_deinit(void)
947  BOOL  BOOL
948  ui_create_window(void)  ui_create_window(void)
949  {  {
950            uint8 null_pointer_mask[1] = { 0x80 };
951            uint8 null_pointer_data[24] = { 0x00 };
952    
953          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
954          XClassHint *classhints;          XClassHint *classhints;
955          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 652  ui_create_window(void) Line 961  ui_create_window(void)
961          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
962    
963          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
964            attribs.border_pixel = WhitePixelOfScreen(g_screen);
965          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
966          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
967            attribs.colormap = g_xcolmap;
968    
969            g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,
970                                  wndheight, 0, g_depth, InputOutput, g_visual,
971                                  CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
972                                  CWBorderPixel, &attribs);
973    
974            if (g_gc == NULL)
975                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
976    
977            if (g_create_bitmap_gc == NULL)
978                    g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);
979    
980          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          if ((g_ownbackstore) && (g_backstore == 0))
981                              0, CopyFromParent, InputOutput, CopyFromParent,          {
982                              CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
983    
984                    /* clear to prevent rubbish being exposed at startup */
985                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
986                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
987            }
988    
989          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
990    
# Line 682  ui_create_window(void) Line 1009  ui_create_window(void)
1009                  XFree(sizehints);                  XFree(sizehints);
1010          }          }
1011    
1012            if (g_embed_wnd)
1013            {
1014                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1015            }
1016    
1017          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1018                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1019    
# Line 697  ui_create_window(void) Line 1029  ui_create_window(void)
1029          if (g_IM != NULL)          if (g_IM != NULL)
1030          {          {
1031                  g_IC = XCreateIC(g_IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),                  g_IC = XCreateIC(g_IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
1032                                 XNClientWindow, g_wnd, XNFocusWindow, g_wnd, NULL);                                   XNClientWindow, g_wnd, XNFocusWindow, g_wnd, NULL);
1033    
1034                  if ((g_IC != NULL)                  if ((g_IC != NULL)
1035                      && (XGetICValues(g_IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))                      && (XGetICValues(g_IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))
# Line 713  ui_create_window(void) Line 1045  ui_create_window(void)
1045                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1046          }          }
1047          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1048            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1049    
1050          g_focused = False;          g_focused = False;
1051          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 722  ui_create_window(void) Line 1055  ui_create_window(void)
1055          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1056          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1057    
1058            /* create invisible 1x1 cursor to be used as null cursor */
1059            if (g_null_cursor == NULL)
1060                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1061    
1062          return True;          return True;
1063  }  }
1064    
1065  void  void
1066    ui_resize_window()
1067    {
1068            XSizeHints *sizehints;
1069            Pixmap bs;
1070    
1071            sizehints = XAllocSizeHints();
1072            if (sizehints)
1073            {
1074                    sizehints->flags = PMinSize | PMaxSize;
1075                    sizehints->min_width = sizehints->max_width = g_width;
1076                    sizehints->min_height = sizehints->max_height = g_height;
1077                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1078                    XFree(sizehints);
1079            }
1080    
1081            if (!(g_fullscreen || g_embed_wnd))
1082            {
1083                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1084            }
1085    
1086            /* create new backstore pixmap */
1087            if (g_backstore != 0)
1088            {
1089                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1090                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1091                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1092                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1093                    XFreePixmap(g_display, g_backstore);
1094                    g_backstore = bs;
1095            }
1096    }
1097    
1098    void
1099  ui_destroy_window(void)  ui_destroy_window(void)
1100  {  {
1101          if (g_IC != NULL)          if (g_IC != NULL)
# Line 771  xwin_process_events(void) Line 1141  xwin_process_events(void)
1141          key_translation tr;          key_translation tr;
1142          char str[256];          char str[256];
1143          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1144    
1145          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1146          {          {
# Line 789  xwin_process_events(void) Line 1156  xwin_process_events(void)
1156    
1157                  switch (xevent.type)                  switch (xevent.type)
1158                  {                  {
1159                            case VisibilityNotify:
1160                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1161                                    break;
1162                          case ClientMessage:                          case ClientMessage:
1163                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1164                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 833  xwin_process_events(void) Line 1203  xwin_process_events(void)
1203                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1204                                          break;                                          break;
1205    
1206                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
1207                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
1208                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1209                                  restore_remote_modifiers();                                  restore_remote_modifiers(ev_time, tr.scancode);
1210    
1211                                  break;                                  break;
1212    
# Line 885  xwin_process_events(void) Line 1255  xwin_process_events(void)
1255                                                  /* The close button, continue */                                                  /* The close button, continue */
1256                                                  ;                                                  ;
1257                                          }                                          }
1258                                          else if (xevent.xbutton.x >= g_width - g_win_button_size * 2)                                          else if (xevent.xbutton.x >=
1259                                                     g_width - g_win_button_size * 2)
1260                                          {                                          {
1261                                                  /* The maximize/restore button. Do not send to                                                  /* The maximize/restore button. Do not send to
1262                                                     server.  It might be a good idea to change the                                                     server.  It might be a good idea to change the
# Line 893  xwin_process_events(void) Line 1264  xwin_process_events(void)
1264                                                     that rdesktop inhibited this click */                                                     that rdesktop inhibited this click */
1265                                                  break;                                                  break;
1266                                          }                                          }
1267                                          else if (xevent.xbutton.x >= g_width - g_win_button_size * 3)                                          else if (xevent.xbutton.x >=
1268                                                     g_width - g_win_button_size * 3)
1269                                          {                                          {
1270                                                  /* The minimize button. Iconify window. */                                                  /* The minimize button. Iconify window. */
1271                                                  XIconifyWindow(g_display, g_wnd,                                                  XIconifyWindow(g_display, g_wnd,
# Line 944  xwin_process_events(void) Line 1316  xwin_process_events(void)
1316                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1317                                          break;                                          break;
1318                                  g_focused = True;                                  g_focused = True;
1319                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1320                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1321                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1322                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1026  xwin_process_events(void) Line 1396  xwin_process_events(void)
1396  int  int
1397  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1398  {  {
1399          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1400          fd_set rfds;          fd_set rfds, wfds;
1401            struct timeval tv;
1402          FD_ZERO(&rfds);          BOOL s_timeout = False;
1403    
1404          while (True)          while (True)
1405          {          {
1406                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1407                  /* Process any events already waiting */                  /* Process any events already waiting */
1408                  if (!xwin_process_events())                  if (!xwin_process_events())
1409                          /* User quit */                          /* User quit */
1410                          return 0;                          return 0;
1411    
1412                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1413                    FD_ZERO(&wfds);
1414                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1415                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1416    
1417                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1418                    /* FIXME: there should be an API for registering fds */
1419                    if (g_dsp_busy)
1420                    {
1421                            FD_SET(g_dsp_fd, &wfds);
1422                            n = (g_dsp_fd > n) ? g_dsp_fd : n;
1423                    }
1424    #endif
1425                    /* default timeout */
1426                    tv.tv_sec = 60;
1427                    tv.tv_usec = 0;
1428    
1429                    /* add redirection handles */
1430                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1431    
1432                    n++;
1433    
1434                    switch (select(n, &rfds, &wfds, NULL, &tv))
1435                  {                  {
1436                          case -1:                          case -1:
1437                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1438    
1439                          case 0:                          case 0:
1440                                    /* Abort serial read calls */
1441                                    if (s_timeout)
1442                                            rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1443                                  continue;                                  continue;
1444                  }                  }
1445    
1446                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1447    
1448                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1449                          return 1;                          return 1;
1450    
1451    #ifdef WITH_RDPSND
1452                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1453                            wave_out_play();
1454    #endif
1455          }          }
1456  }  }
1457    
# Line 1068  ui_create_bitmap(int width, int height, Line 1467  ui_create_bitmap(int width, int height,
1467          XImage *image;          XImage *image;
1468          Pixmap bitmap;          Pixmap bitmap;
1469          uint8 *tdata;          uint8 *tdata;
1470            int bitmap_pad;
1471    
1472            if (g_server_bpp == 8)
1473            {
1474                    bitmap_pad = 8;
1475            }
1476            else
1477            {
1478                    bitmap_pad = g_bpp;
1479    
1480                    if (g_bpp == 24)
1481                            bitmap_pad = 32;
1482            }
1483    
1484          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1485          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1486          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1487                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1488    
1489          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_create_bitmap_gc, image, 0, 0, 0, 0, width, height);
1490    
1491          XFree(image);          XFree(image);
1492          if (!g_owncolmap)          if (tdata != data)
1493                  xfree(tdata);                  xfree(tdata);
1494          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1495  }  }
# Line 1087  ui_paint_bitmap(int x, int y, int cx, in Line 1499  ui_paint_bitmap(int x, int y, int cx, in
1499  {  {
1500          XImage *image;          XImage *image;
1501          uint8 *tdata;          uint8 *tdata;
1502            int bitmap_pad;
1503    
1504            if (g_server_bpp == 8)
1505            {
1506                    bitmap_pad = 8;
1507            }
1508            else
1509            {
1510                    bitmap_pad = g_bpp;
1511    
1512                    if (g_bpp == 24)
1513                            bitmap_pad = 32;
1514            }
1515    
1516          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1517          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1518                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1519    
1520          if (g_ownbackstore)          if (g_ownbackstore)
1521          {          {
# Line 1102  ui_paint_bitmap(int x, int y, int cx, in Line 1528  ui_paint_bitmap(int x, int y, int cx, in
1528          }          }
1529    
1530          XFree(image);          XFree(image);
1531          if (!g_owncolmap)          if (tdata != data)
1532                  xfree(tdata);                  xfree(tdata);
1533  }  }
1534    
# Line 1118  ui_create_glyph(int width, int height, u Line 1544  ui_create_glyph(int width, int height, u
1544          XImage *image;          XImage *image;
1545          Pixmap bitmap;          Pixmap bitmap;
1546          int scanline;          int scanline;
         GC gc;  
1547    
1548          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1549    
1550          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);
1551          gc = XCreateGC(g_display, bitmap, 0, NULL);          if (g_create_glyph_gc == 0)
1552                    g_create_glyph_gc = XCreateGC(g_display, bitmap, 0, NULL);
1553    
1554          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,
1555                               width, height, 8, scanline);                               width, height, 8, scanline);
# Line 1131  ui_create_glyph(int width, int height, u Line 1557  ui_create_glyph(int width, int height, u
1557          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
1558          XInitImage(image);          XInitImage(image);
1559    
1560          XPutImage(g_display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height);
1561    
1562          XFree(image);          XFree(image);
         XFreeGC(g_display, gc);  
1563          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
1564  }  }
1565    
# Line 1228  ui_destroy_cursor(HCURSOR cursor) Line 1653  ui_destroy_cursor(HCURSOR cursor)
1653          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1654  }  }
1655    
1656    void
1657    ui_set_null_cursor(void)
1658    {
1659            ui_set_cursor(g_null_cursor);
1660    }
1661    
1662  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1663                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1664                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1309  ui_create_colourmap(COLOURMAP * colours) Line 1740  ui_create_colourmap(COLOURMAP * colours)
1740    
1741                          }                          }
1742    
1743                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1744                  }                  }
1745                  return map;                  return map;
1746          }          }
# Line 1422  ui_patblt(uint8 opcode, Line 1851  ui_patblt(uint8 opcode,
1851          {          {
1852                  case 0: /* Solid */                  case 0: /* Solid */
1853                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
1854                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1855                          break;                          break;
1856    
1857                  case 2: /* Hatch */                  case 2: /* Hatch */
1858                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1859                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1860                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1861                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1862                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1863                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1864                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1865                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
1866                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1867                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1868                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1443  ui_patblt(uint8 opcode, Line 1872  ui_patblt(uint8 opcode,
1872                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1873                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
1874                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
1875                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
1876                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
1877                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1878                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1879                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
1880                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
1881                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
1882                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
1883                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1462  ui_patblt(uint8 opcode, Line 1888  ui_patblt(uint8 opcode,
1888          }          }
1889    
1890          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1891    
1892            if (g_ownbackstore)
1893                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
1894  }  }
1895    
1896  void  void
# Line 1470  ui_screenblt(uint8 opcode, Line 1899  ui_screenblt(uint8 opcode,
1899               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1900  {  {
1901          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1902          if (g_ownbackstore)          if (g_ownbackstore)
1903                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);          {
1904                    if (g_Unobscured)
1905                    {
1906                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1907                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1908                                      y);
1909                    }
1910                    else
1911                    {
1912                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1913                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
1914                                      y);
1915                    }
1916            }
1917            else
1918            {
1919                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1920            }
1921          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1922  }  }
1923    
# Line 1567  ui_draw_glyph(int mixmode, Line 2012  ui_draw_glyph(int mixmode,
2012  {\  {\
2013    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
2014    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
2015      {\
2016        xyoffset = ttext[++idx];\
2017        if ((xyoffset & 0x80))\
2018      {\      {\
2019        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
2020        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;\  
         }\  
2021        else\        else\
2022          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
2023            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
2024      }\      }\
2025    if (glyph != NULL)\      else\
2026      {\      {\
2027        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
2028                       y + glyph->baseline,\          y += xyoffset;\
2029                       glyph->width, glyph->height,\        else\
2030                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
2031      }\      }\
2032      }\
2033      if (glyph != NULL)\
2034      {\
2035        x1 = x + glyph->offset;\
2036        y1 = y + glyph->baseline;\
2037        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
2038        XSetTSOrigin(g_display, g_gc, x1, y1);\
2039        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
2040        if (flags & TEXT2_IMPLICIT_X)\
2041          x += glyph->width;\
2042      }\
2043  }  }
2044    
2045  void  void
# Line 1603  ui_draw_text(uint8 font, uint8 flags, in Line 2049  ui_draw_text(uint8 font, uint8 flags, in
2049               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
2050  {  {
2051          FONTGLYPH *glyph;          FONTGLYPH *glyph;
2052          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
2053          DATABLOB *entry;          DATABLOB *entry;
2054    
2055          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2056    
2057            /* Sometimes, the boxcx value is something really large, like
2058               32691. This makes XCopyArea fail with Xvnc. The code below
2059               is a quick fix. */
2060            if (boxx + boxcx > g_width)
2061                    boxcx = g_width - boxx;
2062    
2063          if (boxcx > 1)          if (boxcx > 1)
2064          {          {
2065                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 1617  ui_draw_text(uint8 font, uint8 flags, in Line 2069  ui_draw_text(uint8 font, uint8 flags, in
2069                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
2070          }          }
2071    
2072            SET_FOREGROUND(fgcolour);
2073            SET_BACKGROUND(bgcolour);
2074            XSetFillStyle(g_display, g_gc, FillStippled);
2075    
2076          /* Paint text, character by character */          /* Paint text, character by character */
2077          for (i = 0; i < length;)          for (i = 0; i < length;)
2078          {          {
# Line 1667  ui_draw_text(uint8 font, uint8 flags, in Line 2123  ui_draw_text(uint8 font, uint8 flags, in
2123                                  break;                                  break;
2124                  }                  }
2125          }          }
2126    
2127            XSetFillStyle(g_display, g_gc, FillSolid);
2128    
2129          if (g_ownbackstore)          if (g_ownbackstore)
2130          {          {
2131                  if (boxcx > 1)                  if (boxcx > 1)
# Line 1728  ui_desktop_restore(uint32 offset, int x, Line 2187  ui_desktop_restore(uint32 offset, int x,
2187    
2188          XFree(image);          XFree(image);
2189  }  }
2190    
2191    /* these do nothing here but are used in uiports */
2192    void
2193    ui_begin_update(void)
2194    {
2195    }
2196    
2197    void
2198    ui_end_update(void)
2199    {
2200    }

Legend:
Removed from v.450  
changed lines
  Added in v.801

  ViewVC Help
Powered by ViewVC 1.1.26