From 466e9e212f43896166e2ef72c3cc8a64a94ff39f Mon Sep 17 00:00:00 2001 From: Franklin Delehelle Date: Tue, 29 Nov 2016 15:53:32 +0100 Subject: [PATCH] feat(bspwm): Separate focused/unfocused states Closes #201 --- include/components/config.hpp | 10 ++++++++++ include/drawtypes/label.hpp | 2 ++ include/modules/bspwm.hpp | 3 +++ src/drawtypes/label.cpp | 7 +++++++ src/modules/bspwm.cpp | 24 ++++++++++++++++-------- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/components/config.hpp b/include/components/config.hpp index 9be76351..59ffce0c 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -33,6 +33,16 @@ class config { string build_path(const string& section, const string& key) const; void warn_deprecated(const string& section, const string& key, string replacement) const; + + /** + * Returns true if a given parameter exists + */ + template + bool has(string section, string key) const { + auto val = m_ptree.get_optional(build_path(section, key)); + return (val != boost::none); + } + /** * Get parameter for the current bar by name */ diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index 5ecd5092..ae4d4d33 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -73,6 +73,8 @@ namespace drawtypes { label_t load_optional_label(const config& conf, string section, string name, string def = ""); + label_t load_either_config_label(const config& conf, string section, string name1, string name2, string def = ""); + icon_t load_icon(const config& conf, string section, string name, bool required = true, string def = ""); icon_t load_optional_icon(const config& conf, string section, string name, string def = ""); diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 38082119..e311f134 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -12,6 +12,9 @@ namespace modules { WORKSPACE_URGENT, WORKSPACE_EMPTY, WORKSPACE_OCCUPIED, + WORKSPACE_FOCUSED_URGENT, + WORKSPACE_FOCUSED_EMPTY, + WORKSPACE_FOCUSED_OCCUPIED, WORKSPACE_DIMMED, // used when the monitor is out of focus WORKSPACE_DIMMED_ACTIVE, WORKSPACE_DIMMED_URGENT, diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index 2982e461..e7032cee 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -167,6 +167,13 @@ namespace drawtypes { return load_label(conf, move(section), move(name), false, move(def)); } + label_t load_either_config_label(const config& conf, string section, string name1, string name2, string def) { + if (conf.has(section, name1)) + return load_label(conf, section, name1, true, ""); + else + return load_optional_label(conf, section, name2, def); + } + /** * Create an icon by loading values from the configuration */ diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index 01ac34f1..f8baf1b4 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -43,8 +43,16 @@ namespace modules { state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); m_statelabels.insert( make_pair(state_ws::WORKSPACE_URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL))); + m_statelabels.insert( + make_pair(state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL))); m_statelabels.insert( make_pair(state_ws::WORKSPACE_EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL))); + m_statelabels.insert( + make_pair(state_ws::WORKSPACE_FOCUSED_OCCUPIED, load_either_config_label(m_conf, name(), "label-focused-occupied", "label-focused", DEFAULT_WS_LABEL))); + m_statelabels.insert( + make_pair(state_ws::WORKSPACE_FOCUSED_URGENT, load_either_config_label(m_conf, name(), "label-focused-urgent", "label-focused", DEFAULT_WS_LABEL))); + m_statelabels.insert( + make_pair(state_ws::WORKSPACE_FOCUSED_EMPTY, load_either_config_label(m_conf, name(), "label-focused-empty", "label-focused", DEFAULT_WS_LABEL))); m_statelabels.insert(make_pair(state_ws::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed"))); m_statelabels.insert( make_pair(state_ws::WORKSPACE_DIMMED_ACTIVE, load_optional_label(m_conf, name(), "label-dimmed-active"))); @@ -195,23 +203,23 @@ namespace modules { m_monitors.back()->focused = true; break; case 'F': - workspace_flag = state_ws::WORKSPACE_ACTIVE; + workspace_flag = state_ws::WORKSPACE_FOCUSED_EMPTY; break; case 'O': - workspace_flag = state_ws::WORKSPACE_ACTIVE; + workspace_flag = state_ws::WORKSPACE_FOCUSED_OCCUPIED; + break; + case 'U': + workspace_flag = state_ws::WORKSPACE_FOCUSED_URGENT; + break; + case 'f': + workspace_flag = state_ws::WORKSPACE_EMPTY; break; case 'o': workspace_flag = state_ws::WORKSPACE_OCCUPIED; break; - case 'U': - workspace_flag = state_ws::WORKSPACE_URGENT; - break; case 'u': workspace_flag = state_ws::WORKSPACE_URGENT; break; - case 'f': - workspace_flag = state_ws::WORKSPACE_EMPTY; - break; case 'L': switch (value[0]) { case 0: