From f5f01f85dfa71722d495a0b196953a902fb61618 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Sat, 14 Sep 2019 12:05:47 -0400 Subject: [PATCH] Adjust panel buttons with vertical panel size --- panel.js | 46 ++++++++++++++++++++++++++++++---------------- stylesheet.css | 6 +----- windowPreview.js | 14 ++++++++++++-- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/panel.js b/panel.js index 4cb3923..fbb68de 100644 --- a/panel.js +++ b/panel.js @@ -423,6 +423,8 @@ var dtpPanel = Utils.defineClass({ if (!this.isSecondary) { this._setVertical(this, false); + this.remove_style_class_name('dashtopanelPanel vertical horizontal'); + ['_leftBox', '_centerBox', '_rightBox'].forEach(p => { this.remove_child(Main.panel[p]); Main.panel.actor.add_child(Main.panel[p]); @@ -733,12 +735,11 @@ var dtpPanel = Utils.defineClass({ _setPanelPosition: function() { let container = this.intellihide && this.intellihide.enabled ? this.panelBox.get_parent() : this.panelBox; - let isVertical = checkIfVertical(); this.set_size(this.geom.w, this.geom.h); container.set_position(this.geom.x, this.geom.y) - this._setVertical(this, isVertical); + this._setVertical(this, checkIfVertical()); // styles for theming Object.keys(St.Side).forEach(p => { @@ -804,21 +805,34 @@ var dtpPanel = Utils.defineClass({ }, _setVertical: function(actor, isVertical) { - if (!actor || actor instanceof Dash.DashItemContainer) { - return; - } - - if (actor instanceof St.BoxLayout) { - actor.vertical = isVertical; - } else if (actor instanceof PanelMenu.ButtonBox) { - let child = actor.get_first_child(); - - if (child) { - actor.set_width(isVertical ? size : -1); + let _set = (actor, isVertical) => { + if (!actor || actor instanceof Dash.DashItemContainer) { + return; } - } - actor.get_children().forEach(c => this._setVertical(c, isVertical)); + if (actor instanceof St.BoxLayout) { + actor.vertical = isVertical; + } else if (actor instanceof PanelMenu.ButtonBox) { + let child = actor.get_first_child(); + + if (child) { + let [, natWidth] = actor.get_preferred_width(-1); + + child.x_align = Clutter.ActorAlign[isVertical ? 'CENTER' : 'START']; + child.style = (isVertical ? 'padding: 6px 0;' : null); + + isVertical = isVertical && (natWidth > size); + + actor.set_width(isVertical ? size : -1); + actor[(isVertical ? 'add' : 'remove') + '_style_class_name']('vertical'); + } + } + + actor.get_children().forEach(c => _set(c, isVertical)); + }; + + _set(actor, false); + _set(actor, isVertical); }, _setActivitiesButtonVisible: function(isVisible) { @@ -858,7 +872,7 @@ var dtpPanel = Utils.defineClass({ if (clockText.get_layout().is_ellipsized()) { let timeParts = time.split('∶'); - clockText.set_text(timeParts[0] + '\n‧‧\n' + timeParts[1]); + clockText.set_text(timeParts.join('\n‧‧\n')); clockText.set_use_markup(true); } }, diff --git a/stylesheet.css b/stylesheet.css index 2578b1c..76edbb8 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -71,15 +71,11 @@ text-align: center; } -.dashtopanelPanel.vertical .panel-button * { +.dashtopanelPanel.vertical .panel-button.vertical * { padding: 0; margin: 0; } -.dashtopanelPanel.vertical .panel-button > * { - padding: 6px 0; -} - #dashtopanelThumbnailList { spacing: 0em; padding: 0 1em; diff --git a/windowPreview.js b/windowPreview.js index 19e73bc..ea8607f 100644 --- a/windowPreview.js +++ b/windowPreview.js @@ -17,6 +17,7 @@ const Clutter = imports.gi.Clutter; const Config = imports.misc.config; +const GLib = imports.gi.GLib; const Gtk = imports.gi.Gtk; const Main = imports.ui.main; const Mainloop = imports.mainloop; @@ -671,6 +672,7 @@ var Preview = Utils.defineClass({ }); this.window = null; + this._waitWindowId = 0; this._needsCloseButton = true; this.cloneWidth = this.cloneHeight = 0; this._previewMenu = previewMenu; @@ -773,8 +775,11 @@ var Preview = Utils.defineClass({ this._resizeClone(cloneBin, window); this._addClone(cloneBin, animateSize); this._previewMenu.updatePosition(); - } else { - Mainloop.idle_add(() => _assignWindowClone()); + } else if (!this._waitWindowId) { + this._waitWindowId = Mainloop.idle_add(() => { + this._waitWindowId = 0; + _assignWindowClone(); + }); } }; @@ -833,6 +838,11 @@ var Preview = Utils.defineClass({ }, _onDestroy: function() { + if (this._waitWindowId) { + GLib.source_remove(this._waitWindowId); + this._waitWindowId = 0; + } + this._removeWindowSignals(); },