[gnome-shell] keyboard: Properly destroy focus manager when destroying keyboard



commit d8adeba6b6da03284c699743c14792ee49e948c1
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Fri Feb 26 14:34:36 2021 +0100

    keyboard: Properly destroy focus manager when destroying keyboard
    
    We're currently leaking this object, so make sure to disconnect
    everything properly and plug the leak.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1728>

 js/ui/keyboard.js | 44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 9e9a66fc6e..d7c07c0c6d 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -553,39 +553,50 @@ var FocusTracker = class {
         this._currentWindow = null;
         this._rect = null;
 
-        global.display.connect('notify::focus-window', () => {
+        this._notifyFocusId = global.display.connect('notify::focus-window', () => {
             this._setCurrentWindow(global.display.focus_window);
             this.emit('window-changed', this._currentWindow);
         });
 
-        global.display.connect('grab-op-begin', (display, window, op) => {
+        this._grabOpBeginId = global.display.connect('grab-op-begin', (display, window, op) => {
             if (window == this._currentWindow &&
                 (op == Meta.GrabOp.MOVING || op == Meta.GrabOp.KEYBOARD_MOVING))
                 this.emit('window-grabbed');
         });
 
         /* Valid for wayland clients */
-        Main.inputMethod.connect('cursor-location-changed', (o, rect) => {
-            let newRect = { x: rect.get_x(), y: rect.get_y(), width: rect.get_width(), height: 
rect.get_height() };
-            this._setCurrentRect(newRect);
-        });
+        this._cursorLocationChangedId =
+            Main.inputMethod.connect('cursor-location-changed', (o, rect) => {
+                let newRect = { x: rect.get_x(), y: rect.get_y(), width: rect.get_width(), height: 
rect.get_height() };
+                this._setCurrentRect(newRect);
+            });
 
         this._ibusManager = IBusManager.getIBusManager();
-        this._ibusManager.connect('set-cursor-location', (manager, rect) => {
-            /* Valid for X11 clients only */
-            if (Main.inputMethod.currentFocus)
-                return;
+        this._setCursorLocationId =
+            this._ibusManager.connect('set-cursor-location', (manager, rect) => {
+                /* Valid for X11 clients only */
+                if (Main.inputMethod.currentFocus)
+                    return;
 
-            this._setCurrentRect(rect);
-        });
-        this._ibusManager.connect('focus-in', () => {
+                this._setCurrentRect(rect);
+            });
+        this._focusInId = this._ibusManager.connect('focus-in', () => {
             this.emit('focus-changed', true);
         });
-        this._ibusManager.connect('focus-out', () => {
+        this._focusOutId = this._ibusManager.connect('focus-out', () => {
             this.emit('focus-changed', false);
         });
     }
 
+    destroy() {
+        global.display.disconnect(this._notifyFocusId);
+        global.display.disconnect(this._grabOpBeginId);
+        Main.inputMethod.disconnect(this._cursorLocationChangedId);
+        this._ibusManager.disconnect(this._setCursorLocationId);
+        this._ibusManager.disconnect(this._focusInId);
+        this._ibusManager.disconnect(this._focusOutId);
+    }
+
     get currentWindow() {
         return this._currentWindow;
     }
@@ -1304,6 +1315,11 @@ var Keyboard = GObject.registerClass({
     }
 
     _onDestroy() {
+        if (this._focusTracker) {
+            this._focusTracker.destroy();
+            delete this._focusTracker;
+        }
+
         for (let [obj, id] of this._connectionsIDs)
             obj.disconnect(id);
         delete this._connectionsIDs;


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