/[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 438 by jsorg71, Fri Aug 1 17:01:58 2003 UTC revision 447 by jsorg71, Thu Aug 21 23:23:15 2003 UTC
# Line 25  Line 25 
25  #include "rdesktop.h"  #include "rdesktop.h"
26  #include "xproto.h"  #include "xproto.h"
27    
28  extern int width;  extern int g_width;
29  extern int height;  extern int g_height;
30  extern BOOL sendmotion;  extern BOOL g_sendmotion;
31  extern BOOL fullscreen;  extern BOOL g_fullscreen;
32  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
33  extern BOOL hide_decorations;  extern BOOL hide_decorations;
34  extern char title[];  extern char title[];
35  extern int g_server_bpp;  extern int g_server_bpp;
36  extern int win_button_size;  extern int win_button_size;
37  BOOL enable_compose = False;  BOOL g_enable_compose = False;
38  BOOL focused;  BOOL g_focused;
39  BOOL mouse_in_wnd;  BOOL g_mouse_in_wnd;
40    
41  Display *display;  Display *display;
42  Time last_gesturetime;  Time last_gesturetime;
# Line 570  ui_init(void) Line 570  ui_init(void)
570          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
571          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
572    
573          if ((width == 0) || (height == 0))          if ((g_width == 0) || (g_height == 0))
574          {          {
575                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
576                  uint32 x, y, cx, cy;                  uint32 x, y, cx, cy;
577    
578                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
579                  {                  {
580                          width = cx;                          g_width = cx;
581                          height = cy;                          g_height = cy;
582                  }                  }
583                  else                  else
584                  {                  {
585                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");
586                          width = 800;                          g_width = 800;
587                          height = 600;                          g_height = 600;
588                  }                  }
589          }          }
590    
591          if (fullscreen)          if (g_fullscreen)
592          {          {
593                  width = WidthOfScreen(screen);                  g_width = WidthOfScreen(screen);
594                  height = HeightOfScreen(screen);                  g_height = HeightOfScreen(screen);
595          }          }
596    
597          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
598          width = (width + 3) & ~3;          g_width = (g_width + 3) & ~3;
599    
600          if (ownbackstore)          if (ownbackstore)
601          {          {
602                  backstore =                  backstore =
603                          XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);                          XCreatePixmap(display, RootWindowOfScreen(screen), g_width, g_height, depth);
604    
605                  /* clear to prevent rubbish being exposed at startup */                  /* clear to prevent rubbish being exposed at startup */
606                  XSetForeground(display, gc, BlackPixelOfScreen(screen));                  XSetForeground(display, gc, BlackPixelOfScreen(screen));
607                  XFillRectangle(display, backstore, gc, 0, 0, width, height);                  XFillRectangle(display, backstore, gc, 0, 0, g_width, g_height);
608          }          }
609    
610          mod_map = XGetModifierMapping(display);          mod_map = XGetModifierMapping(display);
611    
612          if (enable_compose)          if (g_enable_compose)
613                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
614    
615          xkeymap_init();          xkeymap_init();
# Line 647  ui_create_window(void) Line 647  ui_create_window(void)
647          long input_mask, ic_input_mask;          long input_mask, ic_input_mask;
648          XEvent xevent;          XEvent xevent;
649    
650          wndwidth = fullscreen ? WidthOfScreen(screen) : width;          wndwidth = g_fullscreen ? WidthOfScreen(screen) : g_width;
651          wndheight = fullscreen ? HeightOfScreen(screen) : height;          wndheight = g_fullscreen ? HeightOfScreen(screen) : g_height;
652    
653          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(screen);
654          attribs.backing_store = ownbackstore ? NotUseful : Always;          attribs.backing_store = ownbackstore ? NotUseful : Always;
655          attribs.override_redirect = fullscreen;          attribs.override_redirect = g_fullscreen;
656    
657          wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight,          wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight,
658                              0, CopyFromParent, InputOutput, CopyFromParent,                              0, CopyFromParent, InputOutput, CopyFromParent,
# Line 675  ui_create_window(void) Line 675  ui_create_window(void)
675          if (sizehints)          if (sizehints)
676          {          {
677                  sizehints->flags = PMinSize | PMaxSize;                  sizehints->flags = PMinSize | PMaxSize;
678                  sizehints->min_width = sizehints->max_width = width;                  sizehints->min_width = sizehints->max_width = g_width;
679                  sizehints->min_height = sizehints->max_height = height;                  sizehints->min_height = sizehints->max_height = g_height;
680                  XSetWMNormalHints(display, wnd, sizehints);                  XSetWMNormalHints(display, wnd, sizehints);
681                  XFree(sizehints);                  XFree(sizehints);
682          }          }
# Line 684  ui_create_window(void) Line 684  ui_create_window(void)
684          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
685                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
686    
687          if (sendmotion)          if (g_sendmotion)
688                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
689          if (ownbackstore)          if (ownbackstore)
690                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
691          if (fullscreen || grab_keyboard)          if (g_fullscreen || grab_keyboard)
692                  input_mask |= EnterWindowMask;                  input_mask |= EnterWindowMask;
693          if (grab_keyboard)          if (grab_keyboard)
694                  input_mask |= LeaveWindowMask;                  input_mask |= LeaveWindowMask;
# Line 713  ui_create_window(void) Line 713  ui_create_window(void)
713          }          }
714          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
715    
716          focused = False;          g_focused = False;
717          mouse_in_wnd = False;          g_mouse_in_wnd = False;
718    
719          /* handle the WM_DELETE_WINDOW protocol */          /* handle the WM_DELETE_WINDOW protocol */
720          protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);          protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);
# Line 741  xwin_toggle_fullscreen(void) Line 741  xwin_toggle_fullscreen(void)
741          if (!ownbackstore)          if (!ownbackstore)
742          {          {
743                  /* need to save contents of window */                  /* need to save contents of window */
744                  contents = XCreatePixmap(display, wnd, width, height, depth);                  contents = XCreatePixmap(display, wnd, g_width, g_height, depth);
745                  XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0);                  XCopyArea(display, wnd, contents, gc, 0, 0, g_width, g_height, 0, 0);
746          }          }
747    
748          ui_destroy_window();          ui_destroy_window();
749          fullscreen = !fullscreen;          g_fullscreen = !g_fullscreen;
750          ui_create_window();          ui_create_window();
751    
752          XDefineCursor(display, wnd, current_cursor);          XDefineCursor(display, wnd, current_cursor);
753    
754          if (!ownbackstore)          if (!ownbackstore)
755          {          {
756                  XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0);                  XCopyArea(display, contents, wnd, gc, 0, 0, g_width, g_height, 0, 0);
757                  XFreePixmap(display, contents);                  XFreePixmap(display, contents);
758          }          }
759  }  }
760    
761  /* Process all events in Xlib queue  /* Process all events in Xlib queue
762     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
763  static int  static int
764  xwin_process_events(void)  xwin_process_events(void)
# Line 877  xwin_process_events(void) Line 877  xwin_process_events(void)
877    
878                                          /*  Check from right to left: */                                          /*  Check from right to left: */
879    
880                                          if (xevent.xbutton.x >= width - win_button_size)                                          if (xevent.xbutton.x >= g_width - win_button_size)
881                                          {                                          {
882                                                  /* The close button, continue */                                                  /* The close button, continue */
883                                                  ;                                                  ;
884                                          }                                          }
885                                          else if (xevent.xbutton.x >= width - win_button_size * 2)                                          else if (xevent.xbutton.x >= g_width - win_button_size * 2)
886                                          {                                          {
887                                                  /* The maximize/restore button. Do not send to                                                  /* The maximize/restore button. Do not send to
888                                                     server.  It might be a good idea to change the                                                     server.  It might be a good idea to change the
889                                                     cursor or give some other visible indication                                                     cursor or give some other visible indication
890                                                     that rdesktop inhibited this click */                                                     that rdesktop inhibited this click */
891                                                  break;                                                  break;
892                                          }                                          }
893                                          else if (xevent.xbutton.x >= width - win_button_size * 3)                                          else if (xevent.xbutton.x >= g_width - win_button_size * 3)
894                                          {                                          {
895                                                  /* The minimize button. Iconify window. */                                                  /* The minimize button. Iconify window. */
896                                                  XIconifyWindow(display, wnd,                                                  XIconifyWindow(display, wnd,
# Line 905  xwin_process_events(void) Line 905  xwin_process_events(void)
905                                          else                                          else
906                                          {                                          {
907                                                  /* The title bar. */                                                  /* The title bar. */
908                                                  if ((xevent.type == ButtonPress) && !fullscreen                                                  if ((xevent.type == ButtonPress) && !g_fullscreen
909                                                      && hide_decorations)                                                      && hide_decorations)
910                                                  {                                                  {
911                                                          moving_wnd = True;                                                          moving_wnd = True;
# Line 930  xwin_process_events(void) Line 930  xwin_process_events(void)
930                                          break;                                          break;
931                                  }                                  }
932    
933                                  if (fullscreen && !focused)                                  if (g_fullscreen && !g_focused)
934                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(display, wnd, RevertToPointerRoot,
935                                                         CurrentTime);                                                         CurrentTime);
936                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
# Line 940  xwin_process_events(void) Line 940  xwin_process_events(void)
940                          case FocusIn:                          case FocusIn:
941                                  if (xevent.xfocus.mode == NotifyGrab)                                  if (xevent.xfocus.mode == NotifyGrab)
942                                          break;                                          break;
943                                  focused = True;                                  g_focused = True;
944                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy,                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy,
945                                                &dummy, &dummy, &state);                                                &dummy, &dummy, &state);
946                                  reset_modifier_keys(state);                                  reset_modifier_keys(state);
947                                  if (grab_keyboard && mouse_in_wnd)                                  if (grab_keyboard && g_mouse_in_wnd)
948                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(display, wnd, True,
949                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
950                                  break;                                  break;
# Line 952  xwin_process_events(void) Line 952  xwin_process_events(void)
952                          case FocusOut:                          case FocusOut:
953                                  if (xevent.xfocus.mode == NotifyUngrab)                                  if (xevent.xfocus.mode == NotifyUngrab)
954                                          break;                                          break;
955                                  focused = False;                                  g_focused = False;
956                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)
957                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(display, CurrentTime);
958                                  break;                                  break;
# Line 960  xwin_process_events(void) Line 960  xwin_process_events(void)
960                          case EnterNotify:                          case EnterNotify:
961                                  /* we only register for this event when in fullscreen mode */                                  /* we only register for this event when in fullscreen mode */
962                                  /* or grab_keyboard */                                  /* or grab_keyboard */
963                                  mouse_in_wnd = True;                                  g_mouse_in_wnd = True;
964                                  if (fullscreen)                                  if (g_fullscreen)
965                                  {                                  {
966                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(display, wnd, RevertToPointerRoot,
967                                                         CurrentTime);                                                         CurrentTime);
968                                          break;                                          break;
969                                  }                                  }
970                                  if (focused)                                  if (g_focused)
971                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(display, wnd, True,
972                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
973                                  break;                                  break;
974    
975                          case LeaveNotify:                          case LeaveNotify:
976                                  /* we only register for this event when grab_keyboard */                                  /* we only register for this event when grab_keyboard */
977                                  mouse_in_wnd = False;                                  g_mouse_in_wnd = False;
978                                  XUngrabKeyboard(display, CurrentTime);                                  XUngrabKeyboard(display, CurrentTime);
979                                  break;                                  break;
980    
# Line 1371  ui_reset_clip(void) Line 1371  ui_reset_clip(void)
1371    
1372          rect.x = 0;          rect.x = 0;
1373          rect.y = 0;          rect.y = 0;
1374          rect.width = width;          rect.width = g_width;
1375          rect.height = height;          rect.height = g_height;
1376          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);          XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);
1377  }  }
1378    

Legend:
Removed from v.438  
changed lines
  Added in v.447

  ViewVC Help
Powered by ViewVC 1.1.26