commit c1fe8219bb91c10d451c17e36014434fc170cc49
parent cfc824f41bc38700937fd48db332e66b6f750db7
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date: Tue, 16 Apr 2024 16:47:52 +0300
Make systray spawn at bottom if bar is at bottom
Diffstat:
6 files changed, 64 insertions(+), 36 deletions(-)
diff --git a/dbusmenu.c b/dbusmenu.c
@@ -1,13 +1,16 @@
-/*
- * This whole thing is a mess .......
- */
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
#include <time.h>
#include <glib.h>
+#include <glib-object.h>
#include <gio/gio.h>
+#include <gtk/gtk.h>
#include "dwlbtray.h"
+
static GMenu* create_menumodel(GVariant *data, StatusNotifierItem *snitem);
@@ -177,6 +180,7 @@ create_menumodel(GVariant *data, StatusNotifierItem *snitem)
g_menu_append_item(section, menuitem);
g_object_unref(menuitem);
}
+ // menuitem == NULL means menuitem is a separator
else {
g_menu_append_section(ret, NULL, G_MENU_MODEL(section));
g_object_unref(section);
@@ -217,7 +221,7 @@ on_menulayout_ready(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem *sn
g_error_free(err);
return;
} else if (err) {
- g_warning("%sfrom on_menulayout_ready\n", err->message);
+ g_warning("%s\n", err->message);
g_error_free(err);
return;
}
@@ -272,7 +276,6 @@ on_layout_updated(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem *snit
} else if (err) {
g_warning("%s\n", err->message);
- fprintf(stderr, "from on_layout_updated\n");
g_error_free(err);
return;
}
@@ -360,7 +363,6 @@ create_menu(GObject *obj, GAsyncResult *res, StatusNotifierItem *snitem)
if (err) {
g_warning("%s\n", err->message);
- fprintf(stderr, "from create_menu\n");
g_error_free(err);
return;
}
diff --git a/dwlb.c b/dwlb.c
@@ -109,6 +109,7 @@
" -set-top [OUTPUT] draw bar at the top\n" \
" -set-bottom [OUTPUT] draw bar at the bottom\n" \
" -toggle-location [OUTPUT] toggle bar location\n" \
+ " -nosystray do not launch the systray program\n" \
" -traymon [OUTPUT] set monitor name where systray will appear\n" \
"Other\n" \
" -v get version information\n" \
@@ -1687,13 +1688,14 @@ sig_handler(int sig)
}
static void
-start_systray(const char *parent_progname, const char *traymon)
+start_systray(const char *parent_progname, const char *traymon, bool bottom)
{
char tray_exe_path[PATH_MAX];
char traypath_maybe[PATH_MAX];
char traybg_arg[64];
char height_arg[64];
char traymon_arg[64];
+ char position_arg[64];
pixman_color_t *traybg_clr = &inactive_bg_color;
snprintf(traybg_arg,
@@ -1711,9 +1713,13 @@ start_systray(const char *parent_progname, const char *traymon)
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 (!bottom)
+ snprintf(position_arg, sizeof(position_arg), "--position=%s", "top");
+ else
+ snprintf(position_arg, sizeof(position_arg), "--position=%s", "bottom");
+ char *args[] = { tray_exe_path, position_arg, height_arg, traybg_arg, traymon_arg, NULL };
if (!traymon)
- args[3] = NULL;
+ args[4] = NULL;
int child_pid = fork();
if (child_pid == 0) {
@@ -1729,6 +1735,7 @@ main(int argc, char **argv)
Bar *bar, *bar2;
Seat *seat, *seat2;
const char *traymon = NULL;
+ bool systray_enabled = true;
/* Establish socket directory */
if (!(xdgruntimedir = getenv("XDG_RUNTIME_DIR")))
@@ -1908,6 +1915,8 @@ main(int argc, char **argv)
if (++i >= argc)
DIE("Option -scale requires an argument");
buffer_scale = strtoul(argv[i], &argv[i] + strlen(argv[i]), 10);
+ } else if (!strcmp(argv[i], "-nosystray")) {
+ systray_enabled = false;;
} else if (!strcmp(argv[i], "-traymon")) {
if (++i >= argc)
DIE("Option -traymon requires an argument");
@@ -2005,7 +2014,8 @@ main(int argc, char **argv)
signal(SIGCHLD, SIG_IGN);
/* Start tray program */
- start_systray(argv[0], traymon);
+ if (systray_enabled)
+ start_systray(argv[0], traymon, bottom);
/* Run */
run_display = true;
diff --git a/dwlbtray.c b/dwlbtray.c
@@ -1,10 +1,12 @@
#include <stdlib.h>
-#include <unistd.h>
+#include <string.h>
#include <glib.h>
+#include <glib-object.h>
#include <glib-unix.h>
-#include <gtk4-layer-shell.h>
+#include <gdk/gdk.h>
#include <gtk/gtk.h>
+#include <gtk4-layer-shell.h>
#include "dwlbtray.h"
@@ -30,7 +32,13 @@ activate(GtkApplication* app, StatusNotifierHost *snhost)
gtk_layer_init_for_window(window);
gtk_layer_set_layer(window, GTK_LAYER_SHELL_LAYER_BOTTOM);
gtk_layer_set_exclusive_zone(window, -1);
- static const gboolean anchors[] = {FALSE, TRUE, TRUE, FALSE};
+ static gboolean anchors[] = {FALSE, TRUE, TRUE, FALSE};
+ if (snhost->position == 1) {
+ anchors[0] = FALSE; // left
+ anchors[1] = TRUE; // right
+ anchors[2] = FALSE; // top
+ anchors[3] = TRUE; // bottom
+ }
for (int i = 0; i < GTK_LAYER_SHELL_EDGE_ENTRY_NUMBER; i++) {
gtk_layer_set_anchor(window, i, anchors[i]);
}
@@ -77,6 +85,7 @@ main(int argc, char *argv[])
char *bgcolor = NULL;
char *cssdata;
+ int position = 0;
int i = 1;
for (; i < argc; i++) {
@@ -87,10 +96,15 @@ main(int argc, char *argv[])
snhost->traymon = g_strdup(strings[1]);
} else if (strcmp(strings[0], "--bg-color") == 0) {
bgcolor = strdup(strings[1]);
+ } else if (strcmp(strings[0], "--position") == 0) {
+ if (strcmp(strings[1], "bottom") == 0)
+ position = 1;
}
g_strfreev(strings);
}
+ snhost->position = position;
+
if (bgcolor)
cssdata = g_strdup_printf("window.dwlbtray{background-color:%s;}", bgcolor);
else
diff --git a/dwlbtray.h b/dwlbtray.h
@@ -1,7 +1,10 @@
-#ifndef GTKTRAY_H
-#define GTKTRAY_H
+#ifndef DWLBTRAY_H
+#define DWLBTRAY_H
+
+#include <stdint.h>
#include <glib.h>
+#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
@@ -19,6 +22,7 @@ typedef struct StatusNotifierHost {
char *cssdata;
char *traymon;
gboolean in_exit;
+ int position;
int curwidth;
int height;
int margin;
@@ -203,4 +207,4 @@ void terminate_statusnotifierhost(StatusNotifierHost *snhost);
" </interface>\n" \
"</node>\n"
-#endif /* GTKTRAY_H */
+#endif /* DWLBTRAY_H */
diff --git a/statusnotifierhost.c b/statusnotifierhost.c
@@ -1,11 +1,14 @@
+#include <stdlib.h>
+#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <string.h>
#include <glib.h>
+#include <glib-object.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include <gtk4-layer-shell.h>
#include "dwlbtray.h"
@@ -142,7 +145,6 @@ register_statusnotifieritem(GDBusConnection *conn,
&err);
if (err) {
g_warning("%s\n", err->message);
- fprintf(stderr, "from register_statusnotifieritem\n");
g_error_free(err);
}
}
@@ -359,7 +361,7 @@ name_acquired_handler(GDBusConnection *conn, const char *busname, StatusNotifier
&err);
if (err) {
- g_warning("%s\nfrom name_acquired_handler", err->message);
+ g_warning("%s\n", err->message);
g_error_free(err);
}
}
diff --git a/statusnotifieritem.c b/statusnotifieritem.c
@@ -1,7 +1,13 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
#include <glib.h>
+#include <glib-object.h>
#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
-#include <gtk4-layer-shell.h>
#include "dwlbtray.h"
@@ -65,7 +71,7 @@ rightclick_validate(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem *sn
// Report rest of possible errors
} else if (err) {
- g_warning("%sfrom on_rightclick_cb\n", err->message);
+ g_warning("%s\n", err->message);
g_error_free(err);
} else {
@@ -225,7 +231,6 @@ new_iconname_handler(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem *s
return;
} else if (err) {
g_warning("%s\n", err->message);
- fprintf(stderr, "from new_iconname_handler\n");
g_error_free(err);
return;
}
@@ -265,7 +270,6 @@ new_iconpixmap_handler(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem
return;
} else if (err) {
g_warning("%s\n", err->message);
- fprintf(stderr, "from new_iconpixmap_handler\n");
g_error_free(err);
return;
}
@@ -411,11 +415,6 @@ create_trayitem(GObject *obj, GAsyncResult *res, StatusNotifierItem *snitem)
g_signal_connect(rightclick, "pressed", G_CALLBACK(on_rightclick_cb), snitem);
actiongroup = g_simple_action_group_new();
- if (snitem && icon && GTK_IS_WIDGET(icon)) {
- gtk_widget_insert_action_group(icon,
- "menuitem",
- G_ACTION_GROUP(actiongroup));
- }
snitem->actiongroup = actiongroup;
menu_buspath_v = g_dbus_proxy_get_cached_property(proxy, "Menu");
@@ -424,8 +423,6 @@ create_trayitem(GObject *obj, GAsyncResult *res, StatusNotifierItem *snitem)
else
menu_buspath = NULL;
- // for (int i = 0; valid_menupaths[i]; i++) {
- // if (menu_buspath && g_strrstr(menu_buspath, valid_menupaths[i]) == 0) {
if (menu_buspath) {
GDBusNodeInfo *nodeinfo = g_dbus_node_info_new_for_xml(DBUSMENU_XML, NULL);
g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION,
@@ -438,18 +435,17 @@ create_trayitem(GObject *obj, GAsyncResult *res, StatusNotifierItem *snitem)
(GAsyncReadyCallback)create_menu,
snitem);
g_dbus_node_info_unref(nodeinfo);
+ g_variant_unref(menu_buspath_v);
}
- // }
- // }
if (icon) {
gtk_widget_add_controller(icon, GTK_EVENT_CONTROLLER(leftclick));
gtk_widget_add_controller(icon, GTK_EVENT_CONTROLLER(rightclick));
+ gtk_widget_insert_action_group(icon,
+ "menuitem",
+ G_ACTION_GROUP(actiongroup));
gtk_box_append(GTK_BOX(snitem->host->box), icon);
+
snitem->icon = icon;
}
-
-
- if (menu_buspath_v)
- g_variant_unref(menu_buspath_v);
}