aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/handlekeys.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-15 18:38:18 +1000
committerDavid Walter Seikel2014-04-15 18:38:18 +1000
commitbbaa3db47599ba25949277e7075fa61ccc1c5a3c (patch)
tree63ec62f775c4e68de5a100388b6a3bfcd3a50c56 /handlekeys.c
parentAdd a showkey toy. Not standard, I'll see if there's an actual standard later. (diff)
downloadboxes-bbaa3db47599ba25949277e7075fa61ccc1c5a3c.zip
boxes-bbaa3db47599ba25949277e7075fa61ccc1c5a3c.tar.gz
boxes-bbaa3db47599ba25949277e7075fa61ccc1c5a3c.tar.bz2
boxes-bbaa3db47599ba25949277e7075fa61ccc1c5a3c.tar.xz
Change from using a bunch of callbacks to using one, with a structure and type.
Diffstat (limited to 'handlekeys.c')
-rw-r--r--handlekeys.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/handlekeys.c b/handlekeys.c
index df18088..7501dbd 100644
--- a/handlekeys.c
+++ b/handlekeys.c
@@ -176,10 +176,9 @@ static void handleSIGWINCH(int signalNumber)
176 sigWinch = 1; 176 sigWinch = 1;
177} 177}
178 178
179void handle_keys(long extra, 179void handle_keys(long extra, int (*handle_event)(long extra, struct keyevent *event))
180 int (*handle_sequence)(long extra, char *sequence, int isTranslated),
181 void (*handle_CSI)(long extra, char *command, int *params, int count))
182{ 180{
181 struct keyevent event;
183 fd_set selectFds; 182 fd_set selectFds;
184 struct timespec timeOut; 183 struct timespec timeOut;
185 struct sigaction sigAction, oldSigAction; 184 struct sigaction sigAction, oldSigAction;
@@ -261,6 +260,12 @@ void handle_keys(long extra,
261 else 260 else
262 { 261 {
263 buffIndex += j; 262 buffIndex += j;
263 // Send raw keystrokes, mostly for things like showkey.
264 event.type = HK_RAW;
265 event.sequence = buffer;
266 event.isTranslated = 0;
267 handle_event(extra, &event);
268
264 if (sizeof(buffer) < (buffIndex + 1)) // Ran out of buffer. 269 if (sizeof(buffer) < (buffIndex + 1)) // Ran out of buffer.
265 { 270 {
266 fprintf(stderr, "Full buffer - %s -> %s\n", buffer, sequence); 271 fprintf(stderr, "Full buffer - %s -> %s\n", buffer, sequence);
@@ -331,9 +336,18 @@ void handle_keys(long extra,
331 336
332 if ('M' == buffer[1]) 337 if ('M' == buffer[1])
333 { 338 {
334 // TODO - We have a mouse report, which is CSI M ..., where the rest is 339 // We have a mouse report, which is CSI M ..., where the rest is
335 // binary encoded, more or less. Not fitting into the CSI format. 340 // binary encoded, more or less. Not fitting into the CSI format.
336 // To make things worse, can't tell how long this will be. 341 // To make things worse, can't tell how long this will be.
342 // So leave it up to the caller to tell us if they used it.
343 event.type = HK_MOUSE;
344 event.sequence = buffer;
345 event.isTranslated = 0;
346 if (handle_event(extra, &event))
347 {
348 buffer[0] = buffIndex = 0;
349 sequence[0] = 0;
350 }
337 } 351 }
338 else 352 else
339 { 353 {
@@ -389,8 +403,12 @@ void handle_keys(long extra,
389 t = csFinal + strlen(csFinal) - 1; 403 t = csFinal + strlen(csFinal) - 1;
390 if (('\x40' <= (*t)) && ((*t) <= '\x7e')) 404 if (('\x40' <= (*t)) && ((*t) <= '\x7e'))
391 { 405 {
392 if (handle_CSI) 406 event.type = HK_CSI;
393 handle_CSI(extra, csFinal, csParams, p); 407 event.sequence = csFinal;
408 event.isTranslated = 1;
409 event.count = p;
410 event.params = csParams;
411 handle_event(extra, &event);
394 buffer[0] = buffIndex = 0; 412 buffer[0] = buffIndex = 0;
395 sequence[0] = 0; 413 sequence[0] = 0;
396 } 414 }
@@ -398,12 +416,15 @@ void handle_keys(long extra,
398 } 416 }
399 417
400 // Pass the result to the callback. 418 // Pass the result to the callback.
401 if ((handle_sequence) && (sequence[0] || buffer[0])) 419 if (sequence[0] || buffer[0])
402 { 420 {
403 char b[strlen(sequence) + strlen(buffer) + 1]; 421 char b[strlen(sequence) + strlen(buffer) + 1];
404 422
405 sprintf(b, "%s%s", sequence, buffer); 423 sprintf(b, "%s%s", sequence, buffer);
406 if (handle_sequence(extra, b, (0 != sequence[0]))) 424 event.type = HK_KEYS;
425 event.sequence = b;
426 event.isTranslated = (0 != sequence[0]);
427 if (handle_event(extra, &event))
407 { 428 {
408 buffer[0] = buffIndex = 0; 429 buffer[0] = buffIndex = 0;
409 sequence[0] = 0; 430 sequence[0] = 0;