[gnome-shell/gbsneto/remove-generic-container: 8/38] panel: Stop using Shell.GenericContainer



commit 59af313bba1ca53d4ac1e827533f471fa3ee8fe3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jun 27 16:02:15 2018 -0300

    panel: Stop using Shell.GenericContainer
    
    Shell.GenericContainer exposes the size negotiation machinery
    through the use of signals. Signals are not specially performant.
    One of the reasons is that they acquire a global lock for signal
    handlers lookup. GNOME Shell has more than 2,000 actors at any
    given point in time, up to 20 levels deep in hierarchy, making
    size negotiation and painting non-trivial tasks. Such a critical
    section of Clutter's machinery shouldn't rely on signals
    whatsoever.
    
    Regardless of that, Shell.GenericContainer is a workaround to
    a non-existing issue anymore. It shouldn't be used anyway, and
    any performance improvements that removing it can potentially
    yield are bonuses to it.
    
    This commit starts this work by removing Shell.GenericContainer
    usage from Panel.Panel class. The class now extends St.Widget,
    and as such, it has no "this.actor" field set anymore. A couple
    of places where this actor field was used are adjuste as well.
    
    It is important to notice that we now allocate the Panel itself
    inside vfunc_allocate(). This was previously done before emitting
    the signal by Shell.GenericContainer.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153

 js/ui/overview.js      |  2 +-
 js/ui/panel.js         | 77 +++++++++++++++++++++++---------------------------
 js/ui/windowManager.js |  4 +--
 3 files changed, 39 insertions(+), 44 deletions(-)
