mirror of
https://github.com/morgan9e/dash-to-panel
synced 2026-04-14 00:04:17 +09:00
Prevent monitor id conflicts if no EDID
This commit is contained in:
@@ -578,7 +578,10 @@ export const Panel = GObject.registerClass(
|
||||
'changed::appicon-margin-toscreenborder',
|
||||
'changed::group-apps',
|
||||
],
|
||||
() => this._resetGeometry(),
|
||||
(settings, settingChanged) => {
|
||||
PanelSettings.clearCache(settingChanged)
|
||||
this._resetGeometry()
|
||||
},
|
||||
],
|
||||
[
|
||||
SETTINGS,
|
||||
|
||||
@@ -60,8 +60,9 @@ export const PanelManager = class {
|
||||
}
|
||||
|
||||
enable(reset) {
|
||||
let dtpPrimaryIndex =
|
||||
PanelSettings.monitorIdToIndex[SETTINGS.get_string('primary-monitor')]
|
||||
let dtpPrimaryIndex = PanelSettings.getPrimaryIndex(
|
||||
SETTINGS.get_string('primary-monitor'),
|
||||
)
|
||||
|
||||
this.allPanels = []
|
||||
this.dtpPrimaryMonitor =
|
||||
|
||||
@@ -38,11 +38,11 @@ const displayConfigWrapper = Gio.DBusProxy.makeProxyWrapper(
|
||||
let prefsOpenedId = null
|
||||
let useCache = false
|
||||
let cache = {}
|
||||
let monitorIdToIndex = {}
|
||||
let monitorIndexToId = {}
|
||||
|
||||
export var displayConfigProxy = null
|
||||
export var availableMonitors = []
|
||||
export var monitorIdToIndex = {}
|
||||
export var monitorIndexToId = {}
|
||||
|
||||
export async function init(settings) {
|
||||
useCache = true
|
||||
@@ -100,7 +100,12 @@ function getMonitorSetting(settings, settingName, monitorIndex, fallback) {
|
||||
|
||||
settings = getSettingsJson(settings, settingName)
|
||||
|
||||
return settings[monitorId] || settings[monitorIndex] || fallback
|
||||
return (
|
||||
settings[monitorId] ||
|
||||
settings[monitorIndex] ||
|
||||
settings[availableMonitors[monitorIndex]?.id] ||
|
||||
fallback
|
||||
)
|
||||
}
|
||||
|
||||
function setMonitorSetting(settings, settingName, monitorIndex, value) {
|
||||
@@ -205,6 +210,15 @@ export function setPanelElementPositions(settings, monitorIndex, value) {
|
||||
setMonitorSetting(settings, 'panel-element-positions', monitorIndex, value)
|
||||
}
|
||||
|
||||
export function getPrimaryIndex(dtpPrimaryId) {
|
||||
if (dtpPrimaryId in monitorIdToIndex) return monitorIdToIndex[dtpPrimaryId]
|
||||
|
||||
if (dtpPrimaryId.match(/^\d{1,2}$/) && availableMonitors[dtpPrimaryId])
|
||||
return dtpPrimaryId
|
||||
|
||||
return availableMonitors.findIndex((am) => am.primary)
|
||||
}
|
||||
|
||||
export async function setMonitorsInfo(settings) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@@ -214,22 +228,32 @@ export async function setMonitorsInfo(settings) {
|
||||
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
|
||||
displayInfo[2].forEach((logicalMonitor, i) => {
|
||||
let id = logicalMonitor[5][0][3]
|
||||
let [connector, vendor, product, serial] = logicalMonitor[5][0]
|
||||
let id = i
|
||||
let primary = logicalMonitor[4]
|
||||
|
||||
// if by any chance 2 monitors have the same id, use the connector string
|
||||
// instead, which should be unique but varies between x11 and wayland :(
|
||||
// worst case scenario, resort to using the dumbass index
|
||||
if (vendor && serial) id = `${vendor}-${serial}`
|
||||
|
||||
if (ids[id]) id = connector && !ids[connector] ? connector : i
|
||||
|
||||
if (primary) gsPrimaryIndex = i
|
||||
|
||||
monitorInfos.push({
|
||||
id,
|
||||
name: logicalMonitor[5][0][2],
|
||||
product,
|
||||
primary,
|
||||
})
|
||||
|
||||
monitorIdToIndex[id] = i
|
||||
monitorIndexToId[i] = id
|
||||
ids[id] = 1
|
||||
})
|
||||
|
||||
_saveMonitors(settings, monitorInfos, gsPrimaryIndex)
|
||||
@@ -261,11 +285,12 @@ function _saveMonitors(settings, monitorInfos, gsPrimaryIndex) {
|
||||
let dtpPrimaryMonitor = settings.get_string(keyPrimary)
|
||||
|
||||
// convert previously saved index to monitor id
|
||||
if (dtpPrimaryMonitor.match(/^\d{1,2}$/))
|
||||
dtpPrimaryMonitor = monitorInfos[dtpPrimaryMonitor]?.id
|
||||
if (dtpPrimaryMonitor.match(/^\d{1,2}$/) && monitorInfos[dtpPrimaryMonitor])
|
||||
dtpPrimaryMonitor = monitorInfos[dtpPrimaryMonitor].id
|
||||
|
||||
// default to gnome-shell primary monitor
|
||||
if (!dtpPrimaryMonitor) dtpPrimaryMonitor = monitorInfos[gsPrimaryIndex]?.id
|
||||
if (!dtpPrimaryMonitor)
|
||||
dtpPrimaryMonitor = monitorInfos[gsPrimaryIndex]?.id || 0
|
||||
|
||||
settings.set_string(keyPrimary, dtpPrimaryMonitor)
|
||||
availableMonitors = Object.freeze(monitorInfos)
|
||||
|
||||
18
src/prefs.js
18
src/prefs.js
@@ -348,7 +348,9 @@ const Preferences = class {
|
||||
const monitorSync = this._settings.get_boolean(
|
||||
'panel-element-positions-monitors-sync',
|
||||
)
|
||||
const monitorsToSetFor = monitorSync ? this.monitors : [currentMonitorIndex]
|
||||
const monitorsToSetFor = monitorSync
|
||||
? Object.keys(this.monitors)
|
||||
: [currentMonitorIndex]
|
||||
const allVertical = monitorsToSetFor.every((i) => {
|
||||
const position = PanelSettings.getPanelPosition(this._settings, i)
|
||||
return position === Pos.LEFT || position === Pos.RIGHT
|
||||
@@ -780,6 +782,12 @@ const Preferences = class {
|
||||
return value + ' px'
|
||||
})
|
||||
|
||||
this._builder
|
||||
.get_object('panel_length_scale')
|
||||
.set_format_value_func((scale, value) => {
|
||||
return value + ' %'
|
||||
})
|
||||
|
||||
// style
|
||||
this._builder
|
||||
.get_object('appicon_margin_scale')
|
||||
@@ -889,7 +897,7 @@ const Preferences = class {
|
||||
)
|
||||
let dtpPrimaryMonitorId = this._settings.get_string('primary-monitor')
|
||||
let dtpPrimaryMonitorIndex =
|
||||
PanelSettings.monitorIdToIndex[dtpPrimaryMonitorId]
|
||||
PanelSettings.getPrimaryIndex(dtpPrimaryMonitorId)
|
||||
|
||||
this._currentMonitorIndex = dtpPrimaryMonitorIndex
|
||||
|
||||
@@ -904,7 +912,7 @@ const Preferences = class {
|
||||
? _('Primary monitor')
|
||||
: _('Monitor ') + (i + 1)
|
||||
|
||||
label += monitor.name ? ` (${monitor.name})` : ''
|
||||
label += monitor.product ? ` (${monitor.product})` : ''
|
||||
|
||||
primaryCombo.append_text(label)
|
||||
panelOptionsMonitorCombo.append_text(label)
|
||||
@@ -3539,7 +3547,7 @@ const Preferences = class {
|
||||
revealDonateTimeout = setTimeout(() => {
|
||||
donationRevealer.set_reveal_child(true)
|
||||
donationSpinner.set_spinning(false)
|
||||
}, 20000)
|
||||
}, 18000)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3674,7 +3682,7 @@ const BuilderScope = GObject.registerClass(
|
||||
'panel-element-positions-monitors-sync',
|
||||
)
|
||||
const monitorsToSetFor = monitorSync
|
||||
? this._preferences.monitors
|
||||
? Object.keys(this._preferences.monitors)
|
||||
: [this._preferences._currentMonitorIndex]
|
||||
monitorsToSetFor.forEach((monitorIndex) => {
|
||||
PanelSettings.setPanelSize(
|
||||
|
||||
@@ -90,10 +90,10 @@ let donateDummyApp = {
|
||||
},
|
||||
activate: function () {
|
||||
SETTINGS.set_string('target-prefs-page', 'donation')
|
||||
DTP_EXTENSION.openPreferences()
|
||||
|
||||
if (this.isActive()) return
|
||||
|
||||
DTP_EXTENSION.openPreferences()
|
||||
this._taskbar._timeoutsHandler.add([T4, 5000, this.forceRefresh.bind(this)])
|
||||
this.forceRefresh()
|
||||
},
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
<object class="GtkAdjustment" id="panel_length_adjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">1</property>
|
||||
<property name="page_increment">10</property>
|
||||
<property name="step_increment">0.01</property>
|
||||
<property name="page_increment">0.1</property>
|
||||
</object>
|
||||
|
||||
<object class="AdwPreferencesPage" id="position">
|
||||
|
||||
Reference in New Issue
Block a user