From 70f3a47d57e7cf67fa6c86a9cbd1735679611270 Mon Sep 17 00:00:00 2001 From: julianeisel Date: Tue, 6 Jan 2015 20:27:59 +0100 Subject: [PATCH] Event System Cleanup: Modifier Key Assignment Switch Was quite messy previously, think this is much more readable and easier to follow. --- source/blender/windowmanager/WM_types.h | 2 +- .../windowmanager/intern/wm_event_system.c | 42 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 2db34bbd392..e64b1152252 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -169,7 +169,7 @@ enum { #define KM_OSKEY2 128 /* KM_MOD_ flags for wmKeyMapItem and wmEvent.alt/shift/oskey/ctrl */ -/* note that KM_ANY and false are used with these defines too */ +/* note that KM_ANY and KM_NOTHING are used with these defines too */ #define KM_MOD_FIRST 1 #define KM_MOD_SECOND 2 diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 9473b3e7a68..e7b3de74a5c 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -3196,6 +3196,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U case GHOST_kEventKeyUp: { GHOST_TEventKeyData *kd = customdata; + short keymodifier = KM_NOTHING; event.type = convert_key(kd->key); event.ascii = kd->ascii; memcpy(event.utf8_buf, kd->utf8_buf, sizeof(event.utf8_buf)); /* might be not null terminated*/ @@ -3238,25 +3239,36 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* assigning both first and second is strange - campbell */ switch (event.type) { - case LEFTSHIFTKEY: case RIGHTSHIFTKEY: - event.shift = evt->shift = (event.val == KM_PRESS) ? - ((evt->ctrl || evt->alt || evt->oskey) ? (KM_MOD_FIRST | KM_MOD_SECOND) : KM_MOD_FIRST) : - false; + case LEFTSHIFTKEY: + case RIGHTSHIFTKEY: + if (event.val == KM_PRESS) { + if (evt->ctrl || evt->alt || evt->oskey) keymodifier = (KM_MOD_FIRST | KM_MOD_SECOND); + else keymodifier = KM_MOD_FIRST; + } + event.shift = evt->shift = keymodifier; break; - case LEFTCTRLKEY: case RIGHTCTRLKEY: - event.ctrl = evt->ctrl = (event.val == KM_PRESS) ? - ((evt->shift || evt->alt || evt->oskey) ? (KM_MOD_FIRST | KM_MOD_SECOND) : KM_MOD_FIRST) : - false; + case LEFTCTRLKEY: + case RIGHTCTRLKEY: + if (event.val == KM_PRESS) { + if (evt->shift || evt->alt || evt->oskey) keymodifier = (KM_MOD_FIRST | KM_MOD_SECOND); + else keymodifier = KM_MOD_FIRST; + } + event.ctrl = evt->ctrl = keymodifier; break; - case LEFTALTKEY: case RIGHTALTKEY: - event.alt = evt->alt = (event.val == KM_PRESS) ? - ((evt->ctrl || evt->shift || evt->oskey) ? (KM_MOD_FIRST | KM_MOD_SECOND) : KM_MOD_FIRST) : - false; + case LEFTALTKEY: + case RIGHTALTKEY: + if (event.val == KM_PRESS) { + if (evt->ctrl || evt->shift || evt->oskey) keymodifier = (KM_MOD_FIRST | KM_MOD_SECOND); + else keymodifier = KM_MOD_FIRST; + } + event.alt = evt->alt = keymodifier; break; case OSKEY: - event.oskey = evt->oskey = (event.val == KM_PRESS) ? - ((evt->ctrl || evt->alt || evt->shift) ? (KM_MOD_FIRST | KM_MOD_SECOND) : KM_MOD_FIRST) : - false; + if (event.val == KM_PRESS) { + if (evt->ctrl || evt->alt || evt->shift) keymodifier = (KM_MOD_FIRST | KM_MOD_SECOND); + else keymodifier = KM_MOD_FIRST; + } + event.oskey = evt->oskey = keymodifier; break; default: if (event.val == KM_PRESS && event.keymodifier == 0)