/[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 474 by matthewc, Tue Sep 30 09:11:08 2003 UTC revision 609 by stargo, Mon Feb 16 20:28:09 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;  BOOL g_enable_compose = False;
47    static GC g_gc = NULL;
48  static Visual *g_visual;  static Visual *g_visual;
49  static int g_depth;  static int g_depth;
50  static int g_bpp;  static int g_bpp;
# Line 51  static XIM g_IM; Line 52  static XIM g_IM;
52  static XIC g_IC;  static XIC g_IC;
53  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
54  static Cursor g_current_cursor;  static Cursor g_current_cursor;
55    static HCURSOR g_null_cursor = NULL;
56  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
57    static BOOL g_focused;
58    static BOOL g_mouse_in_wnd;
59    
60  /* endianness */  /* endianness */
61  static BOOL g_host_be;  static BOOL g_host_be;
62  static BOOL g_xserver_be;  static BOOL g_xserver_be;
63    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
64    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
65    
66  /* software backing store */  /* software backing store */
67  static BOOL g_ownbackstore;  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */
68  static Pixmap g_backstore;  static Pixmap g_backstore = 0;
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;  
                         }  
                         break;  
                 case 16:  
                         switch (g_bpp)  
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
                         break;  
                 case 24:  
                         switch (g_bpp)  
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
225                          break;                          break;
         }  
         switch (g_bpp)  
         {  
226                  case 16:                  case 16:
227                          if (g_host_be != g_xserver_be)                          pc = split_colour16(colour);
                                 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 =
789                            XCreateColormap(g_display, RootWindowOfScreen(g_screen), g_visual,
790                                            AllocNone);
791                  if (g_depth <= 8)                  if (g_depth <= 8)
792                          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");
793          }          }
794    
795          g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL);          if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
796            {
797          if (DoesBackingStore(g_screen) != Always)                  warning("External BackingStore not available, using internal\n");
798                  g_ownbackstore = True;                  g_ownbackstore = True;
799            }
800    
801          test = 1;          test = 1;
802          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
803          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
804    
805          if ((g_width == 0) || (g_height == 0))          /*
806             * Determine desktop size
807             */
808            if (g_fullscreen)
809            {
810                    g_width = WidthOfScreen(g_screen);
811                    g_height = HeightOfScreen(g_screen);
812            }
813            else if (g_width < 0)
814            {
815                    /* Percent of screen */
816                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
817                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
818            }
819            else if (g_width == 0)
820          {          {
821                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
822                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 642  ui_init(void) Line 834  ui_init(void)
834                  }                  }
835          }          }
836    
         if (g_fullscreen)  
         {  
                 g_width = WidthOfScreen(g_screen);  
                 g_height = HeightOfScreen(g_screen);  
         }  
   
837          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
838          g_width = (g_width + 3) & ~3;          g_width = (g_width + 3) & ~3;
839    
         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);  
         }  
   
840          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
841    
842            xkeymap_init();
843    
844          if (g_enable_compose)          if (g_enable_compose)
845                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
846    
         xkeymap_init();  
847          xclip_init();          xclip_init();
848    
849          /* 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);  
850    
851          return True;          return True;
852  }  }
# Line 682  ui_deinit(void) Line 857  ui_deinit(void)
857          if (g_IM != NULL)          if (g_IM != NULL)
858                  XCloseIM(g_IM);                  XCloseIM(g_IM);
859    
860            if (g_null_cursor != NULL)
861                    ui_destroy_cursor(g_null_cursor);
862    
863          XFreeModifiermap(g_mod_map);          XFreeModifiermap(g_mod_map);
864    
865          if (g_ownbackstore)          if (g_ownbackstore)
# Line 695  ui_deinit(void) Line 873  ui_deinit(void)
873  BOOL  BOOL
874  ui_create_window(void)  ui_create_window(void)
875  {  {
876            uint8 null_pointer_mask[1] = { 0x80 };
877            uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };
878          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
879          XClassHint *classhints;          XClassHint *classhints;
880          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 706  ui_create_window(void) Line 886  ui_create_window(void)
886          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;          wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height;
887    
888          attribs.background_pixel = BlackPixelOfScreen(g_screen);          attribs.background_pixel = BlackPixelOfScreen(g_screen);
889            attribs.border_pixel = WhitePixelOfScreen(g_screen);
890          attribs.backing_store = g_ownbackstore ? NotUseful : Always;          attribs.backing_store = g_ownbackstore ? NotUseful : Always;
891          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
892            attribs.colormap = g_xcolmap;
893    
894          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,
895                                0, CopyFromParent, InputOutput, CopyFromParent,                                0, g_depth, InputOutput, g_visual,
896                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                                CWBackPixel | CWBackingStore | CWOverrideRedirect |
897                                  CWColormap | CWBorderPixel, &attribs);
898    
899            if (g_gc == NULL)
900                    g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
901    
902            if ((g_ownbackstore) && (g_backstore == 0))
903            {
904                    g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
905    
906                    /* clear to prevent rubbish being exposed at startup */
907                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
908                    XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height);
909            }
910    
911          XStoreName(g_display, g_wnd, g_title);          XStoreName(g_display, g_wnd, g_title);
912    
# Line 776  ui_create_window(void) Line 971  ui_create_window(void)
971          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
972          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
973    
974            /* create invisible 1x1 cursor to be used as null cursor */
975            if (g_null_cursor == NULL)
976                    g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data);
977    
978          return True;          return True;
979  }  }
980    
# Line 825  xwin_process_events(void) Line 1024  xwin_process_events(void)
1024          key_translation tr;          key_translation tr;
1025          char str[256];          char str[256];
1026          Status status;          Status status;
         unsigned int state;  
         Window wdummy;  
         int dummy;  
