wmii/cmd/wmiiplumb.c

93 lines
1.9 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* 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-18 18:55:06 +03:00
"wmiiplumb - window manager improved plumb - " VERSION "\n"
2005-12-05 01:45:59 +03:00
" (C)opyright MMIV-MMV Anselm R. Garbe\n", 0
2005-11-18 18:54:58 +03:00
};
2005-12-05 01:45:59 +03:00
static void usage()
2005-11-18 18:54:58 +03:00
{
fprintf(stderr, "%s\n",
2005-12-18 18:55:06 +03:00
"usage: wmiiplumb [-v]\n" " -v version info\n");
2005-11-18 18:54:58 +03:00
exit(1);
}
2005-12-05 01:45:59 +03:00
static void print_sel(Display * dpy, Window w, XSelectionEvent * e)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
Atom typeret;
int format;
unsigned long nitems, bytesleft;
unsigned char *data;
2005-11-18 18:54:58 +03:00
XGetWindowProperty(dpy, w, e->property, 0L, 4096L, False,
2005-12-05 01:45:59 +03:00
AnyPropertyType, &typeret, &format,
&nitems, &bytesleft, &data);
2005-11-18 18:54:58 +03:00
if (format == 8) {
2005-12-05 01:45:59 +03:00
int i;
2005-11-18 18:54:58 +03:00
for (i = 0; i < nitems; i++)
putchar(data[i]);
putchar('\n');
}
XDeleteProperty(dpy, w, e->property);
}
2005-12-05 01:45:59 +03:00
int main(int argc, char **argv)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
Display *dpy;
Atom xa_clip_string;
Window w;
XEvent ev;
int pdone = 0;
2005-11-18 18:54:58 +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) {
2005-12-18 18:55:06 +03:00
fprintf(stderr, "%s", "wmiiplumb: cannot open display\n");
2005-11-18 18:54:58 +03:00
exit(1);
}
xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False);
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
2005-12-05 01:45:59 +03:00
1, CopyFromParent, CopyFromParent);
2005-11-18 18:54:58 +03:00
while (1 && !pdone) {
XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
2005-12-05 01:45:59 +03:00
w, CurrentTime);
2005-11-18 18:54:58 +03:00
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;
*/
}