---
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 2418f1728a..35f5927a0b 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -226,7 +226,7 @@ var Overview = new Lang.Class({
 
         // Add a clone of the panel to the overview so spacing and such is
         // automatic
-        this._panelGhost = new St.Bin({ child: new Clutter.Clone({ source: Main.panel.actor }),
+        this._panelGhost = new St.Bin({ child: new Clutter.Clone({ source: Main.panel }),
                                         reactive: false,
                                         opacity: 0 });
         this._overview.add_actor(this._panelGhost);
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 3726b84450..27ebec322c 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -774,12 +774,16 @@ const PANEL_ITEM_IMPLEMENTATIONS = {
 
 var Panel = new Lang.Class({
     Name: 'Panel',
+    Extends: St.Widget,
 
     _init() {
-        this.actor = new Shell.GenericContainer({ name: 'panel',
-                                                  reactive: true });
-        this.actor._delegate = this;
-        this.actor.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
+        this.parent({ name: 'panel',
+                      reactive: true });
+
+        // For compatibility with extensions that still use the
+        // this.actor field
+        this.actor = this;
+        this.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS);
 
         this._sessionStyle = null;
 
@@ -788,36 +792,33 @@ var Panel = new Lang.Class({
         this.menuManager = new PopupMenu.PopupMenuManager(this);
 
         this._leftBox = new St.BoxLayout({ name: 'panelLeft' });
-        this.actor.add_actor(this._leftBox);
+        this.add_child(this._leftBox);
         this._centerBox = new St.BoxLayout({ name: 'panelCenter' });
-        this.actor.add_actor(this._centerBox);
+        this.add_child(this._centerBox);
         this._rightBox = new St.BoxLayout({ name: 'panelRight' });
-        this.actor.add_actor(this._rightBox);
+        this.add_child(this._rightBox);
 
         this._leftCorner = new PanelCorner(St.Side.LEFT);
-        this.actor.add_actor(this._leftCorner.actor);
+        this.add_child(this._leftCorner.actor);
 
         this._rightCorner = new PanelCorner(St.Side.RIGHT);
-        this.actor.add_actor(this._rightCorner.actor);
+        this.add_child(this._rightCorner.actor);
 
-        this.actor.connect('get-preferred-width', this._getPreferredWidth.bind(this));
-        this.actor.connect('get-preferred-height', this._getPreferredHeight.bind(this));
-        this.actor.connect('allocate', this._allocate.bind(this));
-        this.actor.connect('button-press-event', this._onButtonPress.bind(this));
-        this.actor.connect('touch-event', this._onButtonPress.bind(this));
-        this.actor.connect('key-press-event', this._onKeyPress.bind(this));
+        this.connect('button-press-event', this._onButtonPress.bind(this));
+        this.connect('touch-event', this._onButtonPress.bind(this));
+        this.connect('key-press-event', this._onKeyPress.bind(this));
 
         Main.overview.connect('showing', () => {
-            this.actor.add_style_pseudo_class('overview');
+            this.add_style_pseudo_class('overview');
             this._updateSolidStyle();
         });
         Main.overview.connect('hiding', () => {
-            this.actor.remove_style_pseudo_class('overview');
+            this.remove_style_pseudo_class('overview');
             this._updateSolidStyle();
         });
 
-        Main.layoutManager.panelBox.add(this.actor);
-        Main.ctrlAltTabManager.addGroup(this.actor, _("Top Bar"), 'focus-top-bar-symbolic',
+        Main.layoutManager.panelBox.add(this);
+        Main.ctrlAltTabManager.addGroup(this, _("Top Bar"), 'focus-top-bar-symbolic',
                                         { sortGroup: CtrlAltTab.SortGroup.TOP });
 
         Main.sessionMode.connect('updated', this._updatePanel.bind(this));
@@ -827,7 +828,7 @@ var Panel = new Lang.Class({
         global.window_group.connect('actor-removed', this._onWindowActorRemoved.bind(this));
         global.window_manager.connect('switch-workspace', this._updateSolidStyle.bind(this));
 
-        global.display.connect('workareas-changed', () => { this.actor.queue_relayout(); });
+        global.display.connect('workareas-changed', () => { this.queue_relayout(); });
         this._updatePanel();
     },
 
@@ -847,24 +848,18 @@ var Panel = new Lang.Class({
         this._updateSolidStyle();
     },
 
-    _getPreferredWidth(actor, forHeight, alloc) {
+    vfunc_get_preferred_width(actor, forHeight) {
         let primaryMonitor = Main.layoutManager.primaryMonitor;
 
-        alloc.min_size = -1;
-
         if (primaryMonitor)
-            alloc.natural_size = primaryMonitor.width;
-        else
-            alloc.natural_size = -1;
-    },
+            return [0, primaryMonitor.width];
 
-    _getPreferredHeight(actor, forWidth, alloc) {
-        // We don't need to implement this; it's forced by the CSS
-        alloc.min_size = -1;
-        alloc.natural_size = -1;
+        return [0,  0];
     },
 
-    _allocate(actor, box, flags) {
+    vfunc_allocate(box, flags) {
+        this.parent(box, flags);
+
         let allocWidth = box.x2 - box.x1;
         let allocHeight = box.y2 - box.y1;
 
@@ -876,7 +871,7 @@ var Panel = new Lang.Class({
         centerWidth = centerNaturalWidth;
 
         // get workspace area and center date entry relative to it
-        let monitor = Main.layoutManager.findMonitorForActor(actor);
+        let monitor = Main.layoutManager.findMonitorForActor(this);
         let centerOffset = 0;
         if (monitor) {
             let workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
@@ -889,7 +884,7 @@ var Panel = new Lang.Class({
 
         childBox.y1 = 0;
         childBox.y2 = allocHeight;
-        if (this.actor.get_text_direction() == Clutter.TextDirection.RTL) {
+        if (this.get_text_direction() == Clutter.TextDirection.RTL) {
             childBox.x1 = Math.max(allocWidth - Math.min(Math.floor(sideWidth),
                                                          leftNaturalWidth),
                                    0);
@@ -909,7 +904,7 @@ var Panel = new Lang.Class({
 
         childBox.y1 = 0;
         childBox.y2 = allocHeight;
-        if (this.actor.get_text_direction() == Clutter.TextDirection.RTL) {
+        if (this.get_text_direction() == Clutter.TextDirection.RTL) {
             childBox.x1 = 0;
             childBox.x2 = Math.min(Math.floor(sideWidth),
                                    rightNaturalWidth);
@@ -1069,7 +1064,7 @@ var Panel = new Lang.Class({
         if (this._sessionStyle)
             this._addStyleClassName(this._sessionStyle);
 
-        if (this.actor.get_text_direction() == Clutter.TextDirection.RTL) {
+        if (this.get_text_direction() == Clutter.TextDirection.RTL) {
             this._leftCorner.setStyleParent(this._rightBox);
             this._rightCorner.setStyleParent(this._leftBox);
         } else {
@@ -1079,7 +1074,7 @@ var Panel = new Lang.Class({
     },
 
     _updateSolidStyle() {
-        if (this.actor.has_style_pseudo_class('overview') || !Main.sessionMode.hasWindows) {
+        if (this.has_style_pseudo_class('overview') || !Main.sessionMode.hasWindows) {
             this._removeStyleClassName('solid');
             return;
         }
@@ -1097,8 +1092,8 @@ var Panel = new Lang.Class({
         });
 
         /* Check if at least one window is near enough to the panel */
-        let [, panelTop] = this.actor.get_transformed_position();
-        let panelBottom = panelTop + this.actor.get_height();
+        let [, panelTop] = this.get_transformed_position();
+        let panelBottom = panelTop + this.get_height();
         let scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
         let isNearEnough = windows.some(metaWindow => {
             let verticalPosition = metaWindow.get_frame_rect().y;
@@ -1190,13 +1185,13 @@ var Panel = new Lang.Class({
     },
 
     _addStyleClassName(className) {
-        this.actor.add_style_class_name(className);
+        this.add_style_class_name(className);
         this._rightCorner.actor.add_style_class_name(className);
         this._leftCorner.actor.add_style_class_name(className);
     },
 
     _removeStyleClassName(className) {
-        this.actor.remove_style_class_name(className);
+        this.remove_style_class_name(className);
         this._rightCorner.actor.remove_style_class_name(className);
         this._leftCorner.actor.remove_style_class_name(className);
     },
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index 0c6ab1be0e..1f6d4d2551 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -1808,11 +1808,11 @@ var WindowManager = new Lang.Class({
         if (direction == Meta.MotionDirection.UP ||
             direction == Meta.MotionDirection.UP_LEFT ||
             direction == Meta.MotionDirection.UP_RIGHT)
-            yDest = -global.screen_height + Main.panel.actor.height;
+            yDest = -global.screen_height + Main.panel.height;
         else if (direction == Meta.MotionDirection.DOWN ||
             direction == Meta.MotionDirection.DOWN_LEFT ||
             direction == Meta.MotionDirection.DOWN_RIGHT)
-            yDest = global.screen_height - Main.panel.actor.height;
+            yDest = global.screen_height - Main.panel.height;
 
         if (direction == Meta.MotionDirection.LEFT ||
             direction == Meta.MotionDirection.UP_LEFT ||


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