Extension event loop in Gnome 3.10 vs 3.14

I wrote this accessibility extension:

Which works in Gnome Shell v3.14 and v3.16, but not in v3.10. It shows only the initial state of the keyboard modifiers after i restarted it and never updated after that.

Here is the full code:

const St = imports.gi.St; const Mainloop = imports.mainloop; const Main = imports.ui.main; const Gdk = imports.gi.Gdk let button, label, keymap; function _update() { let symbols = "⇧⇬⋀βŒ₯β‘ β—†βŒ˜βŽ‡"; let state = keymap.get_modifier_state(); label.text = " "; for (var i=0; i<=8; i++ ) { if (state & 1<<i) { label.text += symbols[i]; } else { //label.text += ""; } } label.text += " "; } function init() { button = new St.Bin({ style_class: 'panel-button', reactive: false, can_focus: false, x_fill: true, y_fill: false, track_hover: false }); label = new St.Label({ style_class: "state-label", text: "" }); button.set_child(label); keymap = Gdk.Keymap.get_default(); keymap.connect('state_changed', _update ); Mainloop.timeout_add(1000, _update ); } function enable() { Main.panel._rightBox.insert_child_at_index(button, 0); } function disable() { Main.panel._rightBox.remove_child(button); } 

Debugging attempt, I changed the code to show (status indicator + counter)

 let c,button, label, keymap; c=0; function _update() { Gtk.main_iteration_do(false); c++; let symbols = "⇧⇬⋀βŒ₯β‘ β—†βŒ˜βŽ‡"; //let keymap = Gdk.Keymap.get_default() let state = keymap.get_modifier_state(); label.text = " "; for (var i=0; i<=8; i++ ) { if (state & 1<<i) { label.text += symbols[i]; } else { //label.text += ""; } } label.text += " "+c+" "; return true; } 

I can confirm this:

  • keymap.connect('state_changed', _update ); this signal never rises
  • timeout callback works well Label
  • updated and shows the initial state and increment counter

So, I think there is something with the event loop, as it does not pull to update the state or not process its events.

Could you show me the way to fix this and what is the difference between v3.10 and v3.14?

+5
source share

Source: https://habr.com/ru/post/1235884/


All Articles