/[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 185 by n-ki, Wed Sep 18 12:13:08 2002 UTC revision 188 by matthewc, Tue Sep 24 06:09:09 2002 UTC
# Line 33  extern BOOL sendmotion; Line 33  extern BOOL sendmotion;
33  extern BOOL fullscreen;  extern BOOL fullscreen;
34  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
35  extern char title[];  extern char title[];
36    BOOL enable_compose = False;
37    
38  Display *display;  Display *display;
39  static int x_socket;  static int x_socket;
# Line 42  static GC gc; Line 43  static GC gc;
43  static Visual *visual;  static Visual *visual;
44  static int depth;  static int depth;
45  static int bpp;  static int bpp;
46    static XIM IM;
47    static XIC IC;
48    static Cursor current_cursor;
49    
50  /* endianness */  /* endianness */
51  static BOOL host_be;  static BOOL host_be;
# Line 62  static Pixmap backstore; Line 66  static Pixmap backstore;
66  static Colormap xcolmap;  static Colormap xcolmap;
67  static uint32 *colmap;  static uint32 *colmap;
68    
 /* Compose support */  
 BOOL enable_compose = False;  
 static XIM IM = NULL;  
 static XIC IC = NULL;  
   
 /* toggle fullscreen globals */  
 static unsigned long input_mask;  
   
69  #define SET_FOREGROUND(col)     XSetForeground(display, gc, translate_colour(colmap[col]));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, translate_colour(colmap[col]));
70  #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));
71    
# Line 189  translate_colour(uint32 colour) Line 185  translate_colour(uint32 colour)
185          return colour;          return colour;
186  }  }
187    
 static unsigned long  
 init_inputmethod(void)  
 {  
         unsigned long filtered_events = 0;  
   
         IM = XOpenIM(display, NULL, NULL, NULL);  
         if (IM == NULL)  
         {  
                 error("Failed to open input method\n");  
         }  
   
         if (IM != NULL)  
         {  
                 /* Must be done after XCreateWindow */  
                 IC = XCreateIC(IM, XNInputStyle,  
                                (XIMPreeditNothing | XIMStatusNothing),  
                                XNClientWindow, wnd, XNFocusWindow, wnd, NULL);  
   
                 if (IC == NULL)  
                 {  
                         error("Failed to create input context\n");  
                         XCloseIM(IM);  
                         IM = NULL;  
                 }  
         }  
   
         /* For correct Multi_key/Compose processing, I guess.  
            It seems to work alright anyway, though. */  
         if (IC != NULL)  
         {  
                 if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL)  
                 {  
                         error("Failed to obtain XNFilterEvents value from IC\n");  
                         filtered_events = 0;  
                 }  
         }  
         return filtered_events;  
 }  
   
 static void  
 close_inputmethod(void)  
 {  
         if (IC != NULL)  
         {  
                 XDestroyIC(IC);  
                 if (IM != NULL)  
                 {  
                         XCloseIM(IM);  
                         IM = NULL;  
                 }  
         }  
 }  
   
188  BOOL  BOOL
189  get_key_state(int keysym)  get_key_state(int keysym)
190  {  {
# Line 276  get_key_state(int keysym) Line 219  get_key_state(int keysym)
219          return (current_state & keysymMask) ? True : False;          return (current_state & keysymMask) ? True : False;
220  }  }
221    
 static void  
 xwin_map_window()  
 {  
         XEvent xevent;  
   
         XMapWindow(display, wnd);  
   
         /* wait for VisibilityChange */  
         XMaskEvent(display, VisibilityChangeMask, &xevent);  
   
         if (fullscreen)  
                 XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);  
 }  
   
