diff options
author | Liav A <liavalb@gmail.com> | 2020-02-27 17:09:41 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-28 12:16:05 +0100 |
commit | 151f32b827d779ba0d19f1a38b79350621d8e0f9 (patch) | |
tree | b1c21053be5c758882b846418be9dba96e62badd /Servers | |
parent | 8dbd1cb9fb22c134050ab09550363abdd2c58927 (diff) | |
download | serenity-151f32b827d779ba0d19f1a38b79350621d8e0f9.zip |
WindowServer: Return richer result when changing resolutions
Now we return a boolean value from set_resolution() in the Compositor
and Screen class. Also, the WindowServer IPC now returns a richer result
after changing the resolution, which can be used in clients later.
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/WindowServer/ClientConnection.cpp | 3 | ||||
-rw-r--r-- | Servers/WindowServer/Compositor.cpp | 7 | ||||
-rw-r--r-- | Servers/WindowServer/Compositor.h | 2 | ||||
-rw-r--r-- | Servers/WindowServer/Screen.cpp | 17 | ||||
-rw-r--r-- | Servers/WindowServer/Screen.h | 2 | ||||
-rw-r--r-- | Servers/WindowServer/WindowManager.cpp | 31 | ||||
-rw-r--r-- | Servers/WindowServer/WindowManager.h | 3 | ||||
-rw-r--r-- | Servers/WindowServer/WindowServer.ipc | 2 |
8 files changed, 46 insertions, 21 deletions
diff --git a/Servers/WindowServer/ClientConnection.cpp b/Servers/WindowServer/ClientConnection.cpp index e5dc8941e9..7f558a0766 100644 --- a/Servers/WindowServer/ClientConnection.cpp +++ b/Servers/WindowServer/ClientConnection.cpp @@ -316,8 +316,7 @@ OwnPtr<Messages::WindowServer::GetWallpaperResponse> ClientConnection::handle(co OwnPtr<Messages::WindowServer::SetResolutionResponse> ClientConnection::handle(const Messages::WindowServer::SetResolution& message) { - WindowManager::the().set_resolution(message.resolution().width(), message.resolution().height()); - return make<Messages::WindowServer::SetResolutionResponse>(); + return make<Messages::WindowServer::SetResolutionResponse>(WindowManager::the().set_resolution(message.resolution().width(), message.resolution().height()), WindowManager::the().resolution()); } OwnPtr<Messages::WindowServer::SetWindowTitleResponse> ClientConnection::handle(const Messages::WindowServer::SetWindowTitle& message) diff --git a/Servers/WindowServer/Compositor.cpp b/Servers/WindowServer/Compositor.cpp index 0289305bb3..adf6d13276 100644 --- a/Servers/WindowServer/Compositor.cpp +++ b/Servers/WindowServer/Compositor.cpp @@ -397,17 +397,18 @@ void Compositor::run_animations() }); } -void Compositor::set_resolution(int desired_width, int desired_height) +bool Compositor::set_resolution(int desired_width, int desired_height) { auto screen_rect = Screen::the().rect(); if (screen_rect.width() == desired_width && screen_rect.height() == desired_height) - return; + return true; // Make sure it's impossible to set an invalid resolution ASSERT(desired_width >= 640 && desired_height >= 480); - Screen::the().set_resolution(desired_width, desired_height); + bool success = Screen::the().set_resolution(desired_width, desired_height); init_bitmaps(); compose(); + return success; } Gfx::Rect Compositor::current_cursor_rect() const diff --git a/Servers/WindowServer/Compositor.h b/Servers/WindowServer/Compositor.h index 14d2423b4a..8a20b6c5c5 100644 --- a/Servers/WindowServer/Compositor.h +++ b/Servers/WindowServer/Compositor.h @@ -53,7 +53,7 @@ public: void invalidate(); void invalidate(const Gfx::Rect&); - void set_resolution(int desired_width, int desired_height); + bool set_resolution(int desired_width, int desired_height); bool set_wallpaper(const String& path, Function<void(bool)>&& callback); String wallpaper_path() const { return m_wallpaper_path; } diff --git a/Servers/WindowServer/Screen.cpp b/Servers/WindowServer/Screen.cpp index 72ac39361a..cf85814ed0 100644 --- a/Servers/WindowServer/Screen.cpp +++ b/Servers/WindowServer/Screen.cpp @@ -68,12 +68,23 @@ Screen::~Screen() { } -void Screen::set_resolution(int width, int height) +bool Screen::set_resolution(int width, int height) { FBResolution resolution { 0, (int)width, (int)height }; int rc = fb_set_resolution(m_framebuffer_fd, &resolution); - ASSERT(rc == 0); - on_change_resolution(resolution.pitch, resolution.width, resolution.height); +#ifdef WSSCREEN_DEBUG + dbg() << "fb_set_resolution() - return code " << rc; +#endif + if (rc == 0) { + on_change_resolution(resolution.pitch, resolution.width, resolution.height); + return true; + } + if (rc == -1) { + dbg() << "Invalid resolution " << width << "x" << height; + on_change_resolution(resolution.pitch, resolution.width, resolution.height); + return false; + } + ASSERT_NOT_REACHED(); } void Screen::on_change_resolution(int pitch, int width, int height) diff --git a/Servers/WindowServer/Screen.h b/Servers/WindowServer/Screen.h index ea639b6f30..d522ea7b96 100644 --- a/Servers/WindowServer/Screen.h +++ b/Servers/WindowServer/Screen.h @@ -40,7 +40,7 @@ public: Screen(unsigned width, unsigned height); ~Screen(); - void set_resolution(int width, int height); + bool set_resolution(int width, int height); bool can_set_buffer() { return m_can_set_buffer; } void set_buffer(int index); diff --git a/Servers/WindowServer/WindowManager.cpp b/Servers/WindowServer/WindowManager.cpp index 995f12602c..e368f686d5 100644 --- a/Servers/WindowServer/WindowManager.cpp +++ b/Servers/WindowServer/WindowManager.cpp @@ -106,9 +106,9 @@ void WindowManager::reload_config(bool set_screen) m_double_click_speed = m_wm_config->read_num_entry("Input", "DoubleClickSpeed", 250); - if (set_screen) - set_resolution(m_wm_config->read_num_entry("Screen", "Width", 1920), - m_wm_config->read_num_entry("Screen", "Height", 1080)); + if (set_screen) { + set_resolution(m_wm_config->read_num_entry("Screen", "Width", 1920), m_wm_config->read_num_entry("Screen", "Height", 1080)); + } m_arrow_cursor = get_cursor("Arrow", { 2, 2 }); m_hand_cursor = get_cursor("Hand", { 8, 4 }); @@ -132,19 +132,32 @@ const Gfx::Font& WindowManager::window_title_font() const return Gfx::Font::default_bold_font(); } -void WindowManager::set_resolution(int width, int height) +bool WindowManager::set_resolution(int width, int height) { - Compositor::the().set_resolution(width, height); + bool success = Compositor::the().set_resolution(width, height); MenuManager::the().set_needs_window_resize(); ClientConnection::for_each_client([&](ClientConnection& client) { client.notify_about_new_screen_rect(Screen::the().rect()); }); if (m_wm_config) { - dbg() << "Saving resolution: " << Gfx::Size(width, height) << " to config file at " << m_wm_config->file_name(); - m_wm_config->write_num_entry("Screen", "Width", width); - m_wm_config->write_num_entry("Screen", "Height", height); - m_wm_config->sync(); + if (success) { + dbg() << "Saving resolution: " << Gfx::Size(width, height) << " to config file at " << m_wm_config->file_name(); + m_wm_config->write_num_entry("Screen", "Width", width); + m_wm_config->write_num_entry("Screen", "Height", height); + m_wm_config->sync(); + } else { + dbg() << "Saving fallback resolution: " << resolution() << " to config file at " << m_wm_config->file_name(); + m_wm_config->write_num_entry("Screen", "Width", resolution().width()); + m_wm_config->write_num_entry("Screen", "Height", resolution().height()); + m_wm_config->sync(); + } } + return success; +} + +Gfx::Size WindowManager::resolution() const +{ + return Screen::the().size(); } void WindowManager::add_window(Window& window) diff --git a/Servers/WindowServer/WindowManager.h b/Servers/WindowServer/WindowManager.h index 4d198bf0a8..b1dc349589 100644 --- a/Servers/WindowServer/WindowManager.h +++ b/Servers/WindowServer/WindowManager.h @@ -141,7 +141,8 @@ public: const Gfx::Font& font() const; const Gfx::Font& window_title_font() const; - void set_resolution(int width, int height); + bool set_resolution(int width, int height); + Gfx::Size resolution() const; void set_active_window(Window*); void set_hovered_button(Button*); diff --git a/Servers/WindowServer/WindowServer.ipc b/Servers/WindowServer/WindowServer.ipc index e742a16cf4..92fafc6c71 100644 --- a/Servers/WindowServer/WindowServer.ipc +++ b/Servers/WindowServer/WindowServer.ipc @@ -74,7 +74,7 @@ endpoint WindowServer = 2 DismissMenu(i32 menu_id) => () AsyncSetWallpaper(String path) =| - SetResolution(Gfx::Size resolution) => () + SetResolution(Gfx::Size resolution) => (bool success, Gfx::Size resolution) SetWindowIconBitmap(i32 window_id, i32 icon_buffer_id, Gfx::Size icon_size) => () GetWallpaper() => (String path) |