Commit d83927d4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

hotkeys: map mouse wheel actions in core

parent a0cb1c29
...@@ -55,7 +55,6 @@ struct intf_sys_t ...@@ -55,7 +55,6 @@ struct intf_sys_t
vout_thread_t *p_last_vout; vout_thread_t *p_last_vout;
int p_channels[ CHANNELS_NUMBER ]; /* contains registered int p_channels[ CHANNELS_NUMBER ]; /* contains registered
* channel IDs */ * channel IDs */
int i_mousewheel_mode;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -108,8 +107,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -108,8 +107,6 @@ static int Open( vlc_object_t *p_this )
p_intf->p_sys = p_sys; p_intf->p_sys = p_sys;
p_sys->p_last_vout = NULL; 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-pressed", SpecialKeyEvent, p_intf );
var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, 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, ...@@ -924,44 +921,20 @@ static int SpecialKeyEvent( vlc_object_t *libvlc, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *p_data ) void *p_data )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_data; (void)p_data;
int i_action = 0;
(void)psz_var; (void)psz_var;
(void)oldval; (void)oldval;
int i_mode = p_intf->p_sys->i_mousewheel_mode;
/* Special action for mouse event */ /* Special action for mouse event */
/* FIXME: rework hotkeys handling to allow more than 1 event /* FIXME: rework hotkeys handling to allow more than 1 event
* to trigger one same action */ * to trigger one same action */
switch (newval.i_int & ~KEY_MODIFIER) 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: case KEY_MENU:
var_SetBool( libvlc, "intf-popupmenu", true ); var_SetBool( libvlc, "intf-popupmenu", true );
break; break;
} }
if( i_mode == NO_MOUSEWHEEL ) return VLC_SUCCESS;
if( i_action )
return PutAction( p_intf, i_action );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#ifdef HAVE_SEARCH_H #ifdef HAVE_SEARCH_H
# include <search.h> # include <search.h>
#endif #endif
#include <errno.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_keys.h> #include <vlc_keys.h>
...@@ -405,14 +406,36 @@ static int vlc_key_to_action (vlc_object_t *obj, const char *varname, ...@@ -405,14 +406,36 @@ static int vlc_key_to_action (vlc_object_t *obj, const char *varname,
return var_SetInteger (obj, "key-action", (*pent)->action); return var_SetInteger (obj, "key-action", (*pent)->action);
} }
/**
* 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. * Sets up all key mappings for a given action.
* \param map tree (of struct mapping entries) to write mappings to * \param map tree (of struct mapping entries) to write mappings to
* \param confname VLC configuration item to read mappings from * \param confname VLC configuration item to read mappings from
* \param action action ID * \param action action ID
*/ */
static void vlc_MapAction (vlc_object_t *obj, void **map, static void vlc_InitAction (vlc_object_t *obj, void **map,
const char *confname, vlc_action_t action) const char *confname, vlc_action_t action)
{ {
char *keys = var_InheritString (obj, confname); char *keys = var_InheritString (obj, confname);
if (keys == NULL) if (keys == NULL)
...@@ -429,25 +452,12 @@ static void vlc_MapAction (vlc_object_t *obj, void **map, ...@@ -429,25 +452,12 @@ static void vlc_MapAction (vlc_object_t *obj, void **map,
continue; continue;
} }
struct mapping *entry = malloc (sizeof (*entry)); if (vlc_AddMapping (map, code, action) == EEXIST)
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);
msg_Warn (obj, "Key \"%s\" bound to multiple actions", key); msg_Warn (obj, "Key \"%s\" bound to multiple actions", key);
}
} }
free (keys); free (keys);
} }
/** /**
* Initializes the key map from configuration. * Initializes the key map from configuration.
*/ */
...@@ -485,12 +495,30 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc) ...@@ -485,12 +495,30 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
char name[12 + MAXACTION]; char name[12 + MAXACTION];
snprintf (name, sizeof (name), "global-key-%s", actions[i].name); snprintf (name, sizeof (name), "global-key-%s", actions[i].name);
vlc_MapAction (obj, &as->map, name + 7, actions[i].value); vlc_InitAction (obj, &as->map, name + 7, actions[i].value);
vlc_MapAction (obj, &as->global_map, name, actions[i].value); vlc_InitAction (obj, &as->global_map, name, actions[i].value);
} }
keys->psz_action = NULL; 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; libvlc->p_hotkeys = as->keys;
var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map); var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map);
var_AddCallback (obj, "global-key-pressed", vlc_key_to_action, var_AddCallback (obj, "global-key-pressed", vlc_key_to_action,
......
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