From 00552193e97053836a2ce8acb3608edc7ba89461 Mon Sep 17 00:00:00 2001 From: Florian Fleissner Date: Thu, 4 Apr 2019 12:46:11 +0200 Subject: [PATCH] Introduced key address version of handler onKeyswitchEvent Signed-off-by: Florian Fleissner --- src/kaleidoscope/Kaleidoscope.h | 1 + src/kaleidoscope/KeyAddr.h | 23 +++++++++++++ src/kaleidoscope/event_handlers.h | 32 +++++++++++++++++-- src/kaleidoscope/hooks.cpp | 1 + src/kaleidoscope/hooks.h | 1 + src/kaleidoscope/macro_helpers.h | 4 +++ .../eventhandler_signature_check.h | 8 ++--- .../type_traits/has_method.h | 2 +- 8 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 src/kaleidoscope/KeyAddr.h diff --git a/src/kaleidoscope/Kaleidoscope.h b/src/kaleidoscope/Kaleidoscope.h index 24b311db..922f685c 100644 --- a/src/kaleidoscope/Kaleidoscope.h +++ b/src/kaleidoscope/Kaleidoscope.h @@ -54,6 +54,7 @@ typedef HARDWARE_IMPLEMENTATION::KeyAddr KeyAddr; #define COLS (KeyboardHardware.matrix_columns) #define LED_COUNT (KeyboardHardware.led_count) +#include "kaleidoscope/KeyAddr.h" #include "kaleidoscope/key_events.h" #include "kaleidoscope/hid.h" #include "kaleidoscope/layers.h" diff --git a/src/kaleidoscope/KeyAddr.h b/src/kaleidoscope/KeyAddr.h new file mode 100644 index 00000000..2ac66d73 --- /dev/null +++ b/src/kaleidoscope/KeyAddr.h @@ -0,0 +1,23 @@ +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2013-2018 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include KALEIDOSCOPE_HARDWARE_H + +extern HARDWARE_IMPLEMENTATION KeyboardHardware; + +typedef HARDWARE_IMPLEMENTATION::KeyAddr KeyAddr; diff --git a/src/kaleidoscope/event_handlers.h b/src/kaleidoscope/event_handlers.h index b27396e2..86c21db9 100644 --- a/src/kaleidoscope/event_handlers.h +++ b/src/kaleidoscope/event_handlers.h @@ -84,6 +84,15 @@ // The list of parameters as they would be passed to a call to the handler. // Parameter names must match the names assigned to the call arguments. +#define _DEPRECATED_MESSAGE_ON_KEYSWITCH_EVENT_HANDLER_V1 \ +"The event handler signature\n" __NL__ \ +"EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, \n" __NL__ \ +" uint8_t keyState)\n" __NL__ \ +"has been deprecated. Please use the new signature\n" __NL__ \ +"EventHandlerResult onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, \n" __NL__ \ +" uint8_t keyState)\n" __NL__ \ +"instead." + #define _FOR_EACH_EVENT_HANDLER(OPERATION, ...) __NL__ \ __NL__ \ OPERATION(onSetup, __NL__ \ @@ -100,6 +109,7 @@ _NOT_ABORTABLE, __NL__ \ (), (), ##__VA_ARGS__) __NL__ \ __NL__ \ + /* DEPRECATED */ __NL__ \ /* Function called for every non-idle key, every cycle, so it */ __NL__ \ /* can decide what to do with it. It can modify the key (which is */ __NL__ \ /* passed by reference for this reason), and decide whether */ __NL__ \ @@ -109,11 +119,26 @@ /* will stop processing there. */ __NL__ \ OPERATION(onKeyswitchEvent, __NL__ \ 1, __NL__ \ - _CURRENT_IMPLEMENTATION, __NL__ \ + DEPRECATED(ON_KEYSWITCH_EVENT_HANDLER_V1), __NL__ \ _ABORTABLE, __NL__ \ (Key &mappedKey, byte row, byte col, uint8_t keyState), __NL__ \ (mappedKey, row, col, keyState), ##__VA_ARGS__) __NL__ \ __NL__ \ + /* Function called for every non-idle key, every cycle, so it */ __NL__ \ + /* can decide what to do with it. It can modify the key (which is */ __NL__ \ + /* passed by reference for this reason), and decide whether */ __NL__ \ + /* further handles should be tried. If it returns */ __NL__ \ + /* EventHandlerResult::OK, other handlers will also get a chance */ __NL__ \ + /* to react to the event. If it returns anything else, Kaleidoscope */ __NL__ \ + /* will stop processing there. */ __NL__ \ + OPERATION(onKeyswitchEvent, __NL__ \ + 2, __NL__ \ + _CURRENT_IMPLEMENTATION, __NL__ \ + _ABORTABLE, __NL__ \ + (Key &mappedKey, KeyAddr key_addr, uint8_t keyState), __NL__ \ + (mappedKey, key_addr, keyState), ##__VA_ARGS__) __NL__ \ + __NL__ \ + __NL__ \ /* Called by an external plugin (such as Kaleidoscope-FocusSerial) */ __NL__ \ /* via Kaleidoscope::onFocusEvent. This is where Focus events can */ __NL__ \ /* be handled. The function can return EventHandlerResult::OK, and */ __NL__ \ @@ -181,9 +206,10 @@ OP(beforeEachCycle, 1) __NL__ \ END(beforeEachCycle, 1) __NL__ \ __NL__ \ - START(onKeyswitchEvent, 1) __NL__ \ + START(onKeyswitchEvent, 1, 2) __NL__ \ OP(onKeyswitchEvent, 1) __NL__ \ - END(onKeyswitchEvent, 1) __NL__ \ + OP(onKeyswitchEvent, 2) __NL__ \ + END(onKeyswitchEvent, 1, 2) __NL__ \ __NL__ \ START(onFocusEvent, 1) __NL__ \ OP(onFocusEvent, 1) __NL__ \ diff --git a/src/kaleidoscope/hooks.cpp b/src/kaleidoscope/hooks.cpp index ce6aea90..ac25c44c 100644 --- a/src/kaleidoscope/hooks.cpp +++ b/src/kaleidoscope/hooks.cpp @@ -14,6 +14,7 @@ * this program. If not, see . */ +#include "Kaleidoscope.h" #include "kaleidoscope/hooks.h" namespace kaleidoscope { diff --git a/src/kaleidoscope/hooks.h b/src/kaleidoscope/hooks.h index 1a56ce2e..076a8fba 100644 --- a/src/kaleidoscope/hooks.h +++ b/src/kaleidoscope/hooks.h @@ -22,6 +22,7 @@ namespace kaleidoscope { union Key; } +#include "kaleidoscope/KeyAddr.h" #include "kaleidoscope/plugin.h" #include "kaleidoscope/event_handlers.h" diff --git a/src/kaleidoscope/macro_helpers.h b/src/kaleidoscope/macro_helpers.h index dffe1834..c056bf25 100644 --- a/src/kaleidoscope/macro_helpers.h +++ b/src/kaleidoscope/macro_helpers.h @@ -48,6 +48,10 @@ #define __STRINGIZE(S) #S #define STRINGIZE(S) __STRINGIZE(S) +#define GLUE2(A, B) A##B +#define GLUE3(A, B, C) A##B##C +#define GLUE4(A, B, C, D) A##B##C##D + // Allow for the creation of verbose messages in static_asserts // #define VERBOSE_STATIC_ASSERT_HEADER \ diff --git a/src/kaleidoscope_internal/eventhandler_signature_check.h b/src/kaleidoscope_internal/eventhandler_signature_check.h index 4e04501e..97ac9c89 100644 --- a/src/kaleidoscope_internal/eventhandler_signature_check.h +++ b/src/kaleidoscope_internal/eventhandler_signature_check.h @@ -73,7 +73,7 @@ template struct static constexpr bool value = true; }; -#define _NOOP(...) __NL__ \ +#define _NOOP(...) __NL__ #define _DEFINE_IMPLEMENTATION_CHECK_CLASSES(HOOK_NAME, ...) \ __NL__ \ @@ -98,7 +98,7 @@ template struct * to do check if a plugin defines a hook method with a specific __NL__ \ * signature. __NL__ \ */ __NL__ \ - DEFINE_HAS_METHOD_TRAITS(Plugin, HOOK_NAME, __NL__ \ + DEFINE_HAS_METHOD_TRAITS(GLUE2(Plugin, HOOK_VERSION), HOOK_NAME, __NL__ \ kaleidoscope::EventHandlerResult, __NL__ \ SIGNATURE) __NL__ \ __NL__ \ @@ -107,7 +107,7 @@ template struct */ __NL__ \ template __NL__ \ struct HookVersionImplemented_##HOOK_NAME __NL__ \ - : public Plugin_HasMethod_##HOOK_NAME __NL__ \ + : public GLUE4(Plugin, HOOK_VERSION, _HasMethod_, HOOK_NAME) __NL__ \ {}; #define _PREPARE_EVENT_HANDLER_SIGNATURE_CHECK_START(HOOK_NAME, ...) \ @@ -219,7 +219,7 @@ template struct */ __NL__ \ __attribute__((unused)) constexpr bool dummy2 __NL__ \ = ___________Culprit_Plugin___________ __NL__ \ - ::value; __NL__ \ + ::value; __NL__ \ } #define _PREPARE_EVENT_HANDLER_SIGNATURE_CHECK \ diff --git a/src/kaleidoscope_internal/type_traits/has_method.h b/src/kaleidoscope_internal/type_traits/has_method.h index 0628b7cd..3051deca 100644 --- a/src/kaleidoscope_internal/type_traits/has_method.h +++ b/src/kaleidoscope_internal/type_traits/has_method.h @@ -25,7 +25,7 @@ * implements a method with given signature. __NL__ \ */ __NL__ \ template __NL__ \ - struct PREFIX##_HasMethod_##METHOD_NAME __NL__ \ + struct GLUE3(PREFIX, _HasMethod_, METHOD_NAME) __NL__ \ { __NL__ \ /* Define a pointer to member function with the correct __NL__ \ * argument signature. The newly defined type is named __NL__ \