Skip to content

Commit c77957e

Browse files
committed
taskbar: add "show window title" option
1 parent 364b573 commit c77957e

5 files changed

Lines changed: 60 additions & 17 deletions

File tree

assets/translations/en.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,14 @@
12211221
"label": "Hide Empty Workspaces",
12221222
"description": "When grouping by workspace, omit capsules that have no running windows in the taskbar list."
12231223
},
1224+
"show_window_title": {
1225+
"label": "Show Window Title",
1226+
"description": "Show the window title next to its icon"
1227+
},
1228+
"window_title_length": {
1229+
"label": "Window Title Length",
1230+
"description": "Maximum length in pixels for window titles"
1231+
},
12241232
"height": {
12251233
"label": "Height",
12261234
"description": "Widget height in pixels"

src/shell/bar/widget_factory.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,13 @@ std::unique_ptr<Widget> WidgetFactory::create(const std::string& name, wl_output
386386
const bool onlyActiveWorkspace = wc != nullptr ? wc->getBool("only_active_workspace", false) : false;
387387
const bool showWorkspaceLabel = wc != nullptr ? wc->getBool("show_workspace_label", true) : true;
388388
const bool hideEmptyWorkspaces = wc != nullptr ? wc->getBool("hide_empty_workspaces", false) : false;
389+
const bool showWindowTitle = wc != nullptr ? wc->getBool("show_window_title", false) : false;
390+
const float windowTitleLength =
391+
static_cast<float>(wc != nullptr ? wc->getDouble("window_title_length", 40.0) : 40.0);
389392
auto widget =
390393
std::make_unique<TaskbarWidget>(m_platform, output, groupByWorkspace, showAllOutputs, onlyActiveWorkspace,
391-
showWorkspaceLabel, hideEmptyWorkspaces, barPosition, m_config.shell.shadow);
394+
showWorkspaceLabel, hideEmptyWorkspaces, showWindowTitle, windowTitleLength,
395+
barPosition, m_config.shell.shadow);
392396
widget->setContentScale(contentScale);
393397
return widget;
394398
}

src/shell/bar/widgets/taskbar_widget.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434

