Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically toggle notifications for the current buffer when WeeChat looses or gains focus #6

Open
lburgazzoli opened this issue Mar 13, 2017 · 17 comments

Comments

@lburgazzoli
Copy link

Hello,

I'm unable to find a way to get a notification when a message is received on a buffer (or weechat itself) has lost focus i.e. I'm writing on on a buffer then I open the browser so weechat is now hidded behind the browser and I do not receive any notification of messages received on the buffer I was on: is there any configuration to do to achieve so ?

Thx

@s3rvac
Copy link
Owner

s3rvac commented Mar 13, 2017

Hi,

the notification plugin does not care whether WeeChat has focus or not. Frankly, I don't even know how I would detect this :). So, notifications should be sent even when WeeChat doesn't have focus.

Can you tell me the following?

  • Used WeeChat client + version.
  • Used operating system + version.
  • Any other information that you think might be relevant.

I will then try to reproduce the issue.

@s3rvac s3rvac self-assigned this Mar 13, 2017
@s3rvac s3rvac changed the title Notification when focus is lost No notifications when focus is lost Mar 13, 2017
@lburgazzoli
Copy link
Author

Hi,
yeah, I do not know if WeeChat has an option to detect if a buffer/windows has lost focus but it would be useful as one does not need to switch app just to check if there are unread messages. In my setup, I have notify_send.notify_for_current_buffer = "off" because I do not want to receive notification on a buffer I'm actively watching (with focus).

My setup:

  • Fedora 25
  • WeeChat 1.7 (build from source)
  • Notify Send 0.7

The plugin configuration is:

python.notify_send.ellipsis = "[..]"
python.notify_send.escape_html = "on"
python.notify_send.icon = "/usr/share/icons/hicolor/32x32/apps/weechat.png"
python.notify_send.ignore_buffers = ""
python.notify_send.ignore_buffers_starting_with = ""
python.notify_send.ignore_nicks = ""
python.notify_send.ignore_nicks_starting_with = ""
python.notify_send.max_length = "72"
python.notify_send.min_notification_delay = "500"
python.notify_send.nick_separator = ": "
python.notify_send.notify_for_current_buffer = "off"
python.notify_send.notify_on_highlights = "on"
python.notify_send.notify_on_privmsgs = "on"
python.notify_send.notify_when_away = "on"
python.notify_send.timeout = "5000"
python.notify_send.urgency = "normal"
python.notify_send.ellipsis = "Ellipsis to be used for notifications that are too long. Default: [..]."
python.notify_send.escape_html = "Escapes the '<', '>', and '&' characters in notification messages. Default: on."
python.notify_send.icon = "Path to an icon to be shown in notifications. Default: /usr/share/icons/hicolor/32x32/apps/weechat.png."
python.notify_send.ignore_buffers = "A comma-separated list of buffers from which no notifications should be shown. Default: ""."
python.notify_send.ignore_buffers_starting_with = "A comma-separated list of buffer prefixes from which no notifications should be shown. Default: ""."
python.notify_send.ignore_nicks = "A comma-separated list of nicks from which no notifications should be shown. Default: ""."
python.notify_send.ignore_nicks_starting_with = "A comma-separated list of nick prefixes from which no notifications should be shown. Default: ""."
python.notify_send.max_length = "Maximal length of a notification (0 means no limit). Default: 72."
python.notify_send.min_notification_delay = "A minimal delay between successive notifications from the same buffer (in milliseconds; set to 0 to show all notifications). Default: 500."
python.notify_send.nick_separator = "A separator between a nick and a message. Default: : ."
python.notify_send.notify_for_current_buffer = "Send also notifications for the currently active buffer. Default: on."
python.notify_send.notify_on_highlights = "Send notifications on highlights. Default: on."
python.notify_send.notify_on_privmsgs = "Send notifications on private messages. Default: on."
python.notify_send.notify_when_away = "Send also notifications when away. Default: on."
python.notify_send.timeout = "Time after which the notification disappears (in milliseconds; set to 0 to disable). Default: 5000."
python.notify_send.urgency = "Urgency (low, normal, critical). Default: normal."

@s3rvac
Copy link
Owner

s3rvac commented Mar 13, 2017

Unfortunately, I am unable to reproduce the issue. This is what I tried:

  • Installed Fedora 25 64b into a virtual machine (VirtualBox).
  • Installed required WeeChat dependencies.
  • Downloaded WeeChat 1.7, built it from source, and installed.
  • Downloaded and installed the plugin.
  • Run WeeChat from terminal, set python.notify_send.notify_for_current_buffer to off.
  • Connected to IRC and started a private conversion (/query other_user).
  • Changed the current buffer to the WeeChat's main buffer (because of python.notify_send.notify_for_current_buffer).
  • Opened Firefox.
  • In another WeeChat client, sent a message in the opened query.
  • In Fedora, I received a notification for the message, even when the currently opened window was Firefox.

Can you please verify that the above process really gives you no notification? When WeeChat has focus, you receive the notification?

@lburgazzoli
Copy link
Author

lburgazzoli commented Mar 13, 2017 via email

@s3rvac
Copy link
Owner

s3rvac commented Mar 14, 2017

What I do not do is:

  • Changed the current buffer to the WeeChat's main buffer (because of python.notify_send.notify_for_current_buffer)

