summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tk/button.c12
-rw-r--r--src/tk/check.c12
-rw-r--r--src/tk/radio.c12
-rw-r--r--src/tk/text.c10
-rw-r--r--src/tk/widget.c12
-rw-r--r--src/tk/widget.h10
-rw-r--r--src/tk/window.c5
7 files changed, 73 insertions, 0 deletions
diff --git a/src/tk/button.c b/src/tk/button.c
index ef7cf6c..90752eb 100644
--- a/src/tk/button.c
+++ b/src/tk/button.c
@@ -41,6 +41,18 @@ _mftk_button_layout(struct mftk_widget *w)
w->h = b->label->h + b->padding * 2;
}
+static void
+_mftk_button_focus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
+static void
+_mftk_button_defocus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
static int
_mftk_button_key_event(struct mftk_widget *w, SDL_Event *e)
{
diff --git a/src/tk/check.c b/src/tk/check.c
index fddd7cf..898a21e 100644
--- a/src/tk/check.c
+++ b/src/tk/check.c
@@ -80,6 +80,18 @@ _mftk_check_layout(struct mftk_widget *w)
}
}
+static void
+_mftk_check_focus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
+static void
+_mftk_check_defocus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
static int
_mftk_check_key_event(struct mftk_widget *w, SDL_Event *e)
{
diff --git a/src/tk/radio.c b/src/tk/radio.c
index d3001c3..f6fe474 100644
--- a/src/tk/radio.c
+++ b/src/tk/radio.c
@@ -71,6 +71,18 @@ _mftk_radio_layout(struct mftk_widget *w)
w->h = r->grid->h;
}
+static void
+_mftk_radio_focus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
+static void
+_mftk_radio_defocus(struct mftk_widget *w __attribute__((__unused__)))
+{
+ /* Nothing to do */
+}
+
static int
_mftk_radio_key_event(struct mftk_widget *w, SDL_Event *e)
{
diff --git a/src/tk/text.c b/src/tk/text.c
index a495cde..dedad4b 100644
--- a/src/tk/text.c
+++ b/src/tk/text.c
@@ -48,6 +48,16 @@ _mftk_text_layout(struct mftk_widget *w __attribute__((__unused__)))
/* Size set in constructor */
}
+static void
+_mftk_text_focus(struct mftk_widget *w __attribute__((__unused__)))
+{
+}
+
+static void
+_mftk_text_defocus(struct mftk_widget *w __attribute__((__unused__)))
+{
+}
+
static int
_mftk_text_key_event(struct mftk_widget *w, SDL_Event *e)
{
diff --git a/src/tk/widget.c b/src/tk/widget.c
index 5cd5878..f1d02dc 100644
--- a/src/tk/widget.c
+++ b/src/tk/widget.c
@@ -71,6 +71,18 @@ mftk_widget_index(struct mftk_widget *w, struct mftk_window *win)
}
}
+void
+mftk_widget_focus(struct mftk_widget *w)
+{
+ w->focus(w);
+}
+
+void
+mftk_widget_defocus(struct mftk_widget *w)
+{
+ w->defocus(w);
+}
+
int
mftk_widget_key_event(struct mftk_widget *w, SDL_Event *e)
{
diff --git a/src/tk/widget.h b/src/tk/widget.h
index a5634a5..e1826d2 100644
--- a/src/tk/widget.h
+++ b/src/tk/widget.h
@@ -43,6 +43,8 @@ struct mftk_widget {
void (*layout)(struct mftk_widget *);
void (*index)(struct mftk_widget *,
struct mftk_window *);
+ void (*focus)(struct mftk_widget *);
+ void (*defocus)(struct mftk_widget *);
int (*key_event)(struct mftk_widget *, SDL_Event *);
int (*mouse_event)(struct mftk_widget *, SDL_Event *,
int, int);
@@ -79,6 +81,8 @@ mftk_widget_new(size_t size);
return NULL; \
}; \
w->layout = &_mftk_##name##_layout; \
+ w->focus = &_mftk_##name##_focus; \
+ w->defocus = &_mftk_##name##_defocus; \
w->key_event = &_mftk_##name##_key_event; \
w->mouse_event = &_mftk_##name##_mouse_event; \
w->render = &_mftk_##name##_render; \
@@ -114,6 +118,12 @@ mftk_widget_layout(struct mftk_widget *w);
void
mftk_widget_index(struct mftk_widget *w, struct mftk_window *win);
+void
+mftk_widget_focus(struct mftk_widget *w);
+
+void
+mftk_widget_defocus(struct mftk_widget *w);
+
int
mftk_widget_mouse_event(struct mftk_widget *w, SDL_Event *e, int x, int y);
diff --git a/src/tk/window.c b/src/tk/window.c
index 64040bf..651a37b 100644
--- a/src/tk/window.c
+++ b/src/tk/window.c
@@ -49,6 +49,7 @@ mftk_window_new(struct mftk_widget *root)
mftk_widget_index(w->root, w);
w->focus = w->first;
w->focus->focused = SDL_TRUE;
+ mftk_widget_focus(w->focus);
return w;
}
@@ -80,12 +81,14 @@ mftk_window_event(struct mftk_window *w, SDL_Event *e)
switch (e->key.keysym.sym) {
case SDLK_TAB:
w->focus->focused = SDL_FALSE;
+ mftk_widget_defocus(w->focus);
if (e->key.keysym.mod & KMOD_SHIFT) {
w->focus = w->focus->prev;
} else {
w->focus = w->focus->next;
}
w->focus->focused = SDL_TRUE;
+ mftk_widget_focus(w->focus);
break;
default:
return mftk_widget_key_event(w->focus,
@@ -105,8 +108,10 @@ void
mftk_window_focus(struct mftk_window *win, struct mftk_widget *wid)
{
win->focus->focused = SDL_FALSE;
+ mftk_widget_defocus(win->focus);
win->focus = wid;
win->focus->focused = SDL_TRUE;
+ mftk_widget_focus(win->focus);
}
int