/[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 118 by astrand, Wed Sep 11 11:45:20 2002 UTC revision 164 by astrand, Mon Sep 16 13:19:54 2002 UTC
# Line 34  extern BOOL fullscreen; Line 34  extern BOOL fullscreen;
34  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
35  extern char title[];  extern char title[];
36    
37  Display *display = NULL;  Display *display;
38  static int x_socket;  static int x_socket;
39    static Screen *screen;
40  static Window wnd;  static Window wnd;
41  static GC gc;  static GC gc;
42  static Visual *visual;  static Visual *visual;
43  static int depth;  static int depth;
44  static int bpp;  static int bpp;
 static int dpy_width;  
 static int dpy_height;  
45    
46  /* endianness */  /* endianness */
47  static BOOL host_be;  static BOOL host_be;
# Line 62  static Pixmap backstore; Line 61  static Pixmap backstore;
61  /* colour maps */  /* colour maps */
62  static BOOL owncolmap;  static BOOL owncolmap;
63  static Colormap xcolmap;  static Colormap xcolmap;
 static uint32 white;  
64  static uint32 *colmap;  static uint32 *colmap;
 static XIM IM = NULL;  
 static XIC IC = NULL;  
65    
66  /* Compose support */  /* Compose support */
67  BOOL enable_compose = False;  BOOL enable_compose = False;
68    static XIM IM = NULL;
69    static XIC IC = NULL;
70    
71  /* toggle fullscreen globals */  /* toggle fullscreen globals */
 static XSetWindowAttributes attribs;  
72  static unsigned long input_mask;  static unsigned long input_mask;
73    
74  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
# Line 281  get_key_state(int keysym) Line 278  get_key_state(int keysym)
278          return (current_state & keysymMask) ? True : False;          return (current_state & keysymMask) ? True : False;
279  }  }
280    
281    static void
282  BOOL  xwin_map_window()
 ui_init()  
 {  
         Screen *screen;  
         display = XOpenDisplay(NULL);  
         if (display == NULL)  
         {  
                 error("Failed to open display\n");  
                 return False;  
         }  
         if (fullscreen)  
         {  
                 screen = DefaultScreenOfDisplay(display);  
                 width = WidthOfScreen(screen);  
                 height = HeightOfScreen(screen);  
         }  
         return True;  
 }  
   
 void  
 ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask)  
283  {  {
         XClassHint *classhints;  
         XSizeHints *sizehints;  
284          XEvent xevent;          XEvent xevent;
         Screen *screen;  
   
         screen = DefaultScreenOfDisplay(display);  
   
         wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos,  
                             ypos, width, height, 0, CopyFromParent,  
                             InputOutput, CopyFromParent, valuemask, &attribs);  
   
   
         XStoreName(display, wnd, title);  
   
         classhints = XAllocClassHint();  
         if (classhints != NULL)  
         {  
                 classhints->res_name = classhints->res_class = "rdesktop";  
                 XSetClassHint(display, wnd, classhints);  
                 XFree(classhints);  
         }  
   
         sizehints = XAllocSizeHints();  
         if (sizehints)  
         {  
                 sizehints->flags = PMinSize | PMaxSize;  
                 sizehints->min_width = sizehints->max_width = width;  
                 sizehints->min_height = sizehints->max_height = height;  
                 XSetWMNormalHints(display, wnd, sizehints);  
                 XFree(sizehints);  
         }  
   
         if (enable_compose)  
                 input_mask |= init_inputmethod();  
   
         XSelectInput(display, wnd, input_mask);  
   
         gc = XCreateGC(display, wnd, 0, NULL);  
285    
286          XMapWindow(display, wnd);          XMapWindow(display, wnd);
287    
288          /* Wait for VisibilityNotify Event */          /* wait for VisibilityChange */
289          for (;;)          XMaskEvent(display, VisibilityChangeMask, &xevent);
         {  
                 XNextEvent(display, &xevent);  
                 if (xevent.type == VisibilityNotify)  
                         break;  
         }  
   
         if (ownbackstore)  
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
290    
291          /* clear the window so that cached data is not viewed upon start... */          if (fullscreen)
292          XSetBackground(display, gc, 0);                  XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
         XSetForeground(display, gc, 0);  
         FILL_RECTANGLE(0, 0, width, height);  
         /* make sure the window is focused */  
         XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);  
