Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added max title length option to window title component #533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading