diff --git a/plugins/Kaleidoscope-Pointer/README.md b/plugins/Kaleidoscope-Pointer/README.md new file mode 100644 index 00000000..c303e63c --- /dev/null +++ b/plugins/Kaleidoscope-Pointer/README.md @@ -0,0 +1 @@ +# Pointer diff --git a/plugins/Kaleidoscope-Pointer/library.properties b/plugins/Kaleidoscope-Pointer/library.properties new file mode 100644 index 00000000..3dfc691a --- /dev/null +++ b/plugins/Kaleidoscope-Pointer/library.properties @@ -0,0 +1,7 @@ +name=Kaleidoscope-Pointer +version=0.0.0 +sentence=Pointing device support for Kaleidoscope +maintainer=Kaleidoscope's Developers +url=https://github.com/keyboardio/Kaleidoscope +author=Keyboardio +paragraph= diff --git a/plugins/Kaleidoscope-Pointer/src/Kaleidoscope-Pointer.h b/plugins/Kaleidoscope-Pointer/src/Kaleidoscope-Pointer.h new file mode 100644 index 00000000..f6341588 --- /dev/null +++ b/plugins/Kaleidoscope-Pointer/src/Kaleidoscope-Pointer.h @@ -0,0 +1,19 @@ +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 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/plugin/Pointer.h" diff --git a/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.cpp b/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.cpp new file mode 100644 index 00000000..0bf17dee --- /dev/null +++ b/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.cpp @@ -0,0 +1,64 @@ +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 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 . + */ + +#include + +#include "kaleidoscope/Runtime.h" +#include "Kaleidoscope-FocusSerial.h" + +namespace kaleidoscope { +namespace plugin { + +// ============================================================================= +// Event Handlers + +// ----------------------------------------------------------------------------- +EventHandlerResult Pointer::onNameQuery() { + return ::Focus.sendName(F("Pointer")); +} + +// ----------------------------------------------------------------------------- +EventHandlerResult Pointer::onSetup(void) { + kaleidoscope::Runtime.hid().mouse().setup(); + + return EventHandlerResult::OK; +} + +// ----------------------------------------------------------------------------- +EventHandlerResult Pointer::afterEachCycle() { + Runtime.hid().mouse().sendReport(); + + return EventHandlerResult::OK; +} + +// ----------------------------------------------------------------------------- +EventHandlerResult Pointer::onPointerSensorEvent(PointerEvent &event) { + if (event.key != POINTER_MOTION && event.key != POINTER_SCROLL) + return EventHandlerResult::OK; + + if (event.key == POINTER_MOTION) { + Runtime.hid().mouse().move(event.x, event.y, 0, 0); + } else if (event.key == POINTER_SCROLL) { + Runtime.hid().mouse().move(0, 0, event.v, event.h); + } + + return EventHandlerResult::EVENT_CONSUMED; +} + +} // namespace plugin +} // namespace kaleidoscope + +kaleidoscope::plugin::Pointer Pointer; diff --git a/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.h b/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.h new file mode 100644 index 00000000..1272ef7b --- /dev/null +++ b/plugins/Kaleidoscope-Pointer/src/kaleidoscope/plugin/Pointer.h @@ -0,0 +1,37 @@ +// -*- mode: c++ -*- +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 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/Runtime.h" + +namespace kaleidoscope { +namespace plugin { + +class Pointer: public kaleidoscope::Plugin { + public: + Pointer() {} + + EventHandlerResult onSetup(); + EventHandlerResult onNameQuery(); + EventHandlerResult onPointerSensorEvent(PointerEvent &event); +}; + +} +} + +extern kaleidoscope::plugin::Pointer Pointer; diff --git a/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h b/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h index 0a3630f2..a872d4d0 100644 --- a/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h +++ b/plugins/Kaleidoscope-Ranges/src/Kaleidoscope-Ranges.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Ranges -- Common ranges, used by a number of Kaleidoscope plugins. - * Copyright (C) 2016, 2017, 2019 Keyboard.io, Inc + * Copyright (C) 2016-2021 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 @@ -83,6 +83,8 @@ enum : uint16_t { OS_META_STICKY, OS_ACTIVE_STICKY, OS_CANCEL, + POINTER_MOTION, + POINTER_SCROLL, SAFE_START, KALEIDOSCOPE_SAFE_START = SAFE_START diff --git a/src/kaleidoscope/PointerEvent.cpp b/src/kaleidoscope/PointerEvent.cpp new file mode 100644 index 00000000..89167171 --- /dev/null +++ b/src/kaleidoscope/PointerEvent.cpp @@ -0,0 +1,23 @@ +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 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 . + */ + +#include "kaleidoscope/PointerEvent.h" + +namespace kaleidoscope { + +PointerEventId PointerEvent::last_id_ = 0; + +} // namespace kaleidoscope diff --git a/src/kaleidoscope/PointerEvent.h b/src/kaleidoscope/PointerEvent.h new file mode 100644 index 00000000..da1bff17 --- /dev/null +++ b/src/kaleidoscope/PointerEvent.h @@ -0,0 +1,68 @@ +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2021 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 // for uint8_t, int8_t + +#include "kaleidoscope/key_defs.h" // for Key, Key_NoKey +#include "kaleidoscope/KeyAddr.h" // for KeyAddr + +namespace kaleidoscope { + +typedef int8_t PointerEventId; + +struct PointerEvent { + + public: + // Constructor for plugin use when regenerating an event with specific ID: + PointerEvent(KeyAddr addr, int8_t x, int8_t y, int8_t h, int8_t v, + Key key = Key_NoKey, PointerEventId id = last_id_) + : addr(addr), x(x), y(y), h(h), v(v), key(key), id_(id) {} + + PointerEventEvent() : id_(last_id_) {} + + // For use by sensor creating a new event from a physical sensor event. + static PointerEvent next(KeyAddr addr, int8_t x, int8_t y, int8_t h, int8_t v) { + return PointerEvent(addr, x, y, h, v, Key_NoKey, ++last_id_); + } + + PointerEventId id() const { + return id_; + } + void swapId(PointerEvent &other) { + PointerEventId tmp_id = id_; + id_ = other.id_; + other.id_ = tmp_id; + } + + KeyAddr addr = KeyAddr::none(); + int8_t x = 0; + int8_t y = 0; + int8_t h = 0; + int8_t v = 0; + Key key = Key_NoKey; + + private: + // serial number of the event: + static PointerEventId last_id_; + PointerEventId id_; +}; + +} // namespace kaleidoscope + +typedef kaleidoscope::PointerEventId PointerEventId; +typedef kaleidoscope::PointerEvent PointerEvent; diff --git a/src/kaleidoscope/event_handlers.h b/src/kaleidoscope/event_handlers.h index 11ca03e9..9f9f4024 100644 --- a/src/kaleidoscope/event_handlers.h +++ b/src/kaleidoscope/event_handlers.h @@ -173,6 +173,21 @@ class SignatureCheckDummy {}; (KeyEvent &event), __NL__ \ (event), ##__VA_ARGS__) __NL__ \ __NL__ \ + /* Function called for every physical pointer sensor event (motion */ __NL__ \ + /* and/or scrolling). The `event` parameter is passed by reference */ __NL__ \ + /* so all of its properties (key, motion, scrolling) can be changed. */ __NL__ \ + /* If it returns EventHandlerResult::OK, the next handler will be */ __NL__ \ + /* passed the event; otherwise Kaleidoscope will stop processing it. */ __NL__ \ + /* Plugins that implement this handler must not process the same */ __NL__ \ + /* event twice in order to prevent handler loops. */ __NL__ \ + OPERATION(onPointerSensorEvent, __NL__ \ + 2, __NL__ \ + _CURRENT_IMPLEMENTATION, __NL__ \ + _ABORTABLE, __NL__ \ + (), (), (), /* non template */ __NL__ \ + (PointerEvent &event), __NL__ \ + (event), ##_VA_ARGS__) __NL__ \ + __NL__ \ /* Function called for every logical key event, including ones that */ __NL__ \ /* originate from a physical keyswitch and ones that are injected */ __NL__ \ /* by plugins. The `event` parameter is passed by reference so its */ __NL__ \