From f6b656b1f211769b71ad1ddb1ae6c22f76ef7cdc Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 06 Aug 2021 09:31:42 -0400 Subject: tk: Fix crash on focusing nested focusable widgets --- (limited to 'src/tk/check.c') 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; -- cgit v0.9.1