Wednesday, June 15, 2011

Tweaking Notify-OSD, incl. GUI for Placement, all Ubuntus

The default version of Notify-OSD still doesn't support any kind of configuration. So, this is an update on the available PPAs and the new features added to the patched versions of it. I will also show how to configure it, and introduce here a GUI to change its position I wrote earlier.

I'm talking about the so-called notification bubbles that come up when an application issues, well, a notification:



These instructions are for all versions of Ubuntu down to Karmic Koala!

Install a patched version of Notify-OSD

First you need to install a patched version of "notify-osd", for example from Leolik's PPA.

In the Terminal, run these commands:

sudo add-apt-repository ppa:leolik/leolik
sudo apt-get update
sudo apt-get upgrade

PPA: https://launchpad.net/~leolik/+archive/leolik

It offers these additional features:
  • Modify the appearance of the bubble.
  • Set its timeout.
  • Modify its position on the screen.
  • Option to close it when clicked on.
  • Option to stop it from fading out when the mouse pointer is near or over it.
Note: The latter both options are only available in the build for Natty Narwhal.

NotifyOSD Configuration

With this tool, you can set
  • the appearance of the bubble,
  • its general positioning style, and
  • its timeout.


Installation in Karmic and Lucid

In the Terminal, run these commands:

sudo add-apt-repository ppa:amandeepgrewal/notifyosdconfig
sudo apt-get update
sudo apt-get install notifyosdconfig

PPA: https://launchpad.net/~amandeepgrewal/+archive/notifyosdconfig

Installation in Maverick and Natty

In the Terminal, run these commands:

sudo add-apt-repository ppa:irie/notifyconf
sudo apt-get update
sudo apt-get install notifyosdconfig

PPA: https://launchpad.net/~irie/+archive/notifyconf

Installation in Oneiric

Dowload the respective .deb package for your architecture from WebUpd8's PPA:

https://launchpad.net/~nilarimogard/+archive/webupd8/+packages?field.name_filter=notifyosdconfig&field.status_filter=published&field.series_filter=oneiric

Then install it either with Software Center or GDebi.

Note: The manual download method is to spare you from adding the whole PPA to your software sources, as it contains a whole lot of other packages as well, which you most probably don't want to upgrade through it.

Installation in Precise

Same as for Oneiric, just follow this link instead:

https://launchpad.net/~nilarimogard/+archive/webupd8/+packages?field.name_filter=notifyosdconfig&field.status_filter=published&field.series_filter=precise

Usage

After the installation, you will find it in "Applications > Accessories" in classic Gnome, or by typing its name into the Unity Dash.

Regarding its "Positioning" option, "Fixed" is the default and means there is a space between the bubble and the upper/lower panel or screen edge, "Dynamic" is just the other way around, no space.

When you press on "Apply", you will see a demo of the bubble's current setup.

Modifying its position on the screen

This is the part I'm most happy with, because I'm proud to be able to present you a GUI tool to do that. For those of you who are -like me- switching the position more often, and don't want to use the command line or Gconf-Editor each time for that.

The Manual Way

In the Terminal, enter:
  • up to Natty 11.04:
    gconftool-2 --set /apps/notify-osd/gravity --type=int [number]
  • from Oneiric 11.10 onwards:
    gsettings set com.canonical.notify-osd gravity [number]
Possible values for [number] are:
1 - top-right corner
2 - middle-right
3 - bottom-right corner
4 - bottom-left corner
5 - middle-left
6 - top-left corner

The GUI Way

Earlier, I've modified a Python script to create a little GUI with which one can easily set the position of the bubble. It makes use of the very same Gconf key and options as stated above.



Sorry, the initial installation may seem a bit multi-stepped, maybe I can provide a deb-package or PPA later.

Create the Script

1. In the Terminal, enter:

gksudo gedit /usr/local/bin/notifyosd-position.py

