Sorry for the broken patch.
There it is as an attachment.

Best regards,

Yvain

2017-07-26 12:18 GMT+02:00 Yvain Thonnart <[email protected]>:

> Actually, I just thought that this creates a regression for the existing
> .tmux.conf of users with 'set bell-on-alert on'
>
> Maybe a 'on' option could be added, which would alias 'BELL_OTHER' as the
> previous default behaviour ?
>
> Best regards,
>
> Yvain
>
> 2017-07-26 11:58 GMT+02:00 Yvain Thonnart <[email protected]>:
>
>> Hi Nicholas,
>>
>> Thanks for the feedback.
>> I tried and went for your second option in the patch below.
>>
>> 'bell-on-alert' mimics 'bell-action' as much as possible.
>> In particular, 'bell-on-alert' now notifies all the clients, as for
>> 'alerts_check_bell'
>>
>> Nevertheless, I kept the original behaviour of both visual+audible (or
>> hint),
>> instead of the if (!visible) in 'alerts_check_bell'.
>>
>> The patch also fixes a typo in 'alerts_check_bell', for
>> 'bell-action'=other (ws!=w -> ws==w)
>>
>> Is that what you had in mind ?
>>
>> Best regards,
>>
>> Yvain
>>
>>
>> From 38a59edc4ed70857e67d88c62d188ecd08515191 Mon Sep 17 00:00:00 2001
>> From: Yvain Thonnart <[email protected]>
>> Date: Wed, 26 Jul 2017 11:14:18 +0200
>> Subject: [PATCH] turn bell-on-alert to a choice option
>>
>> bell-on-alert becomes a choice option like bell-action.
>>
>> bell-on-alert [any | none | current | other]
>>         Set action on window alert.  any means an alert in any window
>> linked
>>         to a session causes an alert in the current window of that
>> session,
>>         none means all alerts are ignored, current means only alerts in
>> win-
>>         dows other than the current window are ignored and other means
>> alerts
>>         in the current window are ignored but not those in other windows.
>>
>> Rationale:
>> Bell can be used as an urgency hint.
>> Excluding current window is fine when the actual terminal running tmux is
>> in the foreground e.g. in a X session, but actually hides the upstream
>> notification to terminal and window-manager.
>>
>> Also fixes a typo in alerts_check_bell, for bell-action=other (ws!=w ->
>> ws==w)
>> ---
>>  alerts.c        | 85 ++++++++++++++++++++++++++++++
>> +++++++++++++++------------
>>  options-table.c |  5 ++--
>>  tmux.1          | 14 ++++++++--
>>  3 files changed, 81 insertions(+), 23 deletions(-)
>>
>> diff --git a/alerts.c b/alerts.c
>> index a489d44..9a9f627 100644
>> --- a/alerts.c
>> +++ b/alerts.c
>> @@ -199,7 +199,7 @@ alerts_check_bell(struct window *w)
>>
>>   if (action == BELL_CURRENT && ws != w)
>>   action = BELL_NONE;
>> - if (action == BELL_OTHER && ws != w)
>> + if (action == BELL_OTHER && ws == w)
>>   action = BELL_NONE;
>>
>>   if (!visual) {
>> @@ -222,8 +222,11 @@ alerts_check_bell(struct window *w)
>>  static int
>>  alerts_check_activity(struct window *w)
>>  {
>> + struct window *ws;
>>   struct winlink *wl;
>>   struct session *s;
>> + struct client *c;
>> + int action, visual;
>>
>>   if (~w->flags & WINDOW_ACTIVITY)
>>   return (0);
>> @@ -237,20 +240,41 @@ alerts_check_activity(struct window *w)
>>   if (wl->flags & WINLINK_ACTIVITY)
>>   continue;
>>   s = wl->session;
>> - if (s->curw == wl)
>> - continue;
>> -
>> - wl->flags |= WINLINK_ACTIVITY;
>> - notify_winlink("alert-activity", wl);
>> + if (s->curw != wl) {
>> + wl->flags |= WINLINK_ACTIVITY;
>> + notify_winlink("alert-activity", wl);
>> + }
>>
>>   if (s->flags & SESSION_ALERTED)
>>   continue;
>>   s->flags |= SESSION_ALERTED;
>>
>> - if (options_get_number(s->options, "bell-on-alert"))
>> - alerts_ring_bell(s);
>> - if (options_get_number(s->options, "visual-activity"))
>> - alerts_set_message(s, "Activity in window %d", wl->idx);
>> + action = options_get_number(s->options, "bell-on-alert");
>> + if (action == BELL_NONE)
>> + return (0);
>> +
>> + visual = options_get_number(s->options, "visual-activity");
>> + 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 (action != BELL_NONE)
>> + tty_putcode(&c->tty, TTYC_BEL);
>> + if (visual) {
>> + if (action == BELL_CURRENT)
>> + status_message_set(c, "Activity in current window");
>> + else if (action != BELL_NONE) {
>> + status_message_set(c, "Activity in window %d",
>> +    wl->idx);
>> + }
>> + }
>> + }
>>   }
>>
>>   return (WINDOW_ACTIVITY);
>> @@ -259,8 +283,11 @@ alerts_check_activity(struct window *w)
>>  static int
>>  alerts_check_silence(struct window *w)
>>  {
>> + struct window *ws;
>>   struct winlink *wl;
>>   struct session *s;
>> + struct client *c;
>> + int action, visual;
>>
>>   if (~w->flags & WINDOW_SILENCE)
>>   return (0);
>> @@ -274,19 +301,41 @@ alerts_check_silence(struct window *w)
>>   if (wl->flags & WINLINK_SILENCE)
>>   continue;
>>   s = wl->session;
>> - if (s->curw == wl)
>> - continue;
>> - wl->flags |= WINLINK_SILENCE;
>> - notify_winlink("alert-silence", wl);
>> + if (s->curw != wl) {
>> + wl->flags |= WINLINK_SILENCE;
>> + notify_winlink("alert-silence", wl);
>> + }
>>
>>   if (s->flags & SESSION_ALERTED)
>>   continue;
>>   s->flags |= SESSION_ALERTED;
>>
>> - if (options_get_number(s->options, "bell-on-alert"))
>> - alerts_ring_bell(s);
>> - if (options_get_number(s->options, "visual-silence"))
>> - alerts_set_message(s, "Silence in window %d", wl->idx);
>> + action = options_get_number(s->options, "bell-on-alert");
>> + if (action == BELL_NONE)
>> + return (0);
>> +
>> + visual = options_get_number(s->options, "visual-silence");
>> + 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 (action != BELL_NONE)
>> + tty_putcode(&c->tty, TTYC_BEL);
>> + if (visual) {
>> + if (action == BELL_CURRENT)
>> + status_message_set(c, "Silence in current window");
>> + else if (action != BELL_NONE) {
>> + status_message_set(c, "Silence in window %d",
>> +    wl->idx);
>> + }
>> + }
>> + }
>>   }
>>
>>   return (WINDOW_SILENCE);
>> diff --git a/options-table.c b/options-table.c
>> index 0c0039f..b7bbdcc 100644
>> --- a/options-table.c
>> +++ b/options-table.c
>> @@ -166,9 +166,10 @@ const struct options_table_entry options_table[] = {
>>   },
>>
>>   { .name = "bell-on-alert",
>> -  .type = OPTIONS_TABLE_FLAG,
>> +  .type = OPTIONS_TABLE_CHOICE,
>>    .scope = OPTIONS_TABLE_SESSION,
>> -  .default_num = 0
>> +  .choices = options_table_bell_action_list,
>> +  .default_num = BELL_NONE
>>   },
>>
>>   { .name = "default-command",
>> diff --git a/tmux.1 b/tmux.1
>> index 09eee74..24acb8e 100644
>> --- a/tmux.1
>> +++ b/tmux.1
>> @@ -2544,10 +2544,18 @@ means only bells in windows other than the
>> current window are ignored and
>>  .Ic other
>>  means bells in the current window are ignored but not those in other
>> windows.
>>  .It Xo Ic bell-on-alert
>> -.Op Ic on | off
>> +.Op Ic any | none | current | other
>>  .Xc
>> -If on, ring the terminal bell when an alert
>> -occurs.
>> +Set action on window alert.
>> +.Ic any
>> +means an alert in any window linked to a session causes an alert in the
>> +current window of that session,
>> +.Ic none
>> +means all alerts are ignored,
>> +.Ic current
>> +means only alerts in windows other than the current window are ignored
>> and
>> +.Ic other
>> +means alerts in the current window are ignored but not those in other
>> windows.
>>  .It Ic default-command Ar shell-command
>>  Set the command used for new windows (if not specified when the window is
>>  created) to
>> --
>> 2.7.0.25.gfc10eb5
>>
>>
>> 2017-07-26 9:32 GMT+02:00 Nicholas Marriott <[email protected]>
>> :
>>
>>> Hi
>>>
>>> Thanks - I don't think we should do this for everyone by default, but
>>> you could do a couple of things instead:
>>>
>>> - bell-on-alert could also check bell-action to decide whether to send
>>>   the bell (so bell-action "current" would also affect bell-on-alert);
>>>
>>> - Or bell-on-alert could become a three-state option like bell-action,
>>>   so you set bell-on-alert to "current" to make it work in the current
>>>   window.
>>>
>>> I think the second option would probably be better. In both cases you
>>> would need to change both alerts_check_activity and
>>> alerts_check_silence.
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 17, 2017 at 07:53:54PM +0200, Yvain Thonnart wrote:
>>> >    Dear tmux maintainers,
>>> >    First of all, many thanks for your impressive continued work on
>>> this great
>>> >    program.
>>> >    I stumbled upon an issue with activity monitoring in trying to
>>> setup a new
>>> >    workflow.
>>> >    I am using the bell as an urgency hint in most of my console
>>> programs, to
>>> >    notify my terminal and windowmanager (namely xterm and i3wm) of
>>> important
>>> >    notices. I have been using it with tmux to pass on a bell signal
>>> for a
>>> >    long time.
>>> >    Yet, as I recently tried to use activity monitoring, I found out
>>> that the
>>> >    alert is sent only when the alterting window is not the current
>>> window.
>>> >    However, as I am using several terminals and workspaces, the current
>>> >    window is not always visible, so I needed to create a dummy window
>>> to
>>> >    switch to in order to get the notification from the real window.
>>> >    I tried to play a bit with the options, and even with the hooks in
>>> the
>>> >    latest versions, with no success.
>>> >    Diggig in the code, I saw that you filter the alerts from the
>>> current
>>> >    window.
>>> >    I propose you a little modification, which actually suits my needs,
>>> where
>>> >    the bell is passed even in current window.
>>> >    Apparently your integration strategy is via email patches, so I
>>> will post
>>> >    it as a followup.
>>> >    I will be happy to discuss this, whether you think it is relevant
>>> or not,
>>> >    or if I missed a simple configuration setup...
>>> >    Best regards,A
>>> >    Yvain Thonnart
>>> >    --------------------
>>> >    Yvain THONNART (1):
>>> >    A  alerts: activity/silence bell in current window
>>> >    A alerts.c | 8 ++++----
>>> >    A 1 file changed, 4 insertions(+), 4 deletions(-)
>>> >
>>> >    --
>>> >    You received this message because you are subscribed to the Google
>>> Groups
>>> >    "tmux-users" group.
>>> >    To unsubscribe from this group and stop receiving emails from it,
>>> send an
>>> >    email to [email protected].
>>> >    To post to this group, send email to [email protected].
>>> >    For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: 0001-turn-bell-on-alert-to-a-choice-option.patch
Description: Binary data

Reply via email to