Code

screen_utils: move KEY_MOUSE check to ignore_key(), avoid recursion
[ncmpc.git] / src / keyboard.c
index c5d8c7814199781863188c7e892acfe3bca77ae6..5042af2a3648e9e0b1237e54b44de3fda42cb8a4 100644 (file)
 #include "command.h"
 #include "ncmpc.h"
 #include "ncmpc_curses.h"
+#include "screen.h"
 #include "Compiler.h"
 
 #include <glib.h>
 
 #include <unistd.h>
 
+gcc_pure
 static command_t
-get_keyboard_command(void)
+translate_key(int key)
 {
-       int key = wgetch(stdscr);
        if (key == ERR || key == '\0')
                return CMD_NONE;
 
@@ -42,6 +43,12 @@ get_keyboard_command(void)
        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,
@@ -69,9 +76,7 @@ keyboard_init(void)
 void
 keyboard_unread(int key)
 {
-       ungetch(key);
-
-       command_t cmd = get_keyboard_command();
+       command_t cmd = translate_key(key);
        if (cmd != CMD_NONE)
                do_input_event(cmd);
 }