From 054aa012c4fb6e4782c4af5cec6ed6596651dc7c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Tue, 16 May 2017 16:48:58 +0900 Subject: [PATCH] evas: Use enum instead of string in Efl.Input.State Ref T5312 --- src/lib/efl/interfaces/efl_common_internal.h | 31 ++++++++++++++++++++ src/lib/elementary/efl_ui_win.c | 6 ++-- src/lib/evas/canvas/efl_input_key.c | 11 +++++-- src/lib/evas/canvas/efl_input_pointer.c | 10 +++++-- src/lib/evas/canvas/efl_input_state.eo | 8 +++-- src/lib/evas/canvas/evas_key_grab.c | 44 +++++++++++++--------------- 6 files changed, 78 insertions(+), 32 deletions(-) diff --git a/src/lib/efl/interfaces/efl_common_internal.h b/src/lib/efl/interfaces/efl_common_internal.h index c7ae160..6cbe7d4 100644 --- a/src/lib/efl/interfaces/efl_common_internal.h +++ b/src/lib/efl/interfaces/efl_common_internal.h @@ -119,6 +119,37 @@ struct _Efl_Input_Focus_Data double timestamp; }; +static inline const char * +_efl_input_modifier_to_string(Efl_Input_Modifier mod) +{ + switch (mod) + { + default: + case EFL_INPUT_MODIFIER_NONE: return NULL; + case EFL_INPUT_MODIFIER_ALT: return "Alt"; + case EFL_INPUT_MODIFIER_CONTROL: return "Control"; + case EFL_INPUT_MODIFIER_SHIFT: return "Shift"; + case EFL_INPUT_MODIFIER_META: return "Meta"; + case EFL_INPUT_MODIFIER_ALTGR: return "AltGr"; + case EFL_INPUT_MODIFIER_HYPER: return "Hyper"; + case EFL_INPUT_MODIFIER_SUPER: return "Super"; + } +} + +static inline const char * +_efl_input_lock_to_string(Efl_Input_Lock lock) +{ + switch (lock) + { + default: + case EFL_INPUT_LOCK_NONE: return NULL; + case EFL_INPUT_LOCK_NUM: return "Num"; + case EFL_INPUT_LOCK_CAPS: return "Caps"; + case EFL_INPUT_LOCK_SCROLL: return "Scroll"; + case EFL_INPUT_LOCK_SHIFT: return "Shift"; + } +} + static inline Eina_Bool _efl_input_value_has(const Efl_Input_Pointer_Data *pd, Efl_Input_Value key) { diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c index 16c4000..dcd41a4 100644 --- a/src/lib/elementary/efl_ui_win.c +++ b/src/lib/elementary/efl_ui_win.c @@ -6557,16 +6557,18 @@ _efl_ui_win_elm_interface_atspi_component_extents_get(Eo *obj, Efl_Ui_Win_Data * } EOLIAN static Eina_Bool -_efl_ui_win_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *pd, const char *name) +_efl_ui_win_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *pd, Efl_Input_Modifier mod) { const Evas_Modifier *m = evas_key_modifier_get(pd->evas); + const char *name = _efl_input_modifier_to_string(mod); return evas_key_modifier_is_set(m, name); } EOLIAN static Eina_Bool -_efl_ui_win_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *pd, const char *name) +_efl_ui_win_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *pd, Efl_Input_Lock lock) { const Evas_Lock *m = evas_key_lock_get(pd->evas); + const char *name = _efl_input_lock_to_string(lock); return evas_key_lock_is_set(m, name); } diff --git a/src/lib/evas/canvas/efl_input_key.c b/src/lib/evas/canvas/efl_input_key.c index 3cc6699..7f6d794 100644 --- a/src/lib/evas/canvas/efl_input_key.c +++ b/src/lib/evas/canvas/efl_input_key.c @@ -240,23 +240,30 @@ _efl_input_key_efl_input_event_device_get(Eo *obj EINA_UNUSED, Efl_Input_Key_Dat } EOLIAN static Eina_Bool -_efl_input_key_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Key_Data *pd, const char * name) +_efl_input_key_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Key_Data *pd, Efl_Input_Modifier mod) { Efl_Input_Device *seat; + const char *name; if (!pd->modifiers) return EINA_FALSE; seat = efl_input_device_seat_get(pd->device); if (!seat) return EINA_FALSE; + name = _efl_input_modifier_to_string(mod); + if (!name) return EINA_FALSE; return evas_seat_key_modifier_is_set(pd->modifiers, name, seat); } EOLIAN static Eina_Bool -_efl_input_key_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Key_Data *pd, const char * name) +_efl_input_key_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Key_Data *pd, Efl_Input_Lock lock) { Efl_Input_Device *seat; + const char *name; + if (!pd->locks) return EINA_FALSE; seat = efl_input_device_seat_get(pd->device); if (!seat) return EINA_FALSE; + name = _efl_input_lock_to_string(lock); + if (!name) return EINA_FALSE; return evas_seat_key_lock_is_set(pd->locks, name, seat); } diff --git a/src/lib/evas/canvas/efl_input_pointer.c b/src/lib/evas/canvas/efl_input_pointer.c index c6e3d05..6eec18e 100644 --- a/src/lib/evas/canvas/efl_input_pointer.c +++ b/src/lib/evas/canvas/efl_input_pointer.c @@ -323,24 +323,30 @@ _efl_input_pointer_tool_set(Eo *obj EINA_UNUSED, Efl_Input_Pointer_Data *pd, int } EOLIAN static Eina_Bool -_efl_input_pointer_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Pointer_Data *pd, const char *name) +_efl_input_pointer_efl_input_state_modifier_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Pointer_Data *pd, Efl_Input_Modifier mod) { Efl_Input_Device *seat; + const char *name; if (!pd->modifiers) return EINA_FALSE; seat = efl_input_device_seat_get(pd->device); if (!seat) return EINA_FALSE; + name = _efl_input_modifier_to_string(mod); + if (!name) return EINA_FALSE; return evas_seat_key_modifier_is_set(pd->modifiers, name, seat); } EOLIAN static Eina_Bool -_efl_input_pointer_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Pointer_Data *pd, const char *name) +_efl_input_pointer_efl_input_state_lock_enabled_get(Eo *obj EINA_UNUSED, Efl_Input_Pointer_Data *pd, Efl_Input_Lock lock) { Efl_Input_Device *seat; + const char *name; if (!pd->locks) return EINA_FALSE; seat = efl_input_device_seat_get(pd->device); if (!seat) return EINA_FALSE; + name = _efl_input_lock_to_string(lock); + if (!name) return EINA_FALSE; return evas_seat_key_lock_is_set(pd->locks, name, seat); } diff --git a/src/lib/evas/canvas/efl_input_state.eo b/src/lib/evas/canvas/efl_input_state.eo index e074d2c..41a0ed5 100644 --- a/src/lib/evas/canvas/efl_input_state.eo +++ b/src/lib/evas/canvas/efl_input_state.eo @@ -1,13 +1,15 @@ +import efl_input_types; + interface Efl.Input.State () { [[Efl input state interface]] eo_prefix: efl_input; methods { @property modifier_enabled { - [[Indicates whether a key modifier is on, such as Ctrl, Shift,...]] + [[Indicates whether a key modifier is on, such as Ctrl, Shift, ...]] get {} keys { - name: string; [[Key name]] + mod: Efl.Input.Modifier; [[The modifier key to test.]] } values { is_set: bool; [[$true if the key modifier is pressed.]] @@ -17,7 +19,7 @@ interface Efl.Input.State () [[Indicates whether a key lock is on, such as NumLock, CapsLock, ...]] get {} keys { - name: string; [[Lock name]] + lock: Efl.Input.Lock; [[The lock key to test.]] } values { is_set: bool; [[$true if the key lock is on.]] diff --git a/src/lib/evas/canvas/evas_key_grab.c b/src/lib/evas/canvas/evas_key_grab.c index 9e5f10f..7d856d2 100644 --- a/src/lib/evas/canvas/evas_key_grab.c +++ b/src/lib/evas/canvas/evas_key_grab.c @@ -1,6 +1,9 @@ #include "evas_common_private.h" #include "evas_private.h" +#define EFL_INTERNAL_UNSTABLE +#include "interfaces/efl_common_internal.h" + /* private calls */ /* FIXME: this is not optimal, but works. i should have a hash of keys per */ @@ -194,33 +197,28 @@ _object_key_ungrab(Eo *eo_obj, Evas_Object_Protected_Data *obj, const char *keyn } } -// Matching function between legacy (used throughout EFL) and EO enums - -static const struct { - const char *keyname; - Efl_Input_Modifier mod; -} _modifier_match[] = { - { "Alt", EFL_INPUT_MODIFIER_ALT }, - { "Control", EFL_INPUT_MODIFIER_CONTROL }, - { "Shift", EFL_INPUT_MODIFIER_SHIFT }, - { "Meta", EFL_INPUT_MODIFIER_META }, - { "AltGr", EFL_INPUT_MODIFIER_ALTGR }, - { "Hyper", EFL_INPUT_MODIFIER_HYPER }, - { "Super", EFL_INPUT_MODIFIER_SUPER }, - { NULL, EFL_INPUT_MODIFIER_NONE } -}; - static inline Evas_Modifier_Mask _efl_input_modifier_to_evas_modifier_mask(Evas_Public_Data *e, Efl_Input_Modifier in) { Evas_Modifier_Mask out = 0; - int i; - - for (i = 0; _modifier_match[i].keyname; i++) - { - if (in & _modifier_match[i].mod) - out |= evas_key_modifier_mask_get(e->evas, _modifier_match[i].keyname); - } + size_t i; + + static const Efl_Input_Modifier mods[] = { + EFL_INPUT_MODIFIER_ALT, + EFL_INPUT_MODIFIER_CONTROL, + EFL_INPUT_MODIFIER_SHIFT, + EFL_INPUT_MODIFIER_META, + EFL_INPUT_MODIFIER_ALTGR, + EFL_INPUT_MODIFIER_HYPER, + EFL_INPUT_MODIFIER_SUPER + }; + + for (i = 0; i < EINA_C_ARRAY_LENGTH(mods); i++) + if (in & mods[i]) + { + out |= evas_key_modifier_mask_get + (e->evas, _efl_input_modifier_to_string(mods[i])); + } return out; } -- 2.7.4