/[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 54 by n-ki, Fri Jun 7 07:49:59 2002 UTC revision 121 by matthewc, Sat Sep 14 11:48:44 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;
43  static int depth;  static int depth;
44  static int bpp;  static int bpp;
45    static int dpy_width;
46    static int dpy_height;
47    
48  /* endianness */  /* endianness */
49  static BOOL host_be;  static BOOL host_be;
# Line 49  static BOOL xserver_be; Line 53  static BOOL xserver_be;
53  static BOOL ownbackstore;  static BOOL ownbackstore;
54  static Pixmap backstore;  static Pixmap backstore;
55    
 /* needed to keep track of the modifiers */  
 static unsigned int numlock_modifier_mask = 0;  
 static unsigned int key_down_state = 0;  
   
   
 #define DShift1Mask   (1<<0)  
 #define DLockMask     (1<<1)  
 #define DControl1Mask (1<<2)  
 #define DMod1Mask     (1<<3)  
 #define DMod2Mask     (1<<4)  
 #define DMod3Mask     (1<<5)  
 #define DMod4Mask     (1<<6)  
 #define DMod5Mask     (1<<7)  
 #define DShift2Mask   (1<<8)  
 #define DControl2Mask (1<<9)  
 #define DNumLockMask  (1<<10)  
   
56  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
57  { \  { \
58          XFillRectangle(display, wnd, gc, x, y, cx, cy); \          XFillRectangle(display, wnd, gc, x, y, cx, cy); \
# Line 76  static unsigned int key_down_state = 0; Line 63  static unsigned int key_down_state = 0;
63  /* colour maps */  /* colour maps */
64  static BOOL owncolmap;  static BOOL owncolmap;
65  static Colormap xcolmap;  static Colormap xcolmap;
 static uint32 white;  
66  static uint32 *colmap;  static uint32 *colmap;
67    
68    /* Compose support */
69    BOOL enable_compose = False;
70    static XIM IM = NULL;
71    static XIC IC = NULL;
72    
73    /* toggle fullscreen globals */
74    static unsigned long input_mask;
75    
76  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )
77  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
78  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
# Line 105  static int rop2_map[] = { Line 99  static int rop2_map[] = {
99  #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]); }
100  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
101    
 void xwin_get_numlock_mask();  
 void xwin_mod_update(uint32 state, uint32 ev_time );  
 void xwin_mod_release(uint32 state, uint32 ev_time, uint32 scancode);  
 void xwin_mod_press(uint32 state, uint32 ev_time, uint32 scancode);  
   
102  static void  static void
103  translate8(uint8 *data, uint8 *out, uint8 *end)  translate8(uint8 * data, uint8 * out, uint8 * end)
104  {  {
105          while (out < end)          while (out < end)
106                  *(out++) = (uint8)colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
107  }  }
108    
109  static void  static void
110  translate16(uint8 *data, uint16 *out, uint16 *end)  translate16(uint8 * data, uint16 * out, uint16 * end)
111  {  {
112          while (out < end)          while (out < end)
113                  *(out++) = (uint16)colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
114  }  }
115    
116  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
117  static void  static void
118  translate24(uint8 *data, uint8 *out, uint8 *end)  translate24(uint8 * data, uint8 * out, uint8 * end)
119  {  {
120          uint32 value;          uint32 value;
121    
# Line 140  translate24(uint8 *data, uint8 *out, uin Line 129  translate24(uint8 *data, uint8 *out, uin
129  }  }
130    
131  static void  static void
132  translate32(uint8 *data, uint32 *out, uint32 *end)  translate32(uint8 * data, uint32 * out, uint32 * end)
133  {  {
134          while (out < end)          while (out < end)
135                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
136  }  }
137    
138  static uint8 *  static uint8 *
139  translate_image(int width, int height, uint8 *data)  translate_image(int width, int height, uint8 * data)
140  {  {
141          int size = width * height * bpp/8;          int size = width * height * bpp / 8;
142          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
143          uint8 *end = out + size;          uint8 *end = out + size;
144    
# Line 160  translate_image(int width, int height, u Line 149  translate_image(int width, int height, u
149                          break;                          break;
150    
151                  case 16:                  case 16:
152                          translate16(data, (uint16 *)out, (uint16 *)end);                          translate16(data, (uint16 *) out, (uint16 *) end);
153                          break;                          break;
154    
155                  case 24:                  case 24:
# Line 168  translate_image(int width, int height, u Line 157  translate_image(int width, int height, u
157                          break;                          break;
158    
159                  case 32:                  case 32:
160                          translate32(data, (uint32 *)out, (uint32 *)end);                          translate32(data, (uint32 *) out, (uint32 *) end);
161                          break;                          break;
162          }          }
163    
# Line 204  translate_colour(uint32 colour) Line 193  translate_colour(uint32 colour)
193          return colour;          return colour;
194  }  }
195    
196  BOOL  static unsigned long
197  ui_create_window(char *title)  init_inputmethod(void)
198  {  {
199          XSetWindowAttributes attribs;          unsigned long filtered_events = 0;
200          XClassHint *classhints;  
201          XSizeHints *sizehints;          IM = XOpenIM(display, NULL, NULL, NULL);
202          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 )  
203          {          {
204                  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;  
205          }          }
206    
207            if (IM != NULL)
208            {
209                    /* Must be done after XCreateWindow */
210                    IC = XCreateIC(IM, XNInputStyle,
211                                   (XIMPreeditNothing | XIMStatusNothing),
212                                   XNClientWindow, wnd, XNFocusWindow, wnd, NULL);
213    
214          display = XkbOpenDisplay( NULL, &xkb_event, &xkb_error, &xkb_major, &xkb_minor, &xkb_reason );                  if (IC == NULL)
215          switch(xkb_reason)                  {
216                            error("Failed to create input context\n");
217                            XCloseIM(IM);
218                            IM = NULL;
219                    }
220            }
221    
222            /* For correct Multi_key/Compose processing, I guess.
223               It seems to work alright anyway, though. */
224            if (IC != NULL)
225          {          {
226                  case XkbOD_BadLibraryVersion:                  if (XGetICValues(IC, XNFilterEvents, &filtered_events, NULL) != NULL)
227                          error("XkbOD_BadLibraryVersion: XKB extensions in server and the library rdesktop is linked against aren't compatible with each other.\n");                  {
228                          break;                          error("Failed to obtain XNFilterEvents value from IC\n");
229                  case XkbOD_ConnectionRefused:                          filtered_events = 0;
230                          error("XkbOD_ConnectionRefused\n");                  }
231                          break;          }
232                  case XkbOD_BadServerVersion:          return filtered_events;
233                          error("XkbOD_BadServerVersion\n");  }
234                          break;  
235                  case XkbOD_NonXkbServer:  static void
236                          error("XkbOD_NonXkbServer: XKB extension not present in server\nupdate your X server.\n");  close_inputmethod(void)
237                          break;  {
238                  case XkbOD_Success:          if (IC != NULL)
239                          DEBUG("XkbOD_Success: Connection established with display\n");          {
240                          break;                  XDestroyIC(IC);
241                    if (IM != NULL)
242                    {
243                            XCloseIM(IM);
244                            IM = NULL;
245                    }
246          }          }
247    }
248    
249    BOOL
250    get_key_state(int keysym)
251    {
252            int keysymMask = 0, modifierpos, key;
253            Window wDummy1, wDummy2;
254            int iDummy3, iDummy4, iDummy5, iDummy6;
255            unsigned int current_state;
256            int offset;
257    
258            XModifierKeymap *map = XGetModifierMapping(display);
259            KeyCode keycode = XKeysymToKeycode(display, keysym);
260    
261            if (keycode == NoSymbol)
262                    return False;
263    
264            for (modifierpos = 0; modifierpos < 8; modifierpos++)
265            {
266                    offset = map->max_keypermod * modifierpos;
267    
268                    for (key = 0; key < map->max_keypermod; key++)
269                    {
270                            if (map->modifiermap[offset + key] == keycode)
271                                    keysymMask = 1 << modifierpos;
272                    }
273            }
274    
275            XQueryPointer(display, DefaultRootWindow(display), &wDummy1,
276                          &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &current_state);
277    
278            XFreeModifiermap(map);
279    
280            return (current_state & keysymMask) ? True : False;
281    }
282    
283    
284    BOOL
285    ui_init()
286    {
287            XPixmapFormatValues *pfm;
288            uint16 test;
289            int i;
290    
291            display = XOpenDisplay(NULL);
292          if (display == NULL)          if (display == NULL)
293          {          {
294                  error("Failed to open display\n");                  error("Failed to open display\n");
# Line 259  ui_create_window(char *title) Line 299  ui_create_window(char *title)
299          screen = DefaultScreenOfDisplay(display);          screen = DefaultScreenOfDisplay(display);
300          visual = DefaultVisualOfScreen(screen);          visual = DefaultVisualOfScreen(screen);
301          depth = DefaultDepthOfScreen(screen);          depth = DefaultDepthOfScreen(screen);
302            
303          pfm = XListPixmapFormats(display, &i);          pfm = XListPixmapFormats(display, &i);
304          if (pfm != NULL)          if (pfm != NULL)
305          {          {
# Line 267  ui_create_window(char *title) Line 307  ui_create_window(char *title)
307                     desirable, e.g. 24 bits->32 bits. */                     desirable, e.g. 24 bits->32 bits. */
308                  while (i--)                  while (i--)
309                  {                  {
310                          if ((pfm[i].depth == depth)                          if ((pfm[i].depth == depth) && (pfm[i].bits_per_pixel > bpp))
                             && (pfm[i].bits_per_pixel > bpp))  
311                          {                          {
312                                  bpp = pfm[i].bits_per_pixel;                                  bpp = pfm[i].bits_per_pixel;
313                          }                          }
# Line 288  ui_create_window(char *title) Line 327  ui_create_window(char *title)
327          else          else
328                  xcolmap = DefaultColormapOfScreen(screen);                  xcolmap = DefaultColormapOfScreen(screen);
329    
330            if (DoesBackingStore(screen) == NotUseful)
331                    ownbackstore = True;
332    
333          test = 1;          test = 1;
334          host_be = !(BOOL)(*(uint8 *)(&test));          host_be = !(BOOL) (*(uint8 *) (&test));
335          xserver_be = (ImageByteOrder(display) == MSBFirst);          xserver_be = (ImageByteOrder(display) == MSBFirst);
336    
         white = WhitePixelOfScreen(screen);  
         attribs.background_pixel = BlackPixelOfScreen(screen);  
         attribs.backing_store = DoesBackingStore(screen);  
   
         if (attribs.backing_store == NotUseful)  
                 ownbackstore = True;  
   
337          if (fullscreen)          if (fullscreen)
338          {          {
                 attribs.override_redirect = True;  
339                  width = WidthOfScreen(screen);                  width = WidthOfScreen(screen);
340                  height = HeightOfScreen(screen);                  height = HeightOfScreen(screen);
341          }          }
         else  
         {  
                 attribs.override_redirect = False;  
         }  
342    
343          width = (width + 3) & ~3; /* make width a multiple of 32 bits */          xkeymap_init();
344            return True;
345    }
346    
347          wnd = XCreateWindow(display, RootWindowOfScreen(screen),  BOOL
348                              0, 0, width, height, 0, CopyFromParent,  ui_create_window()
349                              InputOutput, CopyFromParent,  {
350                              CWBackingStore | CWBackPixel | CWOverrideRedirect,          XSetWindowAttributes attribs;
351                              &attribs);          XClassHint *classhints;
352            XSizeHints *sizehints;
353            XEvent xevent;
354    
355            attribs.background_pixel = BlackPixelOfScreen(screen);
356            attribs.backing_store = ownbackstore ? NotUseful : Always;
357            attribs.override_redirect = fullscreen;
358            wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height,
359                                0, CopyFromParent, InputOutput, CopyFromParent,
360                                CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
361    
362          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
363    
# Line 338  ui_create_window(char *title) Line 379  ui_create_window(char *title)
379                  XFree(sizehints);                  XFree(sizehints);
380          }          }
381    
382          xkeymap_init();          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
383                    VisibilityChangeMask | FocusChangeMask;
384    
385          input_mask = KeyPressMask | KeyReleaseMask |          if (grab_keyboard)
386                           ButtonPressMask | ButtonReleaseMask |                  input_mask |= EnterWindowMask | LeaveWindowMask;
                          EnterWindowMask | LeaveWindowMask;  
387          if (sendmotion)          if (sendmotion)
388                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
   
389          if (ownbackstore)          if (ownbackstore)
390                  input_mask |= ExposureMask;                  input_mask |= ExposureMask;
391            if (enable_compose)
392                    input_mask |= init_inputmethod();
393    
394          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
         gc = XCreateGC(display, wnd, 0, NULL);  
395    
396          if (ownbackstore)          gc = XCreateGC(display, wnd, 0, NULL);
                 backstore = XCreatePixmap(display, wnd, width, height, depth);  
397    
398          XMapWindow(display, wnd);          XMapWindow(display, wnd);
399    
400          /* TODO: error texts... make them friendly. */          /* Wait for VisibilityNotify Event */
401          xkb = XkbGetKeyboard(display, XkbAllComponentsMask, XkbUseCoreKbd);          for (;;)
         if ((int)xkb == BadAlloc || xkb == NULL)  
         {  
                         error( "XkbGetKeyboard failed.\n");  
                         exit(0);  
         }  
   
         /* TODO: error texts... make them friendly. */  
         if( XkbSelectEvents(display, xkb->device_spec, XkbAllEventsMask, XkbAllEventsMask) == False )  
402          {          {
403                          error( "XkbSelectEvents failed.\n");                  XNextEvent(display, &xevent);
404                          exit(0);                  if (xevent.type == VisibilityNotify)
405                            break;
406          }          }
407            
408          xwin_get_numlock_mask();          if (ownbackstore)
409                    backstore = XCreatePixmap(display, wnd, width, height, depth);
410    
411            /* clear the window so that cached data is not viewed upon start... */
412            XSetBackground(display, gc, 0);
413            XSetForeground(display, gc, 0);
414            FILL_RECTANGLE(0, 0, width, height);
415            /* make sure the window is focused */
416            XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime);
417    
418          return True;          return True;
419  }  }
420    
421  void  void
422  xwin_get_numlock_mask()  ui_destroy_window()
423  {  {
424          KeyCode numlockcode;          if (ownbackstore)
425          KeyCode* keycode;                  XFreePixmap(display, backstore);
426          XModifierKeymap *modmap;  
427          int i,j;          XFreeGC(display, gc);
   
         /* Find out if numlock is already defined as a modifier key, and if so where */  
         numlockcode = XKeysymToKeycode(display, 0xFF7F);        /* XF_Num_Lock = 0xFF7F */  
         if (numlockcode) {  
                 modmap = XGetModifierMapping(display);  
                 if (modmap) {  
                         keycode = modmap->modifiermap;  
                         for (i = 0; i < 8; i++)  
                                 for (j = modmap->max_keypermod; j--;) {  
                                         if (*keycode == numlockcode) {  
                                                 numlock_modifier_mask = (1 << i);  
                                                 i = 8;  
                                                 break;  
                                         }  
                                         keycode++;  
                                 }  
                 if (!numlock_modifier_mask) {  
                                 modmap->modifiermap[7 * modmap->max_keypermod] = numlockcode;  
                                 if (XSetModifierMapping(display, modmap) == MappingSuccess)  
                                         numlock_modifier_mask = (1 << 7);  
                                 else  
                                         printf("XSetModifierMapping failed!\n");  
                         }  
                         XFreeModifiermap(modmap);  
                 }  
         }  
428    
429          if (!numlock_modifier_mask)          close_inputmethod();
430                  printf("WARNING: Failed to get a numlock modifier mapping.\n");  
431                            XDestroyWindow(display, wnd);
432            XCloseDisplay(display);
433            display = NULL;
434  }  }
435    
436  void  void
437  ui_destroy_window()  reset_keys()
438  {  {
439          if( xkb != NULL )          /* reset keys */
440                  XkbFreeKeyboard(xkb, XkbAllControlsMask, True);          uint32 ev_time;
441            ev_time = time(NULL);
442            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL);
443            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT);
444            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT);
445            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL);
446            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT);
447            rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT);
448    }
449    
450    void
451    toggle_fullscreen()
452    {
453            /* save window contents */
454            Pixmap pixmap;
455            pixmap = XCreatePixmap(display, wnd, width, height, depth);
456            if (ownbackstore)
457                    XCopyArea(display, backstore, pixmap, gc, 0, 0, width, height, 0, 0);
458            else
459                    XCopyArea(display, wnd, pixmap, gc, 0, 0, width, height, 0, 0);
460            fullscreen = fullscreen ? False : True;
461            close_inputmethod();
462          if (ownbackstore)          if (ownbackstore)
463                  XFreePixmap(display, backstore);                  XFreePixmap(display, backstore);
   
464          XFreeGC(display, gc);          XFreeGC(display, gc);
465          XDestroyWindow(display, wnd);          XDestroyWindow(display, wnd);
466          XCloseDisplay(display);          ui_create_window();
467          display = NULL;          ui_set_cursor(cache_get_cursor(0));
468            ui_move_pointer(width / 2, height / 2);
469            reset_keys();
470            /* restore window contents */
471            if (ownbackstore)
472                    XCopyArea(display, pixmap, backstore, gc, 0, 0, width, height, 0, 0);
473            XCopyArea(display, pixmap, wnd, gc, 0, 0, width, height, 0, 0);
474            XFreePixmap(display, pixmap);
475  }  }
476    
477    /* Process all events in Xlib queue */
478  static void  static void
479  xwin_process_events()  xwin_process_events()
480  {  {
481          XEvent xevent;          XEvent xevent;
482    
483          KeySym keysym;          KeySym keysym;
         uint8 scancode;  
484          uint16 button, flags;          uint16 button, flags;
485          uint32 ev_time;          uint32 ev_time;
486          uint32 tmpmods;          key_translation tr;
487            char *ksname = NULL;
488            char str[256];
489            Status status;
490    
491          while (XCheckMaskEvent(display, ~0, &xevent))          while (XCheckMaskEvent(display, ~0, &xevent))
492          {          {
493                    if (enable_compose && (XFilterEvent(&xevent, None) == True))
494                    {
495                            DEBUG_KBD(("Filtering event\n"));
496                            continue;
497                    }
498    
499                  ev_time = time(NULL);                  ev_time = time(NULL);
500                  flags = 0;                  flags = 0;
501    
502                  switch (xevent.type)                  switch (xevent.type)
503                  {                  {
                         case KeyRelease:  
                                 flags = KBD_FLAG_DOWN | KBD_FLAG_UP;  
                                 /* fall through */  
504                          case KeyPress:                          case KeyPress:
505                                  if( XkbTranslateKeyCode(xkb, xevent.xkey.keycode, xevent.xkey.state, &tmpmods, &keysym) == False )                                  if (IC != NULL)
506                                            /* Multi_key compatible version */
507                                    {
508                                            XmbLookupString(IC,
509                                                            (XKeyPressedEvent *) &
510                                                            xevent, str, sizeof(str), &keysym, &status);
511                                            if (!((status == XLookupKeySym) || (status == XLookupBoth)))
512                                            {
513                                                    error("XmbLookupString failed with status 0x%x\n",
514                                                          status);
515                                                    break;
516                                            }
517                                    }
518                                    else
519                                    {
520                                            /* Plain old XLookupString */
521                                            DEBUG_KBD(("No input context, using XLookupString\n"));
522                                            XLookupString((XKeyEvent *) & xevent,
523                                                          str, sizeof(str), &keysym, NULL);
524                                    }
525    
526                                    ksname = get_ksname(keysym);
527                                    DEBUG_KBD(("\nKeyPress for (keysym 0x%lx, %s)\n", keysym, ksname));
528    
529                                    if (handle_special_keys(keysym, ev_time, True))
530                                          break;                                          break;
                                 scancode = xkeymap_translate_key(keysym, xevent.xkey.keycode, &flags);  
531    
532                                  if (scancode == 0 )                                  tr = xkeymap_translate_key(keysym,
533                                                               xevent.xkey.keycode, xevent.xkey.state);
534    
535                                    if (tr.scancode == 0)
536                                          break;                                          break;
537    
538                                  /* keep track of the modifiers -- needed for stickykeys... */                                  ensure_remote_modifiers(ev_time, tr);
539                                  if( xevent.type == KeyPress )  
540                                          xwin_mod_press( xevent.xkey.state, ev_time, scancode );                                  rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode);
541                                    break;
542                            case KeyRelease:
543                                    XLookupString((XKeyEvent *) & xevent, str,
544                                                  sizeof(str), &keysym, NULL);
545    
546                                    ksname = get_ksname(keysym);
547                                    DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym,
548                                               ksname));
549    
550                                    if (handle_special_keys(keysym, ev_time, False))
551                                            break;
552    
553                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, flags, scancode, 0);                                  tr = xkeymap_translate_key(keysym,
554                                                               xevent.xkey.keycode, xevent.xkey.state);
555    
556                                  if( xevent.type == KeyRelease )                                  if (tr.scancode == 0)
557                                          xwin_mod_release( xevent.xkey.state, ev_time, scancode );                                          break;
558    
559                                    rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode);
560                                  break;                                  break;
561    
562                          case ButtonPress:                          case ButtonPress:
# Line 481  xwin_process_events() Line 569  xwin_process_events()
569                                          break;                                          break;
570    
571                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
572                                                 flags | button,                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
                                                xevent.xbutton.x,  
                                                xevent.xbutton.y);  
