sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
aaslnkbd.c
1#include <setjmp.h>
2#include <signal.h>
3#include <stdio.h>
4#include <sys/time.h>
5#include <sys/types.h>
6#include <unistd.h>
7#include "config.h"
8#ifdef SLANG_KBDDRIVER
9#include <slang.h>
10#ifdef GPM_MOUSEDRIVER
11#include <gpm.h>
12#endif
13#include "aalib.h"
14static int iswaiting;
15static FILE *f;
16static jmp_buf buf;
17int __slang_keyboard;
18extern int __slang_is_up;
19extern int __resized_slang;
20/*extern int __curses_usegpm; */
21static int uninitslang;
22#if 0
23int __curses_x, __curses_y, __curses_buttons;
24int __curses_keyboard;
25#endif
26
27#ifdef SIGWINCH
28static void handler(int i)
29{
30 __resized_slang = 2;
31 signal(SIGWINCH, handler);
32 if (iswaiting)
33 longjmp(buf, 1);
34}
35#endif
36static int slang_init(struct aa_context *context, int mode)
37{
38 if (!__slang_is_up) {
39 fflush(stdout);
40 SLtt_get_terminfo();
41 __slang_is_up = 1;
42 uninitslang = 1;
43 }
44 f = fopen("/dev/null", "r");
45 if (SLang_init_tty(-1, 0, 0) == -1) {
46 return 0;
47 }
48 if (-1 == SLkp_init()) {
49 return 0;
50 }
51 __slang_keyboard = 1;
52#ifdef GPM_MOUSEDRIVER
53 aa_recommendlowmouse("gpm");
54#endif
55
56#ifdef SIGWINCH
57 signal(SIGWINCH, handler);
58#endif
59 return 1;
60}
61static void slang_uninit(aa_context * c)
62{
63 if (uninitslang) {
64 uninitslang = 0;
65 __slang_is_up = 0;
66 }
67 SLang_reset_tty();
68}
69static int slang_getchar(aa_context * c1, int wait)
70{
71 int c, flag = 0;
72#ifdef GPM_MOUSEDRIVER
73 static Gpm_Event ev;
74#endif
75 struct timeval tv;
76 fd_set readfds;
77
78 if (wait) {
79 setjmp(buf);
80 iswaiting = 1;
81 } else
82 iswaiting = 0;
83 if (__resized_slang == 2) {
84 iswaiting = 0;
85 __resized_slang = 1;
86 return (AA_RESIZE);
87 }
88 /*non-gpm way */
89 if (!wait) {
90#ifdef GPM_MOUSEDRIVER
91 if (gpm_fd == -1) {
92#endif
93 if (!SLang_input_pending(0))
94 return AA_NONE;
95#ifdef GPM_MOUSEDRIVER
96 } else {
97 GPM_DRAWPOINTER(&ev);
98 tv.tv_sec = 0;
99 tv.tv_usec = 0;
100 FD_ZERO(&readfds);
101 FD_SET(gpm_fd, &readfds);
102 FD_SET(STDIN_FILENO, &readfds);
103 if (!(flag = select(gpm_fd + 1, &readfds, NULL, NULL, &tv)))
104 return AA_NONE;
105 }
106#endif
107 }
108#ifdef GPM_MOUSEDRIVER
109 if (gpm_fd != -1) {
110 GPM_DRAWPOINTER(&ev);
111 while (!flag) {
112 FD_ZERO(&readfds);
113 FD_SET(gpm_fd, &readfds);
114 FD_SET(STDIN_FILENO, &readfds);
115 tv.tv_sec = 60;
116 flag = select(gpm_fd + 1, &readfds, NULL, NULL, &tv);
117 }
118 if (flag == -1) {
119 printf("error!\n");
120 return (AA_NONE);
121 }
122 if (FD_ISSET(gpm_fd, &readfds)) {
123 if (Gpm_GetEvent(&ev) && gpm_handler
124 && ((*gpm_handler) (&ev, gpm_data))) {
125 gpm_hflag = 1;
126 return AA_MOUSE;
127 }
128 }
129 }
130#endif
131 c = SLkp_getkey();
132 iswaiting = 0;
133
134 if (__resized_slang == 2) {
135 __resized_slang = 1;
136 return (AA_RESIZE);
137 }
138 if (c == 27)
139 return (AA_ESC);
140 if (c > 0 && c < 128 && c != 127)
141 return (c);
142 switch (c) {
143 case SL_KEY_ERR:
144 return (AA_NONE);
145 case SL_KEY_LEFT:
146 return (AA_LEFT);
147 case SL_KEY_RIGHT:
148 return (AA_RIGHT);
149 case SL_KEY_UP:
150 return (AA_UP);
151 case SL_KEY_DOWN:
152 return (AA_DOWN);
153 case SL_KEY_BACKSPACE:
154 case 127:
155 return (AA_BACKSPACE);
156 }
157 return (AA_UNKNOWN);
158}
159
160
161struct aa_kbddriver kbd_slang_d =
162{
163 "slang", "Slang keyboard driver 1.0",
164 0,
165 slang_init,
166 slang_uninit,
167 slang_getchar,
168};
169#endif