1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:27:35 +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

@ -292,11 +292,10 @@ void ClientConnection::set_window_opacity(i32 window_id, float opacity)
it->value->set_opacity(opacity);
}
void ClientConnection::set_wallpaper(String const& path)
void ClientConnection::set_wallpaper(Gfx::ShareableBitmap const& bitmap)
{
Compositor::the().set_wallpaper(path, [&](bool success) {
async_set_wallpaper_finished(success);
});
Compositor::the().set_wallpaper(bitmap.bitmap());
async_set_wallpaper_finished(true);
}
void ClientConnection::set_background_color(String const& background_color)
@ -311,7 +310,7 @@ void ClientConnection::set_wallpaper_mode(String const& mode)
Messages::WindowServer::GetWallpaperResponse ClientConnection::get_wallpaper()
{
return Compositor::the().wallpaper_path();
return Compositor::the().wallpaper_bitmap()->to_shareable_bitmap();
}
Messages::WindowServer::SetScreenLayoutResponse ClientConnection::set_screen_layout(ScreenLayout const& screen_layout, bool save)

View file

@ -123,7 +123,7 @@ private:
virtual void set_fullscreen(i32, bool) override;
virtual void set_frameless(i32, bool) override;
virtual void set_forced_shadow(i32, bool) override;
virtual void set_wallpaper(String const&) override;
virtual void set_wallpaper(Gfx::ShareableBitmap const&) override;
virtual void set_background_color(String const&) override;
virtual void set_wallpaper_mode(String const&) override;
virtual Messages::WindowServer::GetWallpaperResponse get_wallpaper() override;

View file

@ -805,26 +805,14 @@ bool Compositor::set_wallpaper_mode(const String& mode)
return ret_val;
}
bool Compositor::set_wallpaper(const String& path, Function<void(bool)>&& callback)
bool Compositor::set_wallpaper(RefPtr<Gfx::Bitmap> bitmap)
{
(void)Threading::BackgroundAction<ErrorOr<NonnullRefPtr<Gfx::Bitmap>>>::construct(
[path](auto&) {
return Gfx::Bitmap::try_load_from_file(path);
},
if (!bitmap)
m_wallpaper = nullptr;
else
m_wallpaper = bitmap;
invalidate_screen();
[this, path, callback = move(callback)](ErrorOr<NonnullRefPtr<Gfx::Bitmap>> bitmap) {
if (bitmap.is_error() && !path.is_empty()) {
callback(false);
return;
}
m_wallpaper_path = path;
if (bitmap.is_error())
m_wallpaper = nullptr;
else
m_wallpaper = bitmap.release_value();
invalidate_screen();
callback(true);
});
return true;
}

View file

@ -105,8 +105,8 @@ public:
bool set_wallpaper_mode(const String& mode);
bool set_wallpaper(const String& path, Function<void(bool)>&& callback);
String wallpaper_path() const { return m_wallpaper_path; }
bool set_wallpaper(RefPtr<Gfx::Bitmap>);
RefPtr<Gfx::Bitmap> wallpaper_bitmap() const { return m_wallpaper; }
void invalidate_cursor(bool = false);
Gfx::IntRect current_cursor_rect() const;
@ -227,7 +227,6 @@ private:
Gfx::DisjointRectSet m_opaque_wallpaper_rects;
Gfx::DisjointRectSet m_transparent_wallpaper_rects;
String m_wallpaper_path { "" };
WallpaperMode m_wallpaper_mode { WallpaperMode::Unchecked };
RefPtr<Gfx::Bitmap> m_wallpaper;

View file

@ -91,7 +91,7 @@ endpoint WindowServer
popup_menu(i32 menu_id, Gfx::IntPoint screen_position) =|
dismiss_menu(i32 menu_id) =|
set_wallpaper(String path) =|
set_wallpaper(Gfx::ShareableBitmap wallpaper_bitmap) =|
set_background_color(String background_color) =|
set_wallpaper_mode(String mode) =|
@ -106,7 +106,7 @@ endpoint WindowServer
set_window_icon_bitmap(i32 window_id, Gfx::ShareableBitmap icon) =|
get_wallpaper() => (String path)
get_wallpaper() => (Gfx::ShareableBitmap wallpaper_bitmap)
set_window_cursor(i32 window_id, i32 cursor_type) =|
set_window_custom_cursor(i32 window_id, Gfx::ShareableBitmap cursor) =|