wmii/cmd/wmiipsel.c

88 lines
1.7 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>
static char version[] = "wmiipsel - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
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
{
2006-03-23 13:09:50 +03:00
fprintf(stderr, "%s\n", "usage: wmiipsel [-v]\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
{
2006-03-23 13:09:50 +03:00
Atom typeret;
int format;
unsigned long nitems, bytesleft;
unsigned char *data;
2005-11-18 18:54:58 +03:00
2006-03-23 13:09:50 +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
{
2006-03-23 13:09:50 +03:00
Display *dpy;
Atom xa_clip_string;
Window w;
XEvent ev;
int pdone = 0;
2005-11-18 18:54:58 +03:00
2006-03-23 13:09:50 +03:00
/* command line args */
if(argc > 1) {
if(!strncmp(argv[1], "-v", 3)) {
fprintf(stdout, "%s", version);
exit(0);
} else
usage();
}
dpy = XOpenDisplay(0);
if(!dpy) {
fprintf(stderr, "%s", "wmiipsel: cannot open display\n");
exit(1);
}
2006-03-23 13:20:53 +03:00
xa_clip_string = XInternAtom(dpy, "WMII_PSEL_STRING", False);
2006-03-23 13:09:50 +03:00
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
1, CopyFromParent, CopyFromParent);
2006-03-23 13:20:53 +03:00
while(!pdone) {
2006-03-23 13:09:50 +03:00
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;
2005-11-18 18:54:58 +03:00
}