dwm: Make urgent tag state override focused state

A window can have the urgent hint set while being in a focused tag if that
window is not in focus. As a result, the urgent state should overrule the
focused state.

I also added a pretty truth table.
This commit is contained in:
Mihir Lad 2020-07-29 21:22:02 -04:00
parent 567b31bcc6
commit 803fe549c6
2 changed files with 19 additions and 13 deletions

View File

@ -19,8 +19,8 @@ namespace modules {
* Represents the relevant states a tag can have * Represents the relevant states a tag can have
*/ */
enum class state_t : uint8_t { enum class state_t : uint8_t {
FOCUSED, ///< Monitor is selected and tag is selected, overrides all below
URGENT, ///< Tag is urgent, overrides all below URGENT, ///< Tag is urgent, overrides all below
FOCUSED, ///< Monitor is selected and tag is selected, overrides all below
UNFOCUSED, ///< Monitor is not selected, but tag is selected UNFOCUSED, ///< Monitor is not selected, but tag is selected
VISIBLE, ///< Tag is not selected, but occupied VISIBLE, ///< Tag is not selected, but occupied
EMPTY ///< Tag is unoccupied and unselected EMPTY ///< Tag is unoccupied and unselected

View File

@ -57,7 +57,6 @@ namespace modules {
m_socket_path = m_conf.get(name(), "socket-path", m_socket_path); m_socket_path = m_conf.get(name(), "socket-path", m_socket_path);
m_log.info("%s: Initialized formatter and labels", name()); m_log.info("%s: Initialized formatter and labels", name());
if (!file_util::exists(m_socket_path)) { if (!file_util::exists(m_socket_path)) {
throw module_error("Could not find socket: " + (m_socket_path.empty() ? "<empty>" : m_socket_path)); throw module_error("Could not find socket: " + (m_socket_path.empty() ? "<empty>" : m_socket_path));
} }
@ -277,22 +276,29 @@ namespace modules {
} }
auto dwm_module::get_state(tag_mask_t bit_mask) const -> state_t { auto dwm_module::get_state(tag_mask_t bit_mask) const -> state_t {
// Tag selected > occupied > urgent /**
// Monitor selected - Tag selected FOCUSED * ---------------------------------------------------------------
// Monitor unselected - Tag selected UNFOCUSED * | Tag | | |
// Tag unselected - Tag occupied - Tag non-urgent VISIBLE * |------------------------------| Monitor Selected | State |
// Tag unselected - Tag occupied - Tag urgent URGENT * | Urgent | Selected | Occupied | | |
// Tag unselected - Tag unoccupied EMPTY * |--------|----------|----------|------------------|-----------|
* | Yes | * | * | * | Urgent |
* | No | Yes | * | Yes | Focused |
* | No | Yes | * | No | Unfocused |
* | No | No | Yes | * | Visible |
* | No | No | No | * | Empty |
* ---------------------------------------------------------------
*/
auto tag_state = m_bar_mon->tag_state; auto tag_state = m_bar_mon->tag_state;
bool is_mon_active = m_bar_mon == m_active_mon; bool is_mon_active = m_bar_mon == m_active_mon;
if (is_mon_active && tag_state.selected & bit_mask) { if (tag_state.urgent & bit_mask) {
// Tag selected on selected monitor
return state_t::FOCUSED;
} else if (tag_state.urgent & bit_mask) {
// Tag is urgent // Tag is urgent
return state_t::URGENT; return state_t::URGENT;
} else if (is_mon_active && tag_state.selected & bit_mask) {
// Tag selected on selected monitor
return state_t::FOCUSED;
} else if (!is_mon_active && tag_state.selected & bit_mask) { } else if (!is_mon_active && tag_state.selected & bit_mask) {
// Tag is selected, but not on selected monitor // Tag is selected, but not on selected monitor
return state_t::UNFOCUSED; return state_t::UNFOCUSED;