222  BOOL  BOOL
223  ui_init()  ui_init()
224  {  {
# Line 332  ui_init() Line 261  ui_init()
261          }          }
262    
263          xcolmap = DefaultColormapOfScreen(screen);          xcolmap = DefaultColormapOfScreen(screen);
264            gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL);
265    
266          if (DoesBackingStore(screen) == NotUseful)          if (DoesBackingStore(screen) != Always)
267                  ownbackstore = True;                  ownbackstore = True;
268    
269          test = 1;          test = 1;
# Line 349  ui_init() Line 279  ui_init()
279          /* make sure width is a multiple of 4 */          /* make sure width is a multiple of 4 */
280          width = (width + 3) & ~3;          width = (width + 3) & ~3;
281    
282            if (ownbackstore)
283            {
284                    backstore = XCreatePixmap(display, RootWindowOfScreen(screen), width, height, depth);
285    
286                    /* clear to prevent rubbish being exposed at startup */
287                    XSetForeground(display, gc, BlackPixelOfScreen(screen));
288                    XFillRectangle(display, backstore, gc, 0, 0, width, height);
289            }
290    
291            if (enable_compose)
292                    IM = XOpenIM(display, NULL, NULL, NULL);
293    
294          xkeymap_init();          xkeymap_init();
295          return True;          return True;
296  }  }
297    
298    void
299    ui_deinit()
300    {
301            if (IM != NULL)
302                    XCloseIM(IM);
303    
304            if (ownbackstore)
305                    XFreePixmap(display, backstore);
306    
307            XFreeGC(display, gc);
308            XCloseDisplay(display);
309            display = NULL;
310    }
311    
312  BOOL  BOOL
313  ui_create_window()  ui_create_window()
314  {  {
315          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
316          XClassHint *classhints;          XClassHint *classhints;
317          XSizeHints *sizehints;          XSizeHints *sizehints;
318            int wndwidth, wndheight;
319            long input_mask, ic_input_mask;
320          XEvent xevent;          XEvent xevent;
321    
322            wndwidth  = fullscreen ? WidthOfScreen(screen)  : width;
323            wndheight = fullscreen ? HeightOfScreen(screen) : height;
324    
325          attribs.background_pixel = BlackPixelOfScreen(screen);          attribs.background_pixel = BlackPixelOfScreen(screen);
326          attribs.backing_store = ownbackstore ? NotUseful : Always;          attribs.backing_store = ownbackstore ? NotUseful : Always;
327          attribs.override_redirect = fullscreen;          attribs.override_redirect = fullscreen;
328          wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,  
329            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth, wndheight,
330                              0, CopyFromParent, InputOutput, CopyFromParent,                              0, CopyFromParent, InputOutput, CopyFromParent,
331                              CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);                              CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
332    
         if (ownbackstore)  
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
   
333          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
334    
335          classhints = XAllocClassHint();          classhints = XAllocClassHint();
# Line 392  ui_create_window() Line 351  ui_create_window()
351          }          }
352    
353          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
354                  VisibilityChangeMask | FocusChangeMask;                  StructureNotifyMask | FocusChangeMask;
355    
356          if (grab_keyboard)          if (grab_keyboard)
357                  input_mask |= EnterWindowMask | LeaveWindowMask;                  input_mask |= EnterWindowMask | LeaveWindowMask;
# Line 400  ui_create_window() Line 359  ui_create_window()
359                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
360          if (ownbackstore)          if (ownbackstore)
361                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
362          if (enable_compose)  
363                  input_mask |= init_inputmethod();          if (IM != NULL)
364            {
365                    IC = XCreateIC(IM, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
366                                   XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
367    
368                    if ((IC != NULL) && (XGetICValues(IC, XNFilterEvents, &ic_input_mask, NULL) == NULL))
369                            input_mask |= ic_input_mask;
370            }
371    
372          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
373            XMapWindow(display, wnd);
374    
375          xwin_map_window();          /* wait for MapNotify */
376            do {
377                    XMaskEvent(display, StructureNotifyMask, &xevent);
378            } while (xevent.type != MapNotify);
379    
380          /* clear the window so that cached data is not seen */          if (fullscreen)
381          gc = XCreateGC(display, wnd, 0, NULL);                  XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
         XSetForeground(display, gc, 0);  
         FILL_RECTANGLE(0, 0, width, height);  
382    
383          return True;          return True;
384  }  }
# Line 418  ui_create_window() Line 386  ui_create_window()
386  void  void
387  ui_destroy_window()  ui_destroy_window()
388  {  {
389          if (ownbackstore)          if (IC != NULL)
390                  XFreePixmap(display, backstore);                  XDestroyIC(IC);
   
         XFreeGC(display, gc);  
   
         close_inputmethod();  
391    
392          XDestroyWindow(display, wnd);          XDestroyWindow(display, wnd);
         XCloseDisplay(display);  
         display = NULL;  
393  }  }
394    
   
395  void  void
396  xwin_toggle_fullscreen()  xwin_toggle_fullscreen()
397  {  {
398          XEvent xevent;          Pixmap contents = 0;
399          XSetWindowAttributes attribs;  
400          int newwidth, newheight;          if (!ownbackstore)
401            {
402                    /* need to save contents of window */
403                    contents = XCreatePixmap(display, wnd, width, height, depth);
404                    XCopyArea(display, wnd, contents, gc, 0, 0, width, height, 0, 0);
405            }
406    
407            ui_destroy_window();
408          fullscreen = !fullscreen;          fullscreen = !fullscreen;
409          newwidth = fullscreen ? WidthOfScreen(screen) : width;          ui_create_window();
         newheight = fullscreen ? HeightOfScreen(screen) : height;  
410    
411          XUnmapWindow(display, wnd);          XDefineCursor(display, wnd, current_cursor);
412          attribs.override_redirect = fullscreen;  
413          XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight);          if (!ownbackstore)
414          XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs);          {
415          xwin_map_window();                  XCopyArea(display, contents, wnd, gc, 0, 0, width, height, 0, 0);
416                    XFreePixmap(display, contents);
417            }
418  }  }
419    
420  /* Process all events in Xlib queue */  /* Process all events in Xlib queue */
# Line 466  xwin_process_events() Line 434  xwin_process_events()
434          {          {
435                  XNextEvent(display, &xevent);                  XNextEvent(display, &xevent);
436    
437                  if (enable_compose && (XFilterEvent(&xevent, None) == True))                  if ((IC != NULL) && (XFilterEvent(&xevent, None) == True))
438                  {                  {
439                          DEBUG_KBD(("Filtering event\n"));                          DEBUG_KBD(("Filtering event\n"));
440                          continue;                          continue;
# Line 780  ui_create_cursor(unsigned int x, unsigne Line 748  ui_create_cursor(unsigned int x, unsigne
748  void  void
749  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(HCURSOR cursor)
750  {  {
751          XDefineCursor(display, wnd, (Cursor) cursor);          current_cursor = (Cursor) cursor;
752            XDefineCursor(display, wnd, current_cursor);
753  }  }
754    
755  void  void

Legend:
Removed from v.185  
changed lines
  Added in v.188

  ViewVC Help
Powered by ViewVC 1.1.26