diff options
-rw-r--r-- | src/ui.c | 35 | ||||
-rw-r--r-- | src/ui.h | 4 | ||||
-rw-r--r-- | src/ui_elements.c | 23 | ||||
-rw-r--r-- | src/ui_txtwindow.h | 7 |
4 files changed, 39 insertions, 30 deletions
@@ -48,7 +48,6 @@ 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 @@ -217,9 +216,7 @@ ui_thrd(void *arg) now.tv_sec += UILOOP_TIMEOUT; while ( ui_ipc_getvalue(SEM_UI) > 0 ) { cnd_ret = pthread_cond_timedwait(&cnd_update, &mtx_update, &now); - pthread_mutex_lock(&mtx_busy); do_ui_update( (cnd_ret == ETIMEDOUT ? true : false) ); - pthread_mutex_unlock(&mtx_busy); if (cnd_ret == ETIMEDOUT) { clock_gettime(CLOCK_REALTIME, &now); now.tv_sec += UILOOP_TIMEOUT; @@ -230,23 +227,25 @@ ui_thrd(void *arg) } void -ui_thrd_force_update(void) +ui_thrd_force_update(bool force_all) { - pthread_mutex_lock(&mtx_busy); + pthread_mutex_lock(&mtx_update); + if (force_all) + touchwin(wnd_main); pthread_cond_signal(&cnd_update); - pthread_mutex_unlock(&mtx_busy); + pthread_mutex_unlock(&mtx_update); } void ui_thrd_suspend(void) { - pthread_mutex_lock(&mtx_busy); + pthread_mutex_lock(&mtx_update); } void ui_thrd_resume(void) { - pthread_mutex_unlock(&mtx_busy); + pthread_mutex_unlock(&mtx_update); } WINDOW * @@ -293,6 +292,17 @@ stop_ui_thrd(void) return (pthread_join(thrd, NULL)); } +char ui_wgetch(int timeout) +{ + char key; + usleep(timeout/2); + pthread_mutex_lock(&mtx_update); + key = wgetch(wnd_main); + pthread_mutex_unlock(&mtx_update); + usleep(timeout/2); + return key; +} + int do_ui(void) { @@ -310,15 +320,16 @@ do_ui(void) } ui_ipc_semwait(SEM_RD); pthread_mutex_unlock(&mtx_update); - wtimeout(stdscr, 500); + timeout(0); while ( ui_ipc_getvalue(SEM_UI) > 0 ) { - if ((key = wgetch(wnd_main)) == ERR) { + if ( (key = ui_wgetch(3000)) == ERR ) continue; - } + if ( process_key(key) != true ) { raise(SIGTERM); } - ui_thrd_force_update(); + + ui_thrd_force_update(false); } stop_ui_thrd(); free_ui_elements(); @@ -70,7 +70,7 @@ int deactivate_ui_input(void *data); void -ui_thrd_force_update(void); +ui_thrd_force_update(bool force_all); void ui_thrd_suspend(void); @@ -84,6 +84,8 @@ init_ui(void); void free_ui(void); +char ui_wgetch(int timeout); + int do_ui(void); diff --git a/src/ui_elements.c b/src/ui_elements.c index 78aba85..40bfeb3 100644 --- a/src/ui_elements.c +++ b/src/ui_elements.c @@ -63,14 +63,14 @@ void show_info_wnd(struct txtwindow *wnd, char *title, char *text, chtype fore, chtype back, bool activate, bool blink) { ui_thrd_suspend(); + deactivate_input(pw_input); + set_txtwindow_active(wnd, activate); set_txtwindow_blink(wnd, blink); set_txtwindow_color(wnd, fore, back); set_txtwindow_title(wnd, title); set_txtwindow_text(wnd, text); - if (activate) - set_txtwindow_active(wnd, true); ui_thrd_resume(); - ui_thrd_force_update(); + ui_thrd_force_update(false); } static int @@ -88,6 +88,7 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) clear_input(wnd, a); deactivate_input(pw_input); ui_thrd_resume(); + ui_thrd_force_update(false); ui_ipc_msgrecv(MQ_IF, ipc_buf); show_info_wnd(infownd, "BUSY", ipc_buf, COLOR_PAIR(5), COLOR_PAIR(5), true, false); @@ -96,14 +97,15 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) if (ui_ipc_msgcount(MQ_IF) > 0) { ui_ipc_msgrecv(MQ_IF, ipc_buf); - show_info_wnd(infownd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), false, true); - while (wgetch(stdscr) != '\n') { }; + show_info_wnd(infownd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), true, true); + while (ui_wgetch(1500) != '\n') { }; } ui_thrd_suspend(); set_txtwindow_active(infownd, false); activate_input(pw_input); ui_thrd_resume(); + ui_thrd_force_update(true); ui_ipc_sempost(SEM_IN); break; @@ -111,15 +113,7 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) del_input(wnd, a); break; case UIKEY_ESC: - wtimeout(stdscr, 0); - ui_thrd_suspend(); - deactivate_input(pw_input); - set_txtwindow_active(infownd, true); - set_txtwindow_color(infownd, COLOR_PAIR(5), COLOR_PAIR(5)); - set_txtwindow_title(infownd, "BUSY"); - set_txtwindow_text(infownd, "bye bye"); - ui_thrd_resume(); - ui_thrd_force_update(); + show_info_wnd(infownd, "BUSY", "bye bye", COLOR_PAIR(5), COLOR_PAIR(5), true, true); sleep(2); return DOUI_ERR; case UIKEY_DOWN: @@ -132,7 +126,6 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) default: add_input(wnd, a, key); } - refresh(); return DOUI_OK; } diff --git a/src/ui_txtwindow.h b/src/ui_txtwindow.h index 5ebbd65..260a38a 100644 --- a/src/ui_txtwindow.h +++ b/src/ui_txtwindow.h @@ -10,6 +10,10 @@ #define set_txtwindow_active(wnd, activate) wnd->active = activate; #define set_txtwindow_blink(wnd, blink) wnd->title_blink = blink; +struct txtwindow; + +typedef int (*window_func)(WINDOW *, struct txtwindow *, bool); + struct txtwindow { unsigned int y; unsigned int x; @@ -20,12 +24,11 @@ struct txtwindow { bool title_blink; size_t title_len; char **text; - int (*window_func)(WINDOW *, struct txtwindow *, bool); + window_func window_func; chtype attrs; chtype text_attrs; }; -typedef int (*window_func)(WINDOW *, struct txtwindow *, bool); struct txtwindow * init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height, window_func cb_update); |