Skip to content

Commit

Permalink
Merge pull request #353 from charlesg99/fix-dynamic-transparency
Browse files Browse the repository at this point in the history
Fix for dynamic transparency crash under certain themes
  • Loading branch information
jderose9 authored Mar 14, 2018
2 parents 8aef439 + 0742967 commit 1c32306
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var dtpPanel = new Lang.Class({
if (this.panel._updateSolidStyle) {
this._injectionsHandler = new Convenience.InjectionsHandler();
this.panel._dtpPosition = this._dtpSettings.get_string('panel-position');
this.panel._dtpRemoveSolidStyleId = 0;
this._injectionsHandler.addWithLabel('transparency', [
this.panel,
'_updateSolidStyle',
Expand Down Expand Up @@ -263,9 +264,15 @@ var dtpPanel = new Lang.Class({
this._displayShowDesktopButton(false);

if (this.panel._updateSolidStyle) {
if (this.panel._dtpRemoveSolidStyleId) {
Mainloop.source_remove(this._panel._dtpRemoveSolidStyleId);
}

this._injectionsHandler.removeWithLabel('transparency');
this._injectionsHandler.destroy();

delete this.panel._dtpPosition;
delete this.panel._dtpRemoveSolidStyleId;
}

PopupMenu.PopupMenu.prototype.open = this._oldPopupOpen;
Expand Down Expand Up @@ -602,36 +609,47 @@ var dtpPanel = new Lang.Class({
},

_dtpUpdateSolidStyle: function() {
if (this.actor.has_style_pseudo_class('overview') || !Main.sessionMode.hasWindows) {
this._removeStyleClassName('solid');
} else {
/* Get all the windows in the active workspace that are in the
* primary monitor and visible */
let activeWorkspace = global.screen.get_active_workspace();
let windows = activeWorkspace.list_windows().filter(function(metaWindow) {
return metaWindow.is_on_primary_monitor() &&
metaWindow.showing_on_its_workspace() &&
metaWindow.get_window_type() != Meta.WindowType.DESKTOP;
let removeSolidStyle = function(solid) {
this._dtpRemoveSolidStyleId = Mainloop.timeout_add(0, () => {
this._dtpRemoveSolidStyleId = 0;
this._removeStyleClassName('solid');
});
};

/* 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 scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
let isNearEnough = windows.some(Lang.bind(this, function(metaWindow) {
if (this.hasOwnProperty('_dtpPosition') && this._dtpPosition === 'TOP') {
let verticalPosition = metaWindow.get_frame_rect().y;
return verticalPosition < panelBottom + 5 * scale;
} else {
let verticalPosition = metaWindow.get_frame_rect().y + metaWindow.get_frame_rect().height;
return verticalPosition > panelTop - 5 * scale;
}
}));
if (this.actor.has_style_pseudo_class('overview') || !Main.sessionMode.hasWindows) {
removeSolidStyle.call(this);
return;
}

if (isNearEnough)
this._addStyleClassName('solid');
else
this._removeStyleClassName('solid');
if (!Main.layoutManager.primaryMonitor)
return;

/* Get all the windows in the active workspace that are in the primary monitor and visible */
let activeWorkspace = global.screen.get_active_workspace();
let windows = activeWorkspace.list_windows().filter(function(metaWindow) {
return metaWindow.is_on_primary_monitor() &&
metaWindow.showing_on_its_workspace() &&
metaWindow.get_window_type() != Meta.WindowType.DESKTOP;
});

/* 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 scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
let isNearEnough = windows.some(Lang.bind(this, function(metaWindow) {
if (this.hasOwnProperty('_dtpPosition') && this._dtpPosition === 'TOP') {
let verticalPosition = metaWindow.get_frame_rect().y;
return verticalPosition < panelBottom + 5 * scale;
} else {
let verticalPosition = metaWindow.get_frame_rect().y + metaWindow.get_frame_rect().height;
return verticalPosition > panelTop - 5 * scale;
}
}));

if (isNearEnough) {
this._addStyleClassName('solid');
} else {
removeSolidStyle.call(this);
}
}
});
Expand Down

0 comments on commit 1c32306

Please sign in to comment.