Introduction
Introduction Statistics Contact Development Disclaimer Help
sprop.c - sprop - simple xprop replacement
git clone git://git.suckless.org/sprop
Log
Files
Refs
README
LICENSE
---
sprop.c (1360B)
---
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <X11/Xlib.h>
5 #include <X11/Xatom.h>
6
7 static char *getprop(Atom atom);
8 static void setprop(Atom atom, char *value);
9
10 static Atom utf8;
11 static Display *dpy;
12 static Window win;
13
14 int
15 main(int argc, char *argv[])
16 {
17 char *value = NULL;
18 Atom atom;
19
20 if(!(dpy = XOpenDisplay(NULL))) {
21 fputs("sprop: cannot open display\n", stderr);
22 return 1;
23 }
24 switch(argc) {
25 case 4:
26 value = argv[3];
27 case 3:
28 atom = XInternAtom(dpy, argv[2], True);
29 utf8 = XInternAtom(dpy, "UTF8_STRING", True);
30 win = atol(argv[1]);
31 break;
32 case 2:
33 if(!strcmp(argv[1], "-v")) {
34 fputs("sprop-"VERSION", © 2010 Connor Lane Smit…
35 return 0;
36 }
37 default:
38 fprintf(stderr, "usage: sprop <xid> <atom> [<value>] [-v…
39 return 1;
40 }
41 if(value)
42 setprop(atom, value);
43 else {
44 if(!(value = getprop(atom))) {
45 fputs("sprop: cannot get atom\n", stderr);
46 return 1;
47 }
48 printf("%s\n", value);
49 XFree(value);
50 }
51 XCloseDisplay(dpy);
52 return 0;
53 }
54
55 char *
56 getprop(Atom atom)
57 {
58 int di;
59 unsigned long dl;
60 unsigned char *p = NULL;
61 Atom da;
62
63 XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, utf8, &da, …
64 return (char *)p;
65 }
66
67 void
68 setprop(Atom atom, char *value)
69 {
70 XChangeProperty(dpy, win, atom, utf8, 8, PropModeReplace,
71 (unsigned char *)value, strlen(value));
72 }
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.