/[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 52 by n-ki, Fri Apr 26 08:22:39 2002 UTC revision 182 by astrand, Tue Sep 17 16:55:43 2002 UTC
# Line 20  Line 20 
20    
21  #include <X11/Xlib.h>  #include <X11/Xlib.h>
22  #include <X11/Xutil.h>  #include <X11/Xutil.h>
 #include <X11/XKBlib.h>  
23  #include <time.h>  #include <time.h>
24  #include <errno.h>  #include <errno.h>
25    #define XK_MISCELLANY
26    #include <X11/keysymdef.h>
27  #include "rdesktop.h"  #include "rdesktop.h"
28    #include "scancodes.h"
29    
 extern char keymapname[16];  
 extern int keylayout;  
30  extern int width;  extern int width;
31  extern int height;  extern int height;
32  extern BOOL sendmotion;  extern BOOL sendmotion;
33  extern BOOL fullscreen;  extern BOOL fullscreen;
34    extern BOOL grab_keyboard;
35    extern char title[];
36    
37  Display *display;  Display *display;
 XkbDescPtr xkb;  
38  static int x_socket;  static int x_socket;
39    static Screen *screen;
40  static Window wnd;  static Window wnd;
41  static GC gc;  static GC gc;
42  static Visual *visual;  static Visual *visual;
# Line 49  static BOOL xserver_be; Line 51  static BOOL xserver_be;
51  static BOOL ownbackstore;  static BOOL ownbackstore;
52  static Pixmap backstore;  static Pixmap backstore;
53    
 /* needed to keep track of the modifiers */  
 static unsigned int key_modifier_state = 0;  
 static unsigned int key_down_state = 0;  
   
 #define DShift1Mask   (1<<0)  
 #define DShift2Mask   (1<<1)  
 #define DControl1Mask (1<<2)  
 #define DControl2Mask (1<<3)  
 #define DMod1Mask     (1<<4)  
 #define DMod2Mask     (1<<5)  
   
54  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
55  { \  { \
56          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(display, wnd, gc, x, y, cx, cy); \
# Line 70  static unsigned int key_down_state = 0; Line 61  static unsigned int key_down_state = 0;
61  /* colour maps */  /* colour maps */
62  static BOOL owncolmap;  static BOOL owncolmap;
63  static Colormap xcolmap;  static Colormap xcolmap;
 static uint32 white;  
64  static uint32 *colmap;  static uint32 *colmap;
65    
66    /* Compose support */
67    BOOL enable_compose = False;
68    static XIM IM = NULL;
69    static XIC IC = NULL;
70    
71    /* toggle fullscreen globals */
72    static unsigned long input_mask;
73    
74  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
75  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
76  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
# Line 99  static int rop2_map[] = { Line 97  static int rop2_map[] = {
97  #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]); }
98  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
99    
 void xwin_release_modifiers(XKeyEvent* ev, uint32 ev_time, uint32 scancode);  
 void xwin_press_modifiers(XKeyEvent* ev, uint32 ev_time, uint32 scancode);  
   
100  static void  static void
101  translate8(uint8 *data, uint8 *out, uint8 *end)  translate8(uint8 * data, uint8 * out, uint8 * end)
102  {  {
103          while (out < end)          while (out < end)
104                  *(out++) = (uint8)colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
105  }  }
106    
107  static void  static void
108  translate16(uint8 *data, uint16 *out, uint16 *end)  translate16(uint8 * data, uint16 * out, uint16 * end)
109  {  {
110          while (out < end)          while (out < end)
111                  *(out++) = (uint16)colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
112  }  }
113    
114  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
115  static void  static void
116  translate24(uint8 *data, uint8 *out, uint8 *end)  translate24(uint8 * data, uint8 * out, uint8 * end)
117  {  {
118          uint32 value;          uint32 value;
119    
# Line 132  translate24(uint8 *data, uint8 *out, uin Line 127  translate24(uint8 *data, uint8 *out, uin
127  }  }
128    
129  static void  static void
130  translate32(uint8 *data, uint32 *out, uint32 *end)  translate32(uint8 * data, uint32 * out, uint32 * end)
131  {  {
132          while (out < end)          while (out < end)
133                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
134  }  }
135    
136  static uint8 *  static uint8 *
137  translate_image(int width, int height, uint8 *data)  translate_image(int width, int height, uint8 * data)
138  {  {
139          int size = width * height * bpp/8;          int size = width * height * bpp / 8;
140          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
141          uint8 *end = out + size;          uint8 *end = out + size;
142    
# Line 152  translate_image(int width, int height, u Line 147  translate_image(int width, int height, u
147                          break;                          break;
148    
149                  case 16:                  case 16:
150                          translate16(data, (uint16 *)out, (uint16 *)end);                          translate16(data, (uint16 *) out, (uint16 *) end);
151                          break;                          break;
152    
153                  case 24:                  case 24:
# Line 160  translate_image(int width, int height, u Line 155  translate_image(int width, int height, u
155                          break;                          break;
156    
157                  case 32:                  case 32:
158                          translate32(data, (uint32 *)out, (uint32 *)end);                          translate32(data, (uint32 *) out, (uint32 *) end);
159                          break;                          break;
160          }          }
161    
# Line 196  translate_colour(uint32 colour) Line 191  translate_colour(uint32 colour)
191          return colour;          return colour;
192  }  }
193    
194  BOOL  static unsigned long
195  ui_create_window(char *title)  init_inputmethod(void)
196  {  {
197          XSetWindowAttributes attribs;          unsigned long filtered_events = 0;
198          XClassHint *classhints;  
199          XSizeHints *sizehints;          IM = XOpenIM(display, NULL, NULL, NULL);
200          unsigned long input_mask;          if (IM == NULL)
         XPixmapFormatValues *pfm;  
         Screen *screen;  
         uint16 test;  
         int i;  
           
         int xkb_minor, xkb_major;  
         int xkb_event, xkb_error, xkb_reason;  
   
         /* compare compiletime libs with runtime libs. */  
         xkb_major = XkbMajorVersion;  
         xkb_minor = XkbMinorVersion;  
         if( XkbLibraryVersion( &xkb_major, &xkb_minor ) == False )  
201          {          {
202                  error("please re-compile rdesktop\ncompile time version of xkb is not compatible with\nyour runtime version of the library\n");                  error("Failed to open input method\n");
                 return False;  
203          }          }
204    
205            if (IM != NULL)
206            {
207                    /* Must be done after XCreateWindow */
208                    IC = XCreateIC(IM, XNInputStyle,
209                                   (XIMPreeditNothing | XIMStatusNothing),
210                                   XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
211    
212          /* XKB is the 'new' keyboard handler in x.. ( the xkb code in Xfree86 originates from SGI, years 1993 and 1995 from what I could tell. )                  if (IC == NULL)
213           * it makes it possible for people with disabilities to use rdesktop, stickykeys, bouncekeys etc. VERY MUCH useful.                  {
214           * XFree86 has had support for it since it's earliest incarnation. I believe it is a reasonable dependency.                          error("Failed to create input context\n");
215           */                          XCloseIM(IM);
216          display = XkbOpenDisplay( NULL, &xkb_event, &xkb_error, &xkb_major, &xkb_minor, &xkb_reason );                          IM = NULL;
217          switch(xkb_reason)                  }
218            }
219    
220            /* For correct Multi_key/Compose processing, I guess.
221               It seems to work alright anyway, though. */
222            if (IC != NULL)
223          {          {
224                  case XkbOD_BadLibraryVersion:                  if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL)
225                          error("XkbOD_BadLibraryVersion: XKB extensions in server and the library rdesktop is linked against aren't compatible with each other.\n");                  {
226                          break;                          error("Failed to obtain XNFilterEvents value from IC\n");
227                  case XkbOD_ConnectionRefused:                          filtered_events = 0;
228                          error("XkbOD_ConnectionRefused\n");                  }
                         break;  
                 case XkbOD_BadServerVersion:  
                         error("XkbOD_BadServerVersion\n");  
                         break;  
                 case XkbOD_NonXkbServer:  
                         error("XkbOD_NonXkbServer: XKB extension not present in server\nupdate your X server.\n");  
                         break;  
                 case XkbOD_Success:  
                         DEBUG("XkbOD_Success: Connection established with display\n");  
                         break;  
229          }          }
230            return filtered_events;
231    }
232    
233    static void
234    close_inputmethod(void)
235    {
236            if (IC != NULL)
237            {
238                    XDestroyIC(IC);
239                    if (IM != NULL)
240                    {
241                            XCloseIM(IM);
242                            IM = NULL;
243                    }
244            }
245    }
246    
247    BOOL
248    get_key_state(int keysym)
249    {
250            int keysymMask = 0, modifierpos, key;
251            Window wDummy1, wDummy2;
252            int iDummy3, iDummy4, iDummy5, iDummy6;
253            unsigned int current_state;
254            int offset;
255    
256            XModifierKeymap *map = XGetModifierMapping(display);
257            KeyCode keycode = XKeysymToKeycode(display, keysym);
258    
259            if (keycode == NoSymbol)
260                    return False;
261    
262            for (modifierpos = 0; modifierpos < 8; modifierpos++)
263            {
264                    offset = map->max_keypermod * modifierpos;
265    
266                    for (key = 0; key < map->max_keypermod; key++)
267                    {
268                            if (map->modifiermap[offset + key] == keycode)
269                                    keysymMask = 1 << modifierpos;
270                    }
271            }
272    
273            XQueryPointer(display, DefaultRootWindow(display), &wDummy1,
274                          &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &current_state);
275    
276            XFreeModifiermap(map);
277    
278            return (current_state & keysymMask) ? True : False;
279    }
280    
281    static void
282    xwin_map_window()
283    {
284            XEvent xevent;
285    
286            XMapWindow(display, wnd);
287    
288            /* wait for VisibilityChange */
289            XMaskEvent(display, VisibilityChangeMask, &xevent);
290    
291            if (fullscreen)
292                    XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
293    }
294    
295    BOOL
296    ui_init()
297    {
298            XPixmapFormatValues *pfm;
299            uint16 test;
300            int i;
301    
302            display = XOpenDisplay(NULL);
303          if (display == NULL)          if (display == NULL)
304          {          {
305                  error("Failed to open display\n");                  error("Failed to open display\n");
# Line 255  ui_create_window(char *title) Line 310  ui_create_window(char *title)
310          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
311          visual = DefaultVisualOfScreen(screen);          visual = DefaultVisualOfScreen(screen);
312          depth = DefaultDepthOfScreen(screen);          depth = DefaultDepthOfScreen(screen);
313            
314          pfm = XListPixmapFormats(display, &i);          pfm = XListPixmapFormats(display, &i);
315          if (pfm != NULL)          if (pfm != NULL)
316          {          {
# Line 263  ui_create_window(char *title) Line 318  ui_create_window(char *title)
318                     desirable, e.g. 24 bits->32 bits. */                     desirable, e.g. 24 bits->32 bits. */
319                  while (i--)                  while (i--)
320                  {                  {
321                          if ((pfm[i].depth == depth)                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))
                             && (pfm[i].bits_per_pixel > bpp))  
322                          {                          {
323                                  bpp = pfm[i].bits_per_pixel;                                  bpp = pfm[i].bits_per_pixel;
324                          }                          }
# Line 284  ui_create_window(char *title) Line 338  ui_create_window(char *title)
338          else          else
339                  xcolmap = DefaultColormapOfScreen(screen);                  xcolmap = DefaultColormapOfScreen(screen);
340    
341            if (DoesBackingStore(screen) == NotUseful)
342                    ownbackstore = True;
343    
344          test = 1;          test = 1;
345          host_be = !(BOOL)(*(uint8 *)(&test));          host_be = !(BOOL) (*(uint8 *) (&test));
346          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
347    
         white = WhitePixelOfScreen(screen);  
         attribs.background_pixel = BlackPixelOfScreen(screen);  
         attribs.backing_store = DoesBackingStore(screen);  
   
         if (attribs.backing_store == NotUseful)  
                 ownbackstore = True;  
   
348          if (fullscreen)          if (fullscreen)
349          {          {
                 attribs.override_redirect = True;  
350                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
351                  height = HeightOfScreen(screen);                  height = HeightOfScreen(screen);
352          }          }
         else  
         {  
                 attribs.override_redirect = False;  
         }  
353    
354          width = (width + 3) & ~3; /* make width a multiple of 32 bits */          /* make sure width is a multiple of 4 */
355            width = (width + 3) & ~3;
356    
357          wnd = XCreateWindow(display, RootWindowOfScreen(screen),          xkeymap_init();
358                              0, 0, width, height, 0, CopyFromParent,          return True;
359                              InputOutput, CopyFromParent,  }
360                              CWBackingStore | CWBackPixel | CWOverrideRedirect,  
361                              &attribs);  BOOL
362    ui_create_window()
363    {
364            XSetWindowAttributes attribs;
365            XClassHint *classhints;
366            XSizeHints *sizehints;
367            XEvent xevent;
368    
369            attribs.background_pixel = BlackPixelOfScreen(screen);
370            attribs.backing_store = ownbackstore ? NotUseful : Always;
371            attribs.override_redirect = fullscreen;
372            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,
373                                0, CopyFromParent, InputOutput, CopyFromParent,
374                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
375    
376            if (ownbackstore)
377                    backstore = XCreatePixmap(display, wnd, width, height, depth);
378    
379          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
380    
# Line 334  ui_create_window(char *title) Line 396  ui_create_window(char *title)
396                  XFree(sizehints);                  XFree(sizehints);
397          }          }
398    
399          xkeymap_init();          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
400                    VisibilityChangeMask | FocusChangeMask;
401    
402          input_mask = KeyPressMask | KeyReleaseMask |          if (grab_keyboard)
403                           ButtonPressMask | ButtonReleaseMask |                  input_mask |= EnterWindowMask | LeaveWindowMask;
                          EnterWindowMask | LeaveWindowMask | KeymapStateMask;  
404          if (sendmotion)          if (sendmotion)
405                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
   
406          if (ownbackstore)          if (ownbackstore)
407                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
408            if (enable_compose)
409                    input_mask |= init_inputmethod();
410    
411          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
         gc = XCreateGC(display, wnd, 0, NULL);  
   
         if (ownbackstore)  
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
   
         XMapWindow(display, wnd);  
412    
413          /* TODO: error texts... make them friendly. */          xwin_map_window();
         xkb = XkbGetKeyboard(display, XkbAllComponentsMask, XkbUseCoreKbd);  
         if ((int)xkb == BadAlloc || xkb == NULL)  
         {  
                         error( "XkbGetKeyboard failed.\n");  
                         exit(0);  
         }  
414    
415          /* TODO: error texts... make them friendly. */          /* clear the window so that cached data is not seen */
416          if( XkbSelectEvents(display, xkb->device_spec, XkbAllEventsMask, XkbAllEventsMask) == False )          gc = XCreateGC(display, wnd, 0, NULL);
417          {          XSetForeground(display, gc, 0);
418                          error( "XkbSelectEvents failed.\n");          FILL_RECTANGLE(0, 0, width, height);
                         exit(0);  
         }  
419    
420          return True;          return True;
421  }  }
# Line 374  ui_create_window(char *title) Line 423  ui_create_window(char *title)
423  void  void
424  ui_destroy_window()  ui_destroy_window()
425  {  {
         if( xkb != NULL )  
                 XkbFreeKeyboard(xkb, XkbAllControlsMask, True);  
   
426          if (ownbackstore)          if (ownbackstore)
427                  XFreePixmap(display, backstore);                  XFreePixmap(display, backstore);
428    
429          XFreeGC(display, gc);          XFreeGC(display, gc);
430    
431            close_inputmethod();
432    
433          XDestroyWindow(display, wnd);          XDestroyWindow(display, wnd);
434          XCloseDisplay(display);          XCloseDisplay(display);
435          display = NULL;          display = NULL;
436  }  }
437    
438    
439    void
440    xwin_toggle_fullscreen()
441    {
442            XEvent xevent;
443            XSetWindowAttributes attribs;
444            int newwidth, newheight;
445    
446            fullscreen = !fullscreen;
447            newwidth = fullscreen ? WidthOfScreen(screen) : width;
448            newheight = fullscreen ? HeightOfScreen(screen) : height;
449    
450            XUnmapWindow(display, wnd);
451            attribs.override_redirect = fullscreen;
452            XMoveResizeWindow(display, wnd, 0, 0, newwidth, newheight);
453            XChangeWindowAttributes(display, wnd, CWOverrideRedirect, &attribs);
454            xwin_map_window();
455    }
456    
457    /* Process all events in Xlib queue */
458  static void  static void
459  xwin_process_events()  xwin_process_events()
460  {  {
461          XkbEvent xkbevent;          XEvent xevent;
           
462          KeySym keysym;          KeySym keysym;
         uint8 scancode;  
463          uint16 button, flags;          uint16 button, flags;
464          uint32 ev_time;          uint32 ev_time;
465          uint32 tmpmods;          key_translation tr;
466            char *ksname = NULL;
467          if (display == NULL)          char str[256];
468                  return;          Status status;
469    
470          while (XCheckMaskEvent(display, ~0, &xkbevent.core))          while (XPending(display) > 0)
471          {          {
472                    XNextEvent(display, &xevent);
473    
474                    if (enable_compose && (XFilterEvent(&xevent, None) == True))
475                    {
476                            DEBUG_KBD(("Filtering event\n"));
477                            continue;
478                    }
479    
480                  ev_time = time(NULL);                  ev_time = time(NULL);
481                  flags = 0;                  flags = 0;
482    
483                  switch (xkbevent.type)                  switch (xevent.type)
484                  {                  {
485                          case KeymapNotify:                          case KeyPress:
486                                  /* TODO:                                  if (IC != NULL)
487                                   * read modifier status at focus in, and update the local masks, and the other end as well..                                          /* Multi_key compatible version */
488                                   * if not, we may get out of sync.                                  {
489                                   * xkbevent.core.xkeymap.key_vector                                          XmbLookupString(IC,
490                                   * char key_vector[32];                                                          (XKeyPressedEvent *) &
491                                   */                                                          xevent, str, sizeof(str), &keysym, &status);
492                                  break;                                          if (!((status == XLookupKeySym) || (status == XLookupBoth)))
493                                            {
494                                                    error("XmbLookupString failed with status 0x%x\n",
495                                                          status);
496                                                    break;
497                                            }
498                                    }
499                                    else
500                                    {
501                                            /* Plain old XLookupString */
502                                            DEBUG_KBD(("\nNo input context, using XLookupString\n"));
503                                            XLookupString((XKeyEvent *) & xevent,
504                                                          str, sizeof(str), &keysym, NULL);
505                                    }
506    
507                          case KeyRelease:                                  ksname = get_ksname(keysym);
508                                  flags = KBD_FLAG_DOWN | KBD_FLAG_UP;                                  DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
                                 /* fall through */  
509    
510                          case KeyPress:                                  if (handle_special_keys(keysym, ev_time, True))
                                 if( XkbTranslateKeyCode(xkb, xkbevent.core.xkey.keycode, xkbevent.core.xkey.state, &tmpmods, &keysym) == False )  
511                                          break;                                          break;
                                 scancode = xkeymap_translate_key(keysym, xkbevent.core.xkey.keycode, &flags);  
512    
513                                  if (scancode == 0 )                                  tr = xkeymap_translate_key(keysym,
514                                                               xevent.xkey.keycode, xevent.xkey.state);
515    
516                                    if (tr.scancode == 0)
517                                          break;                                          break;
518    
519                                  /* keep track of the modifiers -- needed for stickykeys... */                                  ensure_remote_modifiers(ev_time, tr);
                                 if( xkbevent.type == KeyPress )  
                                         xwin_press_modifiers( &xkbevent.core.xkey, ev_time, scancode );  
520    
521                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, flags, scancode, 0);                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
522                                    break;
523                            case KeyRelease:
524                                    XLookupString((XKeyEvent *) & xevent, str,
525                                                  sizeof(str), &keysym, NULL);
526    
527                                  if( xkbevent.type == KeyRelease )                                  ksname = get_ksname(keysym);
528                                          xwin_release_modifiers( &xkbevent.core.xkey, ev_time, scancode );                                  DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,
529                                               ksname));
530    
531                                    if (handle_special_keys(keysym, ev_time, False))
532                                            break;
533    
534                                    tr = xkeymap_translate_key(keysym,
535                                                               xevent.xkey.keycode, xevent.xkey.state);
536    
537                                    if (tr.scancode == 0)
538                                            break;
539    
540                                    rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
541                                  break;                                  break;
542    
543                          case ButtonPress:                          case ButtonPress:
# Line 444  xwin_process_events() Line 545  xwin_process_events()
545                                  /* fall through */                                  /* fall through */
546    
547                          case ButtonRelease:                          case ButtonRelease:
548                                  button = xkeymap_translate_button(xkbevent.core.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
549                                  if (button == 0)                                  if (button == 0)
550                                          break;                                          break;
551    
552                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
553                                                 flags | button,                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
                                                xkbevent.core.xbutton.x,  
                                                xkbevent.core.xbutton.y);  
554                                  break;                                  break;
555    
556                          case MotionNotify:                          case MotionNotify:
557                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
558                                                 MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
                                                xkbevent.core.xmotion.x,  
                                                xkbevent.core.xmotion.y);  
559                                  break;                                  break;
560    
561                          case EnterNotify:                          case EnterNotify:
562                                  XGrabKeyboard(display, wnd, True, GrabModeAsync,                                  if (grab_keyboard)
563                                                GrabModeAsync, CurrentTime);                                          XGrabKeyboard(display, wnd, True,
564                                                          GrabModeAsync, GrabModeAsync, CurrentTime);
565                                  break;                                  break;
566    
567                          case LeaveNotify:                          case LeaveNotify:
568                                  XUngrabKeyboard(display, CurrentTime);                                  if (grab_keyboard)
569                                            XUngrabKeyboard(display, CurrentTime);
570                                    break;
571    
572                            case FocusIn:
573                                    reset_modifier_keys();
574                                  break;                                  break;
575    
576                          case Expose:                          case Expose:
577                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(display, backstore, wnd, gc,
578                                            xkbevent.core.xexpose.x, xkbevent.core.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
579                                            xkbevent.core.xexpose.width, xkbevent.core.xexpose.height,                                            xevent.xexpose.width,
580                                            xkbevent.core.xexpose.x, xkbevent.core.xexpose.y);                                            xevent.xexpose.height,
581                                              xevent.xexpose.x, xevent.xexpose.y);
582                                  break;                                  break;
                 }  
         }  
 }  
   
 void  
 xwin_release_modifiers(XKeyEvent* ev, uint32 ev_time, uint32 scancode)  
 {  
         switch (scancode) {  
         case 0x2a:  
                 key_down_state &= ~DShift1Mask;  
                 break;  
         case 0x36:  
                 key_down_state &= ~DShift2Mask;  
                 break;  
         case 0x1d:  
                 key_down_state &= ~DControl1Mask;  
                 break;  
         case 0x9d:  
                 key_down_state &= ~DControl2Mask;  
                 break;  
         case 0x38:  
                 key_down_state &= ~DMod1Mask;  
                 break;  
         case 0xb8:  
                 key_down_state &= ~DMod2Mask;  
                 break;  
         }  
   
         if( !(ShiftMask & ev->state) && (key_down_state & DShift1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x2a, 0);  
                 key_down_state &= ~DShift1Mask;  
   
         }  
   
         if( !(ControlMask & ev->state) && (key_down_state & DControl1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x1d, 0);  
                 key_down_state &= ~DControl1Mask;  
   
         }  
           
         if( !(Mod1Mask & ev->state) && (key_down_state & DMod1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x38, 0);  
                 key_down_state &= ~DMod1Mask;  
   
         }  
           
         if( !(Mod2Mask & ev->state) && (key_down_state & DMod2Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0xb8, 0);  
                 key_down_state &= ~DMod2Mask;  
         }  
 }  
   
   
 void  
 xwin_press_modifiers(XKeyEvent* ev, uint32 ev_time, uint32 scancode)  
 {  
         key_modifier_state = ev->state;  
   
         switch (scancode) {  
         case 0x2a:  
                 key_down_state |= DShift1Mask;  
                 break;  
         case 0x36:  
                 key_down_state |= DShift2Mask;  
                 break;  
         case 0x1d:  
                 key_down_state |= DControl1Mask;  
                 break;  
         case 0x9d:  
                 key_down_state |= DControl2Mask;  
                 break;  
         case 0x38:  
                 key_down_state |= DMod1Mask;  
                 break;  
         case 0xb8:  
                 key_down_state |= DMod2Mask;  
                 break;  
         }  
   
         if( (ShiftMask & ev->state) && !((key_down_state & DShift1Mask) || (key_down_state & DShift2Mask)))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x2a, 0);  
                 key_down_state |= DShift1Mask;  
   
         }  
   
         if( (ControlMask & ev->state) && !((key_down_state & DControl1Mask) || (key_down_state & DControl2Mask)))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x1d, 0);  
                 key_down_state |= DControl1Mask;  
   
         }  
