diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-21 15:54:19 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-21 15:54:19 +0100 |
commit | e4dfd5a3a4b87f20bb171dc50ccd0c6f2b9398e4 (patch) | |
tree | 8384e9fe0abe464b7f5446ea1debff7cdd58af24 /Servers | |
parent | fe25f957e55a8355729c6db0443c00b39d9b534c (diff) | |
download | serenity-e4dfd5a3a4b87f20bb171dc50ccd0c6f2b9398e4.zip |
WindowServer: Support PNG wallpapers.
Fix up /bin/pape so it tells the WindowServer which wallpaper file to use.
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/WindowServer/WSAPITypes.h | 5 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.cpp | 24 | ||||
-rw-r--r-- | Servers/WindowServer/WSClientConnection.h | 2 | ||||
-rw-r--r-- | Servers/WindowServer/WSMessage.h | 33 | ||||
-rw-r--r-- | Servers/WindowServer/WSMessageLoop.cpp | 6 | ||||
-rw-r--r-- | Servers/WindowServer/WSWindowManager.cpp | 24 | ||||
-rw-r--r-- | Servers/WindowServer/WSWindowManager.h | 3 |
7 files changed, 86 insertions, 11 deletions
diff --git a/Servers/WindowServer/WSAPITypes.h b/Servers/WindowServer/WSAPITypes.h index 69f33c9612..c05acc3f32 100644 --- a/Servers/WindowServer/WSAPITypes.h +++ b/Servers/WindowServer/WSAPITypes.h @@ -82,11 +82,14 @@ struct WSAPI_ServerMessage { DidGetClipboardContents, DidSetClipboardContents, DidSetWindowBackingStore, + DidSetWallpaper, + DidGetWallpaper, }; Type type { Invalid }; int window_id { -1 }; int text_length { 0 }; char text[256]; + int value { 0 }; union { struct { @@ -159,6 +162,8 @@ struct WSAPI_ClientMessage { GetClipboardContents, SetClipboardContents, Greeting, + SetWallpaper, + GetWallpaper, }; Type type { Invalid }; int window_id { -1 }; diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index 0c577897c0..5a5b93a6b2 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -241,6 +241,26 @@ void WSClientConnection::handle_request(WSAPISetWindowOpacityRequest& request) window.set_opacity(request.opacity()); } +void WSClientConnection::handle_request(WSAPISetWallpaperRequest& request) +{ + bool success = WSWindowManager::the().set_wallpaper(request.wallpaper()); + WSAPI_ServerMessage response; + response.type = WSAPI_ServerMessage::Type::DidSetWallpaper; + response.value = success; + post_message(response); +} + +void WSClientConnection::handle_request(WSAPIGetWallpaperRequest& request) +{ + auto path = WSWindowManager::the().wallpaper_path(); + WSAPI_ServerMessage response; + response.type = WSAPI_ServerMessage::Type::DidGetWallpaper; + ASSERT(path.length() < (int)sizeof(response.text)); + strncpy(response.text, path.characters(), path.length()); + response.text_length = path.length(); + post_message(response); +} + void WSClientConnection::handle_request(WSAPISetWindowTitleRequest& request) { int window_id = request.window_id(); @@ -518,6 +538,10 @@ void WSClientConnection::on_request(WSAPIClientRequest& request) return handle_request(static_cast<WSAPISetWindowOpacityRequest&>(request)); case WSMessage::APISetWindowBackingStoreRequest: return handle_request(static_cast<WSAPISetWindowBackingStoreRequest&>(request)); + case WSMessage::APISetWallpaperRequest: + return handle_request(static_cast<WSAPISetWallpaperRequest&>(request)); + case WSMessage::APIGetWallpaperRequest: + return handle_request(static_cast<WSAPIGetWallpaperRequest&>(request)); default: break; } diff --git a/Servers/WindowServer/WSClientConnection.h b/Servers/WindowServer/WSClientConnection.h index ea8f2571d1..f92f8db505 100644 --- a/Servers/WindowServer/WSClientConnection.h +++ b/Servers/WindowServer/WSClientConnection.h @@ -62,6 +62,8 @@ private: void handle_request(WSAPISetWindowBackingStoreRequest&); void handle_request(WSAPISetGlobalCursorTrackingRequest&); void handle_request(WSAPISetWindowOpacityRequest&); + void handle_request(WSAPISetWallpaperRequest&); + void handle_request(WSAPIGetWallpaperRequest&); void post_error(const String&); diff --git a/Servers/WindowServer/WSMessage.h b/Servers/WindowServer/WSMessage.h index 1b2ec1018c..12dd6fcf35 100644 --- a/Servers/WindowServer/WSMessage.h +++ b/Servers/WindowServer/WSMessage.h @@ -47,6 +47,8 @@ public: APISetWindowBackingStoreRequest, APISetClipboardContentsRequest, APIGetClipboardContentsRequest, + APISetWallpaperRequest, + APIGetWallpaperRequest, __End_API_Client_Requests, }; @@ -227,6 +229,37 @@ private: int m_menu_id { 0 }; }; +class WSAPISetWallpaperRequest final : public WSAPIClientRequest { +public: + explicit WSAPISetWallpaperRequest(int client_id, String&& wallpaper) + : WSAPIClientRequest(WSMessage::APISetWallpaperRequest, client_id) + , m_client_id(client_id) + , m_wallpaper(move(wallpaper)) + { + } + + int client_id() const { return m_client_id; } + String wallpaper() const { return m_wallpaper; } + +private: + int m_client_id { 0 }; + String m_wallpaper; +}; + +class WSAPIGetWallpaperRequest final : public WSAPIClientRequest { +public: + explicit WSAPIGetWallpaperRequest(int client_id) + : WSAPIClientRequest(WSMessage::APIGetWallpaperRequest, client_id) + , m_client_id(client_id) + { + } + + int client_id() const { return m_client_id; } + +private: + int m_client_id { 0 }; +}; + class WSAPISetWindowTitleRequest final : public WSAPIClientRequest { public: explicit WSAPISetWindowTitleRequest(int client_id, int window_id, String&& title) diff --git a/Servers/WindowServer/WSMessageLoop.cpp b/Servers/WindowServer/WSMessageLoop.cpp index 7ef54a7945..923fb491ce 100644 --- a/Servers/WindowServer/WSMessageLoop.cpp +++ b/Servers/WindowServer/WSMessageLoop.cpp @@ -329,6 +329,12 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess case WSAPI_ClientMessage::Type::SetGlobalCursorTracking: post_message(client, make<WSAPISetGlobalCursorTrackingRequest>(client_id, message.window_id, message.value)); break; + case WSAPI_ClientMessage::Type::SetWallpaper: + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); + post_message(client, make<WSAPISetWallpaperRequest>(client_id, String(message.text, message.text_length))); + break; + case WSAPI_ClientMessage::Type::GetWallpaper: + post_message(client, make<WSAPIGetWallpaperRequest>(client_id)); default: break; } diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index a0f1e8c186..ab841f0747 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -14,6 +14,7 @@ #include <unistd.h> #include <stdio.h> #include <time.h> +#include <SharedGraphics/PNGLoader.h> #ifdef KERNEL #include <Kernel/ProcFS.h> @@ -22,7 +23,6 @@ //#define DEBUG_COUNTERS //#define DEBUG_WID_IN_TITLE_BAR //#define RESIZE_DEBUG -#define USE_WALLPAPER static const int window_titlebar_height = 18; @@ -199,18 +199,8 @@ WSWindowManager::WSWindowManager() m_cursor_bitmap_inner = CharacterBitmap::create_from_ascii(cursor_bitmap_inner_ascii, 12, 17); m_cursor_bitmap_outer = CharacterBitmap::create_from_ascii(cursor_bitmap_outer_ascii, 12, 17); -#ifdef USE_WALLPAPER m_wallpaper_path = "/res/wallpapers/retro.rgb"; m_wallpaper = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, m_wallpaper_path, { 1024, 768 }); -#endif - -#ifdef KERNEL - ProcFS::the().add_sys_bool("wm_flash_flush", m_flash_flush); - ProcFS::the().add_sys_string("wm_wallpaper", m_wallpaper_path, [this] { - m_wallpaper = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, m_wallpaper_path, m_screen_rect.size()); - invalidate(m_screen_rect); - }); -#endif m_username = getlogin(); @@ -351,6 +341,18 @@ void WSWindowManager::tick_clock() invalidate(menubar_rect()); } +bool WSWindowManager::set_wallpaper(const String& path) +{ + auto bitmap = load_png(path); + if (!bitmap) + return false; + + m_wallpaper_path = path; + m_wallpaper = move(bitmap); + invalidate(); + return true; +} + void WSWindowManager::set_resolution(int width, int height) { if (m_screen_rect.width() == width && m_screen_rect.height() == height) diff --git a/Servers/WindowServer/WSWindowManager.h b/Servers/WindowServer/WSWindowManager.h index 55fbbdad31..b41906c686 100644 --- a/Servers/WindowServer/WSWindowManager.h +++ b/Servers/WindowServer/WSWindowManager.h @@ -81,6 +81,9 @@ public: void set_resolution(int width, int height); + bool set_wallpaper(const String& path); + String wallpaper_path() const { return m_wallpaper_path; } + private: void process_mouse_event(WSMouseEvent&, WSWindow*& event_window); void handle_menu_mouse_event(WSMenu&, WSMouseEvent&); |