Skip to content

Commit

Permalink
Fix another high-CPU issue. Closes #4
Browse files Browse the repository at this point in the history
allocation handler from shell's main panel code competing with extension and causing circular event loop
  • Loading branch information
jderose9 committed Jan 9, 2017
1 parent 40fb563 commit 3cdd20c
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions panel.js
Expand Up @@ -50,6 +50,28 @@ const taskbarPanel = new Lang.Class({
this.appMenu = this.panel.statusArea.appMenu;
this.panelBox = Main.layoutManager.panelBox;

// The main panel's connection to the "allocate" signal is competing with this extension
// trying to move the centerBox over to the right, creating a never-ending cycle.
// Since we don't have the ID to disconnect that handler, wrap the allocate() function
// it calls instead. If the call didn't originate from this file, ignore it.
this.panel._leftBox.oldLeftBoxAllocate = this.panel._leftBox.allocate;
this.panel._leftBox.allocate = Lang.bind(this.panel._leftBox, function(box, flags, isFromDashToPanel) {
if(isFromDashToPanel === true)
this.oldLeftBoxAllocate(box, flags);
});

this.panel._centerBox.oldCenterBoxAllocate = this.panel._centerBox.allocate;
this.panel._centerBox.allocate = Lang.bind(this.panel._centerBox, function(box, flags, isFromDashToPanel) {
if(isFromDashToPanel === true)
this.oldCenterBoxAllocate(box, flags);
});

this.panel._rightBox.oldRightBoxAllocate = this.panel._rightBox.allocate;
this.panel._rightBox.allocate = Lang.bind(this.panel._rightBox, function(box, flags, isFromDashToPanel) {
if(isFromDashToPanel === true)
this.oldRightBoxAllocate(box, flags);
});

this._panelConnectId = this.panel.actor.connect('allocate', Lang.bind(this, function(actor,box,flags){this._allocate(actor,box,flags);}));
this.container.remove_child(this.appMenu.container);
this.taskbar = new TaskBar.taskbar(this._dtpSettings);
Expand Down Expand Up @@ -127,6 +149,15 @@ const taskbarPanel = new Lang.Class({
},

disable: function () {
this.panel._leftBox.allocate = this.panel._leftBox.oldLeftBoxAllocate;
delete this.panel._leftBox.oldLeftBoxAllocate;

this.panel._centerBox.allocate = this.panel._centerBox.oldCenterBoxAllocate;
delete this.panel._centerBox.oldCenterBoxAllocate;

this.panel._rightBox.allocate = this.panel._rightBox.oldRightBoxAllocate;
delete this.panel._rightBox.oldRightBoxAllocate;

this.panelStyle.disable();

this._signalsHandler.destroy();
Expand Down Expand Up @@ -202,7 +233,7 @@ const taskbarPanel = new Lang.Class({
childBox.x1 = 0;
childBox.x2 = sideWidth;
}
this.panel._leftBox.allocate(childBox, flags);
this.panel._leftBox.allocate(childBox, flags, true);

childBox.y1 = 0;
childBox.y2 = allocHeight;
Expand All @@ -213,7 +244,7 @@ const taskbarPanel = new Lang.Class({
childBox.x1 = allocWidth - centerNaturalWidth - rightNaturalWidth;
childBox.x2 = childBox.x1 + centerNaturalWidth;
}
this.panel._centerBox.allocate(childBox, flags);
this.panel._centerBox.allocate(childBox, flags, true);

childBox.y1 = 0;
childBox.y2 = allocHeight;
Expand All @@ -224,7 +255,7 @@ const taskbarPanel = new Lang.Class({
childBox.x1 = allocWidth - rightNaturalWidth;
childBox.x2 = allocWidth;
}
this.panel._rightBox.allocate(childBox, flags);
this.panel._rightBox.allocate(childBox, flags, true);

let [cornerMinWidth, cornerWidth] = this.panel._leftCorner.actor.get_preferred_width(-1);
let [cornerMinHeight, cornerHeight] = this.panel._leftCorner.actor.get_preferred_width(-1);
Expand Down

0 comments on commit 3cdd20c

Please sign in to comment.