/[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 99 by jsorg71, Tue Aug 20 01:20:08 2002 UTC revision 101 by astrand, Mon Aug 26 17:12:43 2002 UTC
# Line 32  extern int height; Line 32  extern int height;
32  extern BOOL sendmotion;  extern BOOL sendmotion;
33  extern BOOL fullscreen;  extern BOOL fullscreen;
34  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
35    extern char title[];
36    
37  Display *display = NULL;  Display *display = NULL;
38  static int x_socket;  static int x_socket;
# Line 40  static GC gc; Line 41  static GC gc;
41  static Visual *visual;  static Visual *visual;
42  static int depth;  static int depth;
43  static int bpp;  static int bpp;
44    static int dpy_width;
45    static int dpy_height;
46    
47  /* endianness */  /* endianness */
48  static BOOL host_be;  static BOOL host_be;
# Line 67  static XIC IC = NULL; Line 70  static XIC IC = NULL;
70  /* Compose support */  /* Compose support */
71  BOOL enable_compose = False;  BOOL enable_compose = False;
72    
73    /* toggle fullscreen globals */
74    static XSetWindowAttributes attribs;
75    static unsigned long input_mask;
76    
77  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
78  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
79  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
# Line 260  ui_init() Line 267  ui_init()
267  }  }
268    
269  BOOL  BOOL
270  ui_create_window(char *title)  ui_create_window_obj(int xpos, int ypos, int width, int height, int valuemask)
271  {  {
         XSetWindowAttributes attribs;  
272          XClassHint *classhints;          XClassHint *classhints;
273          XSizeHints *sizehints;          XSizeHints *sizehints;
274          unsigned long input_mask;          XEvent xevent;
275            Screen *screen;
276    
277            screen = DefaultScreenOfDisplay(display);
278    
279            wnd = XCreateWindow(display, RootWindowOfScreen(screen), xpos,
280                                ypos, width, height, 0, CopyFromParent,
281                                InputOutput, CopyFromParent, valuemask, &attribs);
282    
283    
284            XStoreName(display, wnd, title);
285    
286            classhints = XAllocClassHint();
287            if (classhints != NULL)
288            {
289                    classhints->res_name = classhints->res_class = "rdesktop";
290                    XSetClassHint(display, wnd, classhints);
291                    XFree(classhints);
292            }
293    
294            sizehints = XAllocSizeHints();
295            if (sizehints)
296            {
297                    sizehints->flags = PMinSize | PMaxSize;
298                    sizehints->min_width = sizehints->max_width = width;
299                    sizehints->min_height = sizehints->max_height = height;
300                    XSetWMNormalHints(display, wnd, sizehints);
301                    XFree(sizehints);
302            }
303    
304            if (enable_compose)
305                    input_mask |= init_inputmethod();
306    
307            XSelectInput(display, wnd, input_mask);
308    
309            gc = XCreateGC(display, wnd, 0, NULL);
310    
311            XMapWindow(display, wnd);
312    
313            /* Wait for VisibilityNotify Event */
314            for (;;)
315            {
316                    XNextEvent(display, &xevent);
317                    if (xevent.type == VisibilityNotify)
318                            break;
319            }
320    
321            if (ownbackstore)
322                    backstore = XCreatePixmap(display, wnd, width, height, depth);
323    
324            /* clear the window so that cached data is not viewed upon start... */
325            XSetBackground(display, gc, 0);
326            XSetForeground(display, gc, 0);
327            FILL_RECTANGLE(0, 0, width, height);
328            /* make sure the window is focused */
329            XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
330    }
331    
332    BOOL
333    ui_create_window()
334    {
335          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
336          Screen *screen;          Screen *screen;
337          uint16 test;          uint16 test;
338          int i;          int i;
         XEvent xevent;  
339    
340          x_socket = ConnectionNumber(display);          x_socket = ConnectionNumber(display);
341          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
# Line 315  ui_create_window(char *title) Line 380  ui_create_window(char *title)
380          if (attribs.backing_store == NotUseful)          if (attribs.backing_store == NotUseful)
381                  ownbackstore = True;                  ownbackstore = True;
382    
383            dpy_width = WidthOfScreen(screen);
384            dpy_height = HeightOfScreen(screen);
385    
386          if (fullscreen)          if (fullscreen)
387          {          {
388                  attribs.override_redirect = True;                  attribs.override_redirect = True;
389                  width = WidthOfScreen(screen);                  width = dpy_width;
390                  height = HeightOfScreen(screen);                  height = dpy_height;
391          }          }
392          else          else
393          {          {
# Line 328  ui_create_window(char *title) Line 396  ui_create_window(char *title)
396    
397          width = (width + 3) & ~3;       /* make width a multiple of 32 bits */          width = (width + 3) & ~3;       /* make width a multiple of 32 bits */
398    
         wnd = XCreateWindow(display, RootWindowOfScreen(screen),  
                             0, 0, width, height, 0, CopyFromParent,  
                             InputOutput, CopyFromParent,  
                             CWBackingStore | CWBackPixel | CWOverrideRedirect, &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);  
         }  
   
         xkeymap_init2();  
399    
400          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
401                          VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
402    
403          if (grab_keyboard)          if (grab_keyboard)
404                  input_mask |= EnterWindowMask | LeaveWindowMask;                  input_mask |= EnterWindowMask | LeaveWindowMask;
405          if (sendmotion)          if (sendmotion)
# Line 365  ui_create_window(char *title) Line 408  ui_create_window(char *title)
408          if (ownbackstore)          if (ownbackstore)
409                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
410    
411          if (enable_compose)          if (fullscreen)
412                  input_mask |= init_inputmethod();                  ui_create_window_obj(0, 0, width, height,
413                                         CWBackingStore | CWBackPixel | CWOverrideRedirect);
414          XSelectInput(display, wnd, input_mask);          else
415                    ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel);
         gc = XCreateGC(display, wnd, 0, NULL);  
   
         if (ownbackstore)  
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
   
         XMapWindow(display, wnd);  
   
         /* Wait for VisibilityNotify Event */  
         for (;;) {  
                 XNextEvent(display, &xevent);  
                 if (xevent.type == VisibilityNotify)  
                         break;  
         }  
416    
417          /* clear the window so that cached data is not viewed upon start... */          xkeymap_init2();
         XSetBackground(display, gc, 0);  
         XSetForeground(display, gc, 0);  
         FILL_RECTANGLE(0, 0, width, height);  
418    
419          return True;          return True;
420  }  }
# Line 407  ui_destroy_window() Line 434  ui_destroy_window()
434          display = NULL;          display = NULL;
435  }  }
436    
437    void
438    reset_keys()
439    {
440            /* reset keys */
441            uint32 ev_time;
442            ev_time = time(NULL);
443            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
444            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);
445            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
446            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);
447            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
448            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
449    }
450    
451    void
452    toggle_fullscreen()
453    {
454            /* save window contents */
455            Pixmap pixmap;
456            pixmap = XCreatePixmap(display, wnd, width, height, depth);
457            if (ownbackstore)
458                    XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0);
459            else
460                    XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0);
461            fullscreen = fullscreen ? False : True;
462            close_inputmethod();
463            if (ownbackstore)
464                    XFreePixmap(display, backstore);
465            XFreeGC(display, gc);
466            XDestroyWindow(display, wnd);
467            if (fullscreen)
468            {
469                    attribs.override_redirect = True;
470                    ui_create_window_obj(0, 0, dpy_width, dpy_height,
471                                         CWBackingStore | CWBackPixel | CWOverrideRedirect);
472            }
473            else
474            {
475                    attribs.override_redirect = False;
476                    ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel);
477            }
478            ui_set_cursor(cache_get_cursor(0));
479            ui_move_pointer(width / 2, height / 2);
480            reset_keys();
481            /* restore window contents */
482            if (ownbackstore)
483                    XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0);
484            XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0);
485            XFreePixmap(display, pixmap);
486    }
487    
488  static void  static void
489  xwin_process_events()  xwin_process_events()
490  {  {
# Line 420  xwin_process_events() Line 498  xwin_process_events()
498          char str[256];          char str[256];
499          Status status;          Status status;
500    
501          /* Refresh keyboard mapping if it has changed. This is important for          /* Refresh keyboard mapping if it has changed. This is important for
502             Xvnc, since it allocates keycodes dynamically */             Xvnc, since it allocates keycodes dynamically */
503          if (XCheckTypedEvent(display, MappingNotify, &xevent))          if (XCheckTypedEvent(display, MappingNotify, &xevent))
504          {          {
# Line 464  xwin_process_events() Line 542  xwin_process_events()
542                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
543                                  }                                  }
544    
545                                    /* FIXME needs alt modifier */
546                                    if (keysym == XK_Break) /* toggle full screen */
547                                    {
548                                            toggle_fullscreen();
549                                            break;
550                                    }
551                                  ksname = get_ksname(keysym);                                  ksname = get_ksname(keysym);
552                                  DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));                                  DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
553    
# Line 530  xwin_process_events() Line 614  xwin_process_events()
614                                  break;                                  break;
615    
616                          case FocusOut:                          case FocusOut:
617                                  /* reset keys */                                  reset_keys();
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);  
                                 rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);  
618                                  /* fall through */                                  /* fall through */
619                          case LeaveNotify:                          case LeaveNotify:
620                                  if (grab_keyboard)                                  if (grab_keyboard)

Legend:
Removed from v.99  
changed lines
  Added in v.101

  ViewVC Help
Powered by ViewVC 1.1.26