v04i002: xcursor -- set the cursor for a window, Part01/01

Dan Heller argv at island.uu.net
Wed May 17 15:00:55 AEST 1989


Submitted-by: Richard Neitzel <thor at thor.ucar.edu>
Posting-number: Volume 4, Issue 2
Archive-name: xcursor/part01

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	Makefile
#	README
#	xcursor.c
#	xcursor.h
#	xcursor.l
# This archive created: Mon May 15 09:12:25 1989
cat << \SHAR_EOF > Makefile
XLIB = -lX11
CDEBUGOPTIONS = -O4

xcursor:  
	cc -o xcursor $(CDEBUGOPTIONS) xcursor.c $(XLIB)
SHAR_EOF
cat << \SHAR_EOF > README
xcursor is small tool that lets one set the cursor for a window. Note
that not all windows will allow this type of change. To make, edit
xcursor.h to reflect the location of cursorfont.h and the local
default cursor type and make any local changes to Makefile. 

This program has been tested on the following:

Sun-3/260
Sun-3E

all running SunOS 4.0.1 and X11r3.

Send comments, flames, etc. to:

Richard Neitzel
National Center for Atmospheric Research
Box 3000
Boulder, CO 80307

thor at thor.ucar.edu
SHAR_EOF
cat << \SHAR_EOF > xcursor.c
/*
  Module: xcursor.c
  Author: Richard Neitzel
  Date:   12 May 1989

revision history
----------------
1.0,12may89,rekn      Written.

  This is a quick program that reads the header file defining cursors
  and lets one change the cursor for a specified window. Window
  defaults to root, cursor to what's in xcursor.h.
*/

#include "xcursor.h"

main(argc,argv)
int argc;
char **argv;
{
    register int opt;		/* Parsed option letter */
    char *id_str;		/* Window id in ASCII */
    extern int optind;
    extern char *optarg;

    if ((display = XOpenDisplay(NULL)) == NULL)
      {
	  perror("xcursor - no display");
	  exit(1);
      }

    while ((opt = getopt(argc,argv,"lvw:")) != -1)
      {
	  switch(opt)
	    {
	      case 'l':		/* Just list cursors */
		lflg++;
		break;

	      case 'v':		/* Print version */
		print_vers();
		break;

	      case 'w':		/* Do this window */
		wflg++;
		id_str = optarg;
		break;

	      case '?':
		local_help();
		break;
	    }
      }

    if (optind < argc)		/* check for user requested cursor */
	  find_cursor = argv[optind];
    else
      find_cursor = default_cursor;

    if (wflg)			/* Use strtol to handle hex */
      window = (Window)strtol(id_str,(char **)NULL,0);
    else
      window = DefaultRootWindow(display);

    work();

    exit(0);
}

void print_vers()
{
    fprintf(stderr,"xcursor version %s\n",version_number);
    exit(0);
}


char *help_text[] = {
"xcursor is a small tool to set the cursor for a specified window.",
"The syntax is:",
"",
"        xcursor [-l][-w id] [cursor]",
"",
"the -l flag lists all known cursors, the -w flag sets the cursor for",
"window id (defaults to root window) and cursor is the name of the",
"cursor you want (defaults to whatever local builder desired)",
0};

void local_help()
{
    register char **ptr;

    for (ptr = help_text; *ptr; ptr++)
      fprintf(stderr,"%s\n",*ptr);

    exit(1);
}


void work()
{
    register FILE *fp;		/* Source file */
    register char *start;	/* Cursor name */
    register char *middle;	/* Value in ASCII */
    register Cursor curs;	/* Selected cursor */
    register unsigned int cursor; /* Converted middle */
    register int flag = 0;	/* OK flag */
    char buffer[BUFSIZE];	/* Read buffer */

    if ((fp = fopen(cursor_file,"r")) == (FILE *)NULL)
      {
	  perror("xcursor");
	  exit(1);
      }

    while (fgets(buffer,BUFSIZE,fp))
      {
	  if ((start = strchr(buffer,'X')) != NULL)
	    {
		if (!strncmp(start,"XC_",3))
		  {
		      middle = strchr(start,' ');
		      *middle++ = 0;
		      cursor = (unsigned int)strtol(middle,(char **)NULL,0);

		      if (lflg)
			{
			    flag++;
			    printf("%s\n",start);
			}
		      else if (!strcmp(start,find_cursor))
			{
			    curs = XCreateFontCursor(display,cursor);
			    XDefineCursor(display,window,curs);
			    XCloseDisplay(display);
			    flag++;
			    break;
			}
		  }
	    }
      }
    if (!flag)
      fprintf(stderr,"xcursor - Cannot find %s\n",find_cursor);

    fclose(fp);
}
SHAR_EOF
cat << \SHAR_EOF > xcursor.h
/*
  
*/

#ifndef INCxcursor
#define INCxcursor

#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>


Display *display;
Window window;

char cursor_file[] = "/usr/include/X11/cursorfont.h";

char default_cursor[] = "XC_gumby";

char version_number[] = "1.0";

char *find_cursor;

int lflg = 0;

int wflg = 0;

#define BUFSIZE 100

void print_vers(), local_help(), work();

#endif
SHAR_EOF
cat << \SHAR_EOF > xcursor.l
.TH xcursor 1 "12 May 1989"
.SH NAME
xcursor \- set cursor in an X window
.SH SYNOPSIS
xcursor [-v][-l][-w id] [cursor]
.SH DESCRIPTION
.I Xcursor
allows the cursor for a window to be set to one of the standard X
cursors or lists the available cursors. If no window id is specified,
.I xcursor
will act on the root window by default. If no cursor name is given,
the default cursor selected at the time
.I xcursor 
was built will be used. Cursors are extracted from the file
cursorfont.h.
.SH OPTIONS
.nf
\-l 		This causes a list of the standard X cursors to be
		given on standard output.

\-v		Prints the version number.

\-w		Denotes that the next option is the window id of the
		window whose cursor will be effected. May be entered
		in decimal, octal or hexadecimal.
.fi
.SH FILES
Requires read access to the cursorfonts.h file (located in the X
includes path).
.SH BUGS
Not all windows will allow their cursor to be reset in this fashion.
Does not understand user defined cursors.
.SH AUTHOR
.nf
Richard Neitzel
National Center for Atmospheric Research
Box 3000
Boulder, CO 80307
thor at thor.ucar.edu
SHAR_EOF
#	End of shell archive
exit 0



-------------------------------------------------------------------------------



More information about the Comp.sources.x mailing list