293  }  }
294    
295  BOOL  BOOL
296  ui_create_window()  ui_init()
297  {  {
298          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
         Screen *screen;  
299          uint16 test;          uint16 test;
300          int i;          int i;
301    
302            display = XOpenDisplay(NULL);
303            if (display == NULL)
304            {
305                    error("Failed to open display\n");
306                    return False;
307            }
308    
309          x_socket = ConnectionNumber(display);          x_socket = ConnectionNumber(display);
310          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
311          visual = DefaultVisualOfScreen(screen);          visual = DefaultVisualOfScreen(screen);
# Line 404  ui_create_window() Line 338  ui_create_window()
338          else          else
339                  xcolmap = DefaultColormapOfScreen(screen);                  xcolmap = DefaultColormapOfScreen(screen);
340    
341            if (DoesBackingStore(screen) == NotUseful)
342                    ownbackstore = True;
343    
344          test = 1;          test = 1;
345          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
346          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
347    
348          white = WhitePixelOfScreen(screen);          if (fullscreen)
349            {
350                    width = WidthOfScreen(screen);
351                    height = HeightOfScreen(screen);
352            }
353    
354            /* make sure width is a multiple of 4 */
355            width = (width + 3) & ~3;
356    
357            xkeymap_init();
358            return True;
359    }
360    
361    BOOL
362    ui_create_window()
363    {
364            XSetWindowAttributes attribs;
365            XClassHint *classhints;
366            XSizeHints *sizehints;
367            XEvent xevent;
368    
369          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(screen);
370          attribs.backing_store = DoesBackingStore(screen);          attribs.backing_store = ownbackstore ? NotUseful : Always;
371            attribs.override_redirect = fullscreen;
372            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,
373                                0, CopyFromParent, InputOutput, CopyFromParent,
374                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
375    
376          if (attribs.backing_store == NotUseful)          if (ownbackstore)
377                  ownbackstore = True;                  backstore = XCreatePixmap(display, wnd, width, height, depth);
378    
379          dpy_width = WidthOfScreen(screen);          XStoreName(display, wnd, title);
         dpy_height = HeightOfScreen(screen);  
380    
381          if (fullscreen)          classhints = XAllocClassHint();
382            if (classhints != NULL)
383          {          {
384                  attribs.override_redirect = True;                  classhints->res_name = classhints->res_class = "rdesktop";
385                  width = dpy_width;                  XSetClassHint(display, wnd, classhints);
386                  height = dpy_height;                  XFree(classhints);
387          }          }
388          else  
389            sizehints = XAllocSizeHints();
390            if (sizehints)
391          {          {
392                  attribs.override_redirect = False;                  sizehints->flags = PMinSize | PMaxSize;
393                    sizehints->min_width = sizehints->max_width = width;
394                    sizehints->min_height = sizehints->max_height = height;
395                    XSetWMNormalHints(display, wnd, sizehints);
396                    XFree(sizehints);
397          }          }
398    
399          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
# Line 436  ui_create_window() Line 403  ui_create_window()
403                  input_mask |= EnterWindowMask | LeaveWindowMask;                  input_mask |= EnterWindowMask | LeaveWindowMask;
404          if (sendmotion)          if (sendmotion)
405                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
   
406          if (ownbackstore)          if (ownbackstore)
407                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
408            if (enable_compose)
409                    input_mask |= init_inputmethod();
410    
411          if (fullscreen)          XSelectInput(display, wnd, input_mask);
                 ui_create_window_obj(0, 0, width, height,  
                                      CWBackingStore | CWBackPixel | CWOverrideRedirect);  
         else  
                 ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel);  
412    
413          xkeymap_init2();          xwin_map_window();
414    
415            /* clear the window so that cached data is not seen */
416            gc = XCreateGC(display, wnd, 0, NULL);
417            XSetForeground(display, gc, 0);
418            FILL_RECTANGLE(0, 0, width, height);
419    
420          return True;          return True;
421  }  }
# Line 466  ui_destroy_window() Line 435  ui_destroy_window()
435          display = NULL;          display = NULL;
436  }  }
437    
438  void  static void
439  reset_keys()  xwin_reset_keys()
440  {  {
441          /* reset keys */          /* reset keys */
442          uint32 ev_time;          uint32 ev_time;
# Line 481  reset_keys() Line 450  reset_keys()
450  }  }
451    
452  void  void
453  toggle_fullscreen()  xwin_toggle_fullscreen()
454  {  {
455          /* save window contents */          XEvent xevent;
456          Pixmap pixmap;          XSetWindowAttributes attribs;
457          pixmap = XCreatePixmap(display, wnd, width, height, depth);          int newwidth, newheight;
458          if (ownbackstore)  
459                  XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0);          fullscreen = !fullscreen;
460          else          newwidth = fullscreen ? WidthOfScreen(screen) : width;
461                  XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0);          newheight = fullscreen ? HeightOfScreen(screen) : height;
462          fullscreen = fullscreen ? False : True;  
463          close_inputmethod();          XUnmapWindow(display, wnd);
464          if (ownbackstore)          attribs.override_redirect = fullscreen;
465                  XFreePixmap(display, backstore);          XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight);
466          XFreeGC(display, gc);          XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs);
467          XDestroyWindow(display, wnd);          xwin_map_window();
         if (fullscreen)  
         {  
                 attribs.override_redirect = True;  
                 ui_create_window_obj(0, 0, dpy_width, dpy_height,  
                                      CWBackingStore | CWBackPixel | CWOverrideRedirect);  
         }  
         else  
         {  
                 attribs.override_redirect = False;  
                 ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel);  
         }  
         ui_set_cursor(cache_get_cursor(0));  
         ui_move_pointer(width / 2, height / 2);  
         reset_keys();  
         /* restore window contents */  
         if (ownbackstore)  
                 XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0);  
         XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0);  
         XFreePixmap(display, pixmap);  
