X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fkeyboard.c;h=d990e3691e7854d011672527062f9d51fc7ede70;hb=42947fa12f82681e2b7062ab3b9c5aacc1b203cf;hp=5bd43e573ab3e173b26542ccbf676418068cf778;hpb=5d149c626cc6a22ab707f6784755bca6bb8ae353;p=ncmpc.git diff --git a/src/keyboard.c b/src/keyboard.c index 5bd43e5..d990e36 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -20,12 +20,34 @@ #include "keyboard.h" #include "command.h" #include "ncmpc.h" +#include "ncmpc_curses.h" #include "Compiler.h" #include #include +gcc_pure +static command_t +translate_key(int key) +{ + if (key == ERR || key == '\0') + 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(stdscr)); +} + static gboolean keyboard_event(gcc_unused GIOChannel *source, gcc_unused GIOCondition condition, @@ -49,3 +71,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); +}