/[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 725 by jsorg71, Sun Jun 27 17:51:54 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 GC g_create_bitmap_gc = NULL;
51    static GC g_create_glyph_gc = NULL;
52  static Visual *g_visual;  static Visual *g_visual;
53  static int g_depth;  static int g_depth;
54  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 56  static XIM g_IM;
56  static XIC g_IC;  static XIC g_IC;
57  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
58  static Cursor g_current_cursor;  static Cursor g_current_cursor;
59    static HCURSOR g_null_cursor = NULL;
60  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
61    static BOOL g_focused;
62    static BOOL g_mouse_in_wnd;
63    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
64    
65  /* endianness */  /* endianness */
66  static BOOL g_host_be;  static BOOL g_host_be;
67  static BOOL g_xserver_be;  static BOOL g_xserver_be;
68    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
69    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
70    
71  /* software backing store */  /* software backing store */
72  static BOOL g_ownbackstore;  extern BOOL g_ownbackstore;
73  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
74    
75  /* Moving in single app mode */  /* Moving in single app mode */
76  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
77  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
78  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
79    
80    #ifdef WITH_RDPSND
81    extern int g_dsp_fd;
82    extern BOOL g_dsp_busy;
83    extern BOOL g_rdpsnd;
84    #endif
85    
86  /* MWM decorations */  /* MWM decorations */
87  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
88  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 101  PixelColour; Line 118  PixelColour;
118  }  }
119    
120  /* colour maps */  /* colour maps */
121  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
122  static Colormap g_xcolmap;  static Colormap g_xcolmap;
123  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
124    
125  #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] )
126  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
127  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
128    
# Line 157  static PixelColour Line 174  static PixelColour
174  split_colour15(uint32 colour)  split_colour15(uint32 colour)
175  {  {
176          PixelColour rv;          PixelColour rv;
177          rv.red = (colour & 0x7c00) >> 10;          rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7);
178          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7);
179          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;  
180          return rv;          return rv;
181  }  }
182    
# Line 170  static PixelColour Line 184  static PixelColour
184  split_colour16(uint32 colour)  split_colour16(uint32 colour)
185  {  {
186          PixelColour rv;          PixelColour rv;
187          rv.red = (colour & 0xf800) >> 11;          rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7);
188          rv.red = (rv.red * 0xff) / 0x1f;          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
189          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;  
190          return rv;          return rv;
191  }  }
192    
# Line 184  split_colour24(uint32 colour) Line 195  split_colour24(uint32 colour)
195  {  {
196          PixelColour rv;          PixelColour rv;
197          rv.blue = (colour & 0xff0000) >> 16;          rv.blue = (colour & 0xff0000) >> 16;
198          rv.green = (colour & 0xff00) >> 8;          rv.green = (colour & 0x00ff00) >> 8;
199          rv.red = (colour & 0xff);          rv.red = (colour & 0x0000ff);
200          return rv;          return rv;
201  }  }
202    
203  static uint32  static uint32
204  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)  
205  {  {
206          return (pc.red << 16) | (pc.green << 8) | pc.blue;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
207                    | ((pc.green >> g_green_shift_r) << g_green_shift_l)
208                    | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
209  }  }
210    
211  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
212  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
213  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
214                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
215    
216  static uint32  static uint32
217  translate_colour(uint32 colour)  translate_colour(uint32 colour)
218  {  {
219            PixelColour pc;
220          switch (g_server_bpp)          switch (g_server_bpp)
221          {          {
222                  case 15:                  case 15:
223                          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;  
                         }  
224                          break;                          break;
225                  case 16:                  case 16:
226                          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;  
                         }  
227                          break;                          break;
228                  case 24:                  case 24:
229                          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;  
                         }  
230                          break;                          break;
231          }          }
232          switch (g_bpp)          return make_colour(pc);
233          {  }
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
                         break;  
