diff options
Diffstat (limited to 'source/blender/windowmanager')
25 files changed, 199 insertions, 76 deletions
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 183b22c9791..e513c49c11b 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -181,7 +181,7 @@ if(WITH_INPUT_NDOF) add_definitions(-DWITH_INPUT_NDOF) endif() -if(WIN32) +if(WIN32 OR APPLE) if(WITH_INPUT_IME) add_definitions(-DWITH_INPUT_IME) endif() diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 319683c8d8e..1c994707ca9 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -31,6 +31,7 @@ /* dna-savable wmStructs here */ #include "BLI_compiler_attrs.h" +#include "BLI_sys_types.h" #include "DNA_windowmanager_types.h" #include "WM_keymap.h" @@ -617,9 +618,14 @@ void WM_operator_type_modal_from_exec_for_object_edit_coords(struct wmOperatorTy void WM_uilisttype_init(void); struct uiListType *WM_uilisttype_find(const char *idname, bool quiet); bool WM_uilisttype_add(struct uiListType *ult); -void WM_uilisttype_freelink(struct uiListType *ult); +void WM_uilisttype_remove_ptr(struct Main *bmain, struct uiListType *ult); void WM_uilisttype_free(void); +void WM_uilisttype_to_full_list_id(const struct uiListType *ult, + const char *list_id, + char r_full_list_id[]); +const char *WM_uilisttype_list_id_get(const struct uiListType *ult, struct uiList *list); + /* wm_menu_type.c */ void WM_menutype_init(void); struct MenuType *WM_menutype_find(const char *idname, bool quiet); @@ -961,7 +967,7 @@ bool WM_xr_session_state_controller_pose_rotation_get(const wmXrData *xr, /* wm_xr_actions.c */ /* XR action functions to be called pre-XR session start. - * Note: The "destroy" functions can also be called post-session start. */ + * NOTE: The "destroy" functions can also be called post-session start. */ bool WM_xr_action_set_create(wmXrData *xr, const char *action_set_name); void WM_xr_action_set_destroy(wmXrData *xr, const char *action_set_name); bool WM_xr_action_create(wmXrData *xr, @@ -1015,7 +1021,7 @@ bool WM_xr_action_state_get(const wmXrData *xr, bool WM_xr_haptic_action_apply(wmXrData *xr, const char *action_set_name, const char *action_name, - const long long *duration, + const int64_t *duration, const float *frequency, const float *amplitude); void WM_xr_haptic_action_stop(wmXrData *xr, const char *action_set_name, const char *action_name); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index e83e36d7a9b..2b48a5f6648 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -339,7 +339,7 @@ typedef struct wmNotifier { #define ND_RENDER_OPTIONS (4 << 16) #define ND_NODES (5 << 16) #define ND_SEQUENCER (6 << 16) -/* Note: If an object was added, removed, merged/joined, ..., it is not enough to notify with +/* NOTE: If an object was added, removed, merged/joined, ..., it is not enough to notify with * this. This affects the layer so also send a layer change notifier (e.g. ND_LAYER_CONTENT)! */ #define ND_OB_ACTIVE (7 << 16) /* See comment on ND_OB_ACTIVE. */ @@ -439,6 +439,13 @@ typedef struct wmNotifier { #define ND_SPACE_FILE_PREVIEW (21 << 16) #define ND_SPACE_SPREADSHEET (22 << 16) +/* NC_ASSET */ +/* Denotes that the AssetList is done reading some previews. NOT that the preview generation of + * assets is done. */ +#define ND_ASSET_LIST (1 << 16) +#define ND_ASSET_LIST_PREVIEW (2 << 16) +#define ND_ASSET_LIST_READING (3 << 16) + /* subtype, 256 entries too */ #define NOTE_SUBTYPE 0x0000FF00 @@ -908,7 +915,7 @@ typedef enum wmDragFlags { WM_DRAG_FREE_DATA = 1, } wmDragFlags; -/* note: structs need not exported? */ +/* NOTE: structs need not exported? */ typedef struct wmDragID { struct wmDragID *next, *prev; diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h index 9a993e1f8d7..1fbbec7f949 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h @@ -107,7 +107,7 @@ typedef enum eWM_GizmoFlagGroupTypeFlag { /** Mark gizmo-group as being 3D */ WM_GIZMOGROUPTYPE_3D = (1 << 0), /** Scale gizmos as 3D object that respects zoom (otherwise zoom independent draw size). - * note: currently only for 3D views, 2D support needs adding. */ + * NOTE: currently only for 3D views, 2D support needs adding. */ WM_GIZMOGROUPTYPE_SCALE = (1 << 1), /** Gizmos can be depth culled with scene objects (covered by other geometry - TODO) */ WM_GIZMOGROUPTYPE_DEPTH_3D = (1 << 2), @@ -445,7 +445,7 @@ typedef struct wmGizmoGroupType { /** Only for convenient removal. */ struct wmKeyConfig *keyconf; - /* Note: currently gizmo-group instances don't store properties, + /* NOTE: currently gizmo-group instances don't store properties, * they're kept in the tool properties. */ /** RNA for properties. */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index 062731dfb3d..213a3c2e342 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -981,10 +981,10 @@ void WM_gizmomaptype_group_unlink(bContext *C, WM_gizmomaptype_group_free(gzgt_ref); } - /* TODO(campbell): Gizmos may share keymaps, for now don't + /* TODO(campbell): Gizmos may share key-maps, for now don't * remove however we could flag them as temporary/owned by the gizmo. */ #if 0 - /* Note, we may want to keep this keymap for editing */ + /* NOTE: we may want to keep this key-map for editing. */ WM_keymap_remove(gzgt->keyconf, gzgt->keymap); #endif diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c index 6ebeb5a76b6..6a793d52f74 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group_type.c @@ -162,7 +162,7 @@ void WM_gizmo_group_type_free_ptr(wmGizmoGroupType *gzgt) gizmogrouptype_free(gzgt); - /* XXX, TODO, update the world! */ + /* XXX, TODO: update the world! */ } bool WM_gizmo_group_type_free(const char *idname) diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 2ffa04bd8ae..6a328679c2e 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -264,7 +264,7 @@ bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, } bool ok = false; - BLI_assert(!"TODO"); + BLI_assert_msg(0, "TODO"); return ok; } @@ -918,7 +918,7 @@ static bool wm_gizmomap_select_all_intern(bContext *C, wmGizmoMap *gzmap) * Select/Deselect all selectable gizmos in \a gzmap. * \return if selection has changed. * - * TODO select all by type + * TODO: select all by type. */ bool WM_gizmomap_select_all(bContext *C, wmGizmoMap *gzmap, const int action) { diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 6dd3e4186c4..9657f8aa03c 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -168,7 +168,7 @@ static void window_manager_blend_read_data(BlendDataReader *reader, ID *id) win->eventstate = NULL; win->cursor_keymap_status = NULL; win->tweak = NULL; -#ifdef WIN32 +#if defined(WIN32) || defined(__APPLE__) win->ime_data = NULL; #endif @@ -516,7 +516,7 @@ void WM_check(bContext *C) } /* Case: fileread. */ - /* Note: this runs in background mode to set the screen context cb. */ + /* NOTE: this runs in background mode to set the screen context cb. */ if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) { ED_screens_init(bmain, wm); wm->initialized |= WM_WINDOW_IS_INIT; diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c index 11783ae3517..50d3a856cbe 100644 --- a/source/blender/windowmanager/intern/wm_cursors.c +++ b/source/blender/windowmanager/intern/wm_cursors.c @@ -124,14 +124,14 @@ static void window_set_custom_cursor( wmWindow *win, const uchar mask[16][2], const uchar bitmap[16][2], int hotx, int hoty) { GHOST_SetCustomCursorShape( - win->ghostwin, (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 16, 16, hotx, hoty, true); + win->ghostwin, (uint8_t *)bitmap, (uint8_t *)mask, 16, 16, hotx, hoty, true); } static void window_set_custom_cursor_ex(wmWindow *win, BCursor *cursor) { GHOST_SetCustomCursorShape(win->ghostwin, - (GHOST_TUns8 *)cursor->bitmap, - (GHOST_TUns8 *)cursor->mask, + (uint8_t *)cursor->bitmap, + (uint8_t *)cursor->mask, 16, 16, cursor->hotx, @@ -163,7 +163,7 @@ void WM_cursor_set(wmWindow *win, int curs) win->cursor = curs; if (curs < 0 || curs >= WM_CURSOR_NUM) { - BLI_assert(!"Invalid cursor number"); + BLI_assert_msg(0, "Invalid cursor number"); return; } @@ -301,7 +301,7 @@ void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2]) static void wm_cursor_warp_relative(wmWindow *win, int x, int y) { - /* note: don't use wmEvent coords because of continuous grab T36409. */ + /* NOTE: don't use wmEvent coords because of continuous grab T36409. */ int cx, cy; wm_cursor_position_get(win, &cx, &cy); WM_cursor_warp(win, cx + x, cy + y); diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index e899cbb22b9..da40040ce56 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -144,7 +144,7 @@ wmDrag *WM_event_start_drag( wmWindowManager *wm = CTX_wm_manager(C); wmDrag *drag = MEM_callocN(sizeof(struct wmDrag), "new drag"); - /* keep track of future multitouch drag too, add a mousepointer id or so */ + /* Keep track of future multi-touch drag too, add a mouse-pointer id or so. */ /* if multiple drags are added, they're drawn as list */ BLI_addtail(&wm->drags, drag); @@ -321,7 +321,7 @@ void WM_drag_add_local_ID(wmDrag *drag, ID *id, ID *from_parent) return; } if (GS(drag_id->id->name) != GS(id->name)) { - BLI_assert(!"All dragged IDs must have the same type"); + BLI_assert_msg(0, "All dragged IDs must have the same type"); return; } } diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 0922aaaee53..f01e28f8822 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -457,6 +457,7 @@ static void wm_draw_region_buffer_create(ARegion *region, bool stereo, bool use_ GPUOffScreen *offscreen = GPU_offscreen_create( region->winx, region->winy, false, false, NULL); if (!offscreen) { + WM_report(RPT_ERROR, "Region could not be drawn!"); return; } diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index 905b0f7b128..e7603a02cff 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -484,7 +484,10 @@ int WM_event_absolute_delta_y(const struct wmEvent *event) * \{ */ #ifdef WITH_INPUT_IME -/* most os using ctrl/oskey + space to switch ime, avoid added space */ +/** + * Most OS's use `Ctrl+Space` / `OsKey+Space` to switch IME, + * so don't type in the space character. + */ bool WM_event_is_ime_switch(const struct wmEvent *event) { return event->val == KM_PRESS && event->type == EVT_SPACEKEY && diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index b82b3c1ff5d..5e29a22304c 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -61,6 +61,7 @@ #include "BLT_translation.h" +#include "ED_asset.h" #include "ED_fileselect.h" #include "ED_info.h" #include "ED_screen.h" @@ -129,7 +130,7 @@ wmEvent *wm_event_add_ex(wmWindow *win, BLI_addtail(&win->event_queue, event); } else { - /* Note: strictly speaking this breaks const-correctness, + /* NOTE: strictly speaking this breaks const-correctness, * however we're only changing 'next' member. */ BLI_insertlinkafter(&win->event_queue, (void *)event_to_add_after, event); } @@ -189,7 +190,7 @@ void wm_event_free(wmEvent *event) if (event->customdata) { if (event->customdatafree) { - /* Note: pointer to listbase struct elsewhere. */ + /* NOTE: pointer to listbase struct elsewhere. */ if (event->custom == EVT_DATA_DRAGDROP) { ListBase *lb = event->customdata; WM_drag_free_list(lb); @@ -326,6 +327,7 @@ void WM_main_remap_editor_id_reference(ID *old_id, ID *new_id) } } } + ED_assetlist_storage_id_remap(old_id, new_id); wmWindowManager *wm = bmain->wm.first; if (wm && wm->message_bus) { @@ -627,7 +629,7 @@ void wm_event_do_notifiers(bContext *C) CTX_wm_window_set(C, NULL); } - /* Autorun warning */ + /* Auto-run warning. */ wm_test_autorun_warning(C); } @@ -915,7 +917,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, bool ca { if (G.background == 0 && caller_owns_reports == false) { /* popup */ if (op->reports->list.first) { - /* FIXME, temp setting window, see other call to UI_popup_menu_reports for why. */ + /* FIXME: temp setting window, see other call to #UI_popup_menu_reports for why. */ wmWindow *win_prev = CTX_wm_window(C); ScrArea *area_prev = CTX_wm_area(C); ARegion *region_prev = CTX_wm_region(C); @@ -1370,7 +1372,7 @@ static int wm_operator_invoke(bContext *C, CLOG_ERROR(WM_LOG_OPERATORS, "invalid operator call '%s'", op->idname); } - /* Note, if the report is given as an argument then assume the caller will deal with displaying + /* NOTE: if the report is given as an argument then assume the caller will deal with displaying * them currently Python only uses this. */ if (!(retval & OPERATOR_HANDLED) && (retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED))) { /* Only show the report if the report list was not given in the function. */ @@ -2379,9 +2381,9 @@ static int wm_handler_fileselect_do(bContext *C, if (handler->op->reports->list.first) { - /* FIXME, temp setting window, this is really bad! + /* FIXME(campbell): temp setting window, this is really bad! * only have because lib linking errors need to be seen by users :( - * it can be removed without breaking anything but then no linking errors - campbell */ + * it can be removed without breaking anything but then no linking errors. */ wmWindow *win_prev = CTX_wm_window(C); ScrArea *area_prev = CTX_wm_area(C); ARegion *region_prev = CTX_wm_region(C); @@ -2393,7 +2395,7 @@ static int wm_handler_fileselect_do(bContext *C, BKE_report_print_level_set(handler->op->reports, RPT_WARNING); UI_popup_menu_reports(C, handler->op->reports); - /* XXX - copied from 'wm_operator_finished()' */ + /* XXX: copied from 'wm_operator_finished()'. */ /* add reports to the global list, otherwise they are not seen */ BLI_movelisttolist(&CTX_wm_reports(C)->list, &handler->op->reports->list); @@ -2796,7 +2798,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers /* Modal handlers can get removed in this loop, we keep the loop this way. * - * Note: check 'handlers->first' because in rare cases the handlers can be cleared + * NOTE: check 'handlers->first' because in rare cases the handlers can be cleared * by the event that's called, for eg: * * Calling a python script which changes the area.type, see T32232. */ @@ -3398,7 +3400,7 @@ void wm_event_do_handlers(bContext *C) wm_tweakevent_test(C, event, action); if ((action & WM_HANDLER_BREAK) == 0) { - /* Note: setting subwin active should be done here, after modal handlers have been done */ + /* NOTE: setting subwin active should be done here, after modal handlers have been done. */ if (event->type == MOUSEMOVE) { /* State variables in screen, cursors. * Also used in wm_draw.c, fails for modal handlers though. */ @@ -4011,7 +4013,7 @@ wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBase *handlers, ListBas return handler; } -/* XXX solution works, still better check the real cause (ton) */ +/* XXX(ton): solution works, still better check the real cause. */ void WM_event_remove_area_handler(ListBase *handlers, void *area) { LISTBASE_FOREACH_MUTABLE (wmEventHandler *, handler_base, handlers) { diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 6230b240d11..3633d3c07d3 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -844,7 +844,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* first try to append data from exotic file formats... */ /* it throws error box when file doesn't exist and returns -1 */ - /* note; it should set some error message somewhere... (ton) */ + /* NOTE(ton): it should set some error message somewhere. */ const int retval = wm_read_exotic(filepath); /* we didn't succeed, now try to read Blender file */ @@ -929,7 +929,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) } else { BKE_reportf(reports, RPT_ERROR, "Unknown error loading '%s'", filepath); - BLI_assert(!"invalid 'retval'"); + BLI_assert_msg(0, "invalid 'retval'"); } if (success == false) { @@ -1606,7 +1606,7 @@ static bool wm_file_write(bContext *C, return ok; } - /* note: used to replace the file extension (to ensure '.blend'), + /* NOTE: used to replace the file extension (to ensure '.blend'), * no need to now because the operator ensures, * its handy for scripts to save to a predefined name without blender editing it */ @@ -1645,13 +1645,13 @@ static bool wm_file_write(bContext *C, ED_editors_flush_edits(bmain); - /* first time saving */ - /* XXX temp solution to solve bug, real fix coming (ton) */ + /* First time saving. */ + /* XXX(ton): temp solution to solve bug, real fix coming. */ if ((BKE_main_blendfile_path(bmain)[0] == '\0') && (use_save_as_copy == false)) { BLI_strncpy(bmain->name, filepath, sizeof(bmain->name)); } - /* XXX temp solution to solve bug, real fix coming (ton) */ + /* XXX(ton): temp solution to solve bug, real fix coming. */ bmain->recovered = 0; if (BLO_write_file(CTX_data_main(C), diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c index 94535427dac..9da901d6c4e 100644 --- a/source/blender/windowmanager/intern/wm_gesture_ops.c +++ b/source/blender/windowmanager/intern/wm_gesture_ops.c @@ -447,7 +447,7 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event) #if 0 /* Allow view navigation??? */ - /* note, this gives issues: + /* NOTE: this gives issues: * 1) other modal ops run on top (box select), * 2) middle-mouse is used now 3) tablet/trackpad? */ else { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 48ab76317b5..d7ea47fc625 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -109,6 +109,7 @@ #include "ED_anim_api.h" #include "ED_armature.h" +#include "ED_asset.h" #include "ED_gpencil.h" #include "ED_keyframes_edit.h" #include "ED_keyframing.h" @@ -226,7 +227,7 @@ void WM_init(bContext *C, int argc, const char **argv) { if (!G.background) { - wm_ghost_init(C); /* note: it assigns C to ghost! */ + wm_ghost_init(C); /* NOTE: it assigns C to ghost! */ wm_init_cursor_data(); BKE_sound_jack_sync_callback_set(sound_jack_sync_callback); } @@ -327,13 +328,13 @@ void WM_init(bContext *C, int argc, const char **argv) ED_spacemacros_init(); - /* note: there is a bug where python needs initializing before loading the + /* NOTE(campbell): there is a bug where python needs initializing before loading the * startup.blend because it may contain PyDrivers. It also needs to be after * initializing space types and other internal data. * * However can't redo this at the moment. Solution is to load python * before wm_homefile_read() or make py-drivers check if python is running. - * Will try fix when the crash can be repeated. - campbell. */ + * Will try fix when the crash can be repeated. */ #ifdef WITH_PYTHON BPY_python_start(C, argc, argv); @@ -376,7 +377,7 @@ void WM_init(bContext *C, int argc, const char **argv) { Main *bmain = CTX_data_main(C); - /* note, logic here is from wm_file_read_post, + /* NOTE: logic here is from wm_file_read_post, * call functions that depend on Python being initialized. */ /* normally 'wm_homefile_read' will do this, @@ -481,7 +482,7 @@ void WM_exit_ex(bContext *C, const bool do_python) /* first wrap up running stuff, we assume only the active WM is running */ /* modal handlers are on window level freed, others too? */ - /* note; same code copied in wm_files.c */ + /* NOTE: same code copied in `wm_files.c`. */ if (C && wm) { if (!G.background) { struct MemFile *undo_memfile = wm->undo_stack ? @@ -552,7 +553,6 @@ void WM_exit_ex(bContext *C, const bool do_python) wm_surfaces_free(); wm_dropbox_free(); WM_menutype_free(); - WM_uilisttype_free(); /* all non-screen and non-space stuff editors did, like editmode */ if (C) { @@ -571,6 +571,7 @@ void WM_exit_ex(bContext *C, const bool do_python) RE_engines_exit(); ED_preview_free_dbase(); /* frees a Main dbase, before BKE_blender_free! */ + ED_assetlist_storage_exit(); if (wm) { /* Before BKE_blender_free! - since the ListBases get freed there. */ @@ -607,6 +608,8 @@ void WM_exit_ex(bContext *C, const bool do_python) wm_gizmomaptypes_free(); wm_gizmogrouptype_free(); wm_gizmotype_free(); + /* Same for UI-list types. */ + WM_uilisttype_free(); BLF_exit(); diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 69b3660038d..25bcf1967ea 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -135,7 +135,7 @@ static void wm_keymap_item_properties_update_ot(wmKeyMapItem *kmi) /* matches wm_keymap_item_properties_set but doesn't alloc new ptr */ WM_operator_properties_create_ptr(kmi->ptr, ot); /* 'kmi->ptr->data' NULL'd above, keep using existing properties. - * Note: the operators property types may have changed, + * NOTE: the operators property types may have changed, * we will need a more comprehensive sanitize function to support this properly. */ if (kmi->properties) { @@ -971,7 +971,7 @@ static const wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(const wmKeyMap *km } } else { - BLI_assert(!"called with non modal keymap"); + BLI_assert_msg(0, "called with non modal keymap"); } return NULL; diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index ba236988c1d..898671706d1 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -133,7 +133,7 @@ void WM_operator_properties_filesel(wmOperatorType *ot, } if (action == FILE_SAVE) { - /* note, this is only used to check if we should highlight the filename area red when the + /* NOTE: this is only used to check if we should highlight the filename area red when the * filepath is an existing file. */ prop = RNA_def_boolean(ot->srna, "check_existing", @@ -198,7 +198,7 @@ void WM_operator_properties_filesel(wmOperatorType *ot, ot->srna, "filter_blenlib", (filter & FILE_TYPE_BLENDERLIB) != 0, "Filter Blender IDs", ""); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); - /* TODO asset only filter? */ + /* TODO: asset only filter? */ prop = RNA_def_int( ot->srna, diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index a2d783afc32..576f15731a0 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -126,8 +126,8 @@ void WM_operator_py_idname(char *to, const char *from) if (sep) { int ofs = (sep - from); - /* note, we use ascii tolower instead of system tolower, because the - * latter depends on the locale, and can lead to idname mismatch */ + /* NOTE: we use ascii `tolower` instead of system `tolower`, because the + * latter depends on the locale, and can lead to `idname` mismatch. */ memcpy(to, from, sizeof(char) * ofs); BLI_str_tolower_ascii(to, ofs); @@ -604,6 +604,12 @@ void WM_operator_properties_create(PointerRNA *ptr, const char *opstring) * used for keymaps and macros */ void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring) { + IDProperty *tmp_properties = NULL; + /* Allow passing NULL for properties, just create the properties here then. */ + if (properties == NULL) { + properties = &tmp_properties; + } + if (*properties == NULL) { IDPropertyTemplate val = {0}; *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp"); @@ -745,7 +751,7 @@ static bool operator_last_properties_init_impl(wmOperator *op, IDProperty *last_ if (idp_src) { IDProperty *idp_dst = IDP_CopyProperty(idp_src); - /* note - in the future this may need to be done recursively, + /* NOTE: in the future this may need to be done recursively, * but for now RNA doesn't access nested operators */ idp_dst->flag |= IDP_FLAG_GHOST; @@ -1156,7 +1162,7 @@ bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFor RNA_property_string_get(op->ptr, prop, filepath); if (BKE_image_path_ensure_ext_from_imformat(filepath, im_format)) { RNA_property_string_set(op->ptr, prop, filepath); - /* note, we could check for and update 'filename' here, + /* NOTE: we could check for and update 'filename' here, * but so far nothing needs this. */ return true; } @@ -2361,7 +2367,7 @@ static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void strdrawlen = BLI_strlen_utf8(str); break; default: - tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE; /* note, this is a dummy value */ + tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE; /* NOTE: this is a dummy value. */ alpha = 0.75; break; } @@ -3202,7 +3208,7 @@ static void redraw_timer_step(bContext *C, int tot = (scene->r.efra - scene->r.sfra) + 1; while (tot--) { - /* todo, ability to escape! */ + /* TODO: ability to escape! */ scene->r.cfra++; if (scene->r.cfra > scene->r.efra) { scene->r.cfra = scene->r.sfra; diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 5300649a0cd..fa21dbcb4bb 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -220,7 +220,7 @@ static void playanim_window_get_size(int *r_width, int *r_height) static void playanim_gl_matrix(void) { /* unified matrix, note it affects offset for drawing */ - /* note! cannot use GPU_matrix_ortho_2d_set here because shader ignores. */ + /* NOTE: cannot use GPU_matrix_ortho_2d_set here because shader ignores. */ GPU_matrix_ortho_set(0.0f, 1.0f, 0.0f, 1.0f, -1.0, 1.0f); } @@ -1114,7 +1114,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) #ifdef WITH_AUDASPACE { PlayAnimPict *picture = picsbase.first; - /* TODO - store in ps direct? */ + /* TODO: store in ps direct? */ int i = 0; while (picture && picture != ps->picture) { @@ -1151,7 +1151,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) #ifdef WITH_AUDASPACE { PlayAnimPict *picture = picsbase.first; - /* TODO - store in ps direct? */ + /* TODO: store in ps direct? */ int i = 0; while (picture && picture != ps->picture) { i++; @@ -1357,7 +1357,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) static void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey) { GHOST_GLSettings glsettings = {0}; - GHOST_TUns32 scr_w, scr_h; + uint32_t scr_w, scr_h; GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &scr_w, &scr_h); @@ -1405,7 +1405,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv) { struct ImBuf *ibuf = NULL; static char filepath[FILE_MAX]; /* abused to return dropped file path */ - GHOST_TUns32 maxwinx, maxwiny; + uint32_t maxwinx, maxwiny; int i; /* This was done to disambiguate the name for use under c++. */ int start_x = 0, start_y = 0; diff --git a/source/blender/windowmanager/intern/wm_splash_screen.c b/source/blender/windowmanager/intern/wm_splash_screen.c index ae726e73fe7..f5881a00998 100644 --- a/source/blender/windowmanager/intern/wm_splash_screen.c +++ b/source/blender/windowmanager/intern/wm_splash_screen.c @@ -112,7 +112,7 @@ static void wm_block_splash_image_roundcorners_add(ImBuf *ibuf) const float distance = sqrt(u * u + v * v); /* Pointer offset to the alpha value of pixel. */ - /* Note, the left corner is flipped in the X-axis. */ + /* NOTE: the left corner is flipped in the X-axis. */ const int offset_l = 4 * (size - x - x - 1) + 3; const int offset_r = 4 * (ibuf->x - size) + 3; diff --git a/source/blender/windowmanager/intern/wm_uilist_type.c b/source/blender/windowmanager/intern/wm_uilist_type.c index 45c14c0bbe9..82ba4aa6e6f 100644 --- a/source/blender/windowmanager/intern/wm_uilist_type.c +++ b/source/blender/windowmanager/intern/wm_uilist_type.c @@ -21,16 +21,24 @@ */ #include <stdio.h> +#include <string.h> +#include "BLI_listbase.h" #include "BLI_sys_types.h" +#include "DNA_space_types.h" #include "DNA_windowmanager_types.h" #include "MEM_guardedalloc.h" +#include "UI_interface.h" + #include "BLI_ghash.h" +#include "BLI_listbase.h" +#include "BLI_string.h" #include "BLI_utildefines.h" +#include "BKE_main.h" #include "BKE_screen.h" #include "WM_api.h" @@ -60,8 +68,62 @@ bool WM_uilisttype_add(uiListType *ult) return 1; } -void WM_uilisttype_freelink(uiListType *ult) +static void wm_uilisttype_unlink_from_region(const uiListType *ult, ARegion *region) { + LISTBASE_FOREACH (uiList *, list, ®ion->ui_lists) { + if (list->type == ult) { + /* Don't delete the list, it's not just runtime data but stored in files. Freeing would make + * that data get lost. */ + list->type = NULL; + } + } +} + +static void wm_uilisttype_unlink_from_area(const uiListType *ult, ScrArea *area) +{ + LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) { + ListBase *regionbase = (space_link == area->spacedata.first) ? &area->regionbase : + &space_link->regionbase; + LISTBASE_FOREACH (ARegion *, region, regionbase) { + wm_uilisttype_unlink_from_region(ult, region); + } + } +} + +/** + * For all lists representing \a ult, clear their `uiListType` pointer. Use when a list-type is + * deleted, so that the UI doesn't keep references to it. + * + * This is a common pattern for unregistering (usually .py defined) types at runtime, e.g. see + * #WM_gizmomaptype_group_unlink(). + * Note that unlike in some other cases using this pattern, we don't actually free the lists with + * type \a ult, we just clear the reference to the type. That's because UI-Lists are written to + * files and we don't want them to get lost together with their (user visible) settings. + */ +static void wm_uilisttype_unlink(Main *bmain, const uiListType *ult) +{ + for (wmWindowManager *wm = bmain->wm.first; wm != NULL; wm = wm->id.next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { + LISTBASE_FOREACH (ScrArea *, global_area, &win->global_areas.areabase) { + wm_uilisttype_unlink_from_area(ult, global_area); + } + } + } + + for (bScreen *screen = bmain->screens.first; screen != NULL; screen = screen->id.next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + wm_uilisttype_unlink_from_area(ult, area); + } + + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { + wm_uilisttype_unlink_from_region(ult, region); + } + } +} + +void WM_uilisttype_remove_ptr(Main *bmain, uiListType *ult) +{ + wm_uilisttype_unlink(bmain, ult); bool ok = BLI_ghash_remove(uilisttypes_hash, ult->idname, NULL, MEM_freeN); @@ -88,3 +150,34 @@ void WM_uilisttype_free(void) BLI_ghash_free(uilisttypes_hash, NULL, MEM_freeN); uilisttypes_hash = NULL; } + +/** + * The "full" list-ID is an internal name used for storing and identifying a list. It is built like + * this: + * "{uiListType.idname}_{list_id}", whereby "list_id" is an optional parameter passed to + * `UILayout.template_list()`. If it is not set, the full list-ID is just "{uiListType.idname}_". + * + * Note that whenever the Python API refers to the list-ID, it's the short, "non-full" one it + * passed to `UILayout.template_list()`. C code can query that through + * #WM_uilisttype_list_id_get(). + */ +void WM_uilisttype_to_full_list_id(const uiListType *ult, + const char *list_id, + char r_full_list_id[/*UI_MAX_NAME_STR*/]) +{ + /* We tag the list id with the list type... */ + BLI_snprintf(r_full_list_id, UI_MAX_NAME_STR, "%s_%s", ult->idname, list_id ? list_id : ""); +} + +/** + * Get the "non-full" list-ID, see #WM_uilisttype_to_full_list_id() for details. + * + * \note Assumes `uiList.list_id` was set using #WM_uilisttype_to_full_list_id()! + */ +const char *WM_uilisttype_list_id_get(const uiListType *ult, uiList *list) +{ + /* Some sanity check for the assumed behavior of #WM_uilisttype_to_full_list_id(). */ + BLI_assert((list->list_id + strlen(ult->idname))[0] == '_'); + /* +1 to skip the '_' */ + return list->list_id + strlen(ult->idname) + 1; +} diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 8f8577e2616..1b08b8dad92 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -462,7 +462,7 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win) /* Informs GHOST of unsaved changes, to set window modified visual indicator (macOS) * and to give hint of unsaved changes for a user warning mechanism in case of OS application * terminate request (e.g. OS Shortcut Alt+F4, Command+Q, (...), or session end). */ - GHOST_SetWindowModifiedState(win->ghostwin, (GHOST_TUns8)!wm->file_saved); + GHOST_SetWindowModifiedState(win->ghostwin, (bool)!wm->file_saved); } } @@ -1136,14 +1136,12 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr return 1; } if (!ghostwin) { - /* XXX - should be checked, why are we getting an event here, and */ - /* what is it? */ + /* XXX: should be checked, why are we getting an event here, and what is it? */ puts("<!> event has no window"); return 1; } if (!GHOST_ValidWindow(g_system, ghostwin)) { - /* XXX - should be checked, why are we getting an event here, and */ - /* what is it? */ + /* XXX: should be checked, why are we getting an event here, and what is it? */ puts("<!> event has invalid window"); return 1; } @@ -1724,7 +1722,7 @@ static char *wm_clipboard_text_get_ex(bool selection, int *r_len, bool firstline return NULL; } - char *buf = (char *)GHOST_getClipboard(selection); + char *buf = GHOST_getClipboard(selection); if (!buf) { *r_len = 0; return NULL; @@ -1811,10 +1809,10 @@ void WM_clipboard_text_set(const char *buf, bool selection) } *p2 = '\0'; - GHOST_putClipboard((GHOST_TInt8 *)newbuf, selection); + GHOST_putClipboard(newbuf, selection); MEM_freeN(newbuf); #else - GHOST_putClipboard((GHOST_TInt8 *)buf, selection); + GHOST_putClipboard(buf, selection); #endif } } @@ -2405,6 +2403,10 @@ void wm_window_IME_begin(wmWindow *win, int x, int y, int w, int h, bool complet { BLI_assert(win); + /* Convert to native OS window coordinates. */ + float fac = GHOST_GetNativePixelSize(win->ghostwin); + x /= fac; + y /= fac; GHOST_BeginIME(win->ghostwin, x, win->sizey - y, w, h, complete); } diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index ccb6e47e7e3..c21bebe8062 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -352,8 +352,8 @@ enum { /* for event checks */ /* only used for KM_TEXTINPUT, so assume that we want all user-inputtable ascii codes included */ /* UNUSED - see wm_eventmatch - BUG T30479. */ -/* #define ISTEXTINPUT(event_type) ((event_type) >= ' ' && (event_type) <= 255) */ -/* note, an alternative could be to check 'event->utf8_buf' */ +// #define ISTEXTINPUT(event_type) ((event_type) >= ' ' && (event_type) <= 255) +/* NOTE: an alternative could be to check `event->utf8_buf`. */ /* test whether the event is a key on the keyboard */ #define ISKEYBOARD(event_type) \ @@ -439,7 +439,7 @@ bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask ma /* Gestures */ /* NOTE: these values are saved in keymap files, do not change them but just add new ones */ enum { - /* value of tweaks and line gestures, note, KM_ANY (-1) works for this case too */ + /* Value of tweaks and line gestures. #KM_ANY (-1) works for this case too. */ EVT_GESTURE_N = 1, EVT_GESTURE_NE = 2, EVT_GESTURE_E = 3, diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actions.c b/source/blender/windowmanager/xr/intern/wm_xr_actions.c index 51ed3dcfd3c..7eabd29baa0 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_actions.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_actions.c @@ -462,7 +462,7 @@ bool WM_xr_action_state_get(const wmXrData *xr, bool WM_xr_haptic_action_apply(wmXrData *xr, const char *action_set_name, const char *action_name, - const long long *duration, + const int64_t *duration, const float *frequency, const float *amplitude) { |