573                                  break;                                  break;
574    
575                          case MotionNotify:                          case MotionNotify:
576                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
577                                                 MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y);
                                                xevent.xmotion.x,  
                                                xevent.xmotion.y);  
578                                  break;                                  break;
579    
580                            case FocusIn:
581                                    /* fall through */
582                          case EnterNotify:                          case EnterNotify:
583                                  XGrabKeyboard(display, wnd, True, GrabModeAsync,                                  if (grab_keyboard)
584                                                GrabModeAsync, CurrentTime);                                          XGrabKeyboard(display, wnd, True,
585                                                          GrabModeAsync, GrabModeAsync, CurrentTime);
                                  xwin_mod_update( xevent.xcrossing.state, ev_time );  
586                                  break;                                  break;
587    
588                            case FocusOut:
589                                    reset_keys();
590                                    /* fall through */
591                          case LeaveNotify:                          case LeaveNotify:
592                                  XUngrabKeyboard(display, CurrentTime);                                  if (grab_keyboard)
593                                            XUngrabKeyboard(display, CurrentTime);
594                                  break;                                  break;
595    
596                          case Expose:                          case Expose:
597                                  XCopyArea(display, backstore, wnd, gc,                                  XCopyArea(display, backstore, wnd, gc,
598                                            xevent.xexpose.x, xevent.xexpose.y,                                            xevent.xexpose.x, xevent.xexpose.y,
599                                            xevent.xexpose.width, xevent.xexpose.height,                                            xevent.xexpose.width,
600                                              xevent.xexpose.height,
601                                            xevent.xexpose.x, xevent.xexpose.y);                                            xevent.xexpose.x, xevent.xexpose.y);
602                                  break;                                  break;
                 }  
         }  
 }  
   
 void  
 xwin_mod_update(uint32 state, uint32 ev_time )  
 {  
         xwin_mod_press(state, ev_time, 0);  
         xwin_mod_release(state, ev_time, 0);  
 }  
   
 void  
 xwin_mod_release(uint32 state, 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( !(numlock_modifier_mask & state) && (key_down_state & DNumLockMask) )  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);  
                 key_down_state &= ~DNumLockMask;  
         }  
   
         if( !(LockMask & state) && (key_down_state & DLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);  
                 key_down_state &= ~DLockMask;  
   
         }  
   
   
         if( !(ShiftMask & state) && (key_down_state & DShift1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x2a, 0);  
                 key_down_state &= ~DShift1Mask;  
   
         }  
   
         if( !(ControlMask & state) && (key_down_state & DControl1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x1d, 0);  
                 key_down_state &= ~DControl1Mask;  
   
         }  
   
         if( !(Mod1Mask & state) && (key_down_state & DMod1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0x38, 0);  
                 key_down_state &= ~DMod1Mask;  
   
         }  
   
         if( !(Mod2Mask & state) && (key_down_state & DMod2Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_UP, 0xb8, 0);  
                 key_down_state &= ~DMod2Mask;  
         }  
 }  
   
   
 void  
 xwin_mod_press(uint32 state, 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 0x3a:  
                 key_down_state ^= DLockMask;  
                 break;  
         case 0x45:  
                 key_down_state ^= DNumLockMask;  
                 break;  
         case 0x38:  
                 key_down_state |= DMod1Mask;  
                 break;  
         case 0xb8:  
                 key_down_state |= DMod2Mask;  
                 break;  
         }  
   
         if( (numlock_modifier_mask && state) && !(key_down_state & DNumLockMask) )  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x45, 0);  
                 key_down_state |= DNumLockMask;  
         }  
   
         if( (LockMask & state) && !(key_down_state & DLockMask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x3a, 0);  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN | KBD_FLAG_UP, 0x3a, 0);  
                 key_down_state |= DLockMask;  
   
         }  
   
   
         if( (ShiftMask & 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 & 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;  
   
         }  
   
         if( (Mod1Mask & state) && !(key_down_state & DMod1Mask))  
         {  
                 rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0x38, 0);  
                 key_down_state |= DMod1Mask;  
   
         }  
603    
604          if( (Mod2Mask & state) && !(key_down_state & DMod2Mask))                          case MappingNotify:
605          {                                  /* Refresh keyboard mapping if it has changed. This is important for
606                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, KBD_FLAG_DOWN, 0xb8, 0);                                     Xvnc, since it allocates keycodes dynamically */
607                  key_down_state |= DMod2Mask;                                  if (xevent.xmapping.request == MappingKeyboard
608                                        || xevent.xmapping.request == MappingModifier)
609                                            XRefreshKeyboardMapping(&xevent.xmapping);
610                                    break;
611    
612                    }
613          }          }
614  }  }
615    
616  void  void
617  ui_select(int rdp_socket)  ui_select(int rdp_socket)
618  {  {
619          int n = (rdp_socket > x_socket) ? rdp_socket+1 : x_socket+1;          int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1;
620          fd_set rfds;          fd_set rfds;
621    
622          FD_ZERO(&rfds);          FD_ZERO(&rfds);
623    
624          while (True)          while (True)
625          {          {
626                    /* Process any events already waiting */
627                    XFlush(display);
628                    xwin_process_events();
629    
630                  FD_ZERO(&rfds);                  FD_ZERO(&rfds);
631                  FD_SET(rdp_socket, &rfds);                  FD_SET(rdp_socket, &rfds);
632                  if (display != NULL)                  FD_SET(x_socket, &rfds);
                 {  
                         FD_SET(x_socket, &rfds);  
                         XFlush(display);  
                 }  
633    
634                  switch (select(n, &rfds, NULL, NULL, NULL))                  switch (select(n, &rfds, NULL, NULL, NULL))
635                  {                  {
# Line 693  ui_select(int rdp_socket) Line 640  ui_select(int rdp_socket)
640                                  continue;                                  continue;
641                  }                  }
642    
                 if (FD_ISSET(x_socket, &rfds))  
                         xwin_process_events();  
   
643                  if (FD_ISSET(rdp_socket, &rfds))                  if (FD_ISSET(rdp_socket, &rfds))
644                          return;                          return;
645          }          }
# Line 708  ui_move_pointer(int x, int y) Line 652  ui_move_pointer(int x, int y)
652  }  }
653    
654  HBITMAP  HBITMAP
655  ui_create_bitmap(int width, int height, uint8 *data)  ui_create_bitmap(int width, int height, uint8 * data)
656  {  {
657          XImage *image;          XImage *image;
658          Pixmap bitmap;          Pixmap bitmap;
# Line 716  ui_create_bitmap(int width, int height, Line 660  ui_create_bitmap(int width, int height,
660    
661          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
662          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
663          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
664                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
665    
666          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
667    
# Line 728  ui_create_bitmap(int width, int height, Line 672  ui_create_bitmap(int width, int height,
672  }  }
673    
674  void  void
675  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)  
676  {  {
677          XImage *image;          XImage *image;
678          uint8 *tdata;          uint8 *tdata;
679    
680          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
681          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
682                               0, tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
683    
684          if (ownbackstore)          if (ownbackstore)
685          {          {
# Line 756  ui_paint_bitmap(int x, int y, int cx, in Line 699  ui_paint_bitmap(int x, int y, int cx, in
699  void  void
700  ui_destroy_bitmap(HBITMAP bmp)  ui_destroy_bitmap(HBITMAP bmp)
701  {  {
702          XFreePixmap(display, (Pixmap)bmp);          XFreePixmap(display, (Pixmap) bmp);
703  }  }
704    
705  HGLYPH  HGLYPH
706  ui_create_glyph(int width, int height, uint8 *data)  ui_create_glyph(int width, int height, uint8 * data)
707  {  {
708          XImage *image;          XImage *image;
709          Pixmap bitmap;          Pixmap bitmap;
# Line 772  ui_create_glyph(int width, int height, u Line 715  ui_create_glyph(int width, int height, u
715          bitmap = XCreatePixmap(display, wnd, width, height, 1);          bitmap = XCreatePixmap(display, wnd, width, height, 1);
716          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(display, bitmap, 0, NULL);
717    
718          image = XCreateImage(display, visual, 1, ZPixmap, 0,          image = XCreateImage(display, visual, 1, ZPixmap, 0, (char *) data,
719                               data, width, height, 8, scanline);                               width, height, 8, scanline);
720          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
721          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
722          XInitImage(image);          XInitImage(image);
# Line 782  ui_create_glyph(int width, int height, u Line 725  ui_create_glyph(int width, int height, u
725    
726          XFree(image);          XFree(image);
727          XFreeGC(display, gc);          XFreeGC(display, gc);
728          return (HGLYPH)bitmap;          return (HGLYPH) bitmap;
729  }  }
730    
731  void  void
732  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(HGLYPH glyph)
733  {  {
734          XFreePixmap(display, (Pixmap)glyph);          XFreePixmap(display, (Pixmap) glyph);
735  }  }
736    
737  HCURSOR  HCURSOR
738  ui_create_cursor(unsigned int x, unsigned int y, int width,  ui_create_cursor(unsigned int x, unsigned int y, int width, int height,
739                   int height, uint8 *andmask, uint8 *xormask)                   uint8 * andmask, uint8 * xormask)
740  {  {
741          HGLYPH maskglyph, cursorglyph;          HGLYPH maskglyph, cursorglyph;
742          XColor bg, fg;          XColor bg, fg;
# Line 850  ui_create_cursor(unsigned int x, unsigne Line 793  ui_create_cursor(unsigned int x, unsigne
793    
794          cursorglyph = ui_create_glyph(width, height, cursor);          cursorglyph = ui_create_glyph(width, height, cursor);
795          maskglyph = ui_create_glyph(width, height, mask);          maskglyph = ui_create_glyph(width, height, mask);
796            
797          xcursor = XCreatePixmapCursor(display, (Pixmap)cursorglyph,          xcursor =
798                                  (Pixmap)maskglyph, &fg, &bg, x, y);                  XCreatePixmapCursor(display, (Pixmap) cursorglyph,
799                                        (Pixmap) maskglyph, &fg, &bg, x, y);
800    
801          ui_destroy_glyph(maskglyph);          ui_destroy_glyph(maskglyph);
802          ui_destroy_glyph(cursorglyph);          ui_destroy_glyph(cursorglyph);
803          xfree(mask);          xfree(mask);
804          xfree(cursor);          xfree(cursor);
805          return (HCURSOR)xcursor;          return (HCURSOR) xcursor;
806  }  }
807    
808  void  void
809  ui_set_cursor(HCURSOR cursor)  ui_set_cursor(HCURSOR cursor)
810  {  {
811          XDefineCursor(display, wnd, (Cursor)cursor);          XDefineCursor(display, wnd, (Cursor) cursor);
812  }  }
813    
814  void  void
815  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_cursor(HCURSOR cursor)
816  {  {
817          XFreeCursor(display, (Cursor)cursor);          XFreeCursor(display, (Cursor) cursor);
818  }  }
819    
820  #define MAKE_XCOLOR(xc,c) \  #define MAKE_XCOLOR(xc,c) \
# Line 880  ui_destroy_cursor(HCURSOR cursor) Line 824  ui_destroy_cursor(HCURSOR cursor)
824                  (xc)->flags = DoRed | DoGreen | DoBlue;                  (xc)->flags = DoRed | DoGreen | DoBlue;
825    
826  HCOLOURMAP  HCOLOURMAP
827  ui_create_colourmap(COLOURMAP *colours)  ui_create_colourmap(COLOURMAP * colours)
828  {  {
829          COLOURENTRY *entry;          COLOURENTRY *entry;
830          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
# Line 903  ui_create_colourmap(COLOURMAP *colours) Line 847  ui_create_colourmap(COLOURMAP *colours)
847                  XStoreColors(display, map, xcolours, ncolours);                  XStoreColors(display, map, xcolours, ncolours);
848    
849                  xfree(xcolours);                  xfree(xcolours);
850                  return (HCOLOURMAP)map;                  return (HCOLOURMAP) map;
851          }          }
852          else          else
853          {          {
# Line 919  ui_create_colourmap(COLOURMAP *colours) Line 863  ui_create_colourmap(COLOURMAP *colours)
863                          if (XAllocColor(display, xcolmap, &xentry) != 0)                          if (XAllocColor(display, xcolmap, &xentry) != 0)
864                                  colour = xentry.pixel;                                  colour = xentry.pixel;
865                          else                          else
866                                  colour = white;                                  colour = WhitePixelOfScreen(screen);
867    
868                          /* byte swap here to make translate_image faster */                          /* byte swap here to make translate_image faster */
869                          map[i] = translate_colour(colour);                          map[i] = translate_colour(colour);
# Line 933  void Line 877  void
877  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
878  {  {
879          if (owncolmap)          if (owncolmap)
880                  XFreeColormap(display, (Colormap)map);                  XFreeColormap(display, (Colormap) map);
881          else          else
882                  xfree(map);                  xfree(map);
883  }  }
# Line 942  void Line 886  void
886  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
887  {  {
888          if (owncolmap)          if (owncolmap)
889                  XSetWindowColormap(display, wnd, (Colormap)map);                  XSetWindowColormap(display, wnd, (Colormap) map);
890          else          else
891                  colmap = map;                  colmap = map;
892  }  }
# Line 989  ui_destblt(uint8 opcode, Line 933  ui_destblt(uint8 opcode,
933  void  void
934  ui_patblt(uint8 opcode,  ui_patblt(uint8 opcode,
935            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
936            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
937  {  {
938          Pixmap fill;          Pixmap fill;
939            uint8 i, ipattern[8];
940    
941          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
942    
# Line 1003  ui_patblt(uint8 opcode, Line 948  ui_patblt(uint8 opcode,
948                          break;                          break;
949    
950                  case 3: /* Pattern */                  case 3: /* Pattern */
951                          fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);                          for (i = 0; i != 8; i++)
952                                    ipattern[7 - i] = brush->pattern[i];
953                            fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
954    
955                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
956                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
# Line 1014  ui_patblt(uint8 opcode, Line 961  ui_patblt(uint8 opcode,
961                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
962    
963                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
964                          ui_destroy_glyph((HGLYPH)fill);                          XSetTSOrigin(display, gc, 0, 0);
965                            ui_destroy_glyph((HGLYPH) fill);
966                          break;                          break;
967    
968                  default:                  default:
# Line 1032  ui_screenblt(uint8 opcode, Line 980  ui_screenblt(uint8 opcode,
980          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
981          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
982          if (ownbackstore)          if (ownbackstore)
983                  XCopyArea(display, backstore, backstore, gc, srcx, srcy,                  XCopyArea(display, backstore, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
984          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
985  }  }
986    
# Line 1043  ui_memblt(uint8 opcode, Line 990  ui_memblt(uint8 opcode,
990            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
991  {  {
992          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
993          XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
994          if (ownbackstore)          if (ownbackstore)
995                  XCopyArea(display, (Pixmap)src, backstore, gc, srcx, srcy,                  XCopyArea(display, (Pixmap) src, backstore, gc, srcx, srcy, cx, cy, x, y);
                           cx, cy, x, y);  
996          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
997  }  }
998    
# Line 1054  void Line 1000  void
1000  ui_triblt(uint8 opcode,  ui_triblt(uint8 opcode,
1001            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
1002            /* src */ HBITMAP src, int srcx, int srcy,            /* src */ HBITMAP src, int srcx, int srcy,
1003            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH * brush, int bgcolour, int fgcolour)
1004  {  {
1005          /* This is potentially difficult to do in general. Until someone          /* This is potentially difficult to do in general. Until someone
1006             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 1063  ui_triblt(uint8 opcode, Line 1009  ui_triblt(uint8 opcode,
1009          {          {
1010                  case 0x69:      /* PDSxxn */                  case 0x69:      /* PDSxxn */
1011                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);
1012                          ui_patblt(ROP2_NXOR, x, y, cx, cy,                          ui_patblt(ROP2_NXOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1013                          break;                          break;
1014    
1015                  case 0xb8:      /* PSDPxax */                  case 0xb8:      /* PSDPxax */
1016                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1017                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);
1018                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   brush, bgcolour, fgcolour);  
1019                          break;                          break;
1020    
1021                  case 0xc0:      /* PSa */                  case 0xc0:      /* PSa */
1022                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
1023                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour, fgcolour);
                                   fgcolour);  
1024                          break;                          break;
1025    
1026                  default:                  default:
# Line 1090  ui_triblt(uint8 opcode, Line 1032  ui_triblt(uint8 opcode,
1032  void  void
1033  ui_line(uint8 opcode,  ui_line(uint8 opcode,
1034          /* dest */ int startx, int starty, int endx, int endy,          /* dest */ int startx, int starty, int endx, int endy,
1035          /* pen */ PEN *pen)          /* pen */ PEN * pen)
1036  {  {
1037          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
1038          SET_FOREGROUND(pen->colour);          SET_FOREGROUND(pen->colour);
# Line 1112  ui_rect( Line 1054  ui_rect(
1054  void  void
1055  ui_draw_glyph(int mixmode,  ui_draw_glyph(int mixmode,
1056                /* dest */ int x, int y, int cx, int cy,                /* dest */ int x, int y, int cx, int cy,
1057                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,                /* src */ HGLYPH glyph, int srcx, int srcy,
1058                int fgcolour)                int bgcolour, int fgcolour)
1059  {  {
1060          SET_FOREGROUND(fgcolour);          SET_FOREGROUND(fgcolour);
1061          SET_BACKGROUND(bgcolour);          SET_BACKGROUND(bgcolour);
1062    
1063          XSetFillStyle(display, gc, (mixmode == MIX_TRANSPARENT)          XSetFillStyle(display, gc,
1064                        ? FillStippled : FillOpaqueStippled);                        (mixmode == MIX_TRANSPARENT) ? FillStippled : FillOpaqueStippled);
1065          XSetStipple(display, gc, (Pixmap)glyph);          XSetStipple(display, gc, (Pixmap) glyph);
1066          XSetTSOrigin(display, gc, x, y);          XSetTSOrigin(display, gc, x, y);
1067    
1068          FILL_RECTANGLE(x, y, cx, cy);          FILL_RECTANGLE(x, y, cx, cy);
# Line 1137  ui_draw_glyph(int mixmode, Line 1079  ui_draw_glyph(int mixmode,
1079        if ((xyoffset & 0x80))\        if ((xyoffset & 0x80))\
1080          {\          {\
1081            if (flags & TEXT2_VERTICAL) \            if (flags & TEXT2_VERTICAL) \
1082              y += ttext[++idx] | (ttext[++idx] << 8);\              y += ttext[idx+1] | (ttext[idx+2] << 8);\
1083            else\            else\
1084              x += ttext[++idx] | (ttext[++idx] << 8);\              x += ttext[idx+1] | (ttext[idx+2] << 8);\
1085              idx += 2;\
1086          }\          }\
1087        else\        else\
1088          {\          {\
# Line 1162  ui_draw_glyph(int mixmode, Line 1105  ui_draw_glyph(int mixmode,
1105    
1106  void  void
1107  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,
1108               int clipx, int clipy, int clipcx, int clipcy, int boxx,               int clipx, int clipy, int clipcx, int clipcy,
1109               int boxy, int boxcx, int boxcy, int bgcolour,               int boxx, int boxy, int boxcx, int boxcy, int bgcolour,
1110               int fgcolour, uint8 * text, uint8 length)               int fgcolour, uint8 * text, uint8 length)
1111  {  {
1112          FONTGLYPH *glyph;          FONTGLYPH *glyph;
# Line 1182  ui_draw_text(uint8 font, uint8 flags, in Line 1125  ui_draw_text(uint8 font, uint8 flags, in
1125          }          }
1126    
1127          /* Paint text, character by character */          /* Paint text, character by character */
1128          for (i = 0; i < length;) {          for (i = 0; i < length;)
1129                  switch (text[i]) {          {
1130                  case 0xff:                  switch (text[i])
1131                          if (i + 2 < length)                  {
1132                                  cache_put_text(text[i + 1], text, text[i + 2]);                          case 0xff:
1133                          else {                                  if (i + 2 < length)
1134                                  error("this shouldn't be happening\n");                                          cache_put_text(text[i + 1], text, text[i + 2]);
1135                                    else
1136                                    {
1137                                            error("this shouldn't be happening\n");
1138                                            break;
1139                                    }
1140                                    /* this will move pointer from start to first character after FF command */
1141                                    length -= i + 3;
1142                                    text = &(text[i + 3]);
1143                                    i = 0;
1144                                  break;                                  break;
                         }  
                         /* this will move pointer from start to first character after FF command */  
                         length -= i + 3;  
                         text = &(text[i + 3]);  
                         i = 0;  
                         break;  
1145    
1146                  case 0xfe:                          case 0xfe:
1147                          entry = cache_get_text(text[i + 1]);                                  entry = cache_get_text(text[i + 1]);
1148                          if (entry != NULL) {                                  if (entry != NULL)
1149                                  if ((((uint8 *) (entry->data))[1] == 0)                                  {
1150                                      && (!(flags & TEXT2_IMPLICIT_X))) {                                          if ((((uint8 *) (entry->data))[1] ==
1151                                          if (flags & TEXT2_VERTICAL)                                               0) && (!(flags & TEXT2_IMPLICIT_X)))
1152                                                  y += text[i + 2];                                          {
1153                                                    if (flags & TEXT2_VERTICAL)
1154                                                            y += text[i + 2];
1155                                                    else
1156                                                            x += text[i + 2];
1157                                            }
1158                                            if (i + 2 < length)
1159                                                    i += 3;
1160                                          else                                          else
1161                                                  x += text[i + 2];                                                  i += 2;
1162                                            length -= i;
1163                                            /* this will move pointer from start to first character after FE command */
1164                                            text = &(text[i]);
1165                                            i = 0;
1166                                            for (j = 0; j < entry->size; j++)
1167                                                    DO_GLYPH(((uint8 *) (entry->data)), j);
1168                                  }                                  }
1169                                  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;  
1170    
1171                  default:                          default:
1172                          DO_GLYPH(text, i);                                  DO_GLYPH(text, i);
1173                          i++;                                  i++;
1174                          break;                                  break;
1175                  }                  }
1176          }          }
1177    
# Line 1238  ui_desktop_save(uint32 offset, int x, in Line 1186  ui_desktop_save(uint32 offset, int x, in
1186    
1187          if (ownbackstore)          if (ownbackstore)
1188          {          {
1189                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes,                  image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1190          }          }
1191          else          else
1192          {          {
1193                  pix = XCreatePixmap(display, wnd, cx, cy, depth);                  pix = XCreatePixmap(display, wnd, cx, cy, depth);
1194                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);                  XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);
1195                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes,                  image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);
                                   ZPixmap);  
1196                  XFreePixmap(display, pix);                  XFreePixmap(display, pix);
1197          }          }
1198    
1199          offset *= bpp/8;          offset *= bpp / 8;
1200          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);  
1201    
1202          XDestroyImage(image);          XDestroyImage(image);
1203  }  }
# Line 1263  ui_desktop_restore(uint32 offset, int x, Line 1208  ui_desktop_restore(uint32 offset, int x,
1208          XImage *image;          XImage *image;
1209          uint8 *data;          uint8 *data;
1210    
1211          offset *= bpp/8;          offset *= bpp / 8;
1212          data = cache_get_desktop(offset, cx, cy, bpp/8);          data = cache_get_desktop(offset, cx, cy, bpp / 8);
1213          if (data == NULL)          if (data == NULL)
1214                  return;                  return;
1215    
1216          image = XCreateImage(display, visual, depth, ZPixmap,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1217                               0, data, cx, cy, BitmapPad(display),                               (char *) data, cx, cy, BitmapPad(display), cx * bpp / 8);
                              cx * bpp/8);  
1218    
1219          if (ownbackstore)          if (ownbackstore)
1220          {          {

Legend:
Removed from v.54  
changed lines
  Added in v.121

  ViewVC Help
Powered by ViewVC 1.1.26