| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: xtell.c,v 1.6 2004/04/08 01:36:29 mdw Exp $ |
| 4 | * |
| 5 | * Wake up a waiting xwait process |
| 6 | * |
| 7 | * (c) 1998 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of the Edgeware X tools collection. |
| 13 | * |
| 14 | * X tools is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * X tools is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with X tools; if not, write to the Free Software Foundation, |
| 26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | */ |
| 28 | |
| 29 | /*----- Header files ------------------------------------------------------*/ |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | |
| 35 | #include <X11/Xlib.h> |
| 36 | #include <X11/Xutil.h> |
| 37 | |
| 38 | #include <mLib/mdwopt.h> |
| 39 | #include <mLib/quis.h> |
| 40 | #include <mLib/report.h> |
| 41 | |
| 42 | #include "xatom.h" |
| 43 | #include "xwait.h" |
| 44 | |
| 45 | /*----- Main code ---------------------------------------------------------*/ |
| 46 | |
| 47 | static void version(FILE *fp) |
| 48 | { |
| 49 | fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); |
| 50 | } |
| 51 | |
| 52 | static void usage(FILE *fp) |
| 53 | { |
| 54 | fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS); |
| 55 | } |
| 56 | |
| 57 | int main(int argc, char *argv[]) |
| 58 | { |
| 59 | char *display = 0; |
| 60 | Display *dpy; |
| 61 | Atom a, m; |
| 62 | char *atom = XWAIT_DIE; |
| 63 | char *msg = XWAIT_DIE_MSG; |
| 64 | |
| 65 | /* --- Parse options --- */ |
| 66 | |
| 67 | ego(argv[0]); |
| 68 | |
| 69 | for (;;) { |
| 70 | static struct option opt[] = { |
| 71 | { "help", 0, 0, 'h' }, |
| 72 | { "usage", 0, 0, 'u' }, |
| 73 | { "version", 0, 0, 'v' }, |
| 74 | { "display", OPTF_ARGREQ, 0, 'd' }, |
| 75 | { "atom", OPTF_ARGREQ, 0, 'a' }, |
| 76 | { "msg", OPTF_ARGREQ, 0, 'm' }, |
| 77 | { 0, 0, 0, 0 } |
| 78 | }; |
| 79 | |
| 80 | int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0); |
| 81 | if (i < 0) |
| 82 | break; |
| 83 | switch (i) { |
| 84 | case 'h': |
| 85 | version(stdout); |
| 86 | fputs("\n", stdout); |
| 87 | usage(stdout); |
| 88 | fputs( |
| 89 | "\n" |
| 90 | "Signals a waiting `xwait' process. Specifically, writes a property\n" |
| 91 | "named ATOM to the X root window, with value MSG.\n" |
| 92 | "\n" |
| 93 | "Options:\n" |
| 94 | "\n" |
| 95 | "-h, --help Display this help text\n" |
| 96 | "-u, --usage Display a short usage summary\n" |
| 97 | "-v, --version Display the program's version number\n" |
| 98 | "\n" |
| 99 | "-d, --display=DISPLAY Choose X display to connect to\n" |
| 100 | "-a, --atom=ATOM\t Choose property name to set [deprecated]\n" |
| 101 | "-m, --msg=MSG Choose value of property to set [deprecated]\n", |
| 102 | stdout); |
| 103 | exit(0); |
| 104 | break; |
| 105 | case 'u': |
| 106 | usage(stdout); |
| 107 | exit(0); |
| 108 | break; |
| 109 | case 'v': |
| 110 | version(stdout); |
| 111 | exit(0); |
| 112 | break; |
| 113 | |
| 114 | case 'd': |
| 115 | display = optarg; |
| 116 | break; |
| 117 | case 'a': |
| 118 | atom = optarg; |
| 119 | break; |
| 120 | case 'm': |
| 121 | msg = optarg; |
| 122 | break; |
| 123 | default: |
| 124 | usage(stderr); |
| 125 | exit(EXIT_FAILURE); |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (optind < argc) { |
| 131 | char *p; |
| 132 | if ((atom = strtok(argv[optind++], ":")) == 0) |
| 133 | die(EXIT_FAILURE, "missing atom name"); |
| 134 | if ((p = strtok(0, ",")) != 0) |
| 135 | msg = p; |
| 136 | } |
| 137 | |
| 138 | if (optind < argc) { |
| 139 | usage(stderr); |
| 140 | exit(EXIT_FAILURE); |
| 141 | } |
| 142 | |
| 143 | /* --- Set the property value and exit --- */ |
| 144 | |
| 145 | if ((dpy = XOpenDisplay(display)) == 0) |
| 146 | die(EXIT_FAILURE, "couldn't open display"); |
| 147 | |
| 148 | a = XInternAtom(dpy, atom, False); |
| 149 | m = XInternAtom(dpy, msg, False); |
| 150 | xatom_set(dpy, DefaultRootWindow(dpy), a, m); |
| 151 | |
| 152 | XCloseDisplay(dpy); |
| 153 | return (0); |
| 154 | } |
| 155 | |
| 156 | /*----- That's all, folks -------------------------------------------------*/ |