Re: [hackers] [lsw] [PATCH] Improve compliance with our coding style

2022-07-03 Thread Quentin Rameau
Hi Tom,

> - if (!XGetTextProperty(dpy, win, &prop, netwmname) || prop.nitems == 0)
> - if (!XGetWMName(dpy, win, &prop) || prop.nitems == 0)
> + if (!XGetTextProperty(dpy, win, &prop, netwmname) || !prop.nitems) {
> + if (!XGetWMName(dpy, win, &prop) || !prop.nitems)
>   return "";
> + }

I disagree with “!prop.nitems” change.
Variable nitems isn't a boolean value,
it's a numeral counter,
so better testing explicitly against 0.

Rest of the changes are good though, thanks. :)



[hackers] [lsw] [PATCH] Improve compliance with our coding style

2022-07-03 Thread Tom Schwindl
---
 lsw.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lsw.c b/lsw.c
index c7d5171e7383..497d6d262c1f 100644
--- a/lsw.c
+++ b/lsw.c
@@ -8,7 +8,7 @@
 static Atom netwmname;
 static Display *dpy;
 
-char *
+static char *
 getname(Window win)
 {
static char buf[BUFSIZ];
@@ -16,22 +16,23 @@ getname(Window win)
int n;
XTextProperty prop;
 
-   if (!XGetTextProperty(dpy, win, &prop, netwmname) || prop.nitems == 0)
-   if (!XGetWMName(dpy, win, &prop) || prop.nitems == 0)
+   if (!XGetTextProperty(dpy, win, &prop, netwmname) || !prop.nitems) {
+   if (!XGetWMName(dpy, win, &prop) || !prop.nitems)
return "";
+   }
if (!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) {
-   strncpy(buf, list[0], sizeof buf);
+   strncpy(buf, list[0], sizeof(buf));
XFreeStringList(list);
} else {
-   strncpy(buf, (char *)prop.value, sizeof buf);
+   strncpy(buf, (char *)prop.value, sizeof(buf));
}
XFree(prop.value);
-   buf[sizeof buf - 1] = '\0';
+   buf[sizeof(buf) - 1] = '\0';
 
return buf;
 }
 
-void
+static void
 lsw(Window win)
 {
unsigned int n;
@@ -40,10 +41,11 @@ lsw(Window win)
 
if (!XQueryTree(dpy, win, &dw, &dw, &wins, &n) || !n)
return;
-   for (w = &wins[n-1]; w >= &wins[0]; w--)
+   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);
 }
 
-- 
2.37.0