/[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 23 by matty, Tue Oct 17 08:24:09 2000 UTC revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC
# Line 61  BOOL ui_create_window(char *title) Line 61  BOOL ui_create_window(char *title)
61    
62          visual = DefaultVisual(display, DefaultScreen(display));          visual = DefaultVisual(display, DefaultScreen(display));
63    
64          attribs.background_pixel = BlackPixel(display, DefaultScreen(display));          attribs.background_pixel =
65                    BlackPixel(display, DefaultScreen(display));
66          attribs.backing_store = Always;          attribs.backing_store = Always;
67          wnd = XCreateWindow(display, DefaultRootWindow(display),          wnd = XCreateWindow(display, DefaultRootWindow(display),
68                          0, 0, width, height, 0, 8, InputOutput, visual,                              0, 0, width, height, 0, 8, InputOutput, visual,
69                          CWBackingStore | CWBackPixel, &attribs);                              CWBackingStore | CWBackPixel, &attribs);
70    
71          XStoreName(display, wnd, title);          XStoreName(display, wnd, title);
72          XMapWindow(display, wnd);          XMapWindow(display, wnd);
73    
74          input_mask  = KeyPressMask | KeyReleaseMask;          input_mask = KeyPressMask | KeyReleaseMask;
75          input_mask |= ButtonPressMask | ButtonReleaseMask;          input_mask |= ButtonPressMask | ButtonReleaseMask;
76          if (motion)          if (motion)
77                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
# Line 99  static uint8 xwin_translate_key(unsigned Line 100  static uint8 xwin_translate_key(unsigned
100    
101          switch (key)          switch (key)
102          {          {
103                  case 0x62: /* left arrow */                  case 0x62:      /* left arrow */
104                          return 0x48;                          return 0x48;
105                  case 0x64: /* up arrow */                  case 0x64:      /* up arrow */
106                          return 0x4b;                          return 0x4b;
107                  case 0x66: /* down arrow */                  case 0x66:      /* down arrow */
108                          return 0x4d;                          return 0x4d;
109                  case 0x68: /* right arrow */                  case 0x68:      /* right arrow */
110                          return 0x50;                          return 0x50;
111                  case 0x73: /* Windows key */                  case 0x73:      /* Windows key */
112                          DEBUG("CHECKPOINT\n");                          DEBUG("CHECKPOINT\n");
113          }          }
114    
# Line 118  static uint16 xwin_translate_mouse(unsig Line 119  static uint16 xwin_translate_mouse(unsig
119  {  {
120          switch (button)          switch (button)
121          {          {
122                  case Button1: /* left */                  case Button1:   /* left */
123                          return MOUSE_FLAG_BUTTON1;                          return MOUSE_FLAG_BUTTON1;
124                  case Button2: /* middle */                  case Button2:   /* middle */
125                          return MOUSE_FLAG_BUTTON3;                          return MOUSE_FLAG_BUTTON3;
126                  case Button3: /* right */                  case Button3:   /* right */
127                          return MOUSE_FLAG_BUTTON2;                          return MOUSE_FLAG_BUTTON2;
128          }          }
129    
# Line 146  void ui_process_events() Line 147  void ui_process_events()
147                  switch (event.type)                  switch (event.type)
148                  {                  {
149                          case KeyPress:                          case KeyPress:
150                                  scancode = xwin_translate_key(event.xkey.keycode);                                  scancode =
151                                            xwin_translate_key(event.xkey.
152                                                               keycode);
153                                  if (scancode == 0)                                  if (scancode == 0)
154                                          break;                                          break;
155    
156                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,
157                                                  scancode, 0);                                                 scancode, 0);
158                                  break;                                  break;
159    
160                          case KeyRelease:                          case KeyRelease:
161                                  scancode = xwin_translate_key(event.xkey.keycode);                                  scancode =
162                                            xwin_translate_key(event.xkey.
163                                                               keycode);
164                                  if (scancode == 0)                                  if (scancode == 0)
165                                          break;                                          break;
166    
167                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE,                                  rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
168                                                  KBD_FLAG_DOWN | KBD_FLAG_UP,                                                 KBD_FLAG_DOWN | KBD_FLAG_UP,
169                                                  scancode, 0);                                                 scancode, 0);
170                                  break;                                  break;
171    
172                          case ButtonPress:                          case ButtonPress:
173                                  button = xwin_translate_mouse(event.xbutton.button);                                  button =
174                                            xwin_translate_mouse(event.xbutton.
175                                                                 button);
176    
177                                  if (button == 0)                                  if (button == 0)
178                                          break;                                          break;
179    
180                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
181                                                  button | MOUSE_FLAG_DOWN,                                                 button | MOUSE_FLAG_DOWN,
182                                                  event.xbutton.x,                                                 event.xbutton.x,
183                                                  event.xbutton.y);                                                 event.xbutton.y);
184                                  break;                                  break;
185    
186                          case ButtonRelease:                          case ButtonRelease:
187                                  button = xwin_translate_mouse(event.xbutton.button);                                  button =
188                                            xwin_translate_mouse(event.xbutton.
189                                                                 button);
190                                  if (button == 0)                                  if (button == 0)
191                                          break;                                          break;
192    
193                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
194                                                  button,                                                 button,
195                                                  event.xbutton.x,                                                 event.xbutton.x,
196                                                  event.xbutton.y);                                                 event.xbutton.y);
197                                  break;                                  break;
198    
199                          case MotionNotify:                          case MotionNotify:
200                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,                                  rdp_send_input(ev_time, RDP_INPUT_MOUSE,
201                                                  MOUSE_FLAG_MOVE,                                                 MOUSE_FLAG_MOVE,
202                                                  event.xmotion.x,                                                 event.xmotion.x,
203                                                  event.xmotion.y);                                                 event.xmotion.y);
204                  }                  }
205          }          }
206  }  }
# Line 209  HBITMAP ui_create_bitmap(int width, int Line 218  HBITMAP ui_create_bitmap(int width, int
218          bitmap = XCreatePixmap(display, wnd, width, height, 8);          bitmap = XCreatePixmap(display, wnd, width, height, 8);
219    
220          image = XCreateImage(display, visual, 8, ZPixmap, 0,          image = XCreateImage(display, visual, 8, ZPixmap, 0,
221                                  data, width, height, 8, width);                               data, width, height, 8, width);
222          XSetFunction(display, gc, GXcopy);          XSetFunction(display, gc, GXcopy);
223          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
224          XFree(image);          XFree(image);
225            
226          return (HBITMAP)bitmap;          return (HBITMAP) bitmap;
227  }  }
228    
229  void ui_paint_bitmap(int x, int y, int cx, int cy,  void ui_paint_bitmap(int x, int y, int cx, int cy,
230                          int width, int height, uint8 *data)                       int width, int height, uint8 *data)
231  {  {
232          XImage *image;          XImage *image;
233    
234          image = XCreateImage(display, visual, 8, ZPixmap, 0,          image = XCreateImage(display, visual, 8, ZPixmap, 0,
235                                  data, width, height, 8, width);                               data, width, height, 8, width);
236          XSetFunction(display, gc, GXcopy);          XSetFunction(display, gc, GXcopy);
237          XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);          XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
238          XFree(image);          XFree(image);
239  }  }
240    
241  void ui_destroy_bitmap(HBITMAP bmp)  void ui_destroy_bitmap(HBITMAP bmp)
242  {  {
243          XFreePixmap(display, (Pixmap)bmp);          XFreePixmap(display, (Pixmap) bmp);
244  }  }
245    
246  HGLYPH ui_create_glyph(int width, int height, uint8 *data)  HGLYPH ui_create_glyph(int width, int height, uint8 *data)
# Line 247  HGLYPH ui_create_glyph(int width, int he Line 256  HGLYPH ui_create_glyph(int width, int he
256          gc = XCreateGC(display, bitmap, 0, NULL);          gc = XCreateGC(display, bitmap, 0, NULL);
257    
258          image = XCreateImage(display, visual, 1, ZPixmap, 0,          image = XCreateImage(display, visual, 1, ZPixmap, 0,
259                                  data, width, height, 8, scanline);                               data, width, height, 8, scanline);
260          image->byte_order = MSBFirst;          image->byte_order = MSBFirst;
261          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
262          XInitImage(image);          XInitImage(image);
# Line 256  HGLYPH ui_create_glyph(int width, int he Line 265  HGLYPH ui_create_glyph(int width, int he
265          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
266          XFree(image);          XFree(image);
267          XFreeGC(display, gc);          XFreeGC(display, gc);
268            
269          return (HGLYPH)bitmap;          return (HGLYPH) bitmap;
270  }  }
271    
272  void ui_destroy_glyph(HGLYPH glyph)  void ui_destroy_glyph(HGLYPH glyph)
273  {  {
274          XFreePixmap(display, (Pixmap)glyph);          XFreePixmap(display, (Pixmap) glyph);
275  }  }
276    
277  HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)  HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
# Line 289  HCOLOURMAP ui_create_colourmap(COLOURMAP Line 298  HCOLOURMAP ui_create_colourmap(COLOURMAP
298          XStoreColors(display, map, xcolours, ncolours);          XStoreColors(display, map, xcolours, ncolours);
299    
300          xfree(xcolours);          xfree(xcolours);
301          return (HCOLOURMAP)map;          return (HCOLOURMAP) map;
302  }  }
303    
304  void ui_destroy_colourmap(HCOLOURMAP map)  void ui_destroy_colourmap(HCOLOURMAP map)
305  {  {
306          XFreeColormap(display, (Colormap)map);          XFreeColormap(display, (Colormap) map);
307  }  }
308    
309  void ui_set_colourmap(HCOLOURMAP map)  void ui_set_colourmap(HCOLOURMAP map)
310  {  {
311          XSetWindowColormap(display, wnd, (Colormap)map);          XSetWindowColormap(display, wnd, (Colormap) map);
312  }  }
313    
314  void ui_set_clip(int x, int y, int cx, int cy)  void ui_set_clip(int x, int y, int cx, int cy)
# Line 330  void ui_bell() Line 339  void ui_bell()
339  }  }
340    
341  static int rop2_map[] = {  static int rop2_map[] = {
342          GXclear,        /* 0 */          GXclear,                /* 0 */
343          GXnor,          /* DPon */          GXnor,                  /* DPon */
344          GXandInverted,  /* DPna */          GXandInverted,          /* DPna */
345          GXcopyInverted, /* Pn */          GXcopyInverted,         /* Pn */
346          GXandReverse,   /* PDna */          GXandReverse,           /* PDna */
347          GXinvert,       /* Dn */          GXinvert,               /* Dn */
348          GXxor,          /* DPx */          GXxor,                  /* DPx */
349          GXnand,         /* DPan */          GXnand,                 /* DPan */
350          GXand,          /* DPa */          GXand,                  /* DPa */
351          GXequiv,        /* DPxn */          GXequiv,                /* DPxn */
352          GXnoop,         /* D */          GXnoop,                 /* D */
353          GXorInverted,   /* DPno */          GXorInverted,           /* DPno */
354          GXcopy,         /* P */          GXcopy,                 /* P */
355          GXorReverse,    /* PDno */          GXorReverse,            /* PDno */
356          GXor,           /* DPo */          GXor,                   /* DPo */
357          GXset           /* 1 */          GXset                   /* 1 */
358  };  };
359    
360  static void xwin_set_function(uint8 rop2)  static void xwin_set_function(uint8 rop2)
# Line 354  static void xwin_set_function(uint8 rop2 Line 363  static void xwin_set_function(uint8 rop2
363  }  }
364    
365  void ui_destblt(uint8 opcode,  void ui_destblt(uint8 opcode,
366          /* dest */  int x, int y, int cx, int cy)                  /* dest */ int x, int y, int cx, int cy)
367  {  {
368          xwin_set_function(opcode);          xwin_set_function(opcode);
369    
# Line 362  void ui_destblt(uint8 opcode, Line 371  void ui_destblt(uint8 opcode,
371  }  }
372    
373  void ui_patblt(uint8 opcode,  void ui_patblt(uint8 opcode,
374          /* dest */  int x, int y, int cx, int cy,                 /* dest */ int x, int y, int cx, int cy,
375          /* brush */ BRUSH *brush, int bgcolour, int fgcolour)                 /* brush */ BRUSH *brush, int bgcolour, int fgcolour)
376  {  {
377          Display *dpy = display;          Display *dpy = display;
378          Pixmap fill;          Pixmap fill;
# Line 372  void ui_patblt(uint8 opcode, Line 381  void ui_patblt(uint8 opcode,
381    
382          switch (brush->style)          switch (brush->style)
383          {          {
384                  case 0: /* Solid */                  case 0: /* Solid */
385                          XSetForeground(dpy, gc, fgcolour);                          XSetForeground(dpy, gc, fgcolour);
386                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);
387                          break;                          break;
388    
389                  case 3: /* Pattern */                  case 3: /* Pattern */
390                          fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);                          fill = (Pixmap) ui_create_glyph(8, 8, brush->pattern);
391    
392                          XSetForeground(dpy, gc, fgcolour);                          XSetForeground(dpy, gc, fgcolour);
393                          XSetBackground(dpy, gc, bgcolour);                          XSetBackground(dpy, gc, bgcolour);
# Line 388  void ui_patblt(uint8 opcode, Line 397  void ui_patblt(uint8 opcode,
397                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);
398    
399                          XSetFillStyle(dpy, gc, FillSolid);                          XSetFillStyle(dpy, gc, FillSolid);
400                          ui_destroy_glyph((HGLYPH)fill);                          ui_destroy_glyph((HGLYPH) fill);
401                          break;                          break;
402    
403                  default:                  default:
# Line 397  void ui_patblt(uint8 opcode, Line 406  void ui_patblt(uint8 opcode,
406  }  }
407    
408  void ui_screenblt(uint8 opcode,  void ui_screenblt(uint8 opcode,
409                  /* dest */ int x, int y, int cx, int cy,                    /* dest */ int x, int y, int cx, int cy,
410                  /* src */  int srcx, int srcy)                    /* src */ int srcx, int srcy)
411  {  {
412          xwin_set_function(opcode);          xwin_set_function(opcode);
413    
414          XCopyArea(display, wnd, wnd, gc, srcx, srcy,          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
                         cx, cy, x, y);  
415  }  }
416    
417  void ui_memblt(uint8 opcode,  void ui_memblt(uint8 opcode,
418          /* dest */  int x, int y, int cx, int cy,                 /* dest */ int x, int y, int cx, int cy,
419          /* src */   HBITMAP src, int srcx, int srcy)                 /* src */ HBITMAP src, int srcx, int srcy)
420  {  {
421          xwin_set_function(opcode);          xwin_set_function(opcode);
422    
423          XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy,          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
                         cx, cy, x, y);  
424  }  }
425    
426  void ui_triblt(uint8 opcode,  void ui_triblt(uint8 opcode,
427          /* dest */  int x, int y, int cx, int cy,                 /* dest */ int x, int y, int cx, int cy,
428          /* src */   HBITMAP src, int srcx, int srcy,                 /* src */ HBITMAP src, int srcx, int srcy,
429          /* brush */ BRUSH *brush, int bgcolour, int fgcolour)                 /* brush */ BRUSH *brush, int bgcolour, int fgcolour)
430  {  {
431          /* This is potentially difficult to do in general. Until someone          /* This is potentially difficult to do in general. Until someone
432             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. */
433    
434          switch (opcode)          switch (opcode)
435          {          {
436                  case 0x69: /* PDSxxn */                  case 0x69:      /* PDSxxn */
437                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy);
438                          ui_patblt(ROP2_NXOR, x, y, cx, cy,                          ui_patblt(ROP2_NXOR, x, y, cx, cy,
439                                          brush, bgcolour, fgcolour);                                    brush, bgcolour, fgcolour);
440                          break;                          break;
441    
442                  case 0xb8: /* PSDPxax */                  case 0xb8:      /* PSDPxax */
443                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy,
444                                          brush, bgcolour, fgcolour);                                    brush, bgcolour, fgcolour);
445                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy);
446                          ui_patblt(ROP2_XOR, x, y, cx, cy,                          ui_patblt(ROP2_XOR, x, y, cx, cy,
447                                          brush, bgcolour, fgcolour);                                    brush, bgcolour, fgcolour);
448                          break;                          break;
449    
450                  default:                  default:
# Line 447  void ui_triblt(uint8 opcode, Line 454  void ui_triblt(uint8 opcode,
454  }  }
455    
456  void ui_line(uint8 opcode,  void ui_line(uint8 opcode,
457          /* dest */  int startx, int starty, int endx, int endy,               /* dest */ int startx, int starty, int endx, int endy,
458          /* pen */   PEN *pen)               /* pen */ PEN *pen)
459  {  {
460          xwin_set_function(opcode);          xwin_set_function(opcode);
461    
# Line 457  void ui_line(uint8 opcode, Line 464  void ui_line(uint8 opcode,
464  }  }
465    
466  void ui_rect(  void ui_rect(
467          /* dest */  int x, int y, int cx, int cy,                      /* dest */ int x, int y, int cx, int cy,
468          /* brush */ int colour)                      /* brush */ int colour)
469  {  {
470          xwin_set_function(ROP2_COPY);          xwin_set_function(ROP2_COPY);
471    
# Line 467  void ui_rect( Line 474  void ui_rect(
474  }  }
475    
476  void ui_draw_glyph(int mixmode,  void ui_draw_glyph(int mixmode,
477          /* dest */ int x, int y, int cx, int cy,                     /* dest */ int x, int y, int cx, int cy,
478          /* src */  HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour)                     /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,
479                       int fgcolour)
480  {  {
481          Pixmap pixmap = (Pixmap)glyph;          Pixmap pixmap = (Pixmap) glyph;
482    
483          xwin_set_function(ROP2_COPY);          xwin_set_function(ROP2_COPY);
484    
# Line 482  void ui_draw_glyph(int mixmode, Line 490  void ui_draw_glyph(int mixmode,
490                          XSetStipple(display, gc, pixmap);                          XSetStipple(display, gc, pixmap);
491                          XSetFillStyle(display, gc, FillStippled);                          XSetFillStyle(display, gc, FillStippled);
492                          XSetTSOrigin(display, gc, x, y);                          XSetTSOrigin(display, gc, x, y);
493                          XFillRectangle(display, wnd, gc,                          XFillRectangle(display, wnd, gc, x, y, cx, cy);
                                         x, y, cx, cy);  
494                          XSetFillStyle(display, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
495                          break;                          break;
496    
497                  case MIX_OPAQUE:                  case MIX_OPAQUE:
498                          XSetBackground(display, gc, bgcolour);                          XSetBackground(display, gc, bgcolour);
499                          XCopyPlane(display, pixmap, wnd, gc,                          XCopyPlane(display, pixmap, wnd, gc,
500                                          srcx, srcy, cx, cy, x, y, 1);                                     srcx, srcy, cx, cy, x, y, 1);
501                          break;                          break;
502    
503                  default:                  default:
# Line 499  void ui_draw_glyph(int mixmode, Line 506  void ui_draw_glyph(int mixmode,
506  }  }
507    
508  void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,  void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,
509                          int clipx, int clipy, int clipcx, int clipcy,                    int clipx, int clipy, int clipcx, int clipcy,
510                          int boxx, int boxy, int boxcx, int boxcy,                    int boxx, int boxy, int boxcx, int boxcy,
511                          int bgcolour, int fgcolour, uint8 *text, uint8 length)                    int bgcolour, int fgcolour, uint8 *text, uint8 length)
512  {  {
513          FONTGLYPH *glyph;          FONTGLYPH *glyph;
514          int i;          int i;
# Line 525  void ui_draw_text(uint8 font, uint8 flag Line 532  void ui_draw_text(uint8 font, uint8 flag
532    
533                  if (glyph != NULL)                  if (glyph != NULL)
534                  {                  {
535                          ui_draw_glyph(mixmode, x + (short)glyph->offset,                          ui_draw_glyph(mixmode, x + (short) glyph->offset,
536                                          y + (short)glyph->baseline,                                        y + (short) glyph->baseline,
537                                          glyph->width, glyph->height,                                        glyph->width, glyph->height,
538                                          glyph->pixmap, 0, 0,                                        glyph->pixmap, 0, 0,
539                                          bgcolour, fgcolour);                                        bgcolour, fgcolour);
540    
541                          if (flags & TEXT2_IMPLICIT_X)                          if (flags & TEXT2_IMPLICIT_X)
542                                  x += glyph->width;                                  x += glyph->width;
# Line 557  void ui_desktop_restore(uint32 offset, i Line 564  void ui_desktop_restore(uint32 offset, i
564                  return;                  return;
565    
566          image = XCreateImage(display, visual, 8, ZPixmap, 0,          image = XCreateImage(display, visual, 8, ZPixmap, 0,
567                                  data, cx, cy, 32, cx);                               data, cx, cy, 32, cx);
568          XSetFunction(display, gc, GXcopy);          XSetFunction(display, gc, GXcopy);
569          XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);          XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
570          XFree(image);          XFree(image);

Legend:
Removed from v.23  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26