1027    
1028          while (XPending(g_display) > 0)          while (XPending(g_display) > 0)
1029          {          {
# Line 1000  xwin_process_events(void) Line 1196  xwin_process_events(void)
1196                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
1197                                          break;                                          break;
1198                                  g_focused = True;                                  g_focused = True;
1199                                  XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy,                                  reset_modifier_keys();
                                               &dummy, &dummy, &state);  
                                 reset_modifier_keys(state);  
1200                                  if (g_grab_keyboard && g_mouse_in_wnd)                                  if (g_grab_keyboard && g_mouse_in_wnd)
1201                                          XGrabKeyboard(g_display, g_wnd, True,                                          XGrabKeyboard(g_display, g_wnd, True,
1202                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
# Line 1082  xwin_process_events(void) Line 1276  xwin_process_events(void)
1276  int  int
1277  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1278  {  {
1279          int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;          int n;
1280          fd_set rfds, wfds;          fd_set rfds, wfds;
1281            struct timeval tv;
1282          FD_ZERO(&rfds);          BOOL s_timeout = False;
1283    
1284          while (True)          while (True)
1285          {          {
1286                    n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket;
1287                  /* Process any events already waiting */                  /* Process any events already waiting */
1288                  if (!xwin_process_events())                  if (!xwin_process_events())
1289                          /* User quit */                          /* User quit */
# Line 1104  ui_select(int rdp_socket) Line 1299  ui_select(int rdp_socket)
1299                  if (g_dsp_busy)                  if (g_dsp_busy)
1300                  {                  {
1301                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1302                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd > n) ? g_dsp_fd : n;
1303                  }                  }
1304  #endif  #endif
1305                    /* default timeout */
1306                    tv.tv_sec = 60;
1307                    tv.tv_usec = 0;
1308    
1309                    /* add redirection handles */
1310                    rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout);
1311    
1312                  switch (select(n, &rfds, &wfds, NULL, NULL))                  n++;
1313    
1314                    switch (select(n, &rfds, &wfds, NULL, &tv))
1315                  {                  {
1316                          case -1:                          case -1:
1317                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1318    
1319                          case 0:                          case 0:
1320                                    /* TODO: if tv.tv_sec just times out
1321                                     * we will segfault.
1322                                     * FIXME:
1323                                     */
1324                                    //s_timeout = True;
1325                                    //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
1326                                  continue;                                  continue;
1327                  }                  }
1328    
1329                    rdpdr_check_fds(&rfds, &wfds, (BOOL) False);
1330    
1331                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1332                          return 1;                          return 1;
1333    
1334  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
1335                  if (FD_ISSET(g_dsp_fd, &wfds))                  if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1336                          wave_out_play();                          wave_out_play();
1337  #endif  #endif
1338          }          }
# Line 1139  ui_create_bitmap(int width, int height, Line 1350  ui_create_bitmap(int width, int height,
1350          XImage *image;          XImage *image;
1351          Pixmap bitmap;          Pixmap bitmap;
1352          uint8 *tdata;          uint8 *tdata;
1353            int bitmap_pad;
1354    
1355            if (g_server_bpp == 8)
1356            {
1357                    bitmap_pad = 8;
1358            }
1359            else
1360            {
1361                    bitmap_pad = g_bpp;
1362    
1363                    if (g_bpp == 24)
1364                            bitmap_pad = 32;
1365            }
1366    
1367          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1368          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1369          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1370                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1371    
1372          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);
1373    
# Line 1158  ui_paint_bitmap(int x, int y, int cx, in Line 1382  ui_paint_bitmap(int x, int y, int cx, in
1382  {  {
1383          XImage *image;          XImage *image;
1384          uint8 *tdata;          uint8 *tdata;
1385            int bitmap_pad;
1386    
1387            if (g_server_bpp == 8)
1388            {
1389                    bitmap_pad = 8;
1390            }
1391            else
1392            {
1393                    bitmap_pad = g_bpp;
1394    
1395                    if (g_bpp == 24)
1396                            bitmap_pad = 32;
1397            }
1398    
1399          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1400          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1401                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1402    
1403          if (g_ownbackstore)          if (g_ownbackstore)
1404          {          {
# Line 1299  ui_destroy_cursor(HCURSOR cursor) Line 1537  ui_destroy_cursor(HCURSOR cursor)
1537          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1538  }  }
1539    
1540    void
1541    ui_set_null_cursor(void)
1542    {
1543            ui_set_cursor(g_null_cursor);
1544    }
1545    
1546  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1547                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1548                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1380  ui_create_colourmap(COLOURMAP * colours) Line 1624  ui_create_colourmap(COLOURMAP * colours)
1624    
1625                          }                          }
1626    
1627                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1628                  }                  }
1629                  return map;                  return map;
1630          }          }
# Line 1499  ui_patblt(uint8 opcode, Line 1741  ui_patblt(uint8 opcode,
1741                  case 2: /* Hatch */                  case 2: /* Hatch */
1742                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1743                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1744                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1745                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1746                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1747                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1748                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
# Line 1541  ui_screenblt(uint8 opcode, Line 1783  ui_screenblt(uint8 opcode,
1783               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
1784  {  {
1785          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
         XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);  
1786          if (g_ownbackstore)          if (g_ownbackstore)
1787            {
1788                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1789                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);
1790            }
1791            else
1792            {
1793                    XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
1794            }
1795          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1796  }  }
1797    
# Line 1638  ui_draw_glyph(int mixmode, Line 1886  ui_draw_glyph(int mixmode,
1886  {\  {\
1887    glyph = cache_get_font (font, ttext[idx]);\    glyph = cache_get_font (font, ttext[idx]);\
1888    if (!(flags & TEXT2_IMPLICIT_X))\    if (!(flags & TEXT2_IMPLICIT_X))\
1889      {\
1890        xyoffset = ttext[++idx];\
1891        if ((xyoffset & 0x80))\
1892      {\      {\
1893        xyoffset = ttext[++idx];\        if (flags & TEXT2_VERTICAL)\
1894        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;\  
         }\  
1895        else\        else\
1896          {\          x += ttext[idx+1] | (ttext[idx+2] << 8);\
1897            if (flags & TEXT2_VERTICAL) \        idx += 2;\
             y += xyoffset;\  
           else\  
             x += xyoffset;\  
         }\  
1898      }\      }\
1899    if (glyph != NULL)\      else\
1900      {\      {\
1901        ui_draw_glyph (mixmode, x + glyph->offset,\        if (flags & TEXT2_VERTICAL)\
1902                       y + glyph->baseline,\          y += xyoffset;\
1903                       glyph->width, glyph->height,\        else\
1904                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\          x += xyoffset;\
       if (flags & TEXT2_IMPLICIT_X)\  
         x += glyph->width;\  
1905      }\      }\
1906      }\
1907      if (glyph != NULL)\
1908      {\
1909        x1 = x + glyph->offset;\
1910        y1 = y + glyph->baseline;\
1911        XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\
1912        XSetTSOrigin(g_display, g_gc, x1, y1);\
1913        FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\
1914        if (flags & TEXT2_IMPLICIT_X)\
1915          x += glyph->width;\
1916      }\
1917  }  }
1918    
1919  void  void
# Line 1674  ui_draw_text(uint8 font, uint8 flags, in Line 1923  ui_draw_text(uint8 font, uint8 flags, in
1923               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1924  {  {
1925          FONTGLYPH *glyph;          FONTGLYPH *glyph;
1926          int i, j, xyoffset;          int i, j, xyoffset, x1, y1;
1927          DATABLOB *entry;          DATABLOB *entry;
1928    
1929          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
# Line 1688  ui_draw_text(uint8 font, uint8 flags, in Line 1937  ui_draw_text(uint8 font, uint8 flags, in
1937                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);                  FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy);
1938          }          }
1939    
1940            SET_FOREGROUND(fgcolour);
1941            SET_BACKGROUND(bgcolour);
1942            XSetFillStyle(g_display, g_gc, FillStippled);
1943    
1944          /* Paint text, character by character */          /* Paint text, character by character */
1945          for (i = 0; i < length;)          for (i = 0; i < length;)
1946          {          {
# Line 1738  ui_draw_text(uint8 font, uint8 flags, in Line 1991  ui_draw_text(uint8 font, uint8 flags, in
1991                                  break;                                  break;
1992                  }                  }
1993          }          }
1994    
1995            XSetFillStyle(g_display, g_gc, FillSolid);
1996    
1997          if (g_ownbackstore)          if (g_ownbackstore)
1998          {          {
1999                  if (boxcx > 1)                  if (boxcx > 1)

Legend:
Removed from v.474  
changed lines
  Added in v.609

  ViewVC Help
Powered by ViewVC 1.1.26