feat(Tray): handle click

This commit is contained in:
Alexis 2018-09-17 23:32:05 +02:00
parent 56e55fa4aa
commit 091b460d03
2 changed files with 38 additions and 1 deletions

View File

@ -33,10 +33,14 @@ class Item {
private: private:
static void proxyReady(GObject* obj, GAsyncResult* res, gpointer data); static void proxyReady(GObject* obj, GAsyncResult* res, gpointer data);
static void getAll(GObject* obj, GAsyncResult* res, gpointer data); static void getAll(GObject* obj, GAsyncResult* res, gpointer data);
static void handleActivate(GObject*, GAsyncResult*, gpointer);
static void handleSecondaryActivate(GObject*, GAsyncResult*, gpointer);
void updateImage(); void updateImage();
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant); Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size); Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
bool handleClick(GdkEventButton* const& /*ev*/);
Glib::Dispatcher* dp_; Glib::Dispatcher* dp_;
GCancellable* cancellable_ = nullptr; GCancellable* cancellable_ = nullptr;
SnOrgKdeStatusNotifierItem* proxy_ = nullptr; SnOrgKdeStatusNotifierItem* proxy_ = nullptr;

View File

@ -9,6 +9,9 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op,
image(Gtk::manage(new Gtk::Image())), dp_(dp) image(Gtk::manage(new Gtk::Image())), dp_(dp)
{ {
event_box.add(*image); event_box.add(*image);
event_box.add_events(Gdk::BUTTON_PRESS_MASK);
event_box.signal_button_press_event()
.connect(sigc::mem_fun(*this, &Item::handleClick));
cancellable_ = g_cancellable_new(); cancellable_ = g_cancellable_new();
sn_org_kde_status_notifier_item_proxy_new_for_bus(G_BUS_TYPE_SESSION, sn_org_kde_status_notifier_item_proxy_new_for_bus(G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE, bus_name.c_str(), object_path.c_str(), G_DBUS_PROXY_FLAGS_NONE, bus_name.c_str(), object_path.c_str(),
@ -210,3 +213,33 @@ Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(
return icon_theme->load_icon(name.c_str(), icon_size, return icon_theme->load_icon(name.c_str(), icon_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE); Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
} }
void waybar::modules::SNI::Item::handleActivate(GObject* src, GAsyncResult* res,
gpointer data)
{
auto item = static_cast<SNI::Item *>(data);
sn_org_kde_status_notifier_item_call_activate_finish(item->proxy_, res,
nullptr);
}
void waybar::modules::SNI::Item::handleSecondaryActivate(GObject* src,
GAsyncResult* res, gpointer data)
{
auto item = static_cast<SNI::Item *>(data);
sn_org_kde_status_notifier_item_call_secondary_activate_finish(item->proxy_,
res, nullptr);
}
bool waybar::modules::SNI::Item::handleClick(GdkEventButton* const& ev)
{
if (ev->type == GDK_BUTTON_PRESS) {
sn_org_kde_status_notifier_item_call_activate(proxy_, ev->x, ev->y, nullptr,
&Item::handleActivate, this);
} else if (ev->type == GDK_2BUTTON_PRESS) {
sn_org_kde_status_notifier_item_call_secondary_activate(proxy_, ev->x,
ev->y, nullptr, &Item::handleSecondaryActivate, this);
} else {
return false;
}
return true;
}