WindowServer: Add methods for set background color and wallpaper mode

This commit is contained in:
Hüseyin ASLITÜRK 2020-03-29 13:32:06 +03:00 committed by Andreas Kling
parent 7194b4823e
commit adf524015a
Notes: sideshowbarker 2024-07-19 08:04:24 +09:00
5 changed files with 55 additions and 1 deletions

View File

@ -309,6 +309,18 @@ void ClientConnection::handle(const Messages::WindowServer::AsyncSetWallpaper& m
}); });
} }
OwnPtr<Messages::WindowServer::SetBackgroundColorResponse> ClientConnection::handle(const Messages::WindowServer::SetBackgroundColor& message)
{
Compositor::the().set_backgound_color(message.background_color());
return make<Messages::WindowServer::SetBackgroundColorResponse>();
}
OwnPtr<Messages::WindowServer::SetWallpaperModeResponse> ClientConnection::handle(const Messages::WindowServer::SetWallpaperMode& message)
{
Compositor::the().set_wallpaper_mode(message.mode());
return make<Messages::WindowServer::SetWallpaperModeResponse>();
}
OwnPtr<Messages::WindowServer::GetWallpaperResponse> ClientConnection::handle(const Messages::WindowServer::GetWallpaper&) OwnPtr<Messages::WindowServer::GetWallpaperResponse> ClientConnection::handle(const Messages::WindowServer::GetWallpaper&)
{ {
return make<Messages::WindowServer::GetWallpaperResponse>(Compositor::the().wallpaper_path()); return make<Messages::WindowServer::GetWallpaperResponse>(Compositor::the().wallpaper_path());

View File

@ -110,6 +110,8 @@ private:
virtual OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> handle(const Messages::WindowServer::MoveWindowToFront&) override; virtual OwnPtr<Messages::WindowServer::MoveWindowToFrontResponse> handle(const Messages::WindowServer::MoveWindowToFront&) override;
virtual OwnPtr<Messages::WindowServer::SetFullscreenResponse> handle(const Messages::WindowServer::SetFullscreen&) override; virtual OwnPtr<Messages::WindowServer::SetFullscreenResponse> handle(const Messages::WindowServer::SetFullscreen&) override;
virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override; virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override;
virtual OwnPtr<Messages::WindowServer::SetBackgroundColorResponse> handle(const Messages::WindowServer::SetBackgroundColor&) override;
virtual OwnPtr<Messages::WindowServer::SetWallpaperModeResponse> handle(const Messages::WindowServer::SetWallpaperMode&) override;
virtual OwnPtr<Messages::WindowServer::GetWallpaperResponse> handle(const Messages::WindowServer::GetWallpaper&) override; virtual OwnPtr<Messages::WindowServer::GetWallpaperResponse> handle(const Messages::WindowServer::GetWallpaper&) override;
virtual OwnPtr<Messages::WindowServer::SetResolutionResponse> handle(const Messages::WindowServer::SetResolution&) override; virtual OwnPtr<Messages::WindowServer::SetResolutionResponse> handle(const Messages::WindowServer::SetResolution&) override;
virtual OwnPtr<Messages::WindowServer::SetWindowOverrideCursorResponse> handle(const Messages::WindowServer::SetWindowOverrideCursor&) override; virtual OwnPtr<Messages::WindowServer::SetWindowOverrideCursorResponse> handle(const Messages::WindowServer::SetWindowOverrideCursor&) override;

View File

@ -139,12 +139,18 @@ void Compositor::compose()
return false; return false;
}; };
Color background_color = wm.palette().desktop_background();
String background_color_entry = wm.wm_config()->read_entry("Background", "Color", "");
if (!background_color_entry.is_empty()) {
background_color = Color::from_string(background_color_entry).value_or(background_color);
}
// Paint the wallpaper. // Paint the wallpaper.
for (auto& dirty_rect : dirty_rects.rects()) { for (auto& dirty_rect : dirty_rects.rects()) {
if (wm.any_opaque_window_contains_rect(dirty_rect)) if (wm.any_opaque_window_contains_rect(dirty_rect))
continue; continue;
// FIXME: If the wallpaper is opaque, no need to fill with color! // FIXME: If the wallpaper is opaque, no need to fill with color!
m_back_painter->fill_rect(dirty_rect, wm.palette().desktop_background()); m_back_painter->fill_rect(dirty_rect, background_color);
if (m_wallpaper) { if (m_wallpaper) {
if (m_wallpaper_mode == WallpaperMode::Simple) { if (m_wallpaper_mode == WallpaperMode::Simple) {
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
@ -325,6 +331,32 @@ void Compositor::invalidate(const Gfx::Rect& a_rect)
} }
} }
bool Compositor::set_backgound_color(const String& background_color)
{
auto& wm = WindowManager::the();
wm.wm_config()->write_entry("Background", "Color", background_color);
bool ret_val = wm.wm_config()->sync();
if (ret_val)
Compositor::invalidate();
return ret_val;
}
bool Compositor::set_wallpaper_mode(const String& mode)
{
auto& wm = WindowManager::the();
wm.wm_config()->write_entry("Background", "Mode", mode);
bool ret_val = wm.wm_config()->sync();
if (ret_val) {
m_wallpaper_mode = mode_to_enum(mode);
Compositor::invalidate();
}
return ret_val;
}
bool Compositor::set_wallpaper(const String& path, Function<void(bool)>&& callback) bool Compositor::set_wallpaper(const String& path, Function<void(bool)>&& callback)
{ {
LibThread::BackgroundAction<RefPtr<Gfx::Bitmap>>::create( LibThread::BackgroundAction<RefPtr<Gfx::Bitmap>>::create(

View File

@ -55,6 +55,10 @@ public:
bool set_resolution(int desired_width, int desired_height); bool set_resolution(int desired_width, int desired_height);
bool set_backgound_color(const String& background_color);
bool set_wallpaper_mode(const String& mode);
bool set_wallpaper(const String& path, Function<void(bool)>&& callback); bool set_wallpaper(const String& path, Function<void(bool)>&& callback);
String wallpaper_path() const { return m_wallpaper_path; } String wallpaper_path() const { return m_wallpaper_path; }

View File

@ -74,6 +74,10 @@ endpoint WindowServer = 2
DismissMenu(i32 menu_id) => () DismissMenu(i32 menu_id) => ()
AsyncSetWallpaper(String path) =| AsyncSetWallpaper(String path) =|
SetBackgroundColor(String background_color) => ()
SetWallpaperMode(String mode) => ()
SetResolution(Gfx::Size resolution) => (bool success, Gfx::Size resolution) SetResolution(Gfx::Size resolution) => (bool success, Gfx::Size resolution)
SetWindowIconBitmap(i32 window_id, i32 icon_buffer_id, Gfx::Size icon_size) => () SetWindowIconBitmap(i32 window_id, i32 icon_buffer_id, Gfx::Size icon_size) => ()