aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoni <toni@devlap.local>2015-11-03 12:49:31 +0100
committertoni <toni@devlap.local>2015-11-03 12:49:31 +0100
commit2e288bb56e9a15c4fb0fb33b4823a2d8650f9d2e (patch)
tree52c698326b2669fac5c71f6d33a84d917eab3bb9
parent295ca9cb2bd2ebf58e9904a75312e3d17904bb51 (diff)
some MV(C) stuff
-rw-r--r--ui.c102
-rw-r--r--ui.h21
-rw-r--r--ui_ani.c5
-rw-r--r--ui_elements.c4
-rw-r--r--ui_input.c17
-rw-r--r--ui_input.h7
-rw-r--r--ui_nwindow.c5
-rw-r--r--ui_statusbar.c5
8 files changed, 55 insertions, 111 deletions
diff --git a/ui.c b/ui.c
index 15d55e4..ef15d57 100644
--- a/ui.c
+++ b/ui.c
@@ -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();
diff --git a/ui.h b/ui.h
index 7273a15..91d5403 100644
--- a/ui.h
+++ b/ui.h
@@ -26,35 +26,28 @@
#define UIKEY_RIGHT 5
-typedef int (*ui_callback)(WINDOW *, void *, bool);
-typedef int (*ui_input_callback)(WINDOW *, void *, int);
+typedef int (*uicb_base)(WINDOW *, void *, bool);
+typedef int (*uicb_input)(WINDOW *, void *, int);
-struct ui_data {
- ui_callback ui_element;
- ui_input_callback ui_input;
+struct ui_callbacks {
+ uicb_base ui_element;
+ uicb_input ui_input;
};
struct nask_ui {
- enum ui_type type;
- union ui_data callback;
+ struct ui_callbacks cbs;
WINDOW *wnd;
void *data;
struct nask_ui *next;
};
void
-register_ui_elt(ui_callback uicb, void *data, WINDOW *wnd);
-
-void
-register_ui_input(ui_input_callback ipcb, void *data, WINDOW *wnd);
+register_ui_elt(struct ui_callbacks *cbs, void *data, WINDOW *wnd);
void
unregister_ui_elt(void *data);
-void
-unregister_ui_input(void *data);
-
int
activate_ui_input(void *data);
diff --git a/ui_ani.c b/ui_ani.c
index d38e090..c18ad4b 100644
--- a/ui_ani.c
+++ b/ui_ani.c
@@ -69,5 +69,8 @@ anic_cb(WINDOW *win, void *data, bool timed_out)
void
register_anic(struct anic *a)
{
- register_ui_elt(anic_cb, (void *) a, NULL);
+ struct ui_callbacks cbs;
+ cbs.ui_element = anic_cb;
+ cbs.ui_input = NULL;
+ register_ui_elt(&cbs, (void *) a, NULL);
}
diff --git a/ui_elements.c b/ui_elements.c
index 4b5c8cb..dc24d2f 100644
--- a/ui_elements.c
+++ b/ui_elements.c
@@ -66,8 +66,6 @@ static int
passwd_input_cb(WINDOW *wnd, void *data, int key)
{
struct input *a = (struct input *) data;
-printf("XXXXXXX\n");
-return DOUI_OK;
/*
* if ( process_key(key, pw_input, wnd_main) == false ) {
* curs_set(0);
@@ -131,7 +129,7 @@ free_ui_elements(void)
unregister_ui_elt(lower);
unregister_ui_elt(higher);
unregister_ui_elt(heartbeat);
- unregister_input(pw_input);
+ unregister_ui_elt(pw_input);
free_input(pw_input);
free_anic(heartbeat);
free_statusbar(higher);
diff --git a/ui_input.c b/ui_input.c
index 43836f1..21d2620 100644
--- a/ui_input.c
+++ b/ui_input.c
@@ -162,7 +162,7 @@ del_input(WINDOW *win, struct input *a)
return (UICB_OK);
}
-int
+static int
input_cb(WINDOW *win, void *data, bool timed_out)
{
struct input *a = (struct input *) data;
@@ -174,16 +174,11 @@ input_cb(WINDOW *win, void *data, bool timed_out)
}
void
-register_input(WINDOW *win, struct input *a, ui_input_callback uin)
+register_input(WINDOW *win, struct input *a, uicb_input ipcb)
{
- a->cb_input = uin;
- register_ui_elt(input_cb, (void *) a, win);
- register_ui_input(uin, (void *) a, win);
+ struct ui_callbacks cbs;
+ cbs.ui_element = input_cb;
+ cbs.ui_input = ipcb;
+ register_ui_elt(&cbs, (void *) a, win);
}
-void
-unregister_input(struct input *a)
-{
- unregister_ui_input( (void *) a );
- unregister_ui_elt( (void *) a );
-}
diff --git a/ui_input.h b/ui_input.h
index be93864..5407616 100644
--- a/ui_input.h
+++ b/ui_input.h
@@ -16,7 +16,7 @@ struct input {
char *prompt;
chtype attrs;
chtype shadow;
- ui_input_callback cb_input;
+ uicb_input cb_input;
};
struct input *
@@ -34,11 +34,8 @@ add_input(WINDOW *win, struct input *a, int key);
int
del_input(WINDOW *win, struct input *a);
-int
-input_cb(WINDOW *win, void *data, bool timed_out);
-
void
-register_input(WINDOW *win, struct input *a, ui_input_callback uin);
+register_input(WINDOW *win, struct input *a, uicb_input ipcb);
void
unregister_input(struct input *a);
diff --git a/ui_nwindow.c b/ui_nwindow.c
index 1b88319..aa1812d 100644
--- a/ui_nwindow.c
+++ b/ui_nwindow.c
@@ -94,7 +94,10 @@ txtwindow_cb(WINDOW *win, void *data, bool timedout)
void inline
register_txtwindow(struct txtwindow *a)
{
- register_ui_elt(txtwindow_cb, (void *) a, NULL);
+ struct ui_callbacks cbs;
+ cbs.ui_element = txtwindow_cb;
+ cbs.ui_input = NULL;
+ register_ui_elt(&cbs, (void *) a, NULL);
}
static size_t
diff --git a/ui_statusbar.c b/ui_statusbar.c
index 8172433..8fcfeb4 100644
--- a/ui_statusbar.c
+++ b/ui_statusbar.c
@@ -63,7 +63,10 @@ statusbar_cb(WINDOW *win, void *data, bool timed_out)
void
register_statusbar(struct statusbar *a)
{
- register_ui_elt(statusbar_cb, (void *) a, NULL);
+ struct ui_callbacks cbs;
+ cbs.ui_element = statusbar_cb;
+ cbs.ui_input = NULL;
+ register_ui_elt(&cbs, (void *) a, NULL);
}
inline void