home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xcursor / part01 next >
Encoding:
Text File  |  1989-05-16  |  6.1 KB  |  286 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i002:  xcursor -- set the cursor for a window, Part01/01
  5. Message-ID: <753@island.uu.net>
  6. Date: 17 May 89 05:00:55 GMT
  7. Sender: news@island.uu.net
  8. Organization: Island Graphics, Marin County, California
  9. Lines: 274
  10. Approved: island!argv@sun.com
  11.  
  12. Submitted-by: Richard Neitzel <thor@thor.ucar.edu>
  13. Posting-number: Volume 4, Issue 2
  14. Archive-name: xcursor/part01
  15.  
  16. #    This is a shell archive.
  17. #    Remove everything above and including the cut line.
  18. #    Then run the rest of the file through sh.
  19. #----cut here-----cut here-----cut here-----cut here----#
  20. #!/bin/sh
  21. # shar:    Shell Archiver
  22. #    Run the following text with /bin/sh to create:
  23. #    Makefile
  24. #    README
  25. #    xcursor.c
  26. #    xcursor.h
  27. #    xcursor.l
  28. # This archive created: Mon May 15 09:12:25 1989
  29. cat << \SHAR_EOF > Makefile
  30. XLIB = -lX11
  31. CDEBUGOPTIONS = -O4
  32.  
  33. xcursor:  
  34.     cc -o xcursor $(CDEBUGOPTIONS) xcursor.c $(XLIB)
  35. SHAR_EOF
  36. cat << \SHAR_EOF > README
  37. xcursor is small tool that lets one set the cursor for a window. Note
  38. that not all windows will allow this type of change. To make, edit
  39. xcursor.h to reflect the location of cursorfont.h and the local
  40. default cursor type and make any local changes to Makefile. 
  41.  
  42. This program has been tested on the following:
  43.  
  44. Sun-3/260
  45. Sun-3E
  46.  
  47. all running SunOS 4.0.1 and X11r3.
  48.  
  49. Send comments, flames, etc. to:
  50.  
  51. Richard Neitzel
  52. National Center for Atmospheric Research
  53. Box 3000
  54. Boulder, CO 80307
  55.  
  56. thor@thor.ucar.edu
  57. SHAR_EOF
  58. cat << \SHAR_EOF > xcursor.c
  59. /*
  60.   Module: xcursor.c
  61.   Author: Richard Neitzel
  62.   Date:   12 May 1989
  63.  
  64. revision history
  65. ----------------
  66. 1.0,12may89,rekn      Written.
  67.  
  68.   This is a quick program that reads the header file defining cursors
  69.   and lets one change the cursor for a specified window. Window
  70.   defaults to root, cursor to what's in xcursor.h.
  71. */
  72.  
  73. #include "xcursor.h"
  74.  
  75. main(argc,argv)
  76. int argc;
  77. char **argv;
  78. {
  79.     register int opt;        /* Parsed option letter */
  80.     char *id_str;        /* Window id in ASCII */
  81.     extern int optind;
  82.     extern char *optarg;
  83.  
  84.     if ((display = XOpenDisplay(NULL)) == NULL)
  85.       {
  86.       perror("xcursor - no display");
  87.       exit(1);
  88.       }
  89.  
  90.     while ((opt = getopt(argc,argv,"lvw:")) != -1)
  91.       {
  92.       switch(opt)
  93.         {
  94.           case 'l':        /* Just list cursors */
  95.         lflg++;
  96.         break;
  97.  
  98.           case 'v':        /* Print version */
  99.         print_vers();
  100.         break;
  101.  
  102.           case 'w':        /* Do this window */
  103.         wflg++;
  104.         id_str = optarg;
  105.         break;
  106.  
  107.           case '?':
  108.         local_help();
  109.         break;
  110.         }
  111.       }
  112.  
  113.     if (optind < argc)        /* check for user requested cursor */
  114.       find_cursor = argv[optind];
  115.     else
  116.       find_cursor = default_cursor;
  117.  
  118.     if (wflg)            /* Use strtol to handle hex */
  119.       window = (Window)strtol(id_str,(char **)NULL,0);
  120.     else
  121.       window = DefaultRootWindow(display);
  122.  
  123.     work();
  124.  
  125.     exit(0);
  126. }
  127.  
  128. void print_vers()
  129. {
  130.     fprintf(stderr,"xcursor version %s\n",version_number);
  131.     exit(0);
  132. }
  133.  
  134.  
  135. char *help_text[] = {
  136. "xcursor is a small tool to set the cursor for a specified window.",
  137. "The syntax is:",
  138. "",
  139. "        xcursor [-l][-w id] [cursor]",
  140. "",
  141. "the -l flag lists all known cursors, the -w flag sets the cursor for",
  142. "window id (defaults to root window) and cursor is the name of the",
  143. "cursor you want (defaults to whatever local builder desired)",
  144. 0};
  145.  
  146. void local_help()
  147. {
  148.     register char **ptr;
  149.  
  150.     for (ptr = help_text; *ptr; ptr++)
  151.       fprintf(stderr,"%s\n",*ptr);
  152.  
  153.     exit(1);
  154. }
  155.  
  156.  
  157. void work()
  158. {
  159.     register FILE *fp;        /* Source file */
  160.     register char *start;    /* Cursor name */
  161.     register char *middle;    /* Value in ASCII */
  162.     register Cursor curs;    /* Selected cursor */
  163.     register unsigned int cursor; /* Converted middle */
  164.     register int flag = 0;    /* OK flag */
  165.     char buffer[BUFSIZE];    /* Read buffer */
  166.  
  167.     if ((fp = fopen(cursor_file,"r")) == (FILE *)NULL)
  168.       {
  169.       perror("xcursor");
  170.       exit(1);
  171.       }
  172.  
  173.     while (fgets(buffer,BUFSIZE,fp))
  174.       {
  175.       if ((start = strchr(buffer,'X')) != NULL)
  176.         {
  177.         if (!strncmp(start,"XC_",3))
  178.           {
  179.               middle = strchr(start,' ');
  180.               *middle++ = 0;
  181.               cursor = (unsigned int)strtol(middle,(char **)NULL,0);
  182.  
  183.               if (lflg)
  184.             {
  185.                 flag++;
  186.                 printf("%s\n",start);
  187.             }
  188.               else if (!strcmp(start,find_cursor))
  189.             {
  190.                 curs = XCreateFontCursor(display,cursor);
  191.                 XDefineCursor(display,window,curs);
  192.                 XCloseDisplay(display);
  193.                 flag++;
  194.                 break;
  195.             }
  196.           }
  197.         }
  198.       }
  199.     if (!flag)
  200.       fprintf(stderr,"xcursor - Cannot find %s\n",find_cursor);
  201.  
  202.     fclose(fp);
  203. }
  204. SHAR_EOF
  205. cat << \SHAR_EOF > xcursor.h
  206. /*
  207.   
  208. */
  209.  
  210. #ifndef INCxcursor
  211. #define INCxcursor
  212.  
  213. #include <stdio.h>
  214. #include <string.h>
  215. #include <X11/Xlib.h>
  216.  
  217.  
  218. Display *display;
  219. Window window;
  220.  
  221. char cursor_file[] = "/usr/include/X11/cursorfont.h";
  222.  
  223. char default_cursor[] = "XC_gumby";
  224.  
  225. char version_number[] = "1.0";
  226.  
  227. char *find_cursor;
  228.  
  229. int lflg = 0;
  230.  
  231. int wflg = 0;
  232.  
  233. #define BUFSIZE 100
  234.  
  235. void print_vers(), local_help(), work();
  236.  
  237. #endif
  238. SHAR_EOF
  239. cat << \SHAR_EOF > xcursor.l
  240. .TH xcursor 1 "12 May 1989"
  241. .SH NAME
  242. xcursor \- set cursor in an X window
  243. .SH SYNOPSIS
  244. xcursor [-v][-l][-w id] [cursor]
  245. .SH DESCRIPTION
  246. .I Xcursor
  247. allows the cursor for a window to be set to one of the standard X
  248. cursors or lists the available cursors. If no window id is specified,
  249. .I xcursor
  250. will act on the root window by default. If no cursor name is given,
  251. the default cursor selected at the time
  252. .I xcursor 
  253. was built will be used. Cursors are extracted from the file
  254. cursorfont.h.
  255. .SH OPTIONS
  256. .nf
  257. \-l         This causes a list of the standard X cursors to be
  258.         given on standard output.
  259.  
  260. \-v        Prints the version number.
  261.  
  262. \-w        Denotes that the next option is the window id of the
  263.         window whose cursor will be effected. May be entered
  264.         in decimal, octal or hexadecimal.
  265. .fi
  266. .SH FILES
  267. Requires read access to the cursorfonts.h file (located in the X
  268. includes path).
  269. .SH BUGS
  270. Not all windows will allow their cursor to be reset in this fashion.
  271. Does not understand user defined cursors.
  272. .SH AUTHOR
  273. .nf
  274. Richard Neitzel
  275. National Center for Atmospheric Research
  276. Box 3000
  277. Boulder, CO 80307
  278. thor@thor.ucar.edu
  279. SHAR_EOF
  280. #    End of shell archive
  281. exit 0
  282.  
  283.  
  284.  
  285. -------------------------------------------------------------------------------
  286.