aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui.c30
-rw-r--r--src/ui.h6
-rw-r--r--src/ui_elements.c19
-rw-r--r--src/ui_input.c5
-rw-r--r--src/ui_input.h2
-rw-r--r--src/ui_txtwindow.h2
6 files changed, 44 insertions, 20 deletions
diff --git a/src/ui.c b/src/ui.c
index fa65e29..f30d10b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -47,7 +47,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_input = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t mtx_busy = PTHREAD_MUTEX_INITIALIZER;
@@ -132,7 +131,6 @@ activate_ui_input(void *data)
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 ) {
@@ -143,7 +141,6 @@ activate_ui_input(void *data)
}
cur = cur->next;
}
- pthread_mutex_unlock(&mtx_input);
return ret;
}
@@ -152,12 +149,10 @@ deactivate_ui_input(void *data)
{
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;
}
@@ -235,6 +230,20 @@ ui_thrd_force_update(void)
pthread_mutex_unlock(&mtx_busy);
}
+void
+ui_thrd_suspend(void)
+{
+ ui_thrd_force_update();
+ pthread_mutex_lock(&mtx_busy);
+}
+
+void
+ui_thrd_resume(void)
+{
+ pthread_mutex_unlock(&mtx_busy);
+ ui_thrd_force_update();
+}
+
WINDOW *
init_ui(void)
{
@@ -293,18 +302,15 @@ do_ui(void)
return ret;
}
ui_ipc_semwait(SEM_RD);
- wtimeout(wnd_main, 1000);
pthread_mutex_unlock(&mtx_update);
+ wtimeout(stdscr, 1000);
while ( ui_ipc_getvalue(SEM_UI) > 0 ) {
- if ((key = wgetch(wnd_main)) == '\0') {
- break;
- }
- if (key == -1) {
+ if ((key = wgetch(wnd_main)) == ERR) {
continue;
}
if ( process_key(key) != true ) {
- ui_ipc_semtrywait(SEM_UI);
- ui_thrd_force_update();
+ //ui_ipc_semtrywait(SEM_UI);
+ //ui_thrd_force_update();
}
}
stop_ui_thrd();
diff --git a/src/ui.h b/src/ui.h
index 6f83149..8aa1d55 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -72,6 +72,12 @@ deactivate_ui_input(void *data);
void
ui_thrd_force_update(void);
+void
+ui_thrd_suspend(void);
+
+void
+ui_thrd_resume(void);
+
WINDOW *
init_ui(void);
diff --git a/src/ui_elements.c b/src/ui_elements.c
index e57c0de..427415a 100644
--- a/src/ui_elements.c
+++ b/src/ui_elements.c
@@ -73,23 +73,36 @@ passwd_input_cb(WINDOW *wnd, void *data, int key)
char ipc_buf[IPC_MQSIZ+1];
memset(ipc_buf, '\0', IPC_MQSIZ+1);
+ wtimeout(stdscr, -1);
switch (key) {
case UIKEY_ENTER:
- deactivate_input(pw_input);
mq_passwd_send(a->input);
+ ui_thrd_suspend();
clear_input(wnd, a);
+ deactivate_input(pw_input);
ui_ipc_msgrecv(MQ_IF, ipc_buf);
set_txtwindow_color(infownd, COLOR_PAIR(5), COLOR_PAIR(5));
set_txtwindow_title(infownd, "BUSY");
set_txtwindow_text(infownd, ipc_buf);
set_txtwindow_active(infownd, true);
+ ui_thrd_resume();
sleep(2);
ui_ipc_msgrecv(MQ_IF, ipc_buf);
+ ui_thrd_suspend();
set_txtwindow_color(infownd, COLOR_PAIR(4), COLOR_PAIR(4) | A_BOLD);
+ set_txtwindow_title(infownd, "ERROR");
set_txtwindow_text(infownd, ipc_buf);
+ ui_thrd_resume();
+// while (getch() != '\n') { }
+wgetch(stdscr);
+ ui_thrd_suspend();
+ set_txtwindow_active(infownd, false);
+ activate_input(pw_input);
+ ui_thrd_resume();
break;
case UIKEY_BACKSPACE:
del_input(wnd, a);
+ ui_thrd_force_update();
break;
case UIKEY_ESC:
return DOUI_ERR;
@@ -102,7 +115,9 @@ passwd_input_cb(WINDOW *wnd, void *data, int key)
break;
default:
add_input(wnd, a, key);
+ ui_thrd_force_update();
}
+ wtimeout(stdscr, 1000);
return DOUI_OK;
}
@@ -129,7 +144,7 @@ init_ui_elements(WINDOW *wnd_main, unsigned int max_x, unsigned int max_y)
register_statusbar(lower);
register_anic_default(heartbeat);
register_txtwindow(infownd);
- activate_input(wnd_main, pw_input);
+ activate_input(pw_input);
set_statusbar_text(higher, title);
}
diff --git a/src/ui_input.c b/src/ui_input.c
index b32570b..9c53330 100644
--- a/src/ui_input.c
+++ b/src/ui_input.c
@@ -121,7 +121,7 @@ print_input(WINDOW *win, struct input *a)
}
int
-activate_input(WINDOW *win, struct input *a)
+activate_input(struct input *a)
{
if (a == NULL) return (UICB_ERR_UNDEF);
curs_set(1);
@@ -146,7 +146,6 @@ add_input(WINDOW *win, struct input *a, int key)
++a->input_len;
a->cur_pos = (a->cur_pos+1 < a->width ? a->cur_pos+1 : a->cur_pos);
ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
- ui_thrd_force_update();
return (UICB_OK);
}
@@ -168,7 +167,6 @@ del_input(WINDOW *win, struct input *a)
}
mvwprintw(win, a->y, a->x + a->cur_pos + strlen(a->prompt), "_");
ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
- ui_thrd_force_update();
return (UICB_OK);
}
@@ -181,7 +179,6 @@ clear_input(WINDOW *win, struct input *a)
a->input_pos = 0;
a->cur_pos = 0;
ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
- ui_thrd_force_update();
return (UICB_OK);
}
diff --git a/src/ui_input.h b/src/ui_input.h
index 8ed7fc3..df7088c 100644
--- a/src/ui_input.h
+++ b/src/ui_input.h
@@ -26,7 +26,7 @@ void
free_input(struct input *a);
int
-activate_input(WINDOW *win, struct input *a);
+activate_input(struct input *a);
int
deactivate_input(struct input *a);
diff --git a/src/ui_txtwindow.h b/src/ui_txtwindow.h
index 913cd99..0ebbd9f 100644
--- a/src/ui_txtwindow.h
+++ b/src/ui_txtwindow.h
@@ -7,7 +7,7 @@
#define INITIAL_TITLE_LEN 32
-#define set_txtwindow_active(wnd, activate) wnd->active = activate; ui_thrd_force_update()
+#define set_txtwindow_active(wnd, activate) wnd->active = activate;
struct txtwindow {
unsigned int y;