3535
TaskbarWidget::TaskbarWidget(CompositorPlatform& platform, wl_output* output, bool groupByWorkspace,
3636
bool showAllOutputs, bool onlyActiveWorkspace, bool showWorkspaceLabel,
37-
bool hideEmptyWorkspaces, std::string barPosition, ShellConfig::ShadowConfig shadowConfig)
37+
bool hideEmptyWorkspaces, bool showWindowTitle, float windowTitleLength,
38+
std::string barPosition, ShellConfig::ShadowConfig shadowConfig)
3839
: m_platform(platform), m_output(output), m_groupByWorkspace(groupByWorkspace), m_showAllOutputs(showAllOutputs),
3940
m_onlyActiveWorkspace(onlyActiveWorkspace), m_showWorkspaceLabel(showWorkspaceLabel),
40-
m_hideEmptyWorkspaces(hideEmptyWorkspaces), m_barPosition(std::move(barPosition)),
41+
m_hideEmptyWorkspaces(hideEmptyWorkspaces), m_showWindowTitle(showWindowTitle),
42+
m_windowTitleLength(windowTitleLength), m_barPosition(std::move(barPosition)),
4143
m_shadowConfig(std::move(shadowConfig)) {
4244
buildDesktopIconIndex();
4345
}
@@ -144,7 +146,8 @@ void TaskbarWidget::buildTaskButtons(Renderer& renderer) {
144146
}
145147
const float iconSize = Style::barGlyphSize * m_contentScale;
146148
const float tilePadding = Style::spaceXs * 0.35f * m_contentScale;
147-
const float tileSize = iconSize + tilePadding * 2.0f;
149+
const float tileHeight = iconSize + tilePadding * 2.0f;
150+
const float tileWidth = tileHeight + (m_showWindowTitle ? m_windowTitleLength * m_contentScale + tilePadding : 0.0f);
148151
const auto workspaceAxisHandler = [this](const InputArea::PointerData& data) -> bool {
149152
if (!m_groupByWorkspace) {
150153
return false;
@@ -169,7 +172,7 @@ void TaskbarWidget::buildTaskButtons(Renderer& renderer) {
169172
};
170173
auto createTaskTile = [&](const TaskModel& task) {
171174
auto area = std::make_unique<InputArea>();
172-
area->setFrameSize(tileSize, tileSize);
175+
area->setFrameSize(tileWidth, tileHeight);
173176
area->setAcceptedButtons(InputArea::buttonMask({BTN_LEFT, BTN_RIGHT}));
174177
area->setOnAxisHandler(workspaceAxisHandler);
175178

@@ -213,25 +216,41 @@ void TaskbarWidget::buildTaskButtons(Renderer& renderer) {
213216
auto image = std::make_unique<Image>();
214217
image->setFit(ImageFit::Contain);
215218
image->setSize(iconSize, iconSize);
216-
image->setPosition(std::round((tileSize - iconSize) * 0.5f), std::round((tileSize - iconSize) * 0.5f));
219+
image->setPosition(std::round((tileHeight - iconSize) * 0.5f), std::round((tileHeight - iconSize) * 0.5f));
217220
image->setSourceFile(renderer, task.iconPath, static_cast<int>(std::round(48.0f * m_contentScale)), true);
218221
area->addChild(std::move(image));
219222
} else {
220223
auto glyph = std::make_unique<Glyph>();
221224
glyph->setGlyph("apps");
222225
glyph->setGlyphSize(iconSize);
223-
glyph->setPosition(std::round((tileSize - iconSize) * 0.5f), std::round((tileSize - iconSize) * 0.5f));
226+
glyph->setPosition(std::round((tileHeight - iconSize) * 0.5f), std::round((tileHeight - iconSize) * 0.5f));
224227
area->addChild(std::move(glyph));
225228
}
226229

230+
if (m_showWindowTitle) {
231+
auto label = std::make_unique<Label>();
232+
label->setText(task.title);
233+
label->setFontSize(Style::fontSizeCaption * m_contentScale);
234+
label->setMaxWidth(m_windowTitleLength * m_contentScale);
235+
label->setPosition(std::round(tileHeight + tilePadding), 0);
236+
area->addChild(std::move(label));
237+
}
238+
227239
if (task.active) {
228240
const float d = std::max(4.0f, std::round(Style::barGlyphSize * 0.32f * m_contentScale));
229241
const float bottomInset = 0.25f * m_contentScale;
230242
auto indicator = std::make_unique<Box>();
231243
indicator->setFill(colorSpecFromRole(ColorRole::Primary));
232-
indicator->setRadius(d * 0.5f);
233-
indicator->setFrameSize(d, d);
234-
indicator->setPosition(std::round((tileSize - d) * 0.5f), std::round(tileSize - d - bottomInset));
244+
if (m_showWindowTitle) {
245+
const float lineThickness = d * 0.5f;
246+
indicator->setRadius(lineThickness * 0.5f);
247+
indicator->setSize(tileWidth - tilePadding * 2, lineThickness);
248+
indicator->setPosition(tilePadding, std::round(tileHeight));
249+
} else {
250+
indicator->setRadius(d * 0.5f);
251+
indicator->setFrameSize(d, d);
252+
indicator->setPosition(std::round((tileHeight - d) * 0.5f), std::round(tileHeight - d - bottomInset));
253+
}
235254
area->addChild(std::move(indicator));
236255
}
237256
return area;
@@ -289,11 +308,11 @@ void TaskbarWidget::buildTaskButtons(Renderer& renderer) {
289308
}
290309
const float taskCount = std::max(1.0f, static_cast<float>(tasks.size()));
291310
const float gapCount = tasks.empty() ? 0.0f : (taskCount - 1.0f);
292-
const float runLength = (tileSize * taskCount) + (groupGap * gapCount);
293-
const float groupWidth = m_vertical ? std::round(tileSize + (groupPadCross * 2.0f))
311+
const float runLength = (tileWidth * taskCount) + (groupGap * gapCount);
312+
const float groupWidth = m_vertical ? std::round(tileWidth + (groupPadCross * 2.0f))
294313
: std::round(groupPadStart + groupPadEnd + runLength);
295314
const float groupHeight = m_vertical ? std::round(groupPadStart + groupPadEnd + runLength)
296-
: std::round(tileSize + (groupPadCross * 2.0f));
315+
: std::round(tileHeight + (groupPadCross * 2.0f));
297316

298317
auto group = std::make_unique<Box>();
299318
group->setFrameSize(groupWidth, groupHeight);
@@ -319,7 +338,7 @@ void TaskbarWidget::buildTaskButtons(Renderer& renderer) {
319338
}
320339

321340
for (std::size_t i = 0; i < tasks.size(); ++i) {
322-
const float tileOffset = (tileSize + groupGap) * static_cast<float>(i);
341+
const float tileOffset = (tileWidth + groupGap) * static_cast<float>(i);
323342
auto tile = createTaskTile(*tasks[i]);
324343
if (m_vertical) {
325344
tile->setPosition(std::round(groupPadCross), std::round(groupPadStart + tileOffset));

src/shell/bar/widgets/taskbar_widget.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct PointerEvent;
2121
class TaskbarWidget : public Widget {
2222
public:
2323
TaskbarWidget(CompositorPlatform& platform, wl_output* output, bool groupByWorkspace, bool showAllOutputs,
24-
bool onlyActiveWorkspace, bool showWorkspaceLabel, bool hideEmptyWorkspaces, std::string barPosition,
25-
ShellConfig::ShadowConfig shadowConfig);
24+
bool onlyActiveWorkspace, bool showWorkspaceLabel, bool hideEmptyWorkspaces, bool showWindowTitle,
25+
float windowTitleLength, std::string barPosition, ShellConfig::ShadowConfig shadowConfig);
2626
~TaskbarWidget() override;
2727

2828
void create() override;
@@ -58,7 +58,7 @@ class TaskbarWidget : public Widget {
5858
std::uint8_t votes = 0;
5959
};
6060

61-
void doLayout(Renderer& renderer, float containerWidth, float containerHeight) override;
61+
void doLayout(Renderer& renwindow_tiderer, float containerWidth, float containerHeight) override;
6262
void doUpdate(Renderer& renderer) override;
6363

6464
void rebuild(Renderer& renderer);
@@ -86,6 +86,8 @@ class TaskbarWidget : public Widget {
8686
bool m_onlyActiveWorkspace = false;
8787
bool m_showWorkspaceLabel = true;
8888
bool m_hideEmptyWorkspaces = false;
89+
bool m_showWindowTitle = false;
90+
float m_windowTitleLength = 40.0;
8991
std::string m_barPosition;
9092
ShellConfig::ShadowConfig m_shadowConfig;
9193
bool m_rebuildPending = true;

src/shell/settings/widget_settings_registry.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,16 @@ namespace settings {
548548
WidgetSettingVisibility{WidgetSettingVisibilityCondition{"group_by_workspace", {"true"}}};
549549
add(std::move(hideEmpty));
550550
}
551+
{
552+
auto showWindowTitle = boolSpec("show_window_title", false);
553+
add(std::move(showWindowTitle));
554+
}
555+
{
556+
auto windowTitleLength = doubleSpec("window_title_length", 100.0, 10.0, 200.0, 1.0);
557+
windowTitleLength.visibleWhen =
558+
WidgetSettingVisibility{WidgetSettingVisibilityCondition{"show_window_title", {"true"}}};
559+
add(std::move(windowTitleLength));
560+
}
551561
for (auto& spec : specs) {
552562
if (spec.key == "capsule_radius") {
553563
spec.descriptionKey = "settings.widgets.settings.capsule_radius.taskbar-description";

0 commit comments

Comments
 (0)