From f9ff267aa255d80a97357d449c71fe88cfb60304 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Sat, 14 Jun 2025 05:43:42 +0300 Subject: [PATCH] Add `truncate` option for `volume` popup --- docs/modules/Volume.md | 27 ++++++++++++++++++--------- src/modules/volume.rs | 11 ++++++++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/docs/modules/Volume.md b/docs/modules/Volume.md index afde862..0750603 100644 --- a/docs/modules/Volume.md +++ b/docs/modules/Volume.md @@ -1,6 +1,7 @@ Displays the current volume level. Clicking on the widget opens a volume mixer, which allows you to change the device output level, the default playback device, and control application volume levels individually. +Use `truncate` option to control the display of application titles in the volume mixer. This requires PulseAudio to function (`pipewire-pulse` is supported). @@ -10,14 +11,18 @@ This requires PulseAudio to function (`pipewire-pulse` is supported). > Type: `volume` -| Name | Type | Default | Description | -|-----------------------|----------|------------------------|----------------------------------------------------------------------------------------------------------------| -| `format` | `string` | `{icon} {percentage}%` | Format string to use for the widget button label. | -| `max_volume` | `float` | `100` | Maximum value to allow volume sliders to reach. Pulse supports values > 100 but this may result in distortion. | -| `icons.volume_high` | `string` | `󰕾` | Icon to show for high volume levels. | -| `icons.volume_medium` | `string` | `󰖀` | Icon to show for medium volume levels. | -| `icons.volume_low` | `string` | `󰕿` | Icon to show for low volume levels. | -| `icons.muted` | `string` | `󰝟` | Icon to show for muted outputs. | +| Name | Type | Default | Description | +|-----------------------|------------------------------------------------------|------------------------|----------------------------------------------------------------------------------------------------------------| +| `format` | `string` | `{icon} {percentage}%` | Format string to use for the widget button label. | +| `max_volume` | `float` | `100` | Maximum value to allow volume sliders to reach. Pulse supports values > 100 but this may result in distortion. | +| `icons.volume_high` | `string` | `󰕾` | Icon to show for high volume levels. | +| `icons.volume_medium` | `string` | `󰖀` | Icon to show for medium volume levels. | +| `icons.volume_low` | `string` | `󰕿` | Icon to show for low volume levels. | +| `icons.muted` | `string` | `󰝟` | Icon to show for muted outputs. | +| `truncate` | `'start'` or `'middle'` or `'end'` or `off` or `Map` | `off` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | +| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | +| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. | +| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
JSON @@ -29,6 +34,7 @@ This requires PulseAudio to function (`pipewire-pulse` is supported). "type": "volume", "format": "{icon} {percentage}%", "max_volume": 100, + "truncate": "middle", "icons": { "volume_high": "󰕾", "volume_medium": "󰖀", @@ -51,6 +57,7 @@ This requires PulseAudio to function (`pipewire-pulse` is supported). type = "volume" format = "{icon} {percentage}%" max_volume = 100 +truncate = "middle" [end.icons] volume_high = "󰕾" @@ -69,6 +76,7 @@ end: - type: "volume" format: "{icon} {percentage}%" max_volume: 100 + truncate: "middle" icons: volume_high: "󰕾" volume_medium: "󰖀" @@ -88,6 +96,7 @@ end: type = "volume" format = "{icon} {percentage}%" max_volume = 100 + truncate = "end" icons.volume_high = "󰕾" icons.volume_medium = "󰖀" icons.volume_low = "󰕿" @@ -125,4 +134,4 @@ The following tokens can be used in the `format` config option: | `.popup-volume .apps-box .app-box .slider` | Application volume slider. | | `.popup-volume .apps-box .app-box .btn-mute` | Application volume mute toggle button. | -For more information on styling, please see the [styling guide](styling-guide). \ No newline at end of file +For more information on styling, please see the [styling guide](styling-guide). diff --git a/src/modules/volume.rs b/src/modules/volume.rs index 32168cd..d8ac23c 100644 --- a/src/modules/volume.rs +++ b/src/modules/volume.rs @@ -1,6 +1,6 @@ use crate::channels::{AsyncSenderExt, BroadcastReceiverExt}; use crate::clients::volume::{self, Event}; -use crate::config::{CommonConfig, LayoutConfig}; +use crate::config::{CommonConfig, LayoutConfig, TruncateMode}; use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, @@ -39,6 +39,11 @@ pub struct VolumeModule { icons: Icons, // -- Common -- + /// See [truncate options](module-level-options#truncate-mode). + /// + /// **Default**: `null` + pub(crate) truncate: Option, + /// See [layout options](module-level-options#layout) #[serde(default, flatten)] layout: LayoutConfig, @@ -403,6 +408,10 @@ impl Module