DriverSDL: add support for key modifiers.
--- a/sdlterm/cython/sdlterm.pyx Wed Jan 23 00:59:21 2013 +0100
+++ b/sdlterm/cython/sdlterm.pyx Wed Jan 23 21:49:40 2013 +0100
@@ -13,6 +13,7 @@
cdef struct Event_key:
char *keyname
Py_UNICODE unicode
+ int mod
cdef struct Event_mouse:
int x, y
@@ -107,7 +108,8 @@
char = event.key.unicode
if char == '\x00':
char = None
- return ('keypress', keyname, char)
+ mod = event.key.mod
+ return ('keypress', keyname, char, mod)
if event.type == event.RESIZE:
return ('resize',)
if event.type == event.QUIT:
--- a/sdlterm/src/sdlterm.cc Wed Jan 23 00:59:21 2013 +0100
+++ b/sdlterm/src/sdlterm.cc Wed Jan 23 21:49:40 2013 +0100
@@ -432,6 +432,7 @@
if (!event.key.unicode)
break; // continue loop (unknown key)
}
+ event.key.mod = _translate_mod(sdl_event.key.keysym.mod);
event_ready = true;
break;
}
@@ -530,6 +531,17 @@
}
+int Terminal::_translate_mod(SDLMod mod)
+{
+ int res = 0;
+ if (mod & KMOD_SHIFT) res |= KeyMod::SHIFT;
+ if (mod & KMOD_ALT) res |= KeyMod::ALT;
+ if (mod & KMOD_CTRL) res |= KeyMod::CTRL;
+ if (mod & KMOD_META) res |= KeyMod::META;
+ return res;
+}
+
+
Uint32 Terminal::_wait_event_callback(Uint32 interval, void *param)
{
SDL_Event event;
--- a/sdlterm/src/sdlterm.h Wed Jan 23 00:59:21 2013 +0100
+++ b/sdlterm/src/sdlterm.h Wed Jan 23 21:49:40 2013 +0100
@@ -18,6 +18,17 @@
};
+namespace KeyMod
+{
+ enum {
+ SHIFT = 1<<0,
+ ALT = 1<<1,
+ CTRL = 1<<2,
+ META = 1<<3,
+ };
+};
+
+
class ColorMap
{
private:
@@ -175,6 +186,7 @@
{
char keyname[10];
Uint32 unicode;
+ int mod;
} key;
struct
{
@@ -226,6 +238,7 @@
int _mousemove_last_y;
const char *_translate_keyname(SDLKey sym);
+ int _translate_mod(SDLMod mod);
static Uint32 _wait_event_callback(Uint32 interval, void *param);
static Uint32 _blink_toggle_callback(Uint32 interval, void *param);
};