Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-12-12 13:39:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-12-12 13:43:26 +0300
commit4357fb63db77d8bee9b1a3d10fdf6abd55e4c798 (patch)
tree477adefe8069f2e09d091086fbf4bfb2968878fd /source/blender/windowmanager
parentadaadb2fa0a4fde53f5f09bc05f6758926e71f44 (diff)
Keymap: event type filter w/ finding keymap items
Now its possibly to ask for only keyboard/mouse/ndof events when finding key map items.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_keymap.h4
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c48
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c21
-rw-r--r--source/blender/windowmanager/wm_event_types.h39
4 files changed, 100 insertions, 12 deletions
diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h
index 7f7612cea35..8f31685e453 100644
--- a/source/blender/windowmanager/WM_keymap.h
+++ b/source/blender/windowmanager/WM_keymap.h
@@ -144,8 +144,8 @@ int WM_keymap_item_raw_to_string(
const short val, const short type, const bool compact,
char *result, const int result_len);
wmKeyMapItem *WM_key_event_operator(
- const struct bContext *C, const char *opname, int opcontext,
- struct IDProperty *properties, const bool is_hotkey,
+ const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties,
+ const short include_mask, const short exclude_mask,
struct wmKeyMap **r_keymap);
char *WM_key_event_operator_string(
const struct bContext *C, const char *opname, int opcontext,
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 58773bd4283..81544c2de62 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -3534,6 +3534,54 @@ bool WM_event_is_modal_tweak_exit(const wmEvent *event, int tweak_event)
return 0;
}
+bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask mask)
+{
+ /* Keyboard. */
+ if (mask & EVT_TYPE_MASK_KEYBOARD) {
+ if (ISKEYBOARD(event_type)) {
+ return true;
+ }
+ }
+ else if (mask & EVT_TYPE_MASK_KEYBOARD_MODIFIER) {
+ if (ISKEYMODIFIER(event_type)) {
+ return true;
+ }
+ }
+
+ /* Mouse. */
+ if (mask & EVT_TYPE_MASK_MOUSE) {
+ if (ISMOUSE(event_type)) {
+ return true;
+ }
+ }
+ else if (mask & EVT_TYPE_MASK_MOUSE_WHEEL) {
+ if (ISMOUSE_WHEEL(event_type)) {
+ return true;
+ }
+ }
+ else if (mask & EVT_TYPE_MASK_MOUSE_GESTURE) {
+ if (ISMOUSE_GESTURE(event_type)) {
+ return true;
+ }
+ }
+
+ /* Tweak. */
+ if (mask & EVT_TYPE_MASK_TWEAK) {
+ if (ISTWEAK(event_type)) {
+ return true;
+ }
+ }
+
+ /* Action Zone. */
+ if (mask & EVT_TYPE_MASK_ACTIONZONE) {
+ if (IS_EVENT_ACTIONZONE(event_type)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
/* ********************* ghost stuff *************** */
static int convert_key(GHOST_TKey key)
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 13744aa04af..2d7814b0377 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -64,7 +64,6 @@
#include "wm_event_system.h"
#include "wm_event_types.h"
-
struct wmKeyMapItemFind_Params {
bool (*filter_fn)(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data);
void *user_data;
@@ -1415,21 +1414,29 @@ char *WM_key_event_operator_string(
return NULL;
}
-static bool kmi_filter_is_visible_hotkey(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data)
+static bool kmi_filter_is_visible_type_mask(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data)
{
- return (ISHOTKEY(kmi->type) && kmi_filter_is_visible(km, kmi, user_data));
+ short *mask_pair = user_data;
+ return ((WM_event_type_mask_test(kmi->type, mask_pair[0]) == true) &&
+ (WM_event_type_mask_test(kmi->type, mask_pair[1]) == false) &&
+ kmi_filter_is_visible(km, kmi, user_data));
}
+/**
+ * \param include_mask, exclude_mask: Event types to include/exclude when looking up keys (#eEventType_Mask).
+ */
wmKeyMapItem *WM_key_event_operator(
- const bContext *C, const char *opname, int opcontext,
- IDProperty *properties, const bool is_hotkey,
+ const bContext *C, const char *opname, int opcontext, IDProperty *properties,
+ const short include_mask, const short exclude_mask,
wmKeyMap **r_keymap)
{
+ short user_data_mask[2] = {include_mask, exclude_mask};
+ bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0);
return wm_keymap_item_find(
C, opname, opcontext, properties, true,
&(struct wmKeyMapItemFind_Params){
- .filter_fn = is_hotkey ? kmi_filter_is_visible_hotkey : kmi_filter_is_visible,
- .user_data = NULL,
+ .filter_fn = use_mask ? kmi_filter_is_visible_type_mask : kmi_filter_is_visible,
+ .user_data = use_mask ? user_data_mask : NULL,
},
r_keymap);
}
diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h
index b2c4c0494ce..0fc4899e401 100644
--- a/source/blender/windowmanager/wm_event_types.h
+++ b/source/blender/windowmanager/wm_event_types.h
@@ -381,9 +381,7 @@ enum {
/* test whether event type is acceptable as hotkey, excluding modifiers */
#define ISHOTKEY(event_type) \
((ISKEYBOARD(event_type) || ISMOUSE(event_type) || ISNDOF(event_type)) && \
- ((event_type) != ESCKEY) && \
- ((event_type) >= LEFTCTRLKEY && (event_type) <= LEFTSHIFTKEY) == false && \
- ((event_type) >= UNKNOWNKEY && (event_type) <= GRLESSKEY) == false)
+ (ISKEYMODIFIER(event_type) == false))
/* internal helpers*/
#define _VA_IS_EVENT_MOD2(v, a) (CHECK_TYPE_INLINE(v, wmEvent *), \
@@ -398,6 +396,41 @@ enum {
/* reusable IS_EVENT_MOD(event, shift, ctrl, alt, oskey), macro */
#define IS_EVENT_MOD(...) VA_NARGS_CALL_OVERLOAD(_VA_IS_EVENT_MOD, __VA_ARGS__)
+enum eEventType_Mask {
+ /* ISKEYMODIFIER */
+ EVT_TYPE_MASK_KEYBOARD_MODIFIER = (1 << 0),
+ /* ISKEYBOARD */
+ EVT_TYPE_MASK_KEYBOARD = (1 << 1) | EVT_TYPE_MASK_KEYBOARD_MODIFIER,
+ /* ISMOUSE_WHEEL */
+ EVT_TYPE_MASK_MOUSE_WHEEL = (1 << 2),
+ /* ISMOUSE_BUTTON */
+ EVT_TYPE_MASK_MOUSE_GESTURE = (1 << 3),
+ /* ISMOUSE_GESTURE */
+ EVT_TYPE_MASK_MOUSE_BUTTON = (1 << 4),
+ /* ISMOUSE */
+ EVT_TYPE_MASK_MOUSE = (1 << 5) | EVT_TYPE_MASK_MOUSE_WHEEL | EVT_TYPE_MASK_MOUSE_GESTURE | EVT_TYPE_MASK_MOUSE_BUTTON,
+ /* ISNDOF */
+ EVT_TYPE_MASK_NDOF = (1 << 6),
+ /* ISTWEAK */
+ EVT_TYPE_MASK_TWEAK = (1 << 7),
+ /* IS_EVENT_ACTIONZONE */
+ EVT_TYPE_MASK_ACTIONZONE = (1 << 8),
+};
+#define EVT_TYPE_MASK_ALL \
+ (EVT_TYPE_MASK_KEYBOARD | \
+ EVT_TYPE_MASK_MOUSE | \
+ EVT_TYPE_MASK_NDOF | \
+ EVT_TYPE_MASK_TWEAK | \
+ EVT_TYPE_MASK_ACTIONZONE)
+
+#define EVT_TYPE_MASK_HOTKEY_INCLUDE \
+ (EVT_TYPE_MASK_KEYBOARD | EVT_TYPE_MASK_MOUSE | EVT_TYPE_MASK_NDOF)
+#define EVT_TYPE_MASK_HOTKEY_EXCLUDE \
+ EVT_TYPE_MASK_KEYBOARD_MODIFIER
+
+bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask mask);
+
+
/* ********** wmEvent.val ********** */
/* Gestures */