1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:47:35 +00:00

WindowServer: Support PNG wallpapers.

Fix up /bin/pape so it tells the WindowServer which wallpaper file to use.
This commit is contained in:
Andreas Kling 2019-03-21 15:54:19 +01:00
parent fe25f957e5
commit e4dfd5a3a4
15 changed files with 150 additions and 12890 deletions

View file

@ -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 };

View file

@ -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;
}

View file

@ -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&);

View file

@ -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)

View file

@ -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;
}

View file

@ -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)

View file

@ -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&);