/[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 501 by stargo, Fri Oct 17 08:23:47 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 52  static XIC g_IC; Line 50  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 Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
53    static BOOL g_focused;
54    static BOOL g_mouse_in_wnd;
55    
56  /* endianness */  /* endianness */
57  static BOOL g_host_be;  static BOOL g_host_be;
# Line 66  static BOOL g_moving_wnd; Line 66  static BOOL g_moving_wnd;
66  static int g_move_x_offset = 0;  static int g_move_x_offset = 0;
67  static int g_move_y_offset = 0;  static int g_move_y_offset = 0;
68    
69    #ifdef WITH_RDPSND
70    extern int g_dsp_fd;
71    extern BOOL g_dsp_busy;
72    extern BOOL g_rdpsnd;
73    #endif
74    
75  /* MWM decorations */  /* MWM decorations */
76  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
77  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 201  make_colour16(PixelColour pc) Line 207  make_colour16(PixelColour pc)
207  static uint32  static uint32
208  make_colour24(PixelColour pc)  make_colour24(PixelColour pc)
209  {  {
210          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
211            {
212                    return pc.red | (pc.green << 8) | (pc.blue << 16);
213            }
214            else
215            {
216                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
217            }
218  }  }
219    
220  static uint32  static uint32
221  make_colour32(PixelColour pc)  make_colour32(PixelColour pc)
222  {  {
223          return (pc.red << 16) | (pc.green << 8) | pc.blue;          if (g_xserver_be)
224            {
225                    return pc.red | (pc.green << 8) | (pc.blue << 16);
226            }
227            else
228            {
229                    return (pc.red << 16) | (pc.green << 8) | pc.blue;
230            }
231  }  }
232    
233  #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 281  translate_colour(uint32 colour)
281                          }                          }
282                          break;                          break;
283          }          }
         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;  
         }  
   
