aboutsummaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-04 16:46:23 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-04 16:46:23 +0000
commit14b951254674c75d8422a8ac5f320a54d1dd8a48 (patch)
treee361a5b014694cb4b609f6c05cd54ce250cf669d /session.c
parentf7ba4dfdc91eb3121ca070a0706d0ec2dfe502e1 (diff)
downloadrtmux-14b951254674c75d8422a8ac5f320a54d1dd8a48.tar.gz
rtmux-14b951254674c75d8422a8ac5f320a54d1dd8a48.tar.bz2
rtmux-14b951254674c75d8422a8ac5f320a54d1dd8a48.zip
Add activity monitoring, also invert items on taskbar which have activity.
Diffstat (limited to 'session.c')
-rw-r--r--session.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/session.c b/session.c
index 0748c117..52d7fd0f 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.33 2008-06-03 21:42:37 nicm Exp $ */
+/* $Id: session.c,v 1.34 2008-06-04 16:46:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,40 +29,51 @@
struct sessions sessions;
void
-session_cancelbell(struct session *s, struct winlink *wl)
+session_alert_cancel(struct session *s, struct winlink *wl)
{
- u_int i;
+ struct session_alert *sa, *sb;
- for (i = 0; i < ARRAY_LENGTH(&s->bells); i++) {
- if (ARRAY_ITEM(&s->bells, i) == wl) {
- ARRAY_REMOVE(&s->bells, i);
- break;
+ sa = TAILQ_FIRST(&s->alerts);
+ while (sa != NULL) {
+ sb = sa;
+ sa = TAILQ_NEXT(sa, entry);
+
+ if (wl == NULL || sb->wl == wl) {
+ TAILQ_REMOVE(&s->alerts, sb, entry);
+ xfree(sb);
}
}
}
void
-session_addbell(struct session *s, struct window *w)
+session_alert_add(struct session *s, struct window *w, int type)
{
- struct winlink *wl;
+ struct session_alert *sa;
+ struct winlink *wl;
RB_FOREACH(wl, winlinks, &s->windows) {
if (wl == s->curw)
continue;
- if (wl->window == w && !session_hasbell(s, wl))
- ARRAY_ADD(&s->bells, wl);
+
+ if (wl->window == w && !session_alert_has(s, wl, type)) {
+ sa = xmalloc(sizeof *sa);
+ sa->wl = wl;
+ sa->type = type;
+ TAILQ_INSERT_HEAD(&s->alerts, sa, entry);
+ }
}
}
int
-session_hasbell(struct session *s, struct winlink *wl)
+session_alert_has(struct session *s, struct winlink *wl, int type)
{
- u_int i;
+ struct session_alert *sa;
- for (i = 0; i < ARRAY_LENGTH(&s->bells); i++) {
- if (ARRAY_ITEM(&s->bells, i) == wl)
+ TAILQ_FOREACH(sa, &s->alerts, entry) {
+ if (sa->wl == wl && sa->type == type)
return (1);
}
+
return (0);
}
@@ -94,7 +105,7 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
fatal("clock_gettime");
s->curw = s->lastw = NULL;
RB_INIT(&s->windows);
- ARRAY_INIT(&s->bells);
+ TAILQ_INIT(&s->alerts);
options_init(&s->options, &global_options);
s->sx = sx;
@@ -138,6 +149,7 @@ session_destroy(struct session *s)
while (!ARRAY_EMPTY(&sessions) && ARRAY_LAST(&sessions) == NULL)
ARRAY_TRUNC(&sessions, 1);
+ session_alert_cancel(s, NULL);
options_free(&s->options);
while (!RB_EMPTY(&s->windows))
@@ -194,7 +206,7 @@ session_detach(struct session *s, struct winlink *wl)
if (s->lastw == wl)
s->lastw = NULL;
- session_cancelbell(s, wl);
+ session_alert_cancel(s, wl);
winlink_remove(&s->windows, wl);
if (RB_EMPTY(&s->windows)) {
session_destroy(s);
@@ -232,7 +244,7 @@ session_next(struct session *s)
return (1);
s->lastw = s->curw;
s->curw = wl;
- session_cancelbell(s, wl);
+ session_alert_cancel(s, wl);
return (0);
}
@@ -252,7 +264,7 @@ session_previous(struct session *s)
return (1);
s->lastw = s->curw;
s->curw = wl;
- session_cancelbell(s, wl);
+ session_alert_cancel(s, wl);
return (0);
}
@@ -269,7 +281,7 @@ session_select(struct session *s, int idx)
return (1);
s->lastw = s->curw;
s->curw = wl;
- session_cancelbell(s, wl);
+ session_alert_cancel(s, wl);
return (0);
}
@@ -287,6 +299,6 @@ session_last(struct session *s)
s->lastw = s->curw;
s->curw = wl;
- session_cancelbell(s, wl);
+ session_alert_cancel(s, wl);
return (0);
}