add tray icons
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "glibmm/refptr.h"
|
||||
#include "gtkmm/application.h"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/tray.hpp"
|
||||
|
||||
class App {
|
||||
public:
|
||||
@@ -16,6 +17,7 @@ private:
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
std::vector<Bar*> bars;
|
||||
HyprlandService hyprlandService;
|
||||
TrayService trayService;
|
||||
|
||||
void setupServices();
|
||||
};
|
||||
@@ -4,13 +4,15 @@
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/tray.hpp"
|
||||
#include "widgets/clock.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
#include "widgets/tray.hpp"
|
||||
|
||||
class Bar : public Gtk::Window
|
||||
{
|
||||
public:
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, int monitorId);
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, int monitorId);
|
||||
|
||||
protected:
|
||||
Clock clock;
|
||||
@@ -21,8 +23,10 @@ class Bar : public Gtk::Window
|
||||
|
||||
private:
|
||||
HyprlandService &m_hyprlandService;
|
||||
TrayService &m_trayService;
|
||||
int m_monitorId;
|
||||
WorkspaceIndicator *m_workspaceIndicator = nullptr;
|
||||
TrayWidget *m_trayWidget = nullptr;
|
||||
|
||||
void setup_ui();
|
||||
void load_css();
|
||||
|
||||
127
include/services/tray.hpp
Normal file
127
include/services/tray.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include <gdkmm/memorytexture.h>
|
||||
#include <giomm/dbusconnection.h>
|
||||
#include <giomm/init.h>
|
||||
#include <glibmm/bytes.h>
|
||||
#include <glibmm/refptr.h>
|
||||
#include <sigc++/sigc++.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TrayService
|
||||
{
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
std::string id;
|
||||
std::string busName;
|
||||
std::string objectPath;
|
||||
std::string title;
|
||||
std::string status;
|
||||
std::string iconName;
|
||||
std::string menuPath;
|
||||
bool menuAvailable = false;
|
||||
Glib::RefPtr<Gdk::Paintable> iconPaintable;
|
||||
};
|
||||
|
||||
TrayService();
|
||||
~TrayService();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
std::vector<Item> snapshotItems() const;
|
||||
const Item *findItem(const std::string &id) const;
|
||||
|
||||
void activate(const std::string &id, int32_t x, int32_t y);
|
||||
void secondaryActivate(const std::string &id, int32_t x, int32_t y);
|
||||
void contextMenu(const std::string &id, int32_t x, int32_t y);
|
||||
|
||||
sigc::signal<void(const Item &)> &signal_item_added();
|
||||
sigc::signal<void(const std::string &)> &signal_item_removed();
|
||||
sigc::signal<void(const Item &)> &signal_item_updated();
|
||||
|
||||
private:
|
||||
struct TrackedItem
|
||||
{
|
||||
Item publicData;
|
||||
guint signalSubscriptionId = 0;
|
||||
guint ownerWatchId = 0;
|
||||
};
|
||||
|
||||
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
||||
Glib::RefPtr<Gio::DBus::NodeInfo> m_nodeInfo;
|
||||
Gio::DBus::InterfaceVTable m_vtable;
|
||||
|
||||
guint m_nameOwnerId = 0;
|
||||
guint m_registrationId = 0;
|
||||
bool m_hostRegistered = false;
|
||||
|
||||
std::map<std::string, std::unique_ptr<TrackedItem>> m_items;
|
||||
|
||||
sigc::signal<void(const Item &)> m_itemAddedSignal;
|
||||
sigc::signal<void(const std::string &)> m_itemRemovedSignal;
|
||||
sigc::signal<void(const Item &)> m_itemUpdatedSignal;
|
||||
|
||||
void on_bus_acquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name);
|
||||
void on_name_acquired(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name);
|
||||
void on_name_lost(const Glib::RefPtr<Gio::DBus::Connection> &connection, const Glib::ustring &name);
|
||||
|
||||
void handle_method_call(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||
const Glib::ustring &sender,
|
||||
const Glib::ustring &object_path,
|
||||
const Glib::ustring &interface_name,
|
||||
const Glib::ustring &method_name,
|
||||
const Glib::VariantContainerBase ¶meters,
|
||||
const Glib::RefPtr<Gio::DBus::MethodInvocation> &invocation);
|
||||
|
||||
void handle_get_property_slot(Glib::VariantBase &result,
|
||||
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||
const Glib::ustring &sender,
|
||||
const Glib::ustring &object_path,
|
||||
const Glib::ustring &interface_name,
|
||||
const Glib::ustring &property_name);
|
||||
bool handle_set_property_slot(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||
const Glib::ustring &sender,
|
||||
const Glib::ustring &object_path,
|
||||
const Glib::ustring &interface_name,
|
||||
const Glib::ustring &property_name,
|
||||
const Glib::VariantBase &value);
|
||||
|
||||
Glib::VariantBase handle_get_property(const Glib::ustring &property_name);
|
||||
bool handle_set_property(const Glib::ustring &property_name, const Glib::VariantBase &value);
|
||||
|
||||
void register_item(const Glib::ustring &sender, const std::string &service);
|
||||
void unregister_item(const std::string &id);
|
||||
|
||||
void refresh_item(TrackedItem &item);
|
||||
void emit_registered_items_changed();
|
||||
|
||||
Glib::Variant<std::vector<Glib::ustring>> create_registered_items_variant() const;
|
||||
|
||||
void emit_watcher_signal(const Glib::ustring &signal_name, const Glib::VariantContainerBase ¶meters);
|
||||
|
||||
static void on_dbus_signal_static(GDBusConnection *connection,
|
||||
const gchar *sender_name,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *signal_name,
|
||||
GVariant *parameters,
|
||||
gpointer user_data);
|
||||
void on_dbus_signal(const gchar *sender_name,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *signal_name,
|
||||
GVariant *parameters);
|
||||
static void on_name_vanished_static(GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data);
|
||||
void on_name_vanished(const gchar *bus_name);
|
||||
|
||||
static Glib::RefPtr<Gdk::Paintable> parse_icon_pixmap(GVariant *variant);
|
||||
};
|
||||
53
include/widgets/tray.hpp
Normal file
53
include/widgets/tray.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/gestureclick.h>
|
||||
#include <gtkmm/picture.h>
|
||||
#include <gtkmm/image.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;
|
||||
|
||||
void on_primary_clicked();
|
||||
void on_secondary_released(int n_press, double x, double y);
|
||||
};
|
||||
|
||||
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();
|
||||
};
|
||||
Reference in New Issue
Block a user