Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tray: allow css styling #245

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/panel/widgets/tray/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static Glib::RefPtr<Gdk::Pixbuf> 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;
Expand All @@ -70,26 +70,47 @@ 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
{
const auto ev_coords = Glib::Variant<std::tuple<int, int>>::create({0, 0});
if (get_item_property<bool>("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<std::tuple<int, int>>::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;
if (get_item_property<bool>("ItemIsMenu", true) || (ev->button == menu_btn))
{
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);
Expand Down
4 changes: 2 additions & 2 deletions src/panel/widgets/tray/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define TRAY_ITEM_HPP

#include <giomm.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/button.h>
#include <gtkmm/hvbox.h>
#include <gtkmm/icontheme.h>
#include <gtkmm/image.h>
Expand All @@ -12,7 +12,7 @@

#include <optional>

class StatusNotifierItem : public Gtk::EventBox
class StatusNotifierItem : public Gtk::Button
{
WfOption<int> smooth_scolling_threshold{"panel/tray_smooth_scrolling_threshold"};
WfOption<int> icon_size{"panel/tray_icon_size"};
Expand Down
Loading