From 35bd419e49ea8380a2a9225eb08e1591488c2456 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 30 Aug 2013 13:25:22 +0200 Subject: [PATCH] Emit signal from main context Signed-off-by: Sebastian Ramacher --- README | 1 + config.mk | 7 +++++-- render.c | 32 +++++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README b/README index c6c966a..d057887 100644 --- a/README +++ b/README @@ -6,6 +6,7 @@ girara user interface library and several document libraries. Requirements ------------ gtk2 (>= 2.28) +glib (>= 2.28) girara sqlite3 (optional, >= 3.5.9) check (for tests) diff --git a/config.mk b/config.mk index 30a0285..07b9ab6 100644 --- a/config.mk +++ b/config.mk @@ -52,6 +52,9 @@ GTHREAD_LIB ?= $(shell pkg-config --libs gthread-2.0) GMODULE_INC ?= $(shell pkg-config --cflags gmodule-no-export-2.0) GMODULE_LIB ?= $(shell pkg-config --libs gmodule-no-export-2.0) +GLIB_INC ?= $(shell pkg-config --cflags --atleast-version=2.28 glib-2.0) +GLIB_LIB ?= $(shell pkg-config --libs --atleast-version=2.28 glib-2.0) + GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION}) GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION}) @@ -65,8 +68,8 @@ MAGIC_INC ?= MAGIC_LIB ?= -lmagic endif -INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC} ${GMODULE_INC} -LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${GMODULE_LIB} -lpthread -lm +INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC} ${GMODULE_INC} ${GLIB_INC} +LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${GMODULE_LIB} ${GLIB_LIB} -lpthread -lm # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS) diff --git a/render.c b/render.c index 8ca519f..91e154e 100644 --- a/render.c +++ b/render.c @@ -405,6 +405,23 @@ colorumax(const double* h, double l, double l1, double l2) return fmin(u, v); } +typedef struct emit_completed_signal_s +{ + ZathuraRenderRequest* request; + cairo_surface_t* surface; +} emit_completed_signal_t; + +static gboolean +emit_completed_signal(void* data) +{ + emit_completed_signal_t* ecs = data; + /* emit the signal */ + g_signal_emit(ecs->request, request_signals[REQUEST_COMPLETED], 0, ecs->surface); + /* clean up the data */ + cairo_surface_destroy(ecs->surface); + g_free(ecs); + return true; +} static bool render(ZathuraRenderRequest* request, ZathuraRenderer* renderer) @@ -534,16 +551,13 @@ render(ZathuraRenderRequest* request, ZathuraRenderer* renderer) } if (priv->about_to_close == false && request_priv->aborted == false) { - /* update the widget */ - /* - gdk_threads_enter(); - GtkWidget* widget = zathura_page_get_widget(zathura, page); - zathura_page_widget_update_surface(ZATHURA_PAGE(widget), surface); - gdk_threads_leave(); */ + emit_completed_signal_t* ecs = g_malloc(sizeof(ecs)); + ecs->request = request; + ecs->surface = surface; + cairo_surface_reference(surface); - gdk_threads_enter(); - g_signal_emit(request, request_signals[REQUEST_COMPLETED], 0, surface); - gdk_threads_leave(); + /* emit signal from the main context, i.e. the main thread */ + g_main_context_invoke(NULL, emit_completed_signal, ecs); } cairo_surface_destroy(surface);