From 10dbe966e120632efaae4cbd5c1336fc163e5c07 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 11 Aug 2015 12:11:48 +0200 Subject: Add WM_event_add/remove_timer_notifier() helpers. This basically does the 'timer' part of Jobs system: it sends a given notifier on every timer step. This is needed for background tasks (not full-fledged jobs, lighter BLI_tasks based) that want to update UI (like for up-comming new thumbnail handling in filebrowser). --- source/blender/windowmanager/WM_api.h | 2 ++ source/blender/windowmanager/intern/wm_window.c | 25 +++++++++++++++++++++++++ source/blender/windowmanager/wm_event_types.h | 1 + 3 files changed, 28 insertions(+) (limited to 'source/blender') diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 28e24e442ca..274265773a4 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -208,7 +208,9 @@ void wm_event_init_from_window(struct wmWindow *win, struct wmEvent *event); /* at maximum, every timestep seconds it triggers event_type events */ struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep); +struct wmTimer *WM_event_add_timer_notifier(struct wmWindowManager *wm, struct wmWindow *win, unsigned int type, double timestep); void WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer); +void WM_event_remove_timer_notifier(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer); void WM_event_timer_sleep(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer, bool do_sleep); /* operator api, default callbacks */ diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index c5387242206..d0ecec66d0b 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1166,6 +1166,8 @@ static int wm_window_timer(const bContext *C) wm_jobs_timer(C, wm, wt); else if (wt->event_type == TIMERAUTOSAVE) wm_autosave_timer(C, wm, wt); + else if (wt->event_type == TIMERNOTIFIER) + WM_main_add_notifier(GET_UINT_FROM_POINTER(wt->customdata), NULL); else if (win) { wmEvent event; wm_event_init_from_window(win, &event); @@ -1285,6 +1287,23 @@ wmTimer *WM_event_add_timer(wmWindowManager *wm, wmWindow *win, int event_type, return wt; } +wmTimer *WM_event_add_timer_notifier(wmWindowManager *wm, wmWindow *win, unsigned int type, double timestep) +{ + wmTimer *wt = MEM_callocN(sizeof(wmTimer), "window timer"); + + wt->event_type = TIMERNOTIFIER; + wt->ltime = PIL_check_seconds_timer(); + wt->ntime = wt->ltime + timestep; + wt->stime = wt->ltime; + wt->timestep = timestep; + wt->win = win; + wt->customdata = SET_UINT_IN_POINTER(type); + + BLI_addtail(&wm->timers, wt); + + return wt; +} + void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *timer) { wmTimer *wt; @@ -1317,6 +1336,12 @@ void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer * } } +void WM_event_remove_timer_notifier(wmWindowManager *wm, wmWindow *win, wmTimer *timer) +{ + timer->customdata = NULL; + WM_event_remove_timer(wm, win, timer); +} + /* ******************* clipboard **************** */ static char *wm_clipboard_text_get_ex(bool selection, int *r_len, diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index ecc29de0e7d..390e769aa88 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -303,6 +303,7 @@ enum { TIMERAUTOSAVE = 0x0115, /* timer event, autosave */ TIMERREPORT = 0x0116, /* timer event, reports */ TIMERREGION = 0x0117, /* timer event, region slide in/out */ + TIMERNOTIFIER = 0x0118, /* timer event, notifier sender */ TIMERF = 0x011F, /* last timer */ /* Tweak, gestures: 0x500x, 0x501x */ -- cgit v1.2.3