234    
235                  case 24:  /* indent is confused by UNROLL8 */
236                          if (g_xserver_be)  /* *INDENT-OFF* */
                                 BSWAP24(colour);  
                         break;  
237    
238                  case 32:  /* repeat and unroll, similar to bitmap.c */
239                          if (g_host_be != g_xserver_be)  /* potentialy any of the following translate */
240                                  BSWAP32(colour);  /* functions can use repeat but just doing */
241                          break;  /* the most common ones */
         }  
242    
243          return colour;  #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
244    /* 2 byte output repeat */
245    #define REPEAT2(stm) \
246    { \
247            while (out <= end - 8 * 2) \
248                    UNROLL8(stm) \
249            while (out < end) \
250                    { stm } \
251    }
252    /* 4 byte output repeat */
253    #define REPEAT4(stm) \
254    { \
255            while (out <= end - 8 * 4) \
256                    UNROLL8(stm) \
257            while (out < end) \
258                    { stm } \
259  }  }
260    
261  static void  static void
# Line 290  translate8to8(uint8 * data, uint8 * out, Line 266  translate8to8(uint8 * data, uint8 * out,
266  }  }
267    
268  static void  static void
269  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
270  {  {
271          while (out < end)          uint16 value;
272                  *(out++) = (uint16) g_colmap[*(data++)];  
273            if (g_arch_match)
274            {
275                    REPEAT2
276                    (
277                            *((uint16 *) out) = g_colmap[*(data++)];
278                            out += 2;
279                    )
280            }
281            else if (g_xserver_be)
282            {
283                    while (out < end)
284                    {
285                            value = (uint16) g_colmap[*(data++)];
286                            *(out++) = value >> 8;
287                            *(out++) = value;
288                    }
289            }
290            else
291            {
292                    while (out < end)
293                    {
294                            value = (uint16) g_colmap[*(data++)];
295                            *(out++) = value;
296                            *(out++) = value >> 8;
297                    }
298            }
299  }  }
300    
301  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 302  translate8to24(uint8 * data, uint8 * out Line 304  translate8to24(uint8 * data, uint8 * out
304  {  {
305          uint32 value;          uint32 value;
306    
307          while (out < end)          if (g_xserver_be)
308          {          {
309                  value = g_colmap[*(data++)];                  while (out < end)
310                  *(out++) = value;                  {
311                  *(out++) = value >> 8;                          value = g_colmap[*(data++)];
312                  *(out++) = value >> 16;                          *(out++) = value >> 16;
313                            *(out++) = value >> 8;
314                            *(out++) = value;
315                    }
316            }
317            else
318            {
319                    while (out < end)
320                    {
321                            value = g_colmap[*(data++)];
322                            *(out++) = value;
323                            *(out++) = value >> 8;
324                            *(out++) = value >> 16;
325                    }
326          }          }
327  }  }
328    
329  static void  static void
330  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
331  {  {
332          while (out < end)          uint32 value;
333                  *(out++) = g_colmap[*(data++)];  
334            if (g_arch_match)
335            {
336                    REPEAT4
337                    (
338                            *((uint32 *) out) = g_colmap[*(data++)];
339                            out += 4;
340                    )
341            }
342            else if (g_xserver_be)
343            {
344                    while (out < end)
345                    {
346                            value = g_colmap[*(data++)];
347                            *(out++) = value >> 24;
348                            *(out++) = value >> 16;
349                            *(out++) = value >> 8;
350                            *(out++) = value;
351                    }
352            }
353            else
354            {
355                    while (out < end)
356                    {
357                            value = g_colmap[*(data++)];
358                            *(out++) = value;
359                            *(out++) = value >> 8;
360                            *(out++) = value >> 16;
361                            *(out++) = value >> 24;
362                    }
363            }
364  }  }
365    
366  /* todo the remaining translate function might need some big endian check ?? */  /* *INDENT-ON* */
367    
368  static void  static void
369  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
370  {  {
371            uint16 pixel;
372            uint16 value;
373    
374          while (out < end)          while (out < end)
375                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
376                    pixel = *(data++);
377    
378                    if (g_host_be)
379                    {
380                            BSWAP16(pixel);
381                    }
382    
383                    value = make_colour(split_colour15(pixel));
384    
385                    if (g_xserver_be)
386                    {
387                            *(out++) = value >> 8;
388                            *(out++) = value;
389                    }
390                    else
391                    {
392                            *(out++) = value;
393                            *(out++) = value >> 8;
394                    }
395            }
396  }  }
397    
398  static void  static void
399  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
400  {  {
401          uint32 value;          uint32 value;
402            uint16 pixel;
403    
404          while (out < end)          while (out < end)
405          {          {
406                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
407                  *(out++) = value;  
408                  *(out++) = value >> 8;                  if (g_host_be)
409                  *(out++) = value >> 16;                  {
410                            BSWAP16(pixel);
411                    }
412    
413                    value = make_colour(split_colour15(pixel));
414                    if (g_xserver_be)
415                    {
416                            *(out++) = value >> 16;
417                            *(out++) = value >> 8;
418                            *(out++) = value;
419                    }
420                    else
421                    {
422                            *(out++) = value;
423                            *(out++) = value >> 8;
424                            *(out++) = value >> 16;
425                    }
426          }          }
427  }  }
428    
429  static void  static void
430  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
431  {  {
432            uint16 pixel;
433            uint32 value;
434    
435          while (out < end)          while (out < end)
436                  *(out++) = make_colour32(split_colour15(*(data++)));          {
437                    pixel = *(data++);
438    
439                    if (g_host_be)
440                    {
441                            BSWAP16(pixel);
442                    }
443    
444                    value = make_colour(split_colour15(pixel));
445    
446                    if (g_xserver_be)
447                    {
448                            *(out++) = value >> 24;
449                            *(out++) = value >> 16;
450                            *(out++) = value >> 8;
451                            *(out++) = value;
452                    }
453                    else
454                    {
455                            *(out++) = value;
456                            *(out++) = value >> 8;
457                            *(out++) = value >> 16;
458                            *(out++) = value >> 24;
459                    }
460            }
461  }  }
462    
463  static void  static void
464  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
465  {  {
466            uint16 pixel;
467            uint16 value;
468    
469          while (out < end)          while (out < end)
470                  *(out++) = (uint16) (*(data++));          {
471  }                  pixel = *(data++);
472    
473                    if (g_host_be)
474                    {
475                            BSWAP16(pixel);
476                    }
477    
478                    value = make_colour(split_colour16(pixel));
479    
480                    if (g_xserver_be)
481                    {
482                            *(out++) = value >> 8;
483                            *(out++) = value;
484                    }
485                    else
486                    {
487                            *(out++) = value;
488                            *(out++) = value >> 8;
489                    }
490            }
491    }
492    
493  static void  static void
494  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
495  {  {
496          uint32 value;          uint32 value;
497            uint16 pixel;
498    
499          while (out < end)          while (out < end)
500          {          {
501                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
502                  *(out++) = value;  
503                  *(out++) = value >> 8;                  if (g_host_be)
504                  *(out++) = value >> 16;                  {
505                            BSWAP16(pixel);
506                    }
507    
508                    value = make_colour(split_colour16(pixel));
509    
510                    if (g_xserver_be)
511                    {
512                            *(out++) = value >> 16;
513                            *(out++) = value >> 8;
514                            *(out++) = value;
515                    }
516                    else
517                    {
518                            *(out++) = value;
519                            *(out++) = value >> 8;
520                            *(out++) = value >> 16;
521                    }
522          }          }
523  }  }
524    
525  static void  static void
526  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
527  {  {
528            uint16 pixel;
529            uint32 value;
530    
531          while (out < end)          while (out < end)
532                  *(out++) = make_colour32(split_colour16(*(data++)));          {
533                    pixel = *(data++);
534    
535                    if (g_host_be)
536                    {
537                            BSWAP16(pixel);
538                    }
539    
540                    value = make_colour(split_colour16(pixel));
541    
542                    if (g_xserver_be)
543                    {
544                            *(out++) = value >> 24;
545                            *(out++) = value >> 16;
546                            *(out++) = value >> 8;
547                            *(out++) = value;
548                    }
549                    else
550                    {
551                            *(out++) = value;
552                            *(out++) = value >> 8;
553                            *(out++) = value >> 16;
554                            *(out++) = value >> 24;
555                    }
556            }
557  }  }
558    
559  static void  static void
560  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
561  {  {
562          uint32 pixel = 0;          uint32 pixel = 0;
563            uint16 value;
564          while (out < end)          while (out < end)
565          {          {
566                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
567                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
568                  pixel |= *(data++);                  pixel |= *(data++);
569                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
570                    value = (uint16) make_colour(split_colour24(pixel));
571    
572                    if (g_xserver_be)
573                    {
574                            *(out++) = value >> 8;
575                            *(out++) = value;
576                    }
577                    else
578                    {
579                            *(out++) = value;
580                            *(out++) = value >> 8;
581                    }
582          }          }
583  }  }
584    
585  static void  static void
586  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
587  {  {
588            uint32 pixel;
589            uint32 value;
590    
591          while (out < end)          while (out < end)
592          {          {
593                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
594                    pixel |= *(data++) << 8;
595                    pixel |= *(data++);
596    
597                    value = make_colour(split_colour24(pixel));
598    
599                    if (g_xserver_be)
600                    {
601                            *(out++) = value >> 16;
602                            *(out++) = value >> 8;
603                            *(out++) = value;
604                    }
605                    else
606                    {
607                            *(out++) = value;
608                            *(out++) = value >> 8;
609                            *(out++) = value >> 16;
610                    }
611          }          }
612  }  }
613    
614  static void  static void
615  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
616  {  {
617          uint32 pixel = 0;          uint32 pixel;
618            uint32 value;
619    
620          while (out < end)          while (out < end)
621          {          {
622                  pixel = *(data++);                  pixel = *(data++) << 16;
623                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
624                  pixel |= *(data++) << 16;                  pixel |= *(data++);
625                  *(out++) = pixel;  
626                    value = make_colour(split_colour24(pixel));
627    
628                    if (g_xserver_be)
629                    {
630                            *(out++) = value >> 24;
631                            *(out++) = value >> 16;
632                            *(out++) = value >> 8;
633                            *(out++) = value;
634                    }
635                    else
636                    {
637                            *(out++) = value;
638                            *(out++) = value >> 8;
639                            *(out++) = value >> 16;
640                            *(out++) = value >> 24;
641                    }
642          }          }
643  }  }
644    
645  static uint8 *  static uint8 *
646  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
647  {  {
648          int size = width * height * g_bpp / 8;          int size;
649          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
650          uint8 *end = out + size;          uint8 *end;
651    
652            /* if server and xserver bpp match, */
653            /* and arch(endian) matches, no need to translate */
654            /* just return data */
655            if (g_arch_match)
656            {
657                    if (g_depth == 15 && g_server_bpp == 15)
658                            return data;
659                    if (g_depth == 16 && g_server_bpp == 16)
660                            return data;
661            }
662    
663            size = width * height * (g_bpp / 8);
664            out = (uint8 *) xmalloc(size);
665            end = out + size;
666    
667          switch (g_server_bpp)          switch (g_server_bpp)
668          {          {
# Line 425  translate_image(int width, int height, u Line 670  translate_image(int width, int height, u
670                          switch (g_bpp)                          switch (g_bpp)
671                          {                          {
672                                  case 32:                                  case 32:
673                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
674                                          break;                                          break;
675                                  case 24:                                  case 24:
676                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
677                                          break;                                          break;
678                                  case 16:                                  case 16:
679                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
680                                          break;                                          break;
681                          }                          }
682                          break;                          break;
# Line 439  translate_image(int width, int height, u Line 684  translate_image(int width, int height, u
684                          switch (g_bpp)                          switch (g_bpp)
685                          {                          {
686                                  case 32:                                  case 32:
687                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
688                                          break;                                          break;
689                                  case 24:                                  case 24:
690                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
691                                          break;                                          break;
692                                  case 16:                                  case 16:
693                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
694                                          break;                                          break;
695                          }                          }
696                          break;                          break;
# Line 455  translate_image(int width, int height, u Line 698  translate_image(int width, int height, u
698                          switch (g_bpp)                          switch (g_bpp)
699                          {                          {
700                                  case 32:                                  case 32:
701                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
702                                          break;                                          break;
703                                  case 24:                                  case 24:
704                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
705                                          break;                                          break;
706                                  case 16:                                  case 16:
707                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
708                                          break;                                          break;
709                          }                          }
710                          break;                          break;
# Line 474  translate_image(int width, int height, u Line 715  translate_image(int width, int height, u
715                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
716                                          break;                                          break;
717                                  case 16:                                  case 16:
718                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
719                                          break;                                          break;
720                                  case 24:                                  case 24:
721                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
722                                          break;                                          break;
723                                  case 32:                                  case 32:
724                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
725                                          break;                                          break;
726                          }                          }
727                          break;                          break;
# Line 513  get_key_state(unsigned int state, uint32 Line 754  get_key_state(unsigned int state, uint32
754          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
755  }  }
756    
757    static void
758    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
759    {
760            *shift_l = ffs(mask) - 1;
761            mask >>= *shift_l;
762            *shift_r = 8 - ffs(mask & ~(mask >> 1));
763    }
764    
765  BOOL  BOOL
766  ui_init(void)  ui_init(void)
767  {  {
768            XVisualInfo vi;
769          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
770          uint16 test;          uint16 test;
771          int i;          int i, screen_num, nvisuals;
772            XVisualInfo *vmatches = NULL;
773            XVisualInfo template;
774            Bool TrueColorVisual = False;
775    
776          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
777          if (g_display == NULL)          if (g_display == NULL)
# Line 527  ui_init(void) Line 780  ui_init(void)
780                  return False;                  return False;
781          }          }
782    
783            screen_num = DefaultScreen(g_display);
784          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
785          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
786          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
787    
788            /* Search for best TrueColor depth */
789            template.class = TrueColor;
790            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
791    
792            nvisuals--;
793            while (nvisuals >= 0)
794            {
795                    if ((vmatches + nvisuals)->depth > g_depth)
796                    {
797                            g_depth = (vmatches + nvisuals)->depth;
798                    }
799                    nvisuals--;
800                    TrueColorVisual = True;
801            }
802    
803            test = 1;
804            g_host_be = !(BOOL) (*(uint8 *) (&test));
805            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
806    
807            if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
808            {
809                    /* we use a colourmap, so the default visual should do */
810                    g_visual = DefaultVisualOfScreen(g_screen);
811                    g_depth = DefaultDepthOfScreen(g_screen);
812    
813                    /* Do not allocate colours on a TrueColor visual */
814                    if (g_visual->class == TrueColor)
815                    {
816                            g_owncolmap = False;
817                    }
818            }
819            else
820            {
821                    /* need a truecolour visual */
822                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
823                    {
824                            error("The display does not support true colour - high colour support unavailable.\n");
825                            return False;
826                    }
827    
828                    g_visual = vi.visual;
829                    g_owncolmap = False;
830                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
831                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
832                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
833    
834                    /* if RGB video and averything is little endian */
835                    if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask)
836                            if (!g_xserver_be && !g_host_be)
837                                    g_arch_match = True;
838            }
839    
840          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
841          if (pfm != NULL)          if (pfm != NULL)
842          {          {
# Line 554  ui_init(void) Line 859  ui_init(void)
859                  return False;                  return False;
860          }          }
861    
862          if (g_owncolmap != True)          if (!g_owncolmap)
863          {          {
864                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap =
865                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
866                                            AllocNone);
867                  if (g_depth <= 8)                  if (g_depth <= 8)
868                          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");
869          }          }
870    
871          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
872            {
873          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
874                  g_ownbackstore = True;                  g_ownbackstore = True;
875            }
876    
877          test = 1;          /*
878          g_host_be = !(BOOL) (*(uint8 *) (&test));           * Determine desktop size
879          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);           */
880            if (g_fullscreen)
881          if ((g_width == 0) || (g_height == 0))          {
882                    g_width = WidthOfScreen(g_screen);
883                    g_height = HeightOfScreen(g_screen);
884            }
885            else if (g_width < 0)
886            {
887                    /* Percent of screen */
888                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
889                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
890            }
891            else if (g_width == 0)
892          {          {
893                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
894                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 588  ui_init(void) Line 906  ui_init(void)
906                  }                  }
907          }          }
908    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
909          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
910          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
911    
         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);  
         }  
   
