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

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