From: NeilBrown Date: Fri, 11 Dec 2015 06:31:41 +0000 (+1100) Subject: Make it possible to replace current event handler. X-Git-Tag: lca2016~54 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d559a13497a924ae3517ac6bd70af34365458fc8;p=edlib.git Make it possible to replace current event handler. Setting DAMAGED_EVENTS on the root and then refreshing should do it. Untested though. Signed-off-by: NeilBrown --- diff --git a/core-pane.c b/core-pane.c index d0862eff..708c73dc 100644 --- a/core-pane.c +++ b/core-pane.c @@ -127,7 +127,7 @@ static void __pane_refresh(struct cmd_info *ci) ci2.extra |= DAMAGED_CONTENT; if (ci2.extra & DAMAGED_CONTENT) ci2.extra |= DAMAGED_CURSOR; - damage &= DAMAGED_SIZE; + damage &= DAMAGED_SIZE | DAMAGED_EVENTS; ci2.comm = p->handle; ret = p->handle->func(&ci2); if (ret == 0) diff --git a/core.h b/core.h index 09577ef0..15741136 100644 --- a/core.h +++ b/core.h @@ -310,6 +310,10 @@ void key_add_range(struct map *map, char *first, char *last, struct command *comm); struct command *key_register_prefix(char *name); +/* DAMAGED_SIZE and DAMAGED_EVENTS propagate down. + * DAMAGED_CURSOR propagates up. + * If any flag is set on children, DAMAGED_CHILD is set. + */ enum { DAMAGED_CHILD = 1, DAMAGED_SIZE = 2, /* these three each impose the next. */ @@ -317,6 +321,7 @@ enum { DAMAGED_CURSOR = 8, DAMAGED_CLOSED = 1024, + DAMAGED_EVENTS = 2048, /* event loop changed, resubmit requests */ }; struct pane *pane_register(struct pane *parent, int z, diff --git a/display-ncurses.c b/display-ncurses.c index 505a811d..d0e95b1a 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -151,6 +151,12 @@ DEF_CMD(ncurses_handle) int damage = ci->extra; if (damage & DAMAGED_SIZE) getmaxyx(stdscr, p->h, p->w); + if (damage & DAMAGED_EVENTS) { + call_home(p, "event:read", p, 0, NULL, + &input_handle); + call_home(p, "event:signal", p, SIGWINCH, NULL, + &handle_winch); + } } return 2; /* request post-order call */ } diff --git a/edlib.c b/edlib.c index 050166a8..f8fdcb4f 100644 --- a/edlib.c +++ b/edlib.c @@ -93,7 +93,8 @@ int main(int argc, char *argv[]) key_handle(&ci); pane_refresh(&ed->root); - call3("event:run", vroot, 0, NULL); + while (call3("event:run", vroot, 0, NULL) == 1) + ; } pane_close(&ed->root); exit(0); diff --git a/lib-libevent.c b/lib-libevent.c index c1fac008..afb1d330 100644 --- a/lib-libevent.c +++ b/lib-libevent.c @@ -68,6 +68,9 @@ DEF_CMD(libevent_signal) DEF_CMD(libevent_run) { struct event_base *b = base; + if (!b) + return 0; + event_base_dispatch(b); while (!list_empty(&event_list)) { struct evt *ev = list_first_entry(&event_list, struct evt, lst);