padOsd: Use per-direction labels on ring/strip actions

Rely on new Mutter API in order to separate mapping/labeling of buttons
and rings/strips, so that the latter may have per-direction labels.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6631
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2766>
This commit is contained in:
Carlos Garnacho 2023-05-16 18:06:40 +02:00 committed by Marge Bot
parent d2ce9de2ad
commit 457f3ae15b

View File

@ -24,12 +24,6 @@ const ACTIVE_COLOR = "#729fcf";
const LTR = 0; const LTR = 0;
const RTL = 1; const RTL = 1;
const CW = 0;
const CCW = 1;
const UP = 0;
const DOWN = 1;
const PadChooser = GObject.registerClass({ const PadChooser = GObject.registerClass({
Signals: { 'pad-selected': { param_types: [Clutter.InputDevice.$gtype] } }, Signals: { 'pad-selected': { param_types: [Clutter.InputDevice.$gtype] } },
}, class PadChooser extends St.Button { }, class PadChooser extends St.Button {
@ -254,7 +248,7 @@ const ActionEditor = GObject.registerClass({
this._actionComboBox.setAction(this._currentAction); this._actionComboBox.setAction(this._currentAction);
this._updateKeybindingEntryState(); this._updateKeybindingEntryState();
let isButton = action == Meta.PadActionType.BUTTON; let isButton = action === null;
this._actionComboBox.setButtonActionsActive(isButton); this._actionComboBox.setButtonActionsActive(isButton);
} }
@ -354,19 +348,19 @@ const PadDiagram = GObject.registerClass({
_initLabels() { _initLabels() {
let i = 0; let i = 0;
for (i = 0; ; i++) { for (i = 0; ; i++) {
if (!this._addLabel(Meta.PadActionType.BUTTON, i)) if (!this._addLabel(null, i))
break; break;
} }
for (i = 0; ; i++) { for (i = 0; ; i++) {
if (!this._addLabel(Meta.PadActionType.RING, i, CW) || if (!this._addLabel(Meta.PadFeatureType.RING, i, Meta.PadDirection.CW) ||
!this._addLabel(Meta.PadActionType.RING, i, CCW)) !this._addLabel(Meta.PadFeatureType.RING, i, Meta.PadDirection.CCW))
break; break;
} }
for (i = 0; ; i++) { for (i = 0; ; i++) {
if (!this._addLabel(Meta.PadActionType.STRIP, i, UP) || if (!this._addLabel(Meta.PadFeatureType.STRIP, i, Meta.PadDirection.UP) ||
!this._addLabel(Meta.PadActionType.STRIP, i, DOWN)) !this._addLabel(Meta.PadFeatureType.STRIP, i, Meta.PadDirection.DOWN))
break; break;
} }
} }
@ -525,7 +519,7 @@ const PadDiagram = GObject.registerClass({
_getRingLabels(number, dir) { _getRingLabels(number, dir) {
let numStr = number > 0 ? (number + 1).toString() : ''; let numStr = number > 0 ? (number + 1).toString() : '';
let dirStr = dir == CW ? 'CW' : 'CCW'; let dirStr = dir === Meta.PadDirection.CW ? 'CW' : 'CCW';
const labelName = `LabelRing${numStr}${dirStr}`; const labelName = `LabelRing${numStr}${dirStr}`;
const leaderName = `LeaderRing${numStr}${dirStr}`; const leaderName = `LeaderRing${numStr}${dirStr}`;
return [labelName, leaderName]; return [labelName, leaderName];
@ -533,21 +527,19 @@ const PadDiagram = GObject.registerClass({
_getStripLabels(number, dir) { _getStripLabels(number, dir) {
let numStr = number > 0 ? (number + 1).toString() : ''; let numStr = number > 0 ? (number + 1).toString() : '';
let dirStr = dir == UP ? 'Up' : 'Down'; let dirStr = dir === Meta.PadDirection.UP ? 'Up' : 'Down';
const labelName = `LabelStrip${numStr}${dirStr}`; const labelName = `LabelStrip${numStr}${dirStr}`;
const leaderName = `LeaderStrip${numStr}${dirStr}`; const leaderName = `LeaderStrip${numStr}${dirStr}`;
return [labelName, leaderName]; return [labelName, leaderName];
} }
_getLabelCoords(action, idx, dir) { _getLabelCoords(action, idx, dir) {
if (action == Meta.PadActionType.BUTTON) if (action === Meta.PadFeatureType.RING)
return this._getItemLabelCoords(...this._getButtonLabels(idx));
else if (action == Meta.PadActionType.RING)
return this._getItemLabelCoords(...this._getRingLabels(idx, dir)); return this._getItemLabelCoords(...this._getRingLabels(idx, dir));
else if (action == Meta.PadActionType.STRIP) else if (action === Meta.PadFeatureType.STRIP)
return this._getItemLabelCoords(...this._getStripLabels(idx, dir)); return this._getItemLabelCoords(...this._getStripLabels(idx, dir));
else
return [false]; return this._getItemLabelCoords(...this._getButtonLabels(idx));
} }
_invalidateSvg() { _invalidateSvg() {
@ -785,8 +777,13 @@ export const PadOsd = GObject.registerClass({
global.display.request_pad_osd(pad, editionMode); global.display.request_pad_osd(pad, editionMode);
} }
_getActionText(type, number) { _getActionText(type, number, dir) {
let str = global.display.get_pad_action_label(this.padDevice, type, number); let str;
if (type === Meta.PadFeatureType.RING || type === Meta.PadFeatureType.STRIP)
str = global.display.get_pad_feature_label(this.padDevice, type, dir, number);
else
str = global.display.get_pad_button_label(this.padDevice, number);
return str ?? _('None'); return str ?? _('None');
} }
@ -828,13 +825,13 @@ export const PadOsd = GObject.registerClass({
event.type() == Clutter.EventType.PAD_STRIP) { event.type() == Clutter.EventType.PAD_STRIP) {
if (this._editionMode) { if (this._editionMode) {
let [retval_, number, mode] = event.get_pad_event_details(); let [retval_, number, mode] = event.get_pad_event_details();
this._startStripActionEdition(number, UP, mode); this._startStripActionEdition(number, Meta.PadDirection.UP, mode);
} }
} else if (event.get_source_device() == this.padDevice && } else if (event.get_source_device() == this.padDevice &&
event.type() == Clutter.EventType.PAD_RING) { event.type() == Clutter.EventType.PAD_RING) {
if (this._editionMode) { if (this._editionMode) {
let [retval_, number, mode] = event.get_pad_event_details(); let [retval_, number, mode] = event.get_pad_event_details();
this._startRingActionEdition(number, CCW, mode); this._startRingActionEdition(number, Meta.PadDirection.CCW, mode);
} }
} }
@ -879,17 +876,18 @@ export const PadOsd = GObject.registerClass({
_followUpActionEdition(str) { _followUpActionEdition(str) {
let { type, dir, number, mode } = this._editedAction; let { type, dir, number, mode } = this._editedAction;
let hasNextAction = type == Meta.PadActionType.RING && dir == CCW || const hasNextAction =
type == Meta.PadActionType.STRIP && dir == UP; type === Meta.PadFeatureType.RING && dir === Meta.PadDirection.CCW
|| type === Meta.PadFeatureType.STRIP && dir === Meta.PadDirection.UP;
if (!hasNextAction) if (!hasNextAction)
return false; return false;
this._padDiagram.stopEdition(true, str); this._padDiagram.stopEdition(true, str);
this._editedAction = null; this._editedAction = null;
if (type == Meta.PadActionType.RING) if (type === Meta.PadFeatureType.RING)
this._startRingActionEdition(number, CW, mode); this._startRingActionEdition(number, Meta.PadDirection.CW, mode);
else else
this._startStripActionEdition(number, DOWN, mode); this._startStripActionEdition(number, Meta.PadDirection.DOWN, mode);
return true; return true;
} }
@ -898,13 +896,12 @@ export const PadOsd = GObject.registerClass({
this._actionEditor.close(); this._actionEditor.close();
if (this._editedAction != null) { if (this._editedAction != null) {
let str = global.display.get_pad_action_label(this.padDevice, const { type, number, dir, mode } = this._editedAction;
this._editedAction.type, const str = this._getActionText(type, number, dir);
this._editedAction.number);
if (this._followUpActionEdition(str)) if (this._followUpActionEdition(str))
return; return;
this._padDiagram.stopEdition(false, str ?? _('None')); this._padDiagram.stopEdition(false, str);
this._editedAction = null; this._editedAction = null;
} }
@ -928,19 +925,19 @@ export const PadOsd = GObject.registerClass({
_startButtonActionEdition(button) { _startButtonActionEdition(button) {
let ch = String.fromCharCode('A'.charCodeAt() + button); let ch = String.fromCharCode('A'.charCodeAt() + button);
let key = `button${ch}`; let key = `button${ch}`;
this._startActionEdition(key, Meta.PadActionType.BUTTON, button); this._startActionEdition(key, null, button);
} }
_startRingActionEdition(ring, dir, mode) { _startRingActionEdition(ring, dir, mode) {
let ch = String.fromCharCode('A'.charCodeAt() + ring); let ch = String.fromCharCode('A'.charCodeAt() + ring);
const key = `ring${ch}-${dir === CCW ? 'ccw' : 'cw'}-mode-${mode}`; const key = `ring${ch}-${dir === Meta.PadDirection.CCW ? 'ccw' : 'cw'}-mode-${mode}`;
this._startActionEdition(key, Meta.PadActionType.RING, ring, dir, mode); this._startActionEdition(key, Meta.PadFeatureType.RING, ring, dir, mode);
} }
_startStripActionEdition(strip, dir, mode) { _startStripActionEdition(strip, dir, mode) {
let ch = String.fromCharCode('A'.charCodeAt() + strip); let ch = String.fromCharCode('A'.charCodeAt() + strip);
const key = `strip${ch}-${dir === UP ? 'up' : 'down'}-mode-${mode}`; const key = `strip${ch}-${dir === Meta.PadDirection.UP ? 'up' : 'down'}-mode-${mode}`;
this._startActionEdition(key, Meta.PadActionType.STRIP, strip, dir, mode); this._startActionEdition(key, Meta.PadFeatureType.STRIP, strip, dir, mode);
} }
setEditionMode(editionMode) { setEditionMode(editionMode) {