From a02f680242464098e3ed4fa896b8de17f30c5f8c Mon Sep 17 00:00:00 2001 From: trigg Date: Sun, 21 Apr 2024 17:50:54 +0100 Subject: [PATCH 1/3] tray: add icons to button tray: fix click logic for button tray: attach popup menu to button --- src/panel/widgets/tray/item.cpp | 30 +++++++++++++++++++++++++----- src/panel/widgets/tray/item.hpp | 4 ++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/panel/widgets/tray/item.cpp b/src/panel/widgets/tray/item.cpp index ae9b1e46..94c92ea2 100644 --- a/src/panel/widgets/tray/item.cpp +++ b/src/panel/widgets/tray/item.cpp @@ -47,7 +47,7 @@ static Glib::RefPtr extract_pixbuf(IconData && pixbuf_data) StatusNotifierItem::StatusNotifierItem(const Glib::ustring & service) { - add(icon); + set_image(icon); const auto & [name, path] = name_and_obj_path(service); dbus_name = name; @@ -73,8 +73,31 @@ void StatusNotifierItem::init_widget() style->add_class("tray-box"); style->add_class("flat"); + signal_clicked().connect([this] () -> void + { + const auto ev_coords = Glib::Variant>::create({0, 0}); + if (get_item_property("ItemIsMenu", true)) + { + if (menu) + { + /* Under all tests I tried this places sensibly */ + menu->popup_at_widget(&icon, Gdk::GRAVITY_NORTH_EAST, Gdk::GRAVITY_SOUTH_EAST, NULL); + } else + { + item_proxy->call("ContextMenu", ev_coords); + } + } else + { + item_proxy->call("Activate", ev_coords); + } + }); + signal_button_press_event().connect([this] (GdkEventButton *ev) -> bool { + if (ev->button == GDK_BUTTON_PRIMARY) + { + return true; + } const auto ev_coords = Glib::Variant>::create({ev->x, ev->y}); const guint menu_btn = menu_on_middle_click ? GDK_BUTTON_MIDDLE : GDK_BUTTON_SECONDARY; const guint secondary_activate_btn = menu_on_middle_click ? GDK_BUTTON_SECONDARY : GDK_BUTTON_MIDDLE; @@ -82,14 +105,11 @@ void StatusNotifierItem::init_widget() { if (menu) { - menu->popup_at_pointer((GdkEvent*)ev); + menu->popup_at_widget(&icon, Gdk::GRAVITY_NORTH_EAST, Gdk::GRAVITY_SOUTH_EAST, NULL); } else { item_proxy->call("ContextMenu", ev_coords); } - } else if (ev->button == GDK_BUTTON_PRIMARY) - { - item_proxy->call("Activate", ev_coords); } else if (ev->button == secondary_activate_btn) { item_proxy->call("SecondaryActivate", ev_coords); diff --git a/src/panel/widgets/tray/item.hpp b/src/panel/widgets/tray/item.hpp index e0a06136..05da26df 100644 --- a/src/panel/widgets/tray/item.hpp +++ b/src/panel/widgets/tray/item.hpp @@ -2,7 +2,7 @@ #define TRAY_ITEM_HPP #include -#include +#include #include #include #include @@ -12,7 +12,7 @@ #include -class StatusNotifierItem : public Gtk::EventBox +class StatusNotifierItem : public Gtk::Button { WfOption smooth_scolling_threshold{"panel/tray_smooth_scrolling_threshold"}; WfOption icon_size{"panel/tray_icon_size"}; From 7320d4046a2bb95c5a9649929d5b1a51c112a33a Mon Sep 17 00:00:00 2001 From: trigg Date: Sun, 21 Apr 2024 17:54:00 +0100 Subject: [PATCH 2/3] uncrustify --- src/panel/widgets/tray/item.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/panel/widgets/tray/item.cpp b/src/panel/widgets/tray/item.cpp index 94c92ea2..e75dd3e4 100644 --- a/src/panel/widgets/tray/item.cpp +++ b/src/panel/widgets/tray/item.cpp @@ -98,6 +98,7 @@ void StatusNotifierItem::init_widget() { return true; } + const auto ev_coords = Glib::Variant>::create({ev->x, ev->y}); const guint menu_btn = menu_on_middle_click ? GDK_BUTTON_MIDDLE : GDK_BUTTON_SECONDARY; const guint secondary_activate_btn = menu_on_middle_click ? GDK_BUTTON_SECONDARY : GDK_BUTTON_MIDDLE; From 4daeb433f41a7b030996282318c5c3375bc1bb2e Mon Sep 17 00:00:00 2001 From: trigg Date: Mon, 22 Apr 2024 09:30:36 +0100 Subject: [PATCH 3/3] tray: update cssname to match --- src/panel/widgets/tray/item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panel/widgets/tray/item.cpp b/src/panel/widgets/tray/item.cpp index e75dd3e4..98c5a1d3 100644 --- a/src/panel/widgets/tray/item.cpp +++ b/src/panel/widgets/tray/item.cpp @@ -70,7 +70,7 @@ void StatusNotifierItem::init_widget() setup_tooltip(); init_menu(); auto style = get_style_context(); - style->add_class("tray-box"); + style->add_class("tray-button"); style->add_class("flat"); signal_clicked().connect([this] () -> void