use g_clear_pointer with gtk_widget_destroy

brief, clear, idiomatic and grep friendly
This commit is contained in:
Hysterical Raisins
2019-07-09 13:33:49 +02:00
parent b3e1d84e6c
commit c33006bcbc

View File

@ -109,8 +109,7 @@ on_notify_keyboard (GObject *object,
if (context->window) { if (context->window) {
if (keyboard == NULL) { if (keyboard == NULL) {
gtk_widget_hide (context->window); gtk_widget_hide (context->window);
gtk_widget_destroy (context->widget); g_clear_pointer (&context->widget, gtk_widget_destroy);
context->widget = NULL;
} else { } else {
gboolean was_visible = gtk_widget_get_visible (context->window); gboolean was_visible = gtk_widget_get_visible (context->window);
/* avoid to send KeyboardVisibilityChanged */ /* avoid to send KeyboardVisibilityChanged */
@ -323,8 +322,9 @@ make_window (ServerContextService *context) {
} }
static void static void
destroy_window (ServerContextService *context) { destroy_window (ServerContextService *context)
context->window = NULL; {
context->window = NULL; // FIXME: doesn't destroy much
} }
static void static void
@ -335,10 +335,7 @@ update_widget (ServerContextService *context)
gchar *theme_path; gchar *theme_path;
EekTheme *theme; EekTheme *theme;
if (context->widget) { g_clear_pointer (&context->widget, gtk_widget_destroy);
gtk_widget_destroy (context->widget);
context->widget = NULL;
}
theme_path = g_build_filename (THEMESDIR, "default.css", NULL); theme_path = g_build_filename (THEMESDIR, "default.css", NULL);
@ -374,9 +371,9 @@ server_context_service_real_hide_keyboard (EekboardContextService *_context)
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context); ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
gtk_widget_hide (context->window); gtk_widget_hide (context->window);
gtk_container_remove(GTK_CONTAINER(context->window), context->widget); g_clear_pointer (&context->widget, gtk_widget_destroy);
context->widget = NULL; // When GTK removes the widget, it doesn't just unlink it, but also frees it
destroy_window (context); destroy_window (context); // <--- FIXME: looks suspect
EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)-> EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)->
hide_keyboard (_context); hide_keyboard (_context);
@ -442,10 +439,8 @@ server_context_service_dispose (GObject *object)
{ {
ServerContextService *context = SERVER_CONTEXT_SERVICE(object); ServerContextService *context = SERVER_CONTEXT_SERVICE(object);
if (context->window) { g_clear_pointer (&context->window, gtk_widget_destroy);
gtk_widget_destroy (context->window); context->widget = NULL;
context->window = NULL;
}
G_OBJECT_CLASS (server_context_service_parent_class)->dispose (object); G_OBJECT_CLASS (server_context_service_parent_class)->dispose (object);
} }