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
This commit is contained in:
MarkS
2020-07-31 15:58:33 -06:00
parent 1784adaef2
commit 0a066890cb
6 changed files with 133 additions and 4 deletions

View File

@@ -2,6 +2,11 @@
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="appicon_margin_adjustment">
<property name="lower">0.33</property>
<property name="upper">1</property>
@@ -4801,6 +4806,69 @@
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="panel_length_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">Length along screen edge, in percent</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="panel_length_spinbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="width_chars">5</property>
<property name="text">100</property>
<property name="adjustment">adjustment1</property>
<property name="numeric">True</property>
<property name="value">100</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="panel_anchor_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">Position along screen edge</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="panel_anchor_combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<items>
<item id="START" translatable="yes">Start</item>
<item id="MIDDLE" translatable="yes">Middle</item>
<item id="END" translatable="yes">End</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<placeholder/>
</child>

View File

@@ -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;
}
@@ -840,6 +843,26 @@ var dtpPanel = Utils.defineClass({
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,

View File

@@ -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()

View File

@@ -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 },

View File

@@ -771,6 +771,23 @@ const Settings = new Lang.Class({
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'),

View File

@@ -40,6 +40,11 @@
<value value='2' nick='LEFT'/>
<value value='3' nick='RIGHT'/>
</enum>
<enum id='org.gnome.shell.extensions.dash-to-panel.anchor'>
<value value='0' nick='START'/>
<value value='1' nick='MIDDLE'/>
<value value='2' nick='END'/>
</enum>
<enum id='org.gnome.shell.extensions.dash-to-panel.proximityBehavior'>
<value value='0' nick='ALL_WINDOWS'/>
<value value='1' nick='FOCUSED_WINDOWS'/>
@@ -87,6 +92,16 @@
<summary>Panel element positions</summary>
<description>Panel element positions (JSON).</description>
</key>
<key type="i" name="panel-length">
<default>100</default>
<summary>Percentage of screen edge for panel to span</summary>
<description>Set the length of the panel, in percent. Horizontal or vertical, according to panel orientation.</description>
</key>
<key name="panel-anchor" enum="org.gnome.shell.extensions.dash-to-panel.anchor">
<default>'MIDDLE'</default>
<summary>Position along screen edge</summary>
<description>Where to show the panel if it is not the full length of the screen edge.</description>
</key>
<key type="i" name="panel-size">
<default>48</default>
<summary>Panel size</summary>