Changeset 1248 for branches


Ignore:
Timestamp:
Mar 31, 2009, 12:33:39 AM (9 years ago)
Author:
dkg
Message:

[svn-upgrade] Integrating new upstream version, xdotool (20090126)

Location:
branches/upstream/xdotool/current
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/upstream/xdotool/current/CHANGELIST

    r1107 r1248  
     120090126:
     2  * Change the default behavior of 'getwindowfocus' to get the first
     3    ancestor-or-self window that has WM_CLASS set. WM_CLASS will be set on
     4    (all?) top-level windows and it's possible that the currently focused window
     5    according to X is not a top-level window. To use the previous behavior, use
     6    'getwindowfocus -f'
     7  * Make 'xdotool key at' work correctly. 'at' is usually Shift+2, for example.
     8    Now all shifted characters should work, but I've only tested on a US
     9    keyboard.
     10  * Minor Makefile fixes for package maintainers.
     11
    11220080720:
    213  * Add 'getmouselocation' which ouputs the coordinate of the mouse cursor and
  • branches/upstream/xdotool/current/Makefile

    r1103 r1248  
    11PREFIX?=/usr/local
    2 INSTALLBIN=$(PREFIX)/bin
    3 INSTALLMAN=$(PREFIX)/man
     2INSTALLBIN?=$(PREFIX)/bin
     3INSTALLMAN?=$(PREFIX)/man
    44
    55WARNFLAGS+=-pedantic -Wall -W -Wundef \
  • branches/upstream/xdotool/current/xdo.c

    r1103 r1248  
    11/* xdo library
    22 *
    3  * $Id: xdo.c 1954 2008-07-16 23:21:28Z jordansissel $
     3 * $Id: xdo.c 2158 2009-01-26 11:05:03Z jordansissel $
    44 *
    55 * - getwindowfocus contributed by Lee Pumphret
     
    3636                                   int *window_list_size);
    3737
    38 static int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, int **keys, int *nkeys);
     38static int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq,
     39                                            charcodemap_t **keys, int *nkeys);
    3940static int _xdo_keysequence_do(xdo_t *xdo, char *keyseq, int pressed);
    4041static int _xdo_regex_match_window(xdo_t *xdo, Window window, int flags, regex_t *re);
     
    4748
    4849/* context-free functions */
    49 char _keysym_to_char(char *keysym);
     50static char _keysym_to_char(const char *keysym);
    5051
    5152xdo_t* xdo_new(char *display_name) {
     
    562563    shiftcode = _xdo_get_shiftcode_if_needed(xdo, key);
    563564
    564     if (shiftcode)
     565    if (shiftcode > 0)
    565566      XTestFakeKeyEvent(xdo->xdpy, shiftcode, True, CurrentTime);
    566567    XTestFakeKeyEvent(xdo->xdpy, keycode, True, CurrentTime);
    567568    XTestFakeKeyEvent(xdo->xdpy, keycode, False, CurrentTime);
    568     if (shiftcode)
     569    if (shiftcode > 0)
    569570      XTestFakeKeyEvent(xdo->xdpy, shiftcode, False, CurrentTime);
    570571
     
    578579int _xdo_keysequence_do(xdo_t *xdo, char *keyseq, int pressed) {
    579580  int ret = 0;
    580   int *keys = NULL;
    581   int nkeys;
     581  charcodemap_t *keys = NULL;
     582  int nkeys = 0;
    582583  int i;
     584  KeyCode shiftcode;
    583585
    584586  if (_xdo_keysequence_to_keycode_list(xdo, keyseq, &keys, &nkeys) == False) {
     
    587589  }
    588590
     591  /* If shiftcode is necessary, send shift before the key if pressed is true,
     592   * otherwise release the shift key after the key is released */
    589593  for (i = 0; i < nkeys; i++) {
    590     ret += !XTestFakeKeyEvent(xdo->xdpy, keys[i], pressed, CurrentTime);
     594    shiftcode = keys[i].shift;
     595
     596    if (pressed > 0 && shiftcode)
     597      ret += !XTestFakeKeyEvent(xdo->xdpy, shiftcode, pressed, CurrentTime);
     598
     599    ret += !XTestFakeKeyEvent(xdo->xdpy, keys[i].code, pressed, CurrentTime);
     600
     601    if (pressed == 0 && shiftcode)
     602      ret += !XTestFakeKeyEvent(xdo->xdpy, shiftcode, pressed, CurrentTime);
    591603  }
    592604
     
    616628  int ret = 0;
    617629  int unused_revert_ret;
     630
    618631  ret = XGetInputFocus(xdo->xdpy, window_ret, &unused_revert_ret);
    619632  return _is_success("XGetInputFocus", ret == 0);
     633}
     634
     635/* Like xdo_window_get_focus, but return the first ancestor-or-self window
     636 * having a property of WM_CLASS. This allows you to get the "real" or
     637 * top-level-ish window having focus rather than something you may
     638 * not expect to be the window having focused. */
     639int xdo_window_sane_get_focus(xdo_t *xdo, Window *window_ret) {
     640  int done = 0;
     641  Window w;
     642  XClassHint classhint;
     643
     644  /* for XQueryTree */
     645  Window dummy, parent, *children = NULL;
     646  unsigned int nchildren;
     647
     648  xdo_window_get_focus(xdo, &w);
     649
     650  while (!done) {
     651    Status s;
     652    s = XGetClassHint(xdo->xdpy, w, &classhint);
     653    //fprintf(stderr, "%d\n", s);
     654
     655    if (s == 0) {
     656      /* Error. This window doesn't have a class hint */
     657      //fprintf(stderr, "no class on: %d\n", w);
     658      XQueryTree(xdo->xdpy, w, &dummy, &parent, &children, &nchildren);
     659
     660      /* Don't care about the children, but we still need to free them */
     661      if (children != NULL)
     662        XFree(children);
     663      //fprintf(stderr, "parent: %d\n", parent);
     664      w = parent;
     665    } else {
     666      /* Must XFree the class and name items. */
     667      XFree(classhint.res_class);
     668      XFree(classhint.res_name);
     669
     670      done = 1;
     671    }
     672  }
     673
     674  *window_ret = w;
     675  return _is_success("xdo_window_sane_get_focus", w == 0);
    620676}
    621677
     
    685741
    686742/* context-free functions */
    687 char _keysym_to_char(char *keysym) {
     743char _keysym_to_char(const char *keysym) {
    688744  int i;
    689745
     
    719775  }
    720776
    721   /* foo */
    722777  if (!XQueryTree(xdo->xdpy, window, &dummy, &dummy, &children, &nchildren))
    723778    return;
     
    739794}
    740795
    741 int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, int **keys, int *nkeys) {
     796int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq,
     797                                     charcodemap_t **keys, int *nkeys) {
    742798  char *tokctx = NULL;
    743799  const char *tok = NULL;
    744800  char *strptr = NULL;
    745801  int i;
     802  KeyCode shift_keycode;
    746803 
    747804  /* Array of keys to press, in order given by keyseq */
     
    754811  }
    755812
    756   *keys = malloc(keys_size * sizeof(int));
     813  shift_keycode = XKeysymToKeycode(xdo->xdpy, XStringToKeysym("Shift_L"));
     814
     815  *keys = malloc(keys_size * sizeof(KeyCode));
    757816  strptr = strdup(keyseq);
    758817  while ((tok = strtok_r(strptr, "+", &tokctx)) != NULL) {
    759     int keysym;
     818    KeySym sym;
     819    KeyCode key;
     820
    760821    if (strptr != NULL)
    761822      strptr = NULL;
     
    767828        tok = symbol_map[i + 1];
    768829
    769     keysym = XStringToKeysym(tok);
    770     if (keysym == NoSymbol) {
     830    sym = XStringToKeysym(tok);
     831    if (sym == NoSymbol) {
    771832      fprintf(stderr, "(symbol) No such key name '%s'. Ignoring it.\n", tok);
    772833      continue;
    773834    }
    774835
    775     (*keys)[*nkeys] = XKeysymToKeycode(xdo->xdpy, keysym);
    776 
    777     if ((*keys)[*nkeys] == 0) {
     836    key = XKeysymToKeycode(xdo->xdpy, sym);
     837    (*keys)[*nkeys].code = key;
     838    if (XKeycodeToKeysym(xdo->xdpy, key, 0) == sym) {
     839      (*keys)[*nkeys].shift = 0;
     840    } else  {
     841      (*keys)[*nkeys].shift = shift_keycode;
     842    }
     843
     844    if ((*keys)[*nkeys].code == 0) {
    778845      fprintf(stderr, "No such key '%s'. Ignoring it.\n", tok);
    779846      continue;
     
    783850    if (*nkeys == keys_size) {
    784851      keys_size *= 2;
    785       *keys = realloc(*keys, keys_size);
     852      *keys = realloc(*keys, keys_size * sizeof(KeyCode));
    786853    }
    787854  }
  • branches/upstream/xdotool/current/xdo.h

    r1103 r1248  
    33 * - include this if you have code that uses xdo
    44 *
    5  * $Id: xdo.h 1947 2008-06-16 03:41:25Z jordansissel $
     5 * $Id: xdo.h 2158 2009-01-26 11:05:03Z jordansissel $
    66 */
    77
     
    6464int xdo_window_raise(xdo_t *xdo, Window wid);
    6565int xdo_window_get_focus(xdo_t *xdo, Window *window_ret);
     66int xdo_window_sane_get_focus(xdo_t *xdo, Window *window_ret);
    6667int xdo_window_activate(xdo_t *xdo, Window wid);
    6768
  • branches/upstream/xdotool/current/xdotool.c

    r1107 r1248  
    33 * command line interface to the xdo library
    44 *
    5  * $Id: xdotool.c 1956 2008-07-20 20:40:17Z jordansissel $
     5 * $Id: xdotool.c 2158 2009-01-26 11:05:03Z jordansissel $
    66 *
    77 * getwindowfocus contributed by Lee Pumphret
     
    137137}
    138138
    139 int cmd_help(int argc, char **args) {
     139int cmd_help(int unused_argc, char **unused_args) {
    140140  int i;
    141141  printf("Available commands:\n");
     
    325325
    326326  if (argc != 3) {
    327     printf("usage: %s wid x y\n", cmd);
     327    fprintf(stderr, "usage: %s wid x y\n", cmd);
    328328    return 1;
    329329  }
     
    346346
    347347  if (argc != 1) {
    348     printf("usage: %s wid\n", cmd);
     348    fprintf(stderr, "usage: %s wid\n", cmd);
    349349    return 1;
    350350  }
     
    365365
    366366  if (argc != 1) {
    367     printf("usage: %s wid\n", cmd);
     367    fprintf(stderr, "usage: %s wid\n", cmd);
    368368    return 1;
    369369  }
     
    383383
    384384  if (argc != 1) {
    385     printf("usage: %s wid\n", cmd);
     385    fprintf(stderr, "usage: %s wid\n", cmd);
    386386    return 1;
    387387   }
     
    426426
    427427  if (argc != 3) {
    428     printf("usage: %s wid width height\n", cmd);
     428    fprintf(stderr, "usage: %s wid width height\n", cmd);
    429429    return 1;
    430430  }
     
    515515  char *cmd = *args; argc--; args++;
    516516
    517   if (argc != 0) {
    518     printf("usage: %s\n", cmd);
    519     return 1;
    520   }
    521 
    522   ret = xdo_window_get_focus(xdo, &wid);
     517  if (argc > 1) {
     518    fprintf(stderr, "usage: %s -f\n", cmd);
     519    return 1;
     520  }
     521
     522  if (argc == 1) {
     523    if (!strcmp(args[0], "-f")) { /* -f was given */
     524      ret = xdo_window_get_focus(xdo, &wid);
     525    } else {
     526      fprintf(stderr, "usage: %s -f\n", cmd);
     527    }
     528  } else {
     529    /* No '-f' flag given, assume sane mode */
     530    ret = xdo_window_sane_get_focus(xdo, &wid);
     531  }
    523532
    524533  if (ret) {
     
    537546
    538547  if (argc != 0) {
    539     printf("usage: %s\n", cmd);
     548    fprintf(stderr, "usage: %s\n", cmd);
    540549    return 1;
    541550  }
     
    548557    window_print(wid);
    549558  }
     559
     560  return ret;
    550561}
    551562
     
    574585
    575586  if (argc != 1) {
    576     printf("usage: %s wid\n", cmd);
     587    fprintf(stderr, "usage: %s wid\n", cmd);
    577588    return 1;
    578589  }
     
    591602
    592603  if (argc != 1) {
    593     printf("usage: %s num_desktops\n", cmd);
     604    fprintf(stderr, "usage: %s num_desktops\n", cmd);
    594605    return 1;
    595606  }
     
    606617
    607618  if (argc != 0) {
    608     printf("usage: %s\n", cmd);
     619    fprintf(stderr, "usage: %s\n", cmd);
    609620    return 1;
    610621  }
     
    621632
    622633  if (argc != 1) {
    623     printf("usage: %s desktop\n", cmd);
     634    fprintf(stderr, "usage: %s desktop\n", cmd);
    624635    return 1;
    625636  }
     
    636647
    637648  if (argc != 0) {
    638     printf("usage: %s\n", cmd);
     649    fprintf(stderr, "usage: %s\n", cmd);
    639650    return 1;
    640651  }
     
    651662
    652663  if (argc != 2) {
    653     printf("usage: %s <window> <desktop>\n", cmd);
     664    fprintf(stderr, "usage: %s <window> <desktop>\n", cmd);
    654665    return 1;
    655666  }
     
    668679
    669680  if (argc != 1) {
    670     printf("usage: %s <window>\n", cmd);
     681    fprintf(stderr, "usage: %s <window>\n", cmd);
    671682    return 1;
    672683  }
  • branches/upstream/xdotool/current/xdotool.pod

    r1107 r1248  
    103103The default options are C<--title --name --class>
    104104
    105 =item B<getwindowfocus>
    106 
    107 Prints the window id of the currently focused window
     105=item B<getwindowfocus> [-f]
     106
     107Prints the window id of the currently focused window.
     108
     109If the current window has no WM_CLASS property, we assume it is not a normal
     110top-level window and traverse up the parents until we find a window with a
     111WM_CLASS set and return that window id.
     112
     113If you really want the window currently having focus and don't care if it has a
     114WM_CLASS setting, then use 'getwindowfocus -f'
    108115
    109116=item B<windowsize> [options] windowid width height
Note: See TracChangeset for help on using the changeset viewer.