[BACK]Return to alerts.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/alerts.c between version 1.20 and 1.21

version 1.20, 2017/06/28 06:45:31 version 1.21, 2017/07/26 16:14:08
Line 34 
Line 34 
 static int      alerts_check_bell(struct window *);  static int      alerts_check_bell(struct window *);
 static int      alerts_check_activity(struct window *);  static int      alerts_check_activity(struct window *);
 static int      alerts_check_silence(struct window *);  static int      alerts_check_silence(struct window *);
 static void printflike(2, 3) alerts_set_message(struct session *, const char *,  static void     alerts_set_message(struct session *, struct window *,
                     ...);                      struct winlink *, const char *, int, int);
 static void     alerts_ring_bell(struct session *);  
   
 static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);  static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);
   
Line 162 
Line 161 
 static int  static int
 alerts_check_bell(struct window *w)  alerts_check_bell(struct window *w)
 {  {
         struct window   *ws;  
         struct winlink  *wl;          struct winlink  *wl;
         struct session  *s;          struct session  *s;
         struct client   *c;  
         int              action, visual;  
   
         if (~w->flags & WINDOW_BELL)          if (~w->flags & WINDOW_BELL)
                 return (0);                  return (0);
Line 187 
Line 183 
                         continue;                          continue;
                 s->flags |= SESSION_ALERTED;                  s->flags |= SESSION_ALERTED;
   
                 action = options_get_number(s->options, "bell-action");                  alerts_set_message(s, w, wl, "Bell",
                 if (action == BELL_NONE)                      options_get_number(s->options, "bell-action"),
                         return (0);                      options_get_number(s->options, "visual-bell"));
   
                 visual = options_get_number(s->options, "visual-bell");  
                 TAILQ_FOREACH(c, &clients, entry) {  
                         if (c->session != s || c->flags & CLIENT_CONTROL)  
                                 continue;  
                         ws = c->session->curw->window;  
   
                         if (action == BELL_CURRENT && ws != w)  
                                 action = BELL_NONE;  
                         if (action == BELL_OTHER && ws != w)  
                                 action = BELL_NONE;  
   
                         if (!visual) {  
                                 if (action != BELL_NONE)  
                                         tty_putcode(&c->tty, TTYC_BEL);  
                                 continue;  
                         }  
                         if (action == BELL_CURRENT)  
                                 status_message_set(c, "Bell in current window");  
                         else if (action != BELL_NONE) {  
                                 status_message_set(c, "Bell in window %d",  
                                     wl->idx);  
                         }  
                 }  
         }          }
   
         return (WINDOW_BELL);          return (WINDOW_BELL);
Line 237 
Line 209 
                 if (wl->flags & WINLINK_ACTIVITY)                  if (wl->flags & WINLINK_ACTIVITY)
                         continue;                          continue;
                 s = wl->session;                  s = wl->session;
                 if (s->curw == wl)                  if (s->curw != wl) {
                         continue;                          wl->flags |= WINLINK_ACTIVITY;
                           notify_winlink("alert-activity", wl);
                   }
   
                 wl->flags |= WINLINK_ACTIVITY;  
                 notify_winlink("alert-activity", wl);  
   
                 if (s->flags & SESSION_ALERTED)                  if (s->flags & SESSION_ALERTED)
                         continue;                          continue;
                 s->flags |= SESSION_ALERTED;                  s->flags |= SESSION_ALERTED;
   
                 if (options_get_number(s->options, "bell-on-alert"))                  alerts_set_message(s, w, wl, "Activity",
                         alerts_ring_bell(s);                      options_get_number(s->options, "activity-action"),
                 if (options_get_number(s->options, "visual-activity"))                      options_get_number(s->options, "visual-activity"));
                         alerts_set_message(s, "Activity in window %d", wl->idx);  
         }          }
   
         return (WINDOW_ACTIVITY);          return (WINDOW_ACTIVITY);
