changeset: 3:ecfe2752b310
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Mon Aug 09 11:55:02 2010 +0100
files: sprop.c
description:
utf8 + display check
diff -r 65280efd14cb -r ecfe2752b310 sprop.c
--- a/sprop.c Mon May 24 13:28:28 2010 +0100
+++ b/sprop.c Mon Aug 09 11:55:02 2010 +0100
@@ -4,30 +4,34 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
-static char *getatom(Atom atom);
-static void setatom(Atom atom, char *value);
+static char *getprop(Atom atom);
+static void setprop(Atom atom, char *value);
+static Atom utf8;
static Display *dpy;
static Window win;
int
main(int argc, char *argv[])
{
+ char *value = NULL;
Atom atom;
- char *value = NULL;
- dpy = XOpenDisplay(NULL);
-
+ if(!(dpy = XOpenDisplay(NULL))) {
+ fputs("sprop: cannot open display\n", stderr);
+ return 1;
+ }
switch(argc) {
case 4:
value = argv[3];
case 3:
atom = XInternAtom(dpy, argv[2], True);
- win = atoi(argv[1]);
+ utf8 = XInternAtom(dpy, "UTF8_STRING", True);
+ win = atol(argv[1]);
break;
case 2:
if(!strcmp(argv[1], "-v")) {
- printf("sprop-"VERSION", © 2010 Connor Lane Smith\n");
+ fputs("sprop-"VERSION", © 2010 Connor Lane Smith\n", stdout);
return 0;
}
default:
@@ -35,10 +39,10 @@
return 1;
}
if(value)
- setatom(atom, value);
+ setprop(atom, value);
else {
- if(!(value = getatom(atom))) {
- fprintf(stderr, "sprop: cannot get atom\n");
+ if(!(value = getprop(atom))) {
+ fputs("sprop: cannot get atom\n", stderr);
return 1;
}
printf("%s\n", value);
@@ -49,21 +53,20 @@
}
char *
-getatom(Atom atom)
+getprop(Atom atom)
{
- Atom adummy;
- int idummy;
- unsigned long ldummy;
+ int di;
+ unsigned long dl;
unsigned char *p = NULL;
+ Atom da;
- XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, XA_STRING,
- &adummy, &idummy, &ldummy, &ldummy, &p);
+ XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, utf8, &da, &di, &dl, &dl, &p);
return (char *)p;
}
void
-setatom(Atom atom, char *value)
+setprop(Atom atom, char *value)
{
- XChangeProperty(dpy, win, atom, XA_STRING, 8, PropModeReplace,
- (unsigned char *)value, strlen(value) + 1);
+ XChangeProperty(dpy, win, atom, utf8, 8, PropModeReplace,
+ (unsigned char *)value, strlen(value));
}
Received on Mon Aug 09 2010 - 12:55:06 CEST
This archive was generated by hypermail 2.2.0 : Mon Aug 09 2010 - 13:00:08 CEST