From eb6366ef3e60cb380bf278639324bdbd828540a4 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Tue, 8 Apr 2025 00:02:36 -0400 Subject: [PATCH] Only persist primary monitor on selection #2278 --- src/panel.js | 9 ++++++++- src/panelManager.js | 4 +++- src/panelSettings.js | 16 ++++------------ src/prefs.js | 7 ++++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/panel.js b/src/panel.js index 09d3864..1491fc2 100644 --- a/src/panel.js +++ b/src/panel.js @@ -382,8 +382,10 @@ export const Panel = GObject.registerClass( this.set_offscreen_redirect(Clutter.OffscreenRedirect.ALWAYS) if (!Main.layoutManager._startingUp) - GLib.idle_add(GLib.PRIORITY_LOW, () => { + this._waitResetGeomId = GLib.idle_add(GLib.PRIORITY_LOW, () => { + this._waitResetGeomId = 0 this._resetGeometry() + return GLib.SOURCE_REMOVE }) } @@ -394,6 +396,11 @@ export const Panel = GObject.registerClass( this._timeoutsHandler.destroy() this._signalsHandler.destroy() + if (this._waitResetGeomId) { + GLib.remove_source(this._waitResetGeomId) + this._waitResetGeomId = 0 + } + this.panel.remove_child(this.taskbar.actor) if (this.intellihide) { diff --git a/src/panelManager.js b/src/panelManager.js index b6ce473..b5197cf 100755 --- a/src/panelManager.js +++ b/src/panelManager.js @@ -278,7 +278,9 @@ export const PanelManager = class { 'monitors-changed', async () => { if (Main.layoutManager.primaryMonitor) { - await PanelSettings.setMonitorsInfo(SETTINGS) + await PanelSettings.setMonitorsInfo(SETTINGS).catch((e) => + console.log(e), + ) this._reset() } }, diff --git a/src/panelSettings.js b/src/panelSettings.js index 86f4094..e21bf88 100644 --- a/src/panelSettings.js +++ b/src/panelSettings.js @@ -221,7 +221,7 @@ export function getPrimaryIndex(dtpPrimaryId) { return availableMonitors.findIndex((am) => am.primary) } -export async function setMonitorsInfo(settings) { +export function setMonitorsInfo(settings) { return new Promise((resolve, reject) => { try { let monitorInfos = [] @@ -229,7 +229,6 @@ export async function setMonitorsInfo(settings) { proxy.GetCurrentStateRemote((displayInfo, e) => { if (e) return reject(`Error getting display state: ${e}`) - let gsPrimaryIndex = 0 let ids = {} //https://gitlab.gnome.org/GNOME/mutter/-/blob/main/data/dbus-interfaces/org.gnome.Mutter.DisplayConfig.xml#L347 @@ -245,8 +244,6 @@ export async function setMonitorsInfo(settings) { if (ids[id]) id = connector && !ids[connector] ? connector : i - if (primary) gsPrimaryIndex = i - monitorInfos.push({ id, product, @@ -258,7 +255,7 @@ export async function setMonitorsInfo(settings) { ids[id] = 1 }) - _saveMonitors(settings, monitorInfos, gsPrimaryIndex) + _saveMonitors(settings, monitorInfos) resolve() }) @@ -282,19 +279,14 @@ export async function setMonitorsInfo(settings) { }) } -function _saveMonitors(settings, monitorInfos, gsPrimaryIndex) { +function _saveMonitors(settings, monitorInfos) { let keyPrimary = 'primary-monitor' let dtpPrimaryMonitor = settings.get_string(keyPrimary) // convert previously saved index to monitor id if (dtpPrimaryMonitor.match(/^\d{1,2}$/) && monitorInfos[dtpPrimaryMonitor]) - dtpPrimaryMonitor = monitorInfos[dtpPrimaryMonitor].id + settings.set_string(keyPrimary, monitorInfos[dtpPrimaryMonitor].id) - // default to gnome-shell primary monitor - if (!dtpPrimaryMonitor) - dtpPrimaryMonitor = monitorInfos[gsPrimaryIndex]?.id || 0 - - settings.set_string(keyPrimary, dtpPrimaryMonitor) availableMonitors = Object.freeze(monitorInfos) } diff --git a/src/prefs.js b/src/prefs.js index 448c449..0252b84 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -802,8 +802,10 @@ const Preferences = class { panelOptionsMonitorCombo.append_text(label) } + this._ignorePrimaryMonitorChange = true primaryCombo.set_active(dtpPrimaryMonitorIndex) panelOptionsMonitorCombo.set_active(dtpPrimaryMonitorIndex) + this._ignorePrimaryMonitorChange = false } _bindSettings() { @@ -1168,7 +1170,10 @@ const Preferences = class { this._builder .get_object('multimon_primary_combo') .connect('changed', (widget) => { - if (this.monitors[widget.get_active()]) + if ( + this.monitors[widget.get_active()] && + !this._ignorePrimaryMonitorChange + ) this._settings.set_string( 'primary-monitor', this.monitors[widget.get_active()].id,