583    
584          if( (Mod1Mask & ev->state) && !(key_down_state & DMod1Mask))                          case MappingNotify:
585          {                                  /* Refresh keyboard mapping if it has changed. This is important for
586                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x38, 0);                                     Xvnc, since it allocates keycodes dynamically */
587                  key_down_state |= DMod1Mask;                                  if (xevent.xmapping.request == MappingKeyboard
588                                        || xevent.xmapping.request == MappingModifier)
589          }                                          XRefreshKeyboardMapping(&xevent.xmapping);
590                                    break;
         if( (Mod2Mask & ev->state) && !(key_down_state & DMod2Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0xb8, 0);  
                 key_down_state |= DMod2Mask;  
591    
592                    }
593          }          }
594  }  }
595    
596  void  void
597  ui_select(int rdp_socket)  ui_select(int rdp_socket)
598  {  {
599          int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1;          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;
600          fd_set rfds;          fd_set rfds;
601    
         XFlush(display);  
   
602          FD_ZERO(&rfds);          FD_ZERO(&rfds);
603    
604          while (True)          while (True)
605          {          {
606                    /* Process any events already waiting */
607                    xwin_process_events();
608    
609                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
610                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
611                  FD_SET(x_socket, &rfds);                  FD_SET(x_socket, &rfds);
# Line 613  ui_select(int rdp_socket) Line 619  ui_select(int rdp_socket)
619                                  continue;                                  continue;
620                  }                  }
621    
                 if (FD_ISSET(x_socket, &rfds))  
                         xwin_process_events();  
   
622                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
623                          return;                          return;
624          }          }
# Line 628  ui_move_pointer(int x, int y) Line 631  ui_move_pointer(int x, int y)
631  }  }
632    
633  HBITMAP  HBITMAP
634  ui_create_bitmap(int width, int height, uint8 *data)  ui_create_bitmap(int width, int height, uint8 * data)
635  {  {
636          XImage *image;          XImage *image;
637          Pixmap bitmap;          Pixmap bitmap;
# Line 636  ui_create_bitmap(int width, int height, Line 639  ui_create_bitmap(int width, int height,
639    
640          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
641          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
642          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
643                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
644    
645          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
646    
# Line 648  ui_create_bitmap(int width, int height, Line 651  ui_create_bitmap(int width, int height,
651  }  }
652    
653  void  void
654  ui_paint_bitmap(int x, int y, int cx, int cy,  ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 * data)
                 int width, int height, uint8 *data)  
