Skip to content

Commit

Permalink
library: Add Wallpaper entry (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoNiC-HeRE committed Jun 18, 2023
1 parent 8de3874 commit e74f337
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Library/demos/Wallpaper/main.blp
@@ -0,0 +1,25 @@
using Gtk 4.0;
using Adw 1;

Adw.StatusPage {
title: _("Wallpaper");
description: _("Request to set the user desktop background image");
margin-top: 48;

Box {
orientation: vertical;
halign: center;

Button button {
label: _("Set Wallpaper");
margin-bottom: 42;
halign: center;
styles ["suggested-action", "pill"]
}

LinkButton {
label: "API Reference";
uri: "https://libportal.org/method.Portal.set_wallpaper.html";
}
}
}
34 changes: 34 additions & 0 deletions src/Library/demos/Wallpaper/main.js
@@ -0,0 +1,34 @@
import Gio from "gi://Gio";
import Xdp from "gi://Xdp";
import XdpGtk from "gi://XdpGtk4";

const portal = new Xdp.Portal();
const parent = XdpGtk.parent_new_gtk(workbench.window);
const button = workbench.builder.get_object("button");

const file = Gio.File.new_for_path(pkg.pkgdatadir).resolve_relative_path(
"Library/demos/Wallpaper/wallpaper.png",
);

Gio._promisify(Xdp.Portal.prototype, "set_wallpaper", "set_wallpaper_finish");

async function onClicked() {
const success = await portal.set_wallpaper(
parent,
file.get_uri(),
Xdp.WallpaperFlags.PREVIEW |
Xdp.WallpaperFlags.BACKGROUND |
Xdp.WallpaperFlags.LOCKSCREEN,
null,
);

if (success) {
console.log("Wallpaper set successfully");
} else {
console.log("Could not set wallpaper");
}
}

button.connect("clicked", () => {
onClicked().catch(logError);
});
7 changes: 7 additions & 0 deletions src/Library/demos/Wallpaper/main.json
@@ -0,0 +1,7 @@
{
"name": "Wallpaper",
"category": "platform",
"description": "Request to set the user desktop background image",
"panels": ["code", "preview"],
"autorun": true
}
Binary file added src/Library/demos/Wallpaper/wallpaper.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/about.js
Expand Up @@ -47,7 +47,10 @@ ${getBlueprintVersion()}
"Sonny Piers https://sonny.re",
"Tobias Bernard <tbernard@gnome.org>",
],
artists: ["Tobias Bernard <tbernard@gnome.org>"],
artists: [
"Tobias Bernard <tbernard@gnome.org>",
"Jakub Steiner https://jimmac.eu",
],
});

dialog.add_credit_section(_("Contributors"), [
Expand Down

0 comments on commit e74f337

Please sign in to comment.