Update prefs dialog on monitors change

This commit is contained in:
Charles Gagnon
2025-02-07 09:22:53 -05:00
parent 0e3cee376c
commit 9b39d5cc96
2 changed files with 51 additions and 35 deletions

View File

@@ -22,6 +22,7 @@ import * as Pos from './panelPositions.js'
const displayConfigWrapper = Gio.DBusProxy.makeProxyWrapper(
`<node>
<interface name="org.gnome.Mutter.DisplayConfig">
<signal name="MonitorsChanged" />
<method name="GetCurrentState">
<arg name="serial" direction="out" type="u" />
<arg name="monitors" direction="out" type="a((ssss)a(siiddada{sv})a{sv})" />
@@ -34,11 +35,11 @@ const displayConfigWrapper = Gio.DBusProxy.makeProxyWrapper(
// the module variables here are different in the settings dialog (gjs process)
// and in gnome-shell (gnome-shell process)
let displayConfigProxy = null
let prefsOpenedId = null
let useCache = false
let cache = {}
export var displayConfigProxy = null
export var availableMonitors = []
export var monitorIdToIndex = {}
export var monitorIndexToId = {}

View File

@@ -880,6 +880,40 @@ const Preferences = class {
})
}
_setMonitorsInfo() {
this.monitors = PanelSettings.availableMonitors
let primaryCombo = this._builder.get_object('multimon_primary_combo')
let panelOptionsMonitorCombo = this._builder.get_object(
'taskbar_position_monitor_combo',
)
let dtpPrimaryMonitorId = this._settings.get_string('primary-monitor')
let dtpPrimaryMonitorIndex =
PanelSettings.monitorIdToIndex[dtpPrimaryMonitorId]
this._currentMonitorIndex = dtpPrimaryMonitorIndex
this._updateVerticalRelatedOptions()
primaryCombo.remove_all()
panelOptionsMonitorCombo.remove_all()
for (let i = 0; i < this.monitors.length; ++i) {
let monitor = this.monitors[i]
let label = monitor.primary
? _('Primary monitor')
: _('Monitor ') + (i + 1)
label += monitor.name ? ` (${monitor.name})` : ''
primaryCombo.append_text(label)
panelOptionsMonitorCombo.append_text(label)
}
primaryCombo.set_active(dtpPrimaryMonitorIndex)
panelOptionsMonitorCombo.set_active(dtpPrimaryMonitorIndex)
}
_bindSettings() {
// size options
let panel_size_scale = this._builder.get_object('panel_size_scale')
@@ -1232,39 +1266,11 @@ const Preferences = class {
})
//multi-monitor
this.monitors = PanelSettings.availableMonitors
let dtpPrimaryMonitorId = this._settings.get_string('primary-monitor')
let dtpPrimaryMonitorIndex =
PanelSettings.monitorIdToIndex[dtpPrimaryMonitorId]
this._currentMonitorIndex = dtpPrimaryMonitorIndex
this._setMonitorsInfo()
this._settings.connect('changed::panel-positions', () =>
this._updateVerticalRelatedOptions(),
)
this._updateVerticalRelatedOptions()
for (let i = 0; i < this.monitors.length; ++i) {
let monitor = this.monitors[i]
let label = monitor.primary
? _('Primary monitor')
: _('Monitor ') + (i + 1)
label += monitor.name ? ` (${monitor.name})` : ''
this._builder.get_object('multimon_primary_combo').append_text(label)
this._builder
.get_object('taskbar_position_monitor_combo')
.append_text(label)
}
this._builder
.get_object('multimon_primary_combo')
.set_active(dtpPrimaryMonitorIndex)
this._builder
.get_object('taskbar_position_monitor_combo')
.set_active(dtpPrimaryMonitorIndex)
this._settings.bind(
'panel-element-positions-monitors-sync',
@@ -1292,10 +1298,11 @@ const Preferences = class {
this._builder
.get_object('multimon_primary_combo')
.connect('changed', (widget) => {
this._settings.set_string(
'primary-monitor',
this.monitors[widget.get_active()].id,
)
if (this.monitors[widget.get_active()])
this._settings.set_string(
'primary-monitor',
this.monitors[widget.get_active()].id,
)
})
this._builder
@@ -3865,6 +3872,14 @@ export default class DashToPanelPreferences extends ExtensionPreferences {
await PanelSettings.setMonitorsInfo(window._settings)
new Preferences(window, window._settings, this.path)
PanelSettings.displayConfigProxy.connectSignal(
'MonitorsChanged',
async () => {
await PanelSettings.setMonitorsInfo(window._settings)
preferences._setMonitorsInfo()
},
)
let preferences = new Preferences(window, window._settings, this.path)
}
}