From d7a319db8ddacf3075dbd0dd0e2588c5278d750b Mon Sep 17 00:00:00 2001 From: Bryan Tan Date: Fri, 20 Mar 2020 14:41:22 -0700 Subject: [PATCH] Add Mouse+Keyboard Combo device class --- src/control/settings/Settings.h | 1 + src/gui/inputdevices/InputContext.cpp | 10 ++++++++-- src/gui/inputdevices/InputEvents.cpp | 2 ++ src/gui/inputdevices/InputEvents.h | 1 + src/gui/inputdevices/KeyboardInputHandler.cpp | 11 +++++++---- ui/settingsDeviceClassConfig.glade | 1 + 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/control/settings/Settings.h b/src/control/settings/Settings.h index 6905e5bf..1c9010f3 100644 --- a/src/control/settings/Settings.h +++ b/src/control/settings/Settings.h @@ -48,6 +48,7 @@ enum class InputDeviceTypeOption { Pen = 2, Eraser = 3, Touchscreen = 4, + MouseKeyboardCombo = 5, }; class ButtonConfig; diff --git a/src/gui/inputdevices/InputContext.cpp b/src/gui/inputdevices/InputContext.cpp index 97afcb19..1fdda6b2 100644 --- a/src/gui/inputdevices/InputContext.cpp +++ b/src/gui/inputdevices/InputContext.cpp @@ -103,6 +103,10 @@ auto InputContext::handle(GdkEvent* sourceEvent) -> bool { return this->stylusHandler->handle(event); } + if (event->deviceClass == INPUT_DEVICE_MOUSE_KEYBOARD_COMBO) { + return this->mouseHandler->handle(event) || this->keyboardHandler->handle(event); + } + // handle mouse devices if (event->deviceClass == INPUT_DEVICE_MOUSE) { return this->mouseHandler->handle(event); @@ -259,8 +263,10 @@ void InputContext::printDebug(GdkEvent* event) { "GDK_SOURCE_TOUCHPAD", "GDK_SOURCE_TRACKPOINT", "GDK_SOURCE_TABLET_PAD"}; GdkDevice* device = gdk_event_get_source_device(event); message += "Source device:\t" + gdkInputSources[gdk_device_get_source(device)] + "\n"; - string gdkInputClasses[] = {"INPUT_DEVICE_MOUSE", "INPUT_DEVICE_PEN", "INPUT_DEVICE_ERASER", - "INPUT_DEVICE_TOUCHSCREEN", "INPUT_DEVICE_KEYBOARD", "INPUT_DEVICE_IGNORE"}; + string gdkInputClasses[] = {"INPUT_DEVICE_MOUSE", "INPUT_DEVICE_PEN", + "INPUT_DEVICE_ERASER", "INPUT_DEVICE_TOUCHSCREEN", + "INPUT_DEVICE_KEYBOARD", "INPUT_DEVICE_MOUSE_KEYBOARD_COMBO", + "INPUT_DEVICE_IGNORE"}; InputDeviceClass deviceClass = InputEvents::translateDeviceType(device, this->getSettings()); message += "Device Class:\t" + gdkInputClasses[deviceClass] + "\n"; diff --git a/src/gui/inputdevices/InputEvents.cpp b/src/gui/inputdevices/InputEvents.cpp index 57c4d050..d4e40ae7 100644 --- a/src/gui/inputdevices/InputEvents.cpp +++ b/src/gui/inputdevices/InputEvents.cpp @@ -86,6 +86,8 @@ auto InputEvents::translateDeviceType(const string& name, GdkInputSource source, return INPUT_DEVICE_ERASER; case InputDeviceTypeOption::Touchscreen: return INPUT_DEVICE_TOUCHSCREEN; + case InputDeviceTypeOption::MouseKeyboardCombo: + return INPUT_DEVICE_MOUSE_KEYBOARD_COMBO; default: return INPUT_DEVICE_IGNORE; } diff --git a/src/gui/inputdevices/InputEvents.h b/src/gui/inputdevices/InputEvents.h index 8c4c372a..22a3eeab 100644 --- a/src/gui/inputdevices/InputEvents.h +++ b/src/gui/inputdevices/InputEvents.h @@ -40,6 +40,7 @@ enum InputDeviceClass { INPUT_DEVICE_ERASER, INPUT_DEVICE_TOUCHSCREEN, INPUT_DEVICE_KEYBOARD, + INPUT_DEVICE_MOUSE_KEYBOARD_COMBO, INPUT_DEVICE_IGNORE }; diff --git a/src/gui/inputdevices/KeyboardInputHandler.cpp b/src/gui/inputdevices/KeyboardInputHandler.cpp index 0726ff49..f6ed4c85 100644 --- a/src/gui/inputdevices/KeyboardInputHandler.cpp +++ b/src/gui/inputdevices/KeyboardInputHandler.cpp @@ -13,10 +13,11 @@ KeyboardInputHandler::KeyboardInputHandler(InputContext* inputContext): Abstract KeyboardInputHandler::~KeyboardInputHandler() = default; auto KeyboardInputHandler::handleImpl(InputEvent* event) -> bool { - auto keyEvent = reinterpret_cast(event->sourceEvent); GtkXournal* xournal = inputContext->getXournal(); + GdkEvent* gdkEvent = event->sourceEvent; - if (keyEvent->type == GDK_KEY_PRESS) { + if (gdkEvent->type == GDK_KEY_PRESS) { + auto keyEvent = reinterpret_cast(gdkEvent); EditSelection* selection = xournal->selection; if (selection) { int d = 3; @@ -46,9 +47,11 @@ auto KeyboardInputHandler::handleImpl(InputEvent* event) -> bool { return true; } } - return xournal->view->onKeyPressEvent(keyEvent); + } else if (gdkEvent->type == GDK_KEY_RELEASE) { + auto keyEvent = reinterpret_cast(gdkEvent); + return inputContext->getView()->onKeyReleaseEvent(keyEvent); } - return inputContext->getView()->onKeyReleaseEvent(keyEvent); + return false; } diff --git a/ui/settingsDeviceClassConfig.glade b/ui/settingsDeviceClassConfig.glade index f8551e5c..732fa335 100644 --- a/ui/settingsDeviceClassConfig.glade +++ b/ui/settingsDeviceClassConfig.glade @@ -40,6 +40,7 @@ Disabled Mouse + Mouse+Keyboard Combo Pen Eraser Touchscreen