]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keys.cpp
Add EventSource abstraction layer below Window
[libs/gui.git] / source / input / keys.cpp
index 4446a7f731568fe828d1b823bc93bf56bd00e675..15f729abe16652ea0f5304e540e9d39333791f76 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -9,6 +9,7 @@ Distributed under the LGPL
 #ifdef WIN32
 #include <windows.h>
 #else
+#include <X11/X.h>
 #include <X11/keysym.h>
 #endif
 #include <msp/core/except.h>
@@ -103,6 +104,15 @@ unsigned keymap[Msp::Input::N_KEYS_]=
 #endif
 };
 
+unsigned modmap[Msp::Input::N_MODS_]=
+{
+#ifndef WIN32
+       ShiftMask, ControlMask, Mod1Mask, Mod4Mask
+#else
+       1, 2, 4, 8
+#endif
+};
+
 }
 
 namespace Msp {
@@ -131,10 +141,19 @@ unsigned key_from_sys(unsigned code)
 
 unsigned key_to_sys(unsigned key)
 {
-       if(key>N_KEYS_)
+       if(key>=N_KEYS_)
                throw InvalidParameterValue("Key out of range");
        return keymap[key];
 }
 
+unsigned mod_from_sys(unsigned mod)
+{
+       unsigned result;
+       for(unsigned i=0; i<N_MODS_; ++i)
+               if(mod&modmap[i])
+                       result|=1<<i;
+       return result;
+}
+
 } // namespace Input
 } // namespace Msp