Skip to content

Commit

Permalink
Merge pull request #39 from Alexays/tray-gdbus
Browse files Browse the repository at this point in the history
Tray beta
  • Loading branch information
Alexays authored Oct 25, 2018
2 parents 4584784 + 0e6147b commit 0dedcc0
Show file tree
Hide file tree
Showing 24 changed files with 1,024 additions and 26 deletions.
18 changes: 7 additions & 11 deletions include/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

#include <unistd.h>
#include <wordexp.h>

#include <fmt/format.h>

#include <gdk/gdk.h>
#include <wayland-client.h>

#include <gdk/gdkwayland.h>

#include "bar.hpp"

namespace waybar {
Expand All @@ -30,14 +26,14 @@ class Client {
struct wl_seat *seat = nullptr;
std::vector<std::unique_ptr<Bar>> bars;

private:
void bindInterfaces();
auto setupCss();
private:
void bindInterfaces();
auto setupCss();

static void handleGlobal(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version);
static void handleGlobalRemove(void *data,
struct wl_registry *registry, uint32_t name);
static void handleGlobal(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version);
static void handleGlobalRemove(void *data,
struct wl_registry *registry, uint32_t name);
};

}
1 change: 1 addition & 0 deletions include/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "modules/battery.hpp"
#include "modules/memory.hpp"
#include "modules/cpu.hpp"
#include "modules/sni/tray.hpp"
#ifdef HAVE_LIBNL
#include "modules/network.hpp"
#endif
Expand Down
39 changes: 39 additions & 0 deletions include/modules/sni/snh.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <gtkmm.h>

#include <tuple>
#include <dbus-status-notifier-watcher.h>
#include "modules/sni/sni.hpp"

namespace waybar::modules::SNI {

class Host {
public:
Host(Glib::Dispatcher*);
std::vector<Item> items;
private:
static void busAcquired(GDBusConnection*, const gchar*, gpointer);
static void nameAppeared(GDBusConnection*, const gchar*, const gchar*,
gpointer);
static void nameVanished(GDBusConnection*, const gchar*, gpointer);
static void proxyReady(GObject*, GAsyncResult*, gpointer);
static void registerHost(GObject*, GAsyncResult*, gpointer);
static void itemRegistered(SnOrgKdeStatusNotifierWatcher*, const gchar*,
gpointer);
static void itemUnregistered(SnOrgKdeStatusNotifierWatcher*, const gchar*,
gpointer);

std::tuple<std::string, std::string> getBusNameAndObjectPath(const gchar*);
void addRegisteredItem(const gchar* service);

uint32_t bus_name_id_;
uint32_t watcher_id_;
std::string bus_name_;
std::string object_path_;
Glib::Dispatcher* dp_;
GCancellable* cancellable_ = nullptr;
SnOrgKdeStatusNotifierWatcher* watcher_ = nullptr;
};

}
51 changes: 51 additions & 0 deletions include/modules/sni/sni.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <dbus-status-notifier-item.h>
#include <gtkmm.h>

namespace waybar::modules::SNI {

class Item {
public:
Item(std::string, std::string, Glib::Dispatcher *);

std::string bus_name;
std::string object_path;
Gtk::EventBox event_box;

int icon_size;
int effective_icon_size;
Gtk::Image *image;
Gtk::Menu *gtk_menu = nullptr;
std::string category;
std::string id;
std::string status;

std::string title;
int32_t window_id;
std::string icon_name;
Glib::RefPtr<Gdk::Pixbuf> icon_pixmap;
std::string overlay_icon_name;
std::string attention_icon_name;
std::string attention_movie_name;
std::string icon_theme_path;
std::string menu;
bool item_is_menu;

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;
};

} // namespace waybar::modules::SNI
47 changes: 47 additions & 0 deletions include/modules/sni/snw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <gtkmm.h>
#include <dbus-status-notifier-watcher.h>

