]> git.sesse.net Git - vlc/commitdiff
Skins2: Factor out getModKey() and getKeyState() (both used twice), use var_SetVarian...
authorJP Dinger <jpd@videolan.org>
Mon, 16 Nov 2009 12:01:49 +0000 (13:01 +0100)
committerJP Dinger <jpd@videolan.org>
Sat, 5 Dec 2009 21:25:41 +0000 (22:25 +0100)
modules/gui/skins2/events/evt_key.cpp
modules/gui/skins2/events/evt_key.hpp
modules/gui/skins2/src/top_window.cpp
modules/gui/skins2/src/vout_window.cpp

index 99d01ad32c694e60ac575bfcd91c360ea5dd9404..7bb3a3241e7ffb2b3465a9488ab5890b4326d318 100644 (file)
@@ -54,3 +54,13 @@ const string EvtKey::getAsString() const
     return event;
 }
 
+int EvtKey::getModKey() const {
+    int i = getKey();
+    if( getMod() & kModAlt )
+        i |= KEY_MODIFIER_ALT;
+    if( getMod() & kModCtrl )
+        i |= KEY_MODIFIER_CTRL;
+    if( getMod() & kModShift )
+        i |= KEY_MODIFIER_SHIFT;
+}
+
index ef50692c98844c2ae84111f3eb7b23ce34b7b641..28d04cba376c416defb0f8515c4306e286833cfa 100644 (file)
@@ -44,6 +44,9 @@ public:
     virtual const string getAsString() const;
 
     int getKey() const { return m_key; }
+    int getModKey() const;
+
+    ActionType_t getKeyState() const { return m_action; }
 
 private:
     /// The concerned key, stored according to the '#define's in vlc_keys.h
index d3d4a74a834eff83481d6136cdb3f15a006484a6..279a28fbcb12765ddde46d60f26790fb6c202d05 100644 (file)
@@ -218,7 +218,7 @@ void TopWindow::processEvent( EvtKey &rEvtKey )
     }
 
     // Only do the action when the key is down
-    if( rEvtKey.getAsString().find( "key:down") != string::npos )
+    if( rEvtKey.getKeyState() == EvtKey::kDown )
     {
         //XXX not to be hardcoded!
         // Ctrl-S = Change skin
@@ -240,31 +240,14 @@ void TopWindow::processEvent( EvtKey &rEvtKey )
             return;
         }
 
-        vlc_value_t val;
-        // Set the key
-        val.i_int = rEvtKey.getKey();
-        // Set the modifiers
-        if( rEvtKey.getMod() & EvtInput::kModAlt )
-        {
-            val.i_int |= KEY_MODIFIER_ALT;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModCtrl )
-        {
-            val.i_int |= KEY_MODIFIER_CTRL;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModShift )
-        {
-            val.i_int |= KEY_MODIFIER_SHIFT;
-        }
-
-        var_Set( getIntf()->p_libvlc, "key-pressed", val );
+        var_SetInteger( getIntf()->p_libvlc, "key-pressed",
+                        rEvtKey.getModKey() );
     }
 
     // Always store the modifier, which can be needed for scroll events
     m_currModifier = rEvtKey.getMod();
 }
 
-
 void TopWindow::processEvent( EvtScroll &rEvtScroll )
 {
     // Raise the windows
@@ -289,20 +272,11 @@ void TopWindow::processEvent( EvtScroll &rEvtScroll )
     }
     else
     {
-        // Treat the scroll event as a hotkey
-        vlc_value_t val;
-        if( rEvtScroll.getDirection() == EvtScroll::kUp )
-        {
-            val.i_int = KEY_MOUSEWHEELUP;
-        }
-        else
-        {
-            val.i_int = KEY_MOUSEWHEELDOWN;
-        }
-        // Add the modifiers
-        val.i_int |= m_currModifier;
+        // Treat the scroll event as a hotkey plus current modifiers
+        int i = (rEvtScroll.getDirection() == EvtScroll::kUp ?
+                 KEY_MOUSEWHEELUP : KEY_MOUSEWHEELDOWN) | m_currModifier;
 
-        var_Set( getIntf()->p_libvlc, "key-pressed", val );
+        var_SetInteger( getIntf()->p_libvlc, "key-pressed", i );
     }
 }
 
index 193660e2c36f3918662e5efb2f1eff398cda4680..0bb52354b71c4f117e1f6bb6cbccf68efa21edc0 100644 (file)
@@ -97,26 +97,8 @@ void VoutWindow::setFullscreen( bool b_fullscreen )
 void VoutWindow::processEvent( EvtKey &rEvtKey )
 {
     // Only do the action when the key is down
-    if( rEvtKey.getAsString().find( "key:down") != string::npos )
-    {
-        vlc_value_t val;
-        // Set the key
-        val.i_int = rEvtKey.getKey();
-        // Set the modifiers
-        if( rEvtKey.getMod() & EvtInput::kModAlt )
-        {
-            val.i_int |= KEY_MODIFIER_ALT;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModCtrl )
-        {
-            val.i_int |= KEY_MODIFIER_CTRL;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModShift )
-        {
-            val.i_int |= KEY_MODIFIER_SHIFT;
-        }
-
-        var_Set( getIntf()->p_libvlc, "key-pressed", val );
-    }
+    if( rEvtKey.getKeyState() == EvtKey::kDown )
+        var_SetInteger( getIntf()->p_libvlc, "key-pressed",
+                         rEvtKey.getModKey() );
 }