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
  • 110,243

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
  • 85,475
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.