mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:22:44 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									8dbd1cb9fb
								
							
						
					
					
						commit
						151f32b827
					
				
					 8 changed files with 46 additions and 21 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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; } | ||||
|  |  | |||
|  | @ -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); | ||||
| #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) | ||||
|  |  | |||
|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) { | ||||
|         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) | ||||
|  |  | |||
|  | @ -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*); | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A