2023-07-10 09:53:00 +00:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import St from 'gi://St';
|
2019-03-20 16:46:12 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import * as PanelMenu from '../panelMenu.js';
|
2019-03-20 16:46:12 +00:00
|
|
|
|
|
|
|
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 13:06:53 +00:00
|
|
|
primary: {
|
2023-08-06 22:34:20 +00:00
|
|
|
name: _('Single Click'),
|
2019-06-29 13:06:53 +00:00
|
|
|
icon: 'pointer-primary-click-symbolic',
|
2019-08-20 21:43:54 +00:00
|
|
|
type: Clutter.PointerA11yDwellClickType.PRIMARY,
|
2019-06-29 13:06:53 +00:00
|
|
|
},
|
|
|
|
double: {
|
2023-08-06 22:34:20 +00:00
|
|
|
name: _('Double Click'),
|
2019-06-29 13:06:53 +00:00
|
|
|
icon: 'pointer-double-click-symbolic',
|
2019-08-20 21:43:54 +00:00
|
|
|
type: Clutter.PointerA11yDwellClickType.DOUBLE,
|
2019-06-29 13:06:53 +00:00
|
|
|
},
|
|
|
|
drag: {
|
2023-08-06 22:34:20 +00:00
|
|
|
name: _('Drag'),
|
2019-06-29 13:06:53 +00:00
|
|
|
icon: 'pointer-drag-symbolic',
|
2019-08-20 21:43:54 +00:00
|
|
|
type: Clutter.PointerA11yDwellClickType.DRAG,
|
2019-06-29 13:06:53 +00:00
|
|
|
},
|
2019-03-20 16:46:12 +00:00
|
|
|
secondary: {
|
2023-08-06 22:34:20 +00:00
|
|
|
name: _('Secondary Click'),
|
2019-06-29 13:06:53 +00:00
|
|
|
icon: 'pointer-secondary-click-symbolic',
|
2019-08-20 21:43:54 +00:00
|
|
|
type: Clutter.PointerA11yDwellClickType.SECONDARY,
|
|
|
|
},
|
2019-03-20 16:46:12 +00:00
|
|
|
};
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const DwellClickIndicator = GObject.registerClass(
|
2019-03-20 16:46:12 +00:00
|
|
|
class DwellClickIndicator extends PanelMenu.Button {
|
|
|
|
_init() {
|
2023-08-06 22:34:20 +00:00
|
|
|
super._init(0.5, _('Dwell Click'));
|
2019-03-20 16:46:12 +00:00
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
this._icon = new St.Icon({
|
|
|
|
style_class: 'system-status-icon',
|
|
|
|
icon_name: 'pointer-primary-click-symbolic',
|
|
|
|
});
|
2021-02-01 11:15:00 +00:00
|
|
|
this.add_child(this._icon);
|
2019-03-20 16:46:12 +00:00
|
|
|
|
2023-08-06 22:40:20 +00:00
|
|
|
this._a11ySettings = new Gio.Settings({schema_id: MOUSE_A11Y_SCHEMA});
|
2022-02-07 14:14:06 +00: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 16:46:12 +00:00
|
|
|
|
2019-10-05 10:35:21 +00: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 16:46:12 +00: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 19:38:51 +00:00
|
|
|
this._a11ySettings.get_boolean(KEY_DWELL_CLICK_ENABLED) &&
|
2023-08-07 00:51:19 +00:00
|
|
|
this._a11ySettings.get_string(KEY_DWELL_MODE) === DWELL_MODE_WINDOW;
|
2019-03-20 16:46:12 +00:00
|
|
|
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_addDwellAction(mode) {
|
|
|
|
this.menu.addAction(mode.name, this._setClickType.bind(this, mode), mode.icon);
|
|
|
|
}
|
|
|
|
|
2019-01-31 13:43:52 +00:00
|
|
|
_updateClickType(manager, clickType) {
|
2019-03-20 16:46:12 +00:00
|
|
|
for (let mode in DWELL_CLICK_MODES) {
|
2023-08-07 00:51:19 +00:00
|
|
|
if (DWELL_CLICK_MODES[mode].type === clickType)
|
2019-03-20 16:46:12 +00:00
|
|
|
this._icon.icon_name = DWELL_CLICK_MODES[mode].icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setClickType(mode) {
|
2019-10-05 10:35:21 +00:00
|
|
|
this._seat.set_pointer_a11y_dwell_click_type(mode.type);
|
2019-03-20 16:46:12 +00:00
|
|
|
this._icon.icon_name = mode.icon;
|
|
|
|
}
|
|
|
|
});
|