From 97350f6488c9e431d4b93a173734c9a3735769d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 21 Jul 2019 17:35:53 +0200 Subject: [PATCH] term: track current window title in terminal struct --- main.c | 3 ++- osc.c | 6 +++--- terminal.c | 9 +++++++++ terminal.h | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index aedc1a29..f2d03171 100644 --- a/main.c +++ b/main.c @@ -589,7 +589,7 @@ main(int argc, char *const *argv) xdg_toplevel_add_listener(term.wl.xdg_toplevel, &xdg_toplevel_listener, &term); xdg_toplevel_set_app_id(term.wl.xdg_toplevel, "foot"); - render_set_title(&term, "foot"); + term_set_window_title(&term, "foot"); wl_surface_commit(term.wl.surface); wl_display_roundtrip(term.wl.display); @@ -848,6 +848,7 @@ out: for (int row = 0; row < term.alt.num_rows; row++) grid_row_free(term.alt.rows[row]); free(term.alt.rows); + free(term.window_title); for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++) { struct font *f = &term.fonts[i]; diff --git a/osc.c b/osc.c index 02f393b6..9ec73ac2 100644 --- a/osc.c +++ b/osc.c @@ -234,9 +234,9 @@ osc_dispatch(struct terminal *term) } switch (param) { - case 0: render_set_title(term, string); break; /* icon + title */ - case 1: break; /* icon */ - case 2: render_set_title(term, string); break; /* title */ + case 0: term_set_window_title(term, string); break; /* icon + title */ + case 1: break; /* icon */ + case 2: term_set_window_title(term, string); break; /* title */ case 52: osc_selection(term, string); break; case 104: /* Reset Color Number 'c' */ diff --git a/terminal.c b/terminal.c index 8871c06f..84bfcc31 100644 --- a/terminal.c +++ b/terminal.c @@ -10,6 +10,7 @@ #define LOG_ENABLE_DBG 0 #include "log.h" #include "grid.h" +#include "render.h" #include "vt.h" #define min(x, y) ((x) < (y) ? (x) : (y)) @@ -460,3 +461,11 @@ term_mouse_motion(struct terminal *term, int button, int row, int col, break; } } + +void +term_set_window_title(struct terminal *term, const char *title) +{ + free(term->window_title); + term->window_title = strdup(title); + render_set_title(term, term->window_title); +} diff --git a/terminal.h b/terminal.h index c757065a..fd924b42 100644 --- a/terminal.h +++ b/terminal.h @@ -245,6 +245,7 @@ struct terminal { int selected_charset; enum charset charset[4]; /* G0-G3 */ + char *window_title; struct vt vt; struct kbd kbd; @@ -341,3 +342,5 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl); void term_mouse_motion(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl); + +void term_set_window_title(struct terminal *term, const char *title);