Is there a way to add an image as a sticky note to my Unity Desktop?

Solution 1:

Showing an image on your desktop

Windows can be of different types. We do not only have "normal" windows, but also windows of (in our case) type "DESKTOP".

Windows of type "DESKTOP" stay below everyting; even all items on your desktop show up above them. Therefore showing an image in a window then results into:

enter image description here

...where the sundew image, pinned on the desktop, is actually a window (just like the desktop clock in the image btw).

The code

#!/usr/bin/env python3
import gi
gi.require_version('GdkPixbuf', '2.0')
from gi.repository import GdkPixbuf
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
import sys

img = sys.argv[1]
xpos = int(sys.argv[2])
ypos = int(sys.argv[3])
w = int(sys.argv[4])
h = int(sys.argv[5])

class ShowPortrait(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="PortraitonMyDesktop")
        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.connect("destroy", Gtk.main_quit)
        self.set_skip_taskbar_hint(True)
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
            img, w, h, preserve_aspect_ratio=True,
            )
        image = Gtk.Image.new_from_pixbuf(pixbuf)
        self.add(image)
        self.move(xpos, ypos)
        self.show_all()

ShowPortrait()
Gtk.main()

How to use

  1. Copy the script into an empty file, save it as showportrait.py
  2. Test- run it with the image, the x-position, y-position, width and height as arguments:

    python3 /path/to/showportrait.py /path/to/image x y width height
    

    for example:

    python3 '/home/jacob/Desktop/showportrait.py' '/home/jacob/Thema/Wallpapers/sundew.jpg' 1000 200 400 400
    

    The image should show on your desktop.

  3. If all works fine, add the command to Startup Applications.

Closing the window

Is easyest done by the command:

kill "$(pgrep -f showportrait.py)"

Note

Setting the width/hight, the script will scale the image until the first is reached, preserving the image' proportions.