/[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 478 by matthewc, Sun Oct 5 12:07:56 2003 UTC revision 566 by stargo, Mon Jan 19 23:45:26 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 <time.h>  #include <time.h>
25  #include <errno.h>  #include <errno.h>
26  #include "rdesktop.h"  #include "rdesktop.h"
# Line 34  extern BOOL g_hide_decorations; Line 35  extern BOOL g_hide_decorations;
35  extern char g_title[];  extern char g_title[];
36  extern int g_server_bpp;  extern int g_server_bpp;
37  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;  
38    
39  Display *g_display;  Display *g_display;
40  Time g_last_gesturetime;  Time g_last_gesturetime;
41  static int g_x_socket;  static int g_x_socket;
42  static Screen *g_screen;  static Screen *g_screen;
43  Window g_wnd;  Window g_wnd;
44    BOOL g_enable_compose = False;
45  static GC g_gc;  static GC g_gc;
46    static BOOL g_gc_initialized = False;
47  static Visual *g_visual;  static Visual *g_visual;
48  static int g_depth;  static int g_depth;
49  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 51  static XIM g_IM;
51  static XIC g_IC;  static XIC g_IC;
52  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
53  static Cursor g_current_cursor;  static Cursor g_current_cursor;
54    static HCURSOR g_null_cursor;
55  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
56    static BOOL g_focused;
57    static BOOL g_mouse_in_wnd;
58    
59  /* endianness */  /* endianness */
60  static BOOL g_host_be;  static BOOL g_host_be;
61  static BOOL g_xserver_be;  static BOOL g_xserver_be;
62    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
63    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
64    
65  /* software backing store */  /* software backing store */
66  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
67  static Pixmap g_backstore;  static Pixmap g_backstore;
68    static BOOL g_backstore_initialized = False;
69    
70  /* Moving in single app mode */  /* Moving in single app mode */
71  static BOOL g_moving_wnd;  static BOOL g_moving_wnd;
# Line 69  static int g_move_y_offset = 0; Line 75  static int g_move_y_offset = 0;
75  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
76  extern int g_dsp_fd;  extern int g_dsp_fd;
77  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
78    extern BOOL g_rdpsnd;
79  #endif  #endif
80    
81  /* MWM decorations */  /* MWM decorations */
# Line 110  BOOL g_owncolmap = False; Line 117  BOOL g_owncolmap = False;
117  static Colormap g_xcolmap;  static Colormap g_xcolmap;
118  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
119    
120  #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] )
121  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
122  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
123    
# Line 195  split_colour24(uint32 colour) Line 202  split_colour24(uint32 colour)
202  }  }
203    
204  static uint32  static uint32
205  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
206  {  {
207          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
208          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
209          pc.blue = (pc.blue * 0x1f) / 0xff;                  | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
         return (pc.red << 11) | (pc.green << 5) | pc.blue;  
 }  
   
 static uint32  
 make_colour24(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
 }  
   
 static uint32  
 make_colour32(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
210  }  }
211    
212  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
213  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
214  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
215                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
216    
217  static uint32  static uint32
218  translate_colour(uint32 colour)  translate_colour(uint32 colour)
219  {  {
220            PixelColour pc;
221          switch (g_server_bpp)          switch (g_server_bpp)
222          {          {
223                  case 15:                  case 15:
224                          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;  
                         }  
225                          break;                          break;
226                  case 16:                  case 16:
227                          switch (g_bpp)                          pc = split_colour16(colour);
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
                         break;  
                 case 24:  
                         switch (g_bpp)  
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
                         break;  
         }  
         switch (g_bpp)  
         {  
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
228                          break;                          break;
   
229                  case 24:                  case 24:
230                          if (g_xserver_be)                          pc = split_colour24(colour);
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP32(colour);  
231                          break;                          break;
232          }          }
233            return make_colour(pc);
         return colour;  
234  }  }
235    
236  static void  static void
# Line 309  translate8to8(uint8 * data, uint8 * out, Line 241  translate8to8(uint8 * data, uint8 * out,
241  }  }
242    
243  static void  static void
244  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
245  {  {
246            uint16 value;
247    
248          while (out < end)          while (out < end)
249                  *(out++) = (uint16) g_colmap[*(data++)];          {
250                    value = (uint16) g_colmap[*(data++)];
251    
252                    if (g_xserver_be)
253                    {
254                            *(out++) = value >> 8;
255                            *(out++) = value;
256                    }
257                    else
258                    {
259                            *(out++) = value;
260                            *(out++) = value >> 8;
261                    }
262            }
263  }  }
264    
265  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 324  translate8to24(uint8 * data, uint8 * out Line 271  translate8to24(uint8 * data, uint8 * out
271          while (out < end)          while (out < end)
272          {          {
273                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
274                  *(out++) = value;  
275                  *(out++) = value >> 8;                  if (g_xserver_be)
276                  *(out++) = value >> 16;                  {
277                            *(out++) = value >> 16;
278                            *(out++) = value >> 8;
279                            *(out++) = value;
280                    }
281                    else
282                    {
283                            *(out++) = value;
284                            *(out++) = value >> 8;
285                            *(out++) = value >> 16;
286                    }
287          }          }
288  }  }
289    
290  static void  static void
291  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
292  {  {
293            uint32 value;
294    
295          while (out < end)          while (out < end)
296                  *(out++) = g_colmap[*(data++)];          {
297  }                  value = g_colmap[*(data++)];
298    
299  /* todo the remaining translate function might need some big endian check ?? */                  if (g_xserver_be)
300                    {
301                            *(out++) = value >> 24;
302                            *(out++) = value >> 16;
303                            *(out++) = value >> 8;
304                            *(out++) = value;
305                    }
306                    else
307                    {
308                            *(out++) = value;
309                            *(out++) = value >> 8;
310                            *(out++) = value >> 16;
311                            *(out++) = value >> 24;
312                    }
313            }
314    }
315    
316  static void  static void
317  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
318  {  {
319            uint16 pixel;
320            uint16 value;
321    
322          while (out < end)          while (out < end)
323                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
324                    pixel = *(data++);
325    
326                    if (g_host_be)
327                    {
328                            BSWAP16(pixel);
329                    }
330    
331                    value = make_colour(split_colour15(pixel));
332    
333                    if (g_xserver_be)
334                    {
335                            *(out++) = value >> 8;
336                            *(out++) = value;
337                    }
338                    else
339                    {
340                            *(out++) = value;
341                            *(out++) = value >> 8;
342                    }
343            }
344  }  }
345    
346  static void  static void
347  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
348  {  {
349          uint32 value;          uint32 value;
350            uint16 pixel;
351    
352          while (out < end)          while (out < end)
353          {          {
354                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
355                  *(out++) = value;  
356                  *(out++) = value >> 8;                  if (g_host_be)
357                  *(out++) = value >> 16;                  {
358                            BSWAP16(pixel);
359                    }
360    
361                    value = make_colour(split_colour15(pixel));
362                    if (g_xserver_be)
363                    {
364                            *(out++) = value >> 16;
365                            *(out++) = value >> 8;
366                            *(out++) = value;
367                    }
368                    else
369                    {
370                            *(out++) = value;
371                            *(out++) = value >> 8;
372                            *(out++) = value >> 16;
373                    }
374          }          }
375  }  }
376    
377  static void  static void
378  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
379  {  {
380          uint16 pixel;          uint16 pixel;
381            uint32 value;
382    
383          while (out < end)          while (out < end)
384          {          {
385                    pixel = *(data++);
386    
387                  if (g_host_be)                  if (g_host_be)
388                  {                  {
389                          pixel = *(data++);                          BSWAP16(pixel);
390                          pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8;                  }
391                          *(out++) = make_colour32(split_colour15(pixel));  
392                    value = make_colour(split_colour15(pixel));
393    
394                    if (g_xserver_be)
395                    {
396                            *(out++) = value >> 24;
397                            *(out++) = value >> 16;
398                            *(out++) = value >> 8;
399                            *(out++) = value;
400                  }                  }
401                  else                  else
402                  {                  {
403                          *(out++) = make_colour32(split_colour15(*(data++)));                          *(out++) = value;
404                            *(out++) = value >> 8;
405                            *(out++) = value >> 16;
406                            *(out++) = value >> 24;
407                  }                  }
408          }          }
409  }  }
410    
411  static void  static void
412  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint8 * out, uint8 * end)
413  {  {
414            uint16 pixel;
415            uint16 value;
416    
417          while (out < end)          while (out < end)
418                  *(out++) = (uint16) (*(data++));          {
419  }                  pixel = *(data++);
420    
421                    if (g_host_be)
422                    {
423                            BSWAP16(pixel);
424                    }
425    
426                    value = make_colour(split_colour16(pixel));
427    
428                    if (g_xserver_be)
429                    {
430                            *(out++) = value >> 8;
431                            *(out++) = value;
432                    }
433                    else
434                    {
435                            *(out++) = value;
436                            *(out++) = value >> 8;
437                    }
438            }
439    }
440    
441  static void  static void
442  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
443  {  {
444          uint32 value;          uint32 value;
445            uint16 pixel;
446    
447          while (out < end)          while (out < end)
448          {          {
449                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
450                  *(out++) = value;  
451                  *(out++) = value >> 8;                  if (g_host_be)
452                  *(out++) = value >> 16;                  {
453                            BSWAP16(pixel);
454                    }
455    
456                    value = make_colour(split_colour16(pixel));
457    
458                    if (g_xserver_be)
459                    {
460                            *(out++) = value >> 16;
461                            *(out++) = value >> 8;
462                            *(out++) = value;
463                    }
464                    else
465                    {
466                            *(out++) = value;
467                            *(out++) = value >> 8;
468                            *(out++) = value >> 16;
469                    }
470          }          }
471  }  }
472    
473  static void  static void
474  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
475  {  {
476          uint16 pixel;          uint16 pixel;
477            uint32 value;
478    
479          while (out < end)          while (out < end)
480          {          {
481                    pixel = *(data++);
482    
483                  if (g_host_be)                  if (g_host_be)
484                  {                  {
485                          pixel = *(data++);                          BSWAP16(pixel);
486                          pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8;                  }
487                          *(out++) = make_colour32(split_colour16(pixel));  
488                    value = make_colour(split_colour16(pixel));
489    
490                    if (g_xserver_be)
491                    {
492                            *(out++) = value >> 24;
493                            *(out++) = value >> 16;
494                            *(out++) = value >> 8;
495                            *(out++) = value;
496                  }                  }
497                  else                  else
498                  {                  {
499                          *(out++) = make_colour32(split_colour16(*(data++)));                          *(out++) = value;
500                            *(out++) = value >> 8;
501                            *(out++) = value >> 16;
502                            *(out++) = value >> 24;
503                  }                  }
504          }          }
505  }  }
506    
507  static void  static void
508  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
509  {  {
510          uint32 pixel = 0;          uint32 pixel = 0;
511            uint16 value;
512          while (out < end)          while (out < end)
513          {          {
514                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
515                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
516                  pixel |= *(data++);                  pixel |= *(data++);
517                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
518                    value = (uint16) make_colour(split_colour24(pixel));
519    
520                    if (g_xserver_be)
521                    {
522                            *(out++) = value >> 8;
523                            *(out++) = value;
524                    }
525                    else
526                    {
527                            *(out++) = value;
528                            *(out++) = value >> 8;
529                    }
530          }          }
531  }  }
532    
533  static void  static void
534  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
535  {  {
536            uint32 pixel;
537            uint32 value;
538    
539          while (out < end)          while (out < end)
540          {          {
541                  *(out++) = (*(data++));                  pixel = *(data++) << 16;
542                    pixel |= *(data++) << 8;
543                    pixel |= *(data++);
544    
545                    value = make_colour(split_colour24(pixel));
546    
547                    if (g_xserver_be)
548                    {
549                            *(out++) = value >> 16;
550                            *(out++) = value >> 8;
551                            *(out++) = value;
552                    }
553                    else
554                    {
555                            *(out++) = value;
556                            *(out++) = value >> 8;
557                            *(out++) = value >> 16;
558                    }
559          }          }
560  }  }
561    
562  static void  static void
563  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
564  {  {
565          uint32 pixel = 0;          uint32 pixel;
566            uint32 value;
567    
568          while (out < end)          while (out < end)
569          {          {
570                  if (g_host_be)                  pixel = *(data++) << 16;
571                    pixel |= *(data++) << 8;
572                    pixel |= *(data++);
573    
574                    value = make_colour(split_colour24(pixel));
575    
576                    if (g_xserver_be)
577                  {                  {
578                          pixel = *(data++) << 16;                          *(out++) = value >> 24;
579                          pixel |= *(data++) << 8;                          *(out++) = value >> 16;
580                          pixel |= *(data++);                          *(out++) = value >> 8;
581                            *(out++) = value;
582                  }                  }
583                  else                  else
584                  {                  {
585                          pixel = *(data++);                          *(out++) = value;
586                          pixel |= *(data++) << 8;                          *(out++) = value >> 8;
587                          pixel |= *(data++) << 16;                          *(out++) = value >> 16;
588                            *(out++) = value >> 24;
589                  }                  }
                 *(out++) = pixel;  
590          }          }
591  }  }
592    
# Line 479  translate_image(int width, int height, u Line 603  translate_image(int width, int height, u
603                          switch (g_bpp)                          switch (g_bpp)
604                          {                          {
605                                  case 32:                                  case 32:
606                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
607                                          break;                                          break;
608                                  case 24:                                  case 24:
609                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
610                                          break;                                          break;
611                                  case 16:                                  case 16:
612                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
613                                          break;                                          break;
614                          }                          }
615                          break;                          break;
# Line 493  translate_image(int width, int height, u Line 617  translate_image(int width, int height, u
617                          switch (g_bpp)                          switch (g_bpp)
618                          {                          {
619                                  case 32:                                  case 32:
620                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
621                                          break;                                          break;
622                                  case 24:                                  case 24:
623                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
624                                          break;                                          break;
625                                  case 16:                                  case 16:
626                                          translate16to16((uint16 *) data, (uint16 *) out,                                          translate16to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
627                                          break;                                          break;
628                          }                          }
629                          break;                          break;
# Line 509  translate_image(int width, int height, u Line 631  translate_image(int width, int height, u
631                          switch (g_bpp)                          switch (g_bpp)
632                          {                          {
633                                  case 32:                                  case 32:
634                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
635                                          break;                                          break;
636                                  case 24:                                  case 24:
637                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
638                                          break;                                          break;
639                                  case 16:                                  case 16:
640                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
641                                          break;                                          break;
642                          }                          }
643                          break;                          break;
# Line 528  translate_image(int width, int height, u Line 648  translate_image(int width, int height, u
648                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
649                                          break;                                          break;
650                                  case 16:                                  case 16:
651                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
652                                          break;                                          break;
653                                  case 24:                                  case 24:
654                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
655                                          break;                                          break;
656                                  case 32:                                  case 32:
657                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
658                                          break;                                          break;
659                          }                          }
660                          break;                          break;
# Line 567  get_key_state(unsigned int state, uint32 Line 687  get_key_state(unsigned int state, uint32
687          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
688  }  }
689    
690    static void
691    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
692    {
693            *shift_l = ffs(mask) - 1;
694            mask >>= *shift_l;
695            *shift_r = 8 - ffs(mask & ~(mask >> 1));
696    }
697    
698  BOOL  BOOL
699  ui_init(void)  ui_init(void)
700  {  {
701            XVisualInfo vi;
702          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
703          uint16 test;          uint16 test;
704          int i;          int i, screen_num, nvisuals;
705            XVisualInfo *vmatches = NULL;
706            XVisualInfo template;
707            Bool TrueColorVisual = False;
708    
709          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
710          if (g_display == NULL)          if (g_display == NULL)
# Line 581  ui_init(void) Line 713  ui_init(void)
713                  return False;                  return False;
714          }          }
715    
716            screen_num = DefaultScreen(g_display);
717          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
718          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
719          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
720    
721            /* Search for best TrueColor depth */
722            template.class = TrueColor;
723            vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
724    
725            nvisuals--;
726            while (nvisuals >= 0)
727            {
728                    if ((vmatches + nvisuals)->depth > g_depth)
729                    {
730                            g_depth = (vmatches + nvisuals)->depth;
731                    }
732                    nvisuals--;
733                    TrueColorVisual = True;
734            }
735    
736            if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8)))
737            {
738                    /* we use a colourmap, so the default visual should do */
739                    g_visual = DefaultVisualOfScreen(g_screen);
740                    g_depth = DefaultDepthOfScreen(g_screen);
741    
742                    /* Do not allocate colours on a TrueColor visual */
743                    if (g_visual->class == TrueColor)
744                    {
745                            g_owncolmap = False;
746                    }
747            }
748            else
749            {
750                    /* need a truecolour visual */
751                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
752                    {
753                            error("The display does not support true colour - high colour support unavailable.\n");
754                            return False;
755                    }
756    
757                    g_visual = vi.visual;
758                    g_owncolmap = False;
759                    calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
760                    calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
761                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
762            }
763    
764          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
765          if (pfm != NULL)          if (pfm != NULL)
766          {          {
# Line 608  ui_init(void) Line 783  ui_init(void)
783                  return False;                  return False;
784          }          }
785    
786          if (g_owncolmap != True)          if (!g_owncolmap)
787          {          {
788                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone);
789                  if (g_depth <= 8)                  if (g_depth <= 8)
790                          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");
791          }          }
792    
         g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);  
   
793          if (DoesBackingStore(g_screen) != Always)          if (DoesBackingStore(g_screen) != Always)
794                  g_ownbackstore = True;                  g_ownbackstore = True;
795    
# Line 624  ui_init(void) Line 797  ui_init(void)
797          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
798          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
799    
800          if ((g_width == 0) || (g_height == 0))          /*
801             * Determine desktop size
802             */
803            if (g_fullscreen)
804            {
805                    g_width = WidthOfScreen(g_screen);
806                    g_height = HeightOfScreen(g_screen);
807            }
808            else if (g_width < 0)
809            {
810                    /* Percent of screen */
811                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
812                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
813            }
814            else if (g_width == 0)
815          {          {
816                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
817                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 642  ui_init(void) Line 829  ui_init(void)
829                  }                  }
830          }          }
831    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
832          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
833          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
834    
         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);  
         }  
   
835          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
836    
837            xkeymap_init();
838    
839          if (g_enable_compose)          if (g_enable_compose)
840                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
841    
         xkeymap_init();  
842          xclip_init();          xclip_init();
843    
844          /* 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);  
845    
846          return True;          return True;
847  }  }
# Line 695  ui_deinit(void) Line 865  ui_deinit(void)
865  BOOL  BOOL
866  ui_create_window(void)  ui_create_window(void)
867  {  {
868            uint8 null_pointer_mask[1] = { 0x80 };
869            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
870          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
871          XClassHint *classhints;          XClassHint *classhints;
872          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 706  ui_create_window(void) Line 878  ui_create_window(void)
878          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
879    
880          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
881            attribs.border_pixel = WhitePixelOfScreen(g_screen);
882          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
883          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
884            attribs.colormap = g_xcolmap;
885    
886          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
887                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
888                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
889                                  CWColormap | CWBorderPixel, &attribs);
890    
891            if ( ! g_gc_initialized )
892            {
893                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
894                    g_gc_initialized = True;
895            }
896    
897            if ((g_ownbackstore) && (! g_backstore_initialized))
898            {
899                    g_backstore =
900                            XCreatePixmap(g_display, g_wnd, g_width, g_height,
901                                          g_depth);
902    
903                    /* clear to prevent rubbish being exposed at startup */
904                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
905                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
906                    g_backstore_initialized = True;
907            }
908    
909          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
910    
# Line 776  ui_create_window(void) Line 969  ui_create_window(void)
969          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
970          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
971    
972            /* create invisible 1x1 cursor to be used as null cursor */
973            g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
974    
975          return True;          return True;
976  }  }
977    
# Line 825  xwin_process_events(void) Line 1021  xwin_process_events(void)
1021          key_translation tr;          key_translation tr;
1022          char str[256];          char str[256];
1023          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1024    
1025          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1026          {          {
# Line 1000  xwin_process_events(void) Line 1193  xwin_process_events(void)
1193                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1194                                          break;                                          break;
1195                                  g_focused = True;                                  g_focused = True;
1196                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1197                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1198                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1199                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1103  ui_select(int rdp_socket) Line 1294  ui_select(int rdp_socket)
1294                  {                  {
1295                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1296                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1297                  }                  }
1298  #endif  #endif
1299    
1300                  switch (select(n, &rfds, &wfds, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, NULL))
# Line 1137  ui_create_bitmap(int width, int height, Line 1328  ui_create_bitmap(int width, int height,
1328          XImage *image;          XImage *image;
1329          Pixmap bitmap;          Pixmap bitmap;
1330          uint8 *tdata;          uint8 *tdata;
1331            int bitmap_pad;
1332    
1333            if (g_server_bpp == 8)
1334            {
1335                    bitmap_pad = 8;
1336            }
1337            else
1338            {
1339                    bitmap_pad = g_bpp;
1340    
1341                    if (g_bpp == 24)
1342                            bitmap_pad = 32;
1343            }
1344    
1345          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1346          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1347          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1348                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1349    
1350          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1351    
# Line 1156  ui_paint_bitmap(int x, int y, int cx, in Line 1360  ui_paint_bitmap(int x, int y, int cx, in
1360  {  {
1361          XImage *image;          XImage *image;
1362          uint8 *tdata;          uint8 *tdata;
1363            int bitmap_pad;
1364    
1365            if (g_server_bpp == 8)
1366            {
1367                    bitmap_pad = 8;
1368            }
1369            else
1370            {
1371                    bitmap_pad = g_bpp;
1372    
1373                    if (g_bpp == 24)
1374                            bitmap_pad = 32;
1375            }
1376    
1377          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1378          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1379                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1380    
1381          if (g_ownbackstore)          if (g_ownbackstore)
1382          {          {
# Line 1297  ui_destroy_cursor(HCURSOR cursor) Line 1515  ui_destroy_cursor(HCURSOR cursor)
1515          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1516  }  }
1517    
1518    void
1519    ui_set_null_cursor(void)
1520    {
1521            ui_set_cursor(g_null_cursor);
1522    }
1523    
1524  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1525                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1526                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1378  ui_create_colourmap(COLOURMAP * colours) Line 1602  ui_create_colourmap(COLOURMAP * colours)
1602    
1603                          }                          }
1604    
1605                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1606                  }                  }
1607                  return map;                  return map;
1608          }          }
# Line 1497  ui_patblt(uint8 opcode, Line 1719  ui_patblt(uint8 opcode,
1719                  case 2: /* Hatch */                  case 2: /* Hatch */
1720                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1721                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1722                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1723                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1724                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1725                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1726                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
# Line 1636  ui_draw_glyph(int mixmode, Line 1858  ui_draw_glyph(int mixmode,
1858  {\  {\
1859    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1860    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1861      {\
1862        xyoffset = ttext[++idx];\
1863        if ((xyoffset & 0x80))\
1864      {\      {\
1865        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1866        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;\  
         }\  
1867        else\        else\
1868          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1869            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1870      }\      }\
1871    if (glyph != NULL)\      else\
1872      {\      {\
1873        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1874                       y + glyph->baseline,\          y += xyoffset;\
1875                       glyph->width, glyph->height,\        else\
1876                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1877      }\      }\
1878      }\
1879      if (glyph != NULL)\
1880      {\
1881        x1 = x + glyph->offset;\
1882        y1 = y + glyph->baseline;\
1883        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1884        XSetTSOrigin(g_display, g_gc, x1, y1);\
1885        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1886        if (flags & TEXT2_IMPLICIT_X)\
1887          x += glyph->width;\
1888      }\
1889  }  }
1890    
1891  void  void
# Line 1672  ui_draw_text(uint8 font, uint8 flags, in Line 1895  ui_draw_text(uint8 font, uint8 flags, in
1895               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1896  {  {
1897          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1898          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1899          DATABLOB *entry;          DATABLOB *entry;
1900    
1901          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1686  ui_draw_text(uint8 font, uint8 flags, in Line 1909  ui_draw_text(uint8 font, uint8 flags, in
1909                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1910          }          }
1911    
1912            SET_FOREGROUND(fgcolour);
1913            SET_BACKGROUND(bgcolour);
1914            XSetFillStyle(g_display, g_gc, FillStippled);
1915    
1916          /* Paint text, character by character */          /* Paint text, character by character */
1917          for (i = 0; i < length;)          for (i = 0; i < length;)
1918          {          {
# Line 1736  ui_draw_text(uint8 font, uint8 flags, in Line 1963  ui_draw_text(uint8 font, uint8 flags, in
1963                                  break;                                  break;
1964                  }                  }
1965          }          }
1966    
1967            XSetFillStyle(g_display, g_gc, FillSolid);
1968    
1969          if (g_ownbackstore)          if (g_ownbackstore)
1970          {          {
1971                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.478  
changed lines
  Added in v.566

  ViewVC Help
Powered by ViewVC 1.1.26