home *** CD-ROM | disk | FTP | other *** search
/ ftp.freefriends.org / ftp.freefriends.org.tar / ftp.freefriends.org / arnold / Source / 9wm-1.1.shar.gz / 9wm-1.1.shar / cursor.c < prev    next >
C/C++ Source or Header  |  1995-01-15  |  6KB  |  184 lines

  1. /* Copyright (c) 1994 David Hogan, see README for licence details */
  2. #include <stdio.h>
  3. #include <X11/X.h>
  4. #include <X11/Xlib.h>
  5. #include <X11/Xutil.h>
  6. #include "dat.h"
  7. #include "fns.h"
  8.  
  9. Cursor  target;
  10. Cursor  sweep0;
  11. Cursor  boxcurs;
  12. Cursor  arrow;
  13. Pixmap  root_pixmap;
  14.  
  15. typedef struct {
  16.     int             width;
  17.     int             hot[2];
  18.     unsigned char   mask[64];
  19.     unsigned char   fore[64];
  20. } Cursordata;
  21.  
  22. Cursordata sweep0data = {
  23.     16,
  24.     {7, 7},
  25.     {0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03,
  26.      0xC0, 0x03, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFF,
  27.      0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xC0, 0x03,
  28.      0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03},
  29.     {0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
  30.      0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFE, 0x7F,
  31.      0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
  32.      0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00}
  33. };
  34.  
  35. Cursordata boxcursdata = {
  36.     16,
  37.     {7, 7},
  38.     {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  39.      0xFF, 0xFF, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8,
  40.      0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0xFF, 0xFF,
  41.      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  42.     {0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F,
  43.      0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70,
  44.      0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70,
  45.      0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x00, 0x00}
  46. };
  47.  
  48. Cursordata sightdata = {
  49.     16,
  50.     {7, 7},
  51.     {0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xDF, 0xFB,
  52.      0xCF, 0xF3, 0xC7, 0xE3, 0xFF, 0xFF, 0xFF, 0xFF,
  53.      0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0xE3, 0xCF, 0xF3,
  54.      0xDF, 0x7B, 0xFE, 0x7F, 0xFC, 0x3F, 0xF8, 0x1F,},
  55.     {0x00, 0x00, 0xF0, 0x0F, 0x8C, 0x31, 0x84, 0x21,
  56.      0x82, 0x41, 0x82, 0x41, 0x82, 0x41, 0xFE, 0x7F,
  57.      0xFE, 0x7F, 0x82, 0x41, 0x82, 0x41, 0x82, 0x41,
  58.      0x84, 0x21, 0x8C, 0x31, 0xF0, 0x0F, 0x00, 0x00,}
  59. };
  60.  
  61. Cursordata arrowdata = {
  62.     16,
  63.     {1, 1},
  64.     {0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00,
  65.      0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07,
  66.      0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F,
  67.      0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,},
  68.     {0x00, 0x00, 0xFE, 0x03, 0xFE, 0x00, 0x3E, 0x00,
  69.      0x7E, 0x00, 0xFE, 0x00, 0xF6, 0x01, 0xE6, 0x03,
  70.      0xC2, 0x07, 0x82, 0x0F, 0x00, 0x1F, 0x00, 0x3E,
  71.      0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00,}
  72. };
  73.  
  74. Cursordata whitearrow = {
  75.     16,
  76.     {0, 0},
  77.     {0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00,
  78.      0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07,
  79.      0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F,
  80.      0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,},
  81.     {0xFF, 0x07, 0xFF, 0x07, 0x83, 0x03, 0xC3, 0x00,
  82.      0xC3, 0x00, 0x83, 0x01, 0x1B, 0x03, 0x3F, 0x06,
  83.      0x67, 0x0C, 0xC7, 0x18, 0x83, 0x31, 0x00, 0x63,
  84.      0x00, 0xC6, 0x00, 0x6C, 0x00, 0x38, 0x00, 0x10,}
  85. };
  86.  
  87. Cursordata blittarget = {
  88.     18,
  89.     {8, 8},
  90.     {0xe0, 0x1f, 0x00, 0xf0, 0x3f, 0x00, 0xf8, 0x7f, 0x00,
  91.      0xfc, 0xff, 0x00, 0xfe, 0xff, 0x01, 0xff, 0xff, 0x03,
  92.      0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03,
  93.      0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03,
  94.      0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0xfc, 0xff, 0x00,
  95.      0xf8, 0x7f, 0x00, 0xf0, 0x3f, 0x00, 0xe0, 0x1f, 0x00},
  96.     {0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00,
  97.      0x38, 0x73, 0x00, 0x8c, 0xc7, 0x00, 0xec, 0xdf, 0x00,
  98.      0x66, 0x9b, 0x01, 0x36, 0xb3, 0x01, 0xfe, 0xff, 0x01,
  99.      0xfe, 0xff, 0x01, 0x36, 0xb3, 0x01, 0x66, 0x9b, 0x01,
  100.      0xec, 0xdf, 0x00, 0x8c, 0xc7, 0x00, 0x38, 0x73, 0x00,
  101.      0xf0, 0x3f, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00}
  102. };
  103.  
  104. Cursordata blitarrow = {
  105.     18,
  106.     {1, 1},
  107.     {0xff, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xff, 0x03, 0x00,
  108.      0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x01, 0x00,
  109.      0xff, 0x03, 0x00, 0xff, 0x07, 0x00, 0xe7, 0x0f, 0x00,
  110.      0xc7, 0x1f, 0x00, 0x87, 0x3f, 0x00, 0x03, 0x7f, 0x00,
  111.      0x01, 0xfe, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xf8, 0x03,
  112.      0x00, 0xf0, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00},
  113.     {0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0xfe, 0x00, 0x00,
  114.      0x3e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00,
  115.      0xf6, 0x01, 0x00, 0xe6, 0x03, 0x00, 0xc2, 0x07, 0x00,
  116.      0x82, 0x0f, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x3e, 0x00,
  117.      0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, 0x01,
  118.      0x00, 0xe0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}
  119. };
  120.  
  121. Cursordata blitsweep = {
  122.     18,
  123.     {8, 8},
  124.     {0xc4, 0xff, 0x03, 0xce, 0xff, 0x03, 0xdf, 0xff, 0x03,
  125.      0x3e, 0x80, 0x03, 0x7c, 0x83, 0x03, 0xf8, 0x83, 0x03,
  126.      0xf7, 0x83, 0x03, 0xe7, 0x83, 0x03, 0xf7, 0x83, 0x03,
  127.      0xf7, 0x83, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03,
  128.      0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03,
  129.      0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03},
  130.     {0x00, 0x00, 0x00, 0x84, 0xff, 0x01, 0x0e, 0x00, 0x01,
  131.      0x1c, 0x00, 0x01, 0x38, 0x00, 0x01, 0x70, 0x01, 0x01,
  132.      0xe0, 0x01, 0x01, 0xc2, 0x01, 0x01, 0xe2, 0x01, 0x01,
  133.      0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01,
  134.      0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01,
  135.      0x02, 0x00, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00}
  136. };
  137.  
  138. /*
  139.  *  Grey tile pattern for root background
  140.  */
  141.  
  142. #define grey_width 4
  143. #define grey_height 2
  144. static char grey_bits[] = {
  145.    0x01, 0x04};
  146.  
  147. Cursor
  148. getcursor(c)
  149. Cursordata *c;
  150. {
  151.     Pixmap f, m;
  152.     XColor bl, wh, d;
  153.  
  154.     f = XCreatePixmapFromBitmapData(dpy, root, (char *)c->fore,
  155.         c->width, c->width, 1, 0, 1);
  156.     m = XCreatePixmapFromBitmapData(dpy, root, (char *)c->mask,
  157.         c->width, c->width, 1, 0, 1);
  158.     XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &bl, &d);
  159.     XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "white", &wh, &d);
  160.     return XCreatePixmapCursor(dpy, f, m, &bl, &wh,
  161.                     c->hot[0], c->hot[1]);
  162. }
  163.  
  164. void
  165. initcurs()
  166. {
  167.     if (nostalgia) {
  168.         arrow = getcursor(&blitarrow);
  169.         target = getcursor(&blittarget);
  170.         sweep0 = getcursor(&blitsweep);
  171.         boxcurs = getcursor(&blitsweep);
  172.     }
  173.     else {
  174.         arrow = getcursor(&arrowdata);
  175.         target = getcursor(&sightdata);
  176.         sweep0 = getcursor(&sweep0data);
  177.         boxcurs = getcursor(&boxcursdata);
  178.     }
  179.  
  180.     root_pixmap = XCreatePixmapFromBitmapData(dpy, root,
  181.         grey_bits, grey_width, grey_height,
  182.         black, white, DefaultDepth(dpy, screen));
  183. }
  184.