diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index f0dcf9e..28b0892 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -210,6 +210,20 @@ static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc, kmscon_pty_resize(term->pty, term->cols, term->rows); } +static void widget_prepare_resize(struct wlt_widget *widget, + unsigned int width, unsigned int height, + unsigned int *new_width, + unsigned int *new_height, + void *data) +{ + struct wlt_terminal *term = data; + + if (*new_width < width) + *new_width = width; + if (*new_height < height) + *new_height = height; +} + static void widget_key(struct wlt_widget *widget, unsigned int mask, uint32_t sym, uint32_t state, void *data) { @@ -326,7 +340,8 @@ int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd) wlt_widget_set_destroy_cb(term->widget, widget_destroy); wlt_widget_set_redraw_cb(term->widget, widget_redraw); - wlt_widget_set_resize_cb(term->widget, NULL, widget_resize); + wlt_widget_set_resize_cb(term->widget, widget_prepare_resize, + widget_resize); wlt_widget_set_keyboard_cb(term->widget, widget_key); *out = term; return 0; diff --git a/src/wlt_theme.c b/src/wlt_theme.c index de54cc7..c7d7b64 100644 --- a/src/wlt_theme.c +++ b/src/wlt_theme.c @@ -252,26 +252,28 @@ static void widget_redraw(struct wlt_widget *widget, void *data) } static void widget_prepare_resize(struct wlt_widget *widget, - unsigned int *width, unsigned int *height, + unsigned int width, unsigned int height, + unsigned int *new_width, + unsigned int *new_height, void *data) { struct wlt_theme *theme = data; - unsigned int minw, minh; + unsigned int minw, minh, tw, th; minw = theme->frame_width * 2; minh = theme->control_height + theme->frame_width * 2; - if (*width < minw) - *width = minw; - if (*height < minh) - *height = minh; - minw = 2 * theme->button_margin + 2 * theme->button_padding + - 3 * theme->button_size; - minh = theme->button_size + 2 * theme->button_padding; - if (*width < minw) - *width = minw; - if (*height < minh) - *height = minh; + tw = 2 * theme->button_margin + 2 * theme->button_padding + + 3 * theme->button_size; + th = theme->button_size + 2 * theme->button_padding; + + if (minw < tw) + minw = tw; + if (minh < th) + minh = th; + + *new_width += minw; + *new_height += minh; } static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc, diff --git a/src/wlt_toolkit.c b/src/wlt_toolkit.c index dc15864..49a78ad 100644 --- a/src/wlt_toolkit.c +++ b/src/wlt_toolkit.c @@ -1036,18 +1036,26 @@ static int resize_window(struct wlt_window *wnd, unsigned int width, struct wlt_pool *old_pool = NULL; size_t nsize; int ret; - unsigned int oldw, oldh; + unsigned int oldw, oldh, neww, newh; if (!wnd || !width || !height) return -EINVAL; + neww = 0; + newh = 0; shl_dlist_for_each(iter, &wnd->widget_list) { widget = shl_dlist_entry(iter, struct wlt_widget, list); if (widget->prepare_resize_cb) - widget->prepare_resize_cb(widget, &width, &height, + widget->prepare_resize_cb(widget, width, height, + &neww, &newh, widget->data); } + if (neww) + width = neww; + if (newh) + height = newh; + if (width == wnd->buffer.width && height == wnd->buffer.height) return 0; diff --git a/src/wlt_toolkit.h b/src/wlt_toolkit.h index 2780969..fce4921 100644 --- a/src/wlt_toolkit.h +++ b/src/wlt_toolkit.h @@ -82,8 +82,10 @@ typedef void (*wlt_widget_redraw_cb) (struct wlt_widget *widget, typedef void (*wlt_widget_destroy_cb) (struct wlt_widget *widget, void *data); typedef void (*wlt_widget_prepare_resize_cb) (struct wlt_widget *widget, - unsigned int *width, - unsigned int *height, + unsigned int width, + unsigned int height, + unsigned int *new_width, + unsigned int *new_height, void *data); typedef void (*wlt_widget_resize_cb) (struct wlt_widget *widget, struct wlt_rect *allocation,