Changeset 1250
- Timestamp:
- Mar 31, 2009, 12:37:37 AM (9 years ago)
- Location:
- trunk/xdotool
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/xdotool/CHANGELIST
r1109 r1250 1 20090126: 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 1 12 20080720: 2 13 * Add 'getmouselocation' which ouputs the coordinate of the mouse cursor and -
trunk/xdotool/Makefile
r1106 r1250 1 1 PREFIX?=/usr/local 2 INSTALLBIN =$(PREFIX)/bin3 INSTALLMAN =$(PREFIX)/man2 INSTALLBIN?=$(PREFIX)/bin 3 INSTALLMAN?=$(PREFIX)/man 4 4 5 5 WARNFLAGS+=-pedantic -Wall -W -Wundef \ -
trunk/xdotool/debian/changelog
r1195 r1250 1 xdotool (200 80720-2~pre1) UNRELEASED; urgency=low1 xdotool (20090126-1~pre1) UNRELEASED; urgency=low 2 2 3 * (NOT RELEASED YET) New upstream release 3 4 * updated my e-mail address 4 5 5 -- Daniel Kahn Gillmor <dkg@fifthhorseman.net> Tue, 06 Jan 2009 11:23:33 -05006 -- Daniel Kahn Gillmor <dkg@fifthhorseman.net> Tue, 31 Mar 2009 00:35:06 -0400 6 7 7 8 xdotool (20080720-1) unstable; urgency=low -
trunk/xdotool/xdo.c
r1105 r1250 1 1 /* xdo library 2 2 * 3 * $Id: xdo.c 1954 2008-07-16 23:21:28Z jordansissel $3 * $Id: xdo.c 2158 2009-01-26 11:05:03Z jordansissel $ 4 4 * 5 5 * - getwindowfocus contributed by Lee Pumphret … … 36 36 int *window_list_size); 37 37 38 static int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, int **keys, int *nkeys); 38 static int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, 39 charcodemap_t **keys, int *nkeys); 39 40 static int _xdo_keysequence_do(xdo_t *xdo, char *keyseq, int pressed); 40 41 static int _xdo_regex_match_window(xdo_t *xdo, Window window, int flags, regex_t *re); … … 47 48 48 49 /* context-free functions */ 49 char _keysym_to_char(char *keysym);50 static char _keysym_to_char(const char *keysym); 50 51 51 52 xdo_t* xdo_new(char *display_name) { … … 562 563 shiftcode = _xdo_get_shiftcode_if_needed(xdo, key); 563 564 564 if (shiftcode )565 if (shiftcode > 0) 565 566 XTestFakeKeyEvent(xdo->xdpy, shiftcode, True, CurrentTime); 566 567 XTestFakeKeyEvent(xdo->xdpy, keycode, True, CurrentTime); 567 568 XTestFakeKeyEvent(xdo->xdpy, keycode, False, CurrentTime); 568 if (shiftcode )569 if (shiftcode > 0) 569 570 XTestFakeKeyEvent(xdo->xdpy, shiftcode, False, CurrentTime); 570 571 … … 578 579 int _xdo_keysequence_do(xdo_t *xdo, char *keyseq, int pressed) { 579 580 int ret = 0; 580 int *keys = NULL;581 int nkeys ;581 charcodemap_t *keys = NULL; 582 int nkeys = 0; 582 583 int i; 584 KeyCode shiftcode; 583 585 584 586 if (_xdo_keysequence_to_keycode_list(xdo, keyseq, &keys, &nkeys) == False) { … … 587 589 } 588 590 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 */ 589 593 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); 591 603 } 592 604 … … 616 628 int ret = 0; 617 629 int unused_revert_ret; 630 618 631 ret = XGetInputFocus(xdo->xdpy, window_ret, &unused_revert_ret); 619 632 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. */ 639 int 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); 620 676 } 621 677 … … 685 741 686 742 /* context-free functions */ 687 char _keysym_to_char(c har *keysym) {743 char _keysym_to_char(const char *keysym) { 688 744 int i; 689 745 … … 719 775 } 720 776 721 /* foo */722 777 if (!XQueryTree(xdo->xdpy, window, &dummy, &dummy, &children, &nchildren)) 723 778 return; … … 739 794 } 740 795 741 int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, int **keys, int *nkeys) { 796 int _xdo_keysequence_to_keycode_list(xdo_t *xdo, char *keyseq, 797 charcodemap_t **keys, int *nkeys) { 742 798 char *tokctx = NULL; 743 799 const char *tok = NULL; 744 800 char *strptr = NULL; 745 801 int i; 802 KeyCode shift_keycode; 746 803 747 804 /* Array of keys to press, in order given by keyseq */ … … 754 811 } 755 812 756 *keys = malloc(keys_size * sizeof(int)); 813 shift_keycode = XKeysymToKeycode(xdo->xdpy, XStringToKeysym("Shift_L")); 814 815 *keys = malloc(keys_size * sizeof(KeyCode)); 757 816 strptr = strdup(keyseq); 758 817 while ((tok = strtok_r(strptr, "+", &tokctx)) != NULL) { 759 int keysym; 818 KeySym sym; 819 KeyCode key; 820 760 821 if (strptr != NULL) 761 822 strptr = NULL; … … 767 828 tok = symbol_map[i + 1]; 768 829 769 keysym = XStringToKeysym(tok);770 if ( keysym == NoSymbol) {830 sym = XStringToKeysym(tok); 831 if (sym == NoSymbol) { 771 832 fprintf(stderr, "(symbol) No such key name '%s'. Ignoring it.\n", tok); 772 833 continue; 773 834 } 774 835 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) { 778 845 fprintf(stderr, "No such key '%s'. Ignoring it.\n", tok); 779 846 continue; … … 783 850 if (*nkeys == keys_size) { 784 851 keys_size *= 2; 785 *keys = realloc(*keys, keys_size );852 *keys = realloc(*keys, keys_size * sizeof(KeyCode)); 786 853 } 787 854 } -
trunk/xdotool/xdo.h
r1105 r1250 3 3 * - include this if you have code that uses xdo 4 4 * 5 * $Id: xdo.h 1947 2008-06-16 03:41:25Z jordansissel $5 * $Id: xdo.h 2158 2009-01-26 11:05:03Z jordansissel $ 6 6 */ 7 7 … … 64 64 int xdo_window_raise(xdo_t *xdo, Window wid); 65 65 int xdo_window_get_focus(xdo_t *xdo, Window *window_ret); 66 int xdo_window_sane_get_focus(xdo_t *xdo, Window *window_ret); 66 67 int xdo_window_activate(xdo_t *xdo, Window wid); 67 68 -
trunk/xdotool/xdotool.c
r1109 r1250 3 3 * command line interface to the xdo library 4 4 * 5 * $Id: xdotool.c 1956 2008-07-20 20:40:17Z jordansissel $5 * $Id: xdotool.c 2158 2009-01-26 11:05:03Z jordansissel $ 6 6 * 7 7 * getwindowfocus contributed by Lee Pumphret … … 137 137 } 138 138 139 int cmd_help(int argc, char **args) {139 int cmd_help(int unused_argc, char **unused_args) { 140 140 int i; 141 141 printf("Available commands:\n"); … … 325 325 326 326 if (argc != 3) { 327 printf("usage: %s wid x y\n", cmd);327 fprintf(stderr, "usage: %s wid x y\n", cmd); 328 328 return 1; 329 329 } … … 346 346 347 347 if (argc != 1) { 348 printf("usage: %s wid\n", cmd);348 fprintf(stderr, "usage: %s wid\n", cmd); 349 349 return 1; 350 350 } … … 365 365 366 366 if (argc != 1) { 367 printf("usage: %s wid\n", cmd);367 fprintf(stderr, "usage: %s wid\n", cmd); 368 368 return 1; 369 369 } … … 383 383 384 384 if (argc != 1) { 385 printf("usage: %s wid\n", cmd);385 fprintf(stderr, "usage: %s wid\n", cmd); 386 386 return 1; 387 387 } … … 426 426 427 427 if (argc != 3) { 428 printf("usage: %s wid width height\n", cmd);428 fprintf(stderr, "usage: %s wid width height\n", cmd); 429 429 return 1; 430 430 } … … 515 515 char *cmd = *args; argc--; args++; 516 516 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 } 523 532 524 533 if (ret) { … … 537 546 538 547 if (argc != 0) { 539 printf("usage: %s\n", cmd);548 fprintf(stderr, "usage: %s\n", cmd); 540 549 return 1; 541 550 } … … 548 557 window_print(wid); 549 558 } 559 560 return ret; 550 561 } 551 562 … … 574 585 575 586 if (argc != 1) { 576 printf("usage: %s wid\n", cmd);587 fprintf(stderr, "usage: %s wid\n", cmd); 577 588 return 1; 578 589 } … … 591 602 592 603 if (argc != 1) { 593 printf("usage: %s num_desktops\n", cmd);604 fprintf(stderr, "usage: %s num_desktops\n", cmd); 594 605 return 1; 595 606 } … … 606 617 607 618 if (argc != 0) { 608 printf("usage: %s\n", cmd);619 fprintf(stderr, "usage: %s\n", cmd); 609 620 return 1; 610 621 } … … 621 632 622 633 if (argc != 1) { 623 printf("usage: %s desktop\n", cmd);634 fprintf(stderr, "usage: %s desktop\n", cmd); 624 635 return 1; 625 636 } … … 636 647 637 648 if (argc != 0) { 638 printf("usage: %s\n", cmd);649 fprintf(stderr, "usage: %s\n", cmd); 639 650 return 1; 640 651 } … … 651 662 652 663 if (argc != 2) { 653 printf("usage: %s <window> <desktop>\n", cmd);664 fprintf(stderr, "usage: %s <window> <desktop>\n", cmd); 654 665 return 1; 655 666 } … … 668 679 669 680 if (argc != 1) { 670 printf("usage: %s <window>\n", cmd);681 fprintf(stderr, "usage: %s <window>\n", cmd); 671 682 return 1; 672 683 } -
trunk/xdotool/xdotool.pod
r1195 r1250 103 103 The default options are C<--title --name --class> 104 104 105 =item B<getwindowfocus> 106 107 Prints the window id of the currently focused window 105 =item B<getwindowfocus> [-f] 106 107 Prints the window id of the currently focused window. 108 109 If the current window has no WM_CLASS property, we assume it is not a normal 110 top-level window and traverse up the parents until we find a window with a 111 WM_CLASS set and return that window id. 112 113 If you really want the window currently having focus and don't care if it has a 114 WM_CLASS setting, then use 'getwindowfocus -f' 108 115 109 116 =item B<windowsize> [options] windowid width height
Note: See TracChangeset
for help on using the changeset viewer.