284          return colour;          return colour;
285  }  }
286    
# Line 321  translate8to32(uint8 * data, uint32 * ou Line 323  translate8to32(uint8 * data, uint32 * ou
323  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
324    
325  static void  static void
326  translate15to16(uint16 * data, uint16 * out, uint16 * end)  translate15to16(uint16 * data, uint8 * out, uint8 * end)
327  {  {
328            uint16 pixel;
329            uint16 value;
330    
331          while (out < end)          while (out < end)
332                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));          {
333                    pixel = *(data++);
334    
335                    if (g_host_be)
336                    {
337                    BSWAP16(pixel)}
338    
339                    value = make_colour16(split_colour15(pixel));
340    
341                    if (g_xserver_be)
342                    {
343                            *(out++) = value >> 8;
344                            *(out++) = value;
345                    }
346                    else
347                    {
348                            *(out++) = value;
349                            *(out++) = value >> 8;
350                    }
351            }
352  }  }
353    
354  static void  static void
355  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(uint16 * data, uint8 * out, uint8 * end)
356  {  {
357          uint32 value;          uint32 value;
358            uint16 pixel;
359    
360          while (out < end)          while (out < end)
361          {          {
362                  value = make_colour24(split_colour15(*(data++)));                  pixel = *(data++);
363                  *(out++) = value;  
364                  *(out++) = value >> 8;                  if (g_host_be)
365                  *(out++) = value >> 16;                  {
366                    BSWAP16(pixel)}
367    
368                    value = make_colour24(split_colour15(pixel));
369                    if (g_xserver_be)
370                    {
371                            *(out++) = value >> 16;
372                            *(out++) = value >> 8;
373                            *(out++) = value;
374                    }
375                    else
376                    {
377                            *(out++) = value;
378                            *(out++) = value >> 8;
379                            *(out++) = value >> 16;
380                    }
381          }          }
382  }  }
383    
384  static void  static void
385  translate15to32(uint16 * data, uint32 * out, uint32 * end)  translate15to32(uint16 * data, uint8 * out, uint8 * end)
386  {  {
387            uint16 pixel;
388            uint32 value;
389    
390          while (out < end)          while (out < end)
391                  *(out++) = make_colour32(split_colour15(*(data++)));          {
392                    pixel = *(data++);
393    
394                    if (g_host_be)
395                    {
396                            BSWAP16(pixel);
397                    }
398    
399                    value = make_colour32(split_colour15(pixel));
400    
401                    if (g_xserver_be)
402                    {
403                            *(out++) = value >> 24;
404                            *(out++) = value >> 16;
405                            *(out++) = value >> 8;
406                            *(out++) = value;
407                    }
408                    else
409                    {
410                            *(out++) = value;
411                            *(out++) = value >> 8;
412                            *(out++) = value >> 16;
413                            *(out++) = value >> 24;
414                    }
415            }
416  }  }
417    
418  static void  static void
419  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate16to16(uint16 * data, uint16 * out, uint16 * end)
420  {  {
421          while (out < end)          uint16 value;
422                  *(out++) = (uint16) (*(data++));  
423            if (g_xserver_be)
424            {
425                    while (out < end)
426                    {
427                            value = *data;
428                            BSWAP16(value);
429                            *out = value;
430                            data++;
431                            out++;
432                    }
433    
434            }
435            else
436            {
437                    while (out < end)
438                    {
439                            *out = *data;
440                            out++;
441                            data++;
442                    }
443            }
444  }  }
445    
446    
# Line 360  static void Line 448  static void
448  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
449  {  {
450          uint32 value;          uint32 value;
451            uint16 pixel;
452    
453          while (out < end)          while (out < end)
454          {          {
455                  value = make_colour24(split_colour16(*(data++)));                  pixel = *(data++);
456                  *(out++) = value;  
457                  *(out++) = value >> 8;                  if (g_host_be)
458                  *(out++) = value >> 16;                  {
459                    BSWAP16(pixel)}
460    
461                    value = make_colour24(split_colour16(pixel));
462    
463                    if (g_xserver_be)
464                    {
465                            *(out++) = value >> 16;
466                            *(out++) = value >> 8;
467                            *(out++) = value;
468                    }
469                    else
470                    {
471                            *(out++) = value;
472                            *(out++) = value >> 8;
473                            *(out++) = value >> 16;
474                    }
475          }          }
476  }  }
477    
478  static void  static void
479  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint8 * out, uint8 * end)
480  {  {
481            uint16 pixel;
482            uint32 value;
483    
484          while (out < end)          while (out < end)
485                  *(out++) = make_colour32(split_colour16(*(data++)));          {
486                    pixel = *(data++);
487    
488                    if (g_host_be)
489                    {
490                    BSWAP16(pixel)}
491    
492                    value = make_colour32(split_colour16(pixel));
493    
494                    if (g_xserver_be)
495                    {
496                            *(out++) = value >> 24;
497                            *(out++) = value >> 16;
498                            *(out++) = value >> 8;
499                            *(out++) = value;
500                    }
501                    else
502                    {
503                            *(out++) = value;
504                            *(out++) = value >> 8;
505                            *(out++) = value >> 16;
506                            *(out++) = value >> 24;
507                    }
508            }
509  }  }
510    
511  static void  static void
512  translate24to16(uint8 * data, uint16 * out, uint16 * end)  translate24to16(uint8 * data, uint8 * out, uint8 * end)
513  {  {
514          uint32 pixel = 0;          uint32 pixel = 0;
515            uint16 value;
516          while (out < end)          while (out < end)
517          {          {
518                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
519                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
520                  pixel |= *(data++);                  pixel |= *(data++);
521                  *(out++) = (uint16) make_colour16(split_colour24(pixel));  
522                    value = (uint16) make_colour16(split_colour24(pixel));
523    
524                    if (g_xserver_be)
525                    {
526                            *(out++) = value >> 8;
527                            *(out++) = value;
528                    }
529                    else
530                    {
531                            *(out++) = value;
532                            *(out++) = value >> 8;
533                    }
534          }          }
535  }  }
536    
# Line 400  translate24to24(uint8 * data, uint8 * ou Line 544  translate24to24(uint8 * data, uint8 * ou
544  }  }
545    
546  static void  static void
547  translate24to32(uint8 * data, uint32 * out, uint32 * end)  translate24to32(uint8 * data, uint8 * out, uint8 * end)
548  {  {
         uint32 pixel = 0;  
549          while (out < end)          while (out < end)
550          {          {
551                  pixel = *(data++);                  if (g_xserver_be)
552                  pixel |= *(data++) << 8;                  {
553                  pixel |= *(data++) << 16;                          *(out++) = 0x00;
554                  *(out++) = pixel;                          *(out++) = *(data++);
555                            *(out++) = *(data++);
556                            *(out++) = *(data++);
557                    }
558                    else
559                    {
560                            *(out++) = *(data++);
561                            *(out++) = *(data++);
562                            *(out++) = *(data++);
563                            *(out++) = 0x00;
564                    }
565          }          }
566  }  }
567    
# Line 425  translate_image(int width, int height, u Line 578  translate_image(int width, int height, u
578                          switch (g_bpp)                          switch (g_bpp)
579                          {                          {
580                                  case 32:                                  case 32:
581                                          translate24to32(data, (uint32 *) out, (uint32 *) end);                                          translate24to32(data, out, end);
582                                          break;                                          break;
583                                  case 24:                                  case 24:
584                                          translate24to24(data, out, end);                                          translate24to24(data, out, end);
585                                          break;                                          break;
586                                  case 16:                                  case 16:
587                                          translate24to16(data, (uint16 *) out, (uint16 *) end);                                          translate24to16(data, out, end);
588                                          break;                                          break;
589                          }                          }
590                          break;                          break;
# Line 439  translate_image(int width, int height, u Line 592  translate_image(int width, int height, u
592                          switch (g_bpp)                          switch (g_bpp)
593                          {                          {
594                                  case 32:                                  case 32:
595                                          translate16to32((uint16 *) data, (uint32 *) out,                                          translate16to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
596                                          break;                                          break;
597                                  case 24:                                  case 24:
598                                          translate16to24((uint16 *) data, out, end);                                          translate16to24((uint16 *) data, out, end);
# Line 455  translate_image(int width, int height, u Line 607  translate_image(int width, int height, u
607                          switch (g_bpp)                          switch (g_bpp)
608                          {                          {
609                                  case 32:                                  case 32:
610                                          translate15to32((uint16 *) data, (uint32 *) out,                                          translate15to32((uint16 *) data, out, end);
                                                         (uint32 *) end);  
611                                          break;                                          break;
612                                  case 24:                                  case 24:
613                                          translate15to24((uint16 *) data, out, end);                                          translate15to24((uint16 *) data, out, end);
614                                          break;                                          break;
615                                  case 16:                                  case 16:
616                                          translate15to16((uint16 *) data, (uint16 *) out,                                          translate15to16((uint16 *) data, out, end);
                                                         (uint16 *) end);  
617                                          break;                                          break;
618                          }                          }
619                          break;                          break;
# Line 570  ui_init(void) Line 720  ui_init(void)
720          g_host_be = !(BOOL) (*(uint8 *) (&test));          g_host_be = !(BOOL) (*(uint8 *) (&test));
721          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);          g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
722    
723          if ((g_width == 0) || (g_height == 0))          /*
724             * Determine desktop size
725             */
726            if (g_width < 0)
727            {
728                    /* Percent of screen */
729                    g_height = HeightOfScreen(g_screen) * (-g_width) / 100;
730                    g_width = WidthOfScreen(g_screen) * (-g_width) / 100;
731            }
732            else if (g_width == 0)
733          {          {
734                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
735                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
# Line 587  ui_init(void) Line 746  ui_init(void)
746                          g_height = 600;                          g_height = 600;
747                  }                  }
748          }          }
749            else if (g_fullscreen)
         if (g_fullscreen)  
