/[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 456 by astrand, Sun Aug 31 20:01:12 2003 UTC revision 517 by matthewc, Tue Oct 28 03:30:51 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 66  static BOOL g_moving_wnd; Line 67  static BOOL g_moving_wnd;
67  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
68  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
69    
70    #ifdef WITH_RDPSND
71    extern int g_dsp_fd;
72    extern BOOL g_dsp_busy;
73    extern BOOL g_rdpsnd;
74    #endif
75    
76  /* MWM decorations */  /* MWM decorations */
77  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
78  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 201  make_colour16(PixelColour pc) Line 208  make_colour16(PixelColour pc)
208  static uint32  static uint32
209  make_colour24(PixelColour pc)  make_colour24(PixelColour pc)
210  {  {
211          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
212            {
213                    return pc.red | (pc.green << 8) | (pc.blue << 16);
214            }
215            else
216            {
217                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
218            }
219  }  }
220    
221  static uint32  static uint32
222  make_colour32(PixelColour pc)  make_colour32(PixelColour pc)
223  {  {
224          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
225            {
226                    return pc.red | (pc.green << 8) | (pc.blue << 16);
227            }
228            else
229            {
230                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
231            }
232  }  }
233    
234  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 261  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 321  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;
389            uint32 value;
390    
391          while (out < end)          while (out < end)
392                  *(out++) = make_colour32(split_colour15(*(data++)));          {
393                    pixel = *(data++);
394    
395                    if (g_host_be)
396                    {
397                            BSWAP16(pixel);
398                    }
399    
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
410                    {
411                            *(out++) = value;
412                            *(out++) = value >> 8;
413                            *(out++) = value >> 16;
414                            *(out++) = value >> 24;
415                    }
416            }
417  }  }
418    
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 360  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;
483            uint32 value;
484    
485          while (out < end)          while (out < end)
486                  *(out++) = make_colour32(split_colour16(*(data++)));          {
487                    pixel = *(data++);
488    
489                    if (g_host_be)
490                    {
491                    BSWAP16(pixel)}
492    
493                    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
503                    {
504                            *(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 400  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                  pixel = *(data++);                  if (g_xserver_be)
553                  pixel |= *(data++) << 8;                  {
554                  pixel |= *(data++) << 16;                          *(out++) = 0x00;
555                  *(out++) = pixel;                          *(out++) = *(data++);
556                            *(out++) = *(data++);
557                            *(out++) = *(data++);
558                    }
559                    else
560                    {
561                            *(out++) = *(data++);
562                            *(out++) = *(data++);
563                            *(out++) = *(data++);
564                            *(out++) = 0x00;
565                    }
566          }          }
567  }  }
568    
# Line 425  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 439  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 455  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 554  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 570  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 587  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 610  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 */          /* todo take this out when high colour is done */
# Line 638  ui_deinit(void) Line 802  ui_deinit(void)
802          g_display = NULL;          g_display = NULL;
803  }  }
804    
805    #define NULL_POINTER_MASK       "\x80"
806    #define NULL_POINTER_DATA       "\x0\x0\x0"
807            
808  BOOL  BOOL
809  ui_create_window(void)  ui_create_window(void)
810  {  {
# Line 722  ui_create_window(void) Line 889  ui_create_window(void)
889          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);          g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True);
890          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);          XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1);
891    
892            /* create invisible 1x1 cursor to be used as null cursor */
893            g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA);
894    
895          return True;          return True;
896  }  }
897    
898  void  void
899  ui_destroy_window(void)  ui_destroy_window(void)
900  {  {
901            ui_destroy_cursor(g_null_cursor);
902            
903          if (g_IC != NULL)          if (g_IC != NULL)
904                  XDestroyIC(g_IC);                  XDestroyIC(g_IC);
905    
# Line 833  xwin_process_events(void) Line 1005  xwin_process_events(void)
1005                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
1006                                          break;                                          break;
1007    
1008                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
1009                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
1010                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
1011                                  restore_remote_modifiers();                                  restore_remote_modifiers(ev_time, tr.scancode);
1012    
1013                                  break;                                  break;
1014    
# Line 1029  int Line 1201  int
1201  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1202  {  {
1203          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;
1204          fd_set rfds;          fd_set rfds, wfds;
   
         FD_ZERO(&rfds);  
1205    
1206          while (True)          while (True)
1207          {          {
# Line 1041  ui_select(int rdp_socket) Line 1211  ui_select(int rdp_socket)
1211                          return 0;                          return 0;
1212    
1213                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1214                    FD_ZERO(&wfds);
1215                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1216                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1217    
1218                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1219                    /* FIXME: there should be an API for registering fds */
1220                    if (g_dsp_busy)
1221                    {
1222                            FD_SET(g_dsp_fd, &wfds);
1223                            n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1224                    }
1225    #endif
1226    
1227                    switch (select(n, &rfds, &wfds, NULL, NULL))
1228                  {                  {
1229                          case -1:                          case -1:
1230                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
# Line 1055  ui_select(int rdp_socket) Line 1235  ui_select(int rdp_socket)
1235    
1236                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1237                          return 1;                          return 1;
1238    
1239    #ifdef WITH_RDPSND
1240                    if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1241                            wave_out_play();
1242    #endif
1243          }          }
1244  }  }
1245    
# Line 1230  ui_destroy_cursor(HCURSOR cursor) Line 1415  ui_destroy_cursor(HCURSOR cursor)
1415          XFreeCursor(g_display, (Cursor) cursor);          XFreeCursor(g_display, (Cursor) cursor);
1416  }  }
1417    
1418    void
1419    ui_set_null_cursor(void)
1420    {
1421            ui_set_cursor(g_null_cursor);
1422    }
1423    
1424  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
1425                  (xc)->red   = ((c)->red   << 8) | (c)->red; \                  (xc)->red   = ((c)->red   << 8) | (c)->red; \
1426                  (xc)->green = ((c)->green << 8) | (c)->green; \                  (xc)->green = ((c)->green << 8) | (c)->green; \
# Line 1430  ui_patblt(uint8 opcode, Line 1621  ui_patblt(uint8 opcode,
1621                  case 2: /* Hatch */                  case 2: /* Hatch */
1622                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1623                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1624                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1625                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1626                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1627                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1628                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);

Legend:
Removed from v.456  
changed lines
  Added in v.517

  ViewVC Help
Powered by ViewVC 1.1.26