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).
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user