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

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