mtr@mace.cc.purdue.edu (Miek Rowan) (11/27/88)
I couldn't find a way to set my root window cursor to one of the "standard"
cursors defined in <X11/cursorfont.h> - If I missed something obvious please
let me know. I added a "-cursorfont <shape>" option to xsetroot so that I
could do just that - change my root window cursor to anything defined in the
server through cursor.snf. It takes the symbolic name from the include
file. ie:
xsetroot -cursorfont XC_dot
At first it would also take a number (eg "xsetroot -cursorfont 38"), but I
decided that that was wrong. I ifdef'ed it out as NONPORTABLE for anyone
who really does want it.
Here are the diffs. Even a man page entry!
mtr
---- cut here ----
*** /tmp/,RCSt1003334 Sat Nov 26 23:20:56 1988
--- xsetroot.c Sat Nov 26 22:56:22 1988
***************
*** 4,9 ****
--- 4,11 ----
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <stdio.h>
+ #include <ctype.h>
+ #include <X11/cursorfont.h>
#include "X11/bitmaps/gray"
/*
***************
*** 42,47 ****
--- 44,50 ----
fprintf(stderr, " -def or -default\n");
fprintf(stderr, " -name <string>\n");
fprintf(stderr, " -cursor <cursor file> <mask file>\n");
+ fprintf(stderr, " -cursorfont <cursor-font>\n");
fprintf(stderr, " -solid <color>\n");
fprintf(stderr, " -gray or -grey\n");
fprintf(stderr, " -bitmap <filename>\n");
***************
*** 61,66 ****
--- 64,70 ----
int excl = 0;
int nonexcl = 0;
int restore_defaults = 0;
+ int iCursor = -1;
char *display_name = NULL;
char *name = NULL;
char *cursor_file = NULL;
***************
*** 145,150 ****
--- 149,170 ----
reverse = 1;
continue;
}
+ if (!strcmp("-cursorfont",argv[i])) {
+ if( i++ >= argc) {
+ usage();
+ }
+ #ifdef NONPORTABLE
+ if(isdigit(*argv[i])) {
+ iCursor = atoi(argv[i]);
+ } else
+ #endif /* NONPORTABLE */
+ if(-1 == (iCursor = SetStdCursor(argv[i]))) {
+ usage();
+ }
+ nonexcl++;
+ continue;
+ }
+
usage();
}
***************
*** 174,180 ****
XDefineCursor(dpy, root, cursor);
XFreeCursor(dpy, cursor);
}
!
/* Handle -gray and -grey options */
if (gray) {
bitmap = XCreateBitmapFromData(dpy, root, gray_bits,
--- 194,210 ----
XDefineCursor(dpy, root, cursor);
XFreeCursor(dpy, cursor);
}
!
! if(iCursor != -1) {
! Cursor cursorfromfont;
!
! cursorfromfont = XCreateFontCursor(dpy, iCursor);
! if((Cursor) 0 != cursorfromfont) {
! XDefineCursor(dpy, root, cursorfromfont);
! XFreeCursor(dpy, cursorfromfont);
! }
! }
!
/* Handle -gray and -grey options */
if (gray) {
bitmap = XCreateBitmapFromData(dpy, root, gray_bits,
***************
*** 208,214 ****
/* Handle restore defaults */
if (restore_defaults) {
! if (!cursor_file)
XUndefineCursor(dpy, root);
if (!excl) {
XSetWindowBackgroundPixmap(dpy, root, (Pixmap) None);
--- 238,244 ----
/* Handle restore defaults */
if (restore_defaults) {
! if (!cursor_file && iCursor != -1)
XUndefineCursor(dpy, root);
if (!excl) {
XSetWindowBackgroundPixmap(dpy, root, (Pixmap) None);
***************
*** 439,442 ****
--- 469,572 ----
program_name, filename);
exit(1);
/*NOTREACHED*/
+ }
+
+ typedef struct {
+ char *pchcursor;
+ int shape;
+ } CursorFontType;
+
+ CursorFontType CursorFonts[] = {
+ "XC_num_glyphs", XC_num_glyphs,
+ "XC_X_cursor", XC_X_cursor,
+ "XC_arrow", XC_arrow,
+ "XC_based_arrow_down", XC_based_arrow_down,
+ "XC_based_arrow_up", XC_based_arrow_up,
+ "XC_boat", XC_boat,
+ "XC_bogosity", XC_bogosity,
+ "XC_bottom_left_corner", XC_bottom_left_corner,
+ "XC_bottom_right_corner", XC_bottom_right_corner,
+ "XC_bottom_side", XC_bottom_side,
+ "XC_bottom_tee", XC_bottom_tee,
+ "XC_box_spiral", XC_box_spiral,
+ "XC_center_ptr", XC_center_ptr,
+ "XC_circle", XC_circle,
+ "XC_clock", XC_clock,
+ "XC_coffee_mug", XC_coffee_mug,
+ "XC_cross", XC_cross,
+ "XC_cross_reverse", XC_cross_reverse,
+ "XC_crosshair", XC_crosshair,
+ "XC_diamond_cross", XC_diamond_cross,
+ "XC_dot", XC_dot,
+ "XC_dotbox", XC_dotbox,
+ "XC_double_arrow", XC_double_arrow,
+ "XC_draft_large", XC_draft_large,
+ "XC_draft_small", XC_draft_small,
+ "XC_draped_box", XC_draped_box,
+ "XC_exchange", XC_exchange,
+ "XC_fleur", XC_fleur,
+ "XC_gobbler", XC_gobbler,
+ "XC_gumby", XC_gumby,
+ "XC_hand1", XC_hand1,
+ "XC_hand2", XC_hand2,
+ "XC_heart", XC_heart,
+ "XC_icon", XC_icon,
+ "XC_iron_cross", XC_iron_cross,
+ "XC_left_ptr", XC_left_ptr,
+ "XC_left_side", XC_left_side,
+ "XC_left_tee", XC_left_tee,
+ "XC_leftbutton", XC_leftbutton,
+ "XC_ll_angle", XC_ll_angle,
+ "XC_lr_angle", XC_lr_angle,
+ "XC_man", XC_man,
+ "XC_middlebutton", XC_middlebutton,
+ "XC_mouse", XC_mouse,
+ "XC_pencil", XC_pencil,
+ "XC_pirate", XC_pirate,
+ "XC_plus", XC_plus,
+ "XC_question_arrow", XC_question_arrow,
+ "XC_right_ptr", XC_right_ptr,
+ "XC_right_side", XC_right_side,
+ "XC_right_tee", XC_right_tee,
+ "XC_rightbutton", XC_rightbutton,
+ "XC_rtl_logo", XC_rtl_logo,
+ "XC_sailboat", XC_sailboat,
+ "XC_sb_down_arrow", XC_sb_down_arrow,
+ "XC_sb_h_double_arrow", XC_sb_h_double_arrow,
+ "XC_sb_left_arrow", XC_sb_left_arrow,
+ "XC_sb_right_arrow", XC_sb_right_arrow,
+ "XC_sb_up_arrow", XC_sb_up_arrow,
+ "XC_sb_v_double_arrow", XC_sb_v_double_arrow,
+ "XC_shuttle", XC_shuttle,
+ "XC_sizing", XC_sizing,
+ "XC_spider", XC_spider,
+ "XC_spraycan", XC_spraycan,
+ "XC_star", XC_star,
+ "XC_target", XC_target,
+ "XC_tcross", XC_tcross,
+ "XC_top_left_arrow", XC_top_left_arrow,
+ "XC_top_left_corner", XC_top_left_corner,
+ "XC_top_right_corner", XC_top_right_corner,
+ "XC_top_side", XC_top_side,
+ "XC_top_tee", XC_top_tee,
+ "XC_trek", XC_trek,
+ "XC_ul_angle", XC_ul_angle,
+ "XC_umbrella", XC_umbrella,
+ "XC_ur_angle", XC_ur_angle,
+ "XC_watch", XC_watch,
+ "XC_xterm", XC_xterm,
+ (char *) 0, -1
+ };
+
+ SetStdCursor(pchCursorDef)
+ char *pchCursorDef;
+ {
+ int iCnt;
+
+ for(iCnt = 0; CursorFonts[iCnt].pchcursor != (char *) 0; iCnt++) {
+ if(!strcmp(pchCursorDef, CursorFonts[iCnt].pchcursor)) {
+ return CursorFonts[iCnt].shape;
+ }
+ }
+ return -1;
}
*** /tmp/,RCSt1003454 Sat Nov 26 23:26:42 1988
--- xsetroot.man Sat Nov 26 23:22:47 1988
***************
*** 41,46 ****
--- 41,52 ----
.I bitmap(1)
program. You probably want the mask file to be all black until you
get used to the way masks work.
+ .IP "\fB-cursorfont\fP \fIcursorfontsymbol\fP"
+ This lets you change the pointer cursor to one of
+ the cursors referenced in
+ .I /usr/include/X11/cursorfont.h
+ which are defined in the font file
+ .I /usr/lib/X11/fonts/misc/cursor.snf.
.IP "\fB-bitmap\fP \fIfilename\fP"
Use the bitmap specified in the file to set the window pattern. You can
make your own bitmap files (little pictures) using the