home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xcursor / patch2 < prev    next >
Encoding:
Text File  |  1989-06-11  |  13.4 KB  |  511 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i024:  xcursor, Patch2
  5. Message-ID: <819@island.uu.net>
  6. Date: 11 Jun 89 23:39:44 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 500
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: thor@stout.UCAR.EDU (Rich Neitzel)
  12. Posting-number: Volume 4, Issue 24
  13. Patch-To: Volume 4, Issues 2,8
  14. Archive-name: xcursor/patch2
  15.  
  16. [ These patches applied to the orignally posted sources plus the first posted
  17.   patch to xcursor from this newsgroup.  This patch is the 2nd official patch
  18.   to this posting.  The patch sent to me consisted of three files.  I combined
  19.   them into one file.  You can simply pipe this article thru patch or save it
  20.   to a file and run patch using this file.
  21.   Note the Patch-To: line above. --argv ]
  22.  
  23. Excerpt from Rich's original note
  24. -------
  25. This set of patches addes support to xcursor for setting the
  26. background and/or foreground color of the cursor and for specifying
  27. bitmapped cursors.
  28.  
  29. *** xcursor.c2    Thu Jun  8 11:07:45 1989
  30. --- xcursor.c    Thu Jun  8 10:55:50 1989
  31. ***************
  32. *** 8,13 ****
  33. --- 8,14 ----
  34.   1.0,12may89,rekn      Written.
  35.   2.0,25may89,rekn      Added support for named windows and selection by 
  36.                         pointer.
  37. + 3.0,8june89,rekn      Added color and bitmap support.
  38.   
  39.     This is a quick program that reads the header file defining cursors
  40.     and lets one change the cursor for a specified window. Window
  41. ***************
  42. *** 24,29 ****
  43. --- 25,31 ----
  44.   "           ====> pointer in that window.",
  45.   0};
  46.   
  47.   main(argc,argv)
  48.   int argc;
  49.   char **argv;
  50. ***************
  51. *** 40,46 ****
  52.   
  53.       opterr = 0;            /* No error msgs from getopt */
  54.   
  55. !     while ((opt = getopt(argc,argv,"lvd:n:i:r")) != -1)
  56.         {
  57.         switch(opt)
  58.           {
  59. --- 42,48 ----
  60.   
  61.       opterr = 0;            /* No error msgs from getopt */
  62.   
  63. !     while ((opt = getopt(argc,argv,"lvb:f:d:n:i:rp")) != -1)
  64.         {
  65.         switch(opt)
  66.           {
  67. ***************
  68. *** 52,57 ****
  69. --- 54,71 ----
  70.           print_vers();
  71.           break;
  72.   
  73. +           case 'f':        /* Foreground color */
  74. +         fcolor = argv[optind++];
  75. +         if (*fcolor == '-')
  76. +           local_help();
  77. +         break;
  78. +           case 'b':        /* Background color */
  79. +         bcolor = argv[optind++];
  80. +         if (*bcolor == '-')
  81. +           local_help();
  82. +         break;
  83.             case 'd':        /* Get display name */
  84.           disp_str = argv[optind++];
  85.           if (*disp_str == '-') /* Check to see if user skipped */
  86. ***************
  87. *** 77,82 ****
  88. --- 91,103 ----
  89.           uflag++;
  90.           break;
  91.   
  92. +           case 'p':        /* Change to named bitmap */
  93. +         source = argv[optind++];
  94. +         mask = argv[optind++];
  95. +         if (*source == '-' || *mask == '-')
  96. +           local_help();
  97. +         break;
  98.             case '?':        /* Ooops! */
  99.           fprintf(stderr,"xcursor - bad option\n\n");
  100.           local_help();
  101. ***************
  102. *** 83,95 ****
  103.           break;
  104.           }
  105.         }
  106. !     
  107.       if ((display = XOpenDisplay(disp_str)) == NULL)
  108.         {
  109.         fprintf(stderr,"Cannot open display %s\n",disp_str);
  110.         exit(1);
  111.         }
  112. !    
  113.       if (name_str != NULL)
  114.         {
  115.         if ((window = window_by_name(DefaultRootWindow(display),name_str)) 
  116. --- 104,118 ----
  117.           break;
  118.           }
  119.         }
  120.       if ((display = XOpenDisplay(disp_str)) == NULL)
  121.         {
  122.         fprintf(stderr,"Cannot open display %s\n",disp_str);
  123.         exit(1);
  124.         }
  125. !     screen = DefaultScreen(display);
  126.       if (name_str != NULL)
  127.         {
  128.         if ((window = window_by_name(DefaultRootWindow(display),name_str)) 
  129. ***************
  130. *** 116,122 ****
  131.       else
  132.         find_cursor = default_cursor;
  133.   
  134. !     work();
  135.   
  136.       exit(0);
  137.   }
  138. --- 139,148 ----
  139.       else
  140.         find_cursor = default_cursor;
  141.   
  142. !     if (source)
  143. !       pixCursor();
  144. !     else
  145. !       work();
  146.   
  147.       exit(0);
  148.   }
  149. ***************
  150. *** 132,138 ****
  151.   "xcursor is a small tool to set the cursor for a specified window.",
  152.   "The syntax is:",
  153.   "",
  154. ! "    xcursor [-l] [-v] [-r] [-display display][-name name] [-id id] [cursor]",
  155.   "",
  156.   "the -l flag lists all known cursors; the -name option sets the cursor for",
  157.   "the named window; the -id option sets the cursor for the window with the",
  158. --- 158,165 ----
  159.   "xcursor is a small tool to set the cursor for a specified window.",
  160.   "The syntax is:",
  161.   "",
  162. ! "    xcursor [-l] [-v] [-r] [-display display][-name name] [-id id]",
  163. ! "            [-fg color] [-bg color] [-p cursorfile maskfile] [cursor]",
  164.   "",
  165.   "the -l flag lists all known cursors; the -name option sets the cursor for",
  166.   "the named window; the -id option sets the cursor for the window with the",
  167. ***************
  168. *** 141,147 ****
  169.   "number of xcursor. The -r option causes the root window to be effected.",
  170.   "Cursor is the name (XC_ prefix optional) of the cursor you want (defaults",
  171.   "to whatever the local builder desired). If none of -r, -id or -name are",
  172. ! "used, xcursor prompts you to use the pointer to select a window.",
  173.   0};
  174.   
  175.   void local_help()
  176. --- 168,178 ----
  177.   "number of xcursor. The -r option causes the root window to be effected.",
  178.   "Cursor is the name (XC_ prefix optional) of the cursor you want (defaults",
  179.   "to whatever the local builder desired). If none of -r, -id or -name are",
  180. ! "used, xcursor prompts you to use the pointer to select a window. Colors may",
  181. ! "be selected by using -bg and -fg. The defaults are a white background and",
  182. ! "a black foreground. The cursor may be specified as a pixmap using -p. This",
  183. ! "takes two file names, one for the cursor and one for the mask. The hot spot",
  184. ! "is taken from the cursor file.",
  185.   0};
  186.   
  187.   void local_help()
  188. ***************
  189. *** 184,190 ****
  190.                 if (lflg)
  191.               {
  192.                   flag++;
  193. !                 printf("%s\n",start);
  194.               }
  195.                 else if (!strcmp(start, find_cursor) ||
  196.                      !strcmp(&start[3], find_cursor))
  197. --- 215,222 ----
  198.                 if (lflg)
  199.               {
  200.                   flag++;
  201. !                 if (strcmp(start,"XC_num_glyphs"))
  202. !                   printf("%s\n",start);
  203.               }
  204.                 else if (!strcmp(start, find_cursor) ||
  205.                      !strcmp(&start[3], find_cursor))
  206. ***************
  207. *** 191,197 ****
  208.               {
  209.                   curs = XCreateFontCursor(display,cursor);
  210.                   XDefineCursor(display,window,curs);
  211. -                 XCloseDisplay(display);
  212.                   flag++;
  213.                   break;
  214.               }
  215. --- 223,228 ----
  216. ***************
  217. *** 200,209 ****
  218. --- 231,341 ----
  219.         }
  220.       if (!flag)
  221.         fprintf(stderr,"xcursor - Cannot find %s\n",find_cursor);
  222. +     else if (bcolor || fcolor)    /* Only if needed */
  223. +       {
  224. +       setCursorColor();
  225. +       XRecolorCursor(display,curs,&fg,&bg);
  226. +       }
  227.   
  228. +     XCloseDisplay(display);
  229.       fclose(fp);
  230.   }
  231.   
  232. + void setCursorColor()
  233. + {
  234. +     Colormap cmp;
  235. +     if (!bcolor)
  236. +       bcolor = "white";
  237. +     
  238. +     if (!fcolor)
  239. +       fcolor = "black";
  240. +     cmp = DefaultColormap(display,screen);
  241. +     if (!XParseColor(display,cmp,bcolor,&bg))
  242. +       {
  243. +       fprintf(stderr,"Cannot locate color %s in color database.\n",bcolor);
  244. +       return;
  245. +       }
  246. +     if (!XParseColor(display,cmp,fcolor,&fg))
  247. +       {
  248. +       fprintf("stderr,Cannot locate color %s in color database.\n",fcolor);
  249. +       return;
  250. +       }
  251. + }
  252. + void pixCursor()
  253. + {
  254. +     Pixmap *psource;        /* Cursor pixmap */
  255. +     Pixmap *pmask;        /* Mask pixmap */
  256. +     int width;            /* Guess */
  257. +     int height;            /*   " */
  258. +     int xhot;            /* X location of hot spot */
  259. +     int yhot;            /* Y location of hot spot */
  260. +     Cursor cursor;        /* Our new cursor */
  261. +     int status;            /* Error return */
  262. +     int dummy;            /* Junk holder */
  263. +     Colormap cmp;        /* Ibid. */
  264. + /* Read the bitmap files and check for errors*/
  265. +     status = XReadBitmapFile(display,window,source,&width,&height,
  266. +                 &psource,&xhot,&yhot);
  267. +     switch(status)
  268. +       {
  269. +     case BitmapOpenFailed:
  270. +       fprintf(stderr,"Sorry, but cannot open file %s\n",source);
  271. +       return;
  272. +       break;
  273. +     case BitmapFileInvalid:
  274. +       fprintf(stderr,"Sorry, but file %s is not is bitmap format\n",
  275. +           source);
  276. +       return;
  277. +       break;
  278. +     case BitmapNoMemory:
  279. +       fprintf(stderr,"Sorry, but the server ran out of memory\n");
  280. +       return;
  281. +       break;
  282. +       }
  283. +     status = XReadBitmapFile(display,window,mask,&width,&height,
  284. +                 &pmask,&dummy,&dummy);
  285. +     switch(status)
  286. +       {
  287. +     case BitmapOpenFailed:
  288. +       fprintf(stderr,"Sorry, but cannot open file %s\n",mask);
  289. +       return;
  290. +       break;
  291. +     case BitmapFileInvalid:
  292. +       fprintf(stderr,"Sorry, but file %s is not is bitmap format\n",
  293. +           mask);
  294. +       return;
  295. +       break;
  296. +     case BitmapNoMemory:
  297. +       fprintf(stderr,"Sorry, but the server ran out of memory\n");
  298. +       return;
  299. +       break;
  300. +       }
  301. +     setCursorColor();        /* Need some color */
  302. +     if ((cursor = XCreatePixmapCursor(display,psource,pmask,&fg,&bg,xhot,yhot))
  303. +     == 0)
  304. +       {
  305. +       fprintf(stderr,"Sorry, cannot create your cursor\n");
  306. +       return;
  307. +       }
  308. +     XDefineCursor(display,window,cursor);
  309. + }
  310.   /* Code for the next two routines was lifted from dsimple.c in 
  311.      xwininfo */
  312.   
  313. ***************
  314. *** 244,250 ****
  315.       XEvent event;
  316.       Window target_win = None;
  317.       int buttons = 0;
  318. -     int screen = DefaultScreen(display);
  319.       
  320.       /* Make the target cursor */
  321.       cursor = XCreateFontCursor(display, XC_crosshair);
  322. --- 376,381 ----
  323. *** xcursor.h2    Thu Jun  8 11:16:11 1989
  324. --- xcursor.h    Thu Jun  8 11:13:27 1989
  325. ***************
  326. *** 8,13 ****
  327. --- 8,14 ----
  328.   1.0,12may89,rekn      Written.
  329.   2.0,25may89,rekn      Added support for named windows and selection by 
  330.                         pointer.
  331. + 3.0,8june89,rekn      Added color and bitmap support.
  332.   */
  333.   #ifndef INCxcursor
  334.   #define INCxcursor
  335. ***************
  336. *** 15,30 ****
  337.   #include <stdio.h>
  338.   #include <string.h>
  339.   #include <X11/Xlib.h>
  340.   #include <X11/cursorfont.h>
  341.   
  342.   Display *display;
  343.   Window window;
  344.   
  345.   char cursor_file[] = "/usr/include/X11/cursorfont.h";
  346.   
  347.   char default_cursor[] = "XC_gumby";
  348.   
  349. ! char version_number[] = "2.0";
  350.   
  351.   char *find_cursor;
  352.   
  353. --- 16,34 ----
  354.   #include <stdio.h>
  355.   #include <string.h>
  356.   #include <X11/Xlib.h>
  357. + #include <X11/Xutil.h>
  358. + #include <X11/Xos.h>
  359.   #include <X11/cursorfont.h>
  360.   
  361.   Display *display;
  362.   Window window;
  363. + int screen;
  364.   
  365.   char cursor_file[] = "/usr/include/X11/cursorfont.h";
  366.   
  367.   char default_cursor[] = "XC_gumby";
  368.   
  369. ! char version_number[] = "3.0";
  370.   
  371.   char *find_cursor;
  372.   
  373. ***************
  374. *** 32,40 ****
  375.   
  376.   int wflg = 0;
  377.   
  378.   #define BUFSIZE 100
  379.   
  380. ! void print_vers(), local_help(), work();
  381.   Window window_by_name(), point_to_window();
  382.   
  383.   #endif
  384. --- 36,53 ----
  385.   
  386.   int wflg = 0;
  387.   
  388. + char *bcolor = 0;
  389. + char *fcolor = 0;
  390. + char *source = 0;
  391. + char *mask = 0;
  392. + XColor bg;
  393. + XColor fg;
  394.   #define BUFSIZE 100
  395.   
  396. ! void print_vers(), local_help(), work(), setCursorColor(), pixCursor();
  397.   Window window_by_name(), point_to_window();
  398.   
  399.   #endif
  400. *** xcursor.l2    Thu Jun  8 11:10:18 1989
  401. --- xcursor.l    Thu Jun  8 11:03:46 1989
  402. ***************
  403. *** 2,18 ****
  404.   .SH NAME
  405.   xcursor \- set cursor in an X window
  406.   .SH SYNOPSIS
  407. ! xcursor [-v][-l][-id id] [-name name] [-display display][-r] [cursor]
  408.   .SH DESCRIPTION
  409.   .I Xcursor
  410.   allows the cursor for a window to be set to one of the standard X
  411. ! cursors or lists the available cursors. If no window id or name is specified,
  412.   .I xcursor
  413.   will prompt the user to selct a window with the pointer. If no cursor
  414.   name is given, the default cursor selected at the time
  415.   .I xcursor 
  416.   was built will be used. Cursors are extracted from the file
  417. ! cursorfont.h.
  418.   .SH OPTIONS
  419.   .nf
  420.   \-l         This causes a list of the standard X cursors to be
  421. --- 2,22 ----
  422.   .SH NAME
  423.   xcursor \- set cursor in an X window
  424.   .SH SYNOPSIS
  425. ! .nf
  426. ! xcursor [-v][-l][-id id] [-name name] [-display display] [-r] [-fg color]
  427. !         [-bg color] [-p cursor_file mask_file] [cursor]
  428. ! .fi
  429.   .SH DESCRIPTION
  430.   .I Xcursor
  431.   allows the cursor for a window to be set to one of the standard X
  432. ! cursors, a user supplied bitmap or lists the available cursors. If no
  433. ! window id or name is specified,
  434.   .I xcursor
  435.   will prompt the user to selct a window with the pointer. If no cursor
  436.   name is given, the default cursor selected at the time
  437.   .I xcursor 
  438.   was built will be used. Cursors are extracted from the file
  439. ! cursorfont.h. Both foreground and background colors may be specified.
  440.   .SH OPTIONS
  441.   .nf
  442.   \-l         This causes a list of the standard X cursors to be
  443. ***************
  444. *** 29,41 ****
  445.   \-name          Denotes that named window should be operated on.
  446.   
  447.   \-r             Selects the root window.
  448.   .fi
  449.   .SH FILES
  450.   Requires read access to the cursorfonts.h file (located in the X
  451.   includes path).
  452. ! .SH BUGS
  453. ! Not all windows will allow their cursor to be reset in this fashion.
  454. ! Does not understand user defined cursors.
  455.   .SH AUTHOR
  456.   .nf
  457.   Richard Neitzel
  458. --- 33,57 ----
  459.   \-name          Denotes that named window should be operated on.
  460.   
  461.   \-r             Selects the root window.
  462. + \-fg            Selects the cursor's foreground color. The 
  463. +                 default is black.
  464. + \-bg            Selects the cursor's background color. The 
  465. +                 default is white.
  466. + \-p             The next two items are the names of the cursor bitmap
  467. +                 file and the mask bitmap file. The hot spot for the
  468. +                 cursor is taken from the cursor file.
  469.   .fi
  470.   .SH FILES
  471.   Requires read access to the cursorfonts.h file (located in the X
  472.   includes path).
  473. ! .SH BUGS AND WARNINGS
  474. ! Not all windows will allow their cursor to be reset in this fashion
  475. ! and some will only function with one of the methods. Since the hot
  476. ! spot location is taken from the cursor bitmap file, cursors may not
  477. ! "point" as exspected.
  478.   .SH AUTHOR
  479.   .nf
  480.   Richard Neitzel
  481.