mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
modules: Revert button to label
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include "modules/wireplumber.hpp"
|
||||
|
||||
waybar::modules::Wireplumber::Wireplumber(const std::string &id, const Json::Value &config)
|
||||
: AButton(config, "wireplumber", id, "{volume}%"),
|
||||
waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "wireplumber", id, "{volume}%"),
|
||||
wp_core_(nullptr),
|
||||
apis_(nullptr),
|
||||
om_(nullptr),
|
||||
@ -9,31 +9,30 @@ waybar::modules::Wireplumber::Wireplumber(const std::string &id, const Json::Val
|
||||
muted_(false),
|
||||
volume_(0.0),
|
||||
node_id_(0) {
|
||||
wp_init(WP_INIT_ALL);
|
||||
wp_core_ = wp_core_new(NULL, NULL);
|
||||
apis_ = g_ptr_array_new_with_free_func(g_object_unref);
|
||||
om_ = wp_object_manager_new();
|
||||
wp_init(WP_INIT_ALL);
|
||||
wp_core_ = wp_core_new(NULL, NULL);
|
||||
apis_ = g_ptr_array_new_with_free_func(g_object_unref);
|
||||
om_ = wp_object_manager_new();
|
||||
|
||||
prepare();
|
||||
prepare();
|
||||
|
||||
loadRequiredApiModules();
|
||||
loadRequiredApiModules();
|
||||
|
||||
if (!wp_core_connect(wp_core_)) {
|
||||
throw std::runtime_error("Could not connect to PipeWire\n");
|
||||
}
|
||||
if (!wp_core_connect(wp_core_)) {
|
||||
throw std::runtime_error("Could not connect to PipeWire\n");
|
||||
}
|
||||
|
||||
g_signal_connect_swapped(om_, "installed", (GCallback)onObjectManagerInstalled, this);
|
||||
|
||||
activatePlugins();
|
||||
|
||||
dp.emit();
|
||||
}
|
||||
g_signal_connect_swapped(om_, "installed", (GCallback)onObjectManagerInstalled, this);
|
||||
|
||||
activatePlugins();
|
||||
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
waybar::modules::Wireplumber::~Wireplumber() {
|
||||
g_clear_pointer(&apis_, g_ptr_array_unref);
|
||||
g_clear_object(&om_);
|
||||
g_clear_object(&wp_core_);
|
||||
|
||||
}
|
||||
|
||||
uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplumber* self) {
|
||||
@ -55,7 +54,9 @@ uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplu
|
||||
}
|
||||
|
||||
void waybar::modules::Wireplumber::updateNodeName(waybar::modules::Wireplumber* self) {
|
||||
auto proxy = static_cast<WpPipewireObject *>(wp_object_manager_lookup(self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "object.id", "=u", self->node_id_, NULL));
|
||||
auto proxy = static_cast<WpPipewireObject*>(wp_object_manager_lookup(
|
||||
self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "object.id", "=u",
|
||||
self->node_id_, NULL));
|
||||
|
||||
if (!proxy) {
|
||||
throw std::runtime_error(fmt::format("Object '{}' not found\n", self->node_id_));
|
||||
@ -85,7 +86,8 @@ void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* se
|
||||
}
|
||||
|
||||
void waybar::modules::Wireplumber::onObjectManagerInstalled(waybar::modules::Wireplumber* self) {
|
||||
self->node_id_ = self->config_["node-id"].isInt() ? self->config_["node-id"].asInt() : getDefaultNodeId(self);
|
||||
self->node_id_ =
|
||||
self->config_["node-id"].isInt() ? self->config_["node-id"].asInt() : getDefaultNodeId(self);
|
||||
|
||||
g_autoptr(WpPlugin) mixer_api = wp_plugin_find(self->wp_core_, "mixer-api");
|
||||
|
||||
@ -94,7 +96,8 @@ void waybar::modules::Wireplumber::onObjectManagerInstalled(waybar::modules::Wir
|
||||
g_signal_connect_swapped(mixer_api, "changed", (GCallback)updateVolume, self);
|
||||
}
|
||||
|
||||
void waybar::modules::Wireplumber::onPluginActivated(WpObject* p, GAsyncResult* res, waybar::modules::Wireplumber* self) {
|
||||
void waybar::modules::Wireplumber::onPluginActivated(WpObject* p, GAsyncResult* res,
|
||||
waybar::modules::Wireplumber* self) {
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!wp_object_activate_finish(p, res, &error)) {
|
||||
@ -108,34 +111,38 @@ void waybar::modules::Wireplumber::onPluginActivated(WpObject* p, GAsyncResult*
|
||||
|
||||
void waybar::modules::Wireplumber::activatePlugins() {
|
||||
for (uint16_t i = 0; i < apis_->len; i++) {
|
||||
WpPlugin* plugin = static_cast<WpPlugin *>(g_ptr_array_index(apis_, i));
|
||||
WpPlugin* plugin = static_cast<WpPlugin*>(g_ptr_array_index(apis_, i));
|
||||
pending_plugins_++;
|
||||
wp_object_activate(WP_OBJECT(plugin), WP_PLUGIN_FEATURE_ENABLED, NULL, (GAsyncReadyCallback)onPluginActivated, this);
|
||||
wp_object_activate(WP_OBJECT(plugin), WP_PLUGIN_FEATURE_ENABLED, NULL,
|
||||
(GAsyncReadyCallback)onPluginActivated, this);
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Wireplumber::prepare() {
|
||||
wp_object_manager_add_interest(om_, WP_TYPE_NODE, NULL);
|
||||
wp_object_manager_request_object_features(om_, WP_TYPE_GLOBAL_PROXY, WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
|
||||
wp_object_manager_request_object_features(om_, WP_TYPE_GLOBAL_PROXY,
|
||||
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
|
||||
}
|
||||
|
||||
void waybar::modules::Wireplumber::loadRequiredApiModules() {
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!wp_core_load_component(wp_core_, "libwireplumber-module-default-nodes-api", "module", NULL, &error)) {
|
||||
if (!wp_core_load_component(wp_core_, "libwireplumber-module-default-nodes-api", "module", NULL,
|
||||
&error)) {
|
||||
throw std::runtime_error(error->message);
|
||||
}
|
||||
|
||||
if (!wp_core_load_component(wp_core_, "libwireplumber-module-mixer-api", "module", NULL, &error)) {
|
||||
if (!wp_core_load_component(wp_core_, "libwireplumber-module-mixer-api", "module", NULL,
|
||||
&error)) {
|
||||
throw std::runtime_error(error->message);
|
||||
}
|
||||
|
||||
g_ptr_array_add(apis_, wp_plugin_find(wp_core_, "default-nodes-api"));
|
||||
g_ptr_array_add (apis_, ({
|
||||
WpPlugin *p = wp_plugin_find(wp_core_, "mixer-api");
|
||||
g_object_set (G_OBJECT (p), "scale", 1 /* cubic */, NULL);
|
||||
p;
|
||||
}));
|
||||
g_ptr_array_add(apis_, ({
|
||||
WpPlugin* p = wp_plugin_find(wp_core_, "mixer-api");
|
||||
g_object_set(G_OBJECT(p), "scale", 1 /* cubic */, NULL);
|
||||
p;
|
||||
}));
|
||||
}
|
||||
|
||||
auto waybar::modules::Wireplumber::update() -> void {
|
||||
@ -144,13 +151,14 @@ auto waybar::modules::Wireplumber::update() -> void {
|
||||
|
||||
if (muted_) {
|
||||
format = config_["format-muted"].isString() ? config_["format-muted"].asString() : format;
|
||||
button_.get_style_context()->add_class("muted");
|
||||
label_.get_style_context()->add_class("muted");
|
||||
} else {
|
||||
button_.get_style_context()->remove_class("muted");
|
||||
label_.get_style_context()->remove_class("muted");
|
||||
}
|
||||
|
||||
std::string markup = fmt::format(format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_));
|
||||
label_->set_markup(markup);
|
||||
std::string markup =
|
||||
fmt::format(format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_));
|
||||
label_.set_markup(markup);
|
||||
|
||||
getState(volume_);
|
||||
|
||||
@ -160,13 +168,13 @@ auto waybar::modules::Wireplumber::update() -> void {
|
||||
}
|
||||
|
||||
if (!tooltip_format.empty()) {
|
||||
button_.set_tooltip_text(fmt::format(
|
||||
tooltip_format, fmt::arg("node_name", node_name_), fmt::arg("volume", volume_)));
|
||||
label_.set_tooltip_text(fmt::format(tooltip_format, fmt::arg("node_name", node_name_),
|
||||
fmt::arg("volume", volume_)));
|
||||
} else {
|
||||
button_.set_tooltip_text(node_name_);
|
||||
label_.set_tooltip_text(node_name_);
|
||||
}
|
||||
}
|
||||
|
||||
// Call parent update
|
||||
AButton::update();
|
||||
}
|
||||
ALabel::update();
|
||||
}
|
||||
|
Reference in New Issue
Block a user