/[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 309 by jsorg71, Tue Feb 4 05:32:13 2003 UTC revision 415 by forsberg, Fri Jun 6 11:10:48 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X Window System     User interface services - X Window System
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2002
# Line 23  Line 23 
23  #include <time.h>  #include <time.h>
24  #include <errno.h>  #include <errno.h>
25  #include "rdesktop.h"  #include "rdesktop.h"
26    #include "xproto.h"
27    
28  extern int width;  extern int width;
29  extern int height;  extern int height;
# Line 32  extern BOOL grab_keyboard; Line 33  extern BOOL grab_keyboard;
33  extern BOOL hide_decorations;  extern BOOL hide_decorations;
34  extern char title[];  extern char title[];
35  extern int server_bpp;  extern int server_bpp;
36    extern int win_button_size;
37  BOOL enable_compose = False;  BOOL enable_compose = False;
38  BOOL focused;  BOOL focused;
39  BOOL mouse_in_wnd;  BOOL mouse_in_wnd;
40    
41  Display *display;  Display *display;
42    Time last_gesturetime;
43  static int x_socket;  static int x_socket;
44  static Screen *screen;  static Screen *screen;
45  static Window wnd;  Window wnd;
46  static GC gc;  static GC gc;
47  static Visual *visual;  static Visual *visual;
48  static int depth;  static int depth;
# Line 49  static XIC IC; Line 52  static XIC IC;
52  static XModifierKeymap *mod_map;  static XModifierKeymap *mod_map;
53  static Cursor current_cursor;  static Cursor current_cursor;
54  static Atom protocol_atom, kill_atom;  static Atom protocol_atom, kill_atom;
55    static long input_mask;         /* Needs to be global since we access it in
56                                       both ui_create_window and the PropertyNotify
57                                       callback functions */
58    
59  /* endianness */  /* endianness */
60  static BOOL host_be;  static BOOL host_be;
# Line 58  static BOOL xserver_be; Line 64  static BOOL xserver_be;
64  static BOOL ownbackstore;  static BOOL ownbackstore;
65  static Pixmap backstore;  static Pixmap backstore;
66    
67    /* Moving in single app mode */
68    static BOOL moving_wnd;
69    static int move_x_offset = 0;
70    static int move_y_offset = 0;
71    
72  /* MWM decorations */  /* MWM decorations */
73  #define MWM_HINTS_DECORATIONS   (1L << 1)  #define MWM_HINTS_DECORATIONS   (1L << 1)
74  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
# Line 71  typedef struct Line 82  typedef struct
82  }  }
83  PropMotifWmHints;  PropMotifWmHints;
84    
85    typedef struct
86    {
87            uint32 red;
88            uint32 green;
89            uint32 blue;
90    }
91    PixelColour;
92    
93    struct _PropNotifyCb;
94    
95    typedef struct _PropNotifyCb
96    {
97            Window wnd;
98            Atom atom;
99            void (*callback) (XPropertyEvent *);
100            struct _PropNotifyCb *next;
101    }
102    PropNotifyCb;
103    
104    
105    static PropNotifyCb *propnotify_callbacks = NULL;
106    
107    
108  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
109  { \  { \
# Line 89  BOOL owncolmap = False; Line 122  BOOL owncolmap = False;
122  static Colormap xcolmap;  static Colormap xcolmap;
123  static uint32 *colmap;  static uint32 *colmap;
124    
125  #define TRANSLATE(col)          ( server_bpp != 8 ? col : owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) )
126  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
127  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
128    
# Line 115  static int rop2_map[] = { Line 148  static int rop2_map[] = {
148  #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]); }
149  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
150    
151  void  static void
152  mwm_hide_decorations(void)  mwm_hide_decorations(void)
153  {  {
154          PropMotifWmHints motif_hints;          PropMotifWmHints motif_hints;
# Line 137  mwm_hide_decorations(void) Line 170  mwm_hide_decorations(void)
170                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
171  }  }
172    
173    static PixelColour
174    split_colour15(uint32 colour)
175    {
176            PixelColour rv;
177            rv.red = (colour & 0x7c00) >> 10;
178            rv.red = (rv.red * 0xff) / 0x1f;
179            rv.green = (colour & 0x03e0) >> 5;
180            rv.green = (rv.green * 0xff) / 0x1f;
181            rv.blue = (colour & 0x1f);
182            rv.blue = (rv.blue * 0xff) / 0x1f;
183            return rv;
184    }
185    
186    static PixelColour
187    split_colour16(uint32 colour)
188    {
189            PixelColour rv;
190            rv.red = (colour & 0xf800) >> 11;
191            rv.red = (rv.red * 0xff) / 0x1f;
192            rv.green = (colour & 0x07e0) >> 5;
193            rv.green = (rv.green * 0xff) / 0x3f;
194            rv.blue = (colour & 0x001f);
195            rv.blue = (rv.blue * 0xff) / 0x1f;
196            return rv;
197    }
198    
199    static PixelColour
200    split_colour24(uint32 colour)
201    {
202            PixelColour rv;
203            rv.blue = (colour & 0xff0000) >> 16;
204            rv.green = (colour & 0xff00) >> 8;
205            rv.red = (colour & 0xff);
206            return rv;
207    }
208    
209    static uint32
210    make_colour16(PixelColour pc)
211    {
212            pc.red = (pc.red * 0x1f) / 0xff;
213            pc.green = (pc.green * 0x3f) / 0xff;
214            pc.blue = (pc.blue * 0x1f) / 0xff;
215            return (pc.red << 11) | (pc.green << 5) | pc.blue;
216    }
217    
218    static uint32
219    make_colour24(PixelColour pc)
220    {
221            return (pc.red << 16) | (pc.green << 8) | pc.blue;
222    }
223    
224    static uint32
225    make_colour32(PixelColour pc)
226    {
227            return (pc.red << 16) | (pc.green << 8) | pc.blue;
228    }
229    
230    #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
231    #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }
232    #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
233                            x = (x << 16) | (x >> 16); }
234    
235    static uint32
236    translate_colour(uint32 colour)
237    {
238            switch (server_bpp)
239            {
240                    case 15:
241                            switch (bpp)
242                            {
243                                    case 16:
244                                            colour = make_colour16(split_colour15(colour));
245                                            break;
246                                    case 24:
247                                            colour = make_colour24(split_colour15(colour));
248                                            break;
249                                    case 32:
250                                            colour = make_colour32(split_colour15(colour));
251                                            break;
252                            }
253                            break;
254                    case 16:
255                            switch (bpp)
256                            {
257                                    case 16:
258                                            break;
259                                    case 24:
260                                            colour = make_colour24(split_colour16(colour));
261                                            break;
262                                    case 32:
263                                            colour = make_colour32(split_colour16(colour));
264                                            break;
265                            }
266                            break;
267                    case 24:
268                            switch (bpp)
269                            {
270                                    case 16:
271                                            colour = make_colour16(split_colour24(colour));
272                                            break;
273                                    case 24:
274                                            break;
275                                    case 32:
276                                            colour = make_colour32(split_colour24(colour));
277                                            break;
278                            }
279                            break;
280            }
281            switch (bpp)
282            {
283                    case 16:
284                            if (host_be != xserver_be)
285                                    BSWAP16(colour);
286                            break;
287    
288                    case 24:
289                            if (xserver_be)
290                                    BSWAP24(colour);
291                            break;
292    
293                    case 32:
294                            if (host_be != xserver_be)
295                                    BSWAP32(colour);
296                            break;
297            }
298    
299            return colour;
300    }
301    
302  static void  static void
303  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
304  {  {
305          while (out < end)          while (out < end)
306                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
307  }  }
308    
309  static void  static void
310  translate16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
311  {  {
312          while (out < end)          while (out < end)
313                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
# Line 153  translate16(uint8 * data, uint16 * out, Line 315  translate16(uint8 * data, uint16 * out,
315    
316  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
317  static void  static void
318  translate24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
319  {  {
320          uint32 value;          uint32 value;
321    
# Line 167  translate24(uint8 * data, uint8 * out, u Line 329  translate24(uint8 * data, uint8 * out, u
329  }  }
330    
331  static void  static void
332  translate32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
333  {  {
334          while (out < end)          while (out < end)
335                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
336  }  }
337    
338  static uint8 *  /* todo the remaining translate function might need some big endian check ?? */
339  translate_image(int width, int height, uint8 * data)  
340    static void
341    translate15to16(uint16 * data, uint16 * out, uint16 * end)
342  {  {
343          int size = width * height * bpp / 8;          while (out < end)
344          uint8 *out = xmalloc(size);                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));
345          uint8 *end = out + size;  }
346    
347          switch (bpp)  static void
348    translate15to24(uint16 * data, uint8 * out, uint8 * end)
349    {
350            uint32 value;
351    
352            while (out < end)
353          {          {
354                  case 8:                  value = make_colour24(split_colour15(*(data++)));
355                          translate8(data, out, end);                  *(out++) = value;
356                          break;                  *(out++) = value >> 8;
357                    *(out++) = value >> 16;
358            }
359    }
360    
361                  case 16:  static void
362                          translate16(data, (uint16 *) out, (uint16 *) end);  translate15to32(uint16 * data, uint32 * out, uint32 * end)
363                          break;  {
364            while (out < end)
365                    *(out++) = make_colour32(split_colour15(*(data++)));
366    }
367    
368                  case 24:  static void
369                          translate24(data, out, end);  translate16to16(uint16 * data, uint16 * out, uint16 * end)
370                          break;  {
371            while (out < end)
372                    *(out++) = (uint16) (*(data++));
373    }
374    
375                  case 32:  
376                          translate32(data, (uint32 *) out, (uint32 *) end);  static void
377                          break;  translate16to24(uint16 * data, uint8 * out, uint8 * end)
378    {
379            uint32 value;
380    
381            while (out < end)
382            {
383                    value = make_colour24(split_colour16(*(data++)));
384                    *(out++) = value;
385                    *(out++) = value >> 8;
386                    *(out++) = value >> 16;
387          }          }
388    }
389    
390          return out;  static void
391    translate16to32(uint16 * data, uint32 * out, uint32 * end)
392    {
393            while (out < end)
394                    *(out++) = make_colour32(split_colour16(*(data++)));
395  }  }
396    
397  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  static void
398  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  translate24to16(uint8 * data, uint16 * out, uint16 * end)
399  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  {
400                          x = (x << 16) | (x >> 16); }          uint32 pixel = 0;
401            while (out < end)
402            {
403                    pixel = *(data++) << 16;
404                    pixel |= *(data++) << 8;
405                    pixel |= *(data++);
406                    *(out++) = (uint16) make_colour16(split_colour24(pixel));
407            }
408    }
409    
410  static uint32  static void
411  translate_colour(uint32 colour)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
412  {  {
413          switch (bpp)          while (out < end)
414          {          {
415                  case 16:                  *(out++) = (*(data++));
416                          if (host_be != xserver_be)          }
417                                  BSWAP16(colour);  }
                         break;  
418    
419    static void
420    translate24to32(uint8 * data, uint32 * out, uint32 * end)
421    {
422            uint32 pixel = 0;
423            while (out < end)
424            {
425                    pixel = *(data++);
426                    pixel |= *(data++) << 8;
427                    pixel |= *(data++) << 16;
428                    *(out++) = pixel;
429            }
430    }
431    
432    static uint8 *
433    translate_image(int width, int height, uint8 * data)
434    {
435            int size = width * height * bpp / 8;
436            uint8 *out = (uint8 *) xmalloc(size);
437            uint8 *end = out + size;
438    
439            switch (server_bpp)
440            {
441                  case 24:                  case 24:
442                          if (xserver_be)                          switch (bpp)
443                                  BSWAP24(colour);                          {
444                                    case 32:
445                                            translate24to32(data, (uint32 *) out, (uint32 *) end);
446                                            break;
447                                    case 24:
448                                            translate24to24(data, out, end);
449                                            break;
450                                    case 16:
451                                            translate24to16(data, (uint16 *) out, (uint16 *) end);
452                                            break;
453                            }
454                          break;                          break;
455                    case 16:
456                  case 32:                          switch (bpp)
457                          if (host_be != xserver_be)                          {
458                                  BSWAP32(colour);                                  case 32:
459                                            translate16to32((uint16 *) data, (uint32 *) out,
460                                                            (uint32 *) end);
461                                            break;
462                                    case 24:
463                                            translate16to24((uint16 *) data, out, end);
464                                            break;
465                                    case 16:
466                                            translate16to16((uint16 *) data, (uint16 *) out,
467                                                            (uint16 *) end);
468                                            break;
469                            }
470                            break;
471                    case 15:
472                            switch (bpp)
473                            {
474                                    case 32:
475                                            translate15to32((uint16 *) data, (uint32 *) out,
476                                                            (uint32 *) end);
477                                            break;
478                                    case 24:
479                                            translate15to24((uint16 *) data, out, end);
480                                            break;
481                                    case 16:
482                                            translate15to16((uint16 *) data, (uint16 *) out,
483                                                            (uint16 *) end);
484                                            break;
485                            }
486                            break;
487                    case 8:
488                            switch (bpp)
489                            {
490                                    case 8:
491                                            translate8to8(data, out, end);
492                                            break;
493                                    case 16:
494                                            translate8to16(data, (uint16 *) out, (uint16 *) end);
495                                            break;
496                                    case 24:
497                                            translate8to24(data, out, end);
498                                            break;
499                                    case 32:
500                                            translate8to32(data, (uint32 *) out, (uint32 *) end);
501                                            break;
502                            }
503                          break;                          break;
504          }          }
505            return out;
         return colour;  
506  }  }
507    
508  BOOL  BOOL
# Line 356  ui_init(void) Line 630  ui_init(void)
630                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
631    
632          xkeymap_init();          xkeymap_init();
633    
634            /* todo take this out when high colour is done */
635            printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
636    
637    
638    
639          return True;          return True;
640  }  }
641    
# Line 382  ui_create_window(void) Line 662  ui_create_window(void)
662          XClassHint *classhints;          XClassHint *classhints;
663          XSizeHints *sizehints;          XSizeHints *sizehints;
664          int wndwidth, wndheight;          int wndwidth, wndheight;
665          long input_mask, ic_input_mask;          long ic_input_mask;
666          XEvent xevent;          XEvent xevent;
667    
668          wndwidth = fullscreen ? WidthOfScreen(screen) : width;          wndwidth = fullscreen ? WidthOfScreen(screen) : width;
# Line 496  xwin_toggle_fullscreen(void) Line 776  xwin_toggle_fullscreen(void)
776          }          }
777  }  }
778    
779    static void
780    xwin_process_propertynotify(XPropertyEvent * xev)
781    {
782            PropNotifyCb *this = propnotify_callbacks;
783            while (NULL != this)
784            {
785                    if (xev->window == this->wnd && xev->atom == this->atom)
786                    {
787                            this->callback(xev);
788                    }
789                    this = this->next;
790            }
791    }
792    
793    
794  /* Process all events in Xlib queue  /* Process all events in Xlib queue
795     Returns 0 after user quit, 1 otherwise */     Returns 0 after user quit, 1 otherwise */
796  static int  static int
# Line 529  xwin_process_events(void) Line 824  xwin_process_events(void)
824                          case ClientMessage:                          case ClientMessage:
825                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
826                                  if ((xevent.xclient.message_type == protocol_atom)                                  if ((xevent.xclient.message_type == protocol_atom)
827                                      && (xevent.xclient.data.l[0] == kill_atom))                                      && ((Atom) xevent.xclient.data.l[0] == kill_atom))
828                                          /* Quit */                                          /* Quit */
829                                          return 0;                                          return 0;
830                                  break;                                  break;
831    
832                          case KeyPress:                          case KeyPress:
833                                    last_gesturetime = ((XKeyEvent *) & xevent)->time;
834                                  if (IC != NULL)                                  if (IC != NULL)
835                                          /* Multi_key compatible version */                                          /* Multi_key compatible version */
836                                  {                                  {
# Line 575  xwin_process_events(void) Line 871  xwin_process_events(void)
871                                  break;                                  break;
872    
873                          case KeyRelease:                          case KeyRelease:
874                                    last_gesturetime = ((XKeyEvent *) & xevent)->time;
875                                  XLookupString((XKeyEvent *) & xevent, str,                                  XLookupString((XKeyEvent *) & xevent, str,
876                                                sizeof(str), &keysym, NULL);                                                sizeof(str), &keysym, NULL);
877    
# Line 595  xwin_process_events(void) Line 892  xwin_process_events(void)
892                                  break;                                  break;
893    
894                          case ButtonPress:                          case ButtonPress:
895                                    last_gesturetime = ((XButtonEvent *) & xevent)->time;
896                                  flags = MOUSE_FLAG_DOWN;                                  flags = MOUSE_FLAG_DOWN;
897                                  /* fall through */                                  /* fall through */
898    
899                          case ButtonRelease:                          case ButtonRelease:
900                                    last_gesturetime = ((XButtonEvent *) & xevent)->time;
901                                  button = xkeymap_translate_button(xevent.xbutton.button);                                  button = xkeymap_translate_button(xevent.xbutton.button);
902                                  if (button == 0)                                  if (button == 0)
903                                          break;                                          break;
904    
905                                    /* If win_button_size is nonzero, enable single app mode */
906                                    if (xevent.xbutton.y < win_button_size)
907                                    {
908                                            /* Stop moving window when button is released, regardless of cursor position */
909                                            if (moving_wnd && (xevent.type == ButtonRelease))
910                                                    moving_wnd = False;
911    
912                                            /*  Check from right to left: */
913    
914                                            if (xevent.xbutton.x >= width - win_button_size)
915                                            {
916                                                    /* The close button, continue */
917                                                    ;
918                                            }
919                                            else if (xevent.xbutton.x >= width - win_button_size * 2)
920                                            {
921                                                    /* The maximize/restore button. Do not send to
922                                                       server.  It might be a good idea to change the
923                                                       cursor or give some other visible indication
924                                                       that rdesktop inhibited this click */
925                                                    break;
926                                            }
927                                            else if (xevent.xbutton.x >= width - win_button_size * 3)
928                                            {
929                                                    /* The minimize button. Iconify window. */
930                                                    XIconifyWindow(display, wnd,
931                                                                   DefaultScreen(display));
932                                                    break;
933                                            }
934                                            else if (xevent.xbutton.x <= win_button_size)
935                                            {
936                                                    /* The system menu. Ignore. */
937                                                    break;
938                                            }
939                                            else
940                                            {
941                                                    /* The title bar. */
942                                                    if ((xevent.type == ButtonPress) && !fullscreen
943                                                        && hide_decorations)
944                                                    {
945                                                            moving_wnd = True;
946                                                            move_x_offset = xevent.xbutton.x;
947                                                            move_y_offset = xevent.xbutton.y;
948                                                    }
949                                                    break;
950    
951                                            }
952                                    }
953    
954                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
955                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
956                                  break;                                  break;
957    
958                          case MotionNotify:                          case MotionNotify:
959                                    if (moving_wnd)
960                                    {
961                                            XMoveWindow(display, wnd,
962                                                        xevent.xmotion.x_root - move_x_offset,
963                                                        xevent.xmotion.y_root - move_y_offset);
964                                            break;
965                                    }
966    
967                                  if (fullscreen && !focused)                                  if (fullscreen && !focused)
968                                          XSetInputFocus(display, wnd, RevertToPointerRoot,                                          XSetInputFocus(display, wnd, RevertToPointerRoot,
969                                                         CurrentTime);                                                         CurrentTime);
# Line 677  xwin_process_events(void) Line 1033  xwin_process_events(void)
1033                                          mod_map = XGetModifierMapping(display);                                          mod_map = XGetModifierMapping(display);
1034                                  }                                  }
1035                                  break;                                  break;
1036                                    /* Clipboard stuff */
1037                            case SelectionClear:
1038                                    cliprdr_handle_SelectionClear();
1039                                    break;
1040                            case SelectionNotify:
1041                                    cliprdr_handle_SelectionNotify((XSelectionEvent *) & xevent);
1042                                    break;
1043                            case SelectionRequest:
1044                                    cliprdr_handle_SelectionRequest((XSelectionRequestEvent *) &
1045                                                                    xevent);
1046                                    break;
1047    
1048                            case PropertyNotify:
1049                                    xwin_process_propertynotify((XPropertyEvent *) & xevent);
1050                                    break;
1051    
1052    
1053                  }                  }
1054          }          }
# Line 734  ui_create_bitmap(int width, int height, Line 1106  ui_create_bitmap(int width, int height,
1106          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
1107          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
1108          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1109                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
1110    
1111          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
1112    
# Line 749  ui_paint_bitmap(int x, int y, int cx, in Line 1121  ui_paint_bitmap(int x, int y, int cx, in
1121  {  {
1122          XImage *image;          XImage *image;
1123          uint8 *tdata;          uint8 *tdata;
   
         if (server_bpp == 16)  
         {  
                 image = XCreateImage(display, visual, depth, ZPixmap, 0,  
                                      (char *) data, width, height, 16, 0);  
   
                 if (ownbackstore)  
                 {  
                         XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);  
                         XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);  
                 }  
                 else  
                 {  
                         XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);  
                 }  
   
                 XFree(image);  
                 return;  
         }  
1124          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
1125          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1126                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
1127    
1128          if (ownbackstore)          if (ownbackstore)
1129          {          {
# Line 841  ui_create_cursor(unsigned int x, unsigne Line 1194  ui_create_cursor(unsigned int x, unsigne
1194          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1195          offset = scanline * height;          offset = scanline * height;
1196    
1197          cursor = xmalloc(offset);          cursor = (uint8 *) xmalloc(offset);
1198          memset(cursor, 0, offset);          memset(cursor, 0, offset);
1199    
1200          mask = xmalloc(offset);          mask = (uint8 *) xmalloc(offset);
1201          memset(mask, 0, offset);          memset(mask, 0, offset);
1202    
1203          /* approximate AND and XOR masks with a monochrome X pointer */          /* approximate AND and XOR masks with a monochrome X pointer */
# Line 923  ui_create_colourmap(COLOURMAP * colours) Line 1276  ui_create_colourmap(COLOURMAP * colours)
1276          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
1277          if (!owncolmap)          if (!owncolmap)
1278          {          {
1279                  uint32 *map = xmalloc(sizeof(*colmap) * ncolours);                  uint32 *map = (uint32 *) xmalloc(sizeof(*colmap) * ncolours);
1280                  XColor xentry;                  XColor xentry;
1281                  XColor xc_cache[256];                  XColor xc_cache[256];
1282                  uint32 colour;                  uint32 colour;
# Line 1001  ui_create_colourmap(COLOURMAP * colours) Line 1354  ui_create_colourmap(COLOURMAP * colours)
1354                  XColor *xcolours, *xentry;                  XColor *xcolours, *xentry;
1355                  Colormap map;                  Colormap map;
1356    
1357                  xcolours = xmalloc(sizeof(XColor) * ncolours);                  xcolours = (XColor *) xmalloc(sizeof(XColor) * ncolours);
1358                  for (i = 0; i < ncolours; i++)                  for (i = 0; i < ncolours; i++)
1359                  {                  {
1360                          entry = &colours->colours[i];                          entry = &colours->colours[i];
# Line 1031  void Line 1384  void
1384  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
1385  {  {
1386          if (!owncolmap)          if (!owncolmap)
1387                  colmap = map;                  colmap = (uint32 *) map;
1388          else          else
1389                  XSetWindowColormap(display, wnd, (Colormap) map);                  XSetWindowColormap(display, wnd, (Colormap) map);
1390  }  }
# Line 1075  ui_destblt(uint8 opcode, Line 1428  ui_destblt(uint8 opcode,
1428          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
1429  }  }
1430    
1431    static uint8 hatch_patterns[] = {
1432            0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0 - bsHorizontal */
1433            0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 1 - bsVertical */
1434            0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, /* 2 - bsFDiagonal */
1435            0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, /* 3 - bsBDiagonal */
1436            0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, /* 4 - bsCross */
1437            0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81  /* 5 - bsDiagCross */
1438    };
1439    
1440  void  void
1441  ui_patblt(uint8 opcode,  ui_patblt(uint8 opcode,
1442            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
# Line 1092  ui_patblt(uint8 opcode, Line 1454  ui_patblt(uint8 opcode,
1454                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
1455                          break;                          break;
1456    
1457                    case 2: /* Hatch */
1458                            fill = (Pixmap) ui_create_glyph(8, 8,
1459                                                            hatch_patterns + brush->pattern[0] * 8);
1460                            SET_FOREGROUND(bgcolour);
1461                            SET_BACKGROUND(fgcolour);
1462                            XSetFillStyle(display, gc, FillOpaqueStippled);
1463                            XSetStipple(display, gc, fill);
1464                            XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);
1465                            FILL_RECTANGLE(x, y, cx, cy);
1466                            XSetFillStyle(display, gc, FillSolid);
1467                            XSetTSOrigin(display, gc, 0, 0);
1468                            ui_destroy_glyph((HGLYPH) fill);
1469                            break;
1470    
1471                  case 3: /* Pattern */                  case 3: /* Pattern */
1472                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
1473                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
# Line 1381  ui_desktop_restore(uint32 offset, int x, Line 1757  ui_desktop_restore(uint32 offset, int x,
1757    
1758          XFree(image);          XFree(image);
1759  }  }
1760    
1761    
1762    void
1763    xwin_register_propertynotify(Window event_wnd, Atom atom,
1764                                 void (*propertycallback) (XPropertyEvent *))
1765    {
1766            PropNotifyCb *this;
1767            int window_already_registrered = 0;
1768            if (NULL != propnotify_callbacks)
1769            {
1770                    this = propnotify_callbacks;
1771                    if (event_wnd == this->wnd)
1772                    {
1773                            window_already_registrered = 1;
1774                            if (atom == this->atom)
1775                                    return;
1776                    }
1777                    while (NULL != this->next)
1778                    {
1779                            if (event_wnd == this->wnd)
1780                            {
1781                                    window_already_registrered = 1;
1782                                    if (atom == this->atom)
1783                                            return;
1784                                    /* Find last entry in list */
1785                            }
1786                            this = this->next;
1787                    }
1788                    this->next = xmalloc(sizeof(PropNotifyCb));
1789                    this->next->next = NULL;
1790                    this = this->next;
1791    
1792            }
1793            else
1794            {
1795                    this = xmalloc(sizeof(PropNotifyCb));
1796                    this->next = NULL;
1797                    propnotify_callbacks = this;
1798            }
1799            if (!window_already_registrered)
1800            {
1801                    if (wnd == event_wnd)
1802                            XSelectInput(display, wnd, input_mask | PropertyChangeMask);
1803                    else
1804                            XSelectInput(display, event_wnd, PropertyChangeMask);
1805            }
1806            this->wnd = event_wnd;
1807            this->atom = atom;
1808            this->callback = propertycallback;
1809    }
1810    
1811    
1812    void
1813    xwin_deregister_propertynotify(Window event_wnd, Atom atom)
1814    {
1815            PropNotifyCb *this = propnotify_callbacks;
1816            PropNotifyCb *prev;
1817            int window_needed = 0;
1818            prev = this;
1819            while (NULL != this)
1820            {
1821                    if (event_wnd == this->wnd)
1822                    {
1823                            if (atom == this->atom)
1824                            {
1825                                    if (prev == this)
1826                                    {
1827                                            propnotify_callbacks = this->next;
1828                                    }
1829                                    else
1830                                    {
1831                                            prev->next = this->next;
1832                                    }
1833                                    xfree(this);
1834                                    continue;
1835                            }
1836                            else
1837                            {
1838                                    window_needed = 1;
1839                            }
1840                    }
1841                    prev = this;
1842                    this = this->next;
1843            }
1844            if (!window_needed)
1845            {
1846                    if (wnd != event_wnd)
1847                    {
1848                            XSelectInput(display, event_wnd, NoEventMask);
1849                    }
1850                    else
1851                    {
1852                            XSelectInput(display, wnd, input_mask);
1853                    }
1854            }
1855    }

Legend:
Removed from v.309  
changed lines
  Added in v.415

  ViewVC Help
Powered by ViewVC 1.1.26