summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-04 23:32:49 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-04 23:32:49 -0700
commitecf02e5509f6f8c18cf0263b54579f5ef4a3c142 (patch)
tree7f1ade7d914d734411565a22d41a528ee0dc93f0 /src
parentd3e8ceb3ac81ac969a13c72de5a357f176548761 (diff)
gtk_fb: actually handle fb window destruction
This never made any attempt to notice when the gtk_fb window was destroyed externally. For now I've just done this a bit hackishly to make things reasonably sane. gtk_fb needs to be revisited in general to firm things up, and til_fb needs better defined semantics surrounding acquire/release vs. init/destroy. A lot of this is vestigial from early rototiller days. This is good enough for now to silence the gtk warnings about destroying the c->image after the containing window destruction already discarded it.
Diffstat (limited to 'src')
-rw-r--r--src/gtk_fb.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/gtk_fb.c b/src/gtk_fb.c
index 5328d05..f9fd015 100644
--- a/src/gtk_fb.c
+++ b/src/gtk_fb.c
@@ -61,6 +61,17 @@ static void resized(GtkWidget *widget, GtkAllocation *allocation, gpointer user_
}
+/* called on "delete-event" for the fb's window */
+static gboolean deleted(GtkWidget *self, GdkEvent *event, gpointer user_data)
+{
+ gtk_fb_t *c = user_data;
+
+ c->window = NULL;
+
+ return FALSE;
+}
+
+
/* parse settings and get the output window realized before
* attempting to create any pages "similar" to it.
*/
@@ -94,6 +105,7 @@ static int gtk_fb_init(const til_settings_t *settings, void **res_context)
c->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_realize(c->window);
+ g_signal_connect(c->window, "delete-event", G_CALLBACK(deleted), c);
*res_context = c;
@@ -105,7 +117,8 @@ static void gtk_fb_shutdown(til_fb_t *fb, void *context)
{
gtk_fb_t *c = context;
- gtk_widget_destroy(c->window);
+ if (c->window)
+ gtk_widget_destroy(c->window);
free(c);
}
@@ -142,6 +155,9 @@ static int gtk_fb_acquire(til_fb_t *fb, void *context, void *page)
gtk_fb_t *c = context;
gtk_fb_page_t *p = page;
+ if (!c->window)
+ return -EPIPE;
+
c->image = gtk_image_new_from_surface(p->surface);
g_signal_connect_after(c->image, "size-allocate", G_CALLBACK(resized), c);
g_signal_connect(c->image, "draw", G_CALLBACK(draw_cb), fb);
@@ -158,7 +174,8 @@ static void gtk_fb_release(til_fb_t *fb, void *context)
{
gtk_fb_t *c = context;
- gtk_widget_destroy(c->image);
+ if (c->window)
+ gtk_widget_destroy(c->image);
}
@@ -168,6 +185,9 @@ static void * gtk_fb_page_alloc(til_fb_t *fb, void *context, til_fb_page_t *res_
gtk_fb_page_t *p;
GdkWindow *gdk_window;
+ if (!c->window)
+ return NULL;
+
p = calloc(1, sizeof(gtk_fb_page_t));
if (!p)
return NULL;
@@ -215,6 +235,9 @@ static int gtk_fb_page_flip(til_fb_t *fb, void *context, void *page)
gtk_fb_t *c = context;
gtk_fb_page_t *p = page;
+ if (!c->window)
+ return -EPIPE;
+
cairo_surface_mark_dirty(p->surface);
gtk_image_set_from_surface(GTK_IMAGE(c->image), p->surface);
© All Rights Reserved