2. Paste this into the text editor:
  • up to Natty 11.04:
    #!/usr/bin/env python
    #
    # GUI to change the position of the Notify-OSD bubble
    #
    # Depends on python-gconf and a patched version of notify-osd
    #
    # Author: Krytarik
    #
    # 1 - top-right corner
    # 2 - middle-right
    # 3 - bottom-right corner
    # 4 - bottom-left corner
    # 5 - middle-left
    # 6 - top-left corner
    #
    
    import gtk
    import gconf
    
    def callback(button, client):
        global p1, p2, p3, p4, p5, p6, key, entry
        if p1.get_active():
            entry = 1
        elif p2.get_active():
            entry = 2
        elif p3.get_active():
            entry = 3
        elif p4.get_active():
            entry = 4
        elif p5.get_active():
            entry = 5
        elif p6.get_active():
            entry = 6
        client.set_int (key, entry)
    
    # Gconf stuff
    client = gconf.client_get_default ()
    key = "/apps/notify-osd/gravity"
    
    # Gtk window
    window = gtk.Window()
    window.set_geometry_hints(min_width=220, min_height=140, max_width=-1, max_height=-1, base_width=-1, base_height=-1, width_inc=-1, height_inc=-1, min_aspect=-1.0, max_aspect=-1.0)
    window.set_title("Notify-OSD")
    p1 = gtk.RadioButton(group=None, label='top right')
    p2 = gtk.RadioButton(p1, label='middle right')
    p3 = gtk.RadioButton(p1, label='bottom right')
    p6 = gtk.RadioButton(p1, label='top left')
    p5 = gtk.RadioButton(p1, label='middle left')
    p4 = gtk.RadioButton(p1, label='bottom left')
    box1 = gtk.VBox(False, 0)
    box1.add(gtk.Label("Choose the position for the bubble: "))
    box2 = gtk.VBox(False, 0)
    box2.add(p1)
    box2.add(p2)
    box2.add(p3)
    box3 = gtk.VBox(False, 0)
    box3.add(p6)
    box3.add(p5)
    box3.add(p4)
    table = gtk.Table(rows=3, columns=4, homogeneous=False)
    table.attach(box2, 3, 4, 1, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=0, ypadding=0)
    table.attach(box3, 1, 2, 1, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=0, ypadding=0)
    box1.add(table)
    done = gtk.Button('Done')
    box4 = gtk.HButtonBox()
    box4.add(done)
    box1.add(box4)
    window.add (box1)
    window.show_all ()
    
    # Widget events
    window.connect('delete_event', gtk.main_quit)
    done.connect('clicked', gtk.main_quit)
    p1.connect ('toggled', callback, client)
    p2.connect ('toggled', callback, client)
    p3.connect ('toggled', callback, client)
    p6.connect ('toggled', callback, client)
    p5.connect ('toggled', callback, client)
    p4.connect ('toggled', callback, client)
    
    # If key isn't writable, then set insensitive
    p1.set_sensitive (client.key_is_writable (key))
    p2.set_sensitive (client.key_is_writable (key))
    p3.set_sensitive (client.key_is_writable (key))
    p6.set_sensitive (client.key_is_writable (key))
    p5.set_sensitive (client.key_is_writable (key))
    p4.set_sensitive (client.key_is_writable (key))
    
    # Get current settings
    entry=client.get_int(key)
    if entry == 1:
            p1.set_active(True)
    elif entry == 2:
            p2.set_active(True)
    elif entry == 3:
            p3.set_active(True)
    elif entry == 4:
            p4.set_active(True)
    elif entry == 5:
            p5.set_active(True)
    elif entry == 6:
            p6.set_active(True)
    
    gtk.main ()
  • from Oneiric 11.10 onwards, Note: I didn't test it yet! :
    #!/usr/bin/env python
    #
    # GUI to change the position of the Notify-OSD bubble
    #
    # Depends on python-gconf and a patched version of notify-osd
    #
    # Author: Krytarik
    #
    # 1 - top-right corner
    # 2 - middle-right
    # 3 - bottom-right corner
    # 4 - bottom-left corner
    # 5 - middle-left
    # 6 - top-left corner
    #
    
    from gi.repository import Gio
    import gtk
    
    def callback(button, client):
        global p1, p2, p3, p4, p5, p6, key, entry
        if p1.get_active():
            entry = 1
        elif p2.get_active():
            entry = 2
        elif p3.get_active():
            entry = 3
        elif p4.get_active():
            entry = 4
        elif p5.get_active():
            entry = 5
        elif p6.get_active():
            entry = 6
        client.set_int (key, entry)
    
    # Gconf stuff
    client = Gio.Settings.new('com.canonical.notify-osd')
    key = 'gravity'
    
    # Gtk window
    window = gtk.Window()
    window.set_geometry_hints(min_width=220, min_height=140, max_width=-1, max_height=-1, base_width=-1, base_height=-1, width_inc=-1, height_inc=-1, min_aspect=-1.0, max_aspect=-1.0)
    window.set_title("Notify-OSD")
    p1 = gtk.RadioButton(group=None, label='top right')
    p2 = gtk.RadioButton(p1, label='middle right')
    p3 = gtk.RadioButton(p1, label='bottom right')
    p6 = gtk.RadioButton(p1, label='top left')
    p5 = gtk.RadioButton(p1, label='middle left')
    p4 = gtk.RadioButton(p1, label='bottom left')
    box1 = gtk.VBox(False, 0)
    box1.add(gtk.Label("Choose the position for the bubble: "))
    box2 = gtk.VBox(False, 0)
    box2.add(p1)
    box2.add(p2)
    box2.add(p3)
    box3 = gtk.VBox(False, 0)
    box3.add(p6)
    box3.add(p5)
    box3.add(p4)
    table = gtk.Table(rows=3, columns=4, homogeneous=False)
    table.attach(box2, 3, 4, 1, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=0, ypadding=0)
    table.attach(box3, 1, 2, 1, 3, xoptions=gtk.EXPAND, yoptions=gtk.EXPAND, xpadding=0, ypadding=0)
    box1.add(table)
    done = gtk.Button('Done')
    box4 = gtk.HButtonBox()
    box4.add(done)
    box1.add(box4)
    window.add (box1)
    window.show_all ()
    
    # Widget events
    window.connect('delete_event', gtk.main_quit)
    done.connect('clicked', gtk.main_quit)
    p1.connect ('toggled', callback, client)
    p2.connect ('toggled', callback, client)
    p3.connect ('toggled', callback, client)
    p6.connect ('toggled', callback, client)
    p5.connect ('toggled', callback, client)
    p4.connect ('toggled', callback, client)
    
    # If key isn't writable, then set insensitive
    p1.set_sensitive (client.is_writable (key))
    p2.set_sensitive (client.is_writable (key))
    p3.set_sensitive (client.is_writable (key))
    p6.set_sensitive (client.is_writable (key))
    p5.set_sensitive (client.is_writable (key))
    p4.set_sensitive (client.is_writable (key))
    
    # Get current settings
    entry=client.get_int(key)
    if entry == 1:
            p1.set_active(True)
    elif entry == 2:
            p2.set_active(True)
    elif entry == 3:
            p3.set_active(True)
    elif entry == 4:
            p4.set_active(True)
    elif entry == 5:
            p5.set_active(True)
    elif entry == 6:
            p6.set_active(True)
    
    gtk.main ()
