[gjs/gnome-3-38] overrides/Gtk: Set BuilderScope in class init



commit 49a55cdfa89aefd1a72bbd44d68253556531d124
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Nov 18 00:09:21 2020 +0100

    overrides/Gtk: Set BuilderScope in class init
    
    The API to set a custom template scope is on the class, not the instance.
    
    On Gtk3 we don't have an alternative for hooking up the correct "this"
    argument (as far as I can tell), but we do have the option with Gtk4.
    
    Moving the code is not only more correct, it is particularly important
    as Gtk4 now relies entirely on ref-counting for destroying widgets
    (and thus ultimately for exiting a Gtk.Application).
    
    Currently the separate reference to the "this" object in the custom
    scope prevents the ref-count of any template widget from ever dropping
    to 0, keeping the app running indefinitely after closing all windows.

 modules/core/overrides/Gtk.js | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
---
diff --git a/modules/core/overrides/Gtk.js b/modules/core/overrides/Gtk.js
index a1e85314..6cf3363e 100644
--- a/modules/core/overrides/Gtk.js
+++ b/modules/core/overrides/Gtk.js
@@ -45,10 +45,7 @@ function _init() {
 
     Gtk.Widget.prototype._init = function (params) {
         if (this.constructor[Gtk.template]) {
-            if (BuilderScope) {
-                Gtk.Widget.set_template_scope.call(this.constructor,
-                    new BuilderScope(this));
-            } else {
+            if (!BuilderScope) {
                 Gtk.Widget.set_connect_func.call(this.constructor,
                     (builder, obj, signalName, handlerName, connectObj, flags) => {
                         const swapped = flags & GObject.ConnectFlags.SWAPPED;
@@ -110,6 +107,9 @@ function _init() {
             } else {
                 Gtk.Widget.set_template.call(klass, template);
             }
+
+            if (BuilderScope)
+                Gtk.Widget.set_template_scope.call(klass, new BuilderScope());
         }
 
         if (children) {
@@ -136,15 +136,11 @@ function _init() {
         BuilderScope = GObject.registerClass({
             Implements: [Gtk.BuilderScope],
         }, class extends GObject.Object {
-            _init(thisArg) {
-                super._init();
-                this._this = thisArg;
-            }
-
             vfunc_create_closure(builder, handlerName, flags, connectObject) {
                 const swapped = flags & Gtk.BuilderClosureFlags.SWAPPED;
                 return _createClosure(
-                    builder, this._this, handlerName, swapped, connectObject);
+                    builder, builder.get_current_object(),
+                    handlerName, swapped, connectObject);
             }
         });
     }


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