/[rdesktop]/sourceforge.net/trunk/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC 1.1.26