3. Save the file, quit.

4. Make the script executable:

sudo chmod +x /usr/local/bin/notifyosd-position.py

Create the Launcher

1. In the Terminal, enter:

gksudo gedit /usr/share/applications/notifyosd-position.desktop

2. Paste this into the text editor:

[Desktop Entry]
Name=NotifyOSD Position
Comment=Change the position of Ubuntu's Notify-OSD bubble
Exec=notifyosd-position.py
Icon=gtk-info
Terminal=false
Type=Application
Categories=GNOME;GTK;Settings;DesktopSettings;
OnlyShowIn=GNOME;Unity;

3. Save the file, quit.

4. Update the menu item cache (otherwise done by dpkg during a usual installation/upgrade):

sudo rm /usr/share/applications/desktop.*.cache
sudo sh -c "/usr/share/gnome-menus/update-gnome-menus-cache /usr/share/applications/ > /usr/share/applications/desktop.${LANG}.cache"

Note: This last step can't be done in Oneiric 11.10, as it doesn't include those tool in the first place, and apparently doesn't do those caching anymore. There you just need to relogin for the new menu item to show up.

Usage

After the installation, you will find "NotifyOSD Position" in "System > Preferences" in classic Gnome, or by typing its name into the Unity Dash.

Setting Close-on-Click and Disable-Fade-out

So far, there is no GUI way to toggle these settings, you have to edit the file "~/.notify-osd" manually, it's in the top level of your home directory, and since it's a hidden file, press Ctrl+H to make it show in Nautilus.

Note: Both of these settings should be applied after using NotifyOSD Configuration, because it would otherwise unset these changes again!

Close-on-Click

Paste this into your "~/.notify-osd":

bubble-close-on-click = 1

Disable-Fade-out

Paste this into your "~/.notify-osd":

bubble-prevent-fade = 1

Revert

To revert to the default behaviour, just remove the respective line again, or set its value to "0".

Restart Notify-OSD

After either of those changes, restart "notify-osd" to apply the new settings. In the Terminal, enter:

killall notify-osd

Note: It will be restarted by any application trying to use it.

Related Posts:

Appearance