feat(Tray): handle click

This commit is contained in:
Alexis 2018-09-17 23:32:05 +02:00
parent 3e2e1a7018
commit fcdb8387af
No known key found for this signature in database
GPG Key ID: 20B1EC2EBBA96BD9
2 changed files with 38 additions and 1 deletions

View File

@ -33,10 +33,14 @@ class Item {
private:
static void proxyReady(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();
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
bool handleClick(GdkEventButton* const& /*ev*/);
Glib::Dispatcher* dp_;
GCancellable* cancellable_ = 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)
{
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();
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(),
@ -210,3 +213,33 @@ Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(
return icon_theme->load_icon(name.c_str(), icon_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;
}