FKEY_EVENTS cleanups

- Fix a bug where an FKEY_EVENT request would always return EINVAL

 - Replace two manual usage of FKEY_EVENT messages by a call to
   fkey_events which is mapped to fkey_ctl.

Change-Id: I7bc54cade45a29f14c89313b3ec4c28d81a4ec93
This commit is contained in:
Lionel Sambuc 2014-06-04 16:04:36 +02:00
parent bfff07c918
commit e2e57d387f
3 changed files with 21 additions and 14 deletions

View file

@ -389,7 +389,8 @@ static void or_reset() {
static void or_dump (message *m) static void or_dump (message *m)
{ {
t_or *orp; t_or *orp;
int sfkeys;
orp = &or_state; orp = &or_state;
if(orp->or_mode == OR_M_DISABLED) { if(orp->or_mode == OR_M_DISABLED) {
@ -399,12 +400,11 @@ static void or_dump (message *m)
if(orp->or_mode != OR_M_ENABLED) if(orp->or_mode != OR_M_ENABLED)
return; return;
m->m_type = TTY_FKEY_CONTROL; if(OK != fkey_events(NULL, &sfkeys)) {
m->FKEY_REQUEST = FKEY_EVENTS;
if(OK!=(ipc_sendrec(TTY_PROC_NR,m)) )
printf("Contacting the TTY failed\n"); printf("Contacting the TTY failed\n");
}
if(bit_isset(m->FKEY_SFKEYS, 11)) { if(bit_isset(sfkeys, 11)) {
print_linkstatus(orp, orp->last_linkstatus); print_linkstatus(orp, orp->last_linkstatus);
} }
} }

View file

@ -501,6 +501,7 @@ message *m_ptr; /* pointer to the request message */
} }
break; break;
case FKEY_EVENTS: case FKEY_EVENTS:
result = OK; /* everything will be ok*/
m_ptr->FKEY_FKEYS = m_ptr->FKEY_SFKEYS = 0; m_ptr->FKEY_FKEYS = m_ptr->FKEY_SFKEYS = 0;
for (i=0; i < 12; i++) { /* check (Shift+) F1-F12 keys */ for (i=0; i < 12; i++) { /* check (Shift+) F1-F12 keys */
if (fkey_obs[i].proc_nr == m_ptr->m_source) { if (fkey_obs[i].proc_nr == m_ptr->m_source) {

View file

@ -67,25 +67,31 @@ int map;
/*===========================================================================* /*===========================================================================*
* handle_fkey * * handle_fkey *
*===========================================================================*/ *===========================================================================*/
#define pressed(k) ((F1<=(k)&&(k)<=F12 && bit_isset(m->FKEY_FKEYS,((k)-F1+1)))\ #define pressed(start, end, bitfield, key) \
|| (SF1<=(k) && (k)<=SF12 && bit_isset(m->FKEY_SFKEYS, ((k)-SF1+1)))) (((start) <= (key)) && ((end) >= (key)) && \
bit_isset((bitfield), ((key) - (start) + 1)))
int do_fkey_pressed(m) int do_fkey_pressed(m)
message *m; /* notification message */ message *m; /* notification message */
{ {
int s, h; int s, h;
int fkeys, sfkeys;
/* The notification message does not convey any information, other /* The notification message does not convey any information, other
* than that some function keys have been pressed. Ask TTY for details. * than that some function keys have been pressed. Ask TTY for details.
*/ */
m->m_type = TTY_FKEY_CONTROL; s = fkey_events(&fkeys, &sfkeys);
m->FKEY_REQUEST = FKEY_EVENTS; if (s < 0) {
if (OK != (s=ipc_sendrec(TTY_PROC_NR, m))) printf("IS: warning, fkey_events failed: %d\n", s);
printf("IS: warning, ipc_sendrec to TTY failed: %d\n", s); }
/* Now check which keys were pressed: F1-F12, SF1-SF12. */ /* Now check which keys were pressed: F1-F12, SF1-SF12. */
for(h=0; h < NHOOKS; h++) for(h=0; h < NHOOKS; h++) {
if(pressed(hooks[h].key)) if (pressed(F1, F12, fkeys, hooks[h].key)) {
hooks[h].function(); hooks[h].function();
} else if (pressed(SF1, SF12, sfkeys, hooks[h].key)) {
hooks[h].function();
}
}
/* Don't send a reply message. */ /* Don't send a reply message. */
return(EDONTREPLY); return(EDONTREPLY);