From 6e5db3e5ba48b5e68efd38360a20ce127cd23578 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 10 Sep 2019 11:40:37 +0300 Subject: [PATCH] Pass modifier state to key_press and key_release functions --- source/systemkeyboardinput.cpp | 26 ++++++++++++++++++++++---- source/systemkeyboardinput.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/systemkeyboardinput.cpp b/source/systemkeyboardinput.cpp index f5657bd..a991832 100644 --- a/source/systemkeyboardinput.cpp +++ b/source/systemkeyboardinput.cpp @@ -7,7 +7,8 @@ namespace GLtk { SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k): InputMethod(r), - keyboard(k) + keyboard(k), + modifier_state(0) { keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press)); keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release)); @@ -19,8 +20,14 @@ bool SystemKeyboardInput::key_press(unsigned key) if(!root.is_visible()) return false; - // TODO modifiers - if(root.key_press(key, 0)) + if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R) + modifier_state |= MOD_SHIFT; + else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R) + modifier_state |= MOD_CTRL; + else if(key==Input::KEY_ALT_L || key==Input::KEY_ALT_R) + modifier_state |= MOD_ALT; + + if(root.key_press(key, modifier_state)) return true; switch(key) @@ -41,7 +48,18 @@ bool SystemKeyboardInput::key_press(unsigned key) bool SystemKeyboardInput::key_release(unsigned key) { if(root.is_visible()) - return root.key_release(key, 0); + { + bool result = root.key_release(key, modifier_state); + + if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R) + modifier_state &= ~MOD_SHIFT; + else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R) + modifier_state &= ~MOD_CTRL; + else if(key==Input::KEY_ALT_L || key==Input::KEY_ALT_R) + modifier_state &= ~MOD_ALT; + + return result; + } else return false; } diff --git a/source/systemkeyboardinput.h b/source/systemkeyboardinput.h index ae988ca..1b37e54 100644 --- a/source/systemkeyboardinput.h +++ b/source/systemkeyboardinput.h @@ -11,6 +11,7 @@ class SystemKeyboardInput: public InputMethod, public sigc::trackable { private: Input::Keyboard &keyboard; + unsigned modifier_state; public: SystemKeyboardInput(Root &, Input::Keyboard &); -- 2.43.0