/[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 100 by jsorg71, Sat Aug 24 20:04:56 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                    XNextEvent(display, &xevent);
316                    if (xevent.type == VisibilityNotify)
317                            break;
318            }
319    
320            if (ownbackstore)
321                    backstore = XCreatePixmap(display, wnd, width, height, depth);
322    
323            /* clear the window so that cached data is not viewed upon start... */
324            XSetBackground(display, gc, 0);
325            XSetForeground(display, gc, 0);
326            FILL_RECTANGLE(0, 0, width, height);
327            /* make sure the window is focused */
328            XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
329    }
330    
331    BOOL
332    ui_create_window()
333    {
334          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
335          Screen *screen;          Screen *screen;
336          uint16 test;          uint16 test;
337          int i;          int i;
         XEvent xevent;  
338    
339          x_socket = ConnectionNumber(display);          x_socket = ConnectionNumber(display);
340          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
# Line 315  ui_create_window(char *title) Line 379  ui_create_window(char *title)
379          if (attribs.backing_store == NotUseful)          if (attribs.backing_store == NotUseful)
380                  ownbackstore = True;                  ownbackstore = True;
381    
382            dpy_width = WidthOfScreen(screen);
383            dpy_height = HeightOfScreen(screen);
384    
385          if (fullscreen)          if (fullscreen)
386          {          {
387                  attribs.override_redirect = True;                  attribs.override_redirect = True;
388                  width = WidthOfScreen(screen);                  width = dpy_width;
389                  height = HeightOfScreen(screen);                  height = dpy_height;
390          }          }
391          else          else
392          {          {
# Line 328  ui_create_window(char *title) Line 395  ui_create_window(char *title)
395    
396          width = (width + 3) & ~3;       /* make width a multiple of 32 bits */          width = (width + 3) & ~3;       /* make width a multiple of 32 bits */
397    
         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();  
398    
399          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
400                          VisibilityChangeMask | FocusChangeMask;                          VisibilityChangeMask | FocusChangeMask;
401    
402          if (grab_keyboard)          if (grab_keyboard)
403                  input_mask |= EnterWindowMask | LeaveWindowMask;                  input_mask |= EnterWindowMask | LeaveWindowMask;
404          if (sendmotion)          if (sendmotion)
# Line 365  ui_create_window(char *title) Line 407  ui_create_window(char *title)
407          if (ownbackstore)          if (ownbackstore)
408                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
409    
410          if (enable_compose)          if (fullscreen)
411                  input_mask |= init_inputmethod();                  ui_create_window_obj(0, 0, width, height, CWBackingStore | CWBackPixel | CWOverrideRedirect);
412            else
413          XSelectInput(display, wnd, input_mask);                  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;  
         }  
414    
415          /* 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);  
416    
417          return True;          return True;
418  }  }
# Line 407  ui_destroy_window() Line 432  ui_destroy_window()
432          display = NULL;          display = NULL;
433  }  }
434    
435    void
436    reset_keys()
437    {
438            /* reset keys */
439            uint32 ev_time;
440            ev_time = time(NULL);
441            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
442            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);
443            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
444            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);
445            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
446            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
447    }
448    
449    void
450    toggle_fullscreen()
451    {
452            /* save window contents */
453            Pixmap pixmap;
454            pixmap = XCreatePixmap(display, wnd, width, height, depth);
455            if (ownbackstore)
456                    XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0);
457            else
458                    XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0);
459            fullscreen = fullscreen ? False : True;
460            close_inputmethod();
461            if (ownbackstore)
462                    XFreePixmap(display, backstore);
463            XFreeGC(display, gc);
464            XDestroyWindow(display, wnd);
465            if (fullscreen) {
466                    attribs.override_redirect = True;
467                    ui_create_window_obj(0, 0, dpy_width, dpy_height,
468                                                                            CWBackingStore | CWBackPixel | CWOverrideRedirect);
469            }
470            else {
471                    attribs.override_redirect = False;
472                    ui_create_window_obj(0, 0, width, height,
473                                                                            CWBackingStore | CWBackPixel);
474            }
475            ui_set_cursor(cache_get_cursor(0));
476            ui_move_pointer(width / 2, height / 2);
477            reset_keys();
478            /* restore window contents */
479            if (ownbackstore)
480                    XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0);
481            XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0);
482            XFreePixmap(display, pixmap);
483    }
484    
485  static void  static void
486  xwin_process_events()  xwin_process_events()
487  {  {
# Line 420  xwin_process_events() Line 495  xwin_process_events()
495          char str[256];          char str[256];
496          Status status;          Status status;
497    
498          /* Refresh keyboard mapping if it has changed. This is important for          /* Refresh keyboard mapping if it has changed. This is important for
499             Xvnc, since it allocates keycodes dynamically */             Xvnc, since it allocates keycodes dynamically */
500          if (XCheckTypedEvent(display, MappingNotify, &xevent))          if (XCheckTypedEvent(display, MappingNotify, &xevent))
501          {          {
# Line 464  xwin_process_events() Line 539  xwin_process_events()
539                                                        str, sizeof(str), &keysym, NULL);                                                        str, sizeof(str), &keysym, NULL);
540                                  }                                  }
541    
542                                    /* FIXME needs alt modifier */
543                                    if (keysym == XK_Break) /* toggle full screen */
544                                    {
545                                            toggle_fullscreen();
546                                            break;
547                                    }
548                                  ksname = get_ksname(keysym);                                  ksname = get_ksname(keysym);
549                                  DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));                                  DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
550    
# Line 530  xwin_process_events() Line 611  xwin_process_events()
611                                  break;                                  break;
612    
613                          case FocusOut:                          case FocusOut:
614                                  /* 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);  
615                                  /* fall through */                                  /* fall through */
616                          case LeaveNotify:                          case LeaveNotify:
617                                  if (grab_keyboard)                                  if (grab_keyboard)

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

  ViewVC Help
Powered by ViewVC 1.1.26