[Bf-blender-cvs] [10dbe96] master: Add WM_event_add/remove_timer_notifier() helpers.

Bastien Montagne noreply at git.blender.org
Tue Aug 11 12:16:18 CEST 2015


Commit: 10dbe966e120632efaae4cbd5c1336fc163e5c07
Author: Bastien Montagne
Date:   Tue Aug 11 12:11:48 2015 +0200
Branches: master
https://developer.blender.org/rB10dbe966e120632efaae4cbd5c1336fc163e5c07

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).

===================================================================

M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_window.c
M	source/blender/windowmanager/wm_event_types.h

===================================================================

diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 28e24e4..2742657 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 c538724..d0ecec6 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 ecc29de..390e769 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 */




More information about the Bf-blender-cvs mailing list