Greetings,
I extensively use wmctrl, but it never worked reliably for me on all my
amd64 machines (specifically, the -l option didn't list all X clients
and the workspace number for sticky windows was clearly wrong).
I recently decided to have a look at the code and discovered that the
root cause is the XGetWindowProperty() function, whose semantics is a
bit tricky: 32-bit data is stored in long format, so the actual number
of 32-bit returned elements should take into account the value of
sizeof(long) to ensure portability to 64 bit systems.
I tried the enclosed patch and verified it's working flawlessly,
restoring the expected behavior for "wmctrl -l" without impacting on the
other command's functions (however, I didn't test it on a 32bit
architecture, in order to confirm that no regressions have been
introduced).
After a quick search on the net I found out that both Debian and Gentoo
uses the same approach (see e.g. [1]).
Even if this is something that should be submitted upstream, it seems
that the author is not reacting for maintenance, so I'm proposing the
patch to ports@ since I consider it a significant usability improvement.
All the best
[1]
https://gitweb.gentoo.org/repo/gentoo.git/tree/x11-misc/wmctrl/files/amd64-Xlib.patch
--
Alessandro De Laurenzis
[mailto:jus...@atlantide.mooo.com]
Web: http://www.atlantide.mooo.com
LinkedIn: http://it.linkedin.com/in/delaurenzis
Index: Makefile
===================================================================
RCS file: /cvs/ports/x11/wmctrl/Makefile,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 Makefile
--- Makefile 12 Jul 2019 20:51:24 -0000 1.21
+++ Makefile 9 May 2020 13:55:11 -0000
@@ -2,7 +2,7 @@
COMMENT= interact with an EWMH/NetWM window manager
DISTNAME= wmctrl-1.07
-REVISION= 8
+REVISION= 9
CATEGORIES= x11
MASTER_SITES= ${HOMEPAGE}
Index: patches/patch-main_c
===================================================================
RCS file: patches/patch-main_c
diff -N patches/patch-main_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-main_c 9 May 2020 13:55:11 -0000
@@ -0,0 +1,24 @@
+$OpenBSD$
+
+Index: main.c
+--- main.c.orig
++++ main.c
+@@ -1439,8 +1439,17 @@ static gchar *get_property (Display *disp, Window win,
+ return NULL;
+ }
+
+- /* null terminate the result to make string handling easier */
++ /* null terminate the result to make string handling easier
++ *
++ * Note: Data returned in 32 bit format is stored as long, so
++ * the actual number of 32 bit elements should be calculated
++ * considering the sizeof(long) value, to ensure portability
++ * to 64 bit systems
++ */
+ tmp_size = (ret_format / 8) * ret_nitems;
++ if (ret_format == 32) {
++ tmp_size *= sizeof(long) / 4;
++ }
+ ret = g_malloc(tmp_size + 1);
+ memcpy(ret, ret_prop, tmp_size);
+ ret[tmp_size] = '\0';