1 /*
2  * Copyright 2008-2013 Various Authors
3  * Copyright 2004-2006 Timo Hirvonen
4  *
5  * keys.[ch] by Frank Terbeck <ft@bewatermyfriend.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * 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, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef CMUS_KEYS_H
22 #define CMUS_KEYS_H
23 
24 #include "uchar.h"
25 
26 #if defined(__sun__) || defined(__CYGWIN__)
27 /* TIOCGWINSZ */
28 #include <termios.h>
29 #include <ncurses.h>
30 #else
31 #include <curses.h>
32 #endif
33 
34 enum key_context {
35 	CTX_BROWSER,
36 	CTX_COMMON,
37 	CTX_FILTERS,
38 	CTX_LIBRARY,
39 	CTX_PLAYLIST,
40 	CTX_QUEUE,
41 	CTX_SETTINGS,
42 };
43 #define NR_CTXS (CTX_SETTINGS + 1)
44 
45 #if NCURSES_MOUSE_VERSION <= 1
46 #define BUTTON5_PRESSED ((REPORT_MOUSE_POSITION) | (BUTTON2_PRESSED))
47 #endif
48 
49 struct key {
50 	const char *name;
51 	int key;
52 	uchar ch;
53 };
54 
55 struct binding {
56 	struct binding *next;
57 	const struct key *key;
58 	enum key_context ctx;
59 	char cmd[];
60 };
61 
62 extern const char * const key_context_names[NR_CTXS + 1];
63 extern const struct key key_table[];
64 extern struct binding *key_bindings[NR_CTXS];
65 
66 void show_binding(const char *context, const char *key);
67 int key_bind(const char *context, const char *key, const char *cmd, int force);
68 int key_unbind(const char *context, const char *key, int force);
69 
70 void normal_mode_ch(uchar ch);
71 void normal_mode_key(int key);
72 void normal_mode_mouse(MEVENT *event);
73 
74 #endif
75