1 #pragma once 2 3 #include <i3ipc++/ipc.hpp> 4 5 #include "components/config.hpp" 6 #include "modules/meta/event_module.hpp" 7 #include "utils/i3.hpp" 8 #include "utils/io.hpp" 9 10 POLYBAR_NS 11 12 namespace modules { 13 class i3_module : public event_module<i3_module> { 14 public: 15 enum class state { 16 NONE, 17 /** 18 * \brief Active workspace on focused monitor 19 */ 20 FOCUSED, 21 /** 22 * \brief Inactive workspace on any monitor 23 */ 24 UNFOCUSED, 25 /** 26 * \brief Active workspace on unfocused monitor 27 */ 28 VISIBLE, 29 /** 30 * \brief Workspace with urgency hint set 31 */ 32 URGENT, 33 }; 34 35 struct workspace { workspacemodules::i3_module::workspace36 explicit workspace(string name, enum state state_, label_t&& label) 37 : name(name), state(state_), label(forward<label_t>(label)) {} 38 39 operator bool(); 40 41 string name; 42 enum state state; 43 label_t label; 44 }; 45 46 public: 47 explicit i3_module(const bar_settings&, string); 48 49 void stop(); 50 bool has_event(); 51 bool update(); 52 bool build(builder* builder, const string& tag) const; 53 54 static constexpr auto TYPE = "internal/i3"; 55 56 static constexpr auto EVENT_FOCUS = "focus"; 57 static constexpr auto EVENT_NEXT = "next"; 58 static constexpr auto EVENT_PREV = "prev"; 59 60 protected: 61 bool input(const string& action, const string& data); 62 63 private: 64 static string make_workspace_command(const string& workspace); 65 66 static constexpr const char* DEFAULT_TAGS{"<label-state> <label-mode>"}; 67 static constexpr const char* DEFAULT_MODE{"default"}; 68 static constexpr const char* DEFAULT_WS_ICON{"ws-icon-default"}; 69 static constexpr const char* DEFAULT_WS_LABEL{"%icon% %name%"}; 70 71 static constexpr const char* TAG_LABEL_STATE{"<label-state>"}; 72 static constexpr const char* TAG_LABEL_MODE{"<label-mode>"}; 73 74 map<state, label_t> m_statelabels; 75 vector<unique_ptr<workspace>> m_workspaces; 76 iconset_t m_icons; 77 78 label_t m_modelabel; 79 bool m_modeactive{false}; 80 81 /** 82 * Separator that is inserted in between workspaces 83 */ 84 label_t m_labelseparator; 85 86 bool m_click{true}; 87 bool m_scroll{true}; 88 bool m_revscroll{true}; 89 bool m_wrap{true}; 90 bool m_indexsort{false}; 91 bool m_pinworkspaces{false}; 92 bool m_strip_wsnumbers{false}; 93 bool m_fuzzy_match{false}; 94 95 unique_ptr<i3_util::connection_t> m_ipc; 96 }; 97 } // namespace modules 98 99 POLYBAR_NS_END 100