/[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 519 by matthewc, Tue Oct 28 03:40:26 2003 UTC
# Line 34  extern BOOL g_hide_decorations; Line 34  extern BOOL g_hide_decorations;
34  extern char g_title[];  extern char g_title[];
35  extern int g_server_bpp;  extern int g_server_bpp;
36  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;  
37    
38  Display *g_display;  Display *g_display;
39  Time g_last_gesturetime;  Time g_last_gesturetime;
40  static int g_x_socket;  static int g_x_socket;
41  static Screen *g_screen;  static Screen *g_screen;
42  Window g_wnd;  Window g_wnd;
43    BOOL g_enable_compose = False;
44  static GC g_gc;  static GC g_gc;
45  static Visual *g_visual;  static Visual *g_visual;
46  static int g_depth;  static int g_depth;
# Line 51  static XIM g_IM; Line 49  static XIM g_IM;
49  static XIC g_IC;  static XIC g_IC;
50  static XModifierKeymap *g_mod_map;  static XModifierKeymap *g_mod_map;
51  static Cursor g_current_cursor;  static Cursor g_current_cursor;
52    static HCURSOR g_null_cursor;
53  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
54    static BOOL g_focused;
55    static BOOL g_mouse_in_wnd;
56    
57  /* endianness */  /* endianness */
58  static BOOL g_host_be;  static BOOL g_host_be;
# Line 69  static int g_move_y_offset = 0; Line 70  static int g_move_y_offset = 0;
70  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
71  extern int g_dsp_fd;  extern int g_dsp_fd;
72  extern BOOL g_dsp_busy;  extern BOOL g_dsp_busy;
73    extern BOOL g_rdpsnd;
74  #endif  #endif
75    
76  /* MWM decorations */  /* MWM decorations */
# Line 280  translate_colour(uint32 colour) Line 282  translate_colour(uint32 colour)
282                          }                          }
283                          break;                          break;
284          }          }
         switch (g_bpp)  
         {  
                 case 16:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP16(colour);  
                         break;  
   
                 case 24:  
                         if (g_xserver_be)  
                                 BSWAP24(colour);  
                         break;  
   
                 case 32:  
                         if (g_host_be != g_xserver_be)  
                                 BSWAP32(colour);  
                         break;  
         }  
   
