Skip to content
Draft
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
3 changes: 3 additions & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<file compressed="true">Application.css</file>
</gresource>
<gresource prefix="/io/elementary/xdg-desktop-portal-pantheon/icons">
<file alias="48x48/emblems/emblem-portal-usb.svg" compressed="true" preprocess="xml-stripblanks">icons/usb.svg</file>
<file alias="48x48@2/emblems/emblem-portal-usb.svg" compressed="true" preprocess="xml-stripblanks">icons/usb.svg</file>

<file alias="48x48/emblems/emblem-portal-screencast.svg" compressed="true" preprocess="xml-stripblanks">icons/screencast.svg</file>
<file alias="48x48@2/emblems/emblem-portal-screencast.svg" compressed="true" preprocess="xml-stripblanks">icons/screencast.svg</file>

Expand Down
2 changes: 2 additions & 0 deletions data/icons/usb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/pantheon.portal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.pantheon
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Background;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.ScreenCast
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Background;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Usb;org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.ScreenCast
UseIn=pantheon
2 changes: 2 additions & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ src/Background/Portal.vala
src/ScreenCast/Dialog.vala
src/ScreenCast/MonitorTracker/Interface.vala
src/Screenshot/SetupDialog.vala
src/Usb/Dialog.vala
src/Usb/Portal.vala
15 changes: 14 additions & 1 deletion src/PortalDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,20 @@ public class PortalDialog : Gtk.Window, PantheonWayland.ExtendedBehavior {
public enum ResponseType {
ALLOW,
CANCEL,
DELETE_EVENT
DELETE_EVENT;

// Convert to response ID expected by portal backends
public uint32 to_id () {
switch (this) {
case ALLOW:
return 0;
case CANCEL:
return 1;
default:
case DELETE_EVENT:
return 2;
}
}
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/Usb/Dialog.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrigthText: 2026 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

[DBus (name = "org.freedesktop.impl.portal.Request")]
public class Usb.Dialog : PortalDialog {
// The ID used to register this dialog on the DBusConnection
public uint register_id { get; set; default = 0; }

// The ID of the app sending the request
public string app_id { get; construct; }

public string reason {
set {
secondary_text = _("It provided the following reason, “%s”").printf (value);
}
}

public Dialog (string app_id) {
Object (app_id: app_id);
}

construct {
default_height = -1;
title = _("An application wants to access the following USB devices");
secondary_icon = new ThemedIcon ("emblem-portal-usb");
secondary_text = _("It did not provide a reason for this request.");

if (app_id != "") {
var app_info = new DesktopAppInfo (app_id + ".desktop");
if (app_info != null) {
primary_icon = app_info.get_icon ();
title = _("“%s” wants to access the following USB devices").printf (app_info.get_display_name ());
}
}

}

[DBus (name = "Close")]
public void on_close () throws DBusError, IOError {
response (DELETE_EVENT);
}
}
65 changes: 65 additions & 0 deletions src/Usb/Portal.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrigthText: 2026 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

[DBus (name = "org.freedesktop.impl.portal.Usb")]
public class Usb.Portal : Object {
private DBusConnection connection;

public Portal (DBusConnection connection) {
this.connection = connection;
}

[DBus (name = "AcquireDevices")]
public async void acquire_devices (
ObjectPath handle,
string parent_window,
string app_id,
// G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("a(sa{sv})"));
// IN devices a(sa{sv}a{sv}),
HashTable<string, Variant> options,
out uint response,
out HashTable<string, Variant> results
) throws DBusError, IOError {
var dialog = new Dialog (app_id) {
parent_handle = parent_window
};

if ("reason" in options) {
dialog.reason = options["reason"].get_string ();
}

try {
dialog.register_id = connection.register_object<Dialog> (handle, dialog);
} catch (Error e) {
critical (e.message);
}

var _results = new HashTable<string, Variant> (str_hash, str_equal);
uint _response = 2;

dialog.response.connect ((response) => {
switch (response) {
case ALLOW:

break;
default:
break;
}

_response = response.to_id ();

acquire_devices.callback ();
});

dialog.present ();
yield;

connection.unregister_object (dialog.register_id);
dialog.destroy ();

results = _results;
response = _response;
}
}
3 changes: 3 additions & 0 deletions src/XdgDesktopPortalPantheon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ private void on_bus_acquired (DBusConnection connection, string name) {
connection.register_object ("/org/freedesktop/portal/desktop", new Screenshot.Portal (connection));
debug ("Screenshot Portal registered!");

connection.register_object ("/org/freedesktop/portal/desktop", new Usb.Portal (connection));
debug ("USB Portal registered!");

connection.register_object ("/org/freedesktop/portal/desktop", new Wallpaper.Portal (connection));
debug ("Wallpaper Portal registered!");

Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ executable(
'Screenshot/Portal.vala',
'Screenshot/SetupDialog.vala',
'Screenshot/Utils.vala',
'Usb' / 'Dialog.vala',
'Usb' / 'Portal.vala',
'Wallpaper/Portal.vala',
configure_file(input: 'Config.vala.in', output: '@BASENAME@', configuration: conf_data),
'DesktopIntegration.vala',
Expand Down
Loading