/** Returns the client window under the specified root subwindow. */
  private static long findClientWindow(long window) {
    if (XlibUtil.isTrueToplevelWindow(window)) {
      return window;
    }

    Set<Long> children = XlibUtil.getChildWindows(window);
    for (Long child : children) {
      long win = findClientWindow(child);
      if (win != 0) {
        return win;
      }
    }

    return 0;
  }