mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-28 23:12:29 +01:00 
			
		
		
		
	feat(Bar): handle widget size changes
This commit is contained in:
		| @@ -120,9 +120,9 @@ waybar::modules::Backlight::Backlight(const std::string &name, const Json::Value | ||||
|  | ||||
|     auto udev_fd = udev_monitor_get_fd(mon.get()); | ||||
|  | ||||
|     auto epoll_fd = FileDescriptor{epoll_create1(0)}; | ||||
|     auto epoll_fd = FileDescriptor{epoll_create1(EPOLL_CLOEXEC)}; | ||||
|     check_neq(epoll_fd.get(), -1, "epoll init failed: "); | ||||
|     epoll_event ctl_event; | ||||
|     epoll_event ctl_event{}; | ||||
|     ctl_event.events = EPOLLIN; | ||||
|     ctl_event.data.fd = udev_fd; | ||||
|  | ||||
|   | ||||
| @@ -115,7 +115,7 @@ const std::string waybar::modules::Battery::getState(uint8_t capacity) const { | ||||
|   if (config_["states"].isObject()) { | ||||
|     for (auto it = config_["states"].begin(); it != config_["states"].end(); ++it) { | ||||
|       if (it->isUInt() && it.key().isString()) { | ||||
|         states.push_back({it.key().asString(), it->asUInt()}); | ||||
|         states.emplace_back(it.key().asString(), it->asUInt()); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   | ||||
| @@ -14,10 +14,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) | ||||
|     auto sub_m = | ||||
|         std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() % | ||||
|         interval_.count(); | ||||
|     if (sub_m > 0) | ||||
|     if (sub_m > 0) { | ||||
|       thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1)); | ||||
|     else | ||||
|     } else { | ||||
|       thread_.sleep_until(timeout - std::chrono::seconds(sub_m)); | ||||
|     } | ||||
|   }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -25,7 +25,7 @@ auto waybar::modules::Cpu::update() -> void { | ||||
| uint16_t waybar::modules::Cpu::getCpuLoad() { | ||||
|   struct sysinfo info = {0}; | ||||
|   if (sysinfo(&info) == 0) { | ||||
|     float    f_load = 1.f / (1u << SI_LOAD_SHIFT); | ||||
|     float    f_load = 1.F / (1U << SI_LOAD_SHIFT); | ||||
|     uint16_t load = info.loads[0] * f_load * 100 / get_nprocs(); | ||||
|     return load; | ||||
|   } | ||||
| @@ -70,7 +70,7 @@ std::vector<std::tuple<size_t, size_t>> waybar::modules::Cpu::parseCpuinfo() { | ||||
|     } | ||||
|     std::stringstream   sline(line.substr(5)); | ||||
|     std::vector<size_t> times; | ||||
|     for (size_t time; sline >> time; times.push_back(time)) | ||||
|     for (size_t time = 0; sline >> time; times.push_back(time)) | ||||
|       ; | ||||
|  | ||||
|     size_t idle_time = 0; | ||||
| @@ -79,7 +79,7 @@ std::vector<std::tuple<size_t, size_t>> waybar::modules::Cpu::parseCpuinfo() { | ||||
|       idle_time = times[3]; | ||||
|       total_time = std::accumulate(times.begin(), times.end(), 0); | ||||
|     } | ||||
|     cpuinfo.push_back({idle_time, total_time}); | ||||
|     cpuinfo.emplace_back(idle_time, total_time); | ||||
|   } | ||||
|   return cpuinfo; | ||||
| } | ||||
|   | ||||
| @@ -19,7 +19,7 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& | ||||
| } | ||||
|  | ||||
| waybar::modules::IdleInhibitor::~IdleInhibitor() { | ||||
|   if (idle_inhibitor_) { | ||||
|   if (idle_inhibitor_ != nullptr) { | ||||
|     zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); | ||||
|     idle_inhibitor_ = nullptr; | ||||
|   } | ||||
| @@ -41,7 +41,7 @@ auto waybar::modules::IdleInhibitor::update() -> void { | ||||
| bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { | ||||
|   if (e->button == 1) { | ||||
|     label_.get_style_context()->remove_class(status_); | ||||
|     if (idle_inhibitor_) { | ||||
|     if (idle_inhibitor_ != nullptr) { | ||||
|       zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); | ||||
|       idle_inhibitor_ = nullptr; | ||||
|       status_ = "deactivated"; | ||||
|   | ||||
| @@ -28,19 +28,19 @@ auto waybar::modules::Memory::update() -> void { | ||||
| } | ||||
|  | ||||
| void waybar::modules::Memory::parseMeminfo() { | ||||
|   long          memfree = -1, membuffer = -1, memcache = -1, memavail = -1; | ||||
|   int64_t       memfree = -1, membuffer = -1, memcache = -1, memavail = -1; | ||||
|   std::ifstream info(data_dir_); | ||||
|   if (!info.is_open()) { | ||||
|     throw std::runtime_error("Can't open " + data_dir_); | ||||
|   } | ||||
|   std::string line; | ||||
|   while (getline(info, line)) { | ||||
|     auto posDelim = line.find(":"); | ||||
|     auto posDelim = line.find(':'); | ||||
|     if (posDelim == std::string::npos) { | ||||
|       continue; | ||||
|     } | ||||
|     std::string name = line.substr(0, posDelim); | ||||
|     long        value = std::stol(line.substr(posDelim + 1)); | ||||
|     int64_t     value = std::stol(line.substr(posDelim + 1)); | ||||
|  | ||||
|     if (name.compare("MemTotal") == 0) { | ||||
|       memtotal_ = value; | ||||
|   | ||||
| @@ -68,7 +68,7 @@ void waybar::modules::Network::createInfoSocket() { | ||||
|   nl_socket_disable_seq_check(info_sock_); | ||||
|   nl_socket_set_nonblocking(info_sock_); | ||||
|   nl_socket_modify_cb(info_sock_, NL_CB_VALID, NL_CB_CUSTOM, handleEvents, this); | ||||
|   efd_ = epoll_create1(0); | ||||
|   efd_ = epoll_create1(EPOLL_CLOEXEC); | ||||
|   if (efd_ < 0) { | ||||
|     throw std::runtime_error("Can't create epoll"); | ||||
|   } | ||||
| @@ -114,7 +114,7 @@ void waybar::modules::Network::worker() { | ||||
|     } | ||||
|     thread_timer_.sleep_for(interval_); | ||||
|   }; | ||||
|   std::array<struct epoll_event, EPOLL_MAX> events; | ||||
|   std::array<struct epoll_event, EPOLL_MAX> events{}; | ||||
|   thread_ = [this, &events] { | ||||
|     int ec = epoll_wait(efd_, events.data(), EPOLL_MAX, -1); | ||||
|     if (ec > 0) { | ||||
|   | ||||
| @@ -99,9 +99,13 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) { | ||||
|   } | ||||
|  | ||||
|   if (direction_up) { | ||||
|     if (volume_ + 1 < 100) pa_cvolume_inc(&pa_volume, change); | ||||
|     if (volume_ + 1 < 100) { | ||||
|       pa_cvolume_inc(&pa_volume, change); | ||||
|     } | ||||
|   } else { | ||||
|     if (volume_ - 1 > 0) pa_cvolume_dec(&pa_volume, change); | ||||
|     if (volume_ - 1 > 0) { | ||||
|       pa_cvolume_dec(&pa_volume, change); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   pa_context_set_sink_volume_by_index(context_, sink_idx_, &pa_volume, volumeModifyCb, this); | ||||
| @@ -116,13 +120,8 @@ void waybar::modules::Pulseaudio::subscribeCb(pa_context *                 conte | ||||
|                                               pa_subscription_event_type_t type, uint32_t idx, | ||||
|                                               void *data) { | ||||
|   unsigned facility = type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK; | ||||
|  | ||||
|   switch (facility) { | ||||
|     case PA_SUBSCRIPTION_EVENT_SINK: | ||||
|       pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data); | ||||
|       break; | ||||
|     default: | ||||
|       break; | ||||
|   if (facility == PA_SUBSCRIPTION_EVENT_SINK) { | ||||
|     pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -131,7 +130,7 @@ void waybar::modules::Pulseaudio::subscribeCb(pa_context *                 conte | ||||
|  */ | ||||
| void waybar::modules::Pulseaudio::volumeModifyCb(pa_context *c, int success, void *data) { | ||||
|   auto pa = static_cast<waybar::modules::Pulseaudio *>(data); | ||||
|   if (success) { | ||||
|   if (success != 0) { | ||||
|     pa_context_get_sink_info_by_index(pa->context_, pa->sink_idx_, sinkInfoCb, data); | ||||
|   } | ||||
| } | ||||
| @@ -146,10 +145,10 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_ | ||||
|     pa->pa_volume_ = i->volume; | ||||
|     float volume = static_cast<float>(pa_cvolume_avg(&(pa->pa_volume_))) / float{PA_VOLUME_NORM}; | ||||
|     pa->sink_idx_ = i->index; | ||||
|     pa->volume_ = std::round(volume * 100.0f); | ||||
|     pa->volume_ = std::round(volume * 100.0F); | ||||
|     pa->muted_ = i->mute != 0; | ||||
|     pa->desc_ = i->description; | ||||
|     pa->port_name_ = i->active_port ? i->active_port->name : "Unknown"; | ||||
|     pa->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; | ||||
|     pa->dp.emit(); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "modules/sni/host.hpp" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace waybar::modules::SNI; | ||||
| namespace waybar::modules::SNI { | ||||
|  | ||||
| Host::Host(const std::size_t id, const Json::Value& config, | ||||
|            const std::function<void(std::unique_ptr<Item>&)>& on_add, | ||||
| @@ -96,7 +95,7 @@ void Host::registerHost(GObject* src, GAsyncResult* res, gpointer data) { | ||||
|   g_signal_connect(host->watcher_, "item-registered", G_CALLBACK(&Host::itemRegistered), data); | ||||
|   g_signal_connect(host->watcher_, "item-unregistered", G_CALLBACK(&Host::itemUnregistered), data); | ||||
|   auto items = sn_watcher_dup_registered_items(host->watcher_); | ||||
|   if (items) { | ||||
|   if (items != nullptr) { | ||||
|     for (uint32_t i = 0; items[i] != nullptr; i += 1) { | ||||
|       host->addRegisteredItem(items[i]); | ||||
|     } | ||||
| @@ -122,7 +121,7 @@ void Host::itemUnregistered(SnWatcher* watcher, const gchar* service, gpointer d | ||||
| } | ||||
|  | ||||
| std::tuple<std::string, std::string> Host::getBusNameAndObjectPath(const std::string service) { | ||||
|   auto it = service.find("/"); | ||||
|   auto it = service.find('/'); | ||||
|   if (it != std::string::npos) { | ||||
|     return {service.substr(0, it), service.substr(it)}; | ||||
|   } | ||||
| @@ -134,3 +133,5 @@ void Host::addRegisteredItem(std::string service) { | ||||
|   items_.emplace_back(new Item(bus_name, object_path, config_)); | ||||
|   on_add_(items_.back()); | ||||
| } | ||||
|  | ||||
| } | ||||
| @@ -1,14 +1,13 @@ | ||||
| #include "modules/sni/item.hpp" | ||||
|  | ||||
| #include <glibmm/main.h> | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace Glib; | ||||
| namespace waybar::modules::SNI { | ||||
|  | ||||
| static const ustring  SNI_INTERFACE_NAME = sn_item_interface_info()->name; | ||||
| static const unsigned UPDATE_DEBOUNCE_TIME = 10; | ||||
| static const Glib::ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name; | ||||
| static const unsigned      UPDATE_DEBOUNCE_TIME = 10; | ||||
|  | ||||
| waybar::modules::SNI::Item::Item(std::string bn, std::string op, const Json::Value& config) | ||||
| Item::Item(const std::string& bn, const std::string& op, const Json::Value& config) | ||||
|     : bus_name(bn), | ||||
|       object_path(op), | ||||
|       icon_size(16), | ||||
| @@ -34,7 +33,7 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op, const Json::Val | ||||
|                                    interface); | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) { | ||||
| void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) { | ||||
|   try { | ||||
|     this->proxy_ = Gio::DBus::Proxy::create_for_bus_finish(result); | ||||
|     /* Properties are already cached during object creation */ | ||||
| @@ -69,11 +68,11 @@ void waybar::modules::SNI::Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& resu | ||||
| } | ||||
|  | ||||
| template <typename T> | ||||
| T get_variant(VariantBase& value) { | ||||
|   return VariantBase::cast_dynamic<Variant<T>>(value).get(); | ||||
| T get_variant(Glib::VariantBase& value) { | ||||
|   return Glib::VariantBase::cast_dynamic<Glib::Variant<T>>(value).get(); | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::setProperty(const ustring& name, VariantBase& value) { | ||||
| void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) { | ||||
|   if (name == "Category") { | ||||
|     category = get_variant<std::string>(value); | ||||
|   } else if (name == "Id") { | ||||
| @@ -112,29 +111,30 @@ void waybar::modules::SNI::Item::setProperty(const ustring& name, VariantBase& v | ||||
|   } | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::getUpdatedProperties() { | ||||
| void Item::getUpdatedProperties() { | ||||
|   update_pending_ = false; | ||||
|  | ||||
|   auto params = VariantContainerBase::create_tuple({Variant<ustring>::create(SNI_INTERFACE_NAME)}); | ||||
|   auto params = Glib::VariantContainerBase::create_tuple( | ||||
|       {Glib::Variant<Glib::ustring>::create(SNI_INTERFACE_NAME)}); | ||||
|   proxy_->call("org.freedesktop.DBus.Properties.GetAll", | ||||
|                sigc::mem_fun(*this, &Item::processUpdatedProperties), | ||||
|                params); | ||||
| }; | ||||
|  | ||||
| void waybar::modules::SNI::Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) { | ||||
| void Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) { | ||||
|   try { | ||||
|     auto result = proxy_->call_finish(_result); | ||||
|     // extract "a{sv}" from VariantContainerBase | ||||
|     Variant<std::map<ustring, VariantBase>> properties_variant; | ||||
|     Glib::Variant<std::map<Glib::ustring, Glib::VariantBase>> properties_variant; | ||||
|     result.get_child(properties_variant); | ||||
|     auto properties = properties_variant.get(); | ||||
|  | ||||
|     for (const auto& [name, value] : properties) { | ||||
|       VariantBase old_value; | ||||
|       Glib::VariantBase old_value; | ||||
|       proxy_->get_cached_property(old_value, name); | ||||
|       if (!value.equal(old_value)) { | ||||
|         proxy_->set_cached_property(name, value); | ||||
|         setProperty(name, const_cast<VariantBase&>(value)); | ||||
|         setProperty(name, const_cast<Glib::VariantBase&>(value)); | ||||
|       } | ||||
|     } | ||||
|  | ||||
| @@ -147,8 +147,8 @@ void waybar::modules::SNI::Item::processUpdatedProperties(Glib::RefPtr<Gio::Asyn | ||||
|   } | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::onSignal(const ustring& sender_name, const ustring& signal_name, | ||||
|                                           const VariantContainerBase& arguments) { | ||||
| void Item::onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name, | ||||
|                     const Glib::VariantContainerBase& arguments) { | ||||
|   if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) { | ||||
|     /* Debounce signals and schedule update of all properties. | ||||
|      * Based on behavior of Plasma dataengine for StatusNotifierItem. | ||||
| @@ -161,7 +161,7 @@ void waybar::modules::SNI::Item::onSignal(const ustring& sender_name, const ustr | ||||
|  | ||||
| static void pixbuf_data_deleter(const guint8* data) { g_free((void*)data); } | ||||
|  | ||||
| Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::extractPixBuf(GVariant* variant) { | ||||
| Glib::RefPtr<Gdk::Pixbuf> Item::extractPixBuf(GVariant* variant) { | ||||
|   GVariantIter* it; | ||||
|   g_variant_get(variant, "a(iiay)", &it); | ||||
|   if (it == nullptr) { | ||||
| @@ -213,7 +213,7 @@ Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::extractPixBuf(GVariant* va | ||||
|   return Glib::RefPtr<Gdk::Pixbuf>{}; | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::updateImage() { | ||||
| void Item::updateImage() { | ||||
|   image.set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU); | ||||
|   image.set_pixel_size(icon_size); | ||||
|   if (!icon_name.empty()) { | ||||
| @@ -244,8 +244,7 @@ void waybar::modules::SNI::Item::updateImage() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(std::string name, | ||||
|                                                                     int         request_size) { | ||||
| Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int request_size) { | ||||
|   int tmp_size = 0; | ||||
|   icon_theme->rescan_if_needed(); | ||||
|   auto sizes = icon_theme->get_icon_sizes(name.c_str()); | ||||
| @@ -277,12 +276,12 @@ Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(std::string | ||||
|       name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Item::onMenuDestroyed(Item* self) { | ||||
| void Item::onMenuDestroyed(Item* self) { | ||||
|   self->gtk_menu = nullptr; | ||||
|   self->dbus_menu = nullptr; | ||||
| } | ||||
|  | ||||
| bool waybar::modules::SNI::Item::makeMenu(GdkEventButton* const& ev) { | ||||
| bool Item::makeMenu(GdkEventButton* const& ev) { | ||||
|   if (gtk_menu == nullptr) { | ||||
|     if (!menu.empty()) { | ||||
|       dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); | ||||
| @@ -305,9 +304,9 @@ bool waybar::modules::SNI::Item::makeMenu(GdkEventButton* const& ev) { | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| bool waybar::modules::SNI::Item::handleClick(GdkEventButton* const& ev) { | ||||
|   auto parameters = VariantContainerBase::create_tuple( | ||||
|       {Variant<int>::create(ev->x), Variant<int>::create(ev->y)}); | ||||
| bool Item::handleClick(GdkEventButton* const& ev) { | ||||
|   auto parameters = Glib::VariantContainerBase::create_tuple( | ||||
|       {Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)}); | ||||
|   if ((ev->button == 1 && item_is_menu) || ev->button == 3) { | ||||
|     if (!makeMenu(ev)) { | ||||
|       proxy_->call("ContextMenu", parameters); | ||||
| @@ -322,3 +321,5 @@ bool waybar::modules::SNI::Item::handleClick(GdkEventButton* const& ev) { | ||||
|   } | ||||
|   return false; | ||||
| } | ||||
|  | ||||
| }  // namespace waybar::modules::SNI | ||||
| @@ -1,36 +1,42 @@ | ||||
| #include "modules/sni/tray.hpp" | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) | ||||
| namespace waybar::modules::SNI { | ||||
|  | ||||
| Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) | ||||
|     : config_(config), | ||||
|       box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), | ||||
|       watcher_(), | ||||
|       host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1), | ||||
|             std::bind(&Tray::onRemove, this, std::placeholders::_1)) { | ||||
|   box_.set_name("tray"); | ||||
|   if (!id.empty()) { | ||||
|     box_.get_style_context()->add_class(id); | ||||
|   } | ||||
|   if (config_["spacing"].isUInt()) { | ||||
|     box_.set_spacing(config_["spacing"].asUInt()); | ||||
|   } | ||||
|   nb_hosts_ += 1; | ||||
|   dp.emit(); | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item) { | ||||
| void Tray::onAdd(std::unique_ptr<Item>& item) { | ||||
|   box_.pack_start(item->event_box); | ||||
|   dp.emit(); | ||||
| } | ||||
|  | ||||
| void waybar::modules::SNI::Tray::onRemove(std::unique_ptr<Item>& item) { | ||||
| void Tray::onRemove(std::unique_ptr<Item>& item) { | ||||
|   box_.remove(item->event_box); | ||||
|   dp.emit(); | ||||
| } | ||||
|  | ||||
| auto waybar::modules::SNI::Tray::update() -> void { | ||||
|   if (box_.get_children().size() > 0) { | ||||
|     box_.set_name("tray"); | ||||
|     box_.show_all(); | ||||
| auto Tray::update() -> void { | ||||
|   if (box_.get_children().empty()) { | ||||
|     box_.hide(); | ||||
|   } else { | ||||
|     box_.set_name(""); | ||||
|     box_.show_all(); | ||||
|   } | ||||
| } | ||||
|  | ||||
| waybar::modules::SNI::Tray::operator Gtk::Widget&() { return box_; } | ||||
| Tray::operator Gtk::Widget&() { return box_; } | ||||
|  | ||||
| } | ||||
| @@ -19,14 +19,14 @@ Watcher::~Watcher() { | ||||
|     bus_name_id_ = 0; | ||||
|   } | ||||
|  | ||||
|   if (hosts_ != NULL) { | ||||
|   if (hosts_ != nullptr) { | ||||
|     g_slist_free_full(hosts_, gfWatchFree); | ||||
|     hosts_ = NULL; | ||||
|     hosts_ = nullptr; | ||||
|   } | ||||
|  | ||||
|   if (items_ != NULL) { | ||||
|   if (items_ != nullptr) { | ||||
|     g_slist_free_full(items_, gfWatchFree); | ||||
|     items_ = NULL; | ||||
|     items_ = nullptr; | ||||
|   } | ||||
|   g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(watcher_)); | ||||
| } | ||||
| @@ -122,7 +122,7 @@ gboolean Watcher::handleRegisterItem(Watcher* obj, GDBusMethodInvocation* invoca | ||||
| Watcher::GfWatch* Watcher::gfWatchFind(GSList* list, const gchar* bus_name, | ||||
|                                        const gchar* object_path) { | ||||
|   for (GSList* l = list; l != nullptr; l = g_slist_next(l)) { | ||||
|     GfWatch* watch = static_cast<GfWatch*>(l->data); | ||||
|     auto watch = static_cast<GfWatch*>(l->data); | ||||
|     if (g_strcmp0(watch->bus_name, bus_name) == 0 && | ||||
|         g_strcmp0(watch->object_path, object_path) == 0) { | ||||
|       return watch; | ||||
| @@ -132,11 +132,11 @@ Watcher::GfWatch* Watcher::gfWatchFind(GSList* list, const gchar* bus_name, | ||||
| } | ||||
|  | ||||
| void Watcher::gfWatchFree(gpointer data) { | ||||
|   GfWatch* watch; | ||||
|   auto watch = static_cast<GfWatch*>(data); | ||||
|  | ||||
|   watch = (GfWatch*)data; | ||||
|  | ||||
|   if (watch->watch_id > 0) g_bus_unwatch_name(watch->watch_id); | ||||
|   if (watch->watch_id > 0) { | ||||
|     g_bus_unwatch_name(watch->watch_id); | ||||
|   } | ||||
|  | ||||
|   g_free(watch->service); | ||||
|   g_free(watch->bus_name); | ||||
| @@ -184,8 +184,8 @@ void Watcher::updateRegisteredItems(SnWatcher* obj) { | ||||
|   GVariantBuilder builder; | ||||
|   g_variant_builder_init(&builder, G_VARIANT_TYPE("as")); | ||||
|   for (GSList* l = items_; l != nullptr; l = g_slist_next(l)) { | ||||
|     GfWatch* watch = static_cast<GfWatch*>(l->data); | ||||
|     gchar*   item = g_strdup_printf("%s%s", watch->bus_name, watch->object_path); | ||||
|     auto   watch = static_cast<GfWatch*>(l->data); | ||||
|     gchar* item = g_strdup_printf("%s%s", watch->bus_name, watch->object_path); | ||||
|     g_variant_builder_add(&builder, "s", item); | ||||
|     g_free(item); | ||||
|   } | ||||
|   | ||||
| @@ -8,14 +8,14 @@ Mode::Mode(const std::string& id, const Bar& bar, const Json::Value& config) | ||||
|   if (!id.empty()) { | ||||
|     label_.get_style_context()->add_class(id); | ||||
|   } | ||||
|   ipc_.subscribe("[ \"mode\" ]"); | ||||
|   ipc_.subscribe(R"(["mode"])"); | ||||
|   ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent)); | ||||
|   // Launch worker | ||||
|   worker(); | ||||
|   dp.emit(); | ||||
| } | ||||
|  | ||||
| void Mode::onEvent(const struct Ipc::ipc_response res) { | ||||
| void Mode::onEvent(const struct Ipc::ipc_response &res) { | ||||
|   if (res.payload["change"] != "default") { | ||||
|     mode_ = res.payload["change"].asString(); | ||||
|   } else { | ||||
|   | ||||
| @@ -12,7 +12,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) | ||||
|     label_.set_hexpand(true); | ||||
|     label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); | ||||
|   } | ||||
|   ipc_.subscribe("[\"window\",\"workspace\"]"); | ||||
|   ipc_.subscribe(R"(["window","workspace"])"); | ||||
|   ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent)); | ||||
|   ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd)); | ||||
|   getFocusedWindow(); | ||||
| @@ -20,7 +20,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) | ||||
|   worker(); | ||||
| } | ||||
|  | ||||
| void Window::onEvent(const struct Ipc::ipc_response res) { | ||||
| void Window::onEvent(const struct Ipc::ipc_response& res) { | ||||
|   auto data = res.payload; | ||||
|   // Check for waybar prevents flicker when hovering window module | ||||
|   if ((data["change"] == "focus" || data["change"] == "title") && | ||||
| @@ -38,7 +38,7 @@ void Window::onEvent(const struct Ipc::ipc_response res) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| void Window::onCmd(const struct Ipc::ipc_response res) { | ||||
| void Window::onCmd(const struct Ipc::ipc_response& res) { | ||||
|   auto [id, name] = getFocusedNode(res.payload["nodes"]); | ||||
|   windowId_ = id; | ||||
|   window_ = name; | ||||
| @@ -62,7 +62,7 @@ auto Window::update() -> void { | ||||
|   } | ||||
| } | ||||
|  | ||||
| std::tuple<int, std::string> Window::getFocusedNode(Json::Value nodes) { | ||||
| std::tuple<int, std::string> Window::getFocusedNode(const Json::Value& nodes) { | ||||
|   for (auto const& node : nodes) { | ||||
|     if (node["focused"].asBool() && node["type"] == "con") { | ||||
|       return {node["id"].asInt(), node["name"].asString()}; | ||||
|   | ||||
| @@ -11,7 +11,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value | ||||
|   if (!id.empty()) { | ||||
|     box_.get_style_context()->add_class(id); | ||||
|   } | ||||
|   ipc_.subscribe("[ \"workspace\" ]"); | ||||
|   ipc_.subscribe(R"(["workspace"])"); | ||||
|   ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent)); | ||||
|   ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd)); | ||||
|   ipc_.sendCmd(IPC_GET_WORKSPACES); | ||||
| @@ -19,9 +19,9 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value | ||||
|   worker(); | ||||
| } | ||||
|  | ||||
| void Workspaces::onEvent(const struct Ipc::ipc_response res) { ipc_.sendCmd(IPC_GET_WORKSPACES); } | ||||
| void Workspaces::onEvent(const struct Ipc::ipc_response &res) { ipc_.sendCmd(IPC_GET_WORKSPACES); } | ||||
|  | ||||
| void Workspaces::onCmd(const struct Ipc::ipc_response res) { | ||||
| void Workspaces::onCmd(const struct Ipc::ipc_response &res) { | ||||
|   if (res.type == IPC_GET_WORKSPACES) { | ||||
|     if (res.payload.isArray()) { | ||||
|       std::lock_guard<std::mutex> lock(mutex_); | ||||
| @@ -209,7 +209,7 @@ const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterat | ||||
| } | ||||
|  | ||||
| std::string Workspaces::trimWorkspaceName(std::string name) { | ||||
|   std::size_t found = name.find(":"); | ||||
|   std::size_t found = name.find(':'); | ||||
|   if (found != std::string::npos) { | ||||
|     return name.substr(found + 1); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Alex
					Alex