/[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 311 by jsorg71, Wed Feb 5 14:16:33 2003 UTC revision 331 by astrand, Tue Feb 18 13:44:27 2003 UTC
# Line 32  extern BOOL grab_keyboard; Line 32  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;  extern int server_bpp;
35    extern int win_button_size;
36  BOOL enable_compose = False;  BOOL enable_compose = False;
37  BOOL focused;  BOOL focused;
38  BOOL mouse_in_wnd;  BOOL mouse_in_wnd;
# Line 71  typedef struct Line 72  typedef struct
72  }  }
73  PropMotifWmHints;  PropMotifWmHints;
74    
75    typedef struct
76    {
77            uint32 red;
78            uint32 green;
79            uint32 blue;
80    }
81    PixelColour;
82    
83  #define FILL_RECTANGLE(x,y,cx,cy)\  #define FILL_RECTANGLE(x,y,cx,cy)\
84  { \  { \
# Line 115  static int rop2_map[] = { Line 123  static int rop2_map[] = {
123  #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]); }
124  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }  #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
125    
126  void  static void
127  mwm_hide_decorations(void)  mwm_hide_decorations(void)
128  {  {
129          PropMotifWmHints motif_hints;          PropMotifWmHints motif_hints;
# Line 137  mwm_hide_decorations(void) Line 145  mwm_hide_decorations(void)
145                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
146  }  }
147    
148  uint32  static PixelColour
149  colour16to24(uint32 colour)  split_colour15(uint32 colour)
150  {  {
151          int r;          PixelColour rv;
152          int g;          rv.red = (colour & 0x7c00) >> 10;
153          int b;          rv.red = (rv.red * 0xff) / 0x1f;
154          r = (colour & 0xf800) >> 11;          rv.green = (colour & 0x03e0) >> 5;
155          r = (r * 0xff) / 0x1f;          rv.green = (rv.green * 0xff) / 0x1f;
156          g = (colour & 0x07e0) >> 5;          rv.blue = (colour & 0x1f);
157          g = (g * 0xff) / 0x3f;          rv.blue = (rv.blue * 0xff) / 0x1f;
158          b = (colour & 0x001f);          return rv;
159          b = (b * 0xff) / 0x1f;  }
160          return (r << 16) | (g << 8) | b;  
161    static PixelColour
162    split_colour16(uint32 colour)
163    {
164            PixelColour rv;
165            rv.red = (colour & 0xf800) >> 11;
166            rv.red = (rv.red * 0xff) / 0x1f;
167            rv.green = (colour & 0x07e0) >> 5;
168            rv.green = (rv.green * 0xff) / 0x3f;
169            rv.blue = (colour & 0x001f);
170            rv.blue = (rv.blue * 0xff) / 0x1f;
171            return rv;
172    }
173    
174    static PixelColour
175    split_colour24(uint32 colour)
176    {
177            PixelColour rv;
178            rv.blue = (colour & 0xff0000) >> 16;
179            rv.green = (colour & 0xff00) >> 8;
180            rv.red = (colour & 0xff);
181            return rv;
182  }  }
183    
184  uint32  static uint32
185  colour16to32(uint32 colour)  make_colour16(PixelColour pc)
186  {  {
187          return colour16to24(colour);          pc.red = (pc.red * 0x1f) / 0xff;
188            pc.green = (pc.green * 0x3f) / 0xff;
189            pc.blue = (pc.blue * 0x1f) / 0xff;
190            return (pc.red << 11) | (pc.green << 5) | pc.blue;
191  }  }
192    
193  uint32  static uint32
194  colour24to32(uint32 colour)  make_colour24(PixelColour pc)
195  {  {
196          return colour;          return (pc.red << 16) | (pc.green << 8) | pc.blue;
197    }
198    
199    static uint32
200    make_colour32(PixelColour pc)
201    {
202            return (pc.red << 16) | (pc.green << 8) | pc.blue;
203  }  }
204    
205  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 174  translate_colour(uint32 colour) Line 212  translate_colour(uint32 colour)
212  {  {
213          switch (server_bpp)          switch (server_bpp)
214          {          {
215                    case 15:
216                            switch (bpp)
217                            {
218                                    case 16:
219                                            colour = make_colour16(split_colour15(colour));
220                                            break;
221                                    case 24:
222                                            colour = make_colour24(split_colour15(colour));
223                                            break;
224                                    case 32:
225                                            colour = make_colour32(split_colour15(colour));
226                                            break;
227                            }
228                            break;
229                  case 16:                  case 16:
230                          switch (bpp)                          switch (bpp)
231                          {                          {
232                                  case 16:                                  case 16:
233                                          break;                                          break;
234                                  case 24:                                  case 24:
235                                          colour = colour16to24(colour);                                          colour = make_colour24(split_colour16(colour));
236                                          break;                                          break;
237                                  case 32:                                  case 32:
238                                          colour = colour16to32(colour);                                          colour = make_colour32(split_colour16(colour));
239                                          break;                                          break;
240                          }                          }
241                          break;                          break;
242                  case 24:                  case 24:
243                          switch (bpp)                          switch (bpp)
244                          {                          {
245                                    case 16:
246                                            colour = make_colour16(split_colour24(colour));
247                                            break;
248                                  case 24:                                  case 24:
249                                          break;                                          break;
250                                  case 32:                                  case 32:
251                                          colour = colour24to32(colour);                                          colour = make_colour32(split_colour24(colour));
252                                          break;                                          break;
253                          }                          }
254                          break;                          break;
# Line 233  translate8to16(uint8 * data, uint16 * ou Line 288  translate8to16(uint8 * data, uint16 * ou
288                  *(out++) = (uint16) colmap[*(data++)];                  *(out++) = (uint16) colmap[*(data++)];
289  }  }
290    
291    /* little endian - conversion happens when colourmap is built */
292  static void  static void
293  translate16to16(uint16 * data, uint16 * out, uint16 * end)  translate8to24(uint8 * data, uint8 * out, uint8 * end)
294  {  {
295            uint32 value;
296    
297          while (out < end)          while (out < end)
298                  *(out++) = (uint16) translate_colour(*(data++));          {
299                    value = colmap[*(data++)];
300                    *(out++) = value;
301                    *(out++) = value >> 8;
302                    *(out++) = value >> 16;
303            }
304  }  }
305    
 /* little endian - conversion happens when colourmap is built */  
306  static void  static void
307  translate8to24(uint8 * data, uint8 * out, uint8 * end)  translate8to32(uint8 * data, uint32 * out, uint32 * end)
308    {
309            while (out < end)
310                    *(out++) = colmap[*(data++)];
311    }
312    
313    /* todo the remaining translate function might need some big endian check ?? */
314    
315    static void
316    translate15to16(uint16 * data, uint16 * out, uint16 * end)
317    {
318            while (out < end)
319                    *(out++) = (uint16) make_colour16(split_colour15(*(data++)));
320    }
321    
322    static void
323    translate15to24(uint16 * data, uint8 * out, uint8 * end)
324  {  {
325          uint32 value;          uint32 value;
326    
327          while (out < end)          while (out < end)
328          {          {
329                  value = colmap[*(data++)];                  value = make_colour24(split_colour15(*(data++)));
330                  *(out++) = value;                  *(out++) = value;
331                  *(out++) = value >> 8;                  *(out++) = value >> 8;
332                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 256  translate8to24(uint8 * data, uint8 * out Line 334  translate8to24(uint8 * data, uint8 * out
334  }  }
335    
336  static void  static void
337    translate15to32(uint16 * data, uint32 * out, uint32 * end)
338    {
339            while (out < end)
340                    *(out++) = make_colour32(split_colour15(*(data++)));
341    }
342    
343    static void
344    translate16to16(uint16 * data, uint16 * out, uint16 * end)
345    {
346            while (out < end)
347                    *(out++) = (uint16) (*(data++));
348    }
349    
350    
351    static void
352  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(uint16 * data, uint8 * out, uint8 * end)
353  {  {
354          uint32 value;          uint32 value;
355    
356          while (out < end)          while (out < end)
357          {          {
358                  value = translate_colour(*(data++));                  value = make_colour24(split_colour16(*(data++)));
359                  *(out++) = value;                  *(out++) = value;
360                  *(out++) = value >> 8;                  *(out++) = value >> 8;
361                  *(out++) = value >> 16;                  *(out++) = value >> 16;
# Line 270  translate16to24(uint16 * data, uint8 * o Line 363  translate16to24(uint16 * data, uint8 * o
363  }  }
364    
365  static void  static void
366  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate16to32(uint16 * data, uint32 * out, uint32 * end)
367  {  {
368          while (out < end)          while (out < end)
369                  *(out++) = colmap[*(data++)];                  *(out++) = make_colour32(split_colour16(*(data++)));
370  }  }
371    
372  static void  static void
373  translate16to32(uint16 * data, uint32 * out, uint32 * end)  translate24to16(uint8 * data, uint16 * out, uint16 * end)
374  {  {
375            uint32 pixel = 0;
376          while (out < end)          while (out < end)
377                  *(out++) = translate_colour(*(data++));          {
378                    pixel = *(data++) << 16;
379                    pixel |= *(data++) << 8;
380                    pixel |= *(data++);
381                    *(out++) = (uint16) make_colour16(split_colour24(pixel));
382            }
383    }
384    
385    static void
386    translate24to24(uint8 * data, uint8 * out, uint8 * end)
387    {
388            while (out < end)
389            {
390                    *(out++) = (*(data++));
391            }
392    }
393    
394    static void
395    translate24to32(uint8 * data, uint32 * out, uint32 * end)
396    {
397            uint32 pixel = 0;
398            while (out < end)
399            {
400                    memcpy(&pixel, data, 3);
401                    data += 3;
402                    *(out++) = pixel;
403            }
404  }  }
405    
406  static uint8 *  static uint8 *
# Line 290  translate_image(int width, int height, u Line 410  translate_image(int width, int height, u
410          uint8 *out = xmalloc(size);          uint8 *out = xmalloc(size);
411          uint8 *end = out + size;          uint8 *end = out + size;
412    
413          if (server_bpp == 16)          switch (server_bpp)
         {  
                 if (bpp == 16)  
                         translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end);  
                 else if (bpp == 24)  
                         translate16to24((uint16 *) data, out, end); /* todo, check this one */  
                 else if (bpp == 32)  
                         translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end);  
                 return out;  
         }  
         /* todo needs server_bpp == 24 */  
         switch (bpp)  
414          {          {
415                  case 8:                  case 24:
416                          translate8to8(data, out, end);                          switch (bpp)
417                            {
418                                    case 32:
419                                            translate24to32(data, (uint32 *) out, (uint32 *) end);
420                                            break;
421                                    case 24:
422                                            translate24to24(data, out, end);
423                                            break;
424                                    case 16:
425                                            translate24to16(data, (uint16 *) out, (uint16 *) end);
426                                            break;
427                            }
428                          break;                          break;
   
429                  case 16:                  case 16:
430                          translate8to16(data, (uint16 *) out, (uint16 *) end);                          switch (bpp)
431                            {
432                                    case 32:
433                                            translate16to32((uint16 *) data, (uint32 *) out,
434                                                            (uint32 *) end);
435                                            break;
436                                    case 24:
437                                            translate16to24((uint16 *) data, out, end);
438                                            break;
439                                    case 16:
440                                            translate16to16((uint16 *) data, (uint16 *) out,
441                                                            (uint16 *) end);
442                                            break;
443                            }
444                          break;                          break;
445                    case 15:
446                  case 24:                          switch (bpp)
447                          translate8to24(data, out, end);                          {
448                                    case 32:
449                                            translate15to32((uint16 *) data, (uint32 *) out,
450                                                            (uint32 *) end);
451                                            break;
452                                    case 24:
453                                            translate15to24((uint16 *) data, out, end);
454                                            break;
455                                    case 16:
456                                            translate15to16((uint16 *) data, (uint16 *) out,
457                                                            (uint16 *) end);
458                                            break;
459                            }
460                          break;                          break;
461                    case 8:
462                  case 32:                          switch (bpp)
463                          translate8to32(data, (uint32 *) out, (uint32 *) end);                          {
464                                    case 8:
465                                            translate8to8(data, out, end);
466                                            break;
467                                    case 16:
468                                            translate8to16(data, (uint16 *) out, (uint16 *) end);
469                                            break;
470                                    case 24:
471                                            translate8to24(data, out, end);
472                                            break;
473                                    case 32:
474                                            translate8to32(data, (uint32 *) out, (uint32 *) end);
475                                            break;
476                            }
477                          break;                          break;
478          }          }
   
479          return out;          return out;
480  }  }
481    
# Line 448  ui_init(void) Line 604  ui_init(void)
604                  IM = XOpenIM(display, NULL, NULL, NULL);                  IM = XOpenIM(display, NULL, NULL, NULL);
605    
606          xkeymap_init();          xkeymap_init();
607    
608            /* todo take this out when high colour is done */
609            printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth);
610    
611          return True;          return True;
612  }  }
613    
# Line 695  xwin_process_events(void) Line 855  xwin_process_events(void)
855                                  if (button == 0)                                  if (button == 0)
856                                          break;                                          break;
857    
858                                    /* If win_button_size is nonzero, enable single app mode */
859                                    if (xevent.xbutton.y < win_button_size)
860                                    {
861                                            if (xevent.xbutton.x < win_button_size)
862                                            {
863                                                    /* The system menu, do not send to server */
864                                                    break;
865                                            }
866                                            else if (xevent.xbutton.x >= width - win_button_size)
867                                            {
868                                                    /* The close button, continue */
869                                                    ;
870                                            }
871                                            else if (xevent.xbutton.x >= width - win_button_size * 2)
872                                            {
873                                                    /* The maximize/restore button. Do not send to
874                                                       server.  It might be a good idea to change the
875                                                       cursor or give some other visible indication
876                                                       that rdesktop inhibited this click */
877                                                    break;
878                                            }
879                                            else if (xevent.xbutton.x >= width - win_button_size * 3)
880                                            {
881                                                    /* The minimize button. Iconify window. */
882                                                    XIconifyWindow(display, wnd,
883                                                                   DefaultScreen(display));
884                                                    break;
885                                            }
886                                    }
887    
888                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,                                  rdp_send_input(time(NULL), RDP_INPUT_MOUSE,
889                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);                                                 flags | button, xevent.xbutton.x, xevent.xbutton.y);
890                                  break;                                  break;

Legend:
Removed from v.311  
changed lines
  Added in v.331

  ViewVC Help
Powered by ViewVC 1.1.26