Blender V5.3
wm_keymap.cc File Reference
#include <cstring>
#include <fmt/format.h>
#include <fmt/ranges.h>
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_workspace_types.h"
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.hh"
#include "BLI_string.hh"
#include "BLI_string_utf8.hh"
#include "BLI_utildefines.hh"
#include "BLI_vector.hh"
#include "BLF_api.hh"
#include "UI_interface.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_main.hh"
#include "BKE_report.hh"
#include "BKE_screen.hh"
#include "BKE_workspace.hh"
#include "BLT_translation.hh"
#include "RNA_access.hh"
#include "RNA_enum_types.hh"
#include "WM_api.hh"
#include "WM_keymap.hh"
#include "WM_types.hh"
#include "wm_event_system.hh"
#include "wm_event_types.hh"
#include "ED_screen.hh"

Go to the source code of this file.

Classes

struct  blender::wmKeyMapItemFind_Params

Namespaces

namespace  blender
 BMesh Iterators.

Functions

Keymap Item

Item in a keymap, that maps from an event to an operator or modal map item.

static wmKeyMapItem * blender::wm_keymap_item_copy (const wmKeyMapItem *kmi)
static void blender::wm_keymap_item_free_data (wmKeyMapItem *kmi)
static void blender::wm_keymap_item_clear_runtime (wmKeyMapItem *kmi)
static void blender::wm_keymap_item_properties_set (wmKeyMapItem *kmi)
static void blender::wm_keymap_item_properties_update_ot (wmKeyMapItem *kmi, const bool keep_properties)
static void blender::wm_keymap_item_properties_update_ot_from_list (ListBaseT< wmKeyMap > *km_lb, const bool keep_properties)
static bool blender::wm_keymap_item_equals_result (const wmKeyMapItem *a, const wmKeyMapItem *b)
static bool blender::wm_keymap_item_equals (const wmKeyMapItem *a, const wmKeyMapItem *b)
void blender::WM_keymap_item_properties_reset (wmKeyMapItem *kmi, IDProperty *properties)
int blender::WM_keymap_item_map_type_get (const wmKeyMapItem *kmi)
Keymap Diff Item

Item in a diff keymap, used for saving diff of keymaps in user preferences.

static wmKeyMapDiffItem * blender::wm_keymap_diff_item_copy (wmKeyMapDiffItem *kmdi)
static void blender::wm_keymap_diff_item_free (wmKeyMapDiffItem *kmdi)
Key Configuration

List of keymaps for all editors, modes, etc. There is a builtin default key configuration, a user key configuration, and other preset configurations.

wmKeyConfig * blender::WM_keyconfig_new (wmWindowManager *wm, const char *idname, bool user_defined)
wmKeyConfig * blender::WM_keyconfig_ensure (wmWindowManager *wm, const char *idname, bool user_defined)
void blender::WM_keyconfig_remove (wmWindowManager *wm, wmKeyConfig *keyconf)
void blender::WM_keyconfig_clear (wmKeyConfig *keyconf)
void blender::WM_keyconfig_free (wmKeyConfig *keyconf)
static wmKeyConfig * blender::WM_keyconfig_active (wmWindowManager *wm)
void blender::WM_keyconfig_set_active (wmWindowManager *wm, const char *idname)
Keymap

List of keymap items for one editor, mode, modal operator.

static wmKeyMap * blender::wm_keymap_new (const char *idname, int spaceid, int regionid)
static void blender::wm_keymap_copy_data (wmKeyMap *keymapn, wmKeyMap *keymap)
static wmKeyMap * blender::wm_keymap_copy (wmKeyMap *keymap)
void blender::WM_keymap_clear (wmKeyMap *keymap)
void blender::WM_keymap_remove (wmKeyConfig *keyconf, wmKeyMap *keymap)
bool blender::WM_keymap_poll (bContext *C, wmKeyMap *keymap)
static bool blender::wm_keymap_is_match (const wmKeyMap *km_a, const wmKeyMap *km_b)
static void blender::keymap_event_set (wmKeyMapItem *kmi, const KeyMapItem_Params *params)
static void blender::keymap_item_set_id (wmKeyMap *keymap, wmKeyMapItem *kmi)
wmKeyMapItem * blender::WM_keymap_add_item (wmKeyMap *keymap, const char *idname, const KeyMapItem_Params *params)
wmKeyMapItem * blender::WM_keymap_add_item_copy (wmKeyMap *keymap, const wmKeyMapItem *kmi_src)
void blender::WM_keymap_remove_item (wmKeyMap *keymap, wmKeyMapItem *kmi)
Keymap Diff and Patch

