Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Library/Library.blp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Adw.PreferencesWindow library {
title: "User Interface";
}

Adw.PreferencesGroup library_platform {
title: "Platform APIs";
}

Adw.PreferencesGroup {
vexpand: true;
valign: end;
Expand Down
32 changes: 32 additions & 0 deletions src/Library/demos/Screenshot/main.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Gtk 4.0;
using Adw 1;

Adw.StatusPage {
title: "Screenshot";
description: _("Take a picture of the screen");
margin-top: 48;

Box {
orientation: vertical;
halign: center;

Box {
Picture picture {}
margin-bottom: 12;
width-request: 256;
height-request: 256;
}

Button button {
label: _("Take Screenshot");
margin-bottom: 42;
halign: center;
styles ["suggested-action"]
}

LinkButton {
label: "API Reference";
uri: "https://libportal.org/method.Portal.take_screenshot.html";
}
}
}
48 changes: 48 additions & 0 deletions src/Library/demos/Screenshot/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Xdp from "gi://Xdp";
import XdpGtk from "gi://XdpGtk4";
import Gio from "gi://Gio";
import Adw from "gi://Adw";

const portal = new Xdp.Portal();
const parent = XdpGtk.parent_new_gtk(workbench.window);

const button = workbench.builder.get_object("button");
const picture = workbench.builder.get_object("picture");

Gio._promisify(
Xdp.Portal.prototype,
"take_screenshot",
"take_screenshot_finish",
);

button.connect("clicked", () => {
takeScreenshot().catch(logError);
});

async function takeScreenshot() {
const flags = Xdp.ScreenshotFlags.NONE;

let uri;
try {
uri = await portal.take_screenshot(parent, flags, null);
} catch (err) {
showPermissionError();
return;
}

const file = Gio.File.new_for_uri(uri);
picture.set_file(file);
}

function showPermissionError() {
const dialog = new Adw.MessageDialog({
heading: "Permission Error",
body: "Ensure Screenshot permission is enabled in\nSettings → Apps → Workbench",
close_response: "ok",
modal: true,
transient_for: workbench.window,
});

dialog.add_response("ok", "OK");
dialog.present();
}
10 changes: 10 additions & 0 deletions src/Library/demos/Screenshot/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Screenshot",
"category": "platform",
"description": "Take a picture of the screen",
"panels": [
"code",
"preview"
],
"autorun": true
}