[gnome-shell/gnome-3-38] magnifier: Add method to enable/disable crosshairs



commit 26e628b04d357cd723476e72872c6fb8a4348cf3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 28 14:19:15 2021 +0200

    magnifier: Add method to enable/disable crosshairs
    
    These do some some signals connection and monitor layout tracking
    that we forget to disconnect when the magnifier is disconnected.
    This causes warnings if enabling the magnifier, disabling it,
    switching to another tty, and back. (Presumably also happens for
    monitor hotplugs).
    
    This signal should just stay connected as long as it's needed,
    so add a setEnabled() method on the CrossHairs actor that we
    can hook on the magnifier.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1902>
    (cherry picked from commit 3df4b5ec7ca40f9e57d4b3316bca8f6b42f7a964)

 js/ui/magnifier.js | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/magnifier.js b/js/ui/magnifier.js
index ff89b6fa6a..074af5d8ed 100644
--- a/js/ui/magnifier.js
+++ b/js/ui/magnifier.js
@@ -175,6 +175,9 @@ var Magnifier = class Magnifier {
             this.stopTrackingMouse();
         }
 
+        if (this._crossHairs)
+            this._crossHairs.setEnabled(activate);
+
         // Make sure system mouse pointer is shown when all zoom regions are
         // invisible.
         if (!activate)
@@ -1681,9 +1684,7 @@ class Crosshairs extends Clutter.Actor {
         this._clipSize = [0, 0];
         this._clones = [];
         this.reCenter();
-
-        Main.layoutManager.connect('monitors-changed',
-                                   this._monitorsChanged.bind(this));
+        this._monitorsChangedId = 0;
     }
 
     _monitorsChanged() {
@@ -1691,6 +1692,16 @@ class Crosshairs extends Clutter.Actor {
         this.reCenter();
     }
 
+    setEnabled(enabled) {
+        if (enabled && this._monitorsChangedId === 0) {
+            this._monitorsChangedId = Main.layoutManager.connect(
+                'monitors-changed', this._monitorsChanged.bind(this));
+        } else if (!enabled && this._monitorsChangedId !== 0) {
+            Main.layoutManager.disconnect(this._monitorsChangedId);
+            this._monitorsChangedId = 0;
+        }
+    }
+
     /**
     * addToZoomRegion
     * Either add the crosshairs actor to the given ZoomRegion, or, if it is


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]