[vlc-devel] commit: Add key-action variable - automatically mapped action from key-pressed ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu Mar 27 21:42:50 CET 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Wed Mar 26 22:20:47 2008 +0200| [88226a802f38e75d0dbea4a74b8ec108a42ca653]

Add key-action variable - automatically mapped action from key-pressed

So for, each hotkey callback had to lookup the hotkey table everytime
a key was pressed, which is fairly wasteful.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=88226a802f38e75d0dbea4a74b8ec108a42ca653
---

 src/Makefile.am     |    1 +
 src/libvlc-common.c |    5 +++++
 src/libvlc.h        |    4 +++-
 src/misc/action.c   |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 597e2fd..f690d1c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -329,6 +329,7 @@ SOURCES_libvlc_common = \
 	misc/threads.c \
 	misc/stats.c \
 	misc/cpu.c \
+	misc/action.c \
 	config/configuration.h \
 	config/core.c \
 	config/chain.c \
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index cf2e525..33a80c1 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -734,9 +734,12 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      * Initialize hotkey handling
      */
     var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER );
+    var_Create( p_libvlc, "key-action", VLC_VAR_INTEGER );
     p_libvlc->p_hotkeys = malloc( libvlc_hotkeys_size );
     /* Do a copy (we don't need to modify the strings) */
     memcpy( p_libvlc->p_hotkeys, libvlc_hotkeys, libvlc_hotkeys_size );
+    var_AddCallback( p_libvlc, "key-pressed", vlc_key_to_action,
+                     p_libvlc->p_hotkeys );
 
     /* Initialize interaction */
     p_libvlc->p_interaction = interaction_Init( p_libvlc );
@@ -1031,6 +1034,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
     FREENULL( p_libvlc->psz_datadir );
     FREENULL( p_libvlc->psz_cachedir );
     FREENULL( p_libvlc->psz_configfile );
+    var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
+                     p_libvlc->p_hotkeys );
     FREENULL( p_libvlc->p_hotkeys );
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
diff --git a/src/libvlc.h b/src/libvlc.h
index 046f0f4..30a2137 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -27,9 +27,11 @@
 
 extern const char vlc_usage[];
 
+/* Hotkey stuff */
 extern const struct hotkey libvlc_hotkeys[];
 extern const size_t libvlc_hotkeys_size;
-
+extern int vlc_key_to_action (vlc_object_t *, const char *,
+                              vlc_value_t, vlc_value_t, void *);
 
 /*
  * OS-specific initialization
diff --git a/src/misc/action.c b/src/misc/action.c
new file mode 100644
index 0000000..a9f79f3
--- /dev/null
+++ b/src/misc/action.c
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * action.c: key to action mapping
+ *****************************************************************************
+ * Copyright © 2008 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc/vlc.h>
+#include "../libvlc.h"
+
+int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
+                       vlc_value_t prevkey, vlc_value_t curkey, void *priv)
+{
+    const struct hotkey *key = priv;
+
+    (void)varname;
+    (void)prevkey;
+
+    while (key->i_key != curkey.i_int)
+    {
+        if (key->psz_action == NULL)
+            return VLC_SUCCESS; /* key is not mapped to anything */
+
+        key++;
+    }
+
+    return var_SetInteger (libvlc, "key-action", key->i_action);
+}
+




More information about the vlc-devel mailing list