Blame SOURCES/0001-padOsd-Re-query-action-labels-after-mode-switches.patch

bd9c5f
From 2bb826291c420dd1b601758c7a686ac48e1086a6 Mon Sep 17 00:00:00 2001
bd9c5f
From: Carlos Garnacho <carlosg@gnome.org>
bd9c5f
Date: Mon, 16 Dec 2019 12:39:49 +0100
bd9c5f
Subject: [PATCH] padOsd: Re-query action labels after mode switches
bd9c5f
bd9c5f
Do this so the pad OSD is able to update dynamically to mode changes,
bd9c5f
showing immediately the new actions for the current mode(s).
bd9c5f
bd9c5f
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/898
bd9c5f
---
bd9c5f
 js/ui/padOsd.js | 31 ++++++++++++++++++++++++++++---
bd9c5f
 1 file changed, 28 insertions(+), 3 deletions(-)
bd9c5f
bd9c5f
diff --git a/js/ui/padOsd.js b/js/ui/padOsd.js
bd9c5f
index a4af47297..b4b3fe453 100644
bd9c5f
--- a/js/ui/padOsd.js
bd9c5f
+++ b/js/ui/padOsd.js
bd9c5f
@@ -555,6 +555,14 @@ var PadDiagram = GObject.registerClass({
bd9c5f
         this.add_actor(label);
bd9c5f
     }
bd9c5f
 
bd9c5f
+    updateLabels(callback) {
bd9c5f
+        for (let i = 0; i < this._labels.length; i++) {
bd9c5f
+            let [label, action, idx, dir] = this._labels[i];
bd9c5f
+            let str = callback(action, idx, dir);
bd9c5f
+            label.set_text(str);
bd9c5f
+        }
bd9c5f
+    }
bd9c5f
+
bd9c5f
     _applyLabel(label, action, idx, dir, str) {
bd9c5f
         if (str != null) {
bd9c5f
             label.set_text(str);
bd9c5f
@@ -758,17 +766,29 @@ var PadOsd = class {
bd9c5f
         global.display.request_pad_osd(pad, editionMode);
bd9c5f
     }
bd9c5f
 
bd9c5f
-    _createLabel(type, number, dir) {
bd9c5f
+    _getActionText(type, number) {
bd9c5f
         let str = global.display.get_pad_action_label(this.padDevice, type, number);
bd9c5f
-        let label = new St.Label({ text: str ? str : _("None") });
bd9c5f
+        return str ? str : _("None");
bd9c5f
+    }
bd9c5f
+
bd9c5f
+    _createLabel(type, number, dir) {
bd9c5f
+        let label = new St.Label({ text: this._getActionText(type, number) });
bd9c5f
         this._padDiagram.addLabel(label, type, number, dir);
bd9c5f
     }
bd9c5f
 
bd9c5f
+    _updateActionLabels() {
bd9c5f
+        this._padDiagram.updateLabels(this._getActionText.bind(this));
bd9c5f
+    }
bd9c5f
+
bd9c5f
     _onCapturedEvent(actor, event) {
bd9c5f
+        let isModeSwitch =
bd9c5f
+            (event.type() == Clutter.EventType.PAD_BUTTON_PRESS ||
bd9c5f
+             event.type() == Clutter.EventType.PAD_BUTTON_RELEASE) &&
bd9c5f
+            this.padDevice.get_mode_switch_button_group(event.get_button()) >= 0;
bd9c5f
+
bd9c5f
         if (event.type() == Clutter.EventType.PAD_BUTTON_PRESS &&
bd9c5f
             event.get_source_device() == this.padDevice) {
bd9c5f
             this._padDiagram.activateButton(event.get_button());
bd9c5f
-            let isModeSwitch = this.padDevice.get_mode_switch_button_group(event.get_button()) >= 0;
bd9c5f
 
bd9c5f
             /* Buttons that switch between modes cannot be edited */
bd9c5f
             if (this._editionMode && !isModeSwitch)
bd9c5f
@@ -777,6 +797,11 @@ var PadOsd = class {
bd9c5f
         } else if (event.type() == Clutter.EventType.PAD_BUTTON_RELEASE &&
bd9c5f
                    event.get_source_device() == this.padDevice) {
bd9c5f
             this._padDiagram.deactivateButton(event.get_button());
bd9c5f
+
bd9c5f
+            if (isModeSwitch) {
bd9c5f
+                this._endActionEdition();
bd9c5f
+                this._updateActionLabels();
bd9c5f
+            }
bd9c5f
             return Clutter.EVENT_STOP;
bd9c5f
         } else if (event.type() == Clutter.EventType.KEY_PRESS &&
bd9c5f
                    (!this._editionMode || event.get_key_symbol() == Clutter.Escape)) {
bd9c5f
-- 
bd9c5f
2.24.0
bd9c5f