changeset: 15:e86225980f5d
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sat Jun 18 18:47:03 2011 +0100
files: lsw.c
description:
reverse list
diff -r 4426592fcac8 -r e86225980f5d lsw.c
--- a/lsw.c Sat Jun 18 04:54:53 2011 +0100
+++ b/lsw.c Sat Jun 18 18:47:03 2011 +0100
@@ -5,8 +5,8 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-static void getname(Window win, char *buf, size_t size);
-static void lsw(Window win);
+static const char *getname(Window);
+static void lsw(Window);
static Atom netwmname;
static Display *dpy;
@@ -32,37 +32,35 @@
void
lsw(Window win) {
- char buf[BUFSIZ];
- unsigned int i, n;
- Window *wins, dw;
+ unsigned int n;
+ Window *wins, *w, dw;
XWindowAttributes wa;
if(!XQueryTree(dpy, win, &dw, &dw, &wins, &n))
return;
- for(i = 0; i < n; i++)
- if(XGetWindowAttributes(dpy, wins[i], &wa)
- && !wa.override_redirect && wa.map_state == IsViewable) {
- getname(wins[i], buf, sizeof buf);
- printf("0x%07lx %s\n", wins[i], buf);
- }
+ for(w = &wins[n-1]; w >= &wins[0]; w--)
+ if(XGetWindowAttributes(dpy, *w, &wa)
+ && !wa.override_redirect && wa.map_state == IsViewable)
+ printf("0x%07lx %s\n", *w, getname(*w));
XFree(wins);
}
-void
-getname(Window win, char *buf, size_t size) {
+const char *
+getname(Window win) {
+ static char buf[BUFSIZ];
char **list;
int n;
XTextProperty prop;
- buf[0] = '\0';
if(!XGetTextProperty(dpy, win, &prop, netwmname) || prop.nitems == 0)
if(!XGetWMName(dpy, win, &prop) || prop.nitems == 0)
- return;
+ return "";
if(!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) {
- strncpy(buf, list[0], size);
+ strncpy(buf, list[0], sizeof buf);
XFreeStringList(list);
}
else
- strncpy(buf, (char *)prop.value, size);
+ strncpy(buf, (char *)prop.value, sizeof buf);
XFree(prop.value);
+ return buf;
}
Received on Sat Jun 18 2011 - 19:47:09 CEST
This archive was generated by hypermail 2.2.0 : Sat Jun 18 2011 - 19:48:05 CEST