From 612dc58ad8c3e736b91b022e6269cc39761303a9 Mon Sep 17 00:00:00 2001 From: lysec Date: Fri, 24 Oct 2025 14:16:02 +0200 Subject: [PATCH] WorkspaceSettings: add setting to change the amount of characters displayed for name workspaces Workspace: change pill width depending on characterCount --- Assets/Translations/de.json | 4 ++++ Assets/Translations/en.json | 4 ++++ Assets/Translations/es.json | 4 ++++ Assets/Translations/fr.json | 4 ++++ Assets/Translations/pt.json | 4 ++++ Assets/Translations/zh-CN.json | 4 ++++ Assets/settings-default.json | 3 ++- Modules/Bar/Widgets/Workspace.qml | 14 ++++++++++++-- .../Bar/WidgetSettings/WorkspaceSettings.qml | 19 +++++++++++++++++++ Services/BarWidgetRegistry.qml | 3 ++- 10 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index e869f6f91..65904b164 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -1057,6 +1057,10 @@ "hide-unoccupied": { "label": "Unbesetzte ausblenden", "description": "Arbeitsbereiche ohne Fenster nicht anzeigen." + }, + "character-count": { + "label": "Zeichenanzahl", + "description": "Anzahl der Zeichen, die von Arbeitsbereichsnamen angezeigt werden (1-10)." } }, "microphone": { diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index f34f59b36..9b590938e 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -1040,6 +1040,10 @@ "hide-unoccupied": { "label": "Hide unoccupied", "description": "Don't display workspaces without windows." + }, + "character-count": { + "label": "Character count", + "description": "Number of characters to display from workspace names (1-10)." } }, "microphone": { diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index 29c055ecf..64f84c665 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -1040,6 +1040,10 @@ "hide-unoccupied": { "label": "Ocultar desocupados", "description": "No mostrar espacios de trabajo sin ventanas." + }, + "character-count": { + "label": "Número de caracteres", + "description": "Número de caracteres a mostrar de los nombres de espacios de trabajo (1-10)." } }, "microphone": { diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index d367abd5b..c57e49388 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -1040,6 +1040,10 @@ "hide-unoccupied": { "label": "Masquer les inoccupés", "description": "Ne pas afficher les espaces de travail sans fenêtres." + }, + "character-count": { + "label": "Nombre de caractères", + "description": "Nombre de caractères à afficher des noms d'espaces de travail (1-10)." } }, "microphone": { diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index addddd367..ad6f88f4b 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -1040,6 +1040,10 @@ "hide-unoccupied": { "label": "Ocultar desocupados", "description": "Não exibir áreas de trabalho sem janelas." + }, + "character-count": { + "label": "Número de caracteres", + "description": "Número de caracteres a exibir dos nomes de espaços de trabalho (1-10)." } }, "microphone": { diff --git a/Assets/Translations/zh-CN.json b/Assets/Translations/zh-CN.json index 35c52c51c..2a34c7a8a 100644 --- a/Assets/Translations/zh-CN.json +++ b/Assets/Translations/zh-CN.json @@ -1040,6 +1040,10 @@ "hide-unoccupied": { "label": "隐藏未占用", "description": "不显示没有窗口的工作区。" + }, + "character-count": { + "label": "字符数量", + "description": "显示工作区名称的字符数量(1-10)。" } }, "microphone": { diff --git a/Assets/settings-default.json b/Assets/settings-default.json index 487bb850d..69787fe8b 100644 --- a/Assets/settings-default.json +++ b/Assets/settings-default.json @@ -24,7 +24,8 @@ ], "center": [ { - "id": "Workspace" + "id": "Workspace", + "characterCount": 2 } ], "right": [ diff --git a/Modules/Bar/Widgets/Workspace.qml b/Modules/Bar/Widgets/Workspace.qml index 96c301f6f..b1c793fb1 100644 --- a/Modules/Bar/Widgets/Workspace.qml +++ b/Modules/Bar/Widgets/Workspace.qml @@ -44,6 +44,7 @@ Item { readonly property string labelMode: (widgetSettings.labelMode !== undefined) ? widgetSettings.labelMode : widgetMetadata.labelMode readonly property bool hideUnoccupied: (widgetSettings.hideUnoccupied !== undefined) ? widgetSettings.hideUnoccupied : widgetMetadata.hideUnoccupied + readonly property int characterCount: (widgetSettings.characterCount !== undefined) ? widgetSettings.characterCount : widgetMetadata.characterCount property bool isDestroying: false property bool hovered: false @@ -68,6 +69,15 @@ Item { function getWorkspaceWidth(ws) { const d = Style.capsuleHeight * root.baseDimensionRatio const factor = ws.isActive ? 2.2 : 1 + + // For name mode, calculate width based on actual text content + if (labelMode === "name" && ws.name && ws.name.length > 0) { + const displayText = ws.name.substring(0, characterCount) + const textWidth = displayText.length * (d * 0.4) // Approximate width per character + const padding = d * 0.6 // Padding on both sides + return Math.max(d * factor, textWidth + padding) + } + return d * factor } @@ -279,7 +289,7 @@ Item { y: (pill.height - height) / 2 + (height - contentHeight) / 2 text: { if (labelMode === "name" && model.name && model.name.length > 0) { - return model.name.substring(0, 2) + return model.name.substring(0, characterCount) } else { return model.idx.toString() } @@ -424,7 +434,7 @@ Item { y: (pillVertical.height - height) / 2 + (height - contentHeight) / 2 text: { if (labelMode === "name" && model.name && model.name.length > 0) { - return model.name.substring(0, 2) + return model.name.substring(0, characterCount) } else { return model.idx.toString() } diff --git a/Modules/Settings/Bar/WidgetSettings/WorkspaceSettings.qml b/Modules/Settings/Bar/WidgetSettings/WorkspaceSettings.qml index fb63a5931..6762549c5 100644 --- a/Modules/Settings/Bar/WidgetSettings/WorkspaceSettings.qml +++ b/Modules/Settings/Bar/WidgetSettings/WorkspaceSettings.qml @@ -17,6 +17,7 @@ ColumnLayout { var settings = Object.assign({}, widgetData || {}) settings.labelMode = labelModeCombo.currentKey settings.hideUnoccupied = hideUnoccupiedToggle.checked + settings.characterCount = characterCountSpinBox.value return settings } @@ -47,4 +48,22 @@ ColumnLayout { checked: widgetData.hideUnoccupied onToggled: checked => hideUnoccupiedToggle.checked = checked } + + NSpinBox { + id: characterCountSpinBox + label: I18n.tr("bar.widget-settings.workspace.character-count.label") + description: I18n.tr("bar.widget-settings.workspace.character-count.description") + from: 1 + to: 10 + value: { + if (widgetData && widgetData.characterCount !== undefined) { + return widgetData.characterCount + } + if (widgetMetadata && widgetMetadata.characterCount !== undefined) { + return widgetMetadata.characterCount + } + return 2 + } + visible: labelModeCombo.currentKey === "name" + } } diff --git a/Services/BarWidgetRegistry.qml b/Services/BarWidgetRegistry.qml index 821db6408..4e8b5621d 100644 --- a/Services/BarWidgetRegistry.qml +++ b/Services/BarWidgetRegistry.qml @@ -146,7 +146,8 @@ Singleton { "Workspace": { "allowUserSettings": true, "labelMode": "index", - "hideUnoccupied": false + "hideUnoccupied": false, + "characterCount": 2 }, "Volume": { "allowUserSettings": true,