문제

I am developing a gnome shell extension for Gnome 3.4. My extension needs to capture the window events if any editable text is focused in/out.

global.stage.connect('notify::focus-key', Lang.bind(this, this._myHandler));

did not work for me.

Here is a simple use-case: whenever user clicks on firefox search box, I want my handler to be run.

Thanks for any help,

도움이 되었습니까?

해결책

Selcuk pointed me this question, so in order to have this answered here for future search.

The library that would allow to set a global-desktop listener to focus changes is libatspi (the client-side library of GNOME accessibility framework). You could use directly C, pyatspi2 (python manual bindings) or gobject-introspection based bindings (ie, javascript). So a small javascript program that prints name:role_name of the focused object each time the focus change would be:

const Atspi = imports.gi.Atspi;

function onChanged (event) {
    log(event.source.get_name() + ',' + event.source.get_role_name());
}

Atspi.init();
let atspiListener = Atspi.EventListener.new(onChanged);
atspiListener.register("object:state-changed:focused");
Atspi.event_main();

In any case, for code examples, you could take a look to recently added focus/caret tracking feature on gnome-shell magnifier (small-size example using javascript) or Orca (GNOME screen reader, big-size example, uses pyatspi2).

libatspi reference here: https://developer.gnome.org/libatspi/

gnome-shell magnifier code here: https://git.gnome.org/browse/gnome-shell/tree/js/ui/magnifier.js

다른 팁

you cannot do this.

application text entry widgets do not fall under the scope of the window manager, so you cannot access their contents, or whether or not they received focus.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top