1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:57:44 +00:00

WindowServer+Userland: Pass wallpapers as Gfx::Bitmap instead of path

The WindowServer _really_ does not need to know the filesystem path to
it's wallpaper, and allows setting arbitrary wallpapers (those outside
of `/res/wallpapers`).

The GUI::Desktop will keep track of the path to the wallpaper (if any),
and save it to config if desired (to be persisted).

This avoids the need to `unveil` paths to the wallpaper, fixing #11158
This commit is contained in:
James Puleo 2022-02-13 13:00:57 -05:00 committed by Ali Mohammad Pur
parent f538545987
commit a0e7a4b9a8
13 changed files with 61 additions and 58 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, James Puleo <james@jame.xyz>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -30,7 +31,7 @@ static int handle_show_all()
static int handle_show_current()
{
outln("{}", GUI::Desktop::the().wallpaper());
outln("{}", GUI::Desktop::the().wallpaper_path());
return 0;
}
@ -40,7 +41,7 @@ static int handle_set_pape(const String& name)
builder.append("/res/wallpapers/");
builder.append(name);
String path = builder.to_string();
if (!GUI::Desktop::the().set_wallpaper(path)) {
if (!GUI::Desktop::the().set_wallpaper(MUST(Gfx::Bitmap::try_load_from_file(path)), path)) {
warnln("pape: Failed to set wallpaper {}", path);
return 1;
}
@ -58,13 +59,13 @@ static int handle_set_random()
while (di.has_next()) {
wallpapers.append(di.next_full_path());
}
wallpapers.remove_all_matching([](const String& wallpaper) { return wallpaper == GUI::Desktop::the().wallpaper(); });
wallpapers.remove_all_matching([](const String& wallpaper) { return wallpaper == GUI::Desktop::the().wallpaper_path(); });
if (wallpapers.is_empty()) {
warnln("pape: No wallpapers found");
return 1;
}
auto& wallpaper = wallpapers.at(get_random_uniform(wallpapers.size()));
if (!GUI::Desktop::the().set_wallpaper(wallpaper)) {
if (!GUI::Desktop::the().set_wallpaper(MUST(Gfx::Bitmap::try_load_from_file(wallpaper)), wallpaper)) {
warnln("pape: Failed to set wallpaper {}", wallpaper);
return 1;
}