Commit fe5af2a1 authored by JP Dinger's avatar JP Dinger

Skins2: Factor out duplicate code (mod), and provide a const accessor to the...

Skins2: Factor out duplicate code (mod), and provide a const accessor to the keymap: std::map<>::operator[] will create empty nodes if they don't exist already.
parent f73b0909
...@@ -48,36 +48,39 @@ ...@@ -48,36 +48,39 @@
// Maximum interval between clicks for a double-click (in microsec) // Maximum interval between clicks for a double-click (in microsec)
int X11Loop::m_dblClickDelay = 400000; int X11Loop::m_dblClickDelay = 400000;
X11Loop::keymap_t X11Loop::m_keymap;
X11Loop::X11Loop( intf_thread_t *pIntf, X11Display &rDisplay ): X11Loop::X11Loop( intf_thread_t *pIntf, X11Display &rDisplay ):
OSLoop( pIntf ), m_rDisplay( rDisplay ), m_exit( false ), OSLoop( pIntf ), m_rDisplay( rDisplay ), m_exit( false ),
m_lastClickTime( 0 ), m_lastClickPosX( 0 ), m_lastClickPosY( 0 ) m_lastClickTime( 0 ), m_lastClickPosX( 0 ), m_lastClickPosY( 0 )
{ {
// Initialize the key map if(m_keymap.empty()) {
keysymToVlcKey[XK_F1] = KEY_F1; // Initialize the key map where VLC keys differ from X11 keys.
keysymToVlcKey[XK_F2] = KEY_F2; m_keymap[XK_F1] = KEY_F1;
keysymToVlcKey[XK_F3] = KEY_F3; m_keymap[XK_F2] = KEY_F2;
keysymToVlcKey[XK_F4] = KEY_F4; m_keymap[XK_F3] = KEY_F3;
keysymToVlcKey[XK_F5] = KEY_F5; m_keymap[XK_F4] = KEY_F4;
keysymToVlcKey[XK_F6] = KEY_F6; m_keymap[XK_F5] = KEY_F5;
keysymToVlcKey[XK_F7] = KEY_F7; m_keymap[XK_F6] = KEY_F6;
keysymToVlcKey[XK_F8] = KEY_F8; m_keymap[XK_F7] = KEY_F7;
keysymToVlcKey[XK_F9] = KEY_F9; m_keymap[XK_F8] = KEY_F8;
keysymToVlcKey[XK_F10] = KEY_F10; m_keymap[XK_F9] = KEY_F9;
keysymToVlcKey[XK_F11] = KEY_F11; m_keymap[XK_F10] = KEY_F10;
keysymToVlcKey[XK_F12] = KEY_F12; m_keymap[XK_F11] = KEY_F11;
keysymToVlcKey[XK_Return] = KEY_ENTER; m_keymap[XK_F12] = KEY_F12;
keysymToVlcKey[XK_Escape] = KEY_ESC; m_keymap[XK_Return] = KEY_ENTER;
keysymToVlcKey[XK_Left] = KEY_LEFT; m_keymap[XK_Escape] = KEY_ESC;
keysymToVlcKey[XK_Right] = KEY_RIGHT; m_keymap[XK_Left] = KEY_LEFT;
keysymToVlcKey[XK_Up] = KEY_UP; m_keymap[XK_Right] = KEY_RIGHT;
keysymToVlcKey[XK_Down] = KEY_DOWN; m_keymap[XK_Up] = KEY_UP;
keysymToVlcKey[XK_Home] = KEY_HOME; m_keymap[XK_Down] = KEY_DOWN;
keysymToVlcKey[XK_End] = KEY_END; m_keymap[XK_Home] = KEY_HOME;
keysymToVlcKey[XK_Prior] = KEY_PAGEUP; m_keymap[XK_End] = KEY_END;
keysymToVlcKey[XK_Next] = KEY_PAGEDOWN; m_keymap[XK_Prior] = KEY_PAGEUP;
keysymToVlcKey[XK_Delete] = KEY_DELETE; m_keymap[XK_Next] = KEY_PAGEDOWN;
keysymToVlcKey[XK_Insert] = KEY_INSERT; m_keymap[XK_Delete] = KEY_DELETE;
m_keymap[XK_Insert] = KEY_INSERT;
}
} }
...@@ -142,6 +145,19 @@ void X11Loop::exit() ...@@ -142,6 +145,19 @@ void X11Loop::exit()
} }
inline int X11Loop::X11ModToMod( unsigned state )
{
int mod = EvtInput::kModNone;
if( state & Mod1Mask )
mod |= EvtInput::kModAlt;
if( state & ControlMask )
mod |= EvtInput::kModCtrl;
if( state & ShiftMask )
mod |= EvtInput::kModShift;
return mod;
}
void X11Loop::handleX11Event() void X11Loop::handleX11Event()
{ {
XEvent event; XEvent event;
...@@ -230,20 +246,7 @@ void X11Loop::handleX11Event() ...@@ -230,20 +246,7 @@ void X11Loop::handleX11Event()
break; break;
} }
// Get the modifiers int mod = X11ModToMod( event.xbutton.state );
int mod = EvtInput::kModNone;
if( event.xbutton.state & Mod1Mask )
{
mod |= EvtInput::kModAlt;
}
if( event.xbutton.state & ControlMask )
{
mod |= EvtInput::kModCtrl;
}
if( event.xbutton.state & ShiftMask )
{
mod |= EvtInput::kModShift;
}
// Check for double clicks // Check for double clicks
if( event.type == ButtonPress && if( event.type == ButtonPress &&
...@@ -316,43 +319,12 @@ void X11Loop::handleX11Event() ...@@ -316,43 +319,12 @@ void X11Loop::handleX11Event()
case KeyPress: case KeyPress:
case KeyRelease: case KeyRelease:
{ {
EvtKey::ActionType_t action = EvtKey::kDown; // Take the first keysym = lower case character, and translate.
int mod = EvtInput::kModNone; int key = keysymToVlcKey( XLookupKeysym( &event.xkey, 0 ) );
// Get the modifiers
if( event.xkey.state & Mod1Mask )
{
mod |= EvtInput::kModAlt;
}
if( event.xkey.state & ControlMask )
{
mod |= EvtInput::kModCtrl;
}
if( event.xkey.state & ShiftMask )
{
mod |= EvtInput::kModShift;
}
// Take the first keysym = lower case character EvtKey evt( getIntf(), key,
KeySym keysym = XLookupKeysym( &event.xkey, 0 ); event.type==KeyRelease ? EvtKey::kUp : EvtKey::kDown,
X11ModToMod( event.xkey.state ) );
// Get VLC key code from the keysym
int key = keysymToVlcKey[keysym];
if( !key )
{
// Normal key
key = keysym;
}
switch( event.type )
{
case KeyPress:
action = EvtKey::kDown;
break;
case KeyRelease:
action = EvtKey::kUp;
break;
}
EvtKey evt( getIntf(), key, action, mod );
pWin->processEvent( evt ); pWin->processEvent( evt );
break; break;
} }
......
...@@ -61,7 +61,15 @@ private: ...@@ -61,7 +61,15 @@ private:
static int m_dblClickDelay; static int m_dblClickDelay;
/// Map associating special (i.e. non ascii) virtual key codes with /// Map associating special (i.e. non ascii) virtual key codes with
/// internal vlc key codes /// internal vlc key codes
map<KeySym, int> keysymToVlcKey; typedef std::map<KeySym, int> keymap_t;
static keymap_t m_keymap;
/// Translate X11 KeySyms to VLC key codes.
static int keysymToVlcKey( KeySym keysym )
{
keymap_t::const_iterator i=m_keymap.find(keysym);
return i!=m_keymap.end() ? (i->second) : keysym;
}
static int X11ModToMod( unsigned state );
// Private because it's a singleton // Private because it's a singleton
X11Loop( intf_thread_t *pIntf, X11Display &rDisplay ); X11Loop( intf_thread_t *pIntf, X11Display &rDisplay );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment