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
*/
enum class state_t : uint8_t {
FOCUSED, ///< Monitor is selected and tag is selected, 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
VISIBLE, ///< Tag is not selected, but occupied
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_log.info("%s: Initialized formatter and labels", name());
if (!file_util::exists(m_socket_path)) {
throw module_error("Could not find socket: " + (m_socket_path.empty() ? "<empty>" : m_socket_path));
}
@ -140,7 +139,7 @@ namespace modules {
this->on_monitor_focus_change(ev);
};
m_ipc->subscribe(dwmipc::Event::MONITOR_FOCUS_CHANGE);
m_log.info("%s: Subscribed to monitor focus change", name());
m_log.info("%s: Subscribed to monitor focus change", name());
} catch (const dwmipc::IPCError& err) {
throw module_error(err.what());
}
@ -277,22 +276,29 @@ namespace modules {
}
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 unselected - Tag occupied - Tag non-urgent VISIBLE
// Tag unselected - Tag occupied - Tag urgent URGENT
// Tag unselected - Tag unoccupied EMPTY
/**
* ---------------------------------------------------------------
* | Tag | | |
* |------------------------------| Monitor Selected | State |
* | Urgent | Selected | Occupied | | |
* |--------|----------|----------|------------------|-----------|
* | 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;
bool is_mon_active = m_bar_mon == m_active_mon;
if (is_mon_active && tag_state.selected & bit_mask) {
// Tag selected on selected monitor
return state_t::FOCUSED;
} else if (tag_state.urgent & bit_mask) {
if (tag_state.urgent & bit_mask) {
// Tag is 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) {
// Tag is selected, but not on selected monitor
return state_t::UNFOCUSED;