From adf524015a28eb641317332dcd93fde4adf16fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ASLIT=C3=9CRK?= Date: Sun, 29 Mar 2020 13:32:06 +0300 Subject: [PATCH] WindowServer: Add methods for set background color and wallpaper mode --- Servers/WindowServer/ClientConnection.cpp | 12 ++++++++ Servers/WindowServer/ClientConnection.h | 2 ++ Servers/WindowServer/Compositor.cpp | 34 ++++++++++++++++++++++- Servers/WindowServer/Compositor.h | 4 +++ Servers/WindowServer/WindowServer.ipc | 4 +++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Servers/WindowServer/ClientConnection.cpp b/Servers/WindowServer/ClientConnection.cpp index 793dfe6ad3a..5065d2deade 100644 --- a/Servers/WindowServer/ClientConnection.cpp +++ b/Servers/WindowServer/ClientConnection.cpp @@ -309,6 +309,18 @@ void ClientConnection::handle(const Messages::WindowServer::AsyncSetWallpaper& m }); } +OwnPtr ClientConnection::handle(const Messages::WindowServer::SetBackgroundColor& message) +{ + Compositor::the().set_backgound_color(message.background_color()); + return make(); +} + +OwnPtr ClientConnection::handle(const Messages::WindowServer::SetWallpaperMode& message) +{ + Compositor::the().set_wallpaper_mode(message.mode()); + return make(); +} + OwnPtr ClientConnection::handle(const Messages::WindowServer::GetWallpaper&) { return make(Compositor::the().wallpaper_path()); diff --git a/Servers/WindowServer/ClientConnection.h b/Servers/WindowServer/ClientConnection.h index a5ebdd5a65a..3a8766c6c56 100644 --- a/Servers/WindowServer/ClientConnection.h +++ b/Servers/WindowServer/ClientConnection.h @@ -110,6 +110,8 @@ private: virtual OwnPtr handle(const Messages::WindowServer::MoveWindowToFront&) override; virtual OwnPtr handle(const Messages::WindowServer::SetFullscreen&) override; virtual void handle(const Messages::WindowServer::AsyncSetWallpaper&) override; + virtual OwnPtr handle(const Messages::WindowServer::SetBackgroundColor&) override; + virtual OwnPtr handle(const Messages::WindowServer::SetWallpaperMode&) override; virtual OwnPtr handle(const Messages::WindowServer::GetWallpaper&) override; virtual OwnPtr handle(const Messages::WindowServer::SetResolution&) override; virtual OwnPtr handle(const Messages::WindowServer::SetWindowOverrideCursor&) override; diff --git a/Servers/WindowServer/Compositor.cpp b/Servers/WindowServer/Compositor.cpp index e5cf24182bb..0a0ab29f1d9 100644 --- a/Servers/WindowServer/Compositor.cpp +++ b/Servers/WindowServer/Compositor.cpp @@ -139,12 +139,18 @@ void Compositor::compose() 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. for (auto& dirty_rect : dirty_rects.rects()) { if (wm.any_opaque_window_contains_rect(dirty_rect)) continue; // 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_mode == WallpaperMode::Simple) { 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&& callback) { LibThread::BackgroundAction>::create( diff --git a/Servers/WindowServer/Compositor.h b/Servers/WindowServer/Compositor.h index ce2069bdc57..a1f654de01a 100644 --- a/Servers/WindowServer/Compositor.h +++ b/Servers/WindowServer/Compositor.h @@ -55,6 +55,10 @@ public: 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&& callback); String wallpaper_path() const { return m_wallpaper_path; } diff --git a/Servers/WindowServer/WindowServer.ipc b/Servers/WindowServer/WindowServer.ipc index 9e29ee34b74..99796c4241e 100644 --- a/Servers/WindowServer/WindowServer.ipc +++ b/Servers/WindowServer/WindowServer.ipc @@ -74,6 +74,10 @@ endpoint WindowServer = 2 DismissMenu(i32 menu_id) => () AsyncSetWallpaper(String path) =| + + SetBackgroundColor(String background_color) => () + SetWallpaperMode(String mode) => () + SetResolution(Gfx::Size resolution) => (bool success, Gfx::Size resolution) SetWindowIconBitmap(i32 window_id, i32 icon_buffer_id, Gfx::Size icon_size) => ()