Rather than duplicating the same logic between monitoring bells in all or
the current window, instead centralise the logic of looping over all
windows, and for the purposes of rendering visual-* alerts, only check the
bell type at that point, and print the appropriate message.
---
 trunk/server-window.c |   50 ++++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)

diff --git a/trunk/server-window.c b/trunk/server-window.c
index 69e4c6c..2fc0e21 100644
--- a/trunk/server-window.c
+++ b/trunk/server-window.c
@@ -76,46 +76,24 @@ server_window_check_bell(struct session *s, struct winlink 
*wl)
                return (0);
        if (s->curw != wl || s->flags & SESSION_UNATTACHED)
                wl->flags |= WINLINK_BELL;
+       if (s->flags & SESSION_UNATTACHED)
+               return (1);
 
+       visual = options_get_number(&s->options, "visual-bell");
        action = options_get_number(&s->options, "bell-action");
-       switch (action) {
-       case BELL_ANY:
-               if (s->flags & SESSION_UNATTACHED)
-                       break;
-               visual = options_get_number(&s->options, "visual-bell");
-               for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
-                       c = ARRAY_ITEM(&clients, i);
-                       if (c == NULL || c->session != s)
-                               continue;
-                       if (!visual) {
-                               tty_bell(&c->tty);
-                               continue;
-                       }
-                       if (c->session->curw->window == w) {
-                               status_message_set(c, "Bell in current window");
-                               continue;
-                       }
-                       status_message_set(c, "Bell in window %u",
-                           winlink_find_by_window(&s->windows, w)->idx);
+       for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+               c = ARRAY_ITEM(&clients, i);
+               if (c == NULL || c->session != s)
+                       continue;
+               if (!visual) {
+                       tty_bell(&c->tty);
+                       continue;
                }
-               break;
-       case BELL_CURRENT:
-               if (s->flags & SESSION_UNATTACHED)
-                       break;
-               visual = options_get_number(&s->options, "visual-bell");
-               for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
-                       c = ARRAY_ITEM(&clients, i);
-                       if (c == NULL || c->session != s)
-                               continue;
-                       if (c->session->curw->window != w)
-                               continue;
-                       if (!visual) {
-                               tty_bell(&c->tty);
-                               continue;
-                       }
+               if (c->session->curw->window == w)
                        status_message_set(c, "Bell in current window");
-               }
-               break;
+               else if (action == BELL_ANY)
+                       status_message_set(c, "Bell in window %u",
+                               winlink_find_by_window(&s->windows, w)->idx);
        }
 
        return (1);
-- 
1.7.10


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to