468  }  }
469    
470    /* Process all events in Xlib queue */
471  static void  static void
472  xwin_process_events()  xwin_process_events()
473  {  {
474          XEvent xevent;          XEvent xevent;
   
475          KeySym keysym;          KeySym keysym;
476          uint16 button, flags;          uint16 button, flags;
477          uint32 ev_time;          uint32 ev_time;
# Line 530  xwin_process_events() Line 480  xwin_process_events()
480          char str[256];          char str[256];
481          Status status;          Status status;
482    
483          /* Refresh keyboard mapping if it has changed. This is important for          while (XPending(display) > 0)
            Xvnc, since it allocates keycodes dynamically */  
         if (XCheckTypedEvent(display, MappingNotify, &xevent))  
484          {          {
485                  if (xevent.xmapping.request == MappingKeyboard                  XNextEvent(display, &xevent);
                     || xevent.xmapping.request == MappingModifier)  
                         XRefreshKeyboardMapping(&xevent.xmapping);  
         }  
486    
         while (XCheckMaskEvent(display, ~0, &xevent))  
         {  
487                  if (enable_compose && (XFilterEvent(&xevent, None) == True))                  if (enable_compose && (XFilterEvent(&xevent, None) == True))
488                  {                  {
489                          DEBUG_KBD(("Filtering event\n"));                          DEBUG_KBD(("Filtering event\n"));
# Line 628  xwin_process_events() Line 571  xwin_process_events()
571                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
572                                  break;                                  break;
573    
                         case FocusIn:  
                                 /* fall through */  
574                          case EnterNotify:                          case EnterNotify:
575                                  if (grab_keyboard)                                  if (grab_keyboard)
576                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(display, wnd, True,
577                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
578                                  break;                                  break;
579    
                         case FocusOut:  
                                 reset_keys();  
                                 /* fall through */  
580                          case LeaveNotify:                          case LeaveNotify:
581                                  if (grab_keyboard)                                  if (grab_keyboard)
582                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(display, CurrentTime);
583                                  break;                                  break;
584    
585                            case FocusOut:
586                                    xwin_reset_keys();
587                                    break;
588    
589                          case Expose:                          case Expose:
590                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(display, backstore, wnd, gc,
591                                            xevent.xexpose.x, xevent.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
# Line 651  xwin_process_events() Line 593  xwin_process_events()
593                                            xevent.xexpose.height,                                            xevent.xexpose.height,
594                                            xevent.xexpose.x, xevent.xexpose.y);                                            xevent.xexpose.x, xevent.xexpose.y);
595                                  break;                                  break;
596    
597                            case MappingNotify:
598                                    /* Refresh keyboard mapping if it has changed. This is important for
599                                       Xvnc, since it allocates keycodes dynamically */
600                                    if (xevent.xmapping.request == MappingKeyboard
601                                        || xevent.xmapping.request == MappingModifier)
602                                            XRefreshKeyboardMapping(&xevent.xmapping);
603                                    break;
604    
605                  }                  }
606          }          }
607  }  }
# Line 665  ui_select(int rdp_socket) Line 616  ui_select(int rdp_socket)
616    
617          while (True)          while (True)
618          {          {
619                    /* Process any events already waiting */
620                    xwin_process_events();
621    
622                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
623                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
624                  if (display != NULL)                  FD_SET(x_socket, &rfds);
                 {  
                         FD_SET(x_socket, &rfds);  
                         XFlush(display);  
                 }  
625    
626                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, NULL, NULL, NULL))
627                  {                  {
# Line 682  ui_select(int rdp_socket) Line 632  ui_select(int rdp_socket)
632                                  continue;                                  continue;
633                  }                  }
634    
                 if (FD_ISSET(x_socket, &rfds))  
                         xwin_process_events();  
   
635                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
636                          return;                          return;
637          }          }
# Line 908  ui_create_colourmap(COLOURMAP * colours) Line 855  ui_create_colourmap(COLOURMAP * colours)
855                          if (XAllocColor(display, xcolmap, &xentry) != 0)                          if (XAllocColor(display, xcolmap, &xentry) != 0)
856                                  colour = xentry.pixel;                                  colour = xentry.pixel;
857                          else                          else
858                                  colour = white;                                  colour = WhitePixelOfScreen(screen);
859    
860                          /* byte swap here to make translate_image faster */                          /* byte swap here to make translate_image faster */
861                          map[i] = translate_colour(colour);                          map[i] = translate_colour(colour);

Legend:
Removed from v.118  
changed lines
  Added in v.164

  ViewVC Help
Powered by ViewVC 1.1.26