diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | ui.c | 23 | ||||
-rw-r--r-- | ui_elements.c | 23 | ||||
-rw-r--r-- | ui_input.c | 19 |
4 files changed, 41 insertions, 26 deletions
@@ -26,7 +26,7 @@ release: all strip debug: $(MAKE) CFLAGS='$(CFLAGS) $(DBGFLAGS)' - $(MAKE) -C tests CFLAGS='$(CFLAGS) $(DBGFLAGS)' + @$(MAKE) -C tests CFLAGS='$(CFLAGS) $(DBGFLAGS)' install: $(INSTALL) -D -m 0755 $(BIN) $(DESTDIR)/lib/cryptsetup/naskpass @@ -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_busy = PTHREAD_MUTEX_INITIALIZER; void @@ -98,10 +99,9 @@ activate_ui_input(void *data) struct nask_ui *cur = nui; if (cur == NULL || data == NULL) return DOUI_NINIT; - while ( cur != NULL ) { - if ( cur == data ) { + 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 ) { -printf("************\n"); active = cur; return DOUI_OK; } @@ -162,15 +162,16 @@ ui_thrd(void *arg) wait.tv_nsec = now.tv_usec * 1000; do_ui_update(true); ui_ipc_sempost(SEM_RD); + pthread_mutex_lock(&mtx_update); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { - pthread_mutex_lock(&mtx_update); + 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); do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) ); if (cnd_ret == ETIMEDOUT) { wait.tv_sec += UILOOP_TIMEOUT; } - pthread_mutex_unlock(&mtx_update); } pthread_mutex_unlock(&mtx_update); return (NULL); @@ -180,7 +181,9 @@ void ui_thrd_force_update(void) { pthread_mutex_lock(&mtx_update); + pthread_mutex_lock(&mtx_busy); pthread_cond_signal(&cnd_update); + pthread_mutex_unlock(&mtx_busy); pthread_mutex_unlock(&mtx_update); } @@ -239,7 +242,7 @@ do_ui(void) goto error; } ui_ipc_semwait(SEM_RD); - wtimeout(wnd_main, 10); + wtimeout(wnd_main, 1000); pthread_mutex_unlock(&mtx_update); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { if ((key = wgetch(wnd_main)) == '\0') { @@ -248,15 +251,11 @@ do_ui(void) if (key == -1) { continue; } -/* if ( process_key(key) != true ) { - break; +// break; } -*/ -process_key(key); - do_ui_update(false); +// do_ui_update(false); } - ui_thrd_force_update(); stop_ui_thrd(); free_ui_elements(); diff --git a/ui_elements.c b/ui_elements.c index dc24d2f..0633b42 100644 --- a/ui_elements.c +++ b/ui_elements.c @@ -34,7 +34,13 @@ lower_statusbar_update(WINDOW *win, struct statusbar *bar) char *tmp = get_system_stat(); set_statusbar_text(bar, tmp); free(tmp); - return (0); + return 0; +} + +static int +higher_statusbar_update(WINDOW *win, struct statusbar *bar) +{ + return 0; } static int @@ -48,7 +54,7 @@ infownd_update(WINDOW *win, struct txtwindow *tw) memset(tmp+1, '\0', 2); } else strcat(tmp, "."); } else (*tmp) = '.'; - return (0); + return 0; } static int @@ -80,9 +86,12 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) */ switch (key) { case UIKEY_ENTER: - if ( mq_passwd_send(a->input, a->input_len) > 0 ) { - return DOUI_OK; - } else return DOUI_ERR; + mq_passwd_send(a->input, a->input_len); + memset(a->input, '\0', a->input_len); + a->input_len = 0; + a->input_pos = 0; + a->cur_pos = 0; + ui_thrd_force_update(); break; case UIKEY_BACKSPACE: del_input(wnd, a); @@ -95,6 +104,8 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) case UIKEY_LEFT: case UIKEY_RIGHT: break; + case UIKEY_ACTIVATE: + break; default: add_input(wnd, a, key); } @@ -107,7 +118,7 @@ init_ui_elements(WINDOW *wnd_main, unsigned int max_x, unsigned int max_y) asprintf(&title, "/* %s-%s */", PKGNAME, VERSION); pw_input = init_input((unsigned int)(max_x / 2)-PASSWD_XRELPOS, (unsigned int)(max_y / 2)-PASSWD_YRELPOS, PASSWD_WIDTH, "PASSWORD: ", IPC_MQSIZ, COLOR_PAIR(3), COLOR_PAIR(2)); heartbeat = init_anic(0, 0, A_BOLD | COLOR_PAIR(1), "[%c]"); - higher = init_statusbar(0, max_x, A_BOLD | COLOR_PAIR(3), NULL); + higher = init_statusbar(0, max_x, A_BOLD | COLOR_PAIR(3), higher_statusbar_update); lower = init_statusbar(max_y - 1, max_x, COLOR_PAIR(3), lower_statusbar_update); infownd = init_txtwindow((unsigned int)(max_x / 2)-INFOWND_XRELPOS, (unsigned int)(max_y / 2)-INFOWND_YRELPOS, INFOWND_WIDTH, INFOWND_HEIGHT, COLOR_PAIR(4), COLOR_PAIR(4) | A_BOLD, infownd_update); infownd->userptr = calloc(4, sizeof(char)); @@ -101,16 +101,21 @@ print_input(WINDOW *win, struct input *a) print_wnd(3, a); attron(a->attrs); - if (win == NULL) { + if (win) { + mvwprintw(win, a->y, a->x, a->prompt); + } else { mvprintw(a->y, a->x, a->prompt); - tmp = calloc(a->width+1, sizeof(char)); - for (i = 0; i < a->width; i++) { - *(tmp + i) = '_'; - } - mvprintw(a->y, a->x + p_len, tmp); - free(tmp); + } + tmp = calloc(a->width+1, sizeof(char)); + for (i = 0; i < a->width; i++) { + *(tmp + i) = '_'; + } + if (win) { + mvwprintw(win, a->y, a->x + p_len, tmp); } else { + mvprintw(a->y, a->x + p_len, tmp); } + free(tmp); print_input_text(win, a); attroff(a->attrs); } |