home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xcursor / patch1 < prev    next >
Encoding:
Internet Message Format  |  1989-05-29  |  13.3 KB

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i008:  xcursor, Patch1
  5. Message-ID: <773@island.uu.net>
  6. Date: 30 May 89 05:07:46 GMT
  7. Sender: news@island.uu.net
  8. Organization: Island Graphics, Marin County, California
  9. Lines: 501
  10. Approved: island!argv@sun.com
  11.  
  12. Submitted-by: thor@stout.UCAR.EDU (Rich Neitzel)
  13. Posting-number: Volume 4, Issue 8
  14. Archive-name: xcursor/patch1
  15.  
  16.  
  17. These patches to xcursor address the following improvements:
  18.     1> Windows may be selected by name.
  19.     2> Windows may be selected by mouse clicks ala xwininfo.
  20.     3> Default action is 2. To select root a new option was added.
  21.     4> Added support for -display option.
  22.  
  23. #    This is a shell archive.
  24. #    Remove everything above and including the cut line.
  25. #    Then run the rest of the file through sh.
  26. #----cut here-----cut here-----cut here-----cut here----#
  27. #!/bin/sh
  28. # shar:    Shell Archiver
  29. #    Run the following text with /bin/sh to create:
  30. #    xcpatch1
  31. #    xcpatch2
  32. #    xcpatch3
  33. #    Apply xcpatch1 to xcursor.c, xcpatch2 to xcursor.h and
  34. #    xcpatch3 to xcursor.l.
  35. #
  36. # This archive created: Fri May 26 12:51:40 1989
  37. sed 's/^X//' << \SHAR_EOF > xcpatch1
  38. X*** xcursor.c.old    Fri May 26 12:42:35 1989
  39. X--- xcursor.c    Fri May 26 08:12:48 1989
  40. X***************
  41. X*** 6,11 ****
  42. X--- 6,13 ----
  43. X  revision history
  44. X  ----------------
  45. X  1.0,12may89,rekn      Written.
  46. X+ 2.0,25may89,rekn      Added support for named windows and selection by 
  47. X+                       pointer.
  48. X  
  49. X    This is a quick program that reads the header file defining cursors
  50. X    and lets one change the cursor for a specified window. Window
  51. X***************
  52. X*** 14,35 ****
  53. X  
  54. X  #include "xcursor.h"
  55. X  
  56. X  main(argc,argv)
  57. X  int argc;
  58. X  char **argv;
  59. X  {
  60. X      register int opt;        /* Parsed option letter */
  61. X!     char *id_str;        /* Window id in ASCII */
  62. X      extern int optind;
  63. X      extern char *optarg;
  64. X  
  65. X!     if ((display = XOpenDisplay(NULL)) == NULL)
  66. X!       {
  67. X!       perror("xcursor - no display");
  68. X!       exit(1);
  69. X!       }
  70. X  
  71. X!     while ((opt = getopt(argc,argv,"lvw:")) != -1)
  72. X        {
  73. X        switch(opt)
  74. X          {
  75. X--- 16,46 ----
  76. X  
  77. X  #include "xcursor.h"
  78. X  
  79. X+ /* Text for select by pointer case */
  80. X+ char *point_txt[] = {
  81. X+ "           ====> Please select the window",
  82. X+ "           ====> whose cursor you wish to",
  83. X+ "           ====> change by clicking the",
  84. X+ "           ====> pointer in that window.",
  85. X+ 0};
  86. X+ 
  87. X  main(argc,argv)
  88. X  int argc;
  89. X  char **argv;
  90. X  {
  91. X      register int opt;        /* Parsed option letter */
  92. X!     char *id_str = 0;        /* Window id in ASCII */
  93. X!     char *disp_str = 0;        /* Display name */
  94. X!     char *name_str = 0;        /* Window name */
  95. X!     register int uflag = 0;    /* Source specified */
  96. X!     register char **ptr;    /* Fast pointer */
  97. X      extern int optind;
  98. X      extern char *optarg;
  99. X+     extern int opterr;
  100. X  
  101. X!     opterr = 0;            /* No error msgs from getopt */
  102. X  
  103. X!     while ((opt = getopt(argc,argv,"lvd:n:i:r")) != -1)
  104. X        {
  105. X        switch(opt)
  106. X          {
  107. X***************
  108. X*** 41,67 ****
  109. X          print_vers();
  110. X          break;
  111. X  
  112. X!           case 'w':        /* Do this window */
  113. X!         wflg++;
  114. X!         id_str = optarg;
  115. X          break;
  116. X  
  117. X!           case '?':
  118. X          local_help();
  119. X          break;
  120. X          }
  121. X        }
  122. X  
  123. X!     if (optind < argc)        /* check for user requested cursor */
  124. X        find_cursor = argv[optind];
  125. X      else
  126. X        find_cursor = default_cursor;
  127. X  
  128. X-     if (wflg)            /* Use strtol to handle hex */
  129. X-       window = (Window)strtol(id_str,(char **)NULL,0);
  130. X-     else
  131. X-       window = DefaultRootWindow(display);
  132. X- 
  133. X      work();
  134. X  
  135. X      exit(0);
  136. X--- 52,121 ----
  137. X          print_vers();
  138. X          break;
  139. X  
  140. X!           case 'd':        /* Get display name */
  141. X!         disp_str = argv[optind++];
  142. X!         if (*disp_str == '-') /* Check to see if user skipped */
  143. X!                       /* required data */
  144. X!           local_help();
  145. X          break;
  146. X  
  147. X!           case 'n':        /* Get window name */
  148. X!         name_str = argv[optind++];
  149. X!         if (*name_str == '-')
  150. X!           local_help();
  151. X!         uflag++;
  152. X!         break;
  153. X! 
  154. X!           case 'i':        /* Get window id */
  155. X!         id_str = argv[optind++];
  156. X!         if (*id_str == '-')
  157. X!           local_help();
  158. X!         uflag++;
  159. X!         break;
  160. X!         
  161. X!           case 'r':        /* Set root cursor */
  162. X!         uflag++;
  163. X!         break;
  164. X! 
  165. X!           case '?':        /* Ooops! */
  166. X!         fprintf(stderr,"xcursor - bad option\n\n");
  167. X          local_help();
  168. X          break;
  169. X          }
  170. X        }
  171. X+     
  172. X+     if ((display = XOpenDisplay(disp_str)) == NULL)
  173. X+       {
  174. X+       fprintf(stderr,"Cannot open display %s\n",disp_str);
  175. X+       exit(1);
  176. X+       }
  177. X+    
  178. X+     if (name_str != NULL)
  179. X+       {
  180. X+       if ((window = window_by_name(DefaultRootWindow(display),name_str)) 
  181. X+            == 0)
  182. X+           {
  183. X+           fprintf(stderr,"No window named %s found.\n",name_str);
  184. X+           exit(2);
  185. X+           }
  186. X+       }
  187. X+     else if (id_str != NULL)
  188. X+       window = (Window)strtol(id_str,(char **)NULL,0);
  189. X+     else if (uflag)
  190. X+       window = DefaultRootWindow(display);
  191. X+     else if (!lflg)
  192. X+       {
  193. X+       for (ptr = point_txt; *ptr; ptr++)
  194. X+         printf("%s\n",*ptr);
  195. X  
  196. X!       window = point_to_window(); /* use pointer to get window */
  197. X!       }
  198. X! 
  199. X!   if (optind < argc)        /* check for user requested cursor */
  200. X        find_cursor = argv[optind];
  201. X      else
  202. X        find_cursor = default_cursor;
  203. X  
  204. X      work();
  205. X  
  206. X      exit(0);
  207. X***************
  208. X*** 78,88 ****
  209. X  "xcursor is a small tool to set the cursor for a specified window.",
  210. X  "The syntax is:",
  211. X  "",
  212. X! "        xcursor [-l][-w id] [cursor]",
  213. X  "",
  214. X! "the -l flag lists all known cursors, the -w flag sets the cursor for",
  215. X! "window id (defaults to root window) and cursor is the name of the",
  216. X! "cursor you want (defaults to whatever local builder desired)",
  217. X  0};
  218. X  
  219. X  void local_help()
  220. X--- 132,147 ----
  221. X  "xcursor is a small tool to set the cursor for a specified window.",
  222. X  "The syntax is:",
  223. X  "",
  224. X! "    xcursor [-l] [-v] [-r] [-display display][-name name] [-id id] [cursor]",
  225. X  "",
  226. X! "the -l flag lists all known cursors; the -name option sets the cursor for",
  227. X! "the named window; the -id option sets the cursor for the window with the",
  228. X! "specified id; the -display option causes the named display to be used",
  229. X! "instead of the default display. The -v option prints the current version",
  230. X! "number of xcursor. The -r option causes the root window to be effected.",
  231. X! "Cursor is the name (XC_ prefix optional) of the cursor you want (defaults",
  232. X! "to whatever the local builder desired). If none of -r, -id or -name are",
  233. X! "used, xcursor prompts you to use the pointer to select a window.",
  234. X  0};
  235. X  
  236. X  void local_help()
  237. X***************
  238. X*** 92,98 ****
  239. X      for (ptr = help_text; *ptr; ptr++)
  240. X        fprintf(stderr,"%s\n",*ptr);
  241. X  
  242. X!     exit(1);
  243. X  }
  244. X  
  245. X  
  246. X--- 151,157 ----
  247. X      for (ptr = help_text; *ptr; ptr++)
  248. X        fprintf(stderr,"%s\n",*ptr);
  249. X  
  250. X!     exit(3);
  251. X  }
  252. X  
  253. X  
  254. X***************
  255. X*** 127,133 ****
  256. X                  flag++;
  257. X                  printf("%s\n",start);
  258. X              }
  259. X!               else if (!strcmp(start,find_cursor))
  260. X              {
  261. X                  curs = XCreateFontCursor(display,cursor);
  262. X                  XDefineCursor(display,window,curs);
  263. X--- 186,193 ----
  264. X                  flag++;
  265. X                  printf("%s\n",start);
  266. X              }
  267. X!               else if (!strcmp(start, find_cursor) ||
  268. X!                    !strcmp(&start[3], find_cursor))
  269. X              {
  270. X                  curs = XCreateFontCursor(display,cursor);
  271. X                  XDefineCursor(display,window,curs);
  272. X***************
  273. X*** 142,145 ****
  274. X--- 202,292 ----
  275. X        fprintf(stderr,"xcursor - Cannot find %s\n",find_cursor);
  276. X  
  277. X      fclose(fp);
  278. X+ }
  279. X+ 
  280. X+ /* Code for the next two routines was lifted from dsimple.c in 
  281. X+    xwininfo */
  282. X+ 
  283. X+ Window window_by_name(wdw,name)
  284. X+ Window wdw;
  285. X+ char *name;
  286. X+ {
  287. X+     Window *offspring;        /* Any children */
  288. X+     Window junk;        /* Just that */
  289. X+     Window w = 0;        /* Found window */
  290. X+     int count;            /* Number of kids */
  291. X+     int loop;            /* Loop counter */
  292. X+     char *wdw_name;        /* Returnewd name */
  293. X+ 
  294. X+     if (XFetchName(display,wdw,&wdw_name) && !strcmp(wdw_name,name))
  295. X+       return(wdw);
  296. X+     
  297. X+     if (!XQueryTree(display,wdw,&junk,&junk,&offspring,&count))
  298. X+       return(0);
  299. X+ 
  300. X+     for (loop = 0; loop < count; loop++)
  301. X+       {
  302. X+       w = window_by_name(offspring[loop],name);
  303. X+       if (w)
  304. X+         break;
  305. X+       }
  306. X+ 
  307. X+     if (offspring)
  308. X+       XFree(offspring);
  309. X+ 
  310. X+     return(w);
  311. X+ }
  312. X+     
  313. X+ Window point_to_window()
  314. X+ {
  315. X+     int status;
  316. X+     Cursor cursor;
  317. X+     XEvent event;
  318. X+     Window target_win = None;
  319. X+     int buttons = 0;
  320. X+     int screen = DefaultScreen(display);
  321. X+     
  322. X+     /* Make the target cursor */
  323. X+     cursor = XCreateFontCursor(display, XC_crosshair);
  324. X+     
  325. X+     /* Grab the pointer using target cursor, letting it room all over */
  326. X+     status = XGrabPointer(display, RootWindow(display, screen), False,
  327. X+               ButtonPressMask|ButtonReleaseMask, GrabModeSync,
  328. X+               GrabModeAsync, None, cursor, CurrentTime);
  329. X+     if (status != GrabSuccess)
  330. X+       {
  331. X+       fprintf(stderr,"Can't grab the mouse.");
  332. X+       exit(4);
  333. X+       }
  334. X+     
  335. X+     /* Let the user select a window... */
  336. X+     while ((target_win == None) || (buttons != 0)) /* allow one more event */
  337. X+       {
  338. X+       XAllowEvents(display, SyncPointer, CurrentTime);
  339. X+       XWindowEvent(display, RootWindow(display, screen),
  340. X+                ButtonPressMask|ButtonReleaseMask, &event);
  341. X+       switch (event.type) 
  342. X+         {
  343. X+           case ButtonPress:
  344. X+         if (target_win == None) 
  345. X+           {
  346. X+               /* window selected */
  347. X+               target_win = event.xbutton.subwindow; 
  348. X+               if (target_win == None)
  349. X+             target_win = RootWindow(display,screen);
  350. X+           }
  351. X+         buttons++;
  352. X+         break;
  353. X+ 
  354. X+         /* there may have been some down before we started */
  355. X+           case ButtonRelease:
  356. X+         if (buttons > 0) 
  357. X+           buttons--;
  358. X+         break;
  359. X+         }
  360. X+       } 
  361. X+     
  362. X+     XUngrabPointer(display, CurrentTime);      /* Done with pointer */
  363. X+     
  364. X+     return(target_win);
  365. X  }
  366. SHAR_EOF
  367. sed 's/^X//' << \SHAR_EOF > xcpatch2
  368. X*** xcursor.h.old    Fri May 26 12:42:45 1989
  369. X--- xcursor.h    Thu May 25 10:15:46 1989
  370. X***************
  371. X*** 1,7 ****
  372. X  /*
  373. X!   
  374. X! */
  375. X  
  376. X  #ifndef INCxcursor
  377. X  #define INCxcursor
  378. X  
  379. X--- 1,14 ----
  380. X  /*
  381. X!   Module: xcursor.h
  382. X!   Author: Richard Neitzel
  383. X!   Date:   12 May 1989
  384. X  
  385. X+ revision history
  386. X+ ----------------
  387. X+ 1.0,12may89,rekn      Written.
  388. X+ 2.0,25may89,rekn      Added support for named windows and selection by 
  389. X+                       pointer.
  390. X+ */
  391. X  #ifndef INCxcursor
  392. X  #define INCxcursor
  393. X  
  394. X***************
  395. X*** 8,15 ****
  396. X  #include <stdio.h>
  397. X  #include <string.h>
  398. X  #include <X11/Xlib.h>
  399. X  
  400. X- 
  401. X  Display *display;
  402. X  Window window;
  403. X  
  404. X--- 15,22 ----
  405. X  #include <stdio.h>
  406. X  #include <string.h>
  407. X  #include <X11/Xlib.h>
  408. X+ #include <X11/cursorfont.h>
  409. X  
  410. X  Display *display;
  411. X  Window window;
  412. X  
  413. X***************
  414. X*** 17,23 ****
  415. X  
  416. X  char default_cursor[] = "XC_gumby";
  417. X  
  418. X! char version_number[] = "1.0";
  419. X  
  420. X  char *find_cursor;
  421. X  
  422. X--- 24,30 ----
  423. X  
  424. X  char default_cursor[] = "XC_gumby";
  425. X  
  426. X! char version_number[] = "2.0";
  427. X  
  428. X  char *find_cursor;
  429. X  
  430. X***************
  431. X*** 28,32 ****
  432. X--- 35,40 ----
  433. X  #define BUFSIZE 100
  434. X  
  435. X  void print_vers(), local_help(), work();
  436. X+ Window window_by_name(), point_to_window();
  437. X  
  438. X  #endif
  439. SHAR_EOF
  440. sed 's/^X//' << \SHAR_EOF > xcpatch3
  441. X*** xcursor.l.old    Fri May 26 12:42:52 1989
  442. X--- xcursor.l    Thu May 25 10:11:20 1989
  443. X***************
  444. X*** 2,15 ****
  445. X  .SH NAME
  446. X  xcursor \- set cursor in an X window
  447. X  .SH SYNOPSIS
  448. X! xcursor [-v][-l][-w id] [cursor]
  449. X  .SH DESCRIPTION
  450. X  .I Xcursor
  451. X  allows the cursor for a window to be set to one of the standard X
  452. X! cursors or lists the available cursors. If no window id is specified,
  453. X  .I xcursor
  454. X! will act on the root window by default. If no cursor name is given,
  455. X! the default cursor selected at the time
  456. X  .I xcursor 
  457. X  was built will be used. Cursors are extracted from the file
  458. X  cursorfont.h.
  459. X--- 2,15 ----
  460. X  .SH NAME
  461. X  xcursor \- set cursor in an X window
  462. X  .SH SYNOPSIS
  463. X! xcursor [-v][-l][-id id] [-name name] [-display display][-r] [cursor]
  464. X  .SH DESCRIPTION
  465. X  .I Xcursor
  466. X  allows the cursor for a window to be set to one of the standard X
  467. X! cursors or lists the available cursors. If no window id or name is specified,
  468. X  .I xcursor
  469. X! will prompt the user to selct a window with the pointer. If no cursor
  470. X! name is given, the default cursor selected at the time
  471. X  .I xcursor 
  472. X  was built will be used. Cursors are extracted from the file
  473. X  cursorfont.h.
  474. X***************
  475. X*** 20,28 ****
  476. X  
  477. X  \-v        Prints the version number.
  478. X  
  479. X! \-w        Denotes that the next option is the window id of the
  480. X          window whose cursor will be effected. May be entered
  481. X          in decimal, octal or hexadecimal.
  482. X  .fi
  483. X  .SH FILES
  484. X  Requires read access to the cursorfonts.h file (located in the X
  485. X--- 20,34 ----
  486. X  
  487. X  \-v        Prints the version number.
  488. X  
  489. X! \-id        Denotes that the next option is the window id of the
  490. X          window whose cursor will be effected. May be entered
  491. X          in decimal, octal or hexadecimal.
  492. X+ 
  493. X+ \-display       Denotes that the named display should be used.
  494. X+ 
  495. X+ \-name          Denotes that named window should be operated on.
  496. X+ 
  497. X+ \-r             Selects the root window.
  498. X  .fi
  499. X  .SH FILES
  500. X  Requires read access to the cursorfonts.h file (located in the X
  501. X***************
  502. X*** 37,39 ****
  503. X--- 43,48 ----
  504. X  Box 3000
  505. X  Boulder, CO 80307
  506. X  thor@thor.ucar.edu
  507. X+ .fi
  508. X+ The selection of named windows and pointing to windows was stolen from
  509. X+ code by Mark Lillibridge.
  510. SHAR_EOF
  511. #    End of shell archive
  512. exit 0
  513.