diff options
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 102 |
1 files changed, 27 insertions, 75 deletions
@@ -41,46 +41,29 @@ static unsigned int max_x, max_y; static WINDOW *wnd_main; -static struct nask_ui /* simple linked list to all GUI objects */ *nui = NULL, - /* simple linked list to all INPUT objects */ *nin = NULL, /* current active input */ *active = NULL; +static struct nask_ui /* simple linked list to all UI objects */ *nui = NULL, + /* current active input */ *active = NULL; static pthread_t thrd; static unsigned int atmout = APP_TIMEOUT; static pthread_cond_t cnd_update = PTHREAD_COND_INITIALIZER; static pthread_mutex_t mtx_update = PTHREAD_MUTEX_INITIALIZER; -static void -register_basic(enum ui_type utype, union ui_data uicb, void *data, WINDOW *wnd) +void +register_ui_elt(struct ui_callbacks *cbs, void *data, WINDOW *wnd) { - struct nask_ui *tmp, *new, *ui = NULL; + struct nask_ui *tmp, *new; - switch (utype) { - case UI_ELEMENT: - ui = nui; - break; - case UI_INPUT: - ui = nin; - break; - } new = calloc(1, sizeof(struct nask_ui)); - new->type = utype; - new->callback = uicb; + new->cbs = *cbs; new->wnd = wnd; new->data = data; new->next = NULL; - if (ui == NULL) { - ui = new; - ui->next = NULL; - switch (utype) { - case UI_ELEMENT: - nui = ui; - break; - case UI_INPUT: - nin = ui; - break; - } + if (nui == NULL) { + nui = new; + nui->next = NULL; } else { - tmp = ui; + tmp = nui; while (tmp->next != NULL) { tmp = tmp->next; } @@ -89,35 +72,11 @@ register_basic(enum ui_type utype, union ui_data uicb, void *data, WINDOW *wnd) } void -register_ui_elt(ui_callback uicb, void *data, WINDOW *wnd) -{ - union ui_data cb; - cb.ui_element = uicb; - register_basic(UI_ELEMENT, cb, data, wnd); -} - -void -register_ui_input(ui_input_callback ipcb, void *data, WINDOW *wnd) -{ - union ui_data cb; - cb.ui_input = ipcb; - register_basic(UI_INPUT, cb, data, wnd); -} - -static void -unregister_basic(enum ui_type utype, void *data) +unregister_ui_elt(void *data) { - struct nask_ui *cur, *next, *before = NULL, **ui = NULL; + struct nask_ui *cur, *next, *before = NULL; - switch (utype) { - case UI_ELEMENT: - ui = &nui; - break; - case UI_INPUT: - ui = &nin; - break; - } - cur = *ui; + cur = nui; while (cur != NULL) { next = cur->next; if (cur->data != NULL && cur->data == data) { @@ -125,7 +84,7 @@ unregister_basic(enum ui_type utype, void *data) if (before != NULL) { before->next = next; } else { - *ui = next; + nui = next; } } before = cur; @@ -133,27 +92,16 @@ unregister_basic(enum ui_type utype, void *data) } } -void -unregister_ui_elt(void *data) -{ - unregister_basic(UI_ELEMENT, data); -} - -void -unregister_ui_input(void *data) -{ - unregister_basic(UI_INPUT, data); -} - int activate_ui_input(void *data) { - struct nask_ui *cur = nin; + struct nask_ui *cur = nui; if (cur == NULL || data == NULL) return DOUI_NINIT; while ( cur != NULL ) { - if ( cur == data && cur->type == UI_INPUT ) { - if ( cur->callback.ui_input(cur->wnd, data, UIKEY_ACTIVATE) == DOUI_OK ) { + if ( cur == data ) { + if ( cur->cbs.ui_input != NULL && cur->cbs.ui_input(cur->wnd, data, UIKEY_ACTIVATE) == DOUI_OK ) { +printf("************\n"); active = cur; return DOUI_OK; } @@ -168,8 +116,7 @@ process_key(char key) { atmout = APP_TIMEOUT; if ( active != NULL ) { -printf("XXXXXXXX\n"); - return ( active->callback.ui_input(active->wnd, active->data, key) == DOUI_OK ? true : false ); + return ( active->cbs.ui_input(active->wnd, active->data, key) == DOUI_OK ? true : false ); } return false; } @@ -185,8 +132,8 @@ do_ui_update(bool timed_out) /* call all draw callback's */ erase(); while (cur != NULL) { - if (cur->type == UI_ELEMENT && cur->callback.ui_element != NULL) { - cur->callback.ui_element(cur->wnd, cur->data, timed_out); + if (cur->cbs.ui_element != NULL) { + cur->cbs.ui_element(cur->wnd, cur->data, timed_out); doupdate(); } else { retval = UICB_ERR_CB; @@ -287,11 +234,13 @@ do_ui(void) init_ui(); init_ui_elements(wnd_main, max_x, max_y); + pthread_mutex_lock(&mtx_update); if (run_ui_thrd() != 0) { goto error; } ui_ipc_semwait(SEM_RD); wtimeout(wnd_main, 10); + pthread_mutex_unlock(&mtx_update); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { if ((key = wgetch(wnd_main)) == '\0') { break; @@ -299,9 +248,12 @@ do_ui(void) if (key == -1) { continue; } +/* if ( process_key(key) != true ) { break; - } else printf("XXXXX\n"); + } +*/ +process_key(key); do_ui_update(false); } ui_thrd_force_update(); |