[vlc-commits] hotkeys: map mouse wheel actions in core

Rémi Denis-Courmont git at videolan.org
Thu Jan 31 22:25:34 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jan 31 23:16:35 2013 +0200| [d83927d402e835ead4159bc673179a182a78f733] | committer: Rémi Denis-Courmont

hotkeys: map mouse wheel actions in core

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

 modules/control/hotkeys.c |   29 +-------------------
 src/config/keys.c         |   66 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index e9348e3..7196352 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -55,7 +55,6 @@ struct intf_sys_t
     vout_thread_t      *p_last_vout;
     int                 p_channels[ CHANNELS_NUMBER ]; /* contains registered
                                                         * channel IDs */
-    int                 i_mousewheel_mode;
 };
 
 /*****************************************************************************
@@ -108,8 +107,6 @@ static int Open( vlc_object_t *p_this )
     p_intf->p_sys = p_sys;
 
     p_sys->p_last_vout = NULL;
-    p_intf->p_sys->i_mousewheel_mode =
-        var_InheritInteger( p_intf, "hotkeys-mousewheel-mode" );
 
     var_AddCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf );
     var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
@@ -924,44 +921,20 @@ static int SpecialKeyEvent( vlc_object_t *libvlc, char const *psz_var,
                             vlc_value_t oldval, vlc_value_t newval,
                             void *p_data )
 {
-    intf_thread_t *p_intf = (intf_thread_t *)p_data;
-    int i_action = 0;
-
+    (void)p_data;
     (void)psz_var;
     (void)oldval;
 
-    int i_mode = p_intf->p_sys->i_mousewheel_mode;
-
     /* Special action for mouse event */
     /* FIXME: rework hotkeys handling to allow more than 1 event
      * to trigger one same action */
     switch (newval.i_int & ~KEY_MODIFIER)
     {
-        case KEY_MOUSEWHEELUP:
-            i_action = (i_mode == MOUSEWHEEL_VOLUME ) ? ACTIONID_VOL_UP
-                                 : ACTIONID_JUMP_FORWARD_EXTRASHORT;
-            break;
-        case KEY_MOUSEWHEELDOWN:
-            i_action = (i_mode == MOUSEWHEEL_VOLUME ) ? ACTIONID_VOL_DOWN
-                                : ACTIONID_JUMP_BACKWARD_EXTRASHORT;
-            break;
-        case KEY_MOUSEWHEELLEFT:
-            i_action = (i_mode == MOUSEWHEEL_VOLUME ) ?
-                        ACTIONID_JUMP_BACKWARD_EXTRASHORT : ACTIONID_VOL_DOWN;
-            break;
-        case KEY_MOUSEWHEELRIGHT:
-            i_action = (i_mode == MOUSEWHEEL_VOLUME ) ?
-                        ACTIONID_JUMP_FORWARD_EXTRASHORT : ACTIONID_VOL_UP;
-            break;
         case KEY_MENU:
             var_SetBool( libvlc, "intf-popupmenu", true );
             break;
     }
 
-    if( i_mode == NO_MOUSEWHEEL ) return VLC_SUCCESS;
-
-    if( i_action )
-        return PutAction( p_intf, i_action );
     return VLC_SUCCESS;
 }
 
diff --git a/src/config/keys.c b/src/config/keys.c
index 7b429ed..e1a568a 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -38,6 +38,7 @@
 #ifdef HAVE_SEARCH_H
 # include <search.h>
 #endif
+#include <errno.h>
 
 #include <vlc_common.h>
 #include <vlc_keys.h>
@@ -406,13 +407,35 @@ static int vlc_key_to_action (vlc_object_t *obj, const char *varname,
 }
 
 /**
+ * Adds a mapping from a certain key code to a certain action.
+ */
+static int vlc_AddMapping (void **map, uint32_t keycode, vlc_action_t action)
+{
+    struct mapping *entry = malloc (sizeof (*entry));
+    if (entry == NULL)
+        return ENOMEM;
+    entry->key = keycode;
+    entry->action = action;
+
+    struct mapping **pent = tsearch (entry, map, keycmp);
+    if (unlikely(pent == NULL))
+        return ENOMEM;
+    if (*pent != entry)
+    {
+        free (entry);
+        return EEXIST;
+    }
+    return 0;
+}
+
+/**
  * Sets up all key mappings for a given action.
  * \param map tree (of struct mapping entries) to write mappings to
  * \param confname VLC configuration item to read mappings from
  * \param action action ID
  */
-static void vlc_MapAction (vlc_object_t *obj, void **map,
-                           const char *confname, vlc_action_t action)
+static void vlc_InitAction (vlc_object_t *obj, void **map,
+                            const char *confname, vlc_action_t action)
 {
     char *keys = var_InheritString (obj, confname);
     if (keys == NULL)
@@ -429,25 +452,12 @@ static void vlc_MapAction (vlc_object_t *obj, void **map,
             continue;
         }
 
-        struct mapping *entry = malloc (sizeof (*entry));
-        if (entry == NULL)
-            continue;
-        entry->key = code;
-        entry->action = action;
-
-        struct mapping **pent = tsearch (entry, map, keycmp);
-        if (unlikely(pent == NULL))
-            continue;
-        if (*pent != entry)
-        {
-            free (entry);
+        if (vlc_AddMapping (map, code, action) == EEXIST)
             msg_Warn (obj, "Key \"%s\" bound to multiple actions", key);
-        }
     }
     free (keys);
 }
 
-
 /**
  * Initializes the key map from configuration.
  */
@@ -485,12 +495,30 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
         char name[12 + MAXACTION];
 
         snprintf (name, sizeof (name), "global-key-%s", actions[i].name);
-        vlc_MapAction (obj, &as->map, name + 7, actions[i].value);
-        vlc_MapAction (obj, &as->global_map, name, actions[i].value);
+        vlc_InitAction (obj, &as->map, name + 7, actions[i].value);
+        vlc_InitAction (obj, &as->global_map, name, actions[i].value);
     }
-
     keys->psz_action = NULL;
 
+    /* Initialize mouse wheel events */
+    int mousemode = var_InheritInteger (obj, "hotkeys-mousewheel-mode");
+    if (mousemode < 2)
+    {
+        vlc_AddMapping (&as->map,
+                        mousemode ? KEY_MOUSEWHEELLEFT : KEY_MOUSEWHEELUP,
+                        ACTIONID_VOL_UP);
+        vlc_AddMapping (&as->map,
+                        mousemode ? KEY_MOUSEWHEELRIGHT : KEY_MOUSEWHEELDOWN,
+                        ACTIONID_VOL_DOWN);
+        vlc_AddMapping (&as->map,
+                        mousemode ? KEY_MOUSEWHEELUP : KEY_MOUSEWHEELLEFT,
+                        ACTIONID_JUMP_FORWARD_EXTRASHORT);
+        vlc_AddMapping (&as->map,
+                        mousemode ? KEY_MOUSEWHEELDOWN : KEY_MOUSEWHEELRIGHT,
+                        ACTIONID_JUMP_BACKWARD_EXTRASHORT);
+    }
+
+
     libvlc->p_hotkeys = as->keys;
     var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map);
     var_AddCallback (obj, "global-key-pressed", vlc_key_to_action,



More information about the vlc-commits mailing list