From b370681111efce35838ef962d1ea187ed90b2157 Mon Sep 17 00:00:00 2001 From: Cy Rossignol Date: Mon, 2 Apr 2018 05:10:44 +0100 Subject: [PATCH] Fix warping while dragging the mouse Before this change, we couldn't use the full functionality of the plugin's warp feature to drag an item (by holding down a mouse button key). The plugin would reset the warp state during each scan cycle, so we could only warp the pointer to a cell in the top-level grid. This fix enables warping repeatedly into sub-cells while holding a mouse button. --- src/Kaleidoscope-MouseKeys.cpp | 6 ++++++ src/MouseWrapper.cpp | 8 +++++++- src/MouseWrapper.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Kaleidoscope-MouseKeys.cpp b/src/Kaleidoscope-MouseKeys.cpp index 4455dde4..2e7de67e 100644 --- a/src/Kaleidoscope-MouseKeys.cpp +++ b/src/Kaleidoscope-MouseKeys.cpp @@ -83,6 +83,12 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON; if (keyIsPressed(keyState)) { + // Reset warp state on initial mouse button key-down only so we can use + // warp keys to drag-and-drop: + if (keyToggledOn(keyState)) { + MouseWrapper.reset_warping(); + } + MouseWrapper.pressButton(button); } else if (keyToggledOff(keyState)) { MouseWrapper.release_button(button); diff --git a/src/MouseWrapper.cpp b/src/MouseWrapper.cpp index 9476a237..54b361f3 100644 --- a/src/MouseWrapper.cpp +++ b/src/MouseWrapper.cpp @@ -24,11 +24,11 @@ void MouseWrapper_::begin(void) { void MouseWrapper_::pressButton(uint8_t button) { kaleidoscope::hid::pressMouseButtons(button); - end_warping(); } void MouseWrapper_::release_button(uint8_t button) { kaleidoscope::hid::releaseMouseButtons(button); + end_warping(); } void MouseWrapper_::warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width) { @@ -49,6 +49,12 @@ void MouseWrapper_::end_warping() { is_warping = false; } +void MouseWrapper_::reset_warping() { + if (is_warping == true) { + begin_warping(); + } +} + void MouseWrapper_::warp(uint8_t warp_cmd) { if (is_warping == false) { begin_warping(); diff --git a/src/MouseWrapper.h b/src/MouseWrapper.h index 732d2af7..e16b7733 100644 --- a/src/MouseWrapper.h +++ b/src/MouseWrapper.h @@ -28,6 +28,7 @@ class MouseWrapper_ { static void begin(void); static void move(int8_t x, int8_t y); static void warp(uint8_t warp_cmd); + static void reset_warping(); static void pressButton(uint8_t button); static void release_button(uint8_t button); static uint8_t accelStep;