Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 1 | /* Public Domain Curses */ |
| 2 | |
| 3 | #include "pdcx11.h" |
| 4 | |
| 5 | RCSID("$Id: pdckbd.c,v 1.62 2008/07/14 04:24:52 wmcbrine Exp $") |
| 6 | |
| 7 | /*man-start************************************************************** |
| 8 | |
| 9 | Name: pdckbd |
| 10 | |
| 11 | Synopsis: |
| 12 | unsigned long PDC_get_input_fd(void); |
| 13 | |
| 14 | Description: |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 15 | PDC_get_input_fd() returns the file descriptor that PDCurses |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 16 | reads its input from. It can be used for select(). |
| 17 | |
| 18 | Portability X/Open BSD SYS V |
| 19 | PDC_get_input_fd - - - |
| 20 | |
| 21 | **man-end****************************************************************/ |
| 22 | |
| 23 | /* check if a key or mouse event is waiting */ |
| 24 | |
| 25 | bool PDC_check_key(void) |
| 26 | { |
| 27 | struct timeval socket_timeout = {0}; |
| 28 | int s; |
| 29 | |
| 30 | /* Is something ready to be read on the socket ? Must be a key. */ |
| 31 | |
| 32 | FD_ZERO(&xc_readfds); |
| 33 | FD_SET(xc_key_sock, &xc_readfds); |
| 34 | |
Stefan Reinauer | e11835e | 2011-10-31 12:54:00 -0700 | [diff] [blame] | 35 | if ((s = select(FD_SETSIZE, (FD_SET_CAST)&xc_readfds, NULL, |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 36 | NULL, &socket_timeout)) < 0) |
| 37 | XCursesExitCursesProcess(3, "child - exiting from " |
| 38 | "PDC_check_key select failed"); |
| 39 | |
| 40 | PDC_LOG(("%s:PDC_check_key() - returning %s\n", XCLOGMSG, |
| 41 | s ? "TRUE" : "FALSE")); |
| 42 | |
| 43 | return !!s; |
| 44 | } |
| 45 | |
| 46 | /* return the next available key or mouse event */ |
| 47 | |
| 48 | int PDC_get_key(void) |
| 49 | { |
| 50 | unsigned long newkey = 0; |
| 51 | int key = 0; |
| 52 | |
| 53 | if (XC_read_socket(xc_key_sock, &newkey, sizeof(unsigned long)) < 0) |
| 54 | XCursesExitCursesProcess(2, "exiting from PDC_get_key"); |
| 55 | |
| 56 | pdc_key_modifiers = (newkey >> 24) & 0xFF; |
| 57 | key = (int)(newkey & 0x00FFFFFF); |
| 58 | |
| 59 | if (key == KEY_MOUSE && SP->key_code) |
| 60 | { |
| 61 | if (XC_read_socket(xc_key_sock, &pdc_mouse_status, |
| 62 | sizeof(MOUSE_STATUS)) < 0) |
| 63 | XCursesExitCursesProcess(2, "exiting from PDC_get_key"); |
| 64 | } |
| 65 | |
| 66 | PDC_LOG(("%s:PDC_get_key() - key %d returned\n", XCLOGMSG, key)); |
| 67 | |
| 68 | return key; |
| 69 | } |
| 70 | |
| 71 | unsigned long PDC_get_input_fd(void) |
| 72 | { |
| 73 | PDC_LOG(("PDC_get_input_fd() - called\n")); |
| 74 | |
| 75 | return xc_key_sock; |
| 76 | } |
| 77 | |
| 78 | void PDC_set_keyboard_binary(bool on) |
| 79 | { |
| 80 | PDC_LOG(("PDC_set_keyboard_binary() - called\n")); |
| 81 | } |
| 82 | |
| 83 | /* discard any pending keyboard or mouse input -- this is the core |
| 84 | routine for flushinp() */ |
| 85 | |
| 86 | void PDC_flushinp(void) |
| 87 | { |
| 88 | PDC_LOG(("PDC_flushinp() - called\n")); |
| 89 | |
| 90 | while (PDC_check_key()) |
| 91 | PDC_get_key(); |
| 92 | } |
| 93 | |
| 94 | int PDC_mouse_set(void) |
| 95 | { |
| 96 | return OK; |
| 97 | } |
| 98 | |
| 99 | int PDC_modifiers_set(void) |
| 100 | { |
| 101 | return OK; |
| 102 | } |