Logo Search packages:      
Sourcecode: xdotool version File versions  Download package

int xdo_window_sane_get_focus ( const xdo_t xdo,
Window *  window_ret 

Like xdo_window_get_focus, but return the first ancestor-or-self window * having a property of WM_CLASS. This allows you to get the "real" or top-level-ish window having focus rather than something you may not expect to be the window having focused.

window_ret Pointer to a window where the currently-focused window will be stored.

Definition at line 982 of file xdo.c.

References xdo::xdpy.

  int done = 0;
  Window w;
  XClassHint classhint;

  /* for XQueryTree */
  Window dummy, parent, *children = NULL;
  unsigned int nchildren;

  xdo_window_get_focus(xdo, &w);

  while (!done) {
    Status s;
    s = XGetClassHint(xdo->xdpy, w, &classhint);
    //fprintf(stderr, "%d\n", s);

    if (s == 0) {
      /* Error. This window doesn't have a class hint */
      //fprintf(stderr, "no class on: %d\n", w);
      XQueryTree(xdo->xdpy, w, &dummy, &parent, &children, &nchildren);

      /* Don't care about the children, but we still need to free them */
      if (children != NULL)
      //fprintf(stderr, "parent: %d\n", parent);
      w = parent;
    } else {
      /* Must XFree the class and name items. */

      done = 1;

  *window_ret = w;
  return _is_success("xdo_window_sane_get_focus", w == 0);

Generated by  Doxygen 1.6.0   Back to index