2019-01-31 09:07:06 -05:00
|
|
|
/* exported DwellClickIndicator */
|
2019-03-20 12:46:12 -04:00
|
|
|
const { Clutter, Gio, GLib, GObject, St } = imports.gi;
|
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
|
|
|
const MOUSE_A11Y_SCHEMA = 'org.gnome.desktop.a11y.mouse';
|
|
|
|
const KEY_DWELL_CLICK_ENABLED = 'dwell-click-enabled';
|
|
|
|
const KEY_DWELL_MODE = 'dwell-mode';
|
|
|
|
const DWELL_MODE_WINDOW = 'window';
|
|
|
|
const DWELL_CLICK_MODES = {
|
2019-06-29 09:06:53 -04:00
|
|
|
primary: {
|
|
|
|
name: _("Single Click"),
|
|
|
|
icon: 'pointer-primary-click-symbolic',
|
2019-08-20 17:43:54 -04:00
|
|
|
type: Clutter.PointerA11yDwellClickType.PRIMARY,
|
2019-06-29 09:06:53 -04:00
|
|
|
},
|
|
|
|
double: {
|
|
|
|
name: _("Double Click"),
|
|
|
|
icon: 'pointer-double-click-symbolic',
|
2019-08-20 17:43:54 -04:00
|
|
|
type: Clutter.PointerA11yDwellClickType.DOUBLE,
|
2019-06-29 09:06:53 -04:00
|
|
|
},
|
|
|
|
drag: {
|
|
|
|
name: _("Drag"),
|
|
|
|
icon: 'pointer-drag-symbolic',
|
2019-08-20 17:43:54 -04:00
|
|
|
type: Clutter.PointerA11yDwellClickType.DRAG,
|
2019-06-29 09:06:53 -04:00
|
|
|
},
|
2019-03-20 12:46:12 -04:00
|
|
|
secondary: {
|
2019-06-29 09:06:53 -04:00
|
|
|
name: _("Secondary Click"),
|
|
|
|
icon: 'pointer-secondary-click-symbolic',
|
2019-08-20 17:43:54 -04:00
|
|
|
type: Clutter.PointerA11yDwellClickType.SECONDARY,
|
|
|
|
},
|
2019-03-20 12:46:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
var DwellClickIndicator = GObject.registerClass(
|
|
|
|
class DwellClickIndicator extends PanelMenu.Button {
|
|
|
|
_init() {
|
2019-06-14 14:58:50 -04:00
|
|
|
super._init(0.5, _("Dwell Click"));
|
2019-03-20 12:46:12 -04:00
|
|
|
|
|
|
|
this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
|
|
|
|
this._icon = new St.Icon({ style_class: 'system-status-icon',
|
|
|
|
icon_name: 'pointer-primary-click-symbolic' });
|
|
|
|
this._hbox.add_child(this._icon);
|
|
|
|
this._hbox.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
|
|
|
|
|
|
|
this.add_child(this._hbox);
|
|
|
|
|
|
|
|
this._a11ySettings = new Gio.Settings({ schema_id: MOUSE_A11Y_SCHEMA });
|
2019-01-29 19:18:24 -05:00
|
|
|
this._a11ySettings.connect(`changed::${KEY_DWELL_CLICK_ENABLED}`, this._syncMenuVisibility.bind(this));
|
|
|
|
this._a11ySettings.connect(`changed::${KEY_DWELL_MODE}`, this._syncMenuVisibility.bind(this));
|
2019-03-20 12:46:12 -04:00
|
|
|
|
2019-10-05 06:35:21 -04:00
|
|
|
this._seat = Clutter.get_default_backend().get_default_seat();
|
|
|
|
this._seat.connect('ptr-a11y-dwell-click-type-changed', this._updateClickType.bind(this));
|
2019-03-20 12:46:12 -04:00
|
|
|
|
|
|
|
this._addDwellAction(DWELL_CLICK_MODES.primary);
|
|
|
|
this._addDwellAction(DWELL_CLICK_MODES.double);
|
|
|
|
this._addDwellAction(DWELL_CLICK_MODES.drag);
|
|
|
|
this._addDwellAction(DWELL_CLICK_MODES.secondary);
|
|
|
|
|
|
|
|
this._setClickType(DWELL_CLICK_MODES.primary);
|
|
|
|
this._syncMenuVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
_syncMenuVisibility() {
|
|
|
|
this.visible =
|
2019-08-19 15:38:51 -04:00
|
|
|
this._a11ySettings.get_boolean(KEY_DWELL_CLICK_ENABLED) &&
|
|
|
|
this._a11ySettings.get_string(KEY_DWELL_MODE) == DWELL_MODE_WINDOW;
|
2019-03-20 12:46:12 -04:00
|
|
|
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_addDwellAction(mode) {
|
|
|
|
this.menu.addAction(mode.name, this._setClickType.bind(this, mode), mode.icon);
|
|
|
|
}
|
|
|
|
|
2019-01-31 08:43:52 -05:00
|
|
|
_updateClickType(manager, clickType) {
|
2019-03-20 12:46:12 -04:00
|
|
|
for (let mode in DWELL_CLICK_MODES) {
|
2019-01-31 08:43:52 -05:00
|
|
|
if (DWELL_CLICK_MODES[mode].type == clickType)
|
2019-03-20 12:46:12 -04:00
|
|
|
this._icon.icon_name = DWELL_CLICK_MODES[mode].icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setClickType(mode) {
|
2019-10-05 06:35:21 -04:00
|
|
|
this._seat.set_pointer_a11y_dwell_click_type(mode.type);
|
2019-03-20 12:46:12 -04:00
|
|
|
this._icon.icon_name = mode.icon;
|
|
|
|
}
|
|
|
|
});
|