dwlb

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d8b05022d45fe1fa73bd585bb2803d53ff01a705
parent 4edb1e9bc8a9c8b4ab8ecffcf07b90cf6df1542e
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date:   Sat, 13 Apr 2024 08:23:11 +0300

Get bg color from arg, get rid of resource files

Diffstat:
MMakefile | 2--
DResources/DBusMenu.xml | 66------------------------------------------------------------------
DResources/StatusNotifierItem.xml | 54------------------------------------------------------
DResources/StatusNotifierWatcher.xml | 22----------------------
DResources/boxbg.css | 3---
Mdwlb.c | 28++++++++++++++++++++--------
Mdwlbtray.c | 16++++++++++------
Mdwlbtray.h | 1+
8 files changed, 31 insertions(+), 161 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,5 @@ BINS = dwlb dwlbtray MANS = dwlb.1 -RESOURCES = Resources/DBusMenu.xml Resources/StatusNotifierItem.xml Resources/StatusNotifierWatcher.xml Resources/boxbg.css PREFIX ?= /usr/local CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-format-truncation -g \ @@ -17,7 +16,6 @@ clean: install: all install -D -t $(PREFIX)/bin $(BINS) install -D -m0644 -t $(PREFIX)/share/man/man1 $(MANS) - install -D -m0644 -t $(PREFIX)/share/dwlb $(RESOURCES) WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols) WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner) diff --git a/Resources/DBusMenu.xml b/Resources/DBusMenu.xml @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<node> - <interface name="com.canonical.dbusmenu"> - <!-- methods --> - <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"> - <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"> - <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> - <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="EventGroup"> - <arg type="a(isvu)" name="events" direction="in"/> - <arg type="ai" name="idErrors" direction="out"/> - </method> - --> - <!-- 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"/> - --> - <!-- 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> diff --git a/Resources/StatusNotifierItem.xml b/Resources/StatusNotifierItem.xml @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<node> - <interface name="org.kde.StatusNotifierItem"> - <!-- methods --> - <method name="Activate"> - <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="orientation" type="s" direction="in"/> - </method> - <method name="ContextMenu"> - <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> - --> - <!-- properties --> - <property name="Menu" type="o" access="read"/> - <property name="IconName" type="s" access="read"/> - <property name="IconPixmap" type="a(iiay)" access="read"/> - <property name="IconThemePath" type="s" access="read"/> - <!-- - <property name="OverlayIconName" type="s" access="read"/> - <property name="OverlayIconPixmap" type="a(iiay)" access="read"/> - <property name="AttentionIconName" type="s" access="read"/> - <property name="AttentionIconPixmap" type="a(iiay)" access="read"/> - <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="ItemIsMenu" type="b" access="read"/> - <property name="AttentionMovieName" type="s" access="read"/> - <property name="ToolTip" type="(sa(iiay)ss)" access="read"/> - --> - <!-- signals --> - <signal name="NewIcon"/> - <!-- - <signal name="NewAttentionIcon"/> - <signal name="NewOverlayIcon"/> - <signal name="NewTitle"/> - <signal name="NewToolTip"/> - <signal name="NewStatus"> - <arg name="status" type="s"/> - </signal> - --> - </interface> -</node> diff --git a/Resources/StatusNotifierWatcher.xml b/Resources/StatusNotifierWatcher.xml @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<node> - <interface name="org.kde.StatusNotifierWatcher"> - <!-- methods --> - <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"/> - </signal> - <signal name="StatusNotifierItemUnregistered"> - <arg type="s"/> - </signal> - <signal name="StatusNotifierHostRegistered"> - </signal> - </interface> -</node> diff --git a/Resources/boxbg.css b/Resources/boxbg.css @@ -1,3 +0,0 @@ -window { - background-color: #222222; -} diff --git a/dwlb.c b/dwlb.c @@ -1962,7 +1962,12 @@ main(int argc, char **argv) signal(SIGCHLD, SIG_IGN); /* Start tray program */ + char tray_exe_path[PATH_MAX]; char progname[PATH_MAX]; + char traybg_arg[64]; + char height_arg[64]; + char traymon_arg[64]; + ssize_t len = readlink("/proc/self/exe", progname, sizeof(progname)); if (len != -1) @@ -1970,22 +1975,29 @@ main(int argc, char **argv) else exit(-1); - char tray_exe_path[PATH_MAX]; + pixman_color_t *traybg_clr = &inactive_bg_color; + snprintf(traybg_arg, + sizeof(traybg_arg), + "--bg-color=#%x%x%x", + (int8_t)traybg_clr->red, + (int8_t)traybg_clr->green, + (int8_t)traybg_clr->blue); + if (strncmp(progname, BUILD_DIR, strlen(BUILD_DIR)) == 0) { strcpy(tray_exe_path, BUILD_DIR); strcat(tray_exe_path, "dwlbtray"); } else { strcpy(tray_exe_path, "dwlbtray"); } + + snprintf(height_arg, sizeof(height_arg), "--height=%u", height); + snprintf(traymon_arg, sizeof(traymon_arg), "--traymon=%s", traymon); + char *args[] = { tray_exe_path, height_arg, traybg_arg, traymon_arg, NULL }; + if (!traymon) + args[3] = NULL; + int child_pid = fork(); if (child_pid == 0) { - char height_param[64]; - char traymon_param[64]; - snprintf(height_param, sizeof(height_param), "--height=%u", height); - snprintf(traymon_param, sizeof(traymon_param), "--traymon=%s", traymon); - char *args[] = { tray_exe_path, height_param, traymon_param, NULL}; - if (!traymon) - args[2] = NULL; execvp(args[0], args); } diff --git a/dwlbtray.c b/dwlbtray.c @@ -16,6 +16,8 @@ const char *RESOURCE_PATH; static void activate(GtkApplication* app, StatusNotifierHost *snhost) { + GdkDisplay *display = gdk_display_get_default(); + GtkWindow *window = GTK_WINDOW(gtk_application_window_new(app)); snhost->window = window; @@ -28,7 +30,7 @@ activate(GtkApplication* app, StatusNotifierHost *snhost) } if (snhost->traymon) { - GListModel *mons = gdk_display_get_monitors(gdk_display_get_default()); + GListModel *mons = gdk_display_get_monitors(display); for (uint i = 0; i < g_list_model_get_n_items(mons); i++) { GdkMonitor *mon = g_list_model_get_item(mons, i); const char *conn = gdk_monitor_get_connector(mon); @@ -39,12 +41,10 @@ activate(GtkApplication* app, StatusNotifierHost *snhost) } GtkCssProvider *css = gtk_css_provider_new(); - char *css_path = g_strdup_printf("%s%s", RESOURCE_PATH, "/boxbg.css"); - gtk_css_provider_load_from_path(css, css_path); - gtk_style_context_add_provider_for_display(gdk_display_get_default(), + gtk_css_provider_load_from_string(css, snhost->cssdata); + gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_USER); - g_free(css_path); GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); @@ -110,18 +110,22 @@ main(int argc, char *argv[]) StatusNotifierHost *snhost = start_statusnotifierhost(); + const char *bgcolor; int i = 1; for (; i < argc; i++) { - char **strings = g_strsplit(argv[i], "=", 0); if (strcmp(strings[0], "--height") == 0) { snhost->height = atoi(strings[1]); } else if (strcmp(strings[0], "--traymon") == 0) { snhost->traymon = g_strdup(strings[1]); + } else if (strcmp(strings[0], "--bg-color") == 0) { + bgcolor = strdup(strings[1]); } g_strfreev(strings); } + snhost->cssdata = g_strdup_printf("window{background-color:%s;}", bgcolor); + GtkApplication *app = gtk_application_new("com.vetu104.Gtktray", G_APPLICATION_DEFAULT_FLAGS); diff --git a/dwlbtray.h b/dwlbtray.h @@ -29,6 +29,7 @@ typedef struct StatusNotifierHost { uint nameowner_sig_sub_id; uint watcher_id; char *traymon; + char *cssdata; } StatusNotifierHost; typedef struct StatusNotifierItem {