padOsd: Re-query action labels after mode switches

Do this so the pad OSD is able to update dynamically to mode changes,
showing immediately the new actions for the current mode(s).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/898
This commit is contained in:
Carlos Garnacho 2019-12-16 12:39:49 +01:00
parent 9115f6e796
commit 14eeaf4a2a

View File

@ -564,6 +564,14 @@ var PadDiagram = GObject.registerClass({
this.add_actor(label); this.add_actor(label);
} }
updateLabels(getText) {
for (let i = 0; i < this._labels.length; i++) {
let [label, action, idx, dir] = this._labels[i];
let str = getText(action, idx, dir);
label.set_text(str);
}
}
_applyLabel(label, action, idx, dir, str) { _applyLabel(label, action, idx, dir, str) {
if (str != null) { if (str != null) {
label.set_text(str); label.set_text(str);
@ -776,17 +784,29 @@ var PadOsd = GObject.registerClass({
global.display.request_pad_osd(pad, editionMode); global.display.request_pad_osd(pad, editionMode);
} }
_createLabel(type, number, dir) { _getActionText(type, number) {
let str = global.display.get_pad_action_label(this.padDevice, type, number); let str = global.display.get_pad_action_label(this.padDevice, type, number);
let label = new St.Label({ text: str ? str : _("None") }); return str ? str : _("None");
}
_createLabel(type, number, dir) {
let label = new St.Label({ text: this._getActionText(type, number) });
this._padDiagram.addLabel(label, type, number, dir); this._padDiagram.addLabel(label, type, number, dir);
} }
_updateActionLabels() {
this._padDiagram.updateLabels(this._getActionText.bind(this));
}
_onCapturedEvent(actor, event) { _onCapturedEvent(actor, event) {
let isModeSwitch =
(event.type() == Clutter.EventType.PAD_BUTTON_PRESS ||
event.type() == Clutter.EventType.PAD_BUTTON_RELEASE) &&
this.padDevice.get_mode_switch_button_group(event.get_button()) >= 0;
if (event.type() == Clutter.EventType.PAD_BUTTON_PRESS && if (event.type() == Clutter.EventType.PAD_BUTTON_PRESS &&
event.get_source_device() == this.padDevice) { event.get_source_device() == this.padDevice) {
this._padDiagram.activateButton(event.get_button()); this._padDiagram.activateButton(event.get_button());
let isModeSwitch = this.padDevice.get_mode_switch_button_group(event.get_button()) >= 0;
/* Buttons that switch between modes cannot be edited */ /* Buttons that switch between modes cannot be edited */
if (this._editionMode && !isModeSwitch) if (this._editionMode && !isModeSwitch)
@ -795,6 +815,11 @@ var PadOsd = GObject.registerClass({
} else if (event.type() == Clutter.EventType.PAD_BUTTON_RELEASE && } else if (event.type() == Clutter.EventType.PAD_BUTTON_RELEASE &&
event.get_source_device() == this.padDevice) { event.get_source_device() == this.padDevice) {
this._padDiagram.deactivateButton(event.get_button()); this._padDiagram.deactivateButton(event.get_button());
if (isModeSwitch) {
this._endActionEdition();
this._updateActionLabels();
}
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} else if (event.type() == Clutter.EventType.KEY_PRESS && } else if (event.type() == Clutter.EventType.KEY_PRESS &&
(!this._editionMode || event.get_key_symbol() === Clutter.KEY_Escape)) { (!this._editionMode || event.get_key_symbol() === Clutter.KEY_Escape)) {