With tweaks by Philip Withnall <philip@tecnocode.co.uk>. https://bugzilla.gnome.org/show_bug.cgi?id=658446