From 6a9a13c50630c86908f70fe162c9b66469ee715c Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Wed, 6 Apr 2022 13:51:55 -0400 Subject: [PATCH] Reuse same monitor as primary if not GS primary --- panelManager.js | 31 +++++++++++++++++++++++++------ prefs.js | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/panelManager.js b/panelManager.js index 535dd9d1..59a456b5 100755 --- a/panelManager.js +++ b/panelManager.js @@ -249,7 +249,7 @@ var PanelManager = class { 'monitors-changed', () => { if (Main.layoutManager.primaryMonitor) { - this._saveMonitors(); + this._saveMonitors(true); this._reset(); } } @@ -400,17 +400,36 @@ var PanelManager = class { } } - _saveMonitors() { + _saveMonitors(savePrimaryChange) { //Mutter meta_monitor_manager_get_primary_monitor (global.display.get_primary_monitor()) doesn't return the same //monitor as GDK gdk_screen_get_primary_monitor (imports.gi.Gdk.Screen.get_default().get_primary_monitor()). //Since the Mutter function is what's used in gnome-shell and we can't access it from the settings dialog, store //the monitors information in a setting so we can use the same monitor indexes as the ones in gnome-shell + let keyMonitors = 'available-monitors'; let primaryIndex = Main.layoutManager.primaryIndex; - let monitors = [primaryIndex]; + let newMonitors = [primaryIndex]; - Main.layoutManager.monitors.filter(m => m.index != primaryIndex).forEach(m => monitors.push(m.index)); - Me.settings.set_value('available-monitors', new GLib.Variant('ai', monitors)); - Me.settings.set_int('primary-monitor', primaryIndex); + Main.layoutManager.monitors.filter(m => m.index != primaryIndex).forEach(m => newMonitors.push(m.index)); + + if (savePrimaryChange) { + let keyPrimary = 'primary-monitor'; + let savedMonitors = Me.settings.get_value(keyMonitors).deep_unpack(); + let dtpPrimaryIndex = Me.settings.get_int(keyPrimary); + let newDtpPrimaryIndex = primaryIndex; + + if (savedMonitors[0] != dtpPrimaryIndex) { + // dash to panel primary wasn't the gnome-shell primary (first index of available-monitors) + let savedIndex = savedMonitors.indexOf(dtpPrimaryIndex) + + // default to primary if it was set to a monitor that is no longer available + newDtpPrimaryIndex = newMonitors[savedIndex]; + newDtpPrimaryIndex = newDtpPrimaryIndex == null ? primaryIndex : newDtpPrimaryIndex; + } + + Me.settings.set_int(keyPrimary, newDtpPrimaryIndex); + } + + Me.settings.set_value(keyMonitors, new GLib.Variant('ai', newMonitors)); } checkIfFocusedMonitor(monitor) { diff --git a/prefs.js b/prefs.js index c07e8a96..4190a853 100644 --- a/prefs.js +++ b/prefs.js @@ -883,7 +883,7 @@ const Preferences = class { this._updateVerticalRelatedOptions(); for (let i = 0; i < this.monitors.length; ++i) { - //the primary index is the first one in the "available-monitors" setting + //the gnome-shell primary index is the first one in the "available-monitors" setting let label = !i ? _('Primary monitor') : _('Monitor ') + (i + 1); this._builder.get_object('multimon_primary_combo').append_text(label);