From: Rui Guo Date: Wed, 3 Jun 2009 04:01:06 +0000 (+0800) Subject: Introduce the event register & dispatching framework. (not finished) X-Git-Url: https://repo.or.cz/w/screen-lua.git/commitdiff_plain/e67ddbc4540b63f143151e8ea76c949b9dfd122a Introduce the event register & dispatching framework. (not finished) 1. Define the script_event structure, lookup table etc. 2. Implement the event lookup logic. 3. Some sample events defined. --- diff --git a/src/script.c b/src/script.c index 4293be4..98d1cbb 100644 --- a/src/script.c +++ b/src/script.c @@ -21,6 +21,9 @@ #include "config.h" #include "screen.h" +#include + +/*Binding structure & functions*/ struct binding *bindings = NULL; @@ -100,6 +103,55 @@ ScriptSource(int argc, const char **argv) LMsg(1, "Could not source specified script %s", script); } +/* Event notification handling */ + +struct gevents { + struct script_event cmdexecuted; +} globalevents; + +/* To add new event, introduce a filed for that event to the object in + * question, don't forget to put a name, offset pair here. NOTE: keep the + * name field sorted in alphabet order, the searching relies on it. + */ + +struct { + char *name; + int offset; +} event_table[] = { + {"global_cmdexecuted", offsetof(struct gevents, cmdexecuted)}, + {"window_resize", offsetof(struct win, resize)}, + {"window_can_resize", offsetof(struct win, canresize)} +}; + +struct script_event * +get_object_event_queue(char *name, char *obj) { + int lo, hi, n, cmp; + if (!obj) + obj = (char *)&globalevents; + + lo = 0; + n = hi = sizeof(event_table); + while (lo < hi) { + int half; + half = (lo + hi) >> 1; + cmp = strcmp(name, event_table[half].name); + if (cmp > 0) + lo = half + 1; + else + hi = half; + } + + if (lo >= n || strcmp(name, event_table[lo].name)) + return 0; + else + return (struct event *)(obj + event_table[lo].offset); +} + +void +register_listener(struct script_event * event, struct listener *listener) +{ +} + #define ALL_SCRIPTS(fn, params, stop) do { \ struct binding *iter; \ for (iter = bindings; iter; iter = iter->b_next) \ diff --git a/src/script.h b/src/script.h index 67b151a..9234509 100644 --- a/src/script.h +++ b/src/script.h @@ -48,5 +48,13 @@ struct binding void LoadBindings(void); void FinializeBindings(void); +struct listener { + +}; + +struct script_event { + int blockable; + struct listener *listeners; +}; #endif diff --git a/src/window.h b/src/window.h index 6c6ca76..f9840c5 100644 --- a/src/window.h +++ b/src/window.h @@ -280,6 +280,10 @@ struct win struct mline *w_alt_hlines; int w_alt_histidx; #endif +#ifdef SCRIPT + struct script_event resize; + struct script_event canresize; +#endif };