/*********************************************************************** * This Source Code Form is subject to the terms of the Mozilla Public * * License, v. 2.0. If a copy of the MPL was not distributed with this * * file, You can obtain one at http://mozilla.org/MPL/2.0/. * ***********************************************************************/ #include #include #include #include #include #include #include #include #include "getch.h" #define FKEY(k) ((k) >= KEY_F1 && (k) <= KEY_F10) || (k) == KEY_F12 || (k) == KEY_F11 #define NOTNUMPAD(k) ((k) >= KEY_HOME && (k) <= KEY_DELETE) #define EVENT_DEVICE_GLOB "/dev/input/by-path/*-event-kbd" static struct termios oldTermAttributes; static int discardRead(unsigned int length) { char buffer[length]; ssize_t bytesRead; int flags = fcntl(STDIN_FILENO, F_GETFL); fcntl(STDIN_FILENO, F_SETFL, flags|O_NONBLOCK); if( (bytesRead = fread(buffer, sizeof(char), length, stdin)) == -1) { perror("discardRead"); } fcntl(STDIN_FILENO, F_SETFL, flags); return (int)bytesRead; } static int getEventDevice(const char * device) { glob_t search; int globResult = glob( EVENT_DEVICE_GLOB, GLOB_NOSORT, NULL, &search ); if(0 != globResult) { globfree(&search); return -1; } if(search.gl_pathc == 0) { globfree(&search); return -1; } size_t pathLength; for(int i = 0; i