285          return colour;          return colour;
286  }  }
287    
# Line 340  translate8to32(uint8 * data, uint32 * ou Line 324  translate8to32(uint8 * data, uint32 * ou
324  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
325    
326  static void  static void
327  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
328  {  {
329            uint16 pixel;
330            uint16 value;
331    
332          while (out < end)          while (out < end)
333                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
334                    pixel = *(data++);
335    
336                    if (g_host_be)
337                    {
338                    BSWAP16(pixel)}
339    
340                    value = make_colour16(split_colour15(pixel));
341    
342                    if (g_xserver_be)
343                    {
344                            *(out++) = value >> 8;
345                            *(out++) = value;
346                    }
347                    else
348                    {
349                            *(out++) = value;
350                            *(out++) = value >> 8;
351                    }
352            }
353  }  }
354    
355  static void  static void
356  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
357  {  {
358          uint32 value;          uint32 value;
359            uint16 pixel;
360    
361          while (out < end)          while (out < end)
362          {          {
363                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
364                  *(out++) = value;  
365                  *(out++) = value >> 8;                  if (g_host_be)
366                  *(out++) = value >> 16;                  {
367                    BSWAP16(pixel)}
368    
369                    value = make_colour24(split_colour15(pixel));
370                    if (g_xserver_be)
371                    {
372                            *(out++) = value >> 16;
373                            *(out++) = value >> 8;
374                            *(out++) = value;
375                    }
376                    else
377                    {
378                            *(out++) = value;
379                            *(out++) = value >> 8;
380                            *(out++) = value >> 16;
381                    }
382          }          }
383  }  }
384    
385  static void  static void
386  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
387  {  {
388          uint16 pixel;          uint16 pixel;
389            uint32 value;
390    
391          while (out < end)          while (out < end)
392          {          {
393                    pixel = *(data++);
394    
395                  if (g_host_be)                  if (g_host_be)
396                  {                  {
397                          pixel = *(data++);                          BSWAP16(pixel);
398                          pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8;                  }
399                          *(out++) = make_colour32(split_colour15(pixel));  
400                    value = make_colour32(split_colour15(pixel));
401    
402                    if (g_xserver_be)
403                    {
404                            *(out++) = value >> 24;
405                            *(out++) = value >> 16;
406                            *(out++) = value >> 8;
407                            *(out++) = value;
408                  }                  }
409                  else                  else
410                  {                  {
411                          *(out++) = make_colour32(split_colour15(*(data++)));                          *(out++) = value;
412                            *(out++) = value >> 8;
413                            *(out++) = value >> 16;
414                            *(out++) = value >> 24;
415                  }                  }
416          }          }
417  }  }
# Line 383  translate15to32(uint16 * data, uint32 * Line 419  translate15to32(uint16 * data, uint32 *
419  static void  static void
420  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint16 * out, uint16 * end)
421  {  {
422          while (out < end)          uint16 value;
423                  *(out++) = (uint16) (*(data++));  
424            if (g_xserver_be)
425            {
426                    while (out < end)
427                    {
428                            value = *data;
429                            BSWAP16(value);
430                            *out = value;
431                            data++;
432                            out++;
433                    }
434    
435            }
436            else
437            {
438                    while (out < end)
439                    {
440                            *out = *data;
441                            out++;
442                            data++;
443                    }
444            }
445  }  }
446    
447    
# Line 392  static void Line 449  static void
449  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
450  {  {
451          uint32 value;          uint32 value;
452            uint16 pixel;
453    
454          while (out < end)          while (out < end)
455          {          {
456                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
457                  *(out++) = value;  
458                  *(out++) = value >> 8;                  if (g_host_be)
459                  *(out++) = value >> 16;                  {
460                    BSWAP16(pixel)}
461    
462                    value = make_colour24(split_colour16(pixel));
463    
464                    if (g_xserver_be)
465                    {
466                            *(out++) = value >> 16;
467                            *(out++) = value >> 8;
468                            *(out++) = value;
469                    }
470                    else
471                    {
472                            *(out++) = value;
473                            *(out++) = value >> 8;
474                            *(out++) = value >> 16;
475                    }
476          }          }
477  }  }
478    
479  static void  static void
480  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
481  {  {
482          uint16 pixel;          uint16 pixel;
483            uint32 value;
484    
485          while (out < end)          while (out < end)
486          {          {
487                    pixel = *(data++);
488    
489                  if (g_host_be)                  if (g_host_be)
490                  {                  {
491                          pixel = *(data++);                  BSWAP16(pixel)}
492                          pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8;  
493                          *(out++) = make_colour32(split_colour16(pixel));                  value = make_colour32(split_colour16(pixel));
494    
495                    if (g_xserver_be)
496                    {
497                            *(out++) = value >> 24;
498                            *(out++) = value >> 16;
499                            *(out++) = value >> 8;
500                            *(out++) = value;
501                  }                  }
502                  else                  else
503                  {                  {
504                          *(out++) = make_colour32(split_colour16(*(data++)));                          *(out++) = value;
505                            *(out++) = value >> 8;
506                            *(out++) = value >> 16;
507                            *(out++) = value >> 24;
508                  }                  }
509          }          }
510  }  }
511    
512  static void  static void
513  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
514  {  {
515          uint32 pixel = 0;          uint32 pixel = 0;
516            uint16 value;
517          while (out < end)          while (out < end)
518          {          {
519                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
520                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
521                  pixel |= *(data++);                  pixel |= *(data++);
522                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
523                    value = (uint16) make_colour16(split_colour24(pixel));
524    
525                    if (g_xserver_be)
526                    {
527                            *(out++) = value >> 8;
528                            *(out++) = value;
529                    }
530                    else
531                    {
532                            *(out++) = value;
533                            *(out++) = value >> 8;
534                    }
535          }          }
536  }  }
537    
# Line 445  translate24to24(uint8 * data, uint8 * ou Line 545  translate24to24(uint8 * data, uint8 * ou
545  }  }
546    
547  static void  static void
548  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
549  {  {
         uint32 pixel = 0;  
550          while (out < end)          while (out < end)
551          {          {
552                  if (g_host_be)                  if (g_xserver_be)
553                  {                  {
554                          pixel = *(data++) << 16;                          *(out++) = 0x00;
555                          pixel |= *(data++) << 8;                          *(out++) = *(data++);
556                          pixel |= *(data++);                          *(out++) = *(data++);
557                            *(out++) = *(data++);
558                  }                  }
559                  else                  else
560                  {                  {
561                          pixel = *(data++);                          *(out++) = *(data++);
562                          pixel |= *(data++) << 8;                          *(out++) = *(data++);
563                          pixel |= *(data++) << 16;                          *(out++) = *(data++);
564                            *(out++) = 0x00;
565                  }                  }
                 *(out++) = pixel;  
566          }          }
567  }  }
568    
# Line 479  translate_image(int width, int height, u Line 579  translate_image(int width, int height, u
579                          switch (g_bpp)                          switch (g_bpp)
580                          {                          {
581                                  case 32:                                  case 32:
582                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
583                                          break;                                          break;
584                                  case 24:                                  case 24:
585                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
586                                          break;                                          break;
587                                  case 16:                                  case 16:
588                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
589                                          break;                                          break;
590                          }                          }
591                          break;                          break;
# Line 493  translate_image(int width, int height, u Line 593  translate_image(int width, int height, u
593                          switch (g_bpp)                          switch (g_bpp)
594                          {                          {
595                                  case 32:                                  case 32:
596                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
597                                          break;                                          break;
598                                  case 24:                                  case 24:
599                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
# Line 509  translate_image(int width, int height, u Line 608  translate_image(int width, int height, u
608                          switch (g_bpp)                          switch (g_bpp)
609                          {                          {
610                                  case 32:                                  case 32:
611                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
612                                          break;                                          break;
613                                  case 24:                                  case 24:
614                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
615                                          break;                                          break;
616                                  case 16:                                  case 16:
617                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
618                                          break;                                          break;
619                          }                          }
620                          break;                          break;
# Line 608  ui_init(void) Line 705  ui_init(void)
705                  return False;                  return False;
706          }          }
707    
708          if (g_owncolmap != True)          /* private colour map code only works for 8 bpp */
709            if (g_owncolmap && (g_bpp > 8))
710                    g_owncolmap = False;
711    
712            if (!g_owncolmap)
713          {          {
714                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = DefaultColormapOfScreen(g_screen);
715                  if (g_depth <= 8)                  if (g_depth <= 8)
# Line 624  ui_init(void) Line 725  ui_init(void)
725          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
726          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
727    
728          if ((g_width == 0) || (g_height == 0))          /*
729             * Determine desktop size
730             */
731            if (g_width < 0)
732            {
733                    /* Percent of screen */
734                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
735                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
736            }
737            else if (g_width == 0)
738          {          {
739                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
740                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 641  ui_init(void) Line 751  ui_init(void)
751                          g_height = 600;                          g_height = 600;
752                  }                  }
753          }          }
754            else if (g_fullscreen)
         if (g_fullscreen)  