655  {  {
656          XImage *image;          XImage *image;
657          uint8 *tdata;          uint8 *tdata;
658    
659          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
660          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
661                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
662    
663          if (ownbackstore)          if (ownbackstore)
664          {          {
# Line 676  ui_paint_bitmap(int x, int y, int cx, in Line 678  ui_paint_bitmap(int x, int y, int cx, in
678  void  void
679  ui_destroy_bitmap(HBITMAP bmp)  ui_destroy_bitmap(HBITMAP bmp)
680  {  {
681          XFreePixmap(display, (Pixmap)bmp);          XFreePixmap(display, (Pixmap) bmp);
682  }  }
683    
684  HGLYPH  HGLYPH
685  ui_create_glyph(int width, int height, uint8 *data)  ui_create_glyph(int width, int height, uint8 * data)
686  {  {
687          XImage *image;          XImage *image;
688          Pixmap bitmap;          Pixmap bitmap;
# Line 692  ui_create_glyph(int width, int height, u Line 694  ui_create_glyph(int width, int height, u
694          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(display, wnd, width, height, 1);
695          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(display, bitmap, 0, NULL);
696    
697          image = XCreateImage(display, visual, 1, ZPixmap, 0,          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,
698                               data, width, height, 8, scanline);                               width, height, 8, scanline);
699          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
700          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
701          XInitImage(image);          XInitImage(image);
# Line 702  ui_create_glyph(int width, int height, u Line 704  ui_create_glyph(int width, int height, u
704    
705          XFree(image);          XFree(image);
706          XFreeGC(display, gc);          XFreeGC(display, gc);
707          return (HGLYPH)bitmap;          return (HGLYPH) bitmap;
708  }  }
709    
710  void  void
711  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(HGLYPH glyph)
712  {  {
713          XFreePixmap(display, (Pixmap)glyph);          XFreePixmap(display, (Pixmap) glyph);
714  }  }
715    
716  HCURSOR  HCURSOR
717  ui_create_cursor(unsigned int x, unsigned int y, int width,  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,
718                   int height, uint8 *andmask, uint8 *xormask)                   uint8 * andmask, uint8 * xormask)
719  {  {
720          HGLYPH maskglyph, cursorglyph;          HGLYPH maskglyph, cursorglyph;
721          XColor bg, fg;          XColor bg, fg;
# Line 770  ui_create_cursor(unsigned int x, unsigne Line 772  ui_create_cursor(unsigned int x, unsigne
772    
773          cursorglyph = ui_create_glyph(width, height, cursor);          cursorglyph = ui_create_glyph(width, height, cursor);
774          maskglyph = ui_create_glyph(width, height, mask);          maskglyph = ui_create_glyph(width, height, mask);
775            
776          xcursor = XCreatePixmapCursor(display, (Pixmap)cursorglyph,          xcursor =
777                                  (Pixmap)maskglyph, &fg, &bg, x, y);                  XCreatePixmapCursor(display, (Pixmap) cursorglyph,
778                                        (Pixmap) maskglyph, &fg, &bg, x, y);
779    
780          ui_destroy_glyph(maskglyph);          ui_destroy_glyph(maskglyph);
781          ui_destroy_glyph(cursorglyph);          ui_destroy_glyph(cursorglyph);
782          xfree(mask);          xfree(mask);
783          xfree(cursor);          xfree(cursor);
784          return (HCURSOR)xcursor;          return (HCURSOR) xcursor;
785  }  }
786    
787  void  void
788  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(HCURSOR cursor)
789  {  {
790          XDefineCursor(display, wnd, (Cursor)cursor);          XDefineCursor(display, wnd, (Cursor) cursor);
791  }  }
792    
793  void  void
794  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_cursor(HCURSOR cursor)
795  {  {
796          XFreeCursor(display, (Cursor)cursor);          XFreeCursor(display, (Cursor) cursor);
797  }  }
798    
799  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
# Line 800  ui_destroy_cursor(HCURSOR cursor) Line 803  ui_destroy_cursor(HCURSOR cursor)
803                  (xc)->flags = DoRed | DoGreen | DoBlue;                  (xc)->flags = DoRed | DoGreen | DoBlue;
804    
805  HCOLOURMAP  HCOLOURMAP
806  ui_create_colourmap(COLOURMAP *colours)  ui_create_colourmap(COLOURMAP * colours)
807  {  {
808          COLOURENTRY *entry;          COLOURENTRY *entry;
809          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
# Line 823  ui_create_colourmap(COLOURMAP *colours) Line 826  ui_create_colourmap(COLOURMAP *colours)
826                  XStoreColors(display, map, xcolours, ncolours);                  XStoreColors(display, map, xcolours, ncolours);
827    
828                  xfree(xcolours);                  xfree(xcolours);
829                  return (HCOLOURMAP)map;                  return (HCOLOURMAP) map;
830          }          }
831          else          else
832          {          {
# Line 839  ui_create_colourmap(COLOURMAP *colours) Line 842  ui_create_colourmap(COLOURMAP *colours)
842                          if (XAllocColor(display, xcolmap, &xentry) != 0)                          if (XAllocColor(display, xcolmap, &xentry) != 0)
843                                  colour = xentry.pixel;                                  colour = xentry.pixel;
844                          else                          else
845                                  colour = white;                                  colour = WhitePixelOfScreen(screen);
846    
847                          /* byte swap here to make translate_image faster */                          /* byte swap here to make translate_image faster */
848                          map[i] = translate_colour(colour);                          map[i] = translate_colour(colour);
# Line 853  void Line 856  void
856  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
857  {  {
858          if (owncolmap)          if (owncolmap)
859                  XFreeColormap(display, (Colormap)map);                  XFreeColormap(display, (Colormap) map);
860          else          else
861                  xfree(map);                  xfree(map);
862  }  }
# Line 862  void Line 865  void
865  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
866  {  {
867          if (owncolmap)          if (owncolmap)
868                  XSetWindowColormap(display, wnd, (Colormap)map);                  XSetWindowColormap(display, wnd, (Colormap) map);
869          else          else
870                  colmap = map;                  colmap = map;
871  }  }
# Line 909  ui_destblt(uint8 opcode, Line 912  ui_destblt(uint8 opcode,
912  void  void
913  ui_patblt(uint8 opcode,  ui_patblt(uint8 opcode,
914            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
915            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
916  {  {
917          Pixmap fill;          Pixmap fill;
918            uint8 i, ipattern[8];
919    
920          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
921    
# Line 923  ui_patblt(uint8 opcode, Line 927  ui_patblt(uint8 opcode,
927                          break;                          break;
928    
929                  case 3: /* Pattern */                  case 3: /* Pattern */
930                          fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);                          for (i = 0; i != 8; i++)
931                                    ipattern[7 - i] = brush->pattern[i];
932                            fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
933    
934                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
935                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
# Line 934  ui_patblt(uint8 opcode, Line 940  ui_patblt(uint8 opcode,
940                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
941    
942                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
943                          ui_destroy_glyph((HGLYPH)fill);                          XSetTSOrigin(display, gc, 0, 0);
944                            ui_destroy_glyph((HGLYPH) fill);
945                          break;                          break;
946    
947                  default:                  default:
# Line 952  ui_screenblt(uint8 opcode, Line 959  ui_screenblt(uint8 opcode,
959          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
960          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
961          if (ownbackstore)          if (ownbackstore)
962                  XCopyArea(display, backstore, backstore, gc, srcx, srcy,                  XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
963          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
964  }  }
965    
# Line 963  ui_memblt(uint8 opcode, Line 969  ui_memblt(uint8 opcode,
969            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
970  {  {
971          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
972          XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
973          if (ownbackstore)          if (ownbackstore)
974                  XCopyArea(display, (Pixmap)src, backstore, gc, srcx, srcy,                  XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
975          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
976  }  }
977    
# Line 974  void Line 979  void
979  ui_triblt(uint8 opcode,  ui_triblt(uint8 opcode,
980            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
981            /* src */ HBITMAP src, int srcx, int srcy,            /* src */ HBITMAP src, int srcx, int srcy,
982            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
983  {  {
984          /* This is potentially difficult to do in general. Until someone          /* This is potentially difficult to do in general. Until someone
985             comes up with a more efficient way of doing it I am using cases. */             comes up with a more efficient way of doing it I am using cases. */
# Line 983  ui_triblt(uint8 opcode, Line 988  ui_triblt(uint8 opcode,
988          {          {
989                  case 0x69:      /* PDSxxn */                  case 0x69:      /* PDSxxn */
990                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);
991                          ui_patblt(ROP2_NXOR, x, y, cx, cy,                          ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
992                          break;                          break;
993    
994                  case 0xb8:      /* PSDPxax */                  case 0xb8:      /* PSDPxax */
995                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
996                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);
997                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
998                          break;                          break;
999    
1000                  case 0xc0:      /* PSa */                  case 0xc0:      /* PSa */
1001                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
1002                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   fgcolour);  
1003                          break;                          break;
1004    
1005                  default:                  default:
# Line 1010  ui_triblt(uint8 opcode, Line 1011  ui_triblt(uint8 opcode,
1011  void  void
1012  ui_line(uint8 opcode,  ui_line(uint8 opcode,
1013          /* dest */ int startx, int starty, int endx, int endy,          /* dest */ int startx, int starty, int endx, int endy,
1014          /* pen */ PEN *pen)          /* pen */ PEN * pen)
1015  {  {
1016          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1017          SET_FOREGROUND(pen->colour);          SET_FOREGROUND(pen->colour);
# Line 1032  ui_rect( Line 1033  ui_rect(
1033  void  void
1034  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1035                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
1036                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,                /* src */ HGLYPH glyph, int srcx, int srcy,
1037                int fgcolour)                int bgcolour, int fgcolour)
1038  {  {
1039          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
1040          SET_BACKGROUND(bgcolour);          SET_BACKGROUND(bgcolour);
1041    
1042          XSetFillStyle(display, gc, (mixmode == MIX_TRANSPARENT)          XSetFillStyle(display, gc,
1043                        ? FillStippled : FillOpaqueStippled);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1044          XSetStipple(display, gc, (Pixmap)glyph);          XSetStipple(display, gc, (Pixmap) glyph);
1045          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(display, gc, x, y);
1046    
1047          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE(x, y, cx, cy);
# Line 1057  ui_draw_glyph(int mixmode, Line 1058  ui_draw_glyph(int mixmode,
1058        if ((xyoffset & 0x80))\        if ((xyoffset & 0x80))\
1059          {\          {\
1060            if (flags & TEXT2_VERTICAL) \            if (flags & TEXT2_VERTICAL) \
1061              y += ttext[++idx] | (ttext[++idx] << 8);\              y += ttext[idx+1] | (ttext[idx+2] << 8);\
1062            else\            else\
1063              x += ttext[++idx] | (ttext[++idx] << 8);\              x += ttext[idx+1] | (ttext[idx+2] << 8);\
1064              idx += 2;\
1065          }\          }\
1066        else\        else\
1067          {\          {\
# Line 1082  ui_draw_glyph(int mixmode, Line 1084  ui_draw_glyph(int mixmode,
1084    
1085  void  void
1086  ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,  ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,
1087               int clipx, int clipy, int clipcx, int clipcy, int boxx,               int clipx, int clipy, int clipcx, int clipcy,
1088               int boxy, int boxcx, int boxcy, int bgcolour,               int boxx, int boxy, int boxcx, int boxcy, int bgcolour,
1089               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1090  {  {
1091          FONTGLYPH *glyph;          FONTGLYPH *glyph;
# Line 1102  ui_draw_text(uint8 font, uint8 flags, in Line 1104  ui_draw_text(uint8 font, uint8 flags, in
1104          }          }
1105    
1106          /* Paint text, character by character */          /* Paint text, character by character */
1107          for (i = 0; i < length;) {          for (i = 0; i < length;)
1108                  switch (text[i]) {          {
1109                  case 0xff:                  switch (text[i])
1110                          if (i + 2 < length)                  {
1111                                  cache_put_text(text[i + 1], text, text[i + 2]);                          case 0xff:
1112                          else {                                  if (i + 2 < length)
1113                                  error("this shouldn't be happening\n");                                          cache_put_text(text[i + 1], text, text[i + 2]);
1114                                    else
1115                                    {
1116                                            error("this shouldn't be happening\n");
1117                                            break;
1118                                    }
1119                                    /* this will move pointer from start to first character after FF command */
1120                                    length -= i + 3;
1121                                    text = &(text[i + 3]);
1122                                    i = 0;
1123                                  break;                                  break;
                         }  
                         /* this will move pointer from start to first character after FF command */  
                         length -= i + 3;  
                         text = &(text[i + 3]);  
                         i = 0;  
                         break;  
1124    
1125                  case 0xfe:                          case 0xfe:
1126                          entry = cache_get_text(text[i + 1]);                                  entry = cache_get_text(text[i + 1]);
1127                          if (entry != NULL) {                                  if (entry != NULL)
1128                                  if ((((uint8 *) (entry->data))[1] == 0)                                  {
1129                                      && (!(flags & TEXT2_IMPLICIT_X))) {                                          if ((((uint8 *) (entry->data))[1] ==
1130                                          if (flags & TEXT2_VERTICAL)                                               0) && (!(flags & TEXT2_IMPLICIT_X)))
1131                                                  y += text[i + 2];                                          {
1132                                                    if (flags & TEXT2_VERTICAL)
1133                                                            y += text[i + 2];
1134                                                    else
1135                                                            x += text[i + 2];
1136                                            }
1137                                            if (i + 2 < length)
1138                                                    i += 3;
1139                                          else                                          else
1140                                                  x += text[i + 2];                                                  i += 2;
1141                                            length -= i;
1142                                            /* this will move pointer from start to first character after FE command */
1143                                            text = &(text[i]);
1144                                            i = 0;
1145                                            for (j = 0; j < entry->size; j++)
1146                                                    DO_GLYPH(((uint8 *) (entry->data)), j);
1147                                  }                                  }
1148                                  if (i + 2 < length)                                  break;
                                         i += 3;  
                                 else  
                                         i += 2;  
                                 length -= i;  
                                 /* this will move pointer from start to first character after FE command */  
                                 text = &(text[i]);  
                                 i = 0;  
                                 for (j = 0; j < entry->size; j++)  
                                         DO_GLYPH(((uint8 *) (entry->data)), j);  
                         }  
                         break;  
1149    
1150                  default:                          default:
1151                          DO_GLYPH(text, i);                                  DO_GLYPH(text, i);
1152                          i++;                                  i++;
1153                          break;                                  break;
1154                  }                  }
1155          }          }
1156    
# Line 1158  ui_desktop_save(uint32 offset, int x, in Line 1165  ui_desktop_save(uint32 offset, int x, in
1165    
1166          if (ownbackstore)          if (ownbackstore)
1167          {          {
1168                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes,                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1169          }          }
1170          else          else
1171          {          {
1172                  pix = XCreatePixmap(display, wnd, cx, cy, depth);                  pix = XCreatePixmap(display, wnd, cx, cy, depth);
1173                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);
1174                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes,                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1175                  XFreePixmap(display, pix);                  XFreePixmap(display, pix);
1176          }          }
1177    
1178          offset *= bpp/8;          offset *= bpp / 8;
1179          cache_put_desktop(offset, cx, cy, image->bytes_per_line,          cache_put_desktop(offset, cx, cy, image->bytes_per_line, bpp / 8, (uint8 *) image->data);
                           bpp/8, (uint8 *)image->data);  
1180    
1181          XDestroyImage(image);          XDestroyImage(image);
1182  }  }
# Line 1183  ui_desktop_restore(uint32 offset, int x, Line 1187  ui_desktop_restore(uint32 offset, int x,
1187          XImage *image;          XImage *image;
1188          uint8 *data;          uint8 *data;
1189    
1190          offset *= bpp/8;          offset *= bpp / 8;
1191          data = cache_get_desktop(offset, cx, cy, bpp/8);          data = cache_get_desktop(offset, cx, cy, bpp / 8);
1192          if (data == NULL)          if (data == NULL)
1193                  return;                  return;
1194    
1195          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1196                               0, data, cx, cy, BitmapPad(display),                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);
                              cx * bpp/8);  
1197    
1198          if (ownbackstore)          if (ownbackstore)
1199          {          {

Legend:
Removed from v.52  
changed lines
  Added in v.182

  ViewVC Help
Powered by ViewVC 1.1.26