2016-06-22 17:57:12 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Atk, Clutter, GDesktopEnums, Gio,
|
|
|
|
GLib, GObject, Gtk, Meta, Rsvg, St } = imports.gi;
|
2016-06-22 17:57:12 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
const Layout = imports.ui.layout;
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
const ACTIVE_COLOR = "#729fcf";
|
|
|
|
|
|
|
|
const LTR = 0;
|
|
|
|
const RTL = 1;
|
|
|
|
|
|
|
|
const CW = 0;
|
|
|
|
const CCW = 1;
|
|
|
|
|
|
|
|
const UP = 0;
|
|
|
|
const DOWN = 1;
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var PadChooser = class {
|
|
|
|
constructor(device, groupDevices) {
|
2017-02-13 14:12:28 +00:00
|
|
|
this.actor = new St.Button({ style_class: 'pad-chooser-button',
|
|
|
|
toggle_mode: true,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
this.currentDevice = device;
|
|
|
|
this._padChooserMenu = null;
|
|
|
|
|
|
|
|
let arrow = new St.Icon({ style_class: 'popup-menu-arrow',
|
|
|
|
icon_name: 'pan-down-symbolic',
|
|
|
|
accessible_role: Atk.Role.ARROW });
|
|
|
|
this.actor.set_child(arrow);
|
|
|
|
this._ensureMenu(groupDevices);
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
this.actor.connect('clicked', actor => {
|
2017-02-13 14:12:28 +00:00
|
|
|
if (actor.get_checked()) {
|
|
|
|
if (this._padChooserMenu != null)
|
|
|
|
this._padChooserMenu.open(true);
|
|
|
|
else
|
|
|
|
this.set_checked(false);
|
|
|
|
} else {
|
|
|
|
this._padChooserMenu.close(true);
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:12:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_ensureMenu(devices) {
|
2017-02-13 14:12:28 +00:00
|
|
|
this._padChooserMenu = new PopupMenu.PopupMenu(this.actor, 0.5, St.Side.TOP);
|
2017-10-31 00:38:18 +00:00
|
|
|
this._padChooserMenu.connect('menu-closed', () => {
|
|
|
|
this.actor.set_checked(false);
|
|
|
|
});
|
2017-02-13 14:12:28 +00:00
|
|
|
this._padChooserMenu.actor.hide();
|
|
|
|
Main.uiGroup.add_actor(this._padChooserMenu.actor);
|
|
|
|
|
|
|
|
for (let i = 0; i < devices.length; i++) {
|
|
|
|
let device = devices[i];
|
|
|
|
if (device == this.currentDevice)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
this._padChooserMenu.addAction(device.get_device_name(), () => {
|
|
|
|
this.emit('pad-selected', device);
|
|
|
|
});
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:12:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDestroy() {
|
2017-02-13 14:12:28 +00:00
|
|
|
this._padChooserMenu.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:12:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
update(devices) {
|
2017-02-13 14:12:28 +00:00
|
|
|
if (this._padChooserMenu)
|
|
|
|
this._padChooserMenu.actor.destroy();
|
|
|
|
this.actor.set_checked(false);
|
|
|
|
this._ensureMenu(devices);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:12:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2017-02-13 14:12:28 +00:00
|
|
|
this.actor.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2017-02-13 14:12:28 +00:00
|
|
|
Signals.addSignalMethods(PadChooser.prototype);
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var KeybindingEntry = class {
|
|
|
|
constructor() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor = new St.Entry({ hint_text: _("New shortcut…"),
|
|
|
|
style: 'width: 10em' });
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('captured-event', this._onCapturedEvent.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onCapturedEvent(actor, event) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (event.type() != Clutter.EventType.KEY_PRESS)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
let str = Gtk.accelerator_name_with_keycode(null,
|
|
|
|
event.get_key_symbol(),
|
|
|
|
event.get_key_code(),
|
|
|
|
event.get_state());
|
|
|
|
this.actor.set_text(str);
|
|
|
|
this.emit('keybinding-edited', str);
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-06-22 17:57:12 +00:00
|
|
|
Signals.addSignalMethods(KeybindingEntry.prototype);
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var ActionComboBox = class {
|
|
|
|
constructor() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor = new St.Button({ style_class: 'button' });
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('clicked', this._onButtonClicked.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor.set_toggle_mode(true);
|
|
|
|
|
|
|
|
let boxLayout = new Clutter.BoxLayout({ orientation: Clutter.Orientation.HORIZONTAL,
|
|
|
|
spacing: 6 });
|
|
|
|
let box = new St.Widget({ layout_manager: boxLayout });
|
|
|
|
this.actor.set_child(box);
|
|
|
|
|
|
|
|
this._label = new St.Label({ style_class: 'combo-box-label' });
|
|
|
|
box.add_child(this._label)
|
|
|
|
|
|
|
|
let arrow = new St.Icon({ style_class: 'popup-menu-arrow',
|
|
|
|
icon_name: 'pan-down-symbolic',
|
|
|
|
accessible_role: Atk.Role.ARROW,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
box.add_child(arrow);
|
|
|
|
|
|
|
|
this._editMenu = new PopupMenu.PopupMenu(this.actor, 0, St.Side.TOP);
|
2017-10-31 00:38:18 +00:00
|
|
|
this._editMenu.connect('menu-closed', () => {
|
|
|
|
this.actor.set_checked(false);
|
|
|
|
});
|
2016-06-22 17:57:12 +00:00
|
|
|
this._editMenu.actor.hide();
|
|
|
|
Main.uiGroup.add_actor(this._editMenu.actor);
|
|
|
|
|
|
|
|
this._actionLabels = new Map();
|
|
|
|
this._actionLabels.set(GDesktopEnums.PadButtonAction.NONE, _("Application defined"));
|
|
|
|
this._actionLabels.set(GDesktopEnums.PadButtonAction.HELP, _("Show on-screen help"));
|
|
|
|
this._actionLabels.set(GDesktopEnums.PadButtonAction.SWITCH_MONITOR, _("Switch monitor"));
|
|
|
|
this._actionLabels.set(GDesktopEnums.PadButtonAction.KEYBINDING, _("Assign keystroke"));
|
|
|
|
|
2017-07-12 16:37:18 +00:00
|
|
|
this._buttonItems = [];
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
for (let [action, label] of this._actionLabels.entries()) {
|
|
|
|
let selectedAction = action;
|
2017-10-31 00:38:18 +00:00
|
|
|
let item = this._editMenu.addAction(label, () => {
|
|
|
|
this._onActionSelected(selectedAction);
|
|
|
|
});
|
2017-07-12 16:37:18 +00:00
|
|
|
|
|
|
|
/* These actions only apply to pad buttons */
|
|
|
|
if (selectedAction == GDesktopEnums.PadButtonAction.HELP ||
|
|
|
|
selectedAction == GDesktopEnums.PadButtonAction.SWITCH_MONITOR)
|
|
|
|
this._buttonItems.push(item);
|
2016-06-22 17:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setAction(GDesktopEnums.PadButtonAction.NONE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onActionSelected(action) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.setAction(action);
|
|
|
|
this.popdown();
|
|
|
|
this.emit('action-selected', action);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setAction(action) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._label.set_text(this._actionLabels.get(action));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
popup() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._editMenu.open(true);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
popdown() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._editMenu.close(true);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onButtonClicked() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this.actor.get_checked())
|
|
|
|
this.popup();
|
|
|
|
else
|
|
|
|
this.popdown();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-12 16:37:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setButtonActionsActive(active) {
|
2017-07-12 16:37:18 +00:00
|
|
|
this._buttonItems.forEach(item => { item.setSensitive(active); });
|
2016-06-22 17:57:12 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-06-22 17:57:12 +00:00
|
|
|
Signals.addSignalMethods(ActionComboBox.prototype);
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var ActionEditor = class {
|
|
|
|
constructor() {
|
2016-06-22 17:57:12 +00:00
|
|
|
let boxLayout = new Clutter.BoxLayout({ orientation: Clutter.Orientation.HORIZONTAL,
|
|
|
|
spacing: 12 });
|
|
|
|
|
|
|
|
this.actor = new St.Widget({ layout_manager: boxLayout });
|
|
|
|
|
|
|
|
this._actionComboBox = new ActionComboBox();
|
2017-12-02 00:27:35 +00:00
|
|
|
this._actionComboBox.connect('action-selected', this._onActionSelected.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor.add_actor(this._actionComboBox.actor);
|
|
|
|
|
|
|
|
this._keybindingEdit = new KeybindingEntry();
|
2017-12-02 00:27:35 +00:00
|
|
|
this._keybindingEdit.connect('keybinding-edited', this._onKeybindingEdited.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor.add_actor(this._keybindingEdit.actor);
|
|
|
|
|
|
|
|
this._doneButton = new St.Button({ label: _("Done"),
|
|
|
|
style_class: 'button',
|
|
|
|
x_expand: false});
|
2017-12-02 00:27:35 +00:00
|
|
|
this._doneButton.connect('clicked', this._onEditingDone.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor.add_actor(this._doneButton);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateKeybindingEntryState() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._currentAction == GDesktopEnums.PadButtonAction.KEYBINDING) {
|
|
|
|
this._keybindingEdit.actor.set_text(this._currentKeybinding);
|
|
|
|
this._keybindingEdit.actor.show();
|
|
|
|
this._keybindingEdit.actor.grab_key_focus();
|
|
|
|
} else {
|
|
|
|
this._keybindingEdit.actor.hide();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setSettings(settings, action) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._buttonSettings = settings;
|
|
|
|
|
|
|
|
this._currentAction = this._buttonSettings.get_enum('action');
|
|
|
|
this._currentKeybinding = this._buttonSettings.get_string('keybinding');
|
|
|
|
this._actionComboBox.setAction(this._currentAction);
|
|
|
|
this._updateKeybindingEntryState();
|
2017-07-12 16:37:18 +00:00
|
|
|
|
|
|
|
let isButton = (action == Meta.PadActionType.BUTTON);
|
|
|
|
this._actionComboBox.setButtonActionsActive(isButton);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
close() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._actionComboBox.popdown();
|
|
|
|
this.actor.hide();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onKeybindingEdited(entry, keybinding) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._currentKeybinding = keybinding;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onActionSelected(menu, action) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._currentAction = action;
|
|
|
|
this._updateKeybindingEntryState();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_storeSettings() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (!this._buttonSettings)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let keybinding = null;
|
|
|
|
|
|
|
|
if (this._currentAction == GDesktopEnums.PadButtonAction.KEYBINDING)
|
|
|
|
keybinding = this._currentKeybinding;
|
|
|
|
|
|
|
|
this._buttonSettings.set_enum('action', this._currentAction);
|
|
|
|
|
|
|
|
if (keybinding)
|
|
|
|
this._buttonSettings.set_string('keybinding', keybinding);
|
|
|
|
else
|
|
|
|
this._buttonSettings.reset('keybinding');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onEditingDone() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._storeSettings();
|
|
|
|
this.close();
|
|
|
|
this.emit('done');
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-06-22 17:57:12 +00:00
|
|
|
Signals.addSignalMethods(ActionEditor.prototype);
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var PadDiagram = GObject.registerClass({
|
2016-06-22 17:57:12 +00:00
|
|
|
Properties: { 'left-handed': GObject.ParamSpec.boolean('left-handed',
|
|
|
|
'left-handed', 'Left handed',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
false),
|
|
|
|
'image': GObject.ParamSpec.string('image', 'image', 'Image',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
null),
|
|
|
|
'editor-actor': GObject.ParamSpec.object('editor-actor',
|
|
|
|
'editor-actor',
|
|
|
|
'Editor actor',
|
|
|
|
GObject.ParamFlags.READWRITE |
|
|
|
|
GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
Clutter.Actor.$gtype) },
|
2017-10-31 01:23:39 +00:00
|
|
|
}, class PadDiagram extends St.DrawingArea {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(params) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/pad-osd.css');
|
|
|
|
let [success, css, etag] = file.load_contents(null);
|
2018-07-30 12:35:27 +00:00
|
|
|
if (css instanceof Uint8Array)
|
|
|
|
css = imports.byteArray.toString(css);
|
2017-07-05 22:05:22 +00:00
|
|
|
this._curEdited = null;
|
|
|
|
this._prevEdited = null;
|
2016-06-22 17:57:12 +00:00
|
|
|
this._css = css;
|
|
|
|
this._labels = [];
|
|
|
|
this._activeButtons = [];
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init(params);
|
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
get left_handed() {
|
|
|
|
return this._leftHanded;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
set left_handed(leftHanded) {
|
|
|
|
this._leftHanded = leftHanded;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
get image() {
|
|
|
|
return this._imagePath;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
set image(imagePath) {
|
|
|
|
let originalHandle = Rsvg.Handle.new_from_file(imagePath);
|
|
|
|
let dimensions = originalHandle.get_dimensions();
|
|
|
|
this._imageWidth = dimensions.width;
|
|
|
|
this._imageHeight = dimensions.height;
|
|
|
|
|
|
|
|
this._imagePath = imagePath;
|
|
|
|
this._handle = this._composeStyledDiagram();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
get editor_actor() {
|
|
|
|
return this._editorActor;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
set editor_actor(actor) {
|
|
|
|
actor.hide();
|
|
|
|
this._editorActor = actor;
|
|
|
|
this.add_actor(actor);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_wrappingSvgHeader() {
|
2016-06-22 17:57:12 +00:00
|
|
|
return ('<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +
|
|
|
|
'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" ' +
|
|
|
|
'xmlns:xi="http://www.w3.org/2001/XInclude" ' +
|
|
|
|
'width="' + this._imageWidth + '" height="' + this._imageHeight + '"> ' +
|
|
|
|
'<style type="text/css">');
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_wrappingSvgFooter() {
|
2016-06-22 17:57:12 +00:00
|
|
|
return ('</style>' +
|
|
|
|
'<xi:include href="' + this._imagePath + '" />' +
|
|
|
|
'</svg>');
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_cssString() {
|
2016-06-22 17:57:12 +00:00
|
|
|
let css = this._css;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._activeButtons.length; i++) {
|
|
|
|
let ch = String.fromCharCode('A'.charCodeAt() + this._activeButtons[i]);
|
|
|
|
css += ('.' + ch + ' { ' +
|
|
|
|
' stroke: ' + ACTIVE_COLOR + ' !important; ' +
|
|
|
|
' fill: ' + ACTIVE_COLOR + ' !important; ' +
|
|
|
|
'} ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return css;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_composeStyledDiagram() {
|
2016-06-22 17:57:12 +00:00
|
|
|
let svgData = '';
|
|
|
|
|
|
|
|
if (!GLib.file_test(this._imagePath, GLib.FileTest.EXISTS))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
svgData += this._wrappingSvgHeader();
|
|
|
|
svgData += this._cssString();
|
|
|
|
svgData += this._wrappingSvgFooter();
|
|
|
|
|
2019-04-26 11:03:42 +00:00
|
|
|
let istream = new Gio.MemoryInputStream();
|
|
|
|
istream.add_bytes(new GLib.Bytes(svgData));
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2019-04-26 11:03:42 +00:00
|
|
|
return Rsvg.Handle.new_from_stream_sync(istream,
|
|
|
|
Gio.File.new_for_path(this._imagePath),
|
|
|
|
0, null);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateDiagramScale() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._handle == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[this._actorWidth, this._actorHeight] = this.get_size();
|
|
|
|
let dimensions = this._handle.get_dimensions();
|
|
|
|
let scaleX = this._actorWidth / dimensions.width;
|
|
|
|
let scaleY = this._actorHeight / dimensions.height;
|
|
|
|
this._scale = Math.min(scaleX, scaleY);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_allocateChild(child, x, y, direction) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let [prefHeight, natHeight] = child.get_preferred_height(-1);
|
|
|
|
let [prefWidth, natWidth] = child.get_preferred_width(natHeight);
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
|
|
|
if (direction == LTR) {
|
|
|
|
childBox.x1 = x;
|
|
|
|
childBox.x2 = x + natWidth;
|
|
|
|
} else {
|
|
|
|
childBox.x1 = x - natWidth;
|
|
|
|
childBox.x2 = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
childBox.y1 = y - natHeight / 2;
|
|
|
|
childBox.y2 = y + natHeight / 2;
|
|
|
|
child.allocate(childBox, 0);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_allocate(box, flags) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super.vfunc_allocate(box, flags);
|
2016-06-22 17:57:12 +00:00
|
|
|
this._updateDiagramScale();
|
|
|
|
|
|
|
|
for (let i = 0; i < this._labels.length; i++) {
|
|
|
|
let [label, action, idx, dir] = this._labels[i];
|
|
|
|
let [found, x, y, arrangement] = this.getLabelCoords(action, idx, dir);
|
|
|
|
this._allocateChild(label, x, y, arrangement);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._editorActor && this._curEdited) {
|
|
|
|
let [label, action, idx, dir] = this._curEdited;
|
|
|
|
let [found, x, y, arrangement] = this.getLabelCoords(action, idx, dir);
|
|
|
|
this._allocateChild(this._editorActor, x, y, arrangement);
|
|
|
|
}
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_repaint() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._handle == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._scale == null)
|
|
|
|
this._updateDiagramScale();
|
|
|
|
|
|
|
|
let [width, height] = this.get_surface_size();
|
|
|
|
let dimensions = this._handle.get_dimensions();
|
|
|
|
let cr = this.get_context();
|
|
|
|
|
|
|
|
cr.save();
|
|
|
|
cr.translate(width/2, height/2);
|
|
|
|
cr.scale(this._scale, this._scale);
|
|
|
|
if (this._leftHanded)
|
|
|
|
cr.rotate(Math.PI);
|
|
|
|
cr.translate(-dimensions.width/2, -dimensions.height/2);
|
|
|
|
this._handle.render_cairo(cr);
|
|
|
|
cr.restore();
|
|
|
|
cr.$dispose();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_transformPoint(x, y) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._handle == null || this._scale == null)
|
|
|
|
return [x, y];
|
|
|
|
|
|
|
|
// I miss Cairo.Matrix
|
|
|
|
let dimensions = this._handle.get_dimensions();
|
|
|
|
x = x * this._scale + this._actorWidth / 2 - dimensions.width / 2 * this._scale;
|
|
|
|
y = y * this._scale + this._actorHeight / 2 - dimensions.height / 2 * this._scale;;
|
|
|
|
return [Math.round(x), Math.round(y)];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getItemLabelCoords(labelName, leaderName) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._handle == null)
|
|
|
|
return [false];
|
|
|
|
|
|
|
|
let leaderPos, leaderSize, pos;
|
|
|
|
let found, direction;
|
|
|
|
|
|
|
|
[found, pos] = this._handle.get_position_sub('#' + labelName);
|
|
|
|
if (!found)
|
|
|
|
return [false];
|
|
|
|
|
|
|
|
[found, leaderPos] = this._handle.get_position_sub('#' + leaderName);
|
|
|
|
[found, leaderSize] = this._handle.get_dimensions_sub('#' + leaderName);
|
|
|
|
if (!found)
|
|
|
|
return [false];
|
|
|
|
|
|
|
|
if (pos.x > leaderPos.x + leaderSize.width)
|
|
|
|
direction = LTR;
|
|
|
|
else
|
|
|
|
direction = RTL;
|
|
|
|
|
|
|
|
if (this._leftHanded) {
|
|
|
|
direction = 1 - direction;
|
|
|
|
pos.x = this._imageWidth - pos.x;
|
|
|
|
pos.y = this._imageHeight - pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
let [x, y] = this._transformPoint(pos.x, pos.y)
|
|
|
|
|
|
|
|
return [true, x, y, direction];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getButtonLabelCoords(button) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let ch = String.fromCharCode('A'.charCodeAt() + button);
|
|
|
|
let labelName = 'Label' + ch;
|
|
|
|
let leaderName = 'Leader' + ch;
|
|
|
|
|
|
|
|
return this._getItemLabelCoords(labelName, leaderName);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getRingLabelCoords(number, dir) {
|
2017-08-03 19:59:26 +00:00
|
|
|
let numStr = number > 0 ? (number + 1).toString() : '';
|
2016-06-22 17:57:12 +00:00
|
|
|
let dirStr = dir == CW ? 'CW' : 'CCW';
|
|
|
|
let labelName = 'LabelRing' + numStr + dirStr;
|
|
|
|
let leaderName = 'LeaderRing' + numStr + dirStr;
|
|
|
|
|
|
|
|
return this._getItemLabelCoords(labelName, leaderName);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getStripLabelCoords(number, dir) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let numStr = number > 0 ? (number + 1).toString() : '';
|
|
|
|
let dirStr = dir == UP ? 'Up' : 'Down';
|
|
|
|
let labelName = 'LabelStrip' + numStr + dirStr;
|
|
|
|
let leaderName = 'LeaderStrip' + numStr + dirStr;
|
|
|
|
|
|
|
|
return this._getItemLabelCoords(labelName, leaderName);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
getLabelCoords(action, idx, dir) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (action == Meta.PadActionType.BUTTON)
|
|
|
|
return this.getButtonLabelCoords(idx);
|
|
|
|
else if (action == Meta.PadActionType.RING)
|
|
|
|
return this.getRingLabelCoords(idx, dir);
|
|
|
|
else if (action == Meta.PadActionType.STRIP)
|
|
|
|
return this.getStripLabelCoords(idx, dir);
|
|
|
|
|
|
|
|
return [false];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_invalidateSvg() {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._handle == null)
|
|
|
|
return;
|
|
|
|
this._handle = this._composeStyledDiagram();
|
|
|
|
this.queue_repaint();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
activateButton(button) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._activeButtons.push(button);
|
|
|
|
this._invalidateSvg();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
deactivateButton(button) {
|
2016-06-22 17:57:12 +00:00
|
|
|
for (let i = 0; i < this._activeButtons.length; i++) {
|
|
|
|
if (this._activeButtons[i] == button)
|
|
|
|
this._activeButtons.splice(i, 1);
|
|
|
|
}
|
|
|
|
this._invalidateSvg();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
addLabel(label, type, idx, dir) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._labels.push([label, type, idx, dir]);
|
|
|
|
this.add_actor(label);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_applyLabel(label, action, idx, dir, str) {
|
2017-07-05 22:03:12 +00:00
|
|
|
if (str != null) {
|
|
|
|
label.set_text(str);
|
|
|
|
|
|
|
|
let [found, x, y, arrangement] = this.getLabelCoords(action, idx, dir);
|
|
|
|
this._allocateChild(label, x, y, arrangement);
|
|
|
|
}
|
|
|
|
label.show();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-05 22:03:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
stopEdition(continues, str) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._editorActor.hide();
|
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
if (this._prevEdited) {
|
|
|
|
let [label, action, idx, dir] = this._prevEdited;
|
|
|
|
this._applyLabel(label, action, idx, dir, str);
|
|
|
|
this._prevEdited = null;
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._curEdited) {
|
|
|
|
let [label, action, idx, dir] = this._curEdited;
|
2017-07-05 22:03:12 +00:00
|
|
|
this._applyLabel(label, action, idx, dir, str);
|
2017-07-05 22:05:22 +00:00
|
|
|
if (continues)
|
|
|
|
this._prevEdited = this._curEdited;
|
2016-06-22 17:57:12 +00:00
|
|
|
this._curEdited = null;
|
|
|
|
}
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
startEdition(action, idx, dir) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let editedLabel;
|
2017-07-05 22:05:22 +00:00
|
|
|
|
|
|
|
if (this._curEdited)
|
|
|
|
return;
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < this._labels.length; i++) {
|
|
|
|
let [label, itemAction, itemIdx, itemDir] = this._labels[i];
|
|
|
|
if (action == itemAction && idx == itemIdx && dir == itemDir) {
|
|
|
|
this._curEdited = this._labels[i];
|
|
|
|
editedLabel = label;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._curEdited == null)
|
|
|
|
return;
|
|
|
|
let [found] = this.getLabelCoords(action, idx, dir);
|
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
this._editorActor.show();
|
|
|
|
editedLabel.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var PadOsd = class {
|
|
|
|
constructor(padDevice, settings, imagePath, editionMode, monitorIndex) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.padDevice = padDevice;
|
2017-02-13 10:55:24 +00:00
|
|
|
this._groupPads = [ padDevice ];
|
2016-06-22 17:57:12 +00:00
|
|
|
this._settings = settings;
|
|
|
|
this._imagePath = imagePath;
|
|
|
|
this._editionMode = editionMode;
|
2017-12-02 00:27:35 +00:00
|
|
|
this._capturedEventId = global.stage.connect('captured-event', this._onCapturedEvent.bind(this));
|
2017-02-13 14:25:20 +00:00
|
|
|
this._padChooser = null;
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
let deviceManager = Clutter.DeviceManager.get_default();
|
2017-10-31 00:38:18 +00:00
|
|
|
this._deviceAddedId = deviceManager.connect('device-added', (manager, device) => {
|
2017-02-13 14:25:20 +00:00
|
|
|
if (device.get_device_type() == Clutter.InputDeviceType.PAD_DEVICE &&
|
|
|
|
this.padDevice.is_grouped(device)) {
|
|
|
|
this._groupPads.push(device);
|
|
|
|
this._updatePadChooser();
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
this._deviceRemovedId = deviceManager.connect('device-removed', (manager, device) => {
|
2016-06-22 17:57:12 +00:00
|
|
|
// If the device is being removed, destroy the padOsd.
|
2017-02-13 14:25:20 +00:00
|
|
|
if (device == this.padDevice) {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.destroy();
|
2018-07-14 20:56:22 +00:00
|
|
|
} else if (this._groupPads.includes(device)) {
|
2017-02-13 14:25:20 +00:00
|
|
|
// Or update the pad chooser if the device belongs to
|
|
|
|
// the same group.
|
|
|
|
this._groupPads.splice(this._groupPads.indexOf(device), 1);
|
|
|
|
this._updatePadChooser();
|
|
|
|
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
deviceManager.list_devices().forEach(device => {
|
2017-02-13 10:55:24 +00:00
|
|
|
if (device != this.padDevice &&
|
|
|
|
device.get_device_type() == Clutter.InputDeviceType.PAD_DEVICE &&
|
|
|
|
this.padDevice.is_grouped(device))
|
|
|
|
this._groupPads.push(device);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-02-13 10:55:24 +00:00
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor = new St.BoxLayout({ style_class: 'pad-osd-window',
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
vertical: true,
|
|
|
|
reactive: true });
|
2017-12-02 00:27:35 +00:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
|
|
|
|
|
|
|
this._monitorIndex = monitorIndex;
|
|
|
|
let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
|
|
|
|
this.actor.add_constraint(constraint);
|
|
|
|
|
2017-02-13 14:11:22 +00:00
|
|
|
this._titleBox = new St.BoxLayout({ style_class: 'pad-osd-title-box',
|
|
|
|
vertical: false,
|
|
|
|
x_expand: false,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this.actor.add_actor(this._titleBox);
|
|
|
|
|
|
|
|
let labelBox = new St.BoxLayout({ style_class: 'pad-osd-title-menu-box',
|
|
|
|
vertical: true });
|
|
|
|
this._titleBox.add_actor(labelBox);
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
this._titleLabel = new St.Label({ style: 'font-side: larger; font-weight: bold;',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this._titleLabel.clutter_text.set_text(padDevice.get_device_name());
|
2017-02-13 14:11:22 +00:00
|
|
|
labelBox.add_actor(this._titleLabel);
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
this._tipLabel = new St.Label({ x_align: Clutter.ActorAlign.CENTER });
|
2017-02-13 14:11:22 +00:00
|
|
|
labelBox.add_actor(this._tipLabel);
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-02-13 14:25:20 +00:00
|
|
|
this._updatePadChooser();
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
this._actionEditor = new ActionEditor();
|
2017-12-02 00:27:35 +00:00
|
|
|
this._actionEditor.connect('done', this._endActionEdition.bind(this));
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
this._padDiagram = new PadDiagram({ image: this._imagePath,
|
|
|
|
left_handed: settings.get_boolean('left-handed'),
|
|
|
|
editor_actor: this._actionEditor.actor,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
|
|
|
this.actor.add_actor(this._padDiagram);
|
|
|
|
|
|
|
|
// FIXME: Fix num buttons.
|
|
|
|
let i = 0;
|
|
|
|
for (i = 0; i < 50; i++) {
|
|
|
|
let [found] = this._padDiagram.getButtonLabelCoords(i);
|
|
|
|
if (!found)
|
|
|
|
break;
|
|
|
|
this._createLabel(Meta.PadActionType.BUTTON, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < padDevice.get_n_rings(); i++) {
|
2017-07-12 20:38:31 +00:00
|
|
|
let [found] = this._padDiagram.getRingLabelCoords(i, CW);
|
|
|
|
if (!found)
|
|
|
|
break;
|
2016-06-22 17:57:12 +00:00
|
|
|
this._createLabel(Meta.PadActionType.RING, i, CW);
|
|
|
|
this._createLabel(Meta.PadActionType.RING, i, CCW);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < padDevice.get_n_strips(); i++) {
|
2017-07-12 20:38:31 +00:00
|
|
|
let [found] = this._padDiagram.getStripLabelCoords(i, UP);
|
|
|
|
if (!found)
|
|
|
|
break;
|
2016-06-22 17:57:12 +00:00
|
|
|
this._createLabel(Meta.PadActionType.STRIP, i, UP);
|
|
|
|
this._createLabel(Meta.PadActionType.STRIP, i, DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
let buttonBox = new St.Widget({ layout_manager: new Clutter.BinLayout(),
|
|
|
|
x_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this.actor.add_actor(buttonBox);
|
|
|
|
this._editButton = new St.Button({ label: _("Edit…"),
|
|
|
|
style_class: 'button',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
can_focus: true });
|
2017-10-31 00:38:18 +00:00
|
|
|
this._editButton.connect('clicked', () => {
|
|
|
|
this.setEditionMode(true);
|
|
|
|
});
|
2016-06-22 17:57:12 +00:00
|
|
|
buttonBox.add_actor(this._editButton);
|
|
|
|
|
|
|
|
this._syncEditionMode();
|
|
|
|
Main.pushModal(this.actor);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updatePadChooser() {
|
2017-02-13 14:25:20 +00:00
|
|
|
if (this._groupPads.length > 1) {
|
|
|
|
if (this._padChooser == null) {
|
|
|
|
this._padChooser = new PadChooser(this.padDevice, this._groupPads)
|
2017-10-31 00:38:18 +00:00
|
|
|
this._padChooser.connect('pad-selected', (chooser, pad) => {
|
2017-02-13 14:25:20 +00:00
|
|
|
this._requestForOtherPad(pad);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-02-13 14:25:20 +00:00
|
|
|
this._titleBox.add_child(this._padChooser.actor);
|
|
|
|
} else {
|
|
|
|
this._padChooser.update(this._groupPads);
|
|
|
|
}
|
|
|
|
} else if (this._padChooser != null) {
|
|
|
|
this._padChooser.destroy();
|
|
|
|
this._padChooser = null;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:25:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_requestForOtherPad(pad) {
|
2018-07-14 20:56:22 +00:00
|
|
|
if (pad == this.padDevice || !this._groupPads.includes(pad))
|
2017-02-13 14:25:20 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
let editionMode = this._editionMode;
|
|
|
|
this.destroy();
|
|
|
|
global.display.request_pad_osd(pad, editionMode);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-13 14:25:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createLabel(type, number, dir) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let str = global.display.get_pad_action_label(this.padDevice, type, number);
|
|
|
|
let label = new St.Label({ text: str ? str : _("None") });
|
|
|
|
this._padDiagram.addLabel(label, type, number, dir);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onCapturedEvent(actor, event) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (event.type() == Clutter.EventType.PAD_BUTTON_PRESS &&
|
|
|
|
event.get_source_device() == this.padDevice) {
|
|
|
|
this._padDiagram.activateButton(event.get_button());
|
2017-07-05 22:05:22 +00:00
|
|
|
let isModeSwitch = this.padDevice.get_mode_switch_button_group(event.get_button()) >= 0;
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
/* Buttons that switch between modes cannot be edited */
|
|
|
|
if (this._editionMode && !isModeSwitch)
|
2016-06-22 17:57:12 +00:00
|
|
|
this._startButtonActionEdition(event.get_button());
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
} else if (event.type() == Clutter.EventType.PAD_BUTTON_RELEASE &&
|
|
|
|
event.get_source_device() == this.padDevice) {
|
|
|
|
this._padDiagram.deactivateButton(event.get_button());
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
} else if (event.type() == Clutter.EventType.KEY_PRESS &&
|
|
|
|
(!this._editionMode || event.get_key_symbol() == Clutter.Escape)) {
|
2017-07-05 22:05:22 +00:00
|
|
|
if (this._editedAction != null)
|
|
|
|
this._endActionEdition();
|
2016-06-22 17:57:12 +00:00
|
|
|
else
|
|
|
|
this.destroy();
|
|
|
|
return Clutter.EVENT_STOP;
|
2017-07-05 22:05:22 +00:00
|
|
|
} else if (event.get_source_device() == this.padDevice &&
|
|
|
|
event.type() == Clutter.EventType.PAD_STRIP) {
|
|
|
|
if (this._editionMode) {
|
|
|
|
let [retval, number, mode] = event.get_pad_event_details();
|
|
|
|
this._startStripActionEdition(number, UP, mode);
|
|
|
|
}
|
|
|
|
} else if (event.get_source_device() == this.padDevice &&
|
|
|
|
event.type() == Clutter.EventType.PAD_RING) {
|
|
|
|
if (this._editionMode) {
|
|
|
|
let [retval, number, mode] = event.get_pad_event_details();
|
|
|
|
this._startRingActionEdition(number, CCW, mode);
|
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 14:25:20 +00:00
|
|
|
// If the event comes from another pad in the same group,
|
|
|
|
// show the OSD for it.
|
2018-07-14 20:56:22 +00:00
|
|
|
if (this._groupPads.includes(event.get_source_device())) {
|
2017-02-13 14:25:20 +00:00
|
|
|
this._requestForOtherPad(event.get_source_device());
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:57:12 +00:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncEditionMode() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._editButton.set_reactive(!this._editionMode);
|
|
|
|
this._editButton.save_easing_state();
|
|
|
|
this._editButton.set_easing_duration(200);
|
|
|
|
this._editButton.set_opacity(this._editionMode ? 128 : 255);
|
|
|
|
this._editButton.restore_easing_state();
|
|
|
|
|
|
|
|
let title;
|
|
|
|
|
|
|
|
if (this._editionMode) {
|
|
|
|
title = _("Press a button to configure");
|
|
|
|
this._tipLabel.set_text(_("Press Esc to exit"));
|
|
|
|
} else {
|
|
|
|
title = this.padDevice.get_device_name();
|
|
|
|
this._tipLabel.set_text(_("Press any key to exit"));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._titleLabel.clutter_text.set_markup('<span size="larger"><b>' + title + '</b></span>');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_isEditedAction(type, number, dir) {
|
2017-07-05 22:05:22 +00:00
|
|
|
if (!this._editedAction)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (this._editedAction.type == type &&
|
|
|
|
this._editedAction.number == number &&
|
|
|
|
this._editedAction.dir == dir);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-05 22:05:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_followUpActionEdition(str) {
|
2017-07-05 22:05:22 +00:00
|
|
|
let { type, dir, number, mode } = this._editedAction;
|
|
|
|
let hasNextAction = (type == Meta.PadActionType.RING && dir == CCW ||
|
|
|
|
type == Meta.PadActionType.STRIP && dir == UP);
|
|
|
|
if (!hasNextAction)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this._padDiagram.stopEdition(true, str);
|
|
|
|
this._editedAction = null;
|
|
|
|
if (type == Meta.PadActionType.RING)
|
|
|
|
this._startRingActionEdition(number, CW, mode);
|
|
|
|
else
|
|
|
|
this._startStripActionEdition(number, DOWN, mode);
|
|
|
|
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-05 22:05:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_endActionEdition() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._actionEditor.close();
|
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
if (this._editedAction != null) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let str = global.display.get_pad_action_label(this.padDevice,
|
2017-07-05 22:05:22 +00:00
|
|
|
this._editedAction.type,
|
|
|
|
this._editedAction.number);
|
|
|
|
if (this._followUpActionEdition(str))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._padDiagram.stopEdition(false, str ? str : _("None"))
|
|
|
|
this._editedAction = null;
|
2016-06-22 17:57:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
this._editedActionSettings = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_startActionEdition(key, type, number, dir, mode) {
|
2017-07-05 22:05:22 +00:00
|
|
|
if (this._isEditedAction(type, number, dir))
|
2016-06-22 17:57:12 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
this._endActionEdition();
|
|
|
|
this._editedAction = { type, number, dir, mode };
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-07-05 22:05:22 +00:00
|
|
|
let settingsPath = this._settings.path + key + '/';
|
|
|
|
this._editedActionSettings = Gio.Settings.new_with_path('org.gnome.desktop.peripherals.tablet.pad-button',
|
2016-06-22 17:57:12 +00:00
|
|
|
settingsPath);
|
2017-07-12 16:37:18 +00:00
|
|
|
this._actionEditor.setSettings(this._editedActionSettings, type);
|
2017-07-05 22:05:22 +00:00
|
|
|
this._padDiagram.startEdition(type, number, dir);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-05 22:05:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_startButtonActionEdition(button) {
|
2017-07-05 22:05:22 +00:00
|
|
|
let ch = String.fromCharCode('A'.charCodeAt() + button);
|
|
|
|
let key = 'button' + ch;
|
|
|
|
this._startActionEdition(key, Meta.PadActionType.BUTTON, button);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-05 22:05:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_startRingActionEdition(ring, dir, mode) {
|
2017-07-05 22:05:22 +00:00
|
|
|
let ch = String.fromCharCode('A'.charCodeAt() + ring);
|
|
|
|
let key = 'ring%s-%s-mode-%d'.format(ch, dir == CCW ? 'ccw' : 'cw', mode);
|
|
|
|
this._startActionEdition(key, Meta.PadActionType.RING, ring, dir, mode);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-07-05 22:05:22 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_startStripActionEdition(strip, dir, mode) {
|
2017-07-05 22:05:22 +00:00
|
|
|
let ch = String.fromCharCode('A'.charCodeAt() + strip);
|
|
|
|
let key = 'strip%s-%s-mode-%d'.format(ch, dir == UP ? 'up' : 'down', mode);
|
|
|
|
this._startActionEdition(key, Meta.PadActionType.STRIP, strip, dir, mode);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setEditionMode(editionMode) {
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._editionMode == editionMode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._editionMode = editionMode;
|
|
|
|
this._syncEditionMode();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this.actor.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDestroy() {
|
2016-06-22 17:57:12 +00:00
|
|
|
Main.popModal(this.actor);
|
|
|
|
this._actionEditor.close();
|
|
|
|
|
2017-02-13 14:25:20 +00:00
|
|
|
let deviceManager = Clutter.DeviceManager.get_default();
|
2016-06-22 17:57:12 +00:00
|
|
|
if (this._deviceRemovedId != 0) {
|
|
|
|
deviceManager.disconnect(this._deviceRemovedId);
|
|
|
|
this._deviceRemovedId = 0;
|
|
|
|
}
|
2017-02-13 14:25:20 +00:00
|
|
|
if (this._deviceAddedId != 0) {
|
|
|
|
deviceManager.disconnect(this._deviceAddedId);
|
|
|
|
this._deviceAddedId = 0;
|
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
|
|
|
if (this._capturedEventId != 0) {
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor = null;
|
|
|
|
this.emit('closed');
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-06-22 17:57:12 +00:00
|
|
|
Signals.addSignalMethods(PadOsd.prototype);
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const PadOsdIface = loadInterfaceXML('org.gnome.Shell.Wacom.PadOsd');
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var PadOsdService = class {
|
|
|
|
constructor() {
|
2016-06-22 17:57:12 +00:00
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(PadOsdIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Wacom');
|
|
|
|
Gio.DBus.session.own_name('org.gnome.Shell.Wacom.PadOsd', Gio.BusNameOwnerFlags.REPLACE, null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
ShowAsync(params, invocation) {
|
2016-06-22 17:57:12 +00:00
|
|
|
let [deviceNode, editionMode] = params;
|
|
|
|
let deviceManager = Clutter.DeviceManager.get_default();
|
|
|
|
let devices = deviceManager.list_devices();
|
|
|
|
let padDevice = null;
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
devices.forEach(device => {
|
2018-01-19 09:45:50 +00:00
|
|
|
if (deviceNode == device.get_device_node() &&
|
2018-01-30 15:33:40 +00:00
|
|
|
device.get_device_type() == Clutter.InputDeviceType.PAD_DEVICE)
|
2016-06-22 17:57:12 +00:00
|
|
|
padDevice = device;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2016-06-22 17:57:12 +00:00
|
|
|
|
2018-01-19 09:45:50 +00:00
|
|
|
if (padDevice == null) {
|
2016-06-22 17:57:12 +00:00
|
|
|
invocation.return_error_literal(Gio.IOErrorEnum,
|
|
|
|
Gio.IOErrorEnum.CANCELLED,
|
|
|
|
"Invalid params");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
global.display.request_pad_osd(padDevice, editionMode);
|
|
|
|
invocation.return_value(null);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2016-06-22 17:57:12 +00:00
|
|
|
Signals.addSignalMethods(PadOsdService.prototype);
|