1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2018 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "keyboard.hxx"
22 #include "Command.hxx"
23 #include "Bindings.hxx"
24 #include "GlobalBindings.hxx"
26 #include "ncmpc_curses.h"
37 return key == ERR || key == '\0';
42 translate_key(int key)
44 return GetGlobalKeyBindings().FindKey(key);
48 keyboard_event(gcc_unused GIOChannel *source,
49 gcc_unused GIOCondition condition,
52 auto *w = (WINDOW *)data;
59 if (key == KEY_MOUSE) {
62 /* retrieve the mouse event from curses */
70 do_mouse_event({event.x, event.y}, event.bstate);
77 Command cmd = translate_key(key);
78 if (cmd == Command::NONE)
83 if (!do_input_event(cmd))
91 keyboard_init(WINDOW *w)
93 GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
94 g_io_add_watch(channel, G_IO_IN, keyboard_event, w);
95 g_io_channel_unref(channel);
99 keyboard_unread(int key)
104 Command cmd = translate_key(key);
105 if (cmd != Command::NONE)