dwlb

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

commit 737a557b8528b07afe5a32ef5fcea7ce19fe2f47
parent d76efa01ff5ba14cb5ad3de2b6c6db69740ead36
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date:   Sun,  7 Jul 2024 16:04:40 +0300

Remove traymon from README and misc cleanup

Diffstat:
MREADME.md | 5-----
Mdwlb.c | 36+++++++++++++++++++++---------------
Msystray/dwlbtray.c | 5++++-
Msystray/sndbusmenu.c | 49+++++++++++++++++++++++++++++++------------------
Msystray/snhost.c | 39++++++++++++++++++++++++---------------
Msystray/snitem.c | 38+++++++++++++++++++++++++++-----------
Msystray/snwatcher.c | 25+++++++++++++------------
7 files changed, 120 insertions(+), 77 deletions(-)

diff --git a/README.md b/README.md @@ -30,11 +30,6 @@ Pass `dwlb` as an argument to dwl's `-s` flag. This will populate each connected dwl -s 'dwlb -font "monospace:size=16"' ``` -To specify on which monitor the systray will appear, append option `-traymon [OUTPUT]` to the command line: -```bash -dwl -s 'dwlb -font "monospace:size=16" -traymon DP-1' -``` - ## Ipc If dwl is [patched](https://github.com/djpohly/dwl/wiki/ipc) appropriately, dwlb is capable of communicating directly with dwl. When ipc is enabled with `-ipc`, dwlb does not read from stdin, and clicking tags functions as you would expect. Ipc can be disabled with `-no-ipc`. diff --git a/dwlb.c b/dwlb.c @@ -11,6 +11,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <libgen.h> #include <sys/mman.h> #include <sys/select.h> #include <sys/socket.h> @@ -180,8 +181,6 @@ typedef struct { struct wl_list link; } Seat; -static const char tray_bin_name[] = "dwlbtray"; - static int sock_fd; static char socketdir[256]; static char *socketpath; @@ -1689,24 +1688,27 @@ sig_handler(int sig) run_display = false; } +#define MAX_ARGS 16 +#define MAX_ARG_LEN 16 + static void construct_tray_path(char *path_buf, const char *parent_progname, size_t size) { + const char tray_bin_name[] = "dwlbtray"; char progname_buf[PATH_MAX]; char traypath_maybe[PATH_MAX]; snprintf(progname_buf, sizeof(progname_buf), "%s", parent_progname); - char *lastslash = strrchr(progname_buf, '/'); - if (lastslash) { - *lastslash = '\0'; + char *dirpath = dirname(progname_buf); + if (dirpath) { snprintf(traypath_maybe, sizeof(traypath_maybe), "%s/systray/%s", - progname_buf, + dirpath, tray_bin_name); } else { - *traypath_maybe = '\0'; + traypath_maybe[0] = '\0'; } if (access(traypath_maybe, X_OK) == 0) @@ -1736,14 +1738,14 @@ construct_trayheight_arg(char *height_arg, size_t size) static void start_systray(const char *parent_progname, bool bottom) { - char *args[16]; + char *args[MAX_ARGS]; char argv0[PATH_MAX]; - char traybg_opt[] = "-c"; - char trayheight_opt[] = "-s"; - char bottom_opt[] = "-b"; - char traybg_arg[16]; - char trayheight_arg[16]; + char traybg_opt[] = "-c"; + char trayheight_opt[] = "-s"; + char bottom_opt[] = "-b"; + char traybg_arg[MAX_ARG_LEN]; + char trayheight_arg[MAX_ARG_LEN]; construct_tray_path(argv0, parent_progname, sizeof(argv0)); construct_traybg_arg(traybg_arg, sizeof(traybg_arg)); @@ -1763,8 +1765,12 @@ start_systray(const char *parent_progname, bool bottom) // char *args[16] = { "/home/user/git/dwlb/systray/dwlbtray", "-c", "#FFFFFF", "-s", "99", "-b", "-t", "DP-1", NULL, *garbage*, ... }; int child_pid = fork(); - if (child_pid == 0) { - execvp(args[0], args); + if (child_pid == -1) { + DIE("Fork failed"); + } else if (child_pid == 0) { + if (execvp(args[0], args) == -1) { + DIE("Could not start systray program"); + }; } } diff --git a/systray/dwlbtray.c b/systray/dwlbtray.c @@ -1,5 +1,7 @@ #include <stdlib.h> +#include <stdio.h> #include <unistd.h> +#include <signal.h> #include <string.h> #include <glib.h> @@ -69,7 +71,8 @@ activate(GtkApplication* app, void *data) GListModel *mons = gdk_display_get_monitors(display); // Create tray for each monitor - for (uint i = 0; i < g_list_model_get_n_items(mons); i++) { + unsigned int i; + for (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); diff --git a/systray/sndbusmenu.c b/systray/sndbusmenu.c @@ -1,8 +1,10 @@ #include "sndbusmenu.h" #include <stdlib.h> +#include <stdio.h> #include <stdint.h> #include <string.h> +#include <time.h> #include <glib.h> #include <glib-object.h> @@ -44,8 +46,10 @@ enum LAST_SIGNAL }; +#define ACTION_NAME_MAX_LEN 32 + static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; -static uint signals[LAST_SIGNAL]; +static unsigned int signals[LAST_SIGNAL]; static const char actiongroup_pfx[] = "menuitem"; static const int layout_update_freq = 80; @@ -59,12 +63,12 @@ static void sn_dbusmenu_dispose (GObject *object); static void sn_dbusmenu_finalize (GObject *object); static void sn_dbusmenu_get_property (GObject *object, - uint property_id, + unsigned int property_id, GValue *value, GParamSpec *pspec); static void sn_dbusmenu_set_property (GObject *object, - uint property_id, + unsigned int property_id, const GValue *value, GParamSpec *pspec); @@ -102,8 +106,9 @@ action_free(void *data, GClosure *closure) static GSimpleAction* create_action(uint32_t id, SnDbusmenu *self) { - char *action_name = g_strdup_printf("%u", id); - GSimpleAction *action = g_simple_action_new(action_name, NULL); + char name[ACTION_NAME_MAX_LEN]; + snprintf(name, sizeof(name), "%u", id); + GSimpleAction *action = g_simple_action_new(name, NULL); ActionCallbackData *data = g_malloc(sizeof(ActionCallbackData)); data->id = id; @@ -116,8 +121,6 @@ create_action(uint32_t id, SnDbusmenu *self) action_free, G_CONNECT_DEFAULT); - g_free(action_name); - return action; } @@ -131,6 +134,7 @@ create_menuitem(int32_t id, GVariant *menuitem_data, GVariant *submenuitem_data, GMenuItem *menuitem = NULL; + char detailed_name[ACTION_NAME_MAX_LEN]; const char *label = NULL; const char *type = NULL; gboolean isenabled = TRUE; @@ -172,21 +176,20 @@ create_menuitem(int32_t id, GVariant *menuitem_data, GVariant *submenuitem_data, if ((label && isvisible && isenabled) && !(type && strcmp(type, "separator") == 0)) { GSimpleAction *action = create_action(id, self); - char *action_name = g_strdup_printf("%s.%u", actiongroup_pfx, id); + snprintf(detailed_name, sizeof(detailed_name), "%s.%u", actiongroup_pfx, id); g_action_map_add_action(actionmap, G_ACTION(action)); - menuitem = g_menu_item_new(label, action_name); + menuitem = g_menu_item_new(label, detailed_name); - g_free(action_name); g_object_unref(action); - } else if ((label && isvisible && !isenabled && !(type && strcmp(type, "separator") == 0))) { + } else if ((label && isvisible && !isenabled && + !(type && strcmp(type, "separator") == 0))) { GSimpleAction *action = create_action(id, self); g_simple_action_set_enabled(action, FALSE); - char *action_name = g_strdup_printf("%s.%u", actiongroup_pfx, id); + snprintf(detailed_name, sizeof(detailed_name), "%s.%u", actiongroup_pfx, id); g_action_map_add_action(actionmap, G_ACTION(action)); - menuitem = g_menu_item_new(label, action_name); + menuitem = g_menu_item_new(label, detailed_name); - g_free(action_name); g_object_unref(action); } @@ -338,7 +341,9 @@ proxy_signal_handler(GDBusProxy *proxy, if (!self->update_pending) { self->update_pending = TRUE; g_object_ref(self->snitem); - g_timeout_add_once(layout_update_freq, (GSourceOnceFunc)layout_update, g_object_ref(self)); + g_timeout_add_once(layout_update_freq, + (GSourceOnceFunc)layout_update, + g_object_ref(self)); } else { g_debug("skipping update"); } @@ -349,7 +354,9 @@ proxy_signal_handler(GDBusProxy *proxy, if (!self->update_pending) { self->update_pending = TRUE; g_object_ref(self->snitem); - g_timeout_add_once(layout_update_freq, (GSourceOnceFunc)layout_update, g_object_ref(self)); + g_timeout_add_once(layout_update_freq, + (GSourceOnceFunc)layout_update, + g_object_ref(self)); } else { g_debug("skipping update"); } @@ -491,13 +498,19 @@ proxy_ready_handler(GObject *obj, GAsyncResult *res, void *data) } static void -sn_dbusmenu_get_property(GObject *object, uint property_id, GValue *value, GParamSpec *pspec) +sn_dbusmenu_get_property(GObject *object, + unsigned int property_id, + GValue *value, + GParamSpec *pspec) { G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); } static void -sn_dbusmenu_set_property(GObject *object, uint property_id, const GValue *value, GParamSpec *pspec) +sn_dbusmenu_set_property(GObject *object, + unsigned int property_id, + const GValue *value, + GParamSpec *pspec) { SnDbusmenu *self = SN_DBUSMENU(object); diff --git a/systray/snhost.c b/systray/snhost.c @@ -1,6 +1,9 @@ #include "snhost.h" #include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <limits.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> @@ -24,8 +27,8 @@ struct _SnHost GHashTable* snitems; char* mon; - ulong reg_sub_id; - ulong unreg_sub_id; + unsigned long reg_sub_id; + unsigned long unreg_sub_id; int defaultwidth; int defaultheight; @@ -84,7 +87,10 @@ dwlb_request_resize(SnHost *self) sockaddr.sun_family = AF_UNIX; - snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s/dwlb/dwlb-0", g_get_user_runtime_dir()); + snprintf(sockaddr.sun_path, + sizeof(sockaddr.sun_path), + "%s/dwlb/dwlb-0", + g_get_user_runtime_dir()); char sockbuf[64]; snprintf(sockbuf, sizeof(sockbuf), "%s %s %i", self->mon, "resize", self->curwidth); @@ -139,7 +145,10 @@ sn_host_unregister_item(SnWatcher *watcher, const char *busname, SnHost *self) } static void -sn_host_set_property(GObject *object, uint property_id, const GValue *value, GParamSpec *pspec) +sn_host_set_property(GObject *object, + unsigned int property_id, + const GValue *value, + GParamSpec *pspec) { SnHost *self = SN_HOST(object); @@ -169,7 +178,7 @@ sn_host_set_property(GObject *object, uint property_id, const GValue *value, GPa } static void -sn_host_get_property(GObject *object, uint property_id, GValue *value, GParamSpec *pspec) +sn_host_get_property(GObject *object, unsigned int property_id, GValue *value, GParamSpec *pspec) { G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); } @@ -194,8 +203,8 @@ sn_host_class_init(SnHostClass *klass) obj_properties[PROP_DEFAULTWIDTH] = g_param_spec_int("defaultwidth", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 22, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | @@ -203,8 +212,8 @@ sn_host_class_init(SnHostClass *klass) obj_properties[PROP_DEFAULTHEIGHT] = g_param_spec_int("defaultheight", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 22, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | @@ -212,8 +221,8 @@ sn_host_class_init(SnHostClass *klass) obj_properties[PROP_ICONSIZE] = g_param_spec_int("iconsize", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 22, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | @@ -221,8 +230,8 @@ sn_host_class_init(SnHostClass *klass) obj_properties[PROP_MARGINS] = g_param_spec_int("margins", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 4, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | @@ -230,8 +239,8 @@ sn_host_class_init(SnHostClass *klass) obj_properties[PROP_SPACING] = g_param_spec_int("spacing", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 4, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | diff --git a/systray/snitem.c b/systray/snitem.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <stdint.h> +#include <limits.h> #include <string.h> #include <glib.h> @@ -31,12 +32,13 @@ struct _SnItem GMenu* init_menu; GSList* cachedicons; + unsigned long popup_sig_id; + int iconsize; gboolean ready; gboolean exiting; gboolean menu_visible; - ulong popup_sig_id; }; G_DEFINE_FINAL_TYPE(SnItem, sn_item, GTK_TYPE_WIDGET) @@ -59,7 +61,7 @@ enum }; static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; -static uint signals[LAST_SIGNAL]; +static unsigned int signals[LAST_SIGNAL]; typedef struct { GVariant* iconpixmap; @@ -258,7 +260,9 @@ sn_item_proxy_new_iconname_handler(GObject *obj, GAsyncResult *res, void *data) return; } - GSList *elem = g_slist_find_custom(self->cachedicons, iconname, (GCompareFunc)find_cached_name); + GSList *elem = g_slist_find_custom(self->cachedicons, + iconname, + (GCompareFunc)find_cached_name); if (elem) { // Cache hit @@ -328,7 +332,9 @@ sn_item_proxy_new_pixmaps_handler(GObject *obj, GAsyncResult *res, void *data) return; } - GSList *elem = g_slist_find_custom(self->cachedicons, pixmap, (GCompareFunc)find_cached_pixmap); + GSList *elem = g_slist_find_custom(self->cachedicons, + pixmap, + (GCompareFunc)find_cached_pixmap); if (elem) { // Cache hit @@ -365,7 +371,9 @@ sn_item_proxy_signal_handler(GDBusProxy *proxy, if (self->iconpixmap) g_dbus_proxy_call(proxy, "org.freedesktop.DBus.Properties.Get", - g_variant_new("(ss)", "org.kde.StatusNotifierItem", "IconPixmap"), + g_variant_new("(ss)", + "org.kde.StatusNotifierItem", + "IconPixmap"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, @@ -375,7 +383,9 @@ sn_item_proxy_signal_handler(GDBusProxy *proxy, if (self->iconname) g_dbus_proxy_call(proxy, "org.freedesktop.DBus.Properties.Get", - g_variant_new("(ss)", "org.kde.StatusNotifierItem", "IconName"), + g_variant_new("(ss)", + "org.kde.StatusNotifierItem", + "IconName"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, @@ -565,7 +575,10 @@ sn_item_size_allocate(GtkWidget *widget, } static void -sn_item_set_property(GObject *object, uint property_id, const GValue *value, GParamSpec *pspec) +sn_item_set_property(GObject *object, + unsigned int property_id, + const GValue *value, + GParamSpec *pspec) { SnItem *self = SN_ITEM(object); @@ -595,7 +608,7 @@ sn_item_set_property(GObject *object, uint property_id, const GValue *value, GPa } static void -sn_item_get_property(GObject *object, uint property_id, GValue *value, GParamSpec *pspec) +sn_item_get_property(GObject *object, unsigned int property_id, GValue *value, GParamSpec *pspec) { SnItem *self = SN_ITEM(object); @@ -653,8 +666,8 @@ sn_item_class_init(SnItemClass *klass) obj_properties[PROP_ICONSIZE] = g_param_spec_int("iconsize", NULL, NULL, - G_MININT, - G_MAXINT, + INT_MIN, + INT_MAX, 22, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | @@ -820,7 +833,10 @@ sn_item_clear_menu_model(SnItem *self) if (!self->popovermenu) return; - gtk_popover_menu_set_menu_model(GTK_POPOVER_MENU(self->popovermenu), G_MENU_MODEL(self->init_menu)); + GtkPopoverMenu *popovermenu = GTK_POPOVER_MENU(self->popovermenu); + GMenuModel *menumodel = G_MENU_MODEL(self->init_menu); + + gtk_popover_menu_set_menu_model(popovermenu, menumodel); } void diff --git a/systray/snwatcher.c b/systray/snwatcher.c @@ -24,17 +24,12 @@ G_DEFINE_FINAL_TYPE(SnWatcher, sn_watcher, G_TYPE_OBJECT) enum { - N_PROPERTIES = 1, -}; - -enum -{ TRAYITEM_REGISTERED, TRAYITEM_UNREGISTERED, LAST_SIGNAL }; -static uint signals[LAST_SIGNAL]; +static unsigned int signals[LAST_SIGNAL]; static void sn_watcher_dispose (GObject *obj); @@ -216,11 +211,14 @@ sn_watcher_monitor_bus(GDBusConnection* conn, const char *new_owner; g_variant_get(params, "(&s&s&s)", &name, &old_owner, &new_owner); if (strcmp(new_owner, "") == 0) { - GList *pmatch = g_list_find_custom(self->tracked_items, name, (GCompareFunc)strcmp); + GList *pmatch = g_list_find_custom(self->tracked_items, + name, + (GCompareFunc)strcmp); if (pmatch) { sn_watcher_unregister_item(self, pmatch->data); g_free(pmatch->data); - self->tracked_items = g_list_delete_link(self->tracked_items, pmatch); + self->tracked_items = g_list_delete_link(self->tracked_items, + pmatch); } } } @@ -309,14 +307,17 @@ sn_watcher_name_lost_handler(GDBusConnection *conn, const char *busname, void *d } static GObject* -sn_watcher_constructor(GType type, uint n_construct_properties, GObjectConstructParam *construct_properties) +sn_watcher_constructor(GType type, + unsigned int n_construct_properties, + GObjectConstructParam *construct_properties) { static GObject *singleton = NULL; if (singleton == NULL) { - singleton = G_OBJECT_CLASS(sn_watcher_parent_class)->constructor(type, - n_construct_properties, - construct_properties); + singleton = + G_OBJECT_CLASS(sn_watcher_parent_class)->constructor(type, + n_construct_properties, + construct_properties); g_object_add_weak_pointer(singleton, (void*)&singleton); return singleton;