waybar/include/modules/sni/item.hpp

93 lines
2.7 KiB
C++
Raw Normal View History

#pragma once
#include <dbus-status-notifier-item.h>
#include <giomm/dbusproxy.h>
#include <glibmm/refptr.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/icontheme.h>
#include <gtkmm/image.h>
#include <gtkmm/menu.h>
2018-10-26 14:53:39 +02:00
#include <json/json.h>
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
#include <sigc++/trackable.h>
#include <set>
#include <string_view>
#include "bar.hpp"
namespace waybar::modules::SNI {
struct ToolTip {
Glib::ustring icon_name;
Glib::ustring text;
};
class Item : public sigc::trackable {
public:
Item(const std::string&, const std::string&, const Json::Value&, const Bar&);
2018-11-22 15:47:23 +01:00
~Item() = default;
std::string bus_name;
std::string object_path;
2022-04-06 08:37:19 +02:00
int icon_size;
int effective_icon_size;
Gtk::Image image;
2018-11-22 15:47:23 +01:00
Gtk::EventBox event_box;
2022-04-06 08:37:19 +02:00
std::string category;
std::string id;
2022-04-06 08:37:19 +02:00
std::string title;
std::string icon_name;
Glib::RefPtr<Gdk::Pixbuf> icon_pixmap;
2019-04-11 15:20:39 +02:00
Glib::RefPtr<Gtk::IconTheme> icon_theme;
2022-04-06 08:37:19 +02:00
std::string overlay_icon_name;
std::string attention_icon_name;
std::string attention_movie_name;
std::string icon_theme_path;
std::string menu;
ToolTip tooltip;
DbusmenuGtkMenu* dbus_menu = nullptr;
Gtk::Menu* gtk_menu = nullptr;
/**
* ItemIsMenu flag means that the item only supports the context menu.
* Default value is true because libappindicator supports neither ItemIsMenu nor Activate method
* while compliant SNI implementation would always reset the flag to desired value.
*/
bool item_is_menu = true;
private:
void onConfigure(GdkEventConfigure* ev);
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
void setProperty(const Glib::ustring& name, Glib::VariantBase& value);
void setStatus(const Glib::ustring& value);
void getUpdatedProperties();
void processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& result);
void onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
const Glib::VariantContainerBase& arguments);
2022-04-06 08:37:19 +02:00
void updateImage();
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
2021-08-01 01:14:02 +02:00
Glib::RefPtr<Gdk::Pixbuf> getIconPixbuf();
2019-04-24 12:37:24 +02:00
Glib::RefPtr<Gdk::Pixbuf> getIconByName(const std::string& name, int size);
2022-04-06 08:37:19 +02:00
double getScaledIconSize();
static void onMenuDestroyed(Item* self, GObject* old_menu_pointer);
void makeMenu();
bool handleClick(GdkEventButton* const& /*ev*/);
bool handleScroll(GdkEventScroll* const&);
2021-06-27 01:33:25 +02:00
// smooth scrolling threshold
gdouble scroll_threshold_ = 0;
gdouble distance_scrolled_x_ = 0;
gdouble distance_scrolled_y_ = 0;
// visibility of items with Status == Passive
bool show_passive_ = false;
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
2019-05-13 15:15:50 +02:00
Glib::RefPtr<Gio::Cancellable> cancellable_;
2022-04-06 08:37:19 +02:00
std::set<std::string_view> update_pending_;
};
} // namespace waybar::modules::SNI