Skip to content

Commit

Permalink
feat(Tray): handle click
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Sep 17, 2018
1 parent 3e2e1a7 commit 2ba8d42
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/modules/sni/sni.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 33 additions & 1 deletion src/modules/sni/sni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -70,7 +73,7 @@ void waybar::modules::SNI::Item::getAll(GObject* obj, GAsyncResult* res,
} else if (g_strcmp0(key, "Status") == 0) {
item->status = g_variant_dup_string(value, nullptr);
} else if (g_strcmp0(key, "WindowId") == 0) {
item->window_id = g_variant_get_int32 (value);
item->window_id = g_variant_get_int32(value);
} else if (g_strcmp0(key, "IconName") == 0) {
item->icon_name = g_variant_dup_string(value, nullptr);
} else if (g_strcmp0(key, "IconPixmap") == 0) {
Expand Down Expand Up @@ -209,4 +212,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);
return false;
}
return true;
}

0 comments on commit 2ba8d42

Please sign in to comment.