26be83f893
* module: Implement proof of concept action router Action implementation inside module becomes much cleaner because each module just registers action names together with a callback (pointer to member function) and the action router does the rest. * Make input function final This forces all modules to use the action router * modules: Catch exceptions in action handlers * Use action router for all modules * Use action_ prefix for function names The mpd module's 'stop' action overwrote the base module's stop function which caused difficult to debug behavior. To prevent this in the future we now prefix each function that is responsible for an action with 'action_' * Cleanup * actions: Throw exception when re-registering action Action names are unique inside modules. Unfortunately there is no way to ensure this statically, the next best thing is to crash the module and let the user know that this is a bug. * Formatting * actions: Ignore data for actions without data This is the same behavior as before. * action_router: Write tests
104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <i3ipc++/ipc.hpp>
|
|
|
|
#include "components/config.hpp"
|
|
#include "modules/meta/event_module.hpp"
|
|
#include "utils/i3.hpp"
|
|
#include "utils/io.hpp"
|
|
|
|
POLYBAR_NS
|
|
|
|
namespace modules {
|
|
class i3_module : public event_module<i3_module> {
|
|
public:
|
|
enum class state {
|
|
NONE,
|
|
/**
|
|
* \brief Active workspace on focused monitor
|
|
*/
|
|
FOCUSED,
|
|
/**
|
|
* \brief Inactive workspace on any monitor
|
|
*/
|
|
UNFOCUSED,
|
|
/**
|
|
* \brief Active workspace on unfocused monitor
|
|
*/
|
|
VISIBLE,
|
|
/**
|
|
* \brief Workspace with urgency hint set
|
|
*/
|
|
URGENT,
|
|
};
|
|
|
|
struct workspace {
|
|
explicit workspace(string name, enum state state_, label_t&& label)
|
|
: name(name), state(state_), label(forward<label_t>(label)) {}
|
|
|
|
operator bool();
|
|
|
|
string name;
|
|
enum state state;
|
|
label_t label;
|
|
};
|
|
|
|
public:
|
|
explicit i3_module(const bar_settings&, string);
|
|
|
|
void stop();
|
|
bool has_event();
|
|
bool update();
|
|
bool build(builder* builder, const string& tag) const;
|
|
|
|
static constexpr auto TYPE = "internal/i3";
|
|
|
|
static constexpr auto EVENT_FOCUS = "focus";
|
|
static constexpr auto EVENT_NEXT = "next";
|
|
static constexpr auto EVENT_PREV = "prev";
|
|
|
|
protected:
|
|
void action_focus(const string& ws);
|
|
void action_next();
|
|
void action_prev();
|
|
|
|
void focus_direction(bool next);
|
|
|
|
private:
|
|
static string make_workspace_command(const string& workspace);
|
|
|
|
static constexpr const char* DEFAULT_TAGS{"<label-state> <label-mode>"};
|
|
static constexpr const char* DEFAULT_MODE{"default"};
|
|
static constexpr const char* DEFAULT_WS_ICON{"ws-icon-default"};
|
|
static constexpr const char* DEFAULT_WS_LABEL{"%icon% %name%"};
|
|
|
|
static constexpr const char* TAG_LABEL_STATE{"<label-state>"};
|
|
static constexpr const char* TAG_LABEL_MODE{"<label-mode>"};
|
|
|
|
map<state, label_t> m_statelabels;
|
|
vector<unique_ptr<workspace>> m_workspaces;
|
|
iconset_t m_icons;
|
|
|
|
label_t m_modelabel;
|
|
bool m_modeactive{false};
|
|
|
|
/**
|
|
* Separator that is inserted in between workspaces
|
|
*/
|
|
label_t m_labelseparator;
|
|
|
|
bool m_click{true};
|
|
bool m_scroll{true};
|
|
bool m_revscroll{true};
|
|
bool m_wrap{true};
|
|
bool m_indexsort{false};
|
|
bool m_pinworkspaces{false};
|
|
bool m_strip_wsnumbers{false};
|
|
bool m_fuzzy_match{false};
|
|
|
|
unique_ptr<i3_util::connection_t> m_ipc;
|
|
};
|
|
} // namespace modules
|
|
|
|
POLYBAR_NS_END
|