}
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;
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
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;
}
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);
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;
}
window->next_attach_serial = serial;
+
+ if (window->state_changed_handler)
+ window->state_changed_handler(window, window->user_data);
}
static void
xdg_surface_unset_maximized(window->xdg_surface);
}
+int
+window_is_resizing(struct window *window)
+{
+ return window->resizing;
+}
+
void
window_set_minimized(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);
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,
void
window_set_maximized(struct window *window, int maximized);
+int
+window_is_resizing(struct window *window);
+
void
window_set_minimized(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);