forked from Mirrors/sngrep
Keystroke popagation: properly manage key handler return codes
The following return codes can be get from key handlers: - KEY_HANDLED - KEY_PROPAGATED - key to be handled by default handler Previous implementation invalidated the third one
This commit is contained in:
parent
5bdd5fc9ef
commit
ace786476f
|
@ -1282,7 +1282,7 @@ call_flow_handle_key(PANEL *panel, int key)
|
|||
break;
|
||||
case ACTION_CLEAR_CALLS:
|
||||
// Propagate the key to the previous panel
|
||||
return -1;
|
||||
return KEY_PROPAGATED;
|
||||
|
||||
default:
|
||||
// Parse next action
|
||||
|
|
|
@ -269,7 +269,7 @@ call_raw_handle_key(PANEL *panel, int key)
|
|||
break;
|
||||
case ACTION_CLEAR_CALLS:
|
||||
// Propagate the key to the previous panel
|
||||
return -1;
|
||||
return KEY_PROPAGATED;
|
||||
default:
|
||||
// Parse next action
|
||||
continue;
|
||||
|
|
|
@ -330,23 +330,24 @@ wait_for_input()
|
|||
continue;
|
||||
|
||||
// Handle received key
|
||||
int hdl = -1;
|
||||
while (hdl != KEY_HANDLED) {
|
||||
int key = c;
|
||||
while (c != KEY_HANDLED) {
|
||||
// Check if current panel has custom bindings for that key
|
||||
hdl = ui_handle_key(ui, c);
|
||||
c = ui_handle_key(ui, c);
|
||||
|
||||
if (hdl == KEY_HANDLED) {
|
||||
if (c == KEY_HANDLED) {
|
||||
// Panel handled this key
|
||||
continue;
|
||||
} else if (hdl == KEY_PROPAGATED) {
|
||||
} else if (c == KEY_PROPAGATED) {
|
||||
// restore the key value
|
||||
c = key;
|
||||
// Destroy current panel
|
||||
ui_destroy(ui);
|
||||
// Try to handle this key with the previus panel
|
||||
ui = ui_find_by_panel(panel_below(NULL));
|
||||
} else {
|
||||
// Key not handled by UI nor propagated. Use default handler
|
||||
default_handle_key(ui, c);
|
||||
break;
|
||||
c = default_handle_key(ui, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -402,8 +403,8 @@ default_handle_key(ui_t *ui, int key)
|
|||
break;
|
||||
}
|
||||
|
||||
// Return this is a valid handled key
|
||||
return (action == ERR) ? key : 0;
|
||||
// Consider the key handled at this point
|
||||
return KEY_HANDLED;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -304,7 +304,7 @@ wait_for_input();
|
|||
/**
|
||||
* @brief Default handler for keys
|
||||
*
|
||||
* If ui doesn't handle the given key (ui_handle_key returns -1)
|
||||
* If ui doesn't handle the given key (ui_handle_key returns the key value)
|
||||
* then the default handler will be invoked
|
||||
*
|
||||
* @param ui Current displayed UI structure
|
||||
|
|
Loading…
Reference in New Issue