dwlb

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

commit cfc824f41bc38700937fd48db332e66b6f750db7
parent 5420ac3f72571a2eb73918e41c59834100469ce2
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date:   Mon, 15 Apr 2024 21:40:50 +0300

Reset bar width on exit

Diffstat:
Mdwlbtray.c | 2+-
Mdwlbtray.h | 1+
Mstatusnotifierhost.c | 28+++++++++++-----------------
Mstatusnotifieritem.c | 33+++++++++++++--------------------
4 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/dwlbtray.c b/dwlbtray.c @@ -99,7 +99,7 @@ main(int argc, char *argv[]) snhost->cssdata = cssdata; g_free(bgcolor); - GtkApplication *app = gtk_application_new("com.vetu104.Gtktray", + GtkApplication *app = gtk_application_new("org.dwlb.dwlbtray", G_APPLICATION_DEFAULT_FLAGS); g_signal_connect(app, "activate", G_CALLBACK(activate), snhost); diff --git a/dwlbtray.h b/dwlbtray.h @@ -18,6 +18,7 @@ typedef struct StatusNotifierHost { GtkWindow *window; char *cssdata; char *traymon; + gboolean in_exit; int curwidth; int height; int margin; diff --git a/statusnotifierhost.c b/statusnotifierhost.c @@ -65,7 +65,9 @@ unregister_all(StatusNotifierHost *snhost) void dwlb_request_resize(StatusNotifierHost *snhost) { - if (snhost->noitems <= 1) + if (snhost->in_exit) + snhost->curwidth = 0; + else if (snhost->noitems <= 1) snhost->curwidth = 22; else snhost->curwidth = 22 * snhost->noitems - 6; // dunno why substract 6 to make it align, just trial and error until it worked @@ -153,36 +155,28 @@ unregister_statusnotifieritem(StatusNotifierItem *snitem) if (snitem->popovermenu) { gtk_popover_menu_set_menu_model(GTK_POPOVER_MENU(snitem->popovermenu), NULL); gtk_widget_unparent(snitem->popovermenu); - snitem->popovermenu = NULL; } if (snitem->icon) { - // TODO: Why do we still have children left??? - GtkWidget *test; - while ((test = gtk_widget_get_first_child(snitem->icon))) { - gtk_widget_unparent(test); - } + gtk_widget_insert_action_group(snitem->icon, "menuitem", NULL); + g_object_unref(snitem->actiongroup); gtk_box_remove(GTK_BOX(snitem->host->box), snitem->icon); snitem->icon = NULL; } - GError *err = NULL; g_dbus_connection_emit_signal(snitem->host->conn, NULL, "/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher", "StatusNotifierItemUnregistered", g_variant_new("(s)", snitem->busname), - &err); - if (err) { - g_warning("%s\n", err->message); - fprintf(stderr, "from unregister_statusnotifieritem\n"); - g_error_free(err); - } + NULL); if (snitem->menuproxy) g_object_unref(snitem->menuproxy); + if (snitem->proxy) + g_object_unref(snitem->proxy); if (snitem->action_cb_data_slist) g_slist_free_full(snitem->action_cb_data_slist, g_free); @@ -194,7 +188,6 @@ unregister_statusnotifieritem(StatusNotifierItem *snitem) g_free(snitem->iconname); } - g_object_unref(snitem->actiongroup); g_free(snitem->busname); snitem->host->trayitems = g_slist_remove(snitem->host->trayitems, snitem); @@ -366,8 +359,7 @@ name_acquired_handler(GDBusConnection *conn, const char *busname, StatusNotifier &err); if (err) { - g_warning("%s\n", err->message); - fprintf(stderr, "from name_acquired_handler\n"); + g_warning("%s\nfrom name_acquired_handler", err->message); g_error_free(err); } } @@ -384,6 +376,8 @@ name_lost_handler(GDBusConnection *conn, const char *busname, StatusNotifierHost static void snhost_finalize(StatusNotifierHost *snhost) { + snhost->in_exit = TRUE; + dwlb_request_resize(snhost); gtk_window_close(snhost->window); g_free(snhost); snhost = NULL; diff --git a/statusnotifieritem.c b/statusnotifieritem.c @@ -109,7 +109,7 @@ pb_destroy(unsigned char *pixeld, void *data) static GVariant* -select_icon_by_size(GVariant *icondata_v) +select_icon_by_size(GVariant *icondata_v, int target_size) { // Apps broadcast icons as variant a(iiay) // Meaning array of tuples, tuple representing an icon @@ -119,7 +119,7 @@ select_icon_by_size(GVariant *icondata_v) GVariantIter iter; int selected_index = 0; int current_index = 0; - int32_t target_icon_size = 22; + int32_t target_icon_size = (int32_t)target_size; int32_t diff = INT32_MAX; GVariant *child; g_variant_iter_init(&iter, icondata_v); @@ -147,11 +147,11 @@ select_icon_by_size(GVariant *icondata_v) static GdkPaintable* -get_paintable_from_data(GVariant *icondata_v) +get_paintable_from_data(GVariant *icondata_v, int target_size) { GdkPaintable *paintable; GVariantIter iter; - GVariant *iconpixmap_v = select_icon_by_size(icondata_v); + GVariant *iconpixmap_v = select_icon_by_size(icondata_v, target_size); int32_t width; int32_t height; @@ -194,7 +194,7 @@ get_paintable_from_data(GVariant *icondata_v) static GdkPaintable* -get_paintable_from_name(const char *iconname) +get_paintable_from_name(const char *iconname, int target_size) { GdkPaintable *paintable = NULL; GtkIconPaintable *icon; @@ -203,7 +203,7 @@ get_paintable_from_name(const char *iconname) icon = gtk_icon_theme_lookup_icon(theme, iconname, NULL, // const char **fallbacks - 22, + target_size, 1, GTK_TEXT_DIR_LTR, 0); // GtkIconLookupFlags @@ -246,7 +246,7 @@ new_iconname_handler(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem *s g_object_unref(snitem->paintable); snitem->iconname = g_strdup(iconname); - snitem->paintable = get_paintable_from_name(snitem->iconname); + snitem->paintable = get_paintable_from_name(snitem->iconname, snitem->host->height); gtk_image_set_from_paintable(GTK_IMAGE(snitem->icon), snitem->paintable); g_variant_unref(data); @@ -283,8 +283,10 @@ new_iconpixmap_handler(GDBusProxy *proxy, GAsyncResult *res, StatusNotifierItem g_object_unref(snitem->paintable); g_variant_unref(snitem->iconpixmap_v); snitem->iconpixmap_v = newpixmap_v; - snitem->paintable = get_paintable_from_data(snitem->iconpixmap_v); - gtk_image_set_from_paintable(GTK_IMAGE (snitem->icon), snitem->paintable); + GdkPaintable *paintable = get_paintable_from_data(snitem->iconpixmap_v, + snitem->host->height); + gtk_image_set_from_paintable(GTK_IMAGE (snitem->icon), paintable); + snitem->paintable = paintable; } @@ -335,7 +337,7 @@ create_icon(GDBusProxy *proxy, StatusNotifierItem *snitem) } if (iconname && strcmp(iconname, "") != 0) { - paintable = get_paintable_from_name(iconname); + paintable = get_paintable_from_name(iconname, snitem->host->height); snitem->iconname = g_strdup(iconname); @@ -343,7 +345,7 @@ create_icon(GDBusProxy *proxy, StatusNotifierItem *snitem) GVariant *iconpixmap_v = g_dbus_proxy_get_cached_property(proxy, "IconPixmap"); if (!iconpixmap_v) return NULL; - paintable = get_paintable_from_data(iconpixmap_v); + paintable = get_paintable_from_data(iconpixmap_v, snitem->host->height); snitem->iconpixmap_v = iconpixmap_v; @@ -388,15 +390,6 @@ create_trayitem(GObject *obj, GAsyncResult *res, StatusNotifierItem *snitem) GSimpleActionGroup *actiongroup; GtkWidget *icon; - /* - * const char *valid_menupaths[] = { - * "/MenuBar", - * "/com/canonical/dbusmenu", - * "/org/ayatana/NotificationItem", - * NULL - * }; - */ - g_signal_connect(proxy, "g-signal", G_CALLBACK(trayitem_signal_handler), snitem); iconthemepath_v = g_dbus_proxy_get_cached_property(proxy, "IconThemePath");