diff options
-rw-r--r-- | src/ui.c | 35 | ||||
-rw-r--r-- | src/ui.h | 3 | ||||
-rw-r--r-- | src/ui_elements.c | 16 | ||||
-rw-r--r-- | src/ui_input.c | 11 | ||||
-rw-r--r-- | src/ui_input.h | 3 |
5 files changed, 42 insertions, 26 deletions
@@ -47,6 +47,7 @@ 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 pthread_mutex_t mtx_input = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mtx_busy = PTHREAD_MUTEX_INITIALIZER; @@ -96,39 +97,49 @@ unregister_ui_elt(void *data) int activate_ui_input(void *data) { + int ret = DOUI_ERR; struct nask_ui *cur = nui; if (cur == NULL || data == NULL) return DOUI_NINIT; + pthread_mutex_lock(&mtx_input); while ( cur->data != NULL ) { if ( cur->data == data ) { if ( cur->cbs.ui_input != NULL && cur->cbs.ui_input(cur->wnd, data, UIKEY_ACTIVATE) == DOUI_OK ) { active = cur; - return DOUI_OK; + ret = DOUI_OK; + break; } } cur = cur->next; } - return DOUI_ERR; + pthread_mutex_unlock(&mtx_input); + return ret; } int -reactivate_ui_input(void) +deactivate_ui_input(void *data) { - if (active) { - if (active->cbs.ui_element) { - } - return ( active->cbs.ui_input(active->wnd, active->data, UIKEY_ACTIVATE) ); - } else return DOUI_ERR; + int ret = DOUI_ERR; + + pthread_mutex_lock(&mtx_input); + if (active != NULL && data == active->data) { + active = NULL; + ret = DOUI_OK; + } + pthread_mutex_unlock(&mtx_input); + return ret; } static bool process_key(char key) { + bool ret = false; + atmout = APP_TIMEOUT; if ( active != NULL ) { - return ( active->cbs.ui_input(active->wnd, active->data, key) == DOUI_OK ? true : false ); + ret = ( active->cbs.ui_input(active->wnd, active->data, key) == DOUI_OK ? true : false ); } - return false; + return ret; } static int @@ -174,11 +185,11 @@ ui_thrd(void *arg) ui_ipc_sempost(SEM_RD); pthread_mutex_lock(&mtx_update); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { - pthread_mutex_unlock(&mtx_busy); cnd_ret = pthread_cond_timedwait(&cnd_update, &mtx_update, &wait); - pthread_mutex_lock(&mtx_busy); if (--atmout == 0) ui_ipc_semtrywait(SEM_UI); + pthread_mutex_lock(&mtx_busy); do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) ); + pthread_mutex_unlock(&mtx_busy); if (cnd_ret == ETIMEDOUT) { wait.tv_sec += UILOOP_TIMEOUT; } @@ -51,6 +51,9 @@ unregister_ui_elt(void *data); int activate_ui_input(void *data); +int +deactivate_ui_input(void *data); + void ui_thrd_force_update(void); diff --git a/src/ui_elements.c b/src/ui_elements.c index 29c2e32..27ccea0 100644 --- a/src/ui_elements.c +++ b/src/ui_elements.c @@ -71,22 +71,13 @@ static int passwd_input_cb(WINDOW *wnd, void *data, int key) { struct input *a = (struct input *) data; -/* - * if ( process_key(key, pw_input, wnd_main) == false ) { - * curs_set(0); - * memset(mq_msg, '\0', IPC_MQSIZ+1); - * mq_receive(mq_info, mq_msg, IPC_MQSIZ+1, 0); - * set_txtwindow_text(infownd, mq_msg); - * set_txtwindow_active(infownd, true); - * sleep(3); - * sem_trywait(sp_ui); - * } - * activate_input(wnd_main, pw_input); - */ + switch (key) { case UIKEY_ENTER: + deactivate_input(pw_input); mq_passwd_send(a->input, a->input_len); clear_input(wnd, a); + set_txtwindow_title(infownd, "BUSY"); set_txtwindow_text(infownd, "BLA"); set_txtwindow_active(infownd, true); break; @@ -125,7 +116,6 @@ init_ui_elements(WINDOW *wnd_main, unsigned int max_x, unsigned int max_y) register_statusbar(lower); register_anic_default(heartbeat); register_txtwindow(infownd); - set_txtwindow_title(infownd, "WARNING"); activate_input(wnd_main, pw_input); set_statusbar_text(higher, title); } diff --git a/src/ui_input.c b/src/ui_input.c index 5f9a679..3065f1d 100644 --- a/src/ui_input.c +++ b/src/ui_input.c @@ -125,6 +125,7 @@ activate_input(WINDOW *win, struct input *a) { if (a == NULL) return (UICB_ERR_UNDEF); size_t p_len = strlen(a->prompt); + curs_set(1); if (win == NULL) { move(a->y, a->x + p_len + a->cur_pos); } else { @@ -134,6 +135,13 @@ activate_input(WINDOW *win, struct input *a) } int +deactivate_input(struct input *a) +{ + curs_set(0); + return (deactivate_ui_input(a)); +} + +int add_input(WINDOW *win, struct input *a, int key) { if (a == NULL) return (UICB_ERR_UNDEF); @@ -142,7 +150,8 @@ add_input(WINDOW *win, struct input *a, int key) ++a->input_pos; ++a->input_len; a->cur_pos = (a->cur_pos+1 < a->width ? a->cur_pos+1 : a->cur_pos); - print_input(win, a); + //print_input(win, a); + ui_thrd_force_update(); return (UICB_OK); } diff --git a/src/ui_input.h b/src/ui_input.h index 657c926..8ed7fc3 100644 --- a/src/ui_input.h +++ b/src/ui_input.h @@ -29,6 +29,9 @@ int activate_input(WINDOW *win, struct input *a); int +deactivate_input(struct input *a); + +int add_input(WINDOW *win, struct input *a, int key); int |