Remove GSourceFunc casts

Convert the callback into a real GSourceFunc.

Split data gathering and timeout handling:
collect_data() does what the name suggests.
init_timeout() will establish a timer.
force_timeout_update() did what collect_data() does.
timeout was in fact a timer_id.

No change in behavior intended.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
This commit is contained in:
Olaf Hering
2020-12-01 21:48:27 +01:00
committed by Simon Steinbeiß
parent e25b5246b2
commit a511e34029

View File

@@ -26,7 +26,7 @@ static XtmSettings *settings;
static GtkWidget *window; static GtkWidget *window;
static GtkStatusIcon *status_icon_or_null = NULL; static GtkStatusIcon *status_icon_or_null = NULL;
static XtmTaskManager *task_manager; static XtmTaskManager *task_manager;
static guint timeout = 0; static guint timer_id;
static gboolean start_hidden = FALSE; static gboolean start_hidden = FALSE;
static GOptionEntry main_entries[] = { static GOptionEntry main_entries[] = {
@@ -120,8 +120,8 @@ delete_window (void)
return TRUE; return TRUE;
} }
static gboolean static void
init_timeout (void) collect_data (void)
{ {
guint num_processes; guint num_processes;
gfloat cpu, memory_percent, swap_percent; gfloat cpu, memory_percent, swap_percent;
@@ -162,32 +162,33 @@ init_timeout (void)
} }
xtm_task_manager_update_model (task_manager); xtm_task_manager_update_model (task_manager);
}
if (timeout == 0) static gboolean
{ init_timeout_cb (gpointer user_data)
guint refresh_rate; {
g_object_get (settings, "refresh-rate", &refresh_rate, NULL); collect_data ();
timeout = g_timeout_add (refresh_rate, (GSourceFunc)init_timeout, NULL);
}
return TRUE; return TRUE;
} }
static void static void
force_timeout_update (void) init_timeout (void)
{ {
init_timeout (); guint refresh_rate;
g_object_get (settings, "refresh-rate", &refresh_rate, NULL);
timer_id = g_timeout_add (refresh_rate, init_timeout_cb, NULL);
} }
static void static void
refresh_rate_changed (void) refresh_rate_changed (void)
{ {
if (!g_source_remove (timeout)) if (!g_source_remove (timer_id))
{ {
g_critical ("Unable to remove source"); g_critical ("Unable to remove source");
return; return;
} }
timeout = 0; timer_id = 0;
init_timeout (); init_timeout ();
} }
@@ -249,10 +250,11 @@ int main (int argc, char *argv[])
task_manager = xtm_task_manager_new (xtm_process_window_get_model (XTM_PROCESS_WINDOW (window))); task_manager = xtm_task_manager_new (xtm_process_window_get_model (XTM_PROCESS_WINDOW (window)));
collect_data ();
init_timeout (); init_timeout ();
g_signal_connect (settings, "notify::refresh-rate", G_CALLBACK (refresh_rate_changed), NULL); g_signal_connect (settings, "notify::refresh-rate", G_CALLBACK (refresh_rate_changed), NULL);
g_signal_connect_after (settings, "notify::more-precision", G_CALLBACK (force_timeout_update), NULL); g_signal_connect_after (settings, "notify::more-precision", G_CALLBACK (collect_data), NULL);
g_signal_connect_after (settings, "notify::full-command-line", G_CALLBACK (force_timeout_update), NULL); g_signal_connect_after (settings, "notify::full-command-line", G_CALLBACK (collect_data), NULL);
g_signal_connect (settings, "notify::show-status-icon", G_CALLBACK (show_hide_status_icon), NULL); g_signal_connect (settings, "notify::show-status-icon", G_CALLBACK (show_hide_status_icon), NULL);
g_signal_connect (window, "destroy", G_CALLBACK (destroy_window), NULL); g_signal_connect (window, "destroy", G_CALLBACK (destroy_window), NULL);
@@ -263,8 +265,8 @@ int main (int argc, char *argv[])
else else
g_warning ("Nothing to do: activate hiding to the notification area when using --start-hidden"); g_warning ("Nothing to do: activate hiding to the notification area when using --start-hidden");
if (timeout > 0) if (timer_id > 0)
g_source_remove (timeout); g_source_remove (timer_id);
return 0; return 0;
} }