diff options
author | Campbell Barton <campbell@blender.org> | 2022-11-05 06:14:39 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-11-05 06:14:39 +0300 |
commit | b3e1540c5048193bdcaa0dd4a3f1e04edee35819 (patch) | |
tree | 158ed58a2be79bd3ab13516a9592c5efeae2e4e6 /source/blender | |
parent | ae3073323e92a1773fb253bd1c5d6c92b826e1e0 (diff) |
Cleanup: use bools and typed enums for WM_job type & flag
Also use typed enum for the event handler flag.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface_panel.cc | 10 | ||||
-rw-r--r-- | source/blender/editors/render/render_preview.cc | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 36 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.cc | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_jobs.c | 15 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_system.h | 8 |
6 files changed, 42 insertions, 32 deletions
diff --git a/source/blender/editors/interface/interface_panel.cc b/source/blender/editors/interface/interface_panel.cc index 24d8281aad8..05b6ecf29d5 100644 --- a/source/blender/editors/interface/interface_panel.cc +++ b/source/blender/editors/interface/interface_panel.cc @@ -2026,7 +2026,7 @@ static void ui_panel_drag_collapse_handler_add(const bContext *C, const bool was ui_panel_drag_collapse_handler, ui_panel_drag_collapse_handler_remove, dragcol_data, - 0); + eWM_EventHandlerFlag(0)); } /** @@ -2510,8 +2510,12 @@ static void panel_handle_data_ensure(const bContext *C, { if (panel->activedata == nullptr) { panel->activedata = MEM_callocN(sizeof(uiHandlePanelData), __func__); - WM_event_add_ui_handler( - C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, 0); + WM_event_add_ui_handler(C, + &win->modalhandlers, + ui_handler_panel, + ui_handler_remove_panel, + panel, + eWM_EventHandlerFlag(0)); } uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata); diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 3a25bb0de0c..8e50e8c04d1 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -1755,7 +1755,8 @@ PreviewLoadJob::~PreviewLoadJob() PreviewLoadJob &PreviewLoadJob::ensure_job(wmWindowManager *wm, wmWindow *win) { - wmJob *wm_job = WM_jobs_get(wm, win, nullptr, "Load Previews", 0, WM_JOB_TYPE_LOAD_PREVIEW); + wmJob *wm_job = WM_jobs_get( + wm, win, nullptr, "Load Previews", eWM_JobFlag(0), WM_JOB_TYPE_LOAD_PREVIEW); if (!WM_jobs_is_running(wm_job)) { PreviewLoadJob *job_data = MEM_new<PreviewLoadJob>("PreviewLoadJobData"); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 37068c13993..329e22c156a 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -341,6 +341,18 @@ void WM_cursor_warp(struct wmWindow *win, int x, int y); /* Handlers. */ +typedef enum eWM_EventHandlerFlag { + /** After this handler all others are ignored. */ + WM_HANDLER_BLOCKING = (1 << 0), + /** Handler accepts double key press events. */ + WM_HANDLER_ACCEPT_DBL_CLICK = (1 << 1), + + /* Internal. */ + /** Handler tagged to be freed in #wm_handlers_do(). */ + WM_HANDLER_DO_FREE = (1 << 7), +} eWM_EventHandlerFlag; +ENUM_OPERATORS(eWM_EventHandlerFlag, WM_HANDLER_DO_FREE) + typedef bool (*EventHandlerPoll)(const ARegion *region, const struct wmEvent *event); struct wmEventHandler_Keymap *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap); struct wmEventHandler_Keymap *WM_event_add_keymap_handler_poll(ListBase *handlers, @@ -407,7 +419,7 @@ struct wmEventHandler_UI *WM_event_add_ui_handler(const struct bContext *C, wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn, void *user_data, - char flag); + eWM_EventHandlerFlag flag); /** * Return the first modal operator of type \a ot or NULL. @@ -450,15 +462,6 @@ void WM_event_modal_handler_region_replace(wmWindow *win, */ void WM_event_remove_handlers(struct bContext *C, ListBase *handlers); -/* handler flag */ -enum { - WM_HANDLER_BLOCKING = (1 << 0), /* after this handler all others are ignored */ - WM_HANDLER_ACCEPT_DBL_CLICK = (1 << 1), /* handler accepts double key press events */ - - /* internal */ - WM_HANDLER_DO_FREE = (1 << 7), /* handler tagged to be freed in wm_handlers_do() */ -}; - struct wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes); @@ -1355,17 +1358,18 @@ void wmOrtho2_pixelspace(float x, float y); void wmGetProjectionMatrix(float mat[4][4], const struct rcti *winrct); /* threaded Jobs Manager */ -enum { +typedef enum eWM_JobFlag { WM_JOB_PRIORITY = (1 << 0), WM_JOB_EXCL_RENDER = (1 << 1), WM_JOB_PROGRESS = (1 << 2), -}; +} eWM_JobFlag; +ENUM_OPERATORS(enum eWM_JobFlag, WM_JOB_PROGRESS); /** * Identifying jobs by owner alone is unreliable, this isn't saved, * order can change (keep 0 for 'any'). */ -enum { +typedef enum eWM_JobType { WM_JOB_TYPE_ANY = 0, WM_JOB_TYPE_COMPOSITE, WM_JOB_TYPE_RENDER, @@ -1397,7 +1401,7 @@ enum { WM_JOB_TYPE_SEQ_DRAG_DROP_PREVIEW, /* add as needed, bake, seq proxy build * if having hard coded values is a problem */ -}; +} eWM_JobType; /** * \return current job or adds new job, but doesn't run it. @@ -1409,8 +1413,8 @@ struct wmJob *WM_jobs_get(struct wmWindowManager *wm, struct wmWindow *win, const void *owner, const char *name, - int flag, - int job_type); + eWM_JobFlag flag, + eWM_JobType job_type); /** * Returns true if job runs, for UI (progress) indicators. diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 181ec89cabd..c84df617f98 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -4535,7 +4535,7 @@ wmEventHandler_UI *WM_event_add_ui_handler(const bContext *C, wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn, void *user_data, - const char flag) + const eWM_EventHandlerFlag flag) { wmEventHandler_UI *handler = MEM_cnew<wmEventHandler_UI>(__func__); handler->head.type = WM_HANDLER_TYPE_UI; diff --git a/source/blender/windowmanager/intern/wm_jobs.c b/source/blender/windowmanager/intern/wm_jobs.c index 5d540c9c251..fcfc83312b8 100644 --- a/source/blender/windowmanager/intern/wm_jobs.c +++ b/source/blender/windowmanager/intern/wm_jobs.c @@ -108,8 +108,9 @@ struct wmJob { /* internal */ const void *owner; - int flag; - short suspended, running, ready, job_type; + eWM_JobFlag flag; + bool suspended, running, ready; + eWM_JobType job_type; bool do_update, stop; float progress; @@ -153,9 +154,9 @@ static void wm_job_main_thread_yield(wmJob *wm_job) /** * Finds if type or owner, compare for it, otherwise any matching job. */ -static wmJob *wm_job_find(const wmWindowManager *wm, const void *owner, const int job_type) +static wmJob *wm_job_find(const wmWindowManager *wm, const void *owner, const eWM_JobType job_type) { - if (owner && job_type) { + if (owner && (job_type != WM_JOB_TYPE_ANY)) { LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->owner == owner && wm_job->job_type == job_type) { return wm_job; @@ -169,7 +170,7 @@ static wmJob *wm_job_find(const wmWindowManager *wm, const void *owner, const in } } } - else if (job_type) { + else if (job_type != WM_JOB_TYPE_ANY) { LISTBASE_FOREACH (wmJob *, wm_job, &wm->jobs) { if (wm_job->job_type == job_type) { return wm_job; @@ -186,8 +187,8 @@ wmJob *WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, - int flag, - int job_type) + const eWM_JobFlag flag, + const eWM_JobType job_type) { wmJob *wm_job = wm_job_find(wm, owner, job_type); diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h index edbfe0202de..f49be20e174 100644 --- a/source/blender/windowmanager/wm_event_system.h +++ b/source/blender/windowmanager/wm_event_system.h @@ -29,21 +29,21 @@ extern "C" { /* wmKeyMap is in DNA_windowmanager.h, it's saveable */ /** Custom types for handlers, for signaling, freeing */ -enum eWM_EventHandlerType { +typedef enum eWM_EventHandlerType { WM_HANDLER_TYPE_GIZMO = 1, WM_HANDLER_TYPE_UI, WM_HANDLER_TYPE_OP, WM_HANDLER_TYPE_DROPBOX, WM_HANDLER_TYPE_KEYMAP, -}; +} eWM_EventHandlerType; typedef bool (*EventHandlerPoll)(const ARegion *region, const wmEvent *event); typedef struct wmEventHandler { struct wmEventHandler *next, *prev; - enum eWM_EventHandlerType type; - char flag; /* WM_HANDLER_BLOCKING, ... */ + eWM_EventHandlerType type; + eWM_EventHandlerFlag flag; EventHandlerPoll poll; } wmEventHandler; |