5

I like those notification bubbles of Unity, but the one thing I really hate of them is that I can't click them away.

I know when I hover above them they become almost transparent and that I may click through them on the window below, but I would prefer a small (x) icon to be able to close it.

Alternatively, it might also close when clicking anywhere on it, that does not matter.

Is it possible to set this up on Ubuntu 15.04 with Unity Desktop? How would I do this?

Byte Commander
  • 107,489
  • Hi Byte Commander, posted my answer. Please let me know if anything is unclear. – Jacob Vlijm Aug 05 '15 at 11:50
  • @JacobVlijm Sorry, I totally missed that you wrote one of your totally awesome scripts for me again! ;D – Byte Commander Aug 05 '15 at 12:34
  • Definitely a duplicate of Notify-send ignores timeout?. The second answer is what you need and even give you more then you need... ;-) (Sorry for having a better answer for once then one of your beautiful scripts @JacobVlijm) :P – Fabby Aug 09 '15 at 19:44
  • @Fabby I am a bit surprised you even can think of seeing this as a dupe. Both the question and the (goal of) the answer(s) are quite different. Am I missing something? This is totally not about ignoring time out, nor is the requested solution. – Jacob Vlijm Aug 09 '15 at 19:54
  • @JacobVlijm: Yes you're missing something: I have that repository installed and that's one of the things it allows you to do: hover over the message to keep it endlessly and click to make it go away and many more goodies... ;-) – Fabby Aug 09 '15 at 20:26
  • I see, but then still the fact that (part) of the answer suits the question does not make the question a dupe. See http://meta.askubuntu.com/questions/13964/dupe-but-no-dupe. – Jacob Vlijm Aug 09 '15 at 20:31

2 Answers2

4

Change the notification's mouse- over behaviour

Almost what you asked for, and possibly what you might like, a tiny, very light background script (no noticeable load to your system whatsoever, if no notification runs, it will only wait/check for one to appear) that will change the mouse-over effect of the notifications from fade:

enter image description here

enter image description here

to disappear (close):

enter image description here

This will only take effect if the mouse is moved from outside the area into the notification area, to make sure you won't miss the notifications if your mouse already is in the notification area if the message is launched.

How to use

  1. The script needs xdotool

    sudo apt-get install xdotool
    
  2. copy the script below into an empty file, save it as manage_notifications.py

  3. Test-run the script by the command:

    python3 /path/to/manage_notifications.py
    

    with the script running, open a terminal window and run the command:

    notify send 'This is a test'
    

    now move the mouse to the notification. Instead of fading, it should disappear.

  4. If all works fine, add it to your startup applications: Dash > Startup Applications > Add the command:

    /bin/bash -c "sleep 15 && python3 /path/to/manage_notifications.py"
    

The script

#!/usr/bin/env python3
import subprocess
import time

w = int([s.split("x")[0] for s in subprocess.check_output(
    ["xrandr"]).decode("utf-8").split() if "+0+0" in s][0]
        )

def get_mouse():
    loc = subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()[:2]
    return [int(n.split(":")[1]) for n in loc]

while True:
    time.sleep(1)
    try: 
        subprocess.check_output(["pgrep", "notify-osd"]).decode("utf-8")
        curloc1 = get_mouse(); t = 1
        while t < 10:
            time.sleep(1)
            curloc2 = get_mouse()
            test1 = curloc1[0] > w - 400 and curloc1[1] < 400
            test2 = curloc2[0] > w - 400 and curloc2[1] < 400
            if all([test1 == False, test2 == True]):
                subprocess.Popen(["pkill", "notify-osd"])
                break
            curloc1 = curloc2
            t = t+1
    except:
        pass
Jacob Vlijm
  • 83,767
0
  1. Go to Settings -> Keyboard -> Shortcuts -> Custom.
  2. Bind the command xkill to a keyboard shortcut (for instance I've set mine to AltShiftK )
  3. Whenever you see a notification, click the keyboard shortcut , hover the pointer over the notification, click it, and it goes away.
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Wrong. xkill-ing a notification bubble kills the window behind it instead and leaves the bubble intact! – Byte Commander Aug 09 '15 at 14:32
  • @ByteCommander Sorry, that was a bit of error on my side - I've installed xfce on my laptop with 15.04 before, and xfce replaces notify-osd with its own package xfce4-notifyd, popups from which are perfectly killable with xkill, but on pc with 14.04 I've same behavior as you described. I can suggest another alternative - bind pkill notify-osd to a keyboard shortcut and whenever you have a popup appear, hit the shortcut. Let me know if I should edit that into my answer – Sergiy Kolodyazhnyy Aug 09 '15 at 18:46
  • Yes, do the edit and I can remove my downvote. Give it a header that the above solution is XFCE only and it's at least a valid and correct answer. trying now whether the other suggestion works. – Byte Commander Aug 10 '15 at 16:46
  • I tried it and it seems to work, but when there are multiple notifications in a queue, it removes all of them instead of just making the currently displayed one disappear. If you could think of a workaround to that, it would be great, but I'll at least give you an upvote as soon as the edit is done. – Byte Commander Aug 10 '15 at 16:55