feat(bspwm,i3): Fuzzy-matching names for icons
Added support for fuzzy matching workspace names when assigning icons. This feature is enabled/disabled through a new option, 'fuzzy-match'. It is disabled by default.
This commit is contained in:
parent
ca0d7345a1
commit
2dfdbd240e
@ -13,7 +13,7 @@ namespace drawtypes {
|
|||||||
public:
|
public:
|
||||||
void add(string id, icon_t&& icon);
|
void add(string id, icon_t&& icon);
|
||||||
bool has(const string& id);
|
bool has(const string& id);
|
||||||
icon_t get(const string& id, const string& fallback_id = "");
|
icon_t get(const string& id, const string& fallback_id = "", bool fuzzy_match = false);
|
||||||
operator bool();
|
operator bool();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -79,6 +79,7 @@ namespace modules {
|
|||||||
bool m_pinworkspaces{true};
|
bool m_pinworkspaces{true};
|
||||||
bool m_inlinemode{false};
|
bool m_inlinemode{false};
|
||||||
string_util::hash_type m_hash{0U};
|
string_util::hash_type m_hash{0U};
|
||||||
|
bool m_fuzzy_match{false};
|
||||||
|
|
||||||
// used while formatting output
|
// used while formatting output
|
||||||
size_t m_index{0U};
|
size_t m_index{0U};
|
||||||
|
@ -72,6 +72,7 @@ namespace modules {
|
|||||||
bool m_indexsort{false};
|
bool m_indexsort{false};
|
||||||
bool m_pinworkspaces{false};
|
bool m_pinworkspaces{false};
|
||||||
bool m_strip_wsnumbers{false};
|
bool m_strip_wsnumbers{false};
|
||||||
|
bool m_fuzzy_match{false};
|
||||||
|
|
||||||
unique_ptr<i3_util::connection_t> m_ipc;
|
unique_ptr<i3_util::connection_t> m_ipc;
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,17 @@ namespace drawtypes {
|
|||||||
return m_icons.find(id) != m_icons.end();
|
return m_icons.find(id) != m_icons.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
icon_t iconset::get(const string& id, const string& fallback_id) {
|
icon_t iconset::get(const string& id, const string& fallback_id, bool fuzzy_match) {
|
||||||
|
if (fuzzy_match) {
|
||||||
|
for (auto const& ent1 : m_icons) {
|
||||||
|
if (id.find(ent1.first) != std::string::npos) {
|
||||||
|
return ent1.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_icons.find(fallback_id)->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not fuzzy matching so use old method which requires an exact match on icon id
|
||||||
auto icon = m_icons.find(id);
|
auto icon = m_icons.find(id);
|
||||||
if (icon == m_icons.end()) {
|
if (icon == m_icons.end()) {
|
||||||
return m_icons.find(fallback_id)->second;
|
return m_icons.find(fallback_id)->second;
|
||||||
|
@ -56,6 +56,7 @@ namespace modules {
|
|||||||
m_scroll = m_conf.get(name(), "enable-scroll", m_scroll);
|
m_scroll = m_conf.get(name(), "enable-scroll", m_scroll);
|
||||||
m_revscroll = m_conf.get(name(), "reverse-scroll", m_revscroll);
|
m_revscroll = m_conf.get(name(), "reverse-scroll", m_revscroll);
|
||||||
m_inlinemode = m_conf.get(name(), "inline-mode", m_inlinemode);
|
m_inlinemode = m_conf.get(name(), "inline-mode", m_inlinemode);
|
||||||
|
m_fuzzy_match = m_conf.get(name(), "fuzzy-match", m_fuzzy_match);
|
||||||
|
|
||||||
// Add formats and create components
|
// Add formats and create components
|
||||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE});
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE});
|
||||||
@ -329,7 +330,7 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (workspace_mask && m_formatter->has(TAG_LABEL_STATE)) {
|
if (workspace_mask && m_formatter->has(TAG_LABEL_STATE)) {
|
||||||
auto icon = m_icons->get(value, DEFAULT_ICON);
|
auto icon = m_icons->get(value, DEFAULT_ICON, m_fuzzy_match);
|
||||||
auto label = m_statelabels.at(workspace_mask)->clone();
|
auto label = m_statelabels.at(workspace_mask)->clone();
|
||||||
|
|
||||||
if (!m_monitors.back()->focused) {
|
if (!m_monitors.back()->focused) {
|
||||||
|
@ -30,6 +30,7 @@ namespace modules {
|
|||||||
m_indexsort = m_conf.get(name(), "index-sort", m_indexsort);
|
m_indexsort = m_conf.get(name(), "index-sort", m_indexsort);
|
||||||
m_pinworkspaces = m_conf.get(name(), "pin-workspaces", m_pinworkspaces);
|
m_pinworkspaces = m_conf.get(name(), "pin-workspaces", m_pinworkspaces);
|
||||||
m_strip_wsnumbers = m_conf.get(name(), "strip-wsnumbers", m_strip_wsnumbers);
|
m_strip_wsnumbers = m_conf.get(name(), "strip-wsnumbers", m_strip_wsnumbers);
|
||||||
|
m_fuzzy_match = m_conf.get(name(), "fuzzy-match", m_fuzzy_match);
|
||||||
|
|
||||||
m_conf.warn_deprecated(name(), "wsname-maxlen", "%name:min:max%");
|
m_conf.warn_deprecated(name(), "wsname-maxlen", "%name:min:max%");
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ namespace modules {
|
|||||||
// Trim leading and trailing whitespace
|
// Trim leading and trailing whitespace
|
||||||
ws_name = string_util::trim(move(ws_name), ' ');
|
ws_name = string_util::trim(move(ws_name), ' ');
|
||||||
|
|
||||||
auto icon = m_icons->get(ws->name, DEFAULT_WS_ICON);
|
auto icon = m_icons->get(ws->name, DEFAULT_WS_ICON, m_fuzzy_match);
|
||||||
auto label = m_statelabels.find(ws_state)->second->clone();
|
auto label = m_statelabels.find(ws_state)->second->clone();
|
||||||
|
|
||||||
label->reset_tokens();
|
label->reset_tokens();
|
||||||
|
Loading…
Reference in New Issue
Block a user