mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Add idle inhibitor module
This commit is contained in:
@ -55,6 +55,10 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
|
||||
o->xdg_output_manager = static_cast<struct zxdg_output_manager_v1 *>(
|
||||
wl_registry_bind(registry, name,
|
||||
&zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION));
|
||||
} else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) {
|
||||
o->idle_inhibit_manager = static_cast<struct zwp_idle_inhibit_manager_v1 *>(
|
||||
wl_registry_bind(registry, name,
|
||||
&zwp_idle_inhibit_manager_v1_interface, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +142,7 @@ int waybar::Client::main(int argc, char* argv[])
|
||||
bars.clear();
|
||||
zxdg_output_manager_v1_destroy(xdg_output_manager);
|
||||
zwlr_layer_shell_v1_destroy(layer_shell);
|
||||
zwp_idle_inhibit_manager_v1_destroy(idle_inhibit_manager);
|
||||
wl_registry_destroy(registry);
|
||||
wl_seat_destroy(seat);
|
||||
wl_display_disconnect(wl_display);
|
||||
|
@ -24,6 +24,9 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
||||
return new waybar::modules::sway::Window(id, bar_, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (ref == "idle_inhibitor") {
|
||||
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);
|
||||
}
|
||||
if (ref == "memory") {
|
||||
return new waybar::modules::Memory(id, config_[name]);
|
||||
}
|
||||
|
48
src/modules/idle_inhibitor.cpp
Normal file
48
src/modules/idle_inhibitor.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "modules/idle_inhibitor.hpp"
|
||||
|
||||
|
||||
waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: ALabel(config, "{status}"), bar_(bar), status_("deactivated"), idle_inhibitor_(nullptr)
|
||||
{
|
||||
label_.set_name("idle_inhibitor");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
event_box_.signal_button_press_event().connect(
|
||||
sigc::mem_fun(*this, &IdleInhibitor::onClick));
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
waybar::modules::IdleInhibitor::~IdleInhibitor()
|
||||
{
|
||||
if(idle_inhibitor_) {
|
||||
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||
idle_inhibitor_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto waybar::modules::IdleInhibitor::update() -> void
|
||||
{
|
||||
label_.set_markup(
|
||||
fmt::format(format_, fmt::arg("status", status_),
|
||||
fmt::arg("icon", getIcon(0, status_))));
|
||||
label_.set_tooltip_text(status_);
|
||||
}
|
||||
|
||||
bool waybar::modules::IdleInhibitor::onClick(GdkEventButton* const& e)
|
||||
{
|
||||
if(e->button == 1) {
|
||||
if (idle_inhibitor_) {
|
||||
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
|
||||
idle_inhibitor_ = nullptr;
|
||||
status_ = "deactivated";
|
||||
} else {
|
||||
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor(
|
||||
bar_.client.idle_inhibit_manager, bar_.surface);
|
||||
status_ = "activated";
|
||||
}
|
||||
}
|
||||
dp.emit();
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user