dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 1ee40ba4b2496c42686cda5475e1632511d2d15d
parent 95e4ab913ec1b36816dd76ceb416c53169427b6a
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 23 Oct 2014 14:55:05 +0200

Simplify title changing callback interface

Diffstat:
dvtm.c | 22+++++++++-------------
vt.c | 12+++++-------
vt.h | 9++-------
3 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/dvtm.c b/dvtm.c @@ -461,19 +461,15 @@ applycolorrules(Client *c) { } static void -term_event_handler(Vt *term, int event, void *event_data) { +term_title_handler(Vt *term, const char *title) { Client *c = (Client *)vt_get_data(term); - switch (event) { - case VT_EVENT_TITLE: - if (event_data) - strncpy(c->title, event_data, sizeof(c->title) - 1); - c->title[event_data ? sizeof(c->title) - 1 : 0] = '\0'; - settitle(c); - if (!isarrange(fullscreen) || sel == c) - draw_border(c); - applycolorrules(c); - break; - } + if (title) + strncpy(c->title, title, sizeof(c->title) - 1); + c->title[title ? sizeof(c->title) - 1 : 0] = '\0'; + settitle(c); + if (!isarrange(fullscreen) || sel == c) + draw_border(c); + applycolorrules(c); } static void @@ -820,7 +816,7 @@ create(const char *args[]) { if (args && args[2] && !strcmp(args[2], "$CWD")) free(cwd); vt_set_data(c->term, c); - vt_set_event_handler(c->term, term_event_handler); + vt_title_handler_set(c->term, term_title_handler); c->w = screen.w; c->h = screen.h; c->x = wax; diff --git a/vt.c b/vt.c @@ -146,8 +146,7 @@ struct Vt { /* xterm style window title */ char title[256]; - - vt_event_handler_t event_handler; + vt_title_handler_t title_handler; void *data; }; @@ -883,12 +882,11 @@ static void interpret_osc(Vt *t) char *data = NULL; int command = strtoul(t->ebuf + 1, &data, 10); if (data && *data == ';') { - ++data; switch (command) { case 0: /* icon name and window title */ case 2: /* window title */ - if (t->event_handler) - t->event_handler(t, VT_EVENT_TITLE, data); + if (t->title_handler) + t->title_handler(t, data+1); break; case 1: /* icon name */ break; @@ -1723,9 +1721,9 @@ void vt_shutdown(void) free(color2palette); } -void vt_set_event_handler(Vt *t, vt_event_handler_t handler) +void vt_title_handler_set(Vt *t, vt_title_handler_t handler) { - t->event_handler = handler; + t->title_handler = handler; } void vt_set_data(Vt *t, void *data) diff --git a/vt.h b/vt.h @@ -32,17 +32,12 @@ #endif typedef struct Vt Vt; - -enum { - VT_EVENT_TITLE, -}; - -typedef void (*vt_event_handler_t)(Vt *, int event, void *data); +typedef void (*vt_title_handler_t)(Vt*, const char *data); void vt_init(void); void vt_set_keytable(char const * const keytable_overlay[], int count); void vt_shutdown(void); -void vt_set_event_handler(Vt *, vt_event_handler_t); +void vt_title_handler_set(Vt*, vt_title_handler_t); void vt_set_data(Vt *, void *); void *vt_get_data(Vt *); void vt_set_default_colors(Vt *, attr_t attrs, short fg, short bg);