74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <gtkmm/box.h>
|
|
#include <gtkmm/button.h>
|
|
#include <gtkmm/gestureclick.h>
|
|
#include <gtkmm/picture.h>
|
|
#include <gtkmm/image.h>
|
|
#include <gtkmm/popovermenu.h>
|
|
#include <giomm/menumodel.h>
|
|
#include <giomm/menu.h>
|
|
#include <giomm/menuitem.h>
|
|
#include <giomm/simpleaction.h>
|
|
#include <giomm/simpleactiongroup.h>
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "services/tray.hpp"
|
|
|
|
class TrayIconWidget : public Gtk::Button
|
|
{
|
|
public:
|
|
TrayIconWidget(TrayService &service, std::string id);
|
|
|
|
void update(const TrayService::Item &item);
|
|
|
|
private:
|
|
TrayService &m_service;
|
|
std::string m_id;
|
|
Gtk::Box m_container;
|
|
Gtk::Picture m_picture;
|
|
Gtk::Image m_image;
|
|
Glib::RefPtr<Gtk::GestureClick> m_secondaryGesture;
|
|
Glib::RefPtr<Gtk::PopoverMenu> m_menuPopover;
|
|
Glib::RefPtr<Gio::SimpleActionGroup> m_menuActions;
|
|
Glib::RefPtr<Gio::MenuModel> m_menuModel;
|
|
sigc::connection m_menuChangedConnection;
|
|
bool m_menuPopupPending = false;
|
|
double m_pendingX = 0.0;
|
|
double m_pendingY = 0.0;
|
|
|
|
void on_primary_clicked();
|
|
void on_secondary_released(int n_press, double x, double y);
|
|
bool ensure_menu();
|
|
void on_menu_items_changed(guint position, guint removed, guint added);
|
|
void try_popup();
|
|
void populate_menu_items(const std::vector<TrayService::MenuNode> &nodes,
|
|
const Glib::RefPtr<Gio::Menu> &menu,
|
|
const Glib::RefPtr<Gio::SimpleActionGroup> &actions);
|
|
void on_menu_action(const Glib::VariantBase ¶meter, int itemId);
|
|
};
|
|
|
|
class TrayWidget : public Gtk::Box
|
|
{
|
|
public:
|
|
explicit TrayWidget(TrayService &service);
|
|
~TrayWidget() override;
|
|
|
|
private:
|
|
TrayService &m_service;
|
|
std::map<std::string, std::unique_ptr<TrayIconWidget>> m_icons;
|
|
|
|
sigc::connection m_addConnection;
|
|
sigc::connection m_removeConnection;
|
|
sigc::connection m_updateConnection;
|
|
|
|
void on_item_added(const TrayService::Item &item);
|
|
void on_item_removed(const std::string &id);
|
|
void on_item_updated(const TrayService::Item &item);
|
|
|
|
void rebuild_existing();
|
|
};
|