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.pull/3017/head
parent
01dce4609c
commit
fe1d49518b
|
@ -62,7 +62,7 @@ class Workspace {
|
|||
public:
|
||||
explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager,
|
||||
const Json::Value& clients_data = Json::Value::nullRef);
|
||||
std::string& selectIcon(std::map<std::string, std::string>& icons_map);
|
||||
std::string& selectString(std::map<std::string, std::string>& string_map);
|
||||
Gtk::Button& button() { return m_button; };
|
||||
|
||||
int id() const { return m_id; };
|
||||
|
@ -199,7 +199,9 @@ class Workspaces : public AModule, public EventHandler {
|
|||
{"DEFAULT", SortMethod::DEFAULT}};
|
||||
|
||||
std::string m_format;
|
||||
std::string m_tooltipFormat;
|
||||
|
||||
std::map<std::string, std::string> m_tooltipMap;
|
||||
bool m_withTooltip;
|
||||
|
||||
std::map<std::string, std::string> m_iconsMap;
|
||||
util::RegexCollection m_windowRewriteRules;
|
||||
|
|
|
@ -70,10 +70,9 @@ Addressed by *hyprland/workspaces*
|
|||
default: true ++
|
||||
Option to disable tooltip on hover.
|
||||
|
||||
*tooltip-format*: ++
|
||||
typeof: string ++
|
||||
default: "{name}" ++
|
||||
The tooltip format.
|
||||
*tooltips*: ++
|
||||
typeof: array ++
|
||||
Based on the workspace ID and state, the corresponding tooltip gets selected. Selection works the same as *format-icons* do. Format replacements are supported. See *icons*.
|
||||
|
||||
# FORMAT REPLACEMENTS
|
||||
|
||||
|
@ -163,7 +162,33 @@ Additional to workspace name matching, the following *format-icons* can be set.
|
|||
"format": "{icon}",
|
||||
"format-window-separator": ", ",
|
||||
"tooltip": true,
|
||||
"tooltip-format": "{name}: {windows}",
|
||||
"tooltips": {
|
||||
"default": "{name}: {windows}",
|
||||
"empty": "" // Will result in no tooltip
|
||||
}
|
||||
"format-icons": {
|
||||
"1": "",
|
||||
"2": "",
|
||||
"3": "",
|
||||
"4": "",
|
||||
"5": "",
|
||||
"active": "",
|
||||
"default": ""
|
||||
},
|
||||
// Window rewrites omitted for brevity
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
"hyprland/workspaces": {
|
||||
"format": "{icon}",
|
||||
"format-window-separator": ", ",
|
||||
"tooltip": true,
|
||||
"tooltips": {
|
||||
"1": "This is the first workspace",
|
||||
"2": "This is the second",
|
||||
"2": "And this is the third"
|
||||
}
|
||||
"format-icons": {
|
||||
"1": "",
|
||||
"2": "",
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue