diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-08-06 09:31:42 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-08-06 09:31:42 (EDT) |
commit | f6b656b1f211769b71ad1ddb1ae6c22f76ef7cdc (patch) | |
tree | 400243e9f7c383bb8835b1695e472daf09d535ba /src | |
parent | 4693d1d70855b97d57cdbe92552ba304362fb453 (diff) | |
download | mazefight-f6b656b1f211769b71ad1ddb1ae6c22f76ef7cdc.zip mazefight-f6b656b1f211769b71ad1ddb1ae6c22f76ef7cdc.tar.gz mazefight-f6b656b1f211769b71ad1ddb1ae6c22f76ef7cdc.tar.bz2 |
tk: Fix crash on focusing nested focusable widgets
Diffstat (limited to 'src')
-rw-r--r-- | src/tk/check.c | 14 | ||||
-rw-r--r-- | src/tk/radio.c | 4 | ||||
-rw-r--r-- | src/tk/widget.h | 3 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/tk/check.c b/src/tk/check.c index fbd3b23..30b7077 100644 --- a/src/tk/check.c +++ b/src/tk/check.c @@ -32,6 +32,7 @@ struct mftk_check { int state; int label_padding; struct mftk_widget *label; + int steals_focus; int (*action)(void *, int); void *user_data; }; @@ -52,6 +53,14 @@ mftk_check_set_state(struct mftk_widget *w, int state) c->state = state; } +void +mftk_check_set_steals_focus(struct mftk_widget *w, int steals_focus) +{ + struct mftk_check *c = (struct mftk_check *) w; + + c->steals_focus = steals_focus; +} + static void _mftk_check_layout(struct mftk_widget *w) { @@ -81,7 +90,9 @@ _mftk_check_event(struct mftk_widget *w, SDL_Event *e, switch (e->type) { case SDL_MOUSEBUTTONUP: if (e->button.button == SDL_BUTTON_LEFT) { - mftk_window_focus(w->window, w); + if (c->steals_focus == SDL_TRUE) { + mftk_window_focus(w->window, w); + } c->state = !c->state; if (c->action == NULL) { return 0; @@ -241,6 +252,7 @@ mftk_check_new(int butn_width, int butn_padding, SDL_Color *butn_color, c->mark_color = mark_color; c->state = state; c->label_padding = label_padding; + c->steals_focus = SDL_TRUE; c->action = action; c->user_data = user_data; diff --git a/src/tk/radio.c b/src/tk/radio.c index 6f767af..2c75406 100644 --- a/src/tk/radio.c +++ b/src/tk/radio.c @@ -79,13 +79,14 @@ _mftk_radio_event(struct mftk_widget *w, SDL_Event *e, int x, int y) case SDL_MOUSEBUTTONUP: if (e->button.button == SDL_BUTTON_LEFT) { mftk_window_focus(w->window, w); + return mftk_widget_event(r->grid, e, x, y); } break; default: break; } - return mftk_widget_event(r->grid, e, x, y); + return 0; } static int @@ -155,6 +156,7 @@ mftk_radio_new(int butn_width, int butn_padding, SDL_Color *butn_color, return NULL; } mftk_check_set_shape(r->children[i], MFTK_CHECK_SHAPE_CIR); + mftk_check_set_steals_focus(r->children[i], SDL_FALSE); r->states[i].r = r; r->states[i].state = i; } diff --git a/src/tk/widget.h b/src/tk/widget.h index 27400c4..e9a88cb 100644 --- a/src/tk/widget.h +++ b/src/tk/widget.h @@ -136,4 +136,7 @@ mftk_check_set_shape(struct mftk_widget *w, enum mftk_check_shape shape); void mftk_check_set_state(struct mftk_widget *w, int state); +void +mftk_check_set_steals_focus(struct mftk_widget *w, int steals_focus); + #endif /* MFTK_WIDGET_H_ */ |