wmii/cmd/wmiiplumb.c

96 lines
2.3 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
2006-01-20 17:20:24 +03:00
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
2005-11-18 18:54:58 +03:00
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
2005-12-05 01:45:59 +03:00
static char *version[] = {
2005-12-21 18:18:11 +03:00
"wmiiplumb - window manager improved plumb - " VERSION "\n"
2006-01-20 17:20:24 +03:00
" (C)opyright MMIV-MMVI Anselm R. Garbe\n", 0
2005-11-18 18:54:58 +03:00
};
2005-12-21 18:18:11 +03:00
static void
usage()
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
fprintf(stderr, "%s\n",
"usage: wmiiplumb [-v]\n" " -v version info\n");
exit(1);
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
static void
print_sel(Display * dpy, Window w, XSelectionEvent * e)
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
Atom typeret;
int format;
unsigned long nitems, bytesleft;
unsigned char *data;
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
XGetWindowProperty(dpy, w, e->property, 0L, 4096L, False,
AnyPropertyType, &typeret, &format,
&nitems, &bytesleft, &data);
if(format == 8) {
int i;
for(i = 0; i < nitems; i++)
putchar(data[i]);
putchar('\n');
}
XDeleteProperty(dpy, w, e->property);
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
int
main(int argc, char **argv)
2005-11-18 18:54:58 +03:00
{
2005-12-21 18:18:11 +03:00
Display *dpy;
Atom xa_clip_string;
Window w;
XEvent ev;
int pdone = 0;
2005-11-18 18:54:58 +03:00
2005-12-21 18:18:11 +03:00
/* command line args */
if(argc > 1) {
if(!strncmp(argv[1], "-v", 3)) {
fprintf(stdout, "%s", version[0]);
exit(0);
} else
usage();
}
dpy = XOpenDisplay(0);
if(!dpy) {
fprintf(stderr, "%s", "wmiiplumb: cannot open display\n");
exit(1);
}
xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False);
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
1, CopyFromParent, CopyFromParent);
while(1 && !pdone) {
XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
w, CurrentTime);
XFlush(dpy);
XNextEvent(dpy, &ev);
switch (ev.type) {
case SelectionNotify:
if(ev.xselection.property != None)
print_sel(dpy, w, &ev.xselection);
else
putchar('\n');
XDestroyWindow(dpy, w);
XCloseDisplay(dpy);
pdone = 1;
break;
default:
break;
}
}
return 0;
/*
* XDestroyWindow(dpy, w); XCloseDisplay(dpy); return 1;
*/
2005-11-18 18:54:58 +03:00
}