755          {          {
756                  g_width = WidthOfScreen(g_screen);                  g_width = WidthOfScreen(g_screen);
757                  g_height = HeightOfScreen(g_screen);                  g_height = HeightOfScreen(g_screen);
# Line 664  ui_init(void) Line 773  ui_init(void)
773    
774          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
775    
776            xkeymap_init();
777    
778          if (g_enable_compose)          if (g_enable_compose)
779                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
780    
         xkeymap_init();  
781          xclip_init();          xclip_init();
782    
783          /* 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);  
784    
785          return True;          return True;
786  }  }
# Line 692  ui_deinit(void) Line 801  ui_deinit(void)
801          g_display = NULL;          g_display = NULL;
802  }  }
803    
804    #define NULL_POINTER_MASK       "\x80"
805    #define NULL_POINTER_DATA       "\x0\x0\x0"
806            
807  BOOL  BOOL
808  ui_create_window(void)  ui_create_window(void)
809  {  {
# Line 776  ui_create_window(void) Line 888  ui_create_window(void)
888          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
889          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
890    
891            /* create invisible 1x1 cursor to be used as null cursor */
892            g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);
893    
894          return True;          return True;
895  }  }
896    
897  void  void
898  ui_destroy_window(void)  ui_destroy_window(void)
899  {  {
900            ui_destroy_cursor(g_null_cursor);
901            
902          if (g_IC != NULL)          if (g_IC != NULL)
903                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
904    
# Line 1085  ui_select(int rdp_socket) Line 1202  ui_select(int rdp_socket)
1202          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;
1203          fd_set rfds, wfds;          fd_set rfds, wfds;
1204    
         FD_ZERO(&rfds);  
   
1205          while (True)          while (True)
1206          {          {
1207                  /* Process any events already waiting */                  /* Process any events already waiting */
# Line 1105  ui_select(int rdp_socket) Line 1220  ui_select(int rdp_socket)
1220                  {                  {
1221                          FD_SET(g_dsp_fd, &wfds);                          FD_SET(g_dsp_fd, &wfds);
1222                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;                          n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1223                  }                  }
1224  #endif  #endif
1225    
1226                  switch (select(n, &rfds, &wfds, NULL, NULL))                  switch (select(n, &rfds, &wfds, NULL, NULL))
# Line 1121  ui_select(int rdp_socket) Line 1236  ui_select(int rdp_socket)
1236                          return 1;                          return 1;
1237    
1238  #ifdef WITH_RDPSND  #ifdef WITH_RDPSND
1239                  if (FD_ISSET(g_dsp_fd, &wfds))                  if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1240                          wave_out_play();                          wave_out_play();
1241  #endif  #endif
1242          }          }
# Line 1299  ui_destroy_cursor(HCURSOR cursor) Line 1414  ui_destroy_cursor(HCURSOR cursor)
1414          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1415  }  }
1416    
1417    void
1418    ui_set_null_cursor(void)
1419    {
1420            ui_set_cursor(g_null_cursor);
1421    }
1422    
1423  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1424                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1425                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1499  ui_patblt(uint8 opcode, Line 1620  ui_patblt(uint8 opcode,
1620                  case 2: /* Hatch */                  case 2: /* Hatch */
1621                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1622                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1623                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1624                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1625                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1626                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1627                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);

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

  ViewVC Help
Powered by ViewVC 1.1.26