dvtm

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

commit e175687badcdb3be5e363b103c827f342f121b2a
parent 60ddc2413c3a119a31fedce7feaf92fea6e3a609
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 21 Nov 2014 09:26:42 +0100

Notification suppoert aka urgent flags

Diffstat:
config.def.h | 5++++-
dvtm.1 | 3---
dvtm.c | 49++++++++++++++++++++++++++++++++++---------------
vt.c | 20++++++++------------
vt.h | 7+++----
5 files changed, 49 insertions(+), 35 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -26,6 +26,8 @@ static Color colors[] = { #define SELECTED_ATTR (COLOR(BLUE) | A_NORMAL) /* curses attributes for normal (not selected) windows */ #define NORMAL_ATTR (COLOR(DEFAULT) | A_NORMAL) +/* curses attributes for a window with pending urgent flag */ +#define URGENT_ATTR NORMAL_ATTR /* curses attributes for the status bar */ #define BAR_ATTR (COLOR(BLUE) | A_NORMAL) /* status bar (command line option -s) position */ @@ -52,6 +54,8 @@ static Color colors[] = { #define TAG_NORMAL (COLOR(DEFAULT) | A_NORMAL) /* curses attributes for not selected tags which contain windows */ #define TAG_OCCUPIED (COLOR(BLUE) | A_NORMAL) +/* curses attributes for not selected tags which with urgent windows */ +#define TAG_URGENT (COLOR(BLUE) | A_NORMAL | A_BLINK) const char tags[][8] = { "1", "2", "3", "4", "5" }; @@ -104,7 +108,6 @@ static KeyBinding bindings[] = { { { MOD, 'a', }, { togglerunall, { NULL } } }, { { MOD, CTRL('L'), }, { redraw, { NULL } } }, { { MOD, 'r', }, { redraw, { NULL } } }, - { { MOD, 'B', }, { togglebell, { NULL } } }, { { MOD, 'e', }, { copymode, { NULL } } }, { { MOD, '/', }, { copymode, { "/" } } }, { { MOD, 'p', }, { paste, { NULL } } }, diff --git a/dvtm.1 b/dvtm.1 @@ -153,9 +153,6 @@ Redraw whole screen. Toggle keyboard multiplexing mode, if activated keypresses are sent to all visible windows. .TP -.B Mod\-B -Toggle bell (off by default). -.TP .B Mod\-M Toggle dvtm mouse grabbing. .TP diff --git a/dvtm.c b/dvtm.c @@ -75,6 +75,7 @@ struct Client { unsigned short int h; bool has_title_line; bool minimized; + bool urgent; volatile sig_atomic_t died; Client *next; Client *prev; @@ -193,7 +194,6 @@ static void setmfact(const char *args[]); static void startup(const char *args[]); static void tag(const char *args[]); static void togglebar(const char *args[]); -static void togglebell(const char *key[]); static void toggleminimize(const char *args[]); static void togglemouse(const char *args[]); static void togglerunall(const char *args[]); @@ -299,12 +299,15 @@ updatebarpos(void) { static void drawbar(void) { int sx, sy, x = 0; - unsigned int occupied = 0; + unsigned int occupied = 0, urgent = 0; if (bar.pos == BAR_OFF) return; - for (Client *c = clients; c; c = c->next) + for (Client *c = clients; c; c = c->next) { occupied |= c->tags; + if (c->urgent) + urgent |= c->tags; + } getyx(stdscr, sy, sx); attrset(BAR_ATTR); @@ -313,6 +316,8 @@ drawbar(void) { for (unsigned int i = 0; i < LENGTH(tags); i++){ if (tagset[seltags] & (1 << i)) attrset(TAG_SEL); + else if (urgent & (1 << i)) + attrset(TAG_URGENT); else if (occupied & (1 << i)) attrset(TAG_OCCUPIED); else @@ -355,12 +360,17 @@ show_border(void) { static void draw_border(Client *c) { + char t = '\0'; + int x, y, maxlen, attrs = NORMAL_ATTR; + if (!show_border()) return; - char t = '\0'; - int x, y, maxlen; + if (sel == c || (runinall && !c->minimized)) + attrs = SELECTED_ATTR; + if (sel != c && c->urgent) + attrs = URGENT_ATTR; - wattrset(c->window, (sel == c || (runinall && !c->minimized)) ? SELECTED_ATTR : NORMAL_ATTR); + wattrset(c->window, attrs); getyx(c->window, y, x); mvwhline(c->window, 0, 0, ACS_HLINE, c->w); maxlen = c->w - (2 + STRLEN(TITLE) - STRLEN("%s%sd") + STRLEN(SEPARATOR) + 2); @@ -526,22 +536,25 @@ detachstack(Client *c) { static void focus(Client *c) { - Client *tmp = sel; if (!c) for (c = stack; c && !isvisible(c); c = c->snext); if (sel == c) return; lastsel = sel; sel = c; - if (tmp && !isarrange(fullscreen)) { - draw_border(tmp); - wnoutrefresh(tmp->window); + if (lastsel) { + lastsel->urgent = false; + if (!isarrange(fullscreen)) { + draw_border(lastsel); + wnoutrefresh(lastsel->window); + } } if (c) { detachstack(c); attachstack(c); settitle(c); + c->urgent = false; if (isarrange(fullscreen)) { draw(c); } else { @@ -584,6 +597,15 @@ term_title_handler(Vt *term, const char *title) { } static void +term_urgent_handler(Vt *term) { + Client *c = (Client *)vt_data_get(term); + c->urgent = true; + printf("\a"); + fflush(stdout); + drawbar(); +} + +static void move_client(Client *c, int x, int y) { if (c->x == x && c->y == y) return; @@ -799,6 +821,7 @@ keypress(int code) { for (Client *c = runinall ? nextvisible(clients) : sel; c; c = nextvisible(c->next)) { if (is_content_visible(c)) { + c->urgent = false; if (code == '\e') vt_write(c->term, buf, len); else @@ -978,6 +1001,7 @@ create(const char *args[]) { free(cwd); vt_data_set(c->term, c); vt_title_handler_set(c->term, term_title_handler); + vt_urgent_handler_set(c->term, term_urgent_handler); c->x = wax; c->y = way; debug("client with pid %d forked\n", c->pid); @@ -1238,11 +1262,6 @@ togglebar(const char *args[]) { } static void -togglebell(const char *args[]) { - vt_togglebell(sel->term); -} - -static void toggleminimize(const char *args[]) { Client *c, *m, *t; unsigned int n; diff --git a/vt.c b/vt.c @@ -192,6 +192,7 @@ struct Vt { int srow, scol; /* last known offset to display start row, start column */ char title[256]; /* xterm style window title */ vt_title_handler_t title_handler; /* hook which is called when title changes */ + vt_urgent_handler_t urgent_handler; /* hook which is called upon bell */ void *data; /* user supplied data */ }; @@ -1247,8 +1248,8 @@ static void process_nonprinting(Vt *t, wchar_t wc) new_escape_sequence(t); break; case '\a': /* BEL */ - if (t->bell) - beep(); + if (t->urgent_handler) + t->urgent_handler(t); break; case '\b': /* BS */ if (b->curs_col > 0) @@ -1550,16 +1551,6 @@ void vt_noscroll(Vt *t) vt_scroll(t, scroll_below); } -void vt_bell(Vt *t, bool bell) -{ - t->bell = bell; -} - -void vt_togglebell(Vt *t) -{ - t->bell = !t->bell; -} - pid_t vt_forkpty(Vt *t, const char *p, const char *argv[], const char *cwd, const char *env[], int *to, int *from) { int vt2ed[2], ed2vt[2]; @@ -1838,6 +1829,11 @@ void vt_title_handler_set(Vt *t, vt_title_handler_t handler) t->title_handler = handler; } +void vt_urgent_handler_set(Vt *t, vt_urgent_handler_t handler) +{ + t->urgent_handler = handler; +} + void vt_data_set(Vt *t, void *data) { t->data = data; diff --git a/vt.h b/vt.h @@ -27,7 +27,8 @@ #endif typedef struct Vt Vt; -typedef void (*vt_title_handler_t)(Vt*, const char *data); +typedef void (*vt_title_handler_t)(Vt*, const char *title); +typedef void (*vt_urgent_handler_t)(Vt*); void vt_init(void); void vt_shutdown(void); @@ -35,6 +36,7 @@ void vt_shutdown(void); void vt_keytable_set(char const * const keytable_overlay[], int count); void vt_default_colors_set(Vt*, attr_t attrs, short fg, short bg); void vt_title_handler_set(Vt*, vt_title_handler_t); +void vt_urgent_handler_set(Vt*, vt_urgent_handler_t); void vt_data_set(Vt*, void *); void *vt_data_get(Vt*); @@ -57,9 +59,6 @@ short vt_color_reserve(short fg, short bg); void vt_scroll(Vt*, int rows); void vt_noscroll(Vt*); -void vt_bell(Vt*, bool bell); -void vt_togglebell(Vt*); - pid_t vt_pid_get(Vt*); size_t vt_content_get(Vt*, char **s); int vt_content_start(Vt*);