Line 264 
Line 234 
   
         if (~w->flags & WINDOW_SILENCE)          if (~w->flags & WINDOW_SILENCE)
                 return (0);                  return (0);
         if (!options_get_number(w->options, "monitor-silence"))          if (options_get_number(w->options, "monitor-silence") == 0)
                 return (0);                  return (0);
   
         TAILQ_FOREACH(wl, &w->winlinks, wentry)          TAILQ_FOREACH(wl, &w->winlinks, wentry)
Line 274 
Line 244 
                 if (wl->flags & WINLINK_SILENCE)                  if (wl->flags & WINLINK_SILENCE)
                         continue;                          continue;
                 s = wl->session;                  s = wl->session;
                 if (s->curw == wl)                  if (s->curw != wl) {
                         continue;                          wl->flags |= WINLINK_SILENCE;
                 wl->flags |= WINLINK_SILENCE;                          notify_winlink("alert-silence", wl);
                 notify_winlink("alert-silence", wl);                  }
   
                 if (s->flags & SESSION_ALERTED)                  if (s->flags & SESSION_ALERTED)
                         continue;                          continue;
                 s->flags |= SESSION_ALERTED;                  s->flags |= SESSION_ALERTED;
   
                 if (options_get_number(s->options, "bell-on-alert"))                  alerts_set_message(s, w, wl, "Silence",
                         alerts_ring_bell(s);                      options_get_number(s->options, "silence-action"),
                 if (options_get_number(s->options, "visual-silence"))                      options_get_number(s->options, "visual-silence"));
                         alerts_set_message(s, "Silence in window %d", wl->idx);  
         }          }
   
         return (WINDOW_SILENCE);          return (WINDOW_SILENCE);
 }  }
   
 static void  static void
 alerts_set_message(struct session *s, const char *fmt, ...)  alerts_set_message(struct session *s, struct window *w, struct winlink *wl,
       const char *type, int action, int visual)
 {  {
         struct client   *c;          struct client   *c;
         va_list          ap;          int              flag;
         char            *message;  
   
         va_start(ap, fmt);          /*
         xvasprintf(&message, fmt, ap);           * We have found an alert (bell, activity or silence), so we need
         va_end(ap);           * to notify the user. For each client attached to this session,
            * decide whether a bell (or visual message) is needed.
            *
            * {bell,activity,silence}-action determines when we notify: none means
            * nothing happens, current means we only do something for the current
            * window and other means only for windows other than the current.
            *
            * If visual-{bell,activity,silence} is on, then a message is
            * substituted for a bell; if it is off, a bell is sent as normal; both
            * mean both a bell and visual message is sent.
            */
   
           if (action == BELL_NONE)
                   return;
         TAILQ_FOREACH(c, &clients, entry) {          TAILQ_FOREACH(c, &clients, entry) {
                 if (c->session == s)                  if (c->session != s || c->flags & CLIENT_CONTROL)
                         status_message_set(c, "%s", message);                          continue;
         }                  flag = 0;
                   if (action == BELL_ANY)
                           flag = 1;
                   else if (action == BELL_CURRENT)
                           flag = (c->session->curw->window == w);
                   else if (action == BELL_OTHER)
                           flag = (c->session->curw->window != w);
                   if (!flag)
                           continue;
   
         free(message);                  if (visual == VISUAL_OFF || visual == VISUAL_BOTH)
 }  
   
 static void  
 alerts_ring_bell(struct session *s)  
 {  
         struct client   *c;  
   
         TAILQ_FOREACH(c, &clients, entry) {  
                 if (c->session == s && !(c->flags & CLIENT_CONTROL))  
                         tty_putcode(&c->tty, TTYC_BEL);                          tty_putcode(&c->tty, TTYC_BEL);
                   if (visual == VISUAL_OFF)
                           continue;
                   if (c->session->curw->window == w)
                           status_message_set(c, "%s in current window", type);
                   else
                           status_message_set(c, "%s in window %d", type, wl->idx);
         }          }
 }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21