Skip to content

Commit

Permalink
track-focus: print more information
Browse files Browse the repository at this point in the history
NB: This crashes easily

darcs-hash:20080820190455-a887e-6650d835b9ac227da20fbe1456e42817e9be13ee.gz
  • Loading branch information
thjaeger committed Aug 20, 2008
1 parent 4b5583c commit ade4d26
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 111 deletions.
5 changes: 1 addition & 4 deletions access/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
88 changes: 0 additions & 88 deletions access/get-comp.c

This file was deleted.

171 changes: 154 additions & 17 deletions access/track-focus.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,73 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "cspi/spi.h"
#include <cspi/spi.h>
#include <map>
#include <string>
#include <iostream>

// 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;
Expand Down Expand Up @@ -48,39 +110,35 @@ void pop(int x) {
}
}

std::map<int, std::string> focus_map;
std::map<int, Accessible *> 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");
if (app) {
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) {
Expand Down Expand Up @@ -132,3 +190,82 @@ int main (int argc, char **argv) {
SPI_event_main();
return SPI_exit();
}

#if 0
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cspi/spi.h>
#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
4 changes: 2 additions & 2 deletions fire.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ade4d26

Please sign in to comment.