]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/systemkeyboardinput.cpp
Add an input method subsystem
[libs/gltk.git] / source / systemkeyboardinput.cpp
diff --git a/source/systemkeyboardinput.cpp b/source/systemkeyboardinput.cpp
new file mode 100644 (file)
index 0000000..cedddd1
--- /dev/null
@@ -0,0 +1,37 @@
+#include <msp/input/keys.h>
+#include "root.h"
+#include "systemkeyboardinput.h"
+
+namespace Msp {
+namespace GLtk {
+
+SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
+       InputMethod(r),
+       keyboard(k)
+{
+       keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press));
+       keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release));
+       keyboard.signal_character.connect(sigc::mem_fun(this, &SystemKeyboardInput::character));
+}
+
+bool SystemKeyboardInput::key_press(unsigned key)
+{
+       // TODO modifiers
+       if(root.key_press(key, 0))
+               return true;
+       
+       return false;
+}
+
+bool SystemKeyboardInput::key_release(unsigned key)
+{
+       return root.key_release(key, 0);
+}
+
+bool SystemKeyboardInput::character(StringCodec::unichar ch)
+{
+       return root.character(ch);
+}
+
+} // namespace GLtk
+} // namespace Msp