mirror of
https://github.com/polybar/polybar.git
synced 2024-10-27 05:23:39 -04:00
* Add toggle_visible action * Add set_visible and set_invisible actions * Rename toggle_visible method to match `action_toggle_visible` -> `action_toggle_visibility` Matches with `EVENT_TOGGLE_VISIBILITY` * Update CHANGELOG * Revert #2320 IPC commands IPC commands are no longer necessary now that the actions are implemented. Changed some method permissions as well to reflect this. * Add logging and change action names - `module_toggle` - `module_show` - `module_hide` Delineate common actions to all modules with a `module_` prefix (for future actions too) * Update documentation
This commit is contained in:
parent
dcd33057fd
commit
06932007a0
7 changed files with 53 additions and 46 deletions
|
@ -76,12 +76,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
([`#316`](https://github.com/polybar/polybar/issues/316))
|
||||
- Added .ini extension check to the default config search.
|
||||
([`#2323`](https://github.com/polybar/polybar/issues/2323))
|
||||
- IPC commands to change visibility of modules
|
||||
(`hide.<name>`, `show.<name>`, and `toggle.<name>`)
|
||||
([`#2108`](https://github.com/polybar/polybar/issues/2108))
|
||||
- Config option to hide a certain module
|
||||
(`hidden = false`)
|
||||
([`#2108`](https://github.com/polybar/polybar/issues/2108))
|
||||
- Actions to control visibility of modules
|
||||
(`module_toggle`, `module_show`, and `module_hide`)
|
||||
([`#2108`](https://github.com/polybar/polybar/issues/2108))
|
||||
- `internal/xworkspaces`: Make the urgent hint persistent
|
||||
([`#1081`](https://github.com/polybar/polybar/issues/1081))
|
||||
- `internal/network`: `interface-type` may be used in place of `interface` to
|
||||
|
|
|
@ -121,6 +121,19 @@ Available Actions
|
|||
The following modules have actions available. Most of them are already used by
|
||||
the module by default for click and scroll events.
|
||||
|
||||
All Modules
|
||||
^^^^^^^^^^^
|
||||
|
||||
These actions are available to all modules and are prefixed with ``module_``.
|
||||
|
||||
:``module_show``, ``module_hide``:
|
||||
Shows/Hides a module. The module is still running in the background when
|
||||
hidden, it is just not drawn. The starting state can be configured with the
|
||||
`hidden` configuration option.
|
||||
|
||||
:``module_toggle``:
|
||||
Toggles the visibility of a module.
|
||||
|
||||
internal/date
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -76,8 +76,6 @@ class controller
|
|||
bool forward_action(const actions_util::action& cmd);
|
||||
bool try_forward_legacy_action(const string& cmd);
|
||||
|
||||
void switch_module_visibility(string module_name_raw, int visible);
|
||||
|
||||
connection& m_connection;
|
||||
signal_emitter& m_sig;
|
||||
const logger& m_log;
|
||||
|
|
|
@ -118,7 +118,6 @@ namespace modules {
|
|||
virtual string name() const = 0;
|
||||
virtual bool running() const = 0;
|
||||
virtual bool visible() const = 0;
|
||||
virtual void set_visible(bool value) = 0;
|
||||
|
||||
/**
|
||||
* Handle action, possibly with data attached
|
||||
|
@ -145,6 +144,10 @@ namespace modules {
|
|||
module(const bar_settings bar, string name);
|
||||
~module() noexcept;
|
||||
|
||||
static constexpr auto EVENT_MODULE_TOGGLE = "module_toggle";
|
||||
static constexpr auto EVENT_MODULE_SHOW = "module_show";
|
||||
static constexpr auto EVENT_MODULE_HIDE = "module_hide";
|
||||
|
||||
string type() const override;
|
||||
|
||||
string name_raw() const override;
|
||||
|
@ -152,7 +155,6 @@ namespace modules {
|
|||
bool running() const override;
|
||||
|
||||
bool visible() const override;
|
||||
void set_visible(bool value) override;
|
||||
|
||||
void stop() override;
|
||||
void halt(string error_message) override;
|
||||
|
@ -171,6 +173,12 @@ namespace modules {
|
|||
string get_format() const;
|
||||
string get_output();
|
||||
|
||||
void set_visible(bool value);
|
||||
|
||||
void action_module_toggle();
|
||||
void action_module_show();
|
||||
void action_module_hide();
|
||||
|
||||
protected:
|
||||
signal_emitter& m_sig;
|
||||
const bar_settings m_bar;
|
||||
|
|
|
@ -26,7 +26,11 @@ namespace modules {
|
|||
, m_builder(make_unique<builder>(bar))
|
||||
, m_formatter(make_unique<module_formatter>(m_conf, m_name))
|
||||
, m_handle_events(m_conf.get(m_name, "handle-events", true))
|
||||
, m_visible(!m_conf.get(m_name, "hidden", false)) {}
|
||||
, m_visible(!m_conf.get(m_name, "hidden", false)) {
|
||||
m_router->register_action(EVENT_MODULE_TOGGLE, &module<Impl>::action_module_toggle);
|
||||
m_router->register_action(EVENT_MODULE_SHOW, &module<Impl>::action_module_show);
|
||||
m_router->register_action(EVENT_MODULE_HIDE, &module<Impl>::action_module_hide);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
module<Impl>::~module() noexcept {
|
||||
|
@ -67,13 +71,6 @@ namespace modules {
|
|||
return static_cast<bool>(m_visible);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::set_visible(bool value) {
|
||||
m_log.info("%s: Visibility changed (state=%s)", m_name, value ? "shown" : "hidden");
|
||||
m_visible = value;
|
||||
broadcast();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::stop() {
|
||||
if (!static_cast<bool>(m_enabled)) {
|
||||
|
@ -231,6 +228,28 @@ namespace modules {
|
|||
return format->decorate(&*m_builder, m_builder->flush());
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::set_visible(bool value) {
|
||||
m_log.notice("%s: Visibility changed (state=%s)", m_name, value ? "shown" : "hidden");
|
||||
m_visible = value;
|
||||
broadcast();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::action_module_toggle() {
|
||||
set_visible(!m_visible);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::action_module_show() {
|
||||
set_visible(true);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::action_module_hide() {
|
||||
set_visible(false);
|
||||
}
|
||||
|
||||
// }}}
|
||||
} // namespace modules
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace modules {
|
|||
bool visible() const override { \
|
||||
return false; \
|
||||
} \
|
||||
void set_visible(bool) override {} \
|
||||
void start() override {} \
|
||||
void stop() override {} \
|
||||
void halt(string) override {} \
|
||||
|
|
|
@ -528,26 +528,6 @@ bool controller::forward_action(const actions_util::action& action_triple) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void controller::switch_module_visibility(string module_name_raw, int visible) {
|
||||
for (auto&& mod : m_modules) {
|
||||
if (mod->name_raw() != module_name_raw)
|
||||
continue;
|
||||
|
||||
if (visible == 0) {
|
||||
mod->set_visible(false);
|
||||
} else if (visible == 1) {
|
||||
mod->set_visible(true);
|
||||
} else if (visible == 2) {
|
||||
mod->set_visible(!mod->visible());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.err("controller: Module '%s' not found for visibility change (state=%s)", module_name_raw,
|
||||
visible ? "shown" : "hidden");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process stored input data
|
||||
*/
|
||||
|
@ -839,10 +819,6 @@ bool controller::on(const signals::ipc::command& evt) {
|
|||
return false;
|
||||
}
|
||||
|
||||
string hide_module{"hide."};
|
||||
string show_module{"show."};
|
||||
string toggle_module{"toggle."};
|
||||
|
||||
if (command == "quit") {
|
||||
enqueue(make_quit_evt(false));
|
||||
} else if (command == "restart") {
|
||||
|
@ -853,12 +829,6 @@ bool controller::on(const signals::ipc::command& evt) {
|
|||
m_bar->show();
|
||||
} else if (command == "toggle") {
|
||||
m_bar->toggle();
|
||||
} else if (command.find(hide_module) == 0) {
|
||||
switch_module_visibility(command.substr(hide_module.length()), 0);
|
||||
} else if (command.find(show_module) == 0) {
|
||||
switch_module_visibility(command.substr(show_module.length()), 1);
|
||||
} else if (command.find(toggle_module) == 0) {
|
||||
switch_module_visibility(command.substr(toggle_module.length()), 2);
|
||||
} else {
|
||||
m_log.warn("\"%s\" is not a valid ipc command", command);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue