Skip to content

Instantly share code, notes, and snippets.

@felipeborges
Last active July 22, 2019 12:16
Show Gist options
  • Save felipeborges/dafb921ead2dced34acf4094e0c277d4 to your computer and use it in GitHub Desktop.
Save felipeborges/dafb921ead2dced34acf4094e0c277d4 to your computer and use it in GitHub Desktop.
// valac --pkg gtk+-3.0 test_xdg_desktop_portal_wallpaper.vala
namespace org.freedesktop.portal {
[DBus (name = "org.freedesktop.portal.Wallpaper")]
interface Wallpaper : Object {
public abstract GLib.ObjectPath ShowWallpaperPreview (string app_id, string uri) throws GLib.Error;
public abstract GLib.ObjectPath SetWallpaper (string app_id, string uri) throws GLib.Error;
}
}
public async void show_wallpaper_preview () {
var bus = yield Bus.get (BusType.SESSION);
var wallpaper = yield bus.get_proxy <org.freedesktop.portal.Wallpaper> ("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop");
var response = wallpaper.ShowWallpaperPreview ("org.gnome.MyApp", "file:///home/feborges/bg.png");
print ("RESPONSE = %s\n", response);
}
public async void set_wallpaper () {
var bus = yield Bus.get (BusType.SESSION);
var wallpaper = yield bus.get_proxy <org.freedesktop.portal.Wallpaper> ("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop");
wallpaper.SetWallpaper ("org.gnome.MyApp", "file:///home/feborges/wp.jpg");
}
public class MyApplication : Gtk.Application {
public MyApplication () {
application_id = "org.gnome.MyApp";
}
protected override void activate () {
var window = new Gtk.ApplicationWindow (this);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
var button = new Gtk.Button.with_label ("Show Wallpaper Preview");
button.clicked.connect (() => { show_wallpaper_preview (); });
box.add (button);
var set_wp_button = new Gtk.Button.with_label ("Set Wallpaper");
set_wp_button.clicked.connect (() => { set_wallpaper (); });
box.add (set_wp_button);
window.add (box);
window.set_title ("Welcome to GNOME");
window.set_default_size (200, 100);
window.show_all ();
}
}
public int main (string[] args) {
GLib.Environment.set_application_name ("Wallpaper APP");
return new MyApplication ().run (args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment