From 041266c0bbc23f679c1192c29f32891f5d176945 Mon Sep 17 00:00:00 2001 From: ParasiteDelta Date: Mon, 5 Feb 2024 16:03:03 -0700 Subject: [PATCH] Added MaxTitleLength to WindowTitle Component. --- .../Components/WindowTitleComponentViewModel.cs | 5 ++--- .../UserConfigs/WindowTitleComponentConfig.cs | 5 +++++ README.md | 10 ++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/GlazeWM.Bar/Components/WindowTitleComponentViewModel.cs b/GlazeWM.Bar/Components/WindowTitleComponentViewModel.cs index e098c5955..c84fcd08b 100644 --- a/GlazeWM.Bar/Components/WindowTitleComponentViewModel.cs +++ b/GlazeWM.Bar/Components/WindowTitleComponentViewModel.cs @@ -56,8 +56,7 @@ private LabelViewModel CreateLabel(string windowTitle) { var variableDictionary = new Dictionary>() { - // TODO: Make truncate max length configurable from config. - { "window_title", () => Truncate(windowTitle, 60) } + { "window_title", () => Truncate(windowTitle, _config.MaxTitleLength) } }; return XamlHelper.ParseLabel(_config.Label, variableDictionary, this); @@ -65,7 +64,7 @@ private LabelViewModel CreateLabel(string windowTitle) public static string Truncate(string value, int maxLength, string truncationSuffix = "…") { - return value?.Length > maxLength + return value?.Length > maxLength && maxLength >= 0 ? string.Concat(value.AsSpan(0, maxLength), truncationSuffix) : value; } diff --git a/GlazeWM.Domain/UserConfigs/WindowTitleComponentConfig.cs b/GlazeWM.Domain/UserConfigs/WindowTitleComponentConfig.cs index 66132ed17..14a7ed296 100644 --- a/GlazeWM.Domain/UserConfigs/WindowTitleComponentConfig.cs +++ b/GlazeWM.Domain/UserConfigs/WindowTitleComponentConfig.cs @@ -6,5 +6,10 @@ public class WindowTitleComponentConfig : BarComponentConfig /// Label assigned to the window title component. /// public string Label { get; set; } = "{window_title}"; + + /// + /// The maximum length after which the window title will be truncated; if set to -1, the title will not be truncated. + /// + public int MaxTitleLength { get; set; } = 60; } } diff --git a/README.md b/README.md index 6a9cf376c..779fa2edf 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,7 @@ Using the example of padding: - [Image](#bar-component-image) - [System Tray](#bar-component-system-tray) - [Music](#bar-component-music) +- [Title](#bar-component-title) #### Bar component: Clock @@ -498,6 +499,15 @@ Displays currently playing music. max_artist_length: 20 ``` +#### Bar component: Title + +Displays the window title of the currently-selected window. + +```yaml +- type: "window title" + max_title_length: 60 +``` + ## Mixing font properties within a label Font family, font weight, font size, and foreground color can be changed within parts of a label. This means that icons and text fonts can be used together in a label. To customize a part of the label, wrap it in an tag: