1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

displays: allow filtering by model over name

This commit is contained in:
bbedward
2025-11-16 13:58:33 -05:00
parent f6db20cd06
commit 6f359df8f9
3 changed files with 124 additions and 37 deletions

View File

@@ -327,6 +327,7 @@ Singleton {
property string updaterCustomCommand: "" property string updaterCustomCommand: ""
property string updaterTerminalAdditionalParams: "" property string updaterTerminalAdditionalParams: ""
property string displayNameMode: "system"
property var screenPreferences: ({}) property var screenPreferences: ({})
property var showOnLastDisplay: ({}) property var showOnLastDisplay: ({})
@@ -637,12 +638,35 @@ rm -rf '${home}'/.cache/icon-cache '${home}'/.cache/thumbnails 2>/dev/null || tr
return { "x": 0, "y": 0, "width": 0, "height": 0, "wingSize": 0 } return { "x": 0, "y": 0, "width": 0, "height": 0, "wingSize": 0 }
} }
function getScreenDisplayName(screen) {
if (!screen) return ""
if (displayNameMode === "model" && screen.model) {
return screen.model
}
return screen.name
}
function isScreenInPreferences(screen, prefs) {
if (!screen) return false
return prefs.some(pref => {
if (typeof pref === "string") {
return pref === "all" || pref === screen.name || pref === screen.model
}
if (displayNameMode === "model") {
return pref.model && screen.model && pref.model === screen.model
}
return pref.name === screen.name
})
}
function getFilteredScreens(componentId) { function getFilteredScreens(componentId) {
var prefs = screenPreferences && screenPreferences[componentId] || ["all"] var prefs = screenPreferences && screenPreferences[componentId] || ["all"]
if (prefs.includes("all")) { if (prefs.includes("all") || (typeof prefs[0] === "string" && prefs[0] === "all")) {
return Quickshell.screens return Quickshell.screens
} }
var filtered = Quickshell.screens.filter(screen => prefs.includes(screen.name)) var filtered = Quickshell.screens.filter(screen => isScreenInPreferences(screen, prefs))
if (filtered.length === 0 && showOnLastDisplay && showOnLastDisplay[componentId] && Quickshell.screens.length === 1) { if (filtered.length === 0 && showOnLastDisplay && showOnLastDisplay[componentId] && Quickshell.screens.length === 1) {
return Quickshell.screens return Quickshell.screens
} }

View File

@@ -237,6 +237,7 @@ var SPEC = {
updaterCustomCommand: { def: "" }, updaterCustomCommand: { def: "" },
updaterTerminalAdditionalParams: { def: "" }, updaterTerminalAdditionalParams: { def: "" },
displayNameMode: { def: "system" },
screenPreferences: { def: {} }, screenPreferences: { def: {} },
showOnLastDisplay: { def: {} } showOnLastDisplay: { def: {} }
}; };

View File

@@ -542,11 +542,57 @@ Item {
width: parent.width width: parent.width
spacing: Theme.spacingS spacing: Theme.spacingS
StyledText { Column {
text: I18n.tr("Available Screens (") + Quickshell.screens.length + ")" width: parent.width
font.pixelSize: Theme.fontSizeMedium spacing: Theme.spacingXS
font.weight: Font.Medium
color: Theme.surfaceText Row {
width: parent.width
spacing: Theme.spacingM
StyledText {
text: I18n.tr("Available Screens (") + Quickshell.screens.length + ")"
font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium
color: Theme.surfaceText
}
Item {
width: 1
height: 1
Layout.fillWidth: true
}
Column {
spacing: Theme.spacingXS
anchors.verticalCenter: parent.verticalCenter
StyledText {
text: I18n.tr("Display Name Format")
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
anchors.horizontalCenter: parent.horizontalCenter
}
DankButtonGroup {
id: displayModeGroup
model: [I18n.tr("Name"), I18n.tr("Model")]
currentIndex: SettingsData.displayNameMode === "model" ? 1 : 0
onSelectionChanged: (index, selected) => {
if (!selected) return
SettingsData.displayNameMode = index === 1 ? "model" : "system"
SettingsData.saveSettings()
}
Connections {
target: SettingsData
function onDisplayNameModeChanged() {
displayModeGroup.currentIndex = SettingsData.displayNameMode === "model" ? 1 : 0
}
}
}
}
}
} }
Repeater { Repeater {
@@ -580,7 +626,7 @@ Item {
spacing: Theme.spacingXS / 2 spacing: Theme.spacingXS / 2
StyledText { StyledText {
text: modelData.name text: SettingsData.getScreenDisplayName(modelData)
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium font.weight: Font.Medium
color: Theme.surfaceText color: Theme.surfaceText
@@ -602,7 +648,7 @@ Item {
} }
StyledText { StyledText {
text: modelData.model || "Unknown Model" text: SettingsData.displayNameMode === "system" ? (modelData.model || "Unknown Model") : modelData.name
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText color: Theme.surfaceVariantText
} }
@@ -701,14 +747,17 @@ Item {
width: parent.width width: parent.width
text: I18n.tr("All displays") text: I18n.tr("All displays")
description: I18n.tr("Show on all connected displays") description: I18n.tr("Show on all connected displays")
checked: displaysTab.getScreenPreferences(parent.componentId).includes("all") checked: {
var prefs = displaysTab.getScreenPreferences(parent.componentId)
return prefs.includes("all") || (typeof prefs[0] === "string" && prefs[0] === "all")
}
onToggled: (checked) => { onToggled: (checked) => {
if (checked) { if (checked) {
displaysTab.setScreenPreferences(parent.componentId, ["all"]); displaysTab.setScreenPreferences(parent.componentId, ["all"])
} else { } else {
displaysTab.setScreenPreferences(parent.componentId, []); displaysTab.setScreenPreferences(parent.componentId, [])
if (["dankBar", "dock", "notifications", "osd", "toast"].includes(parent.componentId)) { if (["dankBar", "dock", "notifications", "osd", "toast"].includes(parent.componentId)) {
displaysTab.setShowOnLastDisplay(parent.componentId, true); displaysTab.setShowOnLastDisplay(parent.componentId, true)
} }
} }
} }
@@ -719,9 +768,13 @@ Item {
text: I18n.tr("Show on Last Display") text: I18n.tr("Show on Last Display")
description: I18n.tr("Always show when there's only one connected display") description: I18n.tr("Always show when there's only one connected display")
checked: displaysTab.getShowOnLastDisplay(parent.componentId) checked: displaysTab.getShowOnLastDisplay(parent.componentId)
visible: !displaysTab.getScreenPreferences(parent.componentId).includes("all") && ["dankBar", "dock", "notifications", "osd", "toast", "notepad", "systemTray"].includes(parent.componentId) visible: {
var prefs = displaysTab.getScreenPreferences(parent.componentId)
var isAll = prefs.includes("all") || (typeof prefs[0] === "string" && prefs[0] === "all")
return !isAll && ["dankBar", "dock", "notifications", "osd", "toast", "notepad", "systemTray"].includes(parent.componentId)
}
onToggled: (checked) => { onToggled: (checked) => {
displaysTab.setShowOnLastDisplay(parent.componentId, checked); displaysTab.setShowOnLastDisplay(parent.componentId, checked)
} }
} }
@@ -730,45 +783,54 @@ Item {
height: 1 height: 1
color: Theme.outline color: Theme.outline
opacity: 0.2 opacity: 0.2
visible: !displaysTab.getScreenPreferences(parent.componentId).includes("all") visible: {
var prefs = displaysTab.getScreenPreferences(parent.componentId)
return !prefs.includes("all") && !(typeof prefs[0] === "string" && prefs[0] === "all")
}
} }
Column { Column {
width: parent.width width: parent.width
spacing: Theme.spacingXS spacing: Theme.spacingXS
visible: !displaysTab.getScreenPreferences(parent.componentId).includes("all") visible: {
var prefs = displaysTab.getScreenPreferences(parent.componentId)
return !prefs.includes("all") && !(typeof prefs[0] === "string" && prefs[0] === "all")
}
Repeater { Repeater {
model: Quickshell.screens model: Quickshell.screens
delegate: DankToggle { delegate: DankToggle {
property string screenName: modelData.name property var screenData: modelData
property string componentId: parent.parent.componentId property string componentId: parent.parent.componentId
width: parent.width width: parent.width
text: screenName text: SettingsData.getScreenDisplayName(screenData)
description: modelData.width + "×" + modelData.height + " • " + (modelData.model || "Unknown Model") description: screenData.width + "×" + screenData.height + " • " + (SettingsData.displayNameMode === "system" ? (screenData.model || "Unknown Model") : screenData.name)
checked: { checked: {
var prefs = displaysTab.getScreenPreferences(componentId); var prefs = displaysTab.getScreenPreferences(componentId)
return !prefs.includes("all") && prefs.includes(screenName); if (typeof prefs[0] === "string" && prefs[0] === "all") return false
return SettingsData.isScreenInPreferences(screenData, prefs)
} }
onToggled: (checked) => { onToggled: (checked) => {
var currentPrefs = displaysTab.getScreenPreferences(componentId); var currentPrefs = displaysTab.getScreenPreferences(componentId)
if (currentPrefs.includes("all")) if (typeof currentPrefs[0] === "string" && currentPrefs[0] === "all") {
currentPrefs = []; currentPrefs = []
var newPrefs = currentPrefs.slice();
if (checked) {
if (!newPrefs.includes(screenName))
newPrefs.push(screenName);
} else {
var index = newPrefs.indexOf(screenName);
if (index > -1)
newPrefs.splice(index, 1);
} }
displaysTab.setScreenPreferences(componentId, newPrefs);
var newPrefs = currentPrefs.filter(pref => {
if (typeof pref === "string") return false
return pref.name !== screenData.name || pref.model !== screenData.model
})
if (checked) {
newPrefs.push({
name: screenData.name,
model: screenData.model || ""
})
}
displaysTab.setScreenPreferences(componentId, newPrefs)
} }
} }