From 87f6314dabdc2067a19e01f8b29f9ecc38ed825b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 8 Mar 2014 14:13:27 +0000 Subject: move scheduleing into browser operation table --- gtk/gui.c | 5 +++-- gtk/scaffolding.c | 9 ++++----- gtk/schedule.c | 23 ++++++++++++++++------- gtk/schedule.h | 3 ++- 4 files changed, 25 insertions(+), 15 deletions(-) (limited to 'gtk') diff --git a/gtk/gui.c b/gtk/gui.c index a3bf57cb3..40c2ad615 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -522,7 +522,7 @@ static bool nslog_stream_configure(FILE *fptr) -static void gui_poll(bool active) +static void nsgtk_poll(bool active) { CURLMcode code; fd_set read_fd_set, write_fd_set, exc_fd_set; @@ -990,7 +990,8 @@ uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) static struct gui_browser_table nsgtk_browser_table = { - .poll = gui_poll, + .poll = nsgtk_poll, + .schedule = nsgtk_schedule, .quit = gui_quit, .set_search_ico = gui_set_search_ico, diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 36ba13a85..ffe6a221c 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -26,7 +26,6 @@ #include #include "utils/messages.h" -#include "utils/schedule.h" #include "utils/url.h" #include "utils/log.h" #include "utils/nsoption.h" @@ -70,7 +69,7 @@ #include "gtk/gdk.h" #include "gtk/scaffolding.h" #include "gtk/tabs.h" - +#include "gtk/schedule.h" /** Macro to define a handler for menu, button and activate events. */ @@ -329,7 +328,7 @@ static void nsgtk_throb(void *p) gtk_image_set_from_pixbuf(g->throbber, nsgtk_throbber->framedata[ g->throb_frame]); - schedule(10, nsgtk_throb, p); + nsgtk_schedule(100, nsgtk_throb, p); } static guint nsgtk_scaffolding_update_edit_actions_sensitivity( @@ -2175,7 +2174,7 @@ void gui_window_start_throbber(struct gui_window* _g) nsgtk_window_update_back_forward(g); - schedule(10, nsgtk_throb, g); + nsgtk_schedule(100, nsgtk_throb, g); } void gui_window_stop_throbber(struct gui_window* _g) @@ -2184,7 +2183,7 @@ void gui_window_stop_throbber(struct gui_window* _g) if (g == NULL) return; nsgtk_window_update_back_forward(g); - schedule_remove(nsgtk_throb, g); + nsgtk_schedule(-1, nsgtk_throb, g); if (g->buttons[STOP_BUTTON] != NULL) g->buttons[STOP_BUTTON]->sensitivity = false; if (g->buttons[RELOAD_BUTTON] != NULL) diff --git a/gtk/schedule.c b/gtk/schedule.c index 5b168b689..e28675a0b 100644 --- a/gtk/schedule.c +++ b/gtk/schedule.c @@ -20,7 +20,8 @@ #include #include -#include "utils/schedule.h" +#include "utils/errors.h" + #include "gtk/schedule.h" #ifdef DEBUG_GTK_SCHEDULE @@ -71,7 +72,7 @@ nsgtk_schedule_kill_callback(void *_target, void *_match) } } -void +static void schedule_remove(void (*callback)(void *p), void *p) { _nsgtk_callback_t cb_match = { @@ -87,19 +88,27 @@ schedule_remove(void (*callback)(void *p), void *p) nsgtk_schedule_kill_callback, &cb_match); } -void -schedule(int t, void (*callback)(void *p), void *p) +/* exported interface documented in gtk/schedule.h */ +nserror nsgtk_schedule(int t, void (*callback)(void *p), void *p) { - const int msec_timeout = t * 10; - _nsgtk_callback_t *cb = malloc(sizeof(_nsgtk_callback_t)); + _nsgtk_callback_t *cb; + /* Kill any pending schedule of this kind. */ schedule_remove(callback, p); + + if (t < 0) { + return NSERROR_OK; + } + + cb = malloc(sizeof(_nsgtk_callback_t)); cb->callback = callback; cb->context = p; cb->callback_killed = false; /* Prepend is faster right now. */ queued_callbacks = g_list_prepend(queued_callbacks, cb); - g_timeout_add(msec_timeout, nsgtk_schedule_generic_callback, cb); + g_timeout_add(t, nsgtk_schedule_generic_callback, cb); + + return NSERROR_OK; } bool diff --git a/gtk/schedule.h b/gtk/schedule.h index c63215e88..0a2d724d4 100644 --- a/gtk/schedule.h +++ b/gtk/schedule.h @@ -19,7 +19,8 @@ #ifndef NETSURF_GTK_CALLBACK_H #define NETSURF_GTK_CALLBACK_H 1 -typedef void (*gtk_callback)(void *p); +nserror nsgtk_schedule(int t, void (*callback)(void *p), void *p); + bool schedule_run(void); #endif /* NETSURF_GTK_CALLBACK_H */ -- cgit v1.2.3