diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2014-04-10 17:23:49 -0700 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2014-05-12 23:34:05 -0700 |
commit | de6809912e1a4639b05a4098a346872f91d8103b (patch) | |
tree | ba547a286a2e8c412ca9841a7664125b5ac3b4f4 | |
parent | 5befdda84fe7cb2fb6d5d8986a5b8552a1372b8a (diff) |
terminal: Only add the new size to the title when we're resizing
Add a new state_changed_handler callback to the window to know when the
window has changed state; the terminal will use this to know when the
window started and ended its resize operation, and modify the terminal's
titlebar accordingly.
-rw-r--r-- | clients/terminal.c | 38 | ||||
-rw-r--r-- | clients/window.c | 17 | ||||
-rw-r--r-- | clients/window.h | 8 |
3 files changed, 49 insertions, 14 deletions
diff --git a/clients/terminal.c b/clients/terminal.c index 924549e1..cc603e98 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -834,12 +834,26 @@ terminal_resize_cells(struct terminal *terminal, } static void +update_title(struct terminal *terminal) +{ + if (window_is_resizing(terminal->window)) { + char *p; + if (asprintf(&p, "%s — [%dx%d]", terminal->title, terminal->width, terminal->height) > 0) { + window_set_title(terminal->window, p); + free(p); + } + } else { + window_set_title(terminal->window, terminal->title); + } +} + +static void resize_handler(struct widget *widget, int32_t width, int32_t height, void *data) { struct terminal *terminal = data; int32_t columns, rows, m; - char *p; + m = 2 * terminal->margin; columns = (width - m) / (int32_t) terminal->average_width; rows = (height - m) / (int32_t) terminal->extents.height; @@ -849,14 +863,17 @@ resize_handler(struct widget *widget, width = columns * terminal->average_width + m; height = rows * terminal->extents.height + m; widget_set_size(terminal->widget, width, height); - if (asprintf(&p, "%s — [%dx%d]", terminal->title, columns, rows) > 0) { - window_set_title(terminal->window, p); - terminal->size_in_title = 1; - free(p); - } } terminal_resize_cells(terminal, columns, rows); + update_title(terminal); +} + +static void +state_changed_handler(struct window *window, void *data) +{ + struct terminal *terminal = data; + update_title(terminal); } static void @@ -2745,14 +2762,6 @@ static int enter_handler(struct widget *widget, struct input *input, float x, float y, void *data) { - struct terminal *terminal = data; - - /* Reset title to get rid of resizing '[WxH]' in titlebar */ - if (terminal->size_in_title) { - window_set_title(terminal->window, terminal->title); - terminal->size_in_title = 0; - } - return CURSOR_IBEAM; } @@ -2860,6 +2869,7 @@ terminal_create(struct display *display) window_set_fullscreen_handler(terminal->window, fullscreen_handler); window_set_output_handler(terminal->window, output_handler); window_set_close_handler(terminal->window, close_handler); + window_set_state_changed_handler(terminal->window, state_changed_handler); window_set_data_handler(terminal->window, data_handler); window_set_drop_handler(terminal->window, drop_handler); diff --git a/clients/window.c b/clients/window.c index 6149618a..c46cb722 100644 --- a/clients/window.c +++ b/clients/window.c @@ -241,6 +241,7 @@ struct window { window_close_handler_t close_handler; window_fullscreen_handler_t fullscreen_handler; window_output_handler_t output_handler; + window_state_changed_handler_t state_changed_handler; struct surface *main_surface; struct xdg_surface *xdg_surface; @@ -3887,6 +3888,9 @@ handle_surface_configure(void *data, struct xdg_surface *xdg_surface, } window->next_attach_serial = serial; + + if (window->state_changed_handler) + window->state_changed_handler(window, window->user_data); } static void @@ -4178,6 +4182,12 @@ window_set_maximized(struct window *window, int maximized) xdg_surface_unset_maximized(window->xdg_surface); } +int +window_is_resizing(struct window *window) +{ + return window->resizing; +} + void window_set_minimized(struct window *window) { @@ -4247,6 +4257,13 @@ window_set_output_handler(struct window *window, } void +window_set_state_changed_handler(struct window *window, + window_state_changed_handler_t handler) +{ + window->state_changed_handler = handler; +} + +void window_set_title(struct window *window, const char *title) { free(window->title); diff --git a/clients/window.h b/clients/window.h index 5cf6b3e3..b7b3f6ae 100644 --- a/clients/window.h +++ b/clients/window.h @@ -219,6 +219,8 @@ typedef void (*window_fullscreen_handler_t)(struct window *window, void *data); typedef void (*window_output_handler_t)(struct window *window, struct output *output, int enter, void *data); +typedef void (*window_state_changed_handler_t)(struct window *window, + void *data); typedef void (*widget_resize_handler_t)(struct widget *widget, int32_t width, int32_t height, @@ -381,6 +383,9 @@ window_is_maximized(struct window *window); void window_set_maximized(struct window *window, int maximized); +int +window_is_resizing(struct window *window); + void window_set_minimized(struct window *window); @@ -415,6 +420,9 @@ window_set_fullscreen_handler(struct window *window, void window_set_output_handler(struct window *window, window_output_handler_t handler); +void +window_set_state_changed_handler(struct window *window, + window_state_changed_handler_t handler); void window_set_title(struct window *window, const char *title); |