From ade4d265599a5f76a92885ff3017a0445bb03cb9 Mon Sep 17 00:00:00 2001 From: Tom Jaeger Date: Wed, 20 Aug 2008 15:04:55 -0400 Subject: [PATCH] track-focus: print more information NB: This crashes easily darcs-hash:20080820190455-a887e-6650d835b9ac227da20fbe1456e42817e9be13ee.gz --- access/Makefile | 5 +- access/get-comp.c | 88 ---------------------- access/track-focus.c | 171 ++++++++++++++++++++++++++++++++++++++----- fire.h | 4 +- 4 files changed, 157 insertions(+), 111 deletions(-) delete mode 100644 access/get-comp.c diff --git a/access/Makefile b/access/Makefile index b9a2134a..4ea9c6b0 100644 --- a/access/Makefile +++ b/access/Makefile @@ -12,10 +12,7 @@ # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -all: track-focus get-comp +all: track-focus track-focus: track-focus.c g++ -Wall `pkg-config gtkmm-2.4 gthread-2.0 cspi-1.0 --cflags --libs` track-focus.c -o track-focus - -get-comp: get-comp.c - g++ -Wall `pkg-config gtkmm-2.4 gthread-2.0 cspi-1.0 --cflags --libs` get-comp.c -o get-comp diff --git a/access/get-comp.c b/access/get-comp.c deleted file mode 100644 index dfe0f751..00000000 --- a/access/get-comp.c +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -#include "cspi/spi.h" - -Display *dpy; -#define ROOT (DefaultRootWindow(dpy)) - -void print_acc(Accessible *obj) { - const char *name = Accessible_getName(obj); - const char *role = Accessible_getRoleName(obj); - printf("%s: %s", role, name); - AccessibleComponent *comp = Accessible_getComponent(obj); - if (comp) { - long int xx, yy, ww, hh; - AccessibleComponent_getExtents(comp, &xx, &yy, &ww, &hh, SPI_COORD_TYPE_SCREEN); - printf(" (%ld, %ld, %ld, %ld)", xx, yy, ww, hh); - } - printf("\n"); -} - -Accessible *get_inf(Accessible *cur, int x, int y) { - for (;;) { - AccessibleComponent *comp = Accessible_getComponent(cur); - if (!comp) - return cur; - Accessible *child = AccessibleComponent_getAccessibleAtPoint(comp, x, y, SPI_COORD_TYPE_SCREEN); - if (!child) - return cur; - cur = child; - } -} - -void get_comp(int x, int y) { - Accessible *desktop = SPI_getDesktop(0); - int n = Accessible_getChildCount(desktop); - for (int i = 0; i < n; i++) { - Accessible *app = Accessible_getChildAtIndex(desktop, i); - if (strcmp(Accessible_getName(app),"Firefox")) - continue; - print_acc(app); - int m = Accessible_getChildCount(app); - for (int j = 0; j < m; j++) { - Accessible *child = Accessible_getChildAtIndex(app, j); - Accessible *inf = get_inf(child, x, y); - if (inf != child) - print_acc(inf); - } - } -}; - -void print_subtree(Accessible *cur, int indent) { - for (int i = 0; i < indent; i++) - printf(" "); - print_acc(cur); - int n = Accessible_getChildCount(cur); - for (int i = 0; i < n; i++) - print_subtree(Accessible_getChildAtIndex(cur, i), indent+2); -} - -void print_tree() { - print_subtree(SPI_getDesktop(0), 0); -} - -int main(int argc, char *argv[]) { - dpy = XOpenDisplay(NULL); - - if (SPI_init()) { - printf("Error: AT-SPI not available\n"); - exit(EXIT_FAILURE); - }; - if (1) { - print_tree(); - exit(EXIT_SUCCESS); - } - - XGrabButton(dpy, 1, AnyModifier, ROOT, True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); - - XEvent ev; - while (1) { - XNextEvent(dpy, &ev); - if (ev.type == ButtonPress) { - XAllowEvents(dpy, ReplayPointer, ev.xbutton.time); - get_comp(ev.xbutton.x, ev.xbutton.y); - } - } -} diff --git a/access/track-focus.c b/access/track-focus.c index a58b26ff..dc559507 100644 --- a/access/track-focus.c +++ b/access/track-focus.c @@ -16,11 +16,73 @@ #include #include #include -#include "cspi/spi.h" +#include #include #include #include +// TODO: Leaks memory +void print_acc(Accessible *obj) { + char *name = Accessible_getName(obj); + char *role = Accessible_getRoleName(obj); + printf("%s: %s", role, name); + SPI_freeString(name); + SPI_freeString(role); + + AccessibleComponent *comp = Accessible_getComponent(obj); + if (comp) { + long int xx, yy, ww, hh; + AccessibleComponent_getExtents(comp, &xx, &yy, &ww, &hh, SPI_COORD_TYPE_SCREEN); + printf(" (%ld, %ld, %ld, %ld)", xx, yy, ww, hh); + } + AccessibleValue *value = Accessible_getValue(obj); + if (value) { + printf(" (value: %f [%f - %f])\n", + AccessibleValue_getCurrentValue(value), + AccessibleValue_getMinimumValue(value), + AccessibleValue_getMaximumValue(value)); + } + AccessibleDocument *doc = Accessible_getDocument(obj); + if (doc) { + AccessibleAttributeSet *attrs = AccessibleDocument_getAttributes(doc); + printf(" (document"); + if (attrs->len != 0) { + printf(": "); + for (int i = 0;;) { + printf("%s", attrs->attributes[i]); + if (++i >= attrs->len) + break; + printf(", "); + } + } + printf(")"); + + } + AccessibleAction *act = Accessible_getAction(obj); + if (act) { + long n = AccessibleAction_getNActions(act); + printf(" (action"); + if (n != 0) { + printf(": "); + for (int i = 0;;) { + printf("%s", AccessibleAction_getName(act, i)); + if (++i >= n) + break; + printf(", "); + } + } + printf(")"); + + } + AccessibleHypertext *hyp = Accessible_getHypertext(obj); + if (hyp) { + AccessibleText *txt = Accessible_getText(obj); + printf(" (link: %s)", AccessibleText_getText(txt, 0, AccessibleText_getCharacterCount(txt))); + + } + printf("\n"); +} + static AccessibleEventListener *focus_listener; static AccessibleEventListener *activate_listener; static AccessibleEventListener *deactivate_listener; @@ -48,28 +110,28 @@ void pop(int x) { } } -std::map focus_map; +std::map focus_map; void print() { - static std::string last = ""; - std::string now = length ? focus_map[stack[0]] : "no app or app doesn't support at-spi"; - if (now == "") - now = "no focus information about this app yet"; - if (now == last) + if (!length) { + printf("no app or app doesn't support at-spi\n"); + return; + } + Accessible *acc = focus_map[stack[0]]; + if (!acc) { + printf("no focus information about this app yet"); return; - last = now; - std::cout << now << std::endl; + } + print_acc(acc); } void on_focus(const AccessibleEvent *event, void *user_data) { if (!event->source) return; AccessibleApplication *app = Accessible_getHostApplication(event->source); - char *name = Accessible_getName(event->source); - char *role = Accessible_getRoleName(event->source); - if (app && name && role) { + if (app) { int app_id = AccessibleApplication_getID(app); - focus_map[app_id] = std::string(name) + "(" + std::string(role) + ")"; + focus_map[app_id] = event->source; push(app_id); print(); } else printf("something went wrong\n"); @@ -77,10 +139,6 @@ void on_focus(const AccessibleEvent *event, void *user_data) { AccessibleApplication_unref(app); AccessibleApplication_unref(app); } - if (name) - SPI_freeString(name); - if (role) - SPI_freeString(role); } void on_activate(const AccessibleEvent *event, void *user_data) { @@ -132,3 +190,82 @@ int main (int argc, char **argv) { SPI_event_main(); return SPI_exit(); } + +#if 0 +#include +#include +#include +#include +#include +#include "print.h" + +Display *dpy; +#define ROOT (DefaultRootWindow(dpy)) + +Accessible *get_inf(Accessible *cur, int x, int y) { + for (;;) { + AccessibleComponent *comp = Accessible_getComponent(cur); + if (!comp) + return cur; + Accessible *child = AccessibleComponent_getAccessibleAtPoint(comp, x, y, SPI_COORD_TYPE_SCREEN); + if (!child) + return cur; + cur = child; + } +} + +void get_comp(int x, int y) { + Accessible *desktop = SPI_getDesktop(0); + int n = Accessible_getChildCount(desktop); + for (int i = 0; i < n; i++) { + Accessible *app = Accessible_getChildAtIndex(desktop, i); + if (strcmp(Accessible_getName(app),"Firefox")) + continue; + print_acc(app); + int m = Accessible_getChildCount(app); + for (int j = 0; j < m; j++) { + Accessible *child = Accessible_getChildAtIndex(app, j); + Accessible *inf = get_inf(child, x, y); + if (inf != child) + print_acc(inf); + } + } +}; + +void print_subtree(Accessible *cur, int indent) { + for (int i = 0; i < indent; i++) + printf(" "); + print_acc(cur); + int n = Accessible_getChildCount(cur); + for (int i = 0; i < n; i++) + print_subtree(Accessible_getChildAtIndex(cur, i), indent+2); +} + +void print_tree() { + print_subtree(SPI_getDesktop(0), 0); +} + +int main(int argc, char *argv[]) { + dpy = XOpenDisplay(NULL); + + if (SPI_init()) { + printf("Error: AT-SPI not available\n"); + exit(EXIT_FAILURE); + }; + if (1) { + print_tree(); + exit(EXIT_SUCCESS); + } + + XGrabButton(dpy, 1, AnyModifier, ROOT, True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None); + + XEvent ev; + while (1) { + XNextEvent(dpy, &ev); + if (ev.type == ButtonPress) { + XAllowEvents(dpy, ReplayPointer, ev.xbutton.time); + get_comp(ev.xbutton.x, ev.xbutton.y); + } + } +} +#endif diff --git a/fire.h b/fire.h index a5e5fb44..66a5164d 100644 --- a/fire.h +++ b/fire.h @@ -28,8 +28,8 @@ class Fire : public Trace, public Timeout { virtual void draw(Point p, Point q); void add_point(float, float); - virtual void start_() { leftover = 0; } - virtual void end_() { set_timeout(200); } + virtual void start_() { if (remove_timeout()) timeout(); leftover = 0; } + virtual void end_() { set_timeout(250); } virtual void timeout(); public: Fire();