Merge pull request #5060 from EzequielColungaAcha/fix-wlr-taskbar-title-ellipsize

fix(wlr/taskbar): let task titles shrink within available space
This commit is contained in:
Alexis Rouillard
2026-07-03 21:51:06 +02:00
committed by GitHub
2 changed files with 43 additions and 4 deletions
+5
View File
@@ -57,6 +57,11 @@ Addressed by *wlr/taskbar*
default: false ++ default: false ++
If set to true, group tasks by their app_id. Cannot be used with 'active-first'. If set to true, group tasks by their app_id. Cannot be used with 'active-first'.
*expand*: ++
typeof: bool ++
default: false ++
If set to true, task buttons stretch to fill the available space in the taskbar and long titles are ellipsized to fit. Only takes effect on a horizontal bar; on a vertical bar the buttons keep their content-based size. If set to false, buttons are sized to their content.
*on-click*: ++ *on-click*: ++
typeof: string ++ typeof: string ++
The action which should be triggered when clicking on the application button with the left mouse button. The action which should be triggered when clicking on the application button with the left mouse button.
+34
View File
@@ -94,9 +94,35 @@ Task::Task(const waybar::Bar& bar, const Json::Value& config, Taskbar* tbar,
button.set_relief(Gtk::RELIEF_NONE); button.set_relief(Gtk::RELIEF_NONE);
/* When "expand" is enabled the buttons stretch to fill the taskbar and the
* titles ellipsize to fit within the available space. This only makes sense
* on a horizontal bar; on a vertical bar the box grows along the vertical
* axis, so ellipsizing/forcing width_chars(1) would truncate every title to
* "…". Keep the historical behavior (buttons sized to their content) as the
* default and when the bar is vertical. */
bool expand = config_["expand"].isBool() && config_["expand"].asBool();
bool horizontal = bar.orientation == Gtk::ORIENTATION_HORIZONTAL;
if (expand && horizontal) {
button.set_hexpand(true);
content_.set_hexpand(true);
text_before_.set_ellipsize(Pango::ELLIPSIZE_END);
text_before_.set_single_line_mode(true);
text_before_.set_width_chars(1);
text_before_.set_xalign(0.0);
text_after_.set_ellipsize(Pango::ELLIPSIZE_END);
text_after_.set_single_line_mode(true);
text_after_.set_width_chars(1);
text_after_.set_xalign(0.0);
content_.pack_start(text_before_, true, true, 0);
content_.pack_start(icon_, false, false, 0);
content_.pack_start(text_after_, true, true, 0);
} else {
content_.add(text_before_); content_.add(text_before_);
content_.add(icon_); content_.add(icon_);
content_.add(text_after_); content_.add(text_after_);
}
content_.show(); content_.show();
button.add(content_); button.add(content_);
@@ -718,7 +744,15 @@ void Taskbar::handle_finished() {
} }
void Taskbar::add_button(Gtk::Button& bt) { void Taskbar::add_button(Gtk::Button& bt) {
/* Only let the buttons expand to fill the taskbar when "expand" is enabled
* and the bar is horizontal (see the Task constructor for details). */
bool expand = config_["expand"].isBool() && config_["expand"].asBool();
bool horizontal = bar_.orientation == Gtk::ORIENTATION_HORIZONTAL;
if (expand && horizontal) {
box_.pack_start(bt, true, true);
} else {
box_.pack_start(bt, false, false); box_.pack_start(bt, false, false);
}
box_.get_style_context()->remove_class("empty"); box_.get_style_context()->remove_class("empty");
} }