]> git.sesse.net Git - vlc/blob - src/misc/action.c
d0be62f2db6b5ea9ecb28389be0dfc0e3544a8d8
[vlc] / src / misc / action.c
1 /*****************************************************************************
2  * action.c: key to action mapping
3  *****************************************************************************
4  * Copyright © 2008 Rémi Denis-Courmont
5  *           © 2009 Antoine Cellerier
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20  *****************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #include <vlc_common.h>
27 #include "../libvlc.h"
28 #include <vlc_keys.h>
29 #include <stdlib.h>
30
31 int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
32                        vlc_value_t prevkey, vlc_value_t curkey, void *priv)
33 {
34     const struct hotkey *key = priv;
35
36     (void)varname;
37     (void)prevkey;
38
39     while (key->i_key != curkey.i_int)
40     {
41         if (key->psz_action == NULL)
42             return VLC_SUCCESS; /* key is not mapped to anything */
43
44         key++;
45     }
46
47     return var_SetInteger (libvlc, "key-action", key->i_action);
48 }
49
50 static int actcmp(const void *key, const void *ent)
51 {
52     const struct action *act = ent;
53     return strcmp(key, act->name);
54 }
55
56 vlc_key_t vlc_GetActionId(const char *name)
57 {
58     const struct action *act;
59
60     act = bsearch(name, libvlc_actions, libvlc_actions_count, sizeof(*act),
61                   actcmp);
62     return (act != NULL) ? act->value : 0;
63 }
64