Merge pull request #3017 from 0x000C0A71/master

[hyprland/workspaces] Add tooltips to hyprland/workspaces
This commit is contained in:
Alexis Rouillard
2026-07-04 01:12:10 +02:00
committed by GitHub
5 changed files with 82 additions and 7 deletions
+9 -3
View File
@@ -296,8 +296,8 @@ bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payloa
return false;
}
std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map) {
spdlog::trace("Selecting icon for workspace {}", name());
std::string& Workspace::selectString(std::map<std::string, std::string>& icons_map) {
spdlog::trace("Selecting string for workspace {}", name());
if (isUrgent()) {
auto urgentNamedIconIt = icons_map.find("urgent:" + name());
if (urgentNamedIconIt != icons_map.end()) {
@@ -379,7 +379,7 @@ std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map
return m_name;
}
void Workspace::update(const std::string& workspace_icon) {
void Workspace::update(const std::string& workspace_icon, const std::string& workspace_tooltip) {
if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) {
m_button.hide();
return;
@@ -489,6 +489,12 @@ void Workspace::update(const std::string& workspace_icon) {
}
}
if (!workspace_tooltip.empty()) {
m_button.set_tooltip_text(
fmt::format(fmt::runtime(workspace_tooltip), fmt::arg("id", id()), fmt::arg("name", name()),
fmt::arg("icon", workspace_icon), fmt::arg("windows", windows)));
}
auto formatBefore = m_workspaceManager.formatBefore();
m_labelBefore.set_markup(fmt::format(fmt::runtime(formatBefore), fmt::arg("id", id()),
fmt::arg("name", name()), fmt::arg("icon", workspace_icon),
+15 -2
View File
@@ -675,6 +675,15 @@ auto Workspaces::parseConfig(const Json::Value& config) -> void {
populateIconsMap(config["format-icons"]);
}
m_withTooltip = tooltipEnabled();
if (m_withTooltip && m_tooltipMap.empty()) {
const Json::Value& tooltipFormats = config["tooltips"];
for (const auto& name : tooltipFormats.getMemberNames()) {
m_tooltipMap.emplace(name, tooltipFormats[name].asString());
}
m_tooltipMap.emplace("", "");
}
populateBoolConfig(config, "all-outputs", m_allOutputs);
populateBoolConfig(config, "show-special", m_showSpecial);
populateBoolConfig(config, "special-visible-only", m_specialVisibleOnly);
@@ -1155,7 +1164,11 @@ void Workspaces::updateWorkspaceStates() {
visibleWorkspaces.end());
std::string& workspaceIcon = m_iconsMap[""];
if (m_withIcon) {
workspaceIcon = workspace->selectIcon(m_iconsMap);
workspaceIcon = workspace->selectString(m_iconsMap);
}
std::string& workspaceTooltip = m_tooltipMap[""];
if (m_withTooltip) {
workspaceTooltip = workspace->selectString(m_tooltipMap);
}
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto& w) {
auto wNameRaw = w["name"].asString();
@@ -1165,7 +1178,7 @@ void Workspaces::updateWorkspaceStates() {
if (updatedWorkspace != updatedWorkspaces.end()) {
workspace->setOutput((*updatedWorkspace)["monitor"].asString());
}
workspace->update(workspaceIcon);
workspace->update(workspaceIcon, workspaceTooltip);
}
}