I just switch app vis alt-tab

I think there might be a misunderstanding about what the notify_for_current_buffer option does. By default, it is on, which means you will receive notifications for all buffers, even for the current buffer. When you turn it off, you will not receive any notifications for the currently selected buffer. Therefore, when you have it off and just switch to a different app via Alt-Tab, you won't get any notifications. This is expected behavior. The plugin does to check whether WeeChat has focus or not.

Can you turn the option back on and check whether this makes the notifications to appear when you do Alt-Tab to a different app?

@lburgazzoli
Copy link
Author

lburgazzoli commented Mar 14, 2017

Yeah in that case it works, but would be lovely to take app focus into account :)

@s3rvac
Copy link
Owner

s3rvac commented Mar 14, 2017

I see. I will mark this issue as a feature request then.

Unfortunately, I have no idea how to check whether WeeChat has focus or not. This a common problem shared by terminal applications. On WeeChat's FAQ, there is a question and answer related to this, but without a portable solution.

So, I am afraid that there is nothing I can do right now. We will have to wait until there is a way of checking whether WeeChat has focus or not.

@s3rvac s3rvac changed the title No notifications when focus is lost Add a way of enabling notifications for the current buffer when WeeChat looses focus Mar 14, 2017
@lburgazzoli
Copy link
Author

no worries :)

@maximbaz
Copy link

maximbaz commented Jan 10, 2018

Hey guys, there is actually a pretty standard way to achieve this today. You can you "xterm focus events" to execute commands in weechat when it gains and loses focus, see here for an example.

So what you need to do is the following:

  • Make sure you have a modern xterm-compatible terminal. It seems to be important that your $TERM starts with xterm prefix too.
  • If you use tmux, add set -g focus-events on to your .tmux.conf (don't trust the link above saying that tmux is not supported, it works perfectly).

Now enable the support for focus-events:

/set weechat.startup.command_after_plugins "/print -stdout \033[?1004h\n"

And configure this plugin to disable and enable notifications on focus gained and focus lost events:

/key bind meta2-I /set plugins.var.python.notify_for_current_buffer off
/key bind meta2-O /set plugins.var.python.notify_for_current_buffer on

I wish there was a global toggle to turn on and off any kind of notifications in all buffers, I would use that one in the configuration above.

Or for a complete toggle:

/key bind meta2-I /script unload notify_send.py
/key bind meta2-O /script load notify_send.py

@sudoforge
Copy link

don't trust the link above saying that tmux is not supported, it works perfectly

From that page:

If you use tmux, you must additionally enable focus events by adding set -g focus-events on to your .tmux.conf file.

@sudoforge
Copy link

sudoforge commented Jul 4, 2018

Additionally, it seems that this should be added to the README - although note that @maximbaz got the option names in the key bindings incorrect; they should be:

/key bind meta2-I /set plugins.var.python.notify_send.notify_for_current_buffer off
/key bind meta2-O /set plugins.var.python.notify_send.notify_for_current_buffer on

@s3rvac
Copy link
Owner

s3rvac commented Jul 8, 2018

Additionally, it seems that this should be added to the README

I will happily take a PR for that.

@s3rvac s3rvac changed the title Add a way of enabling notifications for the current buffer when WeeChat looses focus Automatically turn off notifications for the current buffer when WeeChat looses focus Jul 8, 2018
@maximbaz
Copy link

maximbaz commented Jul 8, 2018

don't trust the link above saying that tmux is not supported, it works perfectly

From that page:

If you use tmux, you must additionally enable focus events by adding set -g focus-events on to your .tmux.conf file.

Turns out their docs are on Github, so I fixed them. Now you can trust the docs again 😉

Thanks for catching the typos 👍

@sudoforge
Copy link

@s3rvac You changed the title to:

Automatically turn off notifications for the current buffer when WeeChat looses focus

This is the opposite of the goal(s) described in the comments here, which is to enable/"turn on" notifications when Weechat loses focus, and disable them when it gains focus - that way you aren't notified when you are currently using Weechat. Instead, I think this title would be slightly clearer:

Automatically toggle notifications for the current buffer when WeeChat looses or gains focus

@s3rvac s3rvac changed the title Automatically turn off notifications for the current buffer when WeeChat looses focus Automatically toggle notifications for the current buffer when WeeChat looses or gains focus Jul 8, 2018
@s3rvac
Copy link
Owner

s3rvac commented Jul 8, 2018

@sudoforge You are right. I have corrected the title to the one that you suggested.

@sudoforge
Copy link

I've been testing the above stated configuration (through regular usage) over the past few days. I'll submit a PR for the change to the README when I am confident that the solution works without any additional configuration needed -- I initially ran into a bug in which the binding for meta2-I did not persist. I wasn't able to determine the cause of the issue, but will be waiting (and suggest waiting) a few days before patching the README.

@sudoforge
Copy link

sudoforge commented Sep 24, 2018

An update on this:

It seems to work fine, save for one minor sometimes-inconvenient action of the keybindings being printed if the window is in a context that doesn't process the keybindings. As an example, with the above settings, if Weechat is loaded and you are prompted for your secure db's passphrase, triggering the focus event (by changing windows, or creating a new tmux pane) will cause characters to be printed to the passphrase input field, causing users to have to manually delete them before entering their password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants