Skip to content

Commit

Permalink
Added MaxTitleLength to WindowTitle Component.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParasiteDelta committed Feb 5, 2024
1 parent 33c8a38 commit 041266c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions GlazeWM.Bar/Components/WindowTitleComponentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ private LabelViewModel CreateLabel(string windowTitle)
{
var variableDictionary = new Dictionary<string, Func<string>>()
{
// 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);
}

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;
}
Expand Down
5 changes: 5 additions & 0 deletions GlazeWM.Domain/UserConfigs/WindowTitleComponentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public class WindowTitleComponentConfig : BarComponentConfig
/// Label assigned to the window title component.
/// </summary>
public string Label { get; set; } = "{window_title}";

/// <summary>
/// The maximum length after which the window title will be truncated; if set to -1, the title will not be truncated.
/// </summary>
public int MaxTitleLength { get; set; } = 60;
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <attr> tag:
Expand Down

0 comments on commit 041266c

Please sign in to comment.