[PATCH] xlsclients looks like ps
Enrique D. Bosch
presidev at gmail.com
Tue May 1 08:42:39 PDT 2007
Hello,
This is patch for a new feature not a bug fix, I have added a new option
(-p) to xlsclients to give a output with look and feel like ps:
$ ./xlsclients -p
ID Machine Name Command
0x00c00002 ameba aterm aterm
0x01200002 sandra aterm aterm
0x00e0005c ameba Calculator xcalc -geometry +507+139
0x01000002 ameba aterm aterm
0x01400007 ameba xeyes xeyes
0x00a00001 ameba gkrellm2 gkrellm2
0x00600001 ameba Firefox firefox-bin
I think this layout is more confortable to do things like, for example,
killing xeyes client from the command line:
$ xkill -id 0x01400007
xkill: killing creator of resource 0x1400007
Of course the previous modes normal and long (verbose) are still available
with full backward compatibility.
If you like this feature please can you add it to the next release.
Thanks.
Regards
Enrique D. Bosch
-------------- next part --------------
diff -urN xlsclients-1.0.1/ChangeLog xlsclients-1.0.1-p/ChangeLog
--- xlsclients-1.0.1/ChangeLog 2005-12-21 03:29:52.000000000 +0100
+++ xlsclients-1.0.1-p/ChangeLog 2007-05-01 14:27:28.182810769 +0200
@@ -1,3 +1,12 @@
+2007-04-30 Enrique D. Bosch <presidev-aat-gmail-dott-com>
+
+ * xlsclients.c:
+ Add new -p option that shows the output with a header and
+ fields in ps style layout.
+
+ * xlsclients.man:
+ Update manpage with the new option.
+
2005-12-20 Kevin E. Martin <kem-at-freedesktop-dot-org>
* configure.ac:
diff -urN xlsclients-1.0.1/xlsclients.c xlsclients-1.0.1-p/xlsclients.c
--- xlsclients-1.0.1/xlsclients.c 2004-04-23 21:54:58.000000000 +0200
+++ xlsclients-1.0.1-p/xlsclients.c 2007-04-30 22:25:32.314874665 +0200
@@ -39,10 +39,10 @@
char *ProgramName;
-static void lookat ( Display *dpy, Window root, Bool verbose, int maxcmdlen );
+static void lookat ( Display *dpy, Window root, int style, int maxcmdlen );
static void print_client_properties ( Display *dpy, Window w,
- Bool verbose, int maxcmdlen );
-static void print_text_field ( Display *dpy, char *s, XTextProperty *tp );
+ int style, int maxcmdlen );
+static void print_text_field ( Display *dpy, char *s, XTextProperty *tp, char *format );
static int print_quoted_word ( char *s, int maxlen );
static void unknown ( Display *dpy, Atom actual_type, int actual_format );
@@ -50,7 +50,7 @@
usage(void)
{
fprintf (stderr,
- "usage: %s [-display dpy] [-m len] [-[a][l]]\n", ProgramName);
+ "usage: %s [-display dpy] [-m len] [-[a][l][p]]\n", ProgramName);
exit (1);
}
@@ -60,7 +60,7 @@
int i;
char *displayname = NULL;
Bool all_screens = False;
- Bool verbose = False;
+ int style = 0;
Display *dpy;
int maxcmdlen = 10000;
@@ -89,7 +89,10 @@
all_screens = True;
continue;
case 'l': /* -long */
- verbose = True;
+ style = 1;
+ continue;
+ case 'p': /* -psstyle */
+ style = 2;
continue;
default:
usage ();
@@ -109,10 +112,10 @@
if (all_screens) {
for (i = 0; i < ScreenCount(dpy); i++) {
- lookat (dpy, RootWindow(dpy,i), verbose, maxcmdlen);
+ lookat (dpy, RootWindow(dpy,i), style, maxcmdlen);
}
} else {
- lookat (dpy, DefaultRootWindow(dpy), verbose, maxcmdlen);
+ lookat (dpy, DefaultRootWindow(dpy), style, maxcmdlen);
}
XCloseDisplay (dpy);
@@ -120,17 +123,20 @@
}
static void
-lookat(Display *dpy, Window root, Bool verbose, int maxcmdlen)
+lookat(Display *dpy, Window root, int style, int maxcmdlen)
{
Window dummy, *children = NULL, client;
unsigned int i, nchildren = 0;
+ /* header for psstyle */
+ if (style == 2) puts("ID Machine Name Command");
+
/*
* clients are not allowed to stomp on the root and ICCCM doesn't yet
* say anything about window managers putting stuff there; but, try
* anyway.
*/
- print_client_properties (dpy, root, verbose, maxcmdlen);
+ print_client_properties (dpy, root, style, maxcmdlen);
/*
* then, get the list of windows
@@ -142,14 +148,14 @@
for (i = 0; i < nchildren; i++) {
client = XmuClientWindow (dpy, children[i]);
if (client != None)
- print_client_properties (dpy, client, verbose, maxcmdlen);
+ print_client_properties (dpy, client, style, maxcmdlen);
}
}
static char *Nil = "(nil)";
static void
-print_client_properties(Display *dpy, Window w, Bool verbose, int maxcmdlen)
+print_client_properties(Display *dpy, Window w, int style, int maxcmdlen)
{
char **cliargv = NULL;
int i, cliargc;
@@ -172,23 +178,39 @@
/*
* do header information
*/
- if (verbose) {
+ switch (style)
+ {
+ case 1: /* long */
printf ("Window 0x%lx:\n", w);
- print_text_field (dpy, " Machine: ", &machtp);
+ print_text_field (dpy, " Machine: ", &machtp, "%s");
if (XGetWMName (dpy, w, &nametp)) {
- print_text_field (dpy, " Name: ", &nametp);
+ print_text_field (dpy, " Name: ", &nametp, "%s");
if (nametp.value) XFree ((char *) nametp.value);
}
- } else {
- print_text_field (dpy, NULL, &machtp);
+ break;
+ case 2: /* psstyle */
+ printf ("0x%08lx ", w);
+ print_text_field (dpy, NULL, &machtp, "%-10.10s");
+ putchar (' ');
+ putchar (' ');
+ if (XGetWMName (dpy, w, &nametp)) {
+ print_text_field (dpy, NULL, &nametp, "%-15.15s");
+ putchar (' ');
+ putchar (' ');
+ if (nametp.value) XFree ((char *) nametp.value);
+ }
+ break;
+ case 0: /* normal */
+ print_text_field (dpy, NULL, &machtp, "%s");
putchar (' ');
putchar (' ');
+ break;
}
if (machtp.value) XFree ((char *) machtp.value);
- if (verbose) {
+ if (style == 1) { /* long */
if (XGetWMIconName (dpy, w, &tp)) {
- print_text_field (dpy, " Icon Name: ", &tp);
+ print_text_field (dpy, " Icon Name: ", &tp, "%s");
if (tp.value) XFree ((char *) tp.value);
}
}
@@ -197,7 +219,7 @@
/*
* do the command
*/
- if (verbose) {
+ if (style == 1) { /* long */
printf (" Command: ");
}
for (i = 0; i < cliargc && charsleft > 0; ) {
@@ -214,7 +236,7 @@
/*
* do trailer information
*/
- if (verbose) {
+ if (style == 1) { /* long */
XClassHint clh;
if (XGetClassHint (dpy, w, &clh)) {
printf (" Instance/Class: %s/%s",
@@ -228,7 +250,7 @@
}
static void
-print_text_field(Display *dpy, char *s, XTextProperty *tp)
+print_text_field(Display *dpy, char *s, XTextProperty *tp, char *format)
{
if (tp->encoding == None || tp->format == 0) {
printf ("''");
@@ -237,7 +259,7 @@
if (s) printf ("%s", s);
if (tp->encoding == XA_STRING && tp->format == 8) {
- printf ("%s", tp->value ? (char *) tp->value : Nil);
+ printf (format, tp->value ? (char *) tp->value : Nil);
} else {
unknown (dpy, tp->encoding, tp->format);
}
diff -urN xlsclients-1.0.1/xlsclients.man xlsclients-1.0.1-p/xlsclients.man
--- xlsclients-1.0.1/xlsclients.man 2004-04-23 21:54:58.000000000 +0200
+++ xlsclients-1.0.1-p/xlsclients.man 2007-04-30 22:25:32.366874665 +0200
@@ -30,7 +30,7 @@
xlsclients - list client applications running on a display
.SH SYNOPSIS
.B "xlsclients"
-[-display \fIdisplayname\fP] [-a] [-l] [-m maxcmdlen]
+[-display \fIdisplayname\fP] [-a] [-l] [-p] [-m maxcmdlen]
.SH DESCRIPTION
.PP
.I Xlsclients
@@ -51,6 +51,10 @@
and class hints in addition to the machine name and command string shown in
the default format.
.TP 8
+.B \-p
+List in ps-style format, giving a header, the window id, machine name,
+window name and command string.
+.TP 8
.B \-m \fImaxcmdlen\fP
This option specifies the maximum number of characters in a command to
print out. The default is 10000.
More information about the xorg
mailing list