polybar-dwm/include/modules/dwm.hpp

88 lines
2.8 KiB
C++
Raw Normal View History

#pragma once
#include <dwmipcpp/connection.hpp>
#include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS
namespace modules {
class dwm_module : public event_module<dwm_module>, public input_handler {
public:
explicit dwm_module(const bar_settings&, string);
using tag_mask_t = unsigned int;
enum class state_t : uint8_t {
FOCUSED, ///< Monitor is selected and tag is selected, overrides all below
URGENT, ///< Tag is urgent, overrides all below
UNFOCUSED, ///< Monitor is not selected, but tag is selected
VISIBLE, ///< Tag is not selected, but occupied
NONE ///< Tag is unoccupied and unselected
};
struct tag_t {
tag_t(string& name, unsigned int bit_mask, state_t state, label_t&& label)
: name(name), bit_mask(bit_mask), state(state), label(forward<label_t>(label)) {}
string name;
unsigned int bit_mask;
state_t state;
label_t label;
};
auto stop() -> void override;
auto has_event() -> bool;
auto update() -> bool;
auto build(builder* builder, const string& tag) const -> bool;
protected:
auto input(string&& cmd) -> bool override;
private:
static constexpr const char* DEFAULT_FORMAT_TAGS{"<label-state> <label-layout> <label-title>"};
static constexpr const char* DEFAULT_TAG_LABEL{"%name%"};
static constexpr const char* TAG_LABEL_STATE{"<label-state>"};
static constexpr const char* TAG_LABEL_LAYOUT{"<label-layout>"};
static constexpr const char* TAG_LABEL_TITLE{"<label-title>"};
dwm: Reorganize module Remove EVENT_SCROLL_{UP_DOWN} since it is not being used. Change EVENT_PREFIX to include dash and event names to be just the name without the prefix, for simplified parsing. Use check_send_cmd function to parse the cmd, using the event name as the IPC command name, and the section after the event name to be the argument. The format of a cmd would be "dwm-<event name>-<arg>", so the cmd can easily be translated into an IPC command. Call member functions for all dwmipc events for better organization and to avoid cluttering the constructor. The dwmipc event functions are now just assigned to a lambda that calls a member function. Add update_tag_labels function for updating the tag labels based on their state since this code is repetetive. Add update_title_labels function since that code is also somewhat repetetive. Move reconnect code to reconnect_dwm for better organization. Use pointers to m_monitors array elements instead of holding onto indices, since most of the time, a member of the Monitor element will need to be accessed. These variables should always hold a valid address starting in the constructor, so checks for nullptr should not be necessary. A monitor will always be active and the bar will always be mapped onto a monitor. Add some comments where needed. Reorganize the constructor into a more logical format Only subscribe to events if their labels are included in the default format. Follow clang-tidy warnings and use trailing return types. Move m_ipc->get_monitors to update_monitor_ref since in most cases where the monitor references would need to be updated using geometry, m_ipc->get_monitors would need to be called.
2020-07-20 02:52:50 +00:00
static constexpr const char* EVENT_PREFIX{"dwm-"};
static constexpr const char* EVENT_LCLICK{"view"};
static constexpr const char* EVENT_RCLICK{"toggleview"};
void on_layout_change(const dwmipc::LayoutChangeEvent& ev);
void on_monitor_focus_change(const dwmipc::MonitorFocusChangeEvent& ev);
void on_tag_change(const dwmipc::TagChangeEvent& ev);
void on_client_focus_change(const dwmipc::ClientFocusChangeEvent& ev);
void on_focused_title_change(const dwmipc::FocusedTitleChangeEvent& ev);
void update_monitor_ref();
dwm: Reorganize module Remove EVENT_SCROLL_{UP_DOWN} since it is not being used. Change EVENT_PREFIX to include dash and event names to be just the name without the prefix, for simplified parsing. Use check_send_cmd function to parse the cmd, using the event name as the IPC command name, and the section after the event name to be the argument. The format of a cmd would be "dwm-<event name>-<arg>", so the cmd can easily be translated into an IPC command. Call member functions for all dwmipc events for better organization and to avoid cluttering the constructor. The dwmipc event functions are now just assigned to a lambda that calls a member function. Add update_tag_labels function for updating the tag labels based on their state since this code is repetetive. Add update_title_labels function since that code is also somewhat repetetive. Move reconnect code to reconnect_dwm for better organization. Use pointers to m_monitors array elements instead of holding onto indices, since most of the time, a member of the Monitor element will need to be accessed. These variables should always hold a valid address starting in the constructor, so checks for nullptr should not be necessary. A monitor will always be active and the bar will always be mapped onto a monitor. Add some comments where needed. Reorganize the constructor into a more logical format Only subscribe to events if their labels are included in the default format. Follow clang-tidy warnings and use trailing return types. Move m_ipc->get_monitors to update_monitor_ref since in most cases where the monitor references would need to be updated using geometry, m_ipc->get_monitors would need to be called.
2020-07-20 02:52:50 +00:00
void update_tag_labels();
void update_title_label(unsigned int client_id);
auto get_state(tag_mask_t bit_mask) const -> state_t;
auto check_send_cmd(string cmd, const string& ev_name) -> bool;
dwm: Reorganize module Remove EVENT_SCROLL_{UP_DOWN} since it is not being used. Change EVENT_PREFIX to include dash and event names to be just the name without the prefix, for simplified parsing. Use check_send_cmd function to parse the cmd, using the event name as the IPC command name, and the section after the event name to be the argument. The format of a cmd would be "dwm-<event name>-<arg>", so the cmd can easily be translated into an IPC command. Call member functions for all dwmipc events for better organization and to avoid cluttering the constructor. The dwmipc event functions are now just assigned to a lambda that calls a member function. Add update_tag_labels function for updating the tag labels based on their state since this code is repetetive. Add update_title_labels function since that code is also somewhat repetetive. Move reconnect code to reconnect_dwm for better organization. Use pointers to m_monitors array elements instead of holding onto indices, since most of the time, a member of the Monitor element will need to be accessed. These variables should always hold a valid address starting in the constructor, so checks for nullptr should not be necessary. A monitor will always be active and the bar will always be mapped onto a monitor. Add some comments where needed. Reorganize the constructor into a more logical format Only subscribe to events if their labels are included in the default format. Follow clang-tidy warnings and use trailing return types. Move m_ipc->get_monitors to update_monitor_ref since in most cases where the monitor references would need to be updated using geometry, m_ipc->get_monitors would need to be called.
2020-07-20 02:52:50 +00:00
auto reconnect_dwm() -> bool;
bool m_click{true};
bool m_pin_tags{false};
dwm: Reorganize module Remove EVENT_SCROLL_{UP_DOWN} since it is not being used. Change EVENT_PREFIX to include dash and event names to be just the name without the prefix, for simplified parsing. Use check_send_cmd function to parse the cmd, using the event name as the IPC command name, and the section after the event name to be the argument. The format of a cmd would be "dwm-<event name>-<arg>", so the cmd can easily be translated into an IPC command. Call member functions for all dwmipc events for better organization and to avoid cluttering the constructor. The dwmipc event functions are now just assigned to a lambda that calls a member function. Add update_tag_labels function for updating the tag labels based on their state since this code is repetetive. Add update_title_labels function since that code is also somewhat repetetive. Move reconnect code to reconnect_dwm for better organization. Use pointers to m_monitors array elements instead of holding onto indices, since most of the time, a member of the Monitor element will need to be accessed. These variables should always hold a valid address starting in the constructor, so checks for nullptr should not be necessary. A monitor will always be active and the bar will always be mapped onto a monitor. Add some comments where needed. Reorganize the constructor into a more logical format Only subscribe to events if their labels are included in the default format. Follow clang-tidy warnings and use trailing return types. Move m_ipc->get_monitors to update_monitor_ref since in most cases where the monitor references would need to be updated using geometry, m_ipc->get_monitors would need to be called.
2020-07-20 02:52:50 +00:00
const dwmipc::Monitor* m_active_mon = nullptr;
const dwmipc::Monitor* m_bar_mon = nullptr;
unsigned int m_focused_client_id = 0;
label_t m_layout_label;
label_t m_seperator_label;
label_t m_title_label;
dwm: Reorganize module Remove EVENT_SCROLL_{UP_DOWN} since it is not being used. Change EVENT_PREFIX to include dash and event names to be just the name without the prefix, for simplified parsing. Use check_send_cmd function to parse the cmd, using the event name as the IPC command name, and the section after the event name to be the argument. The format of a cmd would be "dwm-<event name>-<arg>", so the cmd can easily be translated into an IPC command. Call member functions for all dwmipc events for better organization and to avoid cluttering the constructor. The dwmipc event functions are now just assigned to a lambda that calls a member function. Add update_tag_labels function for updating the tag labels based on their state since this code is repetetive. Add update_title_labels function since that code is also somewhat repetetive. Move reconnect code to reconnect_dwm for better organization. Use pointers to m_monitors array elements instead of holding onto indices, since most of the time, a member of the Monitor element will need to be accessed. These variables should always hold a valid address starting in the constructor, so checks for nullptr should not be necessary. A monitor will always be active and the bar will always be mapped onto a monitor. Add some comments where needed. Reorganize the constructor into a more logical format Only subscribe to events if their labels are included in the default format. Follow clang-tidy warnings and use trailing return types. Move m_ipc->get_monitors to update_monitor_ref since in most cases where the monitor references would need to be updated using geometry, m_ipc->get_monitors would need to be called.
2020-07-20 02:52:50 +00:00
unique_ptr<dwmipc::Connection> m_ipc;
shared_ptr<std::vector<dwmipc::Monitor>> m_monitors;
std::unordered_map<state_t, label_t> m_state_labels;
vector<tag_t> m_tags;
};
} // namespace modules
POLYBAR_NS_END