/[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 297 by matthewc, Tue Jan 28 12:27:28 2003 UTC revision 318 by astrand, Mon Feb 10 12:58:51 2003 UTC
# Line 31  extern BOOL fullscreen; Line 31  extern BOOL fullscreen;
31  extern BOOL grab_keyboard;  extern BOOL grab_keyboard;
32  extern BOOL hide_decorations;  extern BOOL hide_decorations;
33  extern char title[];  extern char title[];
34    extern int server_bpp;
35  BOOL enable_compose = False;  BOOL enable_compose = False;
36  BOOL focused;  BOOL focused;
37  BOOL mouse_in_wnd;  BOOL mouse_in_wnd;
# Line 62  static Pixmap backstore; Line 63  static Pixmap backstore;
63  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5  #define PROP_MOTIF_WM_HINTS_ELEMENTS    5
64  typedef struct  typedef struct
65  {  {
66          unsigned long flags;          uint32 flags;
67          unsigned long functions;          uint32 functions;
68          unsigned long decorations;          uint32 decorations;
69          long inputMode;          sint32 inputMode;
70          unsigned long status;          uint32 status;
71  }  }
72  PropMotifWmHints;  PropMotifWmHints;
73    
74    typedef struct
75    {
76            uint32 red;
77            uint32 green;
78            uint32 blue;
79    }
80    PixelColour;
81    
82  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
83  { \  { \
# Line 88  BOOL owncolmap = False; Line 96  BOOL owncolmap = False;
96  static Colormap xcolmap;  static Colormap xcolmap;
97  static uint32 *colmap;  static uint32 *colmap;
98    
99  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define TRANSLATE(col)          ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) )
100  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
101  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
102    
# Line 136  mwm_hide_decorations(void) Line 144  mwm_hide_decorations(void)
144                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
145  }  }
146    
147    PixelColour
148    split_colour15(uint32 colour)
149    {
150            PixelColour rv;
151            rv.red = (colour & 0x7c00) >> 10;
152            rv.red = (rv.red * 0xff) / 0x1f;
153            rv.green = (colour & 0x03e0) >> 5;
154            rv.green = (rv.green * 0xff) / 0x1f;
155            rv.blue = (colour & 0x1f);
156            rv.blue = (rv.blue * 0xff) / 0x1f;
157            return rv;
158    }
159    
160    PixelColour
161    split_colour16(uint32 colour)
162    {
163            PixelColour rv;
164            rv.red = (colour & 0xf800) >> 11;
165            rv.red = (rv.red * 0xff) / 0x1f;
166            rv.green = (colour & 0x07e0) >> 5;
167            rv.green = (rv.green * 0xff) / 0x3f;
168            rv.blue = (colour & 0x001f);
169            rv.blue = (rv.blue * 0xff) / 0x1f;
170            return rv;
171    }
172    
173    PixelColour
174    split_colour24(uint32 colour)
175    {
176            PixelColour rv;
177            rv.blue = (colour & 0xff0000) >> 16;
178            rv.green = (colour & 0xff00) >> 8;
179            rv.red = (colour & 0xff);
180            return rv;
181    }
182    
183    uint32
184    make_colour16(PixelColour pc)
185    {
186            pc.red = (pc.red * 0x1f) / 0xff;
187            pc.green = (pc.green * 0x3f) / 0xff;
188            pc.blue = (pc.blue * 0x1f) / 0xff;
189            return (pc.red << 11) | (pc.green << 5) | pc.blue;
190    }
191    
192    uint32
193    make_colour24(PixelColour pc)
194    {
195            return (pc.red << 16) | (pc.green << 8) | pc.blue;
196    }
197    
198    uint32
199    make_colour32(PixelColour pc)
200    {
201            return (pc.red << 16) | (pc.green << 8) | pc.blue;
202    }
203    
204    #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
205    #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }
206    #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
207                            x = (x << 16) | (x >> 16); }
208    
209    static uint32
210    translate_colour(uint32 colour)
211    {
212            switch (server_bpp)
213            {
214                    case 15:
215                            switch (bpp)
216                            {
217                                    case 16:
218                                            colour = make_colour16(split_colour15(colour));
219                                            break;
220                                    case 24:
221                                            colour = make_colour24(split_colour15(colour));
222                                            break;
223                                    case 32:
224                                            colour = make_colour32(split_colour15(colour));
225                                            break;
226                            }
227                            break;
228                    case 16:
229                            switch (bpp)
230                            {
231                                    case 16:
232                                            break;
233                                    case 24:
234                                            colour = make_colour24(split_colour16(colour));
235                                            break;
236                                    case 32:
237                                            colour = make_colour32(split_colour16(colour));
238                                            break;
239                            }
240                            break;
241                    case 24:
242                            switch (bpp)
243                            {
244                                    case 16:
245                                            colour = make_colour16(split_colour24(colour));
246                                            break;
247                                    case 24:
248                                            break;
249                                    case 32:
250                                            colour = make_colour32(split_colour24(colour));
251                                            break;
252                            }
253                            break;
254            }
255            switch (bpp)
256            {
257                    case 16:
258                            if (host_be != xserver_be)
259                                    BSWAP16(colour);
260                            break;
261    
262                    case 24:
263                            if (xserver_be)
264                                    BSWAP24(colour);
265                            break;
266    
267                    case 32:
268                            if (host_be != xserver_be)
269                                    BSWAP32(colour);
270                            break;
271            }
272    
273            return colour;
274    }
275    
276  static void  static void
277  translate8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(uint8 * data, uint8 * out, uint8 * end)
278  {  {
279          while (out < end)          while (out < end)
280                  *(out++) = (uint8) colmap[*(data++)];                  *(out++) = (uint8) colmap[*(data++)];
281  }  }
282    
283  static void  static void
284  translate16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint16 * out, uint16 * end)
285  {  {
286          while (out < end)          while (out < end)
287                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
# Line 152  translate16(uint8 * data, uint16 * out, Line 289  translate16(uint8 * data, uint16 * out,
289    
290  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
291  static void  static void
292  translate24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
293  {  {
294          uint32 value;          uint32 value;
295    
# Line 166  translate24(uint8 * data, uint8 * out, u Line 303  translate24(uint8 * data, uint8 * out, u
303  }  }
304    
305  static void  static void
306  translate32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
307  {  {
308          while (out < end)          while (out < end)
309                  *(out++) = colmap[*(data++)];                  *(out++) = colmap[*(data++)];
310  }  }
311    
312  static uint8 *  /* todo the remaining translate function might need some big endian check ?? */
313  translate_image(int width, int height, uint8 * data)  
314    static void
315    translate15to16(uint16 * data, uint16 * out, uint16 * end)
316  {  {
317          int size = width * height * bpp / 8;          while (out < end)
318          uint8 *out = xmalloc(size);                  *(out++) = (uint16) make_colour16(split_colour15(*(data++)));
319          uint8 *end = out + size;  }
320    
321          switch (bpp)  static void
322    translate15to24(uint16 * data, uint8 * out, uint8 * end)
323    {
324            uint32 value;
325    
326            while (out < end)
327          {          {
328                  case 8:                  value = make_colour24(split_colour15(*(data++)));
329                          translate8(data, out, end);                  *(out++) = value;
330                          break;                  *(out++) = value >> 8;
331                    *(out++) = value >> 16;
332            }
333    }
334    
335                  case 16:  static void
336                          translate16(data, (uint16 *) out, (uint16 *) end);  translate15to32(uint16 * data, uint32 * out, uint32 * end)
337                          break;  {
338            while (out < end)
339                    *(out++) = make_colour32(split_colour15(*(data++)));
340    }
341    
342                  case 24:  static void
343                          translate24(data, out, end);  translate16to16(uint16 * data, uint16 * out, uint16 * end)
344                          break;  {
345            while (out < end)
346                    *(out++) = (uint16) (*(data++));
347    }
348    
349                  case 32:  
350                          translate32(data, (uint32 *) out, (uint32 *) end);  static void
351                          break;  translate16to24(uint16 * data, uint8 * out, uint8 * end)
352    {
353            uint32 value;
354    
355            while (out < end)
356            {
357                    value = make_colour24(split_colour16(*(data++)));
358                    *(out++) = value;
359                    *(out++) = value >> 8;
360                    *(out++) = value >> 16;
361          }          }
362    }
363    
364          return out;  static void
365    translate16to32(uint16 * data, uint32 * out, uint32 * end)
366    {
367            while (out < end)
368                    *(out++) = make_colour32(split_colour16(*(data++)));
369  }  }
370    
371  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  static void
372  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); }  translate24to16(uint8 * data, uint16 * out, uint16 * end)
373  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  {
374                          x = (x << 16) | (x >> 16); }          uint32 pixel = 0;
375            while (out < end)
376            {
377                    pixel = *(data++) << 16;
378                    pixel |= *(data++) << 8;
379                    pixel |= *(data++);
380                    *(out++) = (uint16) make_colour16(split_colour24(pixel));
381            }
382    }
383    
384  static uint32  static void
385  translate_colour(uint32 colour)  translate24to24(uint8 * data, uint8 * out, uint8 * end)
386  {  {
387          switch (bpp)          while (out < end)
388          {          {
389                  case 16:                  *(out++) = (*(data++));
390                          if (host_be != xserver_be)          }
391                                  BSWAP16(colour);  }
                         break;  
392    
393    static void
394    translate24to32(uint8 * data, uint32 * out, uint32 * end)
395    {
396            uint32 pixel = 0;
397            while (out < end)
398            {
399                    memcpy(&pixel, data, 3);
400                    data += 3;
401                    *(out++) = pixel;
402            }
403    }
404    
405    static uint8 *
406    translate_image(int width, int height, uint8 * data)
407    {
408            int size = width * height * bpp / 8;
409            uint8 *out = xmalloc(size);
410            uint8 *end = out + size;
411    
412            switch (server_bpp)
413            {
414                  case 24:                  case 24:
415                          if (xserver_be)                          switch (bpp)
416                                  BSWAP24(colour);                          {
417                                    case 32:
418                                            translate24to32(data, (uint32 *) out, (uint32 *) end);
419                                            break;
420                                    case 24:
421                                            translate24to24(data, out, end);
422                                            break;
423                                    case 16:
424                                            translate24to16(data, (uint16 *) out, (uint16 *) end);
425                                            break;
426                            }
427                          break;                          break;
428                    case 16:
429                  case 32:                          switch (bpp)
430                          if (host_be != xserver_be)                          {
431                                  BSWAP32(colour);                                  case 32:
432                                            translate16to32((uint16 *) data, (uint32 *) out,
433                                                            (uint32 *) end);
434                                            break;
435                                    case 24:
436                                            translate16to24((uint16 *) data, out, end);
437                                            break;
438                                    case 16:
439                                            translate16to16((uint16 *) data, (uint16 *) out,
440                                                            (uint16 *) end);
441                                            break;
442                            }
443                            break;
444                    case 15:
445                            switch (bpp)
446                            {
447                                    case 32:
448                                            translate15to32((uint16 *) data, (uint32 *) out,
449                                                            (uint32 *) end);
450                                            break;
451                                    case 24:
452                                            translate15to24((uint16 *) data, out, end);
453                                            break;
454                                    case 16:
455                                            translate15to16((uint16 *) data, (uint16 *) out,
456                                                            (uint16 *) end);
457                                            break;
458                            }
459                            break;
460                    case 8:
461                            switch (bpp)
462                            {
463                                    case 8:
464                                            translate8to8(data, out, end);
465                                            break;
466                                    case 16:
467                                            translate8to16(data, (uint16 *) out, (uint16 *) end);
468                                            break;
469                                    case 24:
470                                            translate8to24(data, out, end);
471                                            break;
472                                    case 32:
473                                            translate8to32(data, (uint32 *) out, (uint32 *) end);
474                                            break;
475                            }
476                          break;                          break;
477          }          }
478            return out;
         return colour;  
479  }  }
480    
481  BOOL  BOOL
# Line 315  ui_init(void) Line 563  ui_init(void)
563          if ((width == 0) || (height == 0))          if ((width == 0) || (height == 0))
564          {          {
565                  /* Fetch geometry from _NET_WORKAREA */                  /* Fetch geometry from _NET_WORKAREA */
566                  uint32 xpos, ypos;                  uint32 x, y, cx, cy;
567    
568                  if (get_current_workarea(&xpos, &ypos, &width, &height) < 0)                  if (get_current_workarea(&x, &y, &cx, &cy) == 0)
569                    {
570                            width = cx;
571                            height = cy;
572                    }
573                    else
574                  {                  {
575                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");                          warning("Failed to get workarea: probably your window manager does not support extended hints\n");
576                          width = 800;                          width = 800;
# Line 350  ui_init(void) Line 603  ui_init(void)
603                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
604    
605          xkeymap_init();          xkeymap_init();
606    
607            /* todo take this out when high colour is done */
608            printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
609    
610          return True;          return True;
611  }  }
612    
# Line 728  ui_create_bitmap(int width, int height, Line 985  ui_create_bitmap(int width, int height,
985          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
986          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
987          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
988                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
989    
990          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
991    
# Line 743  ui_paint_bitmap(int x, int y, int cx, in Line 1000  ui_paint_bitmap(int x, int y, int cx, in
1000  {  {
1001          XImage *image;          XImage *image;
1002          uint8 *tdata;          uint8 *tdata;
   
1003          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = (owncolmap ? data : translate_image(width, height, data));
1004          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
1005                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0);
1006    
1007          if (ownbackstore)          if (ownbackstore)
1008          {          {
# Line 1216  ui_draw_glyph(int mixmode, Line 1472  ui_draw_glyph(int mixmode,
1472      }\      }\
1473    if (glyph != NULL)\    if (glyph != NULL)\
1474      {\      {\
1475        ui_draw_glyph (mixmode, x + (short) glyph->offset,\        ui_draw_glyph (mixmode, x + glyph->offset,\
1476                       y + (short) glyph->baseline,\                       y + glyph->baseline,\
1477                       glyph->width, glyph->height,\                       glyph->width, glyph->height,\
1478                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\                       glyph->pixmap, 0, 0, bgcolour, fgcolour);\
1479        if (flags & TEXT2_IMPLICIT_X)\        if (flags & TEXT2_IMPLICIT_X)\

Legend:
Removed from v.297  
changed lines
  Added in v.318

  ViewVC Help
Powered by ViewVC 1.1.26