From 528441228648b71f143994ec10943e770e1a4beb Mon Sep 17 00:00:00 2001 From: Louis des Landes Date: Wed, 13 Dec 2023 17:59:59 +1030 Subject: [PATCH 1/2] indicator: Don't render if not full allocation given If we render when we don't get a full gtk allocation then the icon never resizes to the correct size, so skip rendering the image if so. --- indicator/plugin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/indicator/plugin.c b/indicator/plugin.c index b97bde5..4fca2ea 100644 --- a/indicator/plugin.c +++ b/indicator/plugin.c @@ -179,11 +179,18 @@ indicator_graph_update_cb(LoadGraph *g, gpointer user_data) } // resize widget and offscreen window to fit into panel + int icon_height = indicator_get_icon_height(); if (multiload_get_orientation(g->multiload) == GTK_ORIENTATION_HORIZONTAL) - gtk_widget_set_size_request(GTK_WIDGET(g->multiload->container), multiload_calculate_size_request(g->multiload), indicator_get_icon_height()); + gtk_widget_set_size_request(GTK_WIDGET(g->multiload->container), multiload_calculate_size_request(g->multiload), icon_height); else - gtk_widget_set_size_request(GTK_WIDGET(g->multiload->container), 120, indicator_get_icon_height()); //TODO 120 should not be hardcoded + gtk_widget_set_size_request(GTK_WIDGET(g->multiload->container), 120, icon_height); //TODO 120 should not be hardcoded + gtk_widget_get_allocation (GTK_WIDGET(g->multiload->container), &allocation); + if (allocation.height != icon_height) { + // If we render now then we don't recover, so skip it + return; + } + gtk_window_resize(GTK_WINDOW(offscr), allocation.width, allocation.height); indicator_update_pixbuf(g->multiload); From bbe2fe301f6ed995534691d6a6ea93a28199bb56 Mon Sep 17 00:00:00 2001 From: Louis des Landes Date: Thu, 14 Dec 2023 08:13:44 +1030 Subject: [PATCH 2/2] Debounce the icon updates a little. --- indicator/plugin.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/indicator/plugin.c b/indicator/plugin.c index 4fca2ea..e9e7139 100644 --- a/indicator/plugin.c +++ b/indicator/plugin.c @@ -49,6 +49,8 @@ static int icon_current_index=0; static gboolean indicator_connected; static GtkWidget *graphs_menu_items[GRAPH_MAX]; +static int lasttick; + static void indicator_cleanup(int sig) { @@ -153,9 +155,9 @@ indicator_update_pixbuf(MultiloadPlugin *ma) if (error != NULL) { g_error("Cannot save Multiload-ng window to temporary buffer: %s\n", error->message); g_clear_error(&error); - } else + } else { app_indicator_set_icon(indicator, icon_filename[icon_current_index]); - + } icon_current_index = 1-icon_current_index; cairo_surface_destroy (surface); cairo_destroy (cr); @@ -166,6 +168,13 @@ indicator_graph_update_cb(LoadGraph *g, gpointer user_data) { GtkAllocation allocation; + // Don't tick too often! + int now = time(NULL); + if (now - lasttick < 1) { + return; + } + lasttick = now; + indicator_update_menu(g->multiload); if (!g->config->visible)