mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:32:46 +00:00 
			
		
		
		
	WindowServer+LibGUI: Allow switching windows in/out of fullscreen mode
You can now call GWindow::set_fullscreen(bool) and it will go in or out of fullscreen mode. WindowServer will also remember the previous window rect when switching to fullscreen, and restore it when switching back. :^)
This commit is contained in:
		
							parent
							
								
									a34f3a3729
								
							
						
					
					
						commit
						d92e26d023
					
				
					 8 changed files with 78 additions and 1 deletions
				
			
		|  | @ -714,3 +714,18 @@ void GWindow::save_to(AK::JsonObject& json) | ||||||
|     json.set("size_increment", size_increment().to_string()); |     json.set("size_increment", size_increment().to_string()); | ||||||
|     CObject::save_to(json); |     CObject::save_to(json); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void GWindow::set_fullscreen(bool fullscreen) | ||||||
|  | { | ||||||
|  |     if (m_fullscreen == fullscreen) | ||||||
|  |         return; | ||||||
|  |     m_fullscreen = fullscreen; | ||||||
|  |     if (!m_window_id) | ||||||
|  |         return; | ||||||
|  | 
 | ||||||
|  |     WSAPI_ClientMessage request; | ||||||
|  |     request.type = WSAPI_ClientMessage::Type::SetFullscreen; | ||||||
|  |     request.window_id = m_window_id; | ||||||
|  |     request.value = fullscreen; | ||||||
|  |     GWindowServerConnection::the().sync_request(request, WSAPI_ServerMessage::Type::DidSetFullscreen); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ public: | ||||||
|     void set_modal(bool); |     void set_modal(bool); | ||||||
| 
 | 
 | ||||||
|     bool is_fullscreen() const { return m_fullscreen; } |     bool is_fullscreen() const { return m_fullscreen; } | ||||||
|     void set_fullscreen(bool fullscreen) { m_fullscreen = fullscreen; } |     void set_fullscreen(bool); | ||||||
| 
 | 
 | ||||||
|     bool is_resizable() const { return m_resizable; } |     bool is_resizable() const { return m_resizable; } | ||||||
|     void set_resizable(bool resizable) { m_resizable = resizable; } |     void set_resizable(bool resizable) { m_resizable = resizable; } | ||||||
|  |  | ||||||
|  | @ -113,6 +113,7 @@ struct WSAPI_ServerMessage { | ||||||
|         DidSetWindowHasAlphaChannel, |         DidSetWindowHasAlphaChannel, | ||||||
|         ScreenRectChanged, |         ScreenRectChanged, | ||||||
|         ClipboardContentsChanged, |         ClipboardContentsChanged, | ||||||
|  |         DidSetFullscreen, | ||||||
| 
 | 
 | ||||||
|         __Begin_WM_Events__, |         __Begin_WM_Events__, | ||||||
|         WM_WindowRemoved, |         WM_WindowRemoved, | ||||||
|  | @ -237,6 +238,7 @@ struct WSAPI_ClientMessage { | ||||||
|         SetWindowHasAlphaChannel, |         SetWindowHasAlphaChannel, | ||||||
|         MoveWindowToFront, |         MoveWindowToFront, | ||||||
|         SetWindowIconBitmap, |         SetWindowIconBitmap, | ||||||
|  |         SetFullscreen, | ||||||
|     }; |     }; | ||||||
|     Type type { Invalid }; |     Type type { Invalid }; | ||||||
|     int window_id { -1 }; |     int window_id { -1 }; | ||||||
|  |  | ||||||
|  | @ -330,6 +330,9 @@ bool WSClientConnection::handle_message(const WSAPI_ClientMessage& message, cons | ||||||
|     case WSAPI_ClientMessage::Type::MoveWindowToFront: |     case WSAPI_ClientMessage::Type::MoveWindowToFront: | ||||||
|         CEventLoop::current().post_event(*this, make<WSAPIMoveWindowToFrontRequest>(client_id(), message.window_id)); |         CEventLoop::current().post_event(*this, make<WSAPIMoveWindowToFrontRequest>(client_id(), message.window_id)); | ||||||
|         break; |         break; | ||||||
|  |     case WSAPI_ClientMessage::Type::SetFullscreen: | ||||||
|  |         CEventLoop::current().post_event(*this, make<WSAPISetFullscreenRequest>(client_id(), message.window_id, message.value)); | ||||||
|  |         break; | ||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|  | @ -544,6 +547,23 @@ void WSClientConnection::handle_request(const WSAPIMoveWindowToFrontRequest& req | ||||||
|     WSWindowManager::the().move_to_front_and_make_active(window); |     WSWindowManager::the().move_to_front_and_make_active(window); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void WSClientConnection::handle_request(const WSAPISetFullscreenRequest& request) | ||||||
|  | { | ||||||
|  |     int window_id = request.window_id(); | ||||||
|  |     auto it = m_windows.find(window_id); | ||||||
|  |     if (it == m_windows.end()) { | ||||||
|  |         post_error("WSAPISetFullscreenRequest: Bad window ID"); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     auto& window = *(*it).value; | ||||||
|  |     window.set_fullscreen(request.fullscreen()); | ||||||
|  | 
 | ||||||
|  |     WSAPI_ServerMessage response; | ||||||
|  |     response.type = WSAPI_ServerMessage::Type::DidSetFullscreen; | ||||||
|  |     response.window_id = window_id; | ||||||
|  |     post_message(response); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void WSClientConnection::handle_request(const WSAPISetWindowOpacityRequest& request) | void WSClientConnection::handle_request(const WSAPISetWindowOpacityRequest& request) | ||||||
| { | { | ||||||
|     int window_id = request.window_id(); |     int window_id = request.window_id(); | ||||||
|  | @ -1038,6 +1058,8 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request) | ||||||
|         return handle_request(static_cast<const WSAPISetWindowHasAlphaChannelRequest&>(request)); |         return handle_request(static_cast<const WSAPISetWindowHasAlphaChannelRequest&>(request)); | ||||||
|     case WSEvent::APIMoveWindowToFrontRequest: |     case WSEvent::APIMoveWindowToFrontRequest: | ||||||
|         return handle_request(static_cast<const WSAPIMoveWindowToFrontRequest&>(request)); |         return handle_request(static_cast<const WSAPIMoveWindowToFrontRequest&>(request)); | ||||||
|  |     case WSEvent::APISetFullscreenRequest: | ||||||
|  |         return handle_request(static_cast<const WSAPISetFullscreenRequest&>(request)); | ||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -84,6 +84,7 @@ private: | ||||||
|     void handle_request(const WSAPIDismissMenuRequest&); |     void handle_request(const WSAPIDismissMenuRequest&); | ||||||
|     void handle_request(const WSAPISetWindowHasAlphaChannelRequest&); |     void handle_request(const WSAPISetWindowHasAlphaChannelRequest&); | ||||||
|     void handle_request(const WSAPIMoveWindowToFrontRequest&); |     void handle_request(const WSAPIMoveWindowToFrontRequest&); | ||||||
|  |     void handle_request(const WSAPISetFullscreenRequest&); | ||||||
| 
 | 
 | ||||||
|     void post_error(const String&); |     void post_error(const String&); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -65,6 +65,7 @@ public: | ||||||
|         APISetWindowOverrideCursorRequest, |         APISetWindowOverrideCursorRequest, | ||||||
|         APISetWindowHasAlphaChannelRequest, |         APISetWindowHasAlphaChannelRequest, | ||||||
|         APIMoveWindowToFrontRequest, |         APIMoveWindowToFrontRequest, | ||||||
|  |         APISetFullscreenRequest, | ||||||
|         WMAPISetActiveWindowRequest, |         WMAPISetActiveWindowRequest, | ||||||
|         WMAPISetWindowMinimizedRequest, |         WMAPISetWindowMinimizedRequest, | ||||||
|         WMAPIStartWindowResizeRequest, |         WMAPIStartWindowResizeRequest, | ||||||
|  | @ -502,6 +503,23 @@ private: | ||||||
|     int m_window_id { 0 }; |     int m_window_id { 0 }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | class WSAPISetFullscreenRequest final : public WSAPIClientRequest { | ||||||
|  | public: | ||||||
|  |     explicit WSAPISetFullscreenRequest(int client_id, int window_id, bool fullscreen) | ||||||
|  |         : WSAPIClientRequest(WSEvent::APISetFullscreenRequest, client_id) | ||||||
|  |         , m_window_id(window_id) | ||||||
|  |         , m_fullscreen(fullscreen) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     int window_id() const { return m_window_id; } | ||||||
|  |     bool fullscreen() const { return m_fullscreen; } | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |     int m_window_id { 0 }; | ||||||
|  |     bool m_fullscreen; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| class WSAPISetClipboardContentsRequest final : public WSAPIClientRequest { | class WSAPISetClipboardContentsRequest final : public WSAPIClientRequest { | ||||||
| public: | public: | ||||||
|     explicit WSAPISetClipboardContentsRequest(int client_id, int shared_buffer_id, int size, const String& data_type) |     explicit WSAPISetClipboardContentsRequest(int client_id, int shared_buffer_id, int size, const String& data_type) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #include "WSWindow.h" | #include "WSWindow.h" | ||||||
| #include "WSEvent.h" | #include "WSEvent.h" | ||||||
| #include "WSEventLoop.h" | #include "WSEventLoop.h" | ||||||
|  | #include "WSScreen.h" | ||||||
| #include "WSWindowManager.h" | #include "WSWindowManager.h" | ||||||
| #include <WindowServer/WSAPITypes.h> | #include <WindowServer/WSAPITypes.h> | ||||||
| #include <WindowServer/WSClientConnection.h> | #include <WindowServer/WSClientConnection.h> | ||||||
|  | @ -354,3 +355,19 @@ void WSWindow::request_close() | ||||||
|     WSEvent close_request(WSEvent::WindowCloseRequest); |     WSEvent close_request(WSEvent::WindowCloseRequest); | ||||||
|     event(close_request); |     event(close_request); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | void WSWindow::set_fullscreen(bool fullscreen) | ||||||
|  | { | ||||||
|  |     if (m_fullscreen == fullscreen) | ||||||
|  |         return; | ||||||
|  |     m_fullscreen = fullscreen; | ||||||
|  |     Rect new_window_rect = m_rect; | ||||||
|  |     if (m_fullscreen) { | ||||||
|  |         m_saved_nonfullscreen_rect = m_rect; | ||||||
|  |         new_window_rect = WSScreen::the().rect(); | ||||||
|  |     } else if (!m_saved_nonfullscreen_rect.is_empty()) { | ||||||
|  |         new_window_rect = m_saved_nonfullscreen_rect; | ||||||
|  |     } | ||||||
|  |     CEventLoop::current().post_event(*this, make<WSResizeEvent>(m_rect, new_window_rect)); | ||||||
|  |     set_rect(new_window_rect); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -38,6 +38,7 @@ public: | ||||||
|     void set_maximized(bool); |     void set_maximized(bool); | ||||||
| 
 | 
 | ||||||
|     bool is_fullscreen() const { return m_fullscreen; } |     bool is_fullscreen() const { return m_fullscreen; } | ||||||
|  |     void set_fullscreen(bool); | ||||||
| 
 | 
 | ||||||
|     bool show_titlebar() const { return m_show_titlebar; } |     bool show_titlebar() const { return m_show_titlebar; } | ||||||
|     void set_show_titlebar(bool show) { m_show_titlebar = show; } |     void set_show_titlebar(bool show) { m_show_titlebar = show; } | ||||||
|  | @ -155,6 +156,7 @@ private: | ||||||
|     WSClientConnection* m_client { nullptr }; |     WSClientConnection* m_client { nullptr }; | ||||||
|     String m_title; |     String m_title; | ||||||
|     Rect m_rect; |     Rect m_rect; | ||||||
|  |     Rect m_saved_nonfullscreen_rect; | ||||||
|     WSWindowType m_type { WSWindowType::Normal }; |     WSWindowType m_type { WSWindowType::Normal }; | ||||||
|     bool m_global_cursor_tracking_enabled { false }; |     bool m_global_cursor_tracking_enabled { false }; | ||||||
|     bool m_automatic_cursor_tracking_enabled { false }; |     bool m_automatic_cursor_tracking_enabled { false }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling