Lines 20-25
Link Here
|
20 |
#include <sys/ioctl.h> |
20 |
#include <sys/ioctl.h> |
21 |
#include <sys/wait.h> |
21 |
#include <sys/wait.h> |
22 |
#include <sys/mman.h> |
22 |
#include <sys/mman.h> |
|
|
23 |
#include <sys/select.h> |
23 |
#include <pthread.h> |
24 |
#include <pthread.h> |
24 |
#include <errno.h> |
25 |
#include <errno.h> |
25 |
#include <dirent.h> |
26 |
#include <dirent.h> |
Lines 29-34
Link Here
|
29 |
#include "common.h" |
30 |
#include "common.h" |
30 |
#include "daemon.h" |
31 |
#include "daemon.h" |
31 |
|
32 |
|
|
|
33 |
#define EV_BUF_SIZE 8 |
34 |
|
32 |
/* Threading structures */ |
35 |
/* Threading structures */ |
33 |
pthread_mutex_t mtx_tty = PTHREAD_MUTEX_INITIALIZER; |
36 |
pthread_mutex_t mtx_tty = PTHREAD_MUTEX_INITIALIZER; |
34 |
pthread_mutex_t mtx_paint = PTHREAD_MUTEX_INITIALIZER; |
37 |
pthread_mutex_t mtx_paint = PTHREAD_MUTEX_INITIALIZER; |
Lines 41-47
Link Here
|
41 |
int ctty = CTTY_VERBOSE; |
44 |
int ctty = CTTY_VERBOSE; |
42 |
|
45 |
|
43 |
/* File descriptors */ |
46 |
/* File descriptors */ |
44 |
int fd_evdev = -1; |
47 |
int fd_evdevs[MAX_KBDS]; |
|
|
48 |
int evdev_count = 0; |
45 |
#ifdef CONFIG_GPM |
49 |
#ifdef CONFIG_GPM |
46 |
int fd_gpm = -1; |
50 |
int fd_gpm = -1; |
47 |
#endif |
51 |
#endif |
Lines 51-57
Link Here
|
51 |
|
55 |
|
52 |
/* Misc settings */ |
56 |
/* Misc settings */ |
53 |
char *notify[2]; |
57 |
char *notify[2]; |
54 |
char *evdev = NULL; |
|
|
55 |
|
58 |
|
56 |
/* Service list */ |
59 |
/* Service list */ |
57 |
list svcs = { NULL, NULL }; |
60 |
list svcs = { NULL, NULL }; |
Lines 400-455
Link Here
|
400 |
} |
403 |
} |
401 |
} |
404 |
} |
402 |
|
405 |
|
|
|
406 |
__u16 get_ev_key_pressed(int fd_evdev, int ev_buf_size, |
407 |
struct input_event *ev_buf) { |
408 |
size_t rb; |
409 |
int i; |
410 |
rb = read(fd_evdev, ev_buf, sizeof(struct input_event) * ev_buf_size); |
411 |
if (rb < (int) sizeof(struct input_event)) |
412 |
return 0; |
413 |
|
414 |
for (i = 0; i < (int) (rb / sizeof(struct input_event)); i++) { |
415 |
if (ev_buf[i].type != EV_KEY || ev_buf[i].value != 0) |
416 |
continue; |
417 |
return ev_buf[i].code; |
418 |
} |
419 |
} |
420 |
|
403 |
/* |
421 |
/* |
404 |
* Event device monitor thread. |
422 |
* Event device monitor thread. |
405 |
*/ |
423 |
*/ |
406 |
void* thf_switch_evdev(void *unused) |
424 |
void* thf_switch_evdev(void *unused) |
407 |
{ |
425 |
{ |
408 |
int i, h, oldstate; |
426 |
int i, h, oldstate, nfds, retval, fd_evdev; |
409 |
size_t rb; |
427 |
fd_set rfds; |
410 |
struct input_event ev[8]; |
428 |
struct input_event ev_buf[EV_BUF_SIZE]; |
|
|
429 |
__u16 key_pressed = 0; |
411 |
|
430 |
|
412 |
while (1) { |
431 |
while (1) { |
413 |
rb = read(fd_evdev, ev, sizeof(struct input_event)*8); |
432 |
nfds = 0, fd_evdev = -1; |
414 |
if (rb < (int) sizeof(struct input_event)) |
433 |
FD_ZERO(&rfds); |
415 |
continue; |
434 |
for (i = 0;i < evdev_count;i++) { |
|
|
435 |
FD_SET(fd_evdevs[i], &rfds); |
436 |
nfds = max(nfds, fd_evdevs[i]); |
437 |
} |
416 |
|
438 |
|
417 |
for (i = 0; i < (int) (rb / sizeof(struct input_event)); i++) { |
439 |
nfds++; |
418 |
if (ev[i].type != EV_KEY || ev[i].value != 0) |
|
|
419 |
continue; |
420 |
|
440 |
|
421 |
switch (ev[i].code) { |
441 |
retval = select(nfds, &rfds, NULL, NULL, NULL); |
422 |
case KEY_F2: |
442 |
if (retval == -1) |
423 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); |
443 |
perror("select()"); |
424 |
pthread_mutex_lock(&mtx_paint); |
444 |
else if (retval) { |
425 |
if (ctty == CTTY_SILENT) { |
445 |
for (i = 0;i < evdev_count;i++) { |
426 |
h = config.tty_v; |
446 |
if (FD_ISSET(fd_evdevs[i], &rfds)) { |
427 |
} else { |
447 |
fd_evdev = fd_evdevs[i]; |
428 |
h = config.tty_s; |
448 |
break; |
429 |
} |
449 |
} |
430 |
pthread_mutex_unlock(&mtx_paint); |
450 |
} |
431 |
pthread_setcancelstate(oldstate, NULL); |
451 |
key_pressed = get_ev_key_pressed(fd_evdev, EV_BUF_SIZE, ev_buf); |
|
|
452 |
if (key_pressed == -1) |
453 |
continue; |
454 |
switch (key_pressed) { |
455 |
case KEY_F2: |
456 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); |
457 |
pthread_mutex_lock(&mtx_paint); |
458 |
h = (ctty == CTTY_SILENT) ? config.tty_v : config.tty_s; |
459 |
pthread_mutex_unlock(&mtx_paint); |
460 |
pthread_setcancelstate(oldstate, NULL); |
461 |
|
462 |
/* Switch to the new tty. This ioctl has to be done on |
463 |
* the silent tty. Sometimes init will mess with the |
464 |
* settings of the verbose console which will prevent |
465 |
* console switching from working properly. |
466 |
* |
467 |
* Don't worry about fd_tty[config.tty_s] |
468 |
* not being protected by a mutex -- |
469 |
* this thread is always killed before any changes |
470 |
* are made to fd_tty[config.tty_s]. |
471 |
*/ |
472 |
ioctl(fd_tty[config.tty_s], VT_ACTIVATE, h); |
473 |
break; |
432 |
|
474 |
|
433 |
/* Switch to the new tty. This ioctl has to be done on |
475 |
case KEY_F3: |
434 |
* the silent tty. Sometimes init will mess with the |
476 |
config.textbox_visible = !config.textbox_visible; |
435 |
* settings of the verbose console which will prevent |
477 |
invalidate_textbox(theme, config.textbox_visible); |
436 |
* console switching from working properly. |
478 |
cmd_paint(NULL); |
437 |
* |
479 |
break; |
438 |
* Don't worry about fd_tty[config.tty_s] not being protected by a |
|
|
439 |
* mutex -- this thread is always killed before any changes |
440 |
* are made to fd_tty[config.tty_s]. |
441 |
*/ |
442 |
ioctl(fd_tty[config.tty_s], VT_ACTIVATE, h); |
443 |
break; |
444 |
|
445 |
case KEY_F3: |
446 |
config.textbox_visible = !config.textbox_visible; |
447 |
invalidate_textbox(theme, config.textbox_visible); |
448 |
cmd_paint(NULL); |
449 |
break; |
450 |
} |
480 |
} |
451 |
} |
481 |
} /* end of else if (retval) */ |
452 |
} |
482 |
} /* end of while(1) */ |
453 |
|
483 |
|
454 |
pthread_exit(NULL); |
484 |
pthread_exit(NULL); |
455 |
} |
485 |
} |
Lines 519-525
Link Here
|
519 |
|
549 |
|
520 |
/* Do we have to start a monitor thread? */ |
550 |
/* Do we have to start a monitor thread? */ |
521 |
if (update & UPD_MON) { |
551 |
if (update & UPD_MON) { |
522 |
if (fd_evdev != -1) { |
552 |
if (evdev_count >= 0) { |
523 |
if (pthread_create(&th_switchmon, NULL, &thf_switch_evdev, NULL)) { |
553 |
if (pthread_create(&th_switchmon, NULL, &thf_switch_evdev, NULL)) { |
524 |
iprint(MSG_ERROR, "Evdev monitor thread creation failed.\n"); |
554 |
iprint(MSG_ERROR, "Evdev monitor thread creation failed.\n"); |
525 |
exit(3); |
555 |
exit(3); |