| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: xtell.c,v 1.1 1998/11/16 23:00:49 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 | /*----- Revision history --------------------------------------------------* |
| 30 | * |
| 31 | * $Log: xtell.c,v $ |
| 32 | * Revision 1.1 1998/11/16 23:00:49 mdw |
| 33 | * Initial versions. |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /*----- Header files ------------------------------------------------------*/ |
| 38 | |
| 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | |
| 43 | #include <unistd.h> |
| 44 | |
| 45 | #include <X11/Xlib.h> |
| 46 | #include <X11/Xutil.h> |
| 47 | |
| 48 | #include "xwait.h" |
| 49 | |
| 50 | /*----- Main code ---------------------------------------------------------*/ |
| 51 | |
| 52 | int main(int argc, char *argv[]) |
| 53 | { |
| 54 | char *display = 0; |
| 55 | Display *dpy; |
| 56 | Atom xwait_die; |
| 57 | char *atom = XWAIT_DIE; |
| 58 | char *msg = XWAIT_DIE_MSG; |
| 59 | |
| 60 | /* --- Parse options --- */ |
| 61 | |
| 62 | for (;;) { |
| 63 | int i = getopt(argc, argv, "d:a:m:"); |
| 64 | if (i < 0) |
| 65 | break; |
| 66 | switch (i) { |
| 67 | case 'd': |
| 68 | display = optarg; |
| 69 | break; |
| 70 | case 'a': |
| 71 | atom = optarg; |
| 72 | break; |
| 73 | case 'm': |
| 74 | msg = optarg; |
| 75 | break; |
| 76 | default: |
| 77 | fprintf(stderr, "Usage: xtell [-d DISPLAY] [-a ATOM] [-m MSG]\n"); |
| 78 | exit(EXIT_FAILURE); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* --- Connect to the display --- */ |
| 84 | |
| 85 | dpy = XOpenDisplay(display); |
| 86 | if (!dpy) { |
| 87 | fprintf(stderr, "xtell: couldn't open display\n"); |
| 88 | exit(EXIT_FAILURE); |
| 89 | } |
| 90 | |
| 91 | /* --- Find the right atom --- */ |
| 92 | |
| 93 | xwait_die = XInternAtom(dpy, atom, False); |
| 94 | |
| 95 | /* --- Set the property value --- */ |
| 96 | |
| 97 | { |
| 98 | XTextProperty prop; |
| 99 | if (!XGetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die)) { |
| 100 | fprintf(stderr, "xtell: no xwait listening for `%s'\n", atom); |
| 101 | exit(EXIT_FAILURE); |
| 102 | } |
| 103 | XStringListToTextProperty(&msg, 1, &prop); |
| 104 | XSetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die); |
| 105 | } |
| 106 | |
| 107 | /* --- Done --- */ |
| 108 | |
| 109 | XCloseDisplay(dpy); |
| 110 | return (0); |
| 111 | } |
| 112 | |
| 113 | /*----- That's all, folks -------------------------------------------------*/ |