Add tooltip selection based on name and state
One can set different tooltips for different workspaces. Selection works the same as it does for Icons. Also refactored the `selectIcon` function to a more general `selectString` function. Man page is updated too.
This commit is contained in:
@@ -60,11 +60,14 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||
m_format = configFormat.isString() ? configFormat.asString() : "{name}";
|
||||
m_withIcon = m_format.find("{icon}") != std::string::npos;
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
const Json::Value &configTooltipFormat = config["tooltip-format"];
|
||||
m_tooltipFormat = configTooltipFormat.isString() ? configTooltipFormat.asString() : "{name}";
|
||||
} else {
|
||||
m_tooltipFormat = "";
|
||||
m_withTooltip = tooltipEnabled();
|
||||
|
||||
if (m_withTooltip && m_tooltipMap.empty()) {
|
||||
Json::Value tooltipFormats = config["tooltips"];
|
||||
for (std::string &name : tooltipFormats.getMemberNames()) {
|
||||
m_tooltipMap.emplace(name, tooltipFormats[name].asString());
|
||||
}
|
||||
m_tooltipMap.emplace("", "");
|
||||
}
|
||||
|
||||
if (m_withIcon && m_iconsMap.empty()) {
|
||||
@@ -232,7 +235,15 @@ void Workspaces::doUpdate() {
|
||||
// set workspace icon
|
||||
std::string &workspaceIcon = m_iconsMap[""];
|
||||
if (m_withIcon) {
|
||||
workspaceIcon = workspace->selectIcon(m_iconsMap);
|
||||
spdlog::trace("Selecting icon for workspace {}", workspace->name());
|
||||
workspaceIcon = workspace->selectString(m_iconsMap);
|
||||
}
|
||||
|
||||
// set tooltip
|
||||
std::string &workspaceTooltip = m_tooltipMap[""];
|
||||
if (m_withTooltip) {
|
||||
spdlog::trace("Selecting tooltip for workspace {}", workspace->name());
|
||||
workspaceTooltip = workspace->selectString(m_tooltipMap);
|
||||
}
|
||||
|
||||
// update m_output
|
||||
@@ -247,7 +258,7 @@ void Workspaces::doUpdate() {
|
||||
workspace->setOutput((*updated_workspace)["monitor"].asString());
|
||||
}
|
||||
|
||||
workspace->update(m_format, workspaceIcon, m_tooltipFormat);
|
||||
workspace->update(m_format, workspaceIcon, workspaceTooltip);
|
||||
}
|
||||
|
||||
spdlog::trace("Updating window count");
|
||||
@@ -984,58 +995,57 @@ void Workspaces::sortWorkspaces() {
|
||||
}
|
||||
}
|
||||
|
||||
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> &string_map) {
|
||||
if (isUrgent()) {
|
||||
auto urgentIconIt = icons_map.find("urgent");
|
||||
if (urgentIconIt != icons_map.end()) {
|
||||
return urgentIconIt->second;
|
||||
auto urgentStringIt = string_map.find("urgent");
|
||||
if (urgentStringIt != string_map.end()) {
|
||||
return urgentStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isActive()) {
|
||||
auto activeIconIt = icons_map.find("active");
|
||||
if (activeIconIt != icons_map.end()) {
|
||||
return activeIconIt->second;
|
||||
auto activeStringIt = string_map.find("active");
|
||||
if (activeStringIt != string_map.end()) {
|
||||
return activeStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSpecial()) {
|
||||
auto specialIconIt = icons_map.find("special");
|
||||
if (specialIconIt != icons_map.end()) {
|
||||
return specialIconIt->second;
|
||||
auto specialStringIt = string_map.find("special");
|
||||
if (specialStringIt != string_map.end()) {
|
||||
return specialStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
auto namedIconIt = icons_map.find(name());
|
||||
if (namedIconIt != icons_map.end()) {
|
||||
return namedIconIt->second;
|
||||
auto namedStringIt = string_map.find(name());
|
||||
if (namedStringIt != string_map.end()) {
|
||||
return namedStringIt->second;
|
||||
}
|
||||
|
||||
if (isVisible()) {
|
||||
auto visibleIconIt = icons_map.find("visible");
|
||||
if (visibleIconIt != icons_map.end()) {
|
||||
return visibleIconIt->second;
|
||||
auto visibleStringIt = string_map.find("visible");
|
||||
if (visibleStringIt != string_map.end()) {
|
||||
return visibleStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isEmpty()) {
|
||||
auto emptyIconIt = icons_map.find("empty");
|
||||
if (emptyIconIt != icons_map.end()) {
|
||||
return emptyIconIt->second;
|
||||
auto emptyStringIt = string_map.find("empty");
|
||||
if (emptyStringIt != string_map.end()) {
|
||||
return emptyStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPersistent()) {
|
||||
auto persistentIconIt = icons_map.find("persistent");
|
||||
if (persistentIconIt != icons_map.end()) {
|
||||
return persistentIconIt->second;
|
||||
auto persistentStringIt = string_map.find("persistent");
|
||||
if (persistentStringIt != string_map.end()) {
|
||||
return persistentStringIt->second;
|
||||
}
|
||||
}
|
||||
|
||||
auto defaultIconIt = icons_map.find("default");
|
||||
if (defaultIconIt != icons_map.end()) {
|
||||
return defaultIconIt->second;
|
||||
auto defaultStringIt = string_map.find("default");
|
||||
if (defaultStringIt != string_map.end()) {
|
||||
return defaultStringIt->second;
|
||||
}
|
||||
|
||||
return m_name;
|
||||
|
||||
Reference in New Issue
Block a user