Skip to content

Commit

Permalink
Reuse same monitor as primary if not GS primary
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesg99 committed Apr 6, 2022
1 parent 6697819 commit 6a9a13c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions panelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ var PanelManager = class {
'monitors-changed',
() => {
if (Main.layoutManager.primaryMonitor) {
this._saveMonitors();
this._saveMonitors(true);
this._reset();
}
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6a9a13c

Please sign in to comment.