0

我正在尝试使用门户org.freedesktop.portal.Wallpaper来设置壁纸,但是当执行门户时,它会创建一个没有扩展名的文件(即 /home/usermane/.config/both)并将其路径放到该文件位于 /org/gnome/desktop/background/picture-uri 设置(GSetting),最后如果文件是 XML 文件,则桌面仅显示黑色背景,否则如果文件是图像(jpg,png)壁纸正常设置。

我与门户通信的界面是:

[DBus (name = "org.freedesktop.portal.Wallpaper")]
public interface WallpaperPortal : Object {
    [DBus (name = "SetWallpaperFile")]
    public abstract GLib.ObjectPath background_file(string parent_window, UnixOutputStream fd, GLib.HashTable<string, GLib.Variant>? options) throws GLib.Error;

    [DBus (name = "SetWallpaperURI")]
    public abstract GLib.ObjectPath background_file_uri(string parent_window, string uri, GLib.HashTable<string, GLib.Variant>? options) throws GLib.Error;
}

我有一种以这种方式使用门户的方法:

public static void set_wallpaper(string image_path) {
    try {
        var wallpaper_portal = Bus.get_proxy_sync <WallpaperPortal> (
                    BusType.SESSION,
                    BUS_NAME,
                    OBJECT_PATH
                );;

        var options = new GLib.HashTable<string, GLib.Variant>(str_hash, str_equal);
        options.insert ("show-preview", new GLib.Variant.boolean (false));
        options.insert ("set-on", new GLib.Variant.string ("both"));
                
        FileStream stream = FileStream.open (image_path, "r");
             
        var uostream = new UnixOutputStream(stream.fileno (), true);
        wallpaper_portal.background_file (App.Configs.Constants.ID, uostream, options);
    } catch (GLib.Error error) {
        GLib.message ("Failed to set wallpaper by org.freedesktop.portal.Wallpaper: %s", error.message);
    }
}

当参数 image_path 是一个图像文件并且门户网站接收到该文件时,它可以正常工作,但是当它是一个 XML(将幻灯片显示为墙纸)时,它就不起作用了。

4

0 回答 0