commit 4edb1e9bc8a9c8b4ab8ecffcf07b90cf6df1542e
parent 8f0823f5513a7c0cf3948d8e14daa35714edf63f
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date: Sat, 13 Apr 2024 07:24:03 +0300
Embed xml files to the binary
Diffstat:
6 files changed, 179 insertions(+), 74 deletions(-)
diff --git a/Resources/DBusMenu.xml b/Resources/DBusMenu.xml
@@ -1,47 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<node>
- <interface name="com.canonical.dbusmenu">
-
+ <interface name="com.canonical.dbusmenu">
<!-- methods -->
- <method name="GetLayout">
+ <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="Event">
+ </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="AboutToShow">
+ </method>
+ <method name="AboutToShow">
<arg type="i" name="id" direction="in"/>
<arg type="b" name="needUpdate" direction="out"/>
- </method>
+ </method>
<!--
- <method name="AboutToShowGroup">
+ <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>
- <method name="GetGroupProperties">
+ </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">
+ </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="EventGroup">
+ </method>
+ <method name="EventGroup">
<arg type="a(isvu)" name="events" direction="in"/>
<arg type="ai" name="idErrors" direction="out"/>
- </method>
+ </method>
-->
-
<!-- properties -->
<!--
<property name="Version" type="u" access="read"/>
@@ -49,22 +47,20 @@
<property name="Status" type="s" access="read"/>
<property name="IconThemePath" type="as" access="read"/>
-->
-
<!-- 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">
+ <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>
<!--
- <signal name="ItemActivationRequested">
+ <signal name="ItemActivationRequested">
<arg type="i" name="id" direction="out"/>
<arg type="u" name="timestamp" direction="out"/>
- </signal>
+ </signal>
-->
-
- </interface>
+ </interface>
</node>
diff --git a/Resources/StatusNotifierItem.xml b/Resources/StatusNotifierItem.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<node>
<interface name="org.kde.StatusNotifierItem">
-
<!-- methods -->
<method name="Activate">
<arg name="x" type="i" direction="in"/>
@@ -21,7 +20,6 @@
<arg name="y" type="i" direction="in"/>
</method>
-->
-
<!-- properties -->
<property name="Menu" type="o" access="read"/>
<property name="IconName" type="s" access="read"/>
@@ -41,7 +39,6 @@
<property name="AttentionMovieName" type="s" access="read"/>
<property name="ToolTip" type="(sa(iiay)ss)" access="read"/>
-->
-
<!-- signals -->
<signal name="NewIcon"/>
<!--
@@ -53,6 +50,5 @@
<arg name="status" type="s"/>
</signal>
-->
-
</interface>
</node>
diff --git a/Resources/StatusNotifierWatcher.xml b/Resources/StatusNotifierWatcher.xml
@@ -5,12 +5,10 @@
<method name="RegisterStatusNotifierItem">
<arg name="service" type="s" direction="in" />
</method>
-
<!-- properties -->
<property name="RegisteredStatusNotifierItems" type="as" access="read" />
<property name="IsStatusNotifierHostRegistered" type="b" access="read" />
<property name="ProtocolVersion" type="i" access="read" />
-
<!-- signals -->
<signal name="StatusNotifierItemRegistered">
<arg type="s"/>
diff --git a/dwlbtray.h b/dwlbtray.h
@@ -60,4 +60,155 @@ StatusNotifierHost* start_statusnotifierhost();
GDBusNodeInfo* get_interface_info(const char *xmlpath);
void dwlb_request_resize(StatusNotifierHost *snhost);
+
+#define DBUSMENU_XML \
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
+ "<node>\n" \
+ " <interface name=\"com.canonical.dbusmenu\">\n" \
+ " <!-- methods -->\n" \
+ " <method name=\"GetLayout\">\n" \
+ " <arg type=\"i\" name=\"parentId\" direction=\"in\"/>\n" \
+ " <arg type=\"i\" name=\"recursionDepth\" direction=\"in\"/>\n" \
+ " <arg type=\"as\" name=\"propertyNames\" direction=\"in\"/>\n" \
+ " <arg type=\"u\" name=\"revision\" direction=\"out\"/>\n" \
+ " <arg type=\"(ia{sv}av)\" name=\"layout\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"Event\">\n" \
+ " <arg type=\"i\" name=\"id\" direction=\"in\"/>\n" \
+ " <arg type=\"s\" name=\"eventId\" direction=\"in\"/>\n" \
+ " <arg type=\"v\" name=\"data\" direction=\"in\"/>\n" \
+ " <arg type=\"u\" name=\"timestamp\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"AboutToShow\">\n" \
+ " <arg type=\"i\" name=\"id\" direction=\"in\"/>\n" \
+ " <arg type=\"b\" name=\"needUpdate\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <!--\n" \
+ " <method name=\"AboutToShowGroup\">\n" \
+ " <arg type=\"ai\" name=\"ids\" direction=\"in\"/>\n" \
+ " <arg type=\"ai\" name=\"updatesNeeded\" direction=\"out\"/>\n" \
+ " <arg type=\"ai\" name=\"idErrors\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"GetGroupProperties\">\n" \
+ " <arg type=\"ai\" name=\"ids\" direction=\"in\"/>\n" \
+ " <arg type=\"as\" name=\"propertyNames\" direction=\"in\"/>\n" \
+ " <arg type=\"a(ia{sv})\" name=\"properties\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"GetProperty\">\n" \
+ " <arg type=\"i\" name=\"id\" direction=\"in\"/>\n" \
+ " <arg type=\"s\" name=\"name\" direction=\"in\"/>\n" \
+ " <arg type=\"v\" name=\"value\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"EventGroup\">\n" \
+ " <arg type=\"a(isvu)\" name=\"events\" direction=\"in\"/>\n" \
+ " <arg type=\"ai\" name=\"idErrors\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " -->\n" \
+ " <!-- properties -->\n" \
+ " <!--\n" \
+ " <property name=\"Version\" type=\"u\" access=\"read\"/>\n" \
+ " <property name=\"TextDirection\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"Status\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"IconThemePath\" type=\"as\" access=\"read\"/>\n" \
+ " -->\n" \
+ " <!-- Signals -->\n" \
+ " <signal name=\"ItemsPropertiesUpdated\">\n" \
+ " <arg type=\"a(ia{sv})\" name=\"updatedProps\" direction=\"out\"/>\n" \
+ " <arg type=\"a(ias)\" name=\"removedProps\" direction=\"out\"/>\n" \
+ " </signal>\n" \
+ " <signal name=\"LayoutUpdated\">\n" \
+ " <arg type=\"u\" name=\"revision\" direction=\"out\"/>\n" \
+ " <arg type=\"i\" name=\"parent\" direction=\"out\"/>\n" \
+ " </signal>\n" \
+ " <!--\n" \
+ " <signal name=\"ItemActivationRequested\">\n" \
+ " <arg type=\"i\" name=\"id\" direction=\"out\"/>\n" \
+ " <arg type=\"u\" name=\"timestamp\" direction=\"out\"/>\n" \
+ " </signal>\n" \
+ " -->\n" \
+ " </interface>\n" \
+ "</node>\n"
+
+
+#define STATUSNOTIFIERITEM_XML \
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
+ "<node>\n" \
+ " <interface name=\"org.kde.StatusNotifierItem\">\n" \
+ " <!-- methods -->\n" \
+ " <method name=\"Activate\">\n" \
+ " <arg name=\"x\" type=\"i\" direction=\"in\"/>\n" \
+ " <arg name=\"y\" type=\"i\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <!--\n" \
+ " <method name=\"Scroll\">\n" \
+ " <arg name=\"delta\" type=\"i\" direction=\"in\"/>\n" \
+ " <arg name=\"orientation\" type=\"s\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"ContextMenu\">\n" \
+ " <arg name=\"x\" type=\"i\" direction=\"in\"/>\n" \
+ " <arg name=\"y\" type=\"i\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " <method name=\"SecondaryActivate\">\n" \
+ " <arg name=\"x\" type=\"i\" direction=\"in\"/>\n" \
+ " <arg name=\"y\" type=\"i\" direction=\"in\"/>\n" \
+ " </method>\n" \
+ " -->\n" \
+ " <!-- properties -->\n" \
+ " <property name=\"Menu\" type=\"o\" access=\"read\"/>\n" \
+ " <property name=\"IconName\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"IconPixmap\" type=\"a(iiay)\" access=\"read\"/>\n" \
+ " <property name=\"IconThemePath\" type=\"s\" access=\"read\"/>\n" \
+ " <!--\n" \
+ " <property name=\"OverlayIconName\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"OverlayIconPixmap\" type=\"a(iiay)\" access=\"read\"/>\n" \
+ " <property name=\"AttentionIconName\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"AttentionIconPixmap\" type=\"a(iiay)\" access=\"read\"/>\n" \
+ " <property name=\"Category\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"Title\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"Status\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"WindowId\" type=\"i\" access=\"read\"/>\n" \
+ " <property name=\"ItemIsMenu\" type=\"b\" access=\"read\"/>\n" \
+ " <property name=\"AttentionMovieName\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"ToolTip\" type=\"(sa(iiay)ss)\" access=\"read\"/>\n" \
+ " -->\n" \
+ " <!-- signals -->\n" \
+ " <signal name=\"NewIcon\"/>\n" \
+ " <!--\n" \
+ " <signal name=\"NewAttentionIcon\"/>\n" \
+ " <signal name=\"NewOverlayIcon\"/>\n" \
+ " <signal name=\"NewTitle\"/>\n" \
+ " <signal name=\"NewToolTip\"/>\n" \
+ " <signal name=\"NewStatus\">\n" \
+ " <arg name=\"status\" type=\"s\"/>\n" \
+ " </signal>\n" \
+ " -->\n" \
+ " </interface>\n" \
+ "</node>\n"
+
+
+#define STATUSNOTIFIERWATCHER_XML \
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \
+ "<node>\n" \
+ " <interface name=\"org.kde.StatusNotifierWatcher\">\n" \
+ " <!-- methods -->\n" \
+ " <method name=\"RegisterStatusNotifierItem\">\n" \
+ " <arg name=\"service\" type=\"s\" direction=\"in\" />\n" \
+ " </method>\n" \
+ " <!-- properties -->\n" \
+ " <property name=\"RegisteredStatusNotifierItems\" type=\"as\" access=\"read\" />\n" \
+ " <property name=\"IsStatusNotifierHostRegistered\" type=\"b\" access=\"read\" />\n" \
+ " <property name=\"ProtocolVersion\" type=\"i\" access=\"read\" />\n" \
+ " <!-- signals -->\n" \
+ " <signal name=\"StatusNotifierItemRegistered\">\n" \
+ " <arg type=\"s\"/>\n" \
+ " </signal>\n" \
+ " <signal name=\"StatusNotifierItemUnregistered\">\n" \
+ " <arg type=\"s\"/>\n" \
+ " </signal>\n" \
+ " <signal name=\"StatusNotifierHostRegistered\">\n" \
+ " </signal>\n" \
+ " </interface>\n" \
+ "</node>\n"
+
#endif /* STATUSNOTIFIERHOST_H */
diff --git a/statusnotifierhost.c b/statusnotifierhost.c
@@ -66,53 +66,24 @@ dwlb_request_resize(StatusNotifierHost *snhost)
g_free(socketpath);
}
-GDBusNodeInfo*
-get_interface_info(const char *xmlpath)
-{
- char *contents;
- GError *err = NULL;
-
- g_file_get_contents(xmlpath, &contents, NULL, &err);
-
- if (err) {
- fprintf(stderr, "%s\n", err->message);
- g_error_free(err);
- return NULL;
- }
-
- GDBusNodeInfo *node = g_dbus_node_info_new_for_xml(contents, &err);
- g_free(contents);
-
- if (err) {
- fprintf(stderr, "%s\n", err->message);
- g_error_free(err);
- return NULL;
- }
-
- return node;
-}
-
-
static void
register_statusnotifieritem(const char *busname,
const char *busobj,
StatusNotifierHost *snhost)
{
- char *xml_path = g_strdup_printf("%s%s", RESOURCE_PATH, "/StatusNotifierItem.xml");
-
StatusNotifierItem *snitem;
snitem = g_malloc0(sizeof(StatusNotifierItem));
snitem->host = snhost;
snitem->busname = g_strdup(busname);
snitem->busobj = g_strdup(busobj);
- snitem->nodeinfo = get_interface_info(xml_path);
+ snitem->nodeinfo = g_dbus_node_info_new_for_xml(STATUSNOTIFIERITEM_XML, NULL);
snhost->noitems = snhost->noitems + 1;
snhost->trayitems = g_slist_prepend(snhost->trayitems, snitem);
- g_free(xml_path);
+ // g_free(xml_path);
dwlb_request_resize(snhost);
g_dbus_proxy_new(snhost->conn,
@@ -402,9 +373,7 @@ StatusNotifierHost*
start_statusnotifierhost()
{
StatusNotifierHost *snhost = g_malloc0(sizeof(StatusNotifierHost));
- char *xml_path = g_strdup_printf("%s%s", RESOURCE_PATH, "/StatusNotifierWatcher.xml");
- snhost->nodeinfo = get_interface_info(xml_path);
- g_free(xml_path);
+ snhost->nodeinfo = g_dbus_node_info_new_for_xml(STATUSNOTIFIERWATCHER_XML, NULL);
snhost->height = 22;
snhost->margin = 4;
diff --git a/statusnotifieritem.c b/statusnotifieritem.c
@@ -375,12 +375,7 @@ create_trayitem(GDBusConnection *conn, GAsyncResult *res, StatusNotifierItem *sn
}
snitem->actiongroup = g_simple_action_group_new();
- char *xml_path = g_strdup_printf("%s%s", RESOURCE_PATH, "/DBusMenu.xml");
- snitem->menunodeinfo = get_interface_info(xml_path);
- g_free(xml_path);
-
- // gtk_popover_menu_set_menu_model(GTK_POPOVER_MENU(snitem->popovermenu),
- // G_MENU_MODEL(snitem->menu));
+ snitem->menunodeinfo = g_dbus_node_info_new_for_xml(DBUSMENU_XML, NULL);
g_signal_connect(snitem->proxy, "g-signal", G_CALLBACK(trayitem_signal_handler), snitem);