From 0a066890cb4bf3136e2b23334fcc968952893981 Mon Sep 17 00:00:00 2001 From: MarkS Date: Fri, 31 Jul 2020 15:58:33 -0600 Subject: [PATCH] Display panel along percent of screen edge Set the length of the panel according to a specified percent value, so it can span only part of the screen edge. Position the panel at the start, middle, or end of the screen edge, as specified. Tests okay with multiple monitors. May also satisfy home-sweet-gnome/dash-to-panel#726 --- Settings.ui | 68 +++++++++++++++++++ panel.js | 29 +++++++- panelManager.js | 2 + panelPositions.js | 4 ++ prefs.js | 19 +++++- ...shell.extensions.dash-to-panel.gschema.xml | 15 ++++ 6 files changed, 133 insertions(+), 4 deletions(-) diff --git a/Settings.ui b/Settings.ui index 052397f..a92d065 100644 --- a/Settings.ui +++ b/Settings.ui @@ -2,6 +2,11 @@ + + 100 + 1 + 10 + 0.33 1 @@ -4801,6 +4806,69 @@ 2 + + + True + False + 12 + 12 + False + Length along screen edge, in percent + 0 + + + 0 + 3 + + + + + True + True + 12 + 12 + 5 + 100 + adjustment1 + True + 100 + + + 1 + 3 + + + + + True + False + 12 + 12 + False + Position along screen edge + 0 + + + 0 + 4 + + + + + True + False + center + + Start + Middle + End + + + + 1 + 4 + + diff --git a/panel.js b/panel.js index b089aab..9bcce26 100644 --- a/panel.js +++ b/panel.js @@ -798,6 +798,9 @@ var dtpPanel = Utils.defineClass({ let topPadding = panelBoxTheme.get_padding(St.Side.TOP); let tbPadding = topPadding + panelBoxTheme.get_padding(St.Side.BOTTOM); let position = this.getPosition(); + let length = Me.settings.get_int('panel-length') / 100; + let anchor = Me.settings.get_string('panel-anchor'); + let anchorPlaceOnMonitor = 0; let gsTopPanelOffset = 0; let x = 0, y = 0; let w = 0, h = 0; @@ -819,13 +822,13 @@ var dtpPanel = Utils.defineClass({ this.varCoord = { c1: 'y1', c2: 'y2' }; w = this.dtpSize; - h = this.monitor.height - tbPadding - gsTopPanelOffset; + h = this.monitor.height * length - tbPadding - gsTopPanelOffset; } else { this.sizeFunc = 'get_preferred_width'; this.fixedCoord = { c1: 'y1', c2: 'y2' }; this.varCoord = { c1: 'x1', c2: 'x2' }; - w = this.monitor.width - lrPadding; + w = this.monitor.width * length - lrPadding; h = this.dtpSize; } @@ -836,10 +839,30 @@ var dtpPanel = Utils.defineClass({ x = this.monitor.x + this.monitor.width - this.dtpSize - lrPadding; y = this.monitor.y + gsTopPanelOffset; } else { //BOTTOM - x = this.monitor.x; + x = this.monitor.x; y = this.monitor.y + this.monitor.height - this.dtpSize - tbPadding; } + if (this.checkIfVertical()) { + if (anchor === Pos.MIDDLE) { + anchorPlaceOnMonitor = (this.monitor.height - h) / 2; + } else if (anchor === Pos.END) { + anchorPlaceOnMonitor = this.monitor.height - h; + } else { // Pos.START + anchorPlaceOnMonitor = 0; + } + y = y + anchorPlaceOnMonitor; + } else { + if (anchor === Pos.MIDDLE) { + anchorPlaceOnMonitor = (this.monitor.width - w) / 2; + } else if (anchor === Pos.END) { + anchorPlaceOnMonitor = this.monitor.width - w; + } else { // Pos.START + anchorPlaceOnMonitor = 0; + } + x = x + anchorPlaceOnMonitor; + } + return { x: x, y: y, w: w, h: h, diff --git a/panelManager.js b/panelManager.js index 16f7869..e193a86 100755 --- a/panelManager.js +++ b/panelManager.js @@ -235,6 +235,8 @@ var dtpPanelManager = Utils.defineClass({ 'changed::multi-monitors', 'changed::isolate-monitors', 'changed::panel-positions', + 'changed::panel-length', + 'changed::panel-anchor', 'changed::stockgs-keep-top-panel' ], () => this._reset() diff --git a/panelPositions.js b/panelPositions.js index 3c2d1af..3197d27 100644 --- a/panelPositions.js +++ b/panelPositions.js @@ -35,6 +35,10 @@ var BOTTOM = 'BOTTOM'; var LEFT = 'LEFT'; var RIGHT = 'RIGHT'; +var START = 'START'; +var MIDDLE = 'MIDDLE'; +var END = 'END'; + var defaults = [ { element: SHOW_APPS_BTN, visible: true, position: STACKED_TL }, { element: ACTIVITIES_BTN, visible: false, position: STACKED_TL }, diff --git a/prefs.js b/prefs.js index 4eeb162..8f9b3d5 100644 --- a/prefs.js +++ b/prefs.js @@ -770,7 +770,24 @@ const Settings = new Lang.Class({ if (this.monitors.length === 1) { this._builder.get_object('multimon_multi_switch').set_sensitive(false); } - + + // Length and position along screen edge + + // Minimum length could be 0, but a higher value may help prevent confusion about where the panel went. + let panel_length_min=10 + let panel_length_max=100 + let panel_length_spinbutton = this._builder.get_object('panel_length_spinbutton'); + panel_length_spinbutton.set_range(panel_length_min, panel_length_max); + panel_length_spinbutton.set_value(this._settings.get_int('panel-length')); + this._builder.get_object('panel_length_spinbutton').connect('value-changed', Lang.bind (this, function(widget) { + this._settings.set_int('panel-length', widget.get_value()); + })); + + this._builder.get_object('panel_anchor_combo').set_active_id(this._settings.get_string('panel-anchor')); + this._builder.get_object('panel_anchor_combo').connect('changed', Lang.bind (this, function(widget) { + this._settings.set_string('panel-anchor', widget.get_active_id()); + })); + //dynamic opacity this._settings.bind('trans-use-custom-bg', this._builder.get_object('trans_bg_switch'), diff --git a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml index c832084..b6f7257 100644 --- a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml +++ b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml @@ -40,6 +40,11 @@ + + + + + @@ -87,6 +92,16 @@ Panel element positions Panel element positions (JSON). + + 100 + Percentage of screen edge for panel to span + Set the length of the panel, in percent. Horizontal or vertical, according to panel orientation. + + + 'MIDDLE' + Position along screen edge + Where to show the panel if it is not the full length of the screen edge. + 48 Panel size