750          {          {
751                  g_width = WidthOfScreen(g_screen);                  g_width = WidthOfScreen(g_screen);
752                  g_height = HeightOfScreen(g_screen);                  g_height = HeightOfScreen(g_screen);
# Line 610  ui_init(void) Line 768  ui_init(void)
768    
769          g_mod_map = XGetModifierMapping(g_display);          g_mod_map = XGetModifierMapping(g_display);
770    
771            xkeymap_init();
772    
773          if (g_enable_compose)          if (g_enable_compose)
774                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);                  g_IM = XOpenIM(g_display, NULL, NULL, NULL);
775    
         xkeymap_init();  
776          xclip_init();          xclip_init();
777    
778          /* todo take this out when high colour is done */          /* todo take this out when high colour is done */
# Line 833  xwin_process_events(void) Line 992  xwin_process_events(void)
992                                  if (tr.scancode == 0)                                  if (tr.scancode == 0)
993                                          break;                                          break;
994    
995                                  save_remote_modifiers();                                  save_remote_modifiers(tr.scancode);
996                                  ensure_remote_modifiers(ev_time, tr);                                  ensure_remote_modifiers(ev_time, tr);
997                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
998                                  restore_remote_modifiers(ev_time);                                  restore_remote_modifiers(ev_time, tr.scancode);
999    
1000                                  break;                                  break;
1001    
# Line 1029  int Line 1188  int
1188  ui_select(int rdp_socket)  ui_select(int rdp_socket)
1189  {  {
1190          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;
1191          fd_set rfds;          fd_set rfds, wfds;
   
         FD_ZERO(&rfds);  
1192    
1193          while (True)          while (True)
1194          {          {
# Line 1041  ui_select(int rdp_socket) Line 1198  ui_select(int rdp_socket)
1198                          return 0;                          return 0;
1199    
1200                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
1201                    FD_ZERO(&wfds);
1202                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
1203                  FD_SET(g_x_socket, &rfds);                  FD_SET(g_x_socket, &rfds);
1204    
1205                  switch (select(n, &rfds, NULL, NULL, NULL))  #ifdef WITH_RDPSND
1206                    /* FIXME: there should be an API for registering fds */
1207                    if (g_rdpsnd && g_dsp_busy)
1208                    {
1209                            FD_SET(g_dsp_fd, &wfds);
1210                            n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
1211                    }
1212    #endif
1213    
1214                    switch (select(n, &rfds, &wfds, NULL, NULL))
1215                  {                  {
1216                          case -1:                          case -1:
1217                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
# Line 1055  ui_select(int rdp_socket) Line 1222  ui_select(int rdp_socket)
1222    
1223                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
1224                          return 1;                          return 1;
1225    
1226    #ifdef WITH_RDPSND
1227                    if (g_rdpsnd && g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds))
1228                            wave_out_play();
1229    #endif
1230          }          }
1231  }  }
1232    
# Line 1430  ui_patblt(uint8 opcode, Line 1602  ui_patblt(uint8 opcode,
1602                  case 2: /* Hatch */                  case 2: /* Hatch */
1603                          fill = (Pixmap) ui_create_glyph(8, 8,                          fill = (Pixmap) ui_create_glyph(8, 8,
1604                                                          hatch_patterns + brush->pattern[0] * 8);                                                          hatch_patterns + brush->pattern[0] * 8);
1605                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(fgcolour);
1606                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(bgcolour);
1607                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
1608                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
1609                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);

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

  ViewVC Help
Powered by ViewVC 1.1.26