912          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
913    
914            xkeymap_init();
915    
916          if (g_enable_compose)          if (g_enable_compose)
917                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
918    
         xkeymap_init();  
919          xclip_init();          xclip_init();
920    
921          /* 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);  
922    
923          return True;          return True;
924  }  }
# Line 628  ui_deinit(void) Line 929  ui_deinit(void)
929          if (g_IM != NULL)          if (g_IM != NULL)
930                  XCloseIM(g_IM);                  XCloseIM(g_IM);
931    
932            if (g_null_cursor != NULL)
933                    ui_destroy_cursor(g_null_cursor);
934    
935          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
936    
937          if (g_ownbackstore)          if (g_ownbackstore)
# Line 641  ui_deinit(void) Line 945  ui_deinit(void)
945  BOOL  BOOL
946  ui_create_window(void)  ui_create_window(void)
947  {  {
948            uint8 null_pointer_mask[1] = { 0x80 };
949            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
950          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
951          XClassHint *classhints;          XClassHint *classhints;
952          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 652  ui_create_window(void) Line 958  ui_create_window(void)
958          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
959    
960          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
961            attribs.border_pixel = WhitePixelOfScreen(g_screen);
962          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
963          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
964            attribs.colormap = g_xcolmap;
965    
966          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
967                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
968                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
969                                  CWColormap | CWBorderPixel, &attribs);
970    
971            if (g_gc == NULL)
972                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
973    
974            if (g_create_bitmap_gc == NULL)
975                    g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);
976    
977            if ((g_ownbackstore) && (g_backstore == 0))
978            {
979                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
980    
981                    /* clear to prevent rubbish being exposed at startup */
982                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
983                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
984            }
985    
986          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
987    
# Line 682  ui_create_window(void) Line 1006  ui_create_window(void)
1006                  XFree(sizehints);                  XFree(sizehints);
1007          }          }
1008    
1009            if (g_embed_wnd)
1010            {
1011                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1012            }
1013    
1014          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1015                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1016    
# Line 713  ui_create_window(void) Line 1042  ui_create_window(void)
1042                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1043          }          }
1044          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1045            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1046    
1047          g_focused = False;          g_focused = False;
1048          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 722  ui_create_window(void) Line 1052  ui_create_window(void)
1052          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
1053          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
1054    
1055            /* create invisible 1x1 cursor to be used as null cursor */
1056            if (g_null_cursor == NULL)
1057                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
1058    
1059          return True;          return True;
1060  }  }
1061    
1062  void  void
1063    ui_resize_window()
1064    {
1065            XSizeHints *sizehints;
1066            Pixmap bs;
1067    
1068            sizehints = XAllocSizeHints();
1069            if (sizehints)
1070            {
1071                    sizehints->flags = PMinSize | PMaxSize;
1072                    sizehints->min_width = sizehints->max_width = g_width;
1073                    sizehints->min_height = sizehints->max_height = g_height;
1074                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1075                    XFree(sizehints);
1076            }
1077    
1078            if (!(g_fullscreen || g_embed_wnd))
1079            {
1080                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1081            }
1082    
1083            /* create new backstore pixmap */
1084            if (g_backstore != 0)
1085            {
1086                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1087                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1088                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1089                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1090                    XFreePixmap(g_display, g_backstore);
1091                    g_backstore = bs;
1092            }
1093    }
1094    
1095    void
1096  ui_destroy_window(void)  ui_destroy_window(void)
1097  {  {
1098          if (g_IC != NULL)          if (g_IC != NULL)
# Line 771  xwin_process_events(void) Line 1138  xwin_process_events(void)
1138          key_translation tr;          key_translation tr;
1139          char str[256];          char str[256];
1140          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1141    
1142          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1143          {          {
# Line 789  xwin_process_events(void) Line 1153  xwin_process_events(void)
1153    
1154                  switch (xevent.type)                  switch (xevent.type)
1155                  {                  {
1156                            case VisibilityNotify:
1157                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1158                                    break;
1159                          case ClientMessage:                          case ClientMessage:
1160                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1161                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 833  xwin_process_events(void) Line 1200  xwin_process_events(void)
1200                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1201                                          break;                                          break;
1202    
1203                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
1204                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
1205                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1206                                  restore_remote_modifiers(ev_time);                                  restore_remote_modifiers(ev_time, tr.scancode);
1207    
1208                                  break;                                  break;
1209    
# Line 946  xwin_process_events(void) Line 1313  xwin_process_events(void)
1313                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1314                                          break;                                          break;
1315                                  g_focused = True;                                  g_focused = True;
1316                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1317                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1318                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1319                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1028  xwin_process_events(void) Line 1393  xwin_process_events(void)
1393  int  int
1394  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1395  {  {
1396          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1397          fd_set rfds;          fd_set rfds, wfds;
1398            struct timeval tv;
1399          FD_ZERO(&rfds);          BOOL s_timeout = False;
1400    
1401          while (True)          while (True)
1402          {          {
1403                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1404                  /* Process any events already waiting */                  /* Process any events already waiting */
1405                  if (!xwin_process_events())                  if (!xwin_process_events())
1406                          /* User quit */                          /* User quit */
1407                          return 0;                          return 0;
1408    
1409                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1410                    FD_ZERO(&wfds);
1411                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1412                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1413    
1414                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1415                    /* FIXME: there should be an API for registering fds */
1416                    if (g_dsp_busy)
1417                    {
1418                            FD_SET(g_dsp_fd, &wfds);
1419                            n = (g_dsp_fd > n) ? g_dsp_fd : n;
1420                    }
1421    #endif
1422                    /* default timeout */
1423                    tv.tv_sec = 60;
1424                    tv.tv_usec = 0;
1425    
1426                    /* add redirection handles */
1427                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1428    
1429                    n++;
1430    
1431                    switch (select(n, &rfds, &wfds, NULL, &tv))
1432                  {                  {
1433                          case -1:                          case -1:
1434                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1435    
1436                          case 0:                          case 0:
1437                                    /* TODO: if tv.tv_sec just times out
1438                                     * we will segfault.
1439                                     * FIXME:
1440                                     */
1441                                    //s_timeout = True;
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 1070  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 1089  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 1104  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 1120  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 1133  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 1230  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 1311  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 1424  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 1445  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 1464  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 1472  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 1569  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 1605  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 1619  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 1669  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 1730  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.461  
changed lines
  Added in v.725

  ViewVC Help
Powered by ViewVC 1.1.26