Rather than saving the entire keymap for user preferences, we only save a diff so that changes in the defaults get synced. This system is not perfect but works better than overriding the keymap entirely when only few items are changed.

static void blender::wm_keymap_addon_add (wmKeyMap *keymap, wmKeyMap *addonmap)
static wmKeyMapItem * blender::wm_keymap_find_item_equals (wmKeyMap *km, const wmKeyMapItem *needle)
static wmKeyMapItem * blender::wm_keymap_find_item_equals_result (wmKeyMap *km, const wmKeyMapItem *needle)
static void blender::wm_keymap_diff (wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km)
static void blender::wm_keymap_patch (wmKeyMap *km, wmKeyMap *diff_km)
static wmKeyMap * blender::wm_keymap_patch_update (ListBaseT< wmKeyMap > *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap)
static void blender::wm_keymap_diff_update (ListBaseT< wmKeyMap > *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *km)
Storage in WM

Name id's are for storing general or multiple keymaps.

wmKeyMap * blender::WM_keymap_list_find (ListBaseT< wmKeyMap > *lb, const char *idname, int spaceid, int regionid)
wmKeyMap * blender::WM_keymap_list_find_spaceid_or_empty (ListBaseT< wmKeyMap > *lb, const char *idname, int spaceid, int regionid)
wmKeyMap * blender::WM_keymap_ensure (wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
wmKeyMap * blender::WM_keymap_find_all (wmWindowManager *wm, const char *idname, int spaceid, int regionid)
wmKeyMap * blender::WM_keymap_find_all_spaceid_or_empty (wmWindowManager *wm, const char *idname, int spaceid, int regionid)
Modal Keymaps

Modal key-maps get linked to a running operator, and filter the keys before sending to #wmOperatorType.modal callback.

wmKeyMap * blender::WM_modalkeymap_ensure (wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
wmKeyMap * blender::WM_modalkeymap_find (wmKeyConfig *keyconf, const char *idname)
wmKeyMapItem * blender::WM_modalkeymap_add_item (wmKeyMap *km, const KeyMapItem_Params *params, int value)
wmKeyMapItem * blender::WM_modalkeymap_add_item_str (wmKeyMap *km, const KeyMapItem_Params *params, const char *value)
static const wmKeyMapItem * blender::wm_modalkeymap_find_propvalue_iter (const wmKeyMap *km, const wmKeyMapItem *kmi, const int propvalue)
const wmKeyMapItem * blender::WM_modalkeymap_find_propvalue (const wmKeyMap *km, const int propvalue)
void blender::WM_modalkeymap_assign (wmKeyMap *km, const char *opname)
static void blender::wm_user_modal_keymap_set_items (wmWindowManager *wm, wmKeyMap *km)
Text from Key Events
static const char * blender::key_event_glyph_or_text (const int font_id, const char *text, const char *single_glyph)
const char * blender::WM_key_event_string (const short type, const bool compact)
std::optional< std::string > blender::WM_keymap_item_raw_to_string (const int8_t shift, const int8_t ctrl, const int8_t alt, const int8_t oskey, const int8_t hyper, const short keymodifier, const short val, const short type, const bool compact)
std::optional< std::string > blender::WM_keymap_item_to_string (const wmKeyMapItem *kmi, const bool compact)
std::optional< std::string > blender::WM_modalkeymap_items_to_string (const wmKeyMap *km, const int propvalue, const bool compact)
std::optional< std::string > blender::WM_modalkeymap_operator_items_to_string (wmOperatorType *ot, const int propvalue, const bool compact)
Keymap Finding Utilities
static wmKeyMapItem * blender::wm_keymap_item_find_in_keymap (wmKeyMap *keymap, const char *opname, const IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params)
static wmKeyMapItem * blender::wm_keymap_item_find_handlers (const bContext *C, wmWindowManager *wm, wmWindow *win, ListBaseT< wmEventHandler > *handlers, const char *opname, wm::OpCallContext, const IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static wmKeyMapItem * blender::wm_keymap_item_find_props (const bContext *C, const char *opname, wm::OpCallContext opcontext, const IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static wmKeyMapItem * blender::wm_keymap_item_find (const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static bool blender::kmi_filter_is_visible (const wmKeyMap *, const wmKeyMapItem *kmi, void *)
std::optional< std::string > blender::WM_key_event_operator_string (const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
static bool blender::kmi_filter_is_visible_type_mask (const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data)
wmKeyMapItem * blender::WM_key_event_operator (const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const short include_mask, const short exclude_mask, wmKeyMap **r_keymap)
wmKeyMapItem * blender::WM_key_event_operator_from_keymap (wmKeyMap *keymap, const char *opname, IDProperty *properties, const short include_mask, const short exclude_mask)
bool blender::WM_keymap_item_compare (const wmKeyMapItem *k1, const wmKeyMapItem *k2)
Event Handling

Handlers have pointers to the keymap in the default configuration. During event handling this function is called to get the keymap from the final configuration.

wmKeyMap * blender::WM_keymap_active (const wmWindowManager *wm, wmKeyMap *keymap)
Keymap Editor

In the keymap editor the user key configuration is edited.

void blender::WM_keymap_item_restore_to_default (wmWindowManager *wm, wmKeyMap *keymap, wmKeyMapItem *kmi)
void blender::WM_keymap_restore_to_default (wmKeyMap *keymap, wmWindowManager *wm)
const char * blender::WM_bool_as_string (bool test)
Keymap Queries
wmKeyMapItem * blender::WM_keymap_item_find_id (wmKeyMap *keymap, const int id)
wmKeyMapItem * blender::WM_keymap_item_find_match (wmKeyMap *km_base, wmKeyMap *km_match, const wmKeyMapItem *kmi_match, ReportList *reports)

Update Final Configuration

On load or other changes, the final user key configuration is rebuilt from the preset, add-on and user preferences keymaps. We also test if the final configuration changed and write the changes to the user preferences.

enum  { blender::WM_KEYMAP_UPDATE_RECONFIGURE = (1 << 0) , blender::WM_KEYMAP_UPDATE_OPERATORTYPE = (1 << 1) , blender::WM_KEYMAP_UPDATE_POSTPONE = (1 << 2) }
static char blender::wm_keymap_update_flag = 0
static char blender::wm_keymap_update_suppress_flag = 0
static int8_t blender::wm_keymap_update_suppress_count = 0
void blender::WM_keyconfig_update_tag (wmKeyMap *keymap, wmKeyMapItem *kmi)
void blender::WM_keyconfig_update_operatortype_tag ()
void blender::WM_keyconfig_update_suppress_begin ()
void blender::WM_keyconfig_update_suppress_end ()
void blender::WM_keyconfig_update_postpone_begin ()
void blender::WM_keyconfig_update_postpone_end ()
static bool blender::wm_keymap_test_and_clear_update (wmKeyMap *km)
static wmKeyMap * blender::wm_keymap_preset (wmWindowManager *wm, wmKeyConfig *keyconf, wmKeyMap *km)
void blender::WM_keyconfig_update_on_startup (wmWindowManager *wm)
void blender::WM_keyconfig_update (wmWindowManager *wm)
void blender::WM_keyconfig_update_ex (wmWindowManager *wm, bool keep_properties)

Detailed Description

Configurable key-maps - add/remove/find/compare/patch...

Definition in file wm_keymap.cc.