2018-08-29 18:36:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <dbus-status-notifier-item.h>
|
2019-03-28 02:56:19 +00:00
|
|
|
#include <giomm/dbusproxy.h>
|
2019-04-17 12:19:04 +00:00
|
|
|
#include <glibmm/refptr.h>
|
2019-01-08 20:05:44 +00:00
|
|
|
#include <gtkmm/eventbox.h>
|
|
|
|
#include <gtkmm/icontheme.h>
|
2019-04-17 12:19:04 +00:00
|
|
|
#include <gtkmm/image.h>
|
2019-01-08 20:05:44 +00:00
|
|
|
#include <gtkmm/menu.h>
|
2018-10-26 12:53:39 +00:00
|
|
|
#include <json/json.h>
|
2018-11-16 11:01:03 +00:00
|
|
|
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
2019-03-28 02:56:19 +00:00
|
|
|
#include <sigc++/trackable.h>
|
2018-08-29 18:36:39 +00:00
|
|
|
|
2021-06-23 07:27:42 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string_view>
|
|
|
|
|
2021-08-17 06:33:29 +00:00
|
|
|
#include "bar.hpp"
|
|
|
|
|
2018-08-29 18:36:39 +00:00
|
|
|
namespace waybar::modules::SNI {
|
|
|
|
|
2021-06-24 06:47:35 +00:00
|
|
|
struct ToolTip {
|
|
|
|
Glib::ustring icon_name;
|
|
|
|
Glib::ustring text;
|
|
|
|
};
|
|
|
|
|
2019-03-28 02:56:19 +00:00
|
|
|
class Item : public sigc::trackable {
|
2019-04-17 12:19:04 +00:00
|
|
|
public:
|
2021-08-17 06:33:29 +00:00
|
|
|
Item(const std::string&, const std::string&, const Json::Value&, const Bar&);
|
2018-11-22 14:47:23 +00:00
|
|
|
~Item() = default;
|
2018-10-04 16:47:06 +00:00
|
|
|
|
|
|
|
std::string bus_name;
|
|
|
|
std::string object_path;
|
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
int icon_size;
|
|
|
|
int effective_icon_size;
|
|
|
|
Gtk::Image image;
|
2018-11-22 14:47:23 +00:00
|
|
|
Gtk::EventBox event_box;
|
2022-04-06 06:37:19 +00:00
|
|
|
std::string category;
|
|
|
|
std::string id;
|
2018-10-04 16:47:06 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
std::string title;
|
|
|
|
std::string icon_name;
|
|
|
|
Glib::RefPtr<Gdk::Pixbuf> icon_pixmap;
|
2019-04-11 13:20:39 +00:00
|
|
|
Glib::RefPtr<Gtk::IconTheme> icon_theme;
|
2022-04-06 06:37:19 +00: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;
|
2019-06-14 13:44:11 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2018-10-04 16:47:06 +00:00
|
|
|
|
2019-04-17 12:19:04 +00:00
|
|
|
private:
|
2021-08-17 06:33:29 +00:00
|
|
|
void onConfigure(GdkEventConfigure* ev);
|
2019-03-28 02:56:19 +00:00
|
|
|
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
|
|
|
|
void setProperty(const Glib::ustring& name, Glib::VariantBase& value);
|
2021-07-03 02:44:10 +00:00
|
|
|
void setStatus(const Glib::ustring& value);
|
2019-03-30 01:40:28 +00:00
|
|
|
void getUpdatedProperties();
|
|
|
|
void processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& result);
|
|
|
|
void onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
2019-04-17 12:19:04 +00:00
|
|
|
const Glib::VariantContainerBase& arguments);
|
2018-10-04 16:47:06 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
void updateImage();
|
2019-04-17 12:19:04 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
|
2021-07-31 23:14:02 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> getIconPixbuf();
|
2019-04-24 10:37:24 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> getIconByName(const std::string& name, int size);
|
2022-04-06 06:37:19 +00: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-26 23:33:25 +00:00
|
|
|
|
|
|
|
// smooth scrolling threshold
|
|
|
|
gdouble scroll_threshold_ = 0;
|
|
|
|
gdouble distance_scrolled_x_ = 0;
|
|
|
|
gdouble distance_scrolled_y_ = 0;
|
2021-07-03 02:44:10 +00:00
|
|
|
// visibility of items with Status == Passive
|
|
|
|
bool show_passive_ = false;
|
2018-10-04 16:47:06 +00:00
|
|
|
|
2023-08-21 19:03:43 +00:00
|
|
|
const Bar& bar_;
|
|
|
|
|
2019-03-28 02:56:19 +00:00
|
|
|
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
2019-05-13 13:15:50 +00:00
|
|
|
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
2022-04-06 06:37:19 +00:00
|
|
|
std::set<std::string_view> update_pending_;
|
2018-08-29 18:36:39 +00:00
|
|
|
};
|
|
|
|
|
2019-04-17 12:19:04 +00:00
|
|
|
} // namespace waybar::modules::SNI
|