Reuse same monitor as primary if not GS primary

This commit is contained in:
Charles Gagnon
2022-04-06 13:51:55 -04:00
parent 669781996b
commit 6a9a13c506
2 changed files with 26 additions and 7 deletions

View File

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

View File

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