[vlc-devel] commit: Skins2: Factor out getModKey() and getKeyState() (both used twice), use var_SetVariant() instead of var_Set(). (JP Dinger )
git version control
git at videolan.org
Sat Dec 5 22:35:06 CET 2009
vlc | branch: master | JP Dinger <jpd at videolan.org> | Mon Nov 16 13:01:49 2009 +0100| [da48f73ff3442c6b36283eb611422e93e4dee51e] | committer: JP Dinger
Skins2: Factor out getModKey() and getKeyState() (both used twice), use var_SetVariant() instead of var_Set().
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=da48f73ff3442c6b36283eb611422e93e4dee51e
---
modules/gui/skins2/events/evt_key.cpp | 10 ++++++++
modules/gui/skins2/events/evt_key.hpp | 3 ++
modules/gui/skins2/src/top_window.cpp | 40 +++++--------------------------
modules/gui/skins2/src/vout_window.cpp | 24 ++----------------
4 files changed, 23 insertions(+), 54 deletions(-)
diff --git a/modules/gui/skins2/events/evt_key.cpp b/modules/gui/skins2/events/evt_key.cpp
index 99d01ad..7bb3a32 100644
--- a/modules/gui/skins2/events/evt_key.cpp
+++ b/modules/gui/skins2/events/evt_key.cpp
@@ -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;
+}
+
diff --git a/modules/gui/skins2/events/evt_key.hpp b/modules/gui/skins2/events/evt_key.hpp
index ef50692..28d04cb 100644
--- a/modules/gui/skins2/events/evt_key.hpp
+++ b/modules/gui/skins2/events/evt_key.hpp
@@ -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
diff --git a/modules/gui/skins2/src/top_window.cpp b/modules/gui/skins2/src/top_window.cpp
index d3d4a74..279a28f 100644
--- a/modules/gui/skins2/src/top_window.cpp
+++ b/modules/gui/skins2/src/top_window.cpp
@@ -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 );
}
}
diff --git a/modules/gui/skins2/src/vout_window.cpp b/modules/gui/skins2/src/vout_window.cpp
index 193660e..0bb5235 100644
--- a/modules/gui/skins2/src/vout_window.cpp
+++ b/modules/gui/skins2/src/vout_window.cpp
@@ -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() );
}
More information about the vlc-devel
mailing list