home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / contrib / gwmsend / gwmsend.c
C/C++ Source or Header  |  1995-07-03  |  1KB  |  61 lines

  1. /* 
  2.    gwmsend.c
  3.    Author: Anders Holst (aho@nada.kth.se)
  4.    Copyright (C) 1994  Anders Holst 
  5.      This file is copyrighted under the same terms as the rest of GWM
  6.      (see the X Inc license for details). There is no warranty that it
  7.      works. 
  8.    Compiles with:
  9.      gcc -o gwmsend gwmsend.c -lX11
  10.    Usage:
  11.      gwmsend 'WOOL-expression'
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <X11/Xatom.h>
  17. #include <X11/X.h>
  18. #include <X11/Xlib.h>
  19.  
  20. Display* display;
  21. char* dispName;
  22. Atom gwmprop;
  23. char buf[512];
  24.  
  25. void die(char* str) 
  26.   fprintf(stderr, str);
  27.   exit(1);
  28. }
  29.  
  30. int initDisplay()
  31. {
  32.   if (!(dispName = getenv("DISPLAY")))
  33.     return 0;
  34.   if (!(display = XOpenDisplay(dispName)))
  35.     return 0;
  36.   gwmprop = XInternAtom(display, "GWM_EXECUTE", 1); 
  37.   if (gwmprop == None)
  38.     return 0;
  39.   return 1;
  40. }
  41.  
  42. void sendGwm(char* str)
  43. {
  44.   int len;
  45.   sprintf(buf, "(? %s \"\\n\")", str);
  46.   len = strlen(buf);
  47.   XChangeProperty(display, DefaultRootWindow(display),
  48.                   gwmprop, XA_STRING, 8, PropModeReplace, buf, len);
  49.   XFlush(display); 
  50. }
  51.  
  52. void main(int argc, char** argv)
  53. {
  54.   if (argc != 2)
  55.     die("Usage: gwmsend 'expression'\n");
  56.   if (!initDisplay())
  57.     die("Could not connect to server. Check your DISPLAY environment variable.\n");
  58.   sendGwm(argv[1]);
  59. }
  60.