summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-09-30 07:23:10 +0300
committerDevaev Maxim <[email protected]>2019-09-30 07:23:10 +0300
commiteb445ca45dc6cd002d2d13889000adda0639f81d (patch)
tree30ae3c43f4ca9667dab5a3e204a55f3ccfe9efcc
parentf29c5296cb9b5213574e657fcd151a232f4b2170 (diff)
serial hid: added middle button
-rw-r--r--hid/src/main.cpp36
-rw-r--r--kvmd/plugins/hid/serial.py4
2 files changed, 22 insertions, 18 deletions
diff --git a/hid/src/main.cpp b/hid/src/main.cpp
index 4d2b0c3c..37957cc7 100644
--- a/hid/src/main.cpp
+++ b/hid/src/main.cpp
@@ -49,10 +49,12 @@
#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13
#define PROTO_CMD_MOUSE_WHEEL_EVENT 0x14
// -----------------------------------------
-#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
-#define PROTO_CMD_MOUSE_BUTTON_LEFT_STATE 0b00001000
-#define PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT 0b01000000
-#define PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE 0b00000100
+#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
+#define PROTO_CMD_MOUSE_BUTTON_LEFT_STATE 0b00001000
+#define PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT 0b01000000
+#define PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE 0b00000100
+#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_SELECT 0b00100000
+#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_STATE 0b00000010
// -----------------------------------------------------------------------------
@@ -86,21 +88,21 @@ INLINE void cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
INLINE void cmdMouseButtonEvent(const uint8_t *buffer) { // 1 byte
uint8_t state = buffer[0];
- if (state & PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT) {
- if (state & PROTO_CMD_MOUSE_BUTTON_LEFT_STATE) {
- SingleAbsoluteMouse.press(MOUSE_LEFT);
- } else {
- SingleAbsoluteMouse.release(MOUSE_LEFT);
+# define PROCESS_BUTTON(name) { \
+ if (state & PROTO_CMD_MOUSE_BUTTON_##name##_SELECT) { \
+ if (state & PROTO_CMD_MOUSE_BUTTON_##name##_STATE) { \
+ SingleAbsoluteMouse.press(MOUSE_##name); \
+ } else { \
+ SingleAbsoluteMouse.release(MOUSE_##name); \
+ } \
+ } \
}
- }
- if (state & PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT) {
- if (state & PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE) {
- SingleAbsoluteMouse.press(MOUSE_RIGHT);
- } else {
- SingleAbsoluteMouse.release(MOUSE_RIGHT);
- }
- }
+ PROCESS_BUTTON(LEFT);
+ PROCESS_BUTTON(RIGHT);
+ PROCESS_BUTTON(MIDDLE);
+
+# undef PROCESS_BUTTON
}
INLINE void cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 31ba0fd6..40eb3268 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -102,7 +102,7 @@ class _MouseMoveEvent(_IntEvent):
@dataclasses.dataclass(frozen=True)
class _MouseButtonEvent(_BoolEvent):
def __post_init__(self) -> None:
- assert self.name in ["left", "right"]
+ assert self.name in ["left", "right", "middle"]
def make_command(self) -> bytes:
code = 0
@@ -110,6 +110,8 @@ class _MouseButtonEvent(_BoolEvent):
code = (0b10000000 | (0b00001000 if self.state else 0))
elif self.name == "right":
code = (0b01000000 | (0b00000100 if self.state else 0))
+ elif self.name == "middle":
+ code = (0b00100000 | (0b00000010 if self.state else 0))
assert code, self
return b"\x13" + bytes([code]) + b"\x00\x00\x00"