/[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 208 by matthewc, Fri Sep 27 01:04:34 2002 UTC revision 275 by astrand, Tue Nov 19 14:48:02 2002 UTC
# Line 29  extern int height; Line 29  extern int height;
29  extern BOOL sendmotion;  extern BOOL sendmotion;
30  extern BOOL fullscreen;  extern BOOL fullscreen;
31  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
32    extern BOOL hide_decorations;
33  extern char title[];  extern char title[];
34  BOOL enable_compose = False;  BOOL enable_compose = False;
35    BOOL focused;
36    BOOL mouse_in_wnd;
37    
38  Display *display;  Display *display;
39  static int x_socket;  static int x_socket;
# Line 44  static XIM IM; Line 47  static XIM IM;
47  static XIC IC;  static XIC IC;
48  static XModifierKeymap *mod_map;  static XModifierKeymap *mod_map;
49  static Cursor current_cursor;  static Cursor current_cursor;
50    static Atom protocol_atom, kill_atom;
51    
52  /* endianness */  /* endianness */
53  static BOOL host_be;  static BOOL host_be;
# Line 53  static BOOL xserver_be; Line 57  static BOOL xserver_be;
57  static BOOL ownbackstore;  static BOOL ownbackstore;
58  static Pixmap backstore;  static Pixmap backstore;
59    
60    /* MWM decorations */
61    #define MWM_HINTS_DECORATIONS   (1L << 1)
62    #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
63    typedef struct
64    {
65            unsigned long flags;
66            unsigned long functions;
67            unsigned long decorations;
68            long inputMode;
69            unsigned long status;
70    }
71    PropMotifWmHints;
72    
73    
74  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
75  { \  { \
76          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(display, wnd, gc, x, y, cx, cy); \
# Line 89  static int rop2_map[] = { Line 107  static int rop2_map[] = {
107  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }  #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }
108  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
109    
110    void
111    mwm_hide_decorations(void)
112    {
113            PropMotifWmHints motif_hints;
114            Atom hintsatom;
115    
116            /* setup the property */
117            motif_hints.flags = MWM_HINTS_DECORATIONS;
118            motif_hints.decorations = 0;
119    
120            /* get the atom for the property */
121            hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False);
122            if (!hintsatom)
123            {
124                    error("Failed to get atom _MOTIF_WM_HINTS\n");
125                    return;
126            }
127    
128            XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace,
129                            (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
130    }
131    
132  static void  static void
133  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8(uint8 * data, uint8 * out, uint8 * end)
134  {  {
# Line 184  translate_colour(uint32 colour) Line 224  translate_colour(uint32 colour)
224  }  }
225    
226  BOOL  BOOL
227  get_key_state(uint32 keysym, unsigned int state)  get_key_state(unsigned int state, uint32 keysym)
228  {  {
229          int modifierpos, key, keysymMask = 0;          int modifierpos, key, keysymMask = 0;
230          int offset;          int offset;
# Line 218  ui_init(void) Line 258  ui_init(void)
258          display = XOpenDisplay(NULL);          display = XOpenDisplay(NULL);
259          if (display == NULL)          if (display == NULL)
260          {          {
261                  error("Failed to open display\n");                  error("Failed to open display: %s\n", XDisplayName(NULL));
262                  return False;                  return False;
263          }          }
264    
# Line 259  ui_init(void) Line 299  ui_init(void)
299          host_be = !(BOOL) (*(uint8 *) (&test));          host_be = !(BOOL) (*(uint8 *) (&test));
300          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
301    
302            if ((width == 0) || (height == 0))
303            {
304                    /* Fetch geometry from _NET_WORKAREA */
305                    uint32 xpos, ypos;
306    
307                    if (get_current_workarea(&xpos, &ypos, &width, &height) < 0)
308                    {
309                            error("Failed to get workarea.\n");
310                            error("Perhaps your window manager does not support EWMH?\n");
311                            error("Defaulting to geometry 800x600\n");
312                            width = 800;
313                            height = 600;
314                    }
315            }
316    
317          if (fullscreen)          if (fullscreen)
318          {          {
319                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
# Line 326  ui_create_window(void) Line 381  ui_create_window(void)
381    
382          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
383    
384            if (hide_decorations)
385                    mwm_hide_decorations();
386    
387          classhints = XAllocClassHint();          classhints = XAllocClassHint();
388          if (classhints != NULL)          if (classhints != NULL)
389          {          {
# Line 351  ui_create_window(void) Line 409  ui_create_window(void)
409                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
410          if (ownbackstore)          if (ownbackstore)
411                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
412            if (fullscreen || grab_keyboard)
413                    input_mask |= EnterWindowMask;
414            if (grab_keyboard)
415                    input_mask |= LeaveWindowMask;
416    
417          if (IM != NULL)          if (IM != NULL)
418          {          {
# Line 372  ui_create_window(void) Line 434  ui_create_window(void)
434          }          }
435          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
436    
437          if (fullscreen)          focused = False;
438                  XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);          mouse_in_wnd = False;
439    
440            /* handle the WM_DELETE_WINDOW protocol */
441            protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True);
442            kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True);
443            XSetWMProtocols(display, wnd, &kill_atom, 1);
444    
445          return True;          return True;
446  }  }
# Line 412  xwin_toggle_fullscreen(void) Line 479  xwin_toggle_fullscreen(void)
479          }          }
480  }  }
481    
482  /* Process all events in Xlib queue */  /* Process all events in Xlib queue
483  static void     Returns 0 after user quit, 1 otherwise */
484    static int
485  xwin_process_events(void)  xwin_process_events(void)
486  {  {
487          XEvent xevent;          XEvent xevent;
# Line 441  xwin_process_events(void) Line 509  xwin_process_events(void)
509    
510                  switch (xevent.type)                  switch (xevent.type)
511                  {                  {
512                            case ClientMessage:
513                                    /* the window manager told us to quit */
514                                    if ((xevent.xclient.message_type == protocol_atom)
515                                        && (xevent.xclient.data.l[0] == kill_atom))
516                                            /* Quit */
517                                            return 0;
518                                    break;
519    
520                          case KeyPress:                          case KeyPress:
521                                  if (IC != NULL)                                  if (IC != NULL)
522                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
# Line 463  xwin_process_events(void) Line 539  xwin_process_events(void)
539                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
540                                  }                                  }
541    
542                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)));                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym,
543                                               get_ksname(keysym)));
544    
545                                  ev_time = time(NULL);                                  ev_time = time(NULL);
546                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))                                  if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True))
# Line 519  xwin_process_events(void) Line 596  xwin_process_events(void)
596                                  break;                                  break;
597    
598                          case FocusIn:                          case FocusIn:
599                                  XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state);                                  if (xevent.xfocus.mode == NotifyGrab)
600                                            break;
601                                    focused = True;
602                                    XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy,
603                                                  &dummy, &dummy, &state);
604                                  reset_modifier_keys(state);                                  reset_modifier_keys(state);
605                                  if (grab_keyboard)                                  if (grab_keyboard && mouse_in_wnd)
606                                          XGrabKeyboard(display, wnd, True,                                          XGrabKeyboard(display, wnd, True,
607                                                        GrabModeAsync, GrabModeAsync, CurrentTime);                                                        GrabModeAsync, GrabModeAsync, CurrentTime);
608                                  break;                                  break;
609    
610                          case FocusOut:                          case FocusOut:
611                                    if (xevent.xfocus.mode == NotifyUngrab)
612                                            break;
613                                    focused = False;
614                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)                                  if (xevent.xfocus.mode == NotifyWhileGrabbed)
615                                          XUngrabKeyboard(display, CurrentTime);                                          XUngrabKeyboard(display, CurrentTime);
616                                  break;                                  break;
617    
618                            case EnterNotify:
619                                    /* we only register for this event when in fullscreen mode */
620                                    /* or grab_keyboard */
621                                    mouse_in_wnd = True;
622                                    if (fullscreen)
623                                    {
624                                            XSetInputFocus(display, wnd, RevertToPointerRoot,
625                                                           CurrentTime);
626                                            break;
627                                    }
628                                    if (focused)
629                                            XGrabKeyboard(display, wnd, True,
630                                                          GrabModeAsync, GrabModeAsync, CurrentTime);
631                                    break;
632    
633                            case LeaveNotify:
634                                    /* we only register for this event when grab_keyboard */
635                                    mouse_in_wnd = False;
636                                    XUngrabKeyboard(display, CurrentTime);
637                                    break;
638    
639                          case Expose:                          case Expose:
640                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(display, backstore, wnd, gc,
641                                            xevent.xexpose.x, xevent.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
# Line 555  xwin_process_events(void) Line 660  xwin_process_events(void)
660    
661                  }                  }
662          }          }
663            /* Keep going */
664            return 1;
665  }  }
666    
667  void  /* Returns 0 after user quit, 1 otherwise */
668    int
669  ui_select(int rdp_socket)  ui_select(int rdp_socket)
670  {  {
671          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;
# Line 568  ui_select(int rdp_socket) Line 676  ui_select(int rdp_socket)
676          while (True)          while (True)
677          {          {
678                  /* Process any events already waiting */                  /* Process any events already waiting */
679                  xwin_process_events();                  if (!xwin_process_events())
680                            /* User quit */
681                            return 0;
682    
683                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
684                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
# Line 584  ui_select(int rdp_socket) Line 694  ui_select(int rdp_socket)
694                  }                  }
695    
696                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
697                          return;                          return 1;
698          }          }
699  }  }
700    
# Line 1100  ui_draw_text(uint8 font, uint8 flags, in Line 1210  ui_draw_text(uint8 font, uint8 flags, in
1210                                  else                                  else
1211                                  {                                  {
1212                                          error("this shouldn't be happening\n");                                          error("this shouldn't be happening\n");
1213                                          break;                                          exit(1);
1214                                  }                                  }
1215                                  /* this will move pointer from start to first character after FF command */                                  /* this will move pointer from start to first character after FF command */
1216                                  length -= i + 3;                                  length -= i + 3;

Legend:
Removed from v.208  
changed lines
  Added in v.275

  ViewVC Help
Powered by ViewVC 1.1.26