X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fkeyboard.c;h=edf7e61a6c5536fe2fdcfbe0fa37351b695c7b7a;hb=6827c0b2b729b2ba0bd481f7dfc28bd339c05c86;hp=226306cf7543fc1823fb167b115baa2ad54f7c03;hpb=018511981ff4ea6798d8e5683e64f945b49d5637;p=ncmpc.git diff --git a/src/keyboard.c b/src/keyboard.c index 226306c..edf7e61 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -20,12 +20,41 @@ #include "keyboard.h" #include "command.h" #include "ncmpc.h" +#include "ncmpc_curses.h" +#include "screen.h" #include "Compiler.h" #include #include +static bool +ignore_key(int key) +{ + return key == ERR || key == '\0'; +} + +gcc_pure +static command_t +translate_key(int key) +{ + if (ignore_key(key)) + return CMD_NONE; + +#ifdef HAVE_GETMOUSE + if (key == KEY_MOUSE) + return CMD_MOUSE_EVENT; +#endif + + return get_key_command(key); +} + +static command_t +get_keyboard_command(void) +{ + return translate_key(wgetch(screen.main_window.w)); +} + static gboolean keyboard_event(gcc_unused GIOChannel *source, gcc_unused GIOCondition condition, @@ -35,7 +64,7 @@ keyboard_event(gcc_unused GIOChannel *source, command_t cmd = get_keyboard_command(); if (cmd != CMD_NONE) - if (do_input_event(cmd) != 0) + if (!do_input_event(cmd)) return FALSE; end_input_event(); @@ -49,3 +78,11 @@ keyboard_init(void) g_io_add_watch(channel, G_IO_IN, keyboard_event, NULL); g_io_channel_unref(channel); } + +void +keyboard_unread(int key) +{ + command_t cmd = translate_key(key); + if (cmd != CMD_NONE) + do_input_event(cmd); +}