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