Я написал (очень простое) расширение gnome-shell для переключения режима фокусировки (gnome-shell 3.10 в Ubuntu 14.04). Расширение доступно на github; Я жду, чтобы отправить его, потому что у него есть очень неприятная ошибка --- которую я не могу понять и поэтому исправить.
Расширение основано на стандартном расширении примера, код настолько прост, что я могу полностью вставить его сюда, хотя для работы ему нужны файлы значков.
const FFM_VARIANT='sloppy';
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const ExtensionUtils = imports.misc.extensionUtils;
const Meta = ExtensionUtils.getCurrentExtension();
const Util = imports.misc.util;
const Gio = imports.gi.Gio;
let text, button, icon_f, icon_c, wm_prefs;
var focus;
const FFM=0;
const CTF=1;
function _set_FFM() {
focus = FFM;
button.set_child(icon_f);
wm_prefs.set_string('focus-mode', FFM_VARIANT);
}
function _set_CTF() {
focus = CTF;
button.set_child(icon_c);
wm_prefs.set_string('focus-mode', 'click');
}
function _hideMsg() {
if (text) {
Main.uiGroup.remove_actor(text);
text = null;
}
}
function _showMsg(what) {
if (!text) {
text = new St.Label({ style_class: 'msg-label', text: what });
Main.uiGroup.add_actor(text);
}
text.opacity = 255;
let monitor = Main.layoutManager.primaryMonitor;
text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
Math.floor(monitor.height / 2 - text.height / 2));
Tweener.addTween(text,
{ opacity: 0,
time: 3,
transition: 'easeOutQuad',
onComplete: _hideMsg });
}
function _switch() {
_hideMsg();
if (focus == FFM) {
_showMsg("Setting Click-to-focus");
_set_CTF();
} else {
_showMsg("Setting Focus-follow-mouse");
_set_FFM();
}
}
function init() {
button = new St.Bin({ style_class: 'panel-button',
reactive: true,
can_focus: true,
x_fill: true,
y_fill: false,
track_hover: true });
Gtk.IconTheme.get_default().append_search_path(Meta.dir.get_child('icons').get_path());
icon_f = new St.Icon({ icon_name: 'fmode',
style_class: 'system-status-icon' });
icon_c = new St.Icon({ icon_name: 'cmode',
style_class: 'system-status-icon' });
wm_prefs=new Gio.Settings({schema: 'org.gnome.desktop.wm.preferences'});
}
function enable() {
// start with the current mode --- sync icon and internal state.
what=wm_prefs.get_string('focus-mode');
if (what == 'click') {
_set_CTF();
} else { // sloppy or mouse
_set_FFM();
}
button.connect('button-press-event', _switch);
Main.panel._rightBox.insert_child_at_index(button, 0);
}
function disable() {
Main.panel._rightBox.remove_child(button);
}
...и он отлично работает, переключая режим фокусировки при каждом нажатии, меняя значок и делая то, что должен делать.
Но если я блокирую и разблокирую экран, расширение пазлов перестает работать. При нажатии на значок просто отображается то же сообщение (застрявшее в режиме фокусировки, в котором оно было до блокировки). Включение и отключение расширения возобновит правильную работу.
Разве блокировка-разблокировка не должна быть прозрачной для приложений? А если нет, есть какой-то хук, который я могу использовать, чтобы принудительно включить / отключить разблокировку экрана? Зеркало не показывает никаких ошибок, и нигде не видно журналов.