Bug 7474

Summary: XmuClientWindow chooses the wrong window
Product: xorg Reporter: Mark Tiefenbruck <mark>
Component: Lib/XmuAssignee: Jeremy Huddleston Sequoia <jeremyhu>
Status: RESOLVED INVALID QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: high CC: tomi
Version: unspecifiedKeywords: patch
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard: 2011BRB_Reviewed
i915 platform: i915 features:
Attachments:
Description Flags
patch to libXmu-1.0.2/src/ClientWin.c none

Description Mark Tiefenbruck 2006-07-09 22:39:36 UTC
In ClientWin.c, TryChildren() calls XQueryTree and returns the first window in
the list with a WM_STATE property set. However, XQueryTree returns a list of
children that "are listed in current stacking order, from bottom-most (first) to
top-most (last)." Thus, when a window contains more than one client,
XmuClientWindow returns the bottom-most one. This affects the behavior of tools
like xprop in fluxbox and probably ion, pekwm, etc. I've tested the following
patch, and it fixes the behavior:

--- oldClientWin.c      2006-07-10 00:26:04.000000000 -0500
+++ ClientWin.c 2006-07-10 00:09:26.000000000 -0500
@@ -82,18 +82,18 @@

     if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren))
        return 0;
-    for (i = 0; !inf && (i < nchildren); i++) {
+    for (i = nchildren; !inf && i; i--) {
        data = NULL;
-       XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False,
+       XGetWindowProperty(dpy, children[i-1], WM_STATE, 0, 0, False,
                           AnyPropertyType, &type, &format, &nitems,
                           &after, &data);
        if (data)
            XFree(data);
        if (type)
-           inf = children[i];
+           inf = children[i-1];
     }
-    for (i = 0; !inf && (i < nchildren); i++)
-       inf = TryChildren(dpy, children[i], WM_STATE);
+    for (i = nchildren; !inf && i; i--)
+       inf = TryChildren(dpy, children[i-1], WM_STATE);
     if (children)
        XFree(children);
     return inf;
Comment 1 Mark Tiefenbruck 2006-07-29 01:08:30 UTC
Created attachment 6392 [details] [review]
patch to libXmu-1.0.2/src/ClientWin.c

It seems that somewhere between here and the file, the number of spaces on each
line changes. Thus, the patch doesn't apply easily. I'm attaching a copy, in
case you don't feel like figuring out why. I also accidentally came upon a page
confirming that this causes problems for Ion, too.
Comment 2 Daniel Stone 2007-02-27 01:32:53 UTC
Sorry about the phenomenal bug spam, guys.  Adding xorg-team@ to the QA contact so bugs don't get lost in future.
Comment 3 Jeremy Huddleston Sequoia 2011-10-02 13:27:23 UTC
You say that it "affects the behavior of tools like xprop in fluxbox" ... how 
does it affect their behavior.  Why does the ordering of the list matter?  
Other tools may expect the current ordering.
Comment 4 Mark Tiefenbruck 2011-10-02 13:51:19 UTC
The window managers I listed implement tabbed windows: multiple client windows are children of the same parent window. `xprop' allows a user to click on a window and get a list of its window properties. However, under the current implementation, `xprop' returns the information for a client window other than the one being clicked on (specifically, the least recently used client in the parent window).

While it's possible that other tools rely on the current order, I've been using this patch for five years and haven't noticed any side effects.
Comment 5 Jeremy Huddleston Sequoia 2011-10-02 23:02:47 UTC
Would you mind sending it to xorg-devel for review?
Comment 6 Adam Jackson 2018-06-12 19:08:59 UTC
Mass closure: This bug has been untouched for more than six years, and is not
obviously still valid. Please reopen this bug or file a new report if you continue to experience issues with current releases.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.