namespace waybar::modules::SNI {

class Watcher {
public:
Watcher();
~Watcher();

private:
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;

typedef struct {
GfWatchType type;
Watcher *watcher;
gchar *service;
gchar *bus_name;
gchar *object_path;
guint watch_id;
} GfWatch;

static void busAcquired(GDBusConnection *, const gchar *, gpointer);
static gboolean handleRegisterHost(Watcher *, GDBusMethodInvocation *,
const gchar *);
static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *,
const gchar *);
static GfWatch *gfWatchFind(GSList *list, const gchar *bus_name,
const gchar *object_path);
static GfWatch *gfWatchNew(GfWatchType, const gchar *, const gchar *,
const gchar *, Watcher *);
static void nameVanished(GDBusConnection *connection, const char *name,
gpointer data);

void updateRegisteredItems(SnOrgKdeStatusNotifierWatcher *obj);

uint32_t bus_name_id_;
uint32_t watcher_id_;
GSList *hosts_ = nullptr;
GSList *items_ = nullptr;
SnOrgKdeStatusNotifierWatcher *watcher_ = nullptr;
};

} // namespace waybar::modules::SNI

25 changes: 25 additions & 0 deletions include/modules/sni/tray.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <fmt/format.h>
#include <thread>
#include "util/json.hpp"
#include "IModule.hpp"
#include "modules/sni/snw.hpp"
#include "modules/sni/snh.hpp"

namespace waybar::modules::SNI {

class Tray : public IModule {
public:
Tray(const Json::Value&);
auto update() -> void;
operator Gtk::Widget &();
private:
std::thread thread_;
const Json::Value& config_;
Gtk::Box box_;
SNI::Watcher watcher_ ;
SNI::Host host_;
};

}
8 changes: 7 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ wayland_cursor = dependency('wayland-cursor')
wayland_protos = dependency('wayland-protocols')
wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots'])
gtkmm = dependency('gtkmm-3.0')
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4')
jsoncpp = dependency('jsoncpp')
sigcpp = dependency('sigc++-2.0')
libnl = dependency('libnl-3.0', required: get_option('libnl'))
Expand All @@ -46,6 +47,10 @@ src_files = files(
'src/modules/clock.cpp',
'src/modules/custom.cpp',
'src/modules/cpu.cpp',
'src/modules/sni/tray.cpp',
'src/modules/sni/snw.cpp',
'src/modules/sni/snh.cpp',
'src/modules/sni/sni.cpp',
'src/main.cpp',
'src/bar.cpp',
'src/client.cpp'
Expand Down Expand Up @@ -86,9 +91,10 @@ executable(
libinput,
wayland_cursor,
gtkmm,
dbusmenu_gtk,
libnl,
libnlgen,
libpulse,
libpulse
],
include_directories: [include_directories('include')],
install: true,
Expand Down
69 changes: 69 additions & 0 deletions protocol/dbus-menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.canonical.dbusmenu">
<!-- Properties -->
<property name="Version" type="u" access="read" />
<property name="TextDirection" type="s" access="read" />
<property name="Status" type="s" access="read" />
<property name="IconThemePath" type="as" access="read" />

<!-- Functions -->
<method name="GetLayout">
<arg type="i" name="parentId" direction="in" />
<arg type="i" name="recursionDepth" direction="in" />
<arg type="as" name="propertyNames" direction="in" />
<arg type="u" name="revision" direction="out" />
<arg type="(ia{sv}av)" name="layout" direction="out" />
</method>

<method name="GetGroupProperties">
<arg type="ai" name="ids" direction="in" />
<arg type="as" name="propertyNames" direction="in" />
<arg type="a(ia{sv})" name="properties" direction="out" />
</method>

<method name="GetProperty">
<arg type="i" name="id" direction="in" />
<arg type="s" name="name" direction="in" />
<arg type="v" name="value" direction="out" />
</method>

<method name="Event">
<arg type="i" name="id" direction="in" />
<arg type="s" name="eventId" direction="in" />
<arg type="v" name="data" direction="in" />
<arg type="u" name="timestamp" direction="in" />
</method>

<method name="EventGroup">
<arg type="a(isvu)" name="events" direction="in" />
<arg type="ai" name="idErrors" direction="out" />
</method>

<method name="AboutToShow">
<arg type="i" name="id" direction="in" />
<arg type="b" name="needUpdate" direction="out" />
</method>

<method name="AboutToShowGroup">
<arg type="ai" name="ids" direction="in" />
<arg type="ai" name="updatesNeeded" direction="out" />
<arg type="ai" name="idErrors" direction="out" />
</method>

<!-- Signals -->
<signal name="ItemsPropertiesUpdated">
<arg type="a(ia{sv})" name="updatedProps" direction="out" />
<arg type="a(ias)" name="removedProps" direction="out" />
</signal>
<signal name="LayoutUpdated">
<arg type="u" name="revision" direction="out" />
<arg type="i" name="parent" direction="out" />
</signal>
<signal name="ItemActivationRequested">
<arg type="i" name="id" direction="out" />
<arg type="u" name="timestamp" direction="out" />
</signal>
</interface>
</node>
77 changes: 77 additions & 0 deletions protocol/dbus-status-notifier-item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.StatusNotifierItem">
<property name="Category" type="s" access="read"/>
<property name="Id" type="s" access="read"/>
<property name="Title" type="s" access="read"/>
<property name="Status" type="s" access="read"/>
<property name="WindowId" type="i" access="read"/>
<property name="Menu" type="o" access="read" />

<!-- main icon -->
<!-- names are preferred over pixmaps -->
<property name="IconName" type="s" access="read" />
<property name="IconThemePath" type="s" access="read" />

<!-- struct containing width, height and image data-->
<!-- implementation has been dropped as of now -->
<property name="IconPixmap" type="a(iiay)" access="read" />

<!-- not used in ayatana code, no test case so far -->
<property name="OverlayIconName" type="s" access="read"/>
<property name="OverlayIconPixmap" type="a(iiay)" access="read" />

<!-- Requesting attention icon -->
<property name="AttentionIconName" type="s" access="read"/>

<!--same definition as image-->
<property name="AttentionIconPixmap" type="a(iiay)" access="read" />

<!-- tooltip data -->
<!-- unimplemented as of now -->
<!--(iiay) is an image-->
<property name="ToolTip" type="(sa(iiay)ss)" access="read" />


<!-- interaction: actually, we do not use them. -->
<method name="Activate">
<arg name="x" type="i" direction="in"/>
<arg name="y" type="i" direction="in"/>
</method>
<method name="SecondaryActivate">
<arg name="x" type="i" direction="in"/>
<arg name="y" type="i" direction="in"/>
</method>
<method name="Scroll">
<arg name="delta" type="i" direction="in"/>
<arg name="dir" type="s" direction="in"/>
</method>

<!-- Signals: the client wants to change something in the status-->
<signal name="NewTitle"></signal>
<signal name="NewIcon"></signal>
<signal name="NewIconThemePath">
<arg type="s" name="icon_theme_path" direction="out" />
</signal>
<signal name="NewAttentionIcon"></signal>
<signal name="NewOverlayIcon"></signal>
<signal name="NewToolTip"></signal>
<signal name="NewStatus">
<arg name="status" type="s" />
</signal>

<!-- ayatana labels -->
<!-- These are commented out because GDBusProxy would otherwise require them,
but they are not available for KDE indicators
-->
<!--<signal name="XAyatanaNewLabel">
<arg type="s" name="label" direction="out" />
<arg type="s" name="guide" direction="out" />
</signal>
<property name="XAyatanaLabel" type="s" access="read" />
<property name="XAyatanaLabelGuide" type="s" access="read" />-->


</interface>
</node>
Loading

0 comments on commit 0dedcc0

Please sign in to comment.