forked from Bananymous/banan-os
				
			LibGUI: Implement set_max_size
I already support set_min_size so why not this :)
This commit is contained in:
		
							parent
							
								
									85f200bd86
								
							
						
					
					
						commit
						bbb490b24f
					
				|  | @ -178,6 +178,16 @@ namespace LibGUI | ||||||
| 			return on_socket_error(__FUNCTION__); | 			return on_socket_error(__FUNCTION__); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	void Window::set_max_size(uint32_t width, uint32_t height) | ||||||
|  | 	{ | ||||||
|  | 		WindowPacket::WindowSetMaxSize packet; | ||||||
|  | 		packet.width = width; | ||||||
|  | 		packet.height = height; | ||||||
|  | 
 | ||||||
|  | 		if (auto ret = packet.send_serialized(m_server_fd); ret.is_error()) | ||||||
|  | 			return on_socket_error(__FUNCTION__); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	void Window::set_attributes(Attributes attributes) | 	void Window::set_attributes(Attributes attributes) | ||||||
| 	{ | 	{ | ||||||
| 		WindowPacket::WindowSetAttributes packet; | 		WindowPacket::WindowSetAttributes packet; | ||||||
|  |  | ||||||
|  | @ -165,6 +165,7 @@ namespace LibGUI | ||||||
| 		WindowSetMouseCapture, | 		WindowSetMouseCapture, | ||||||
| 		WindowSetSize, | 		WindowSetSize, | ||||||
| 		WindowSetMinSize, | 		WindowSetMinSize, | ||||||
|  | 		WindowSetMaxSize, | ||||||
| 		WindowSetFullscreen, | 		WindowSetFullscreen, | ||||||
| 		WindowSetTitle, | 		WindowSetTitle, | ||||||
| 
 | 
 | ||||||
|  | @ -234,6 +235,12 @@ namespace LibGUI | ||||||
| 			uint32_t, height | 			uint32_t, height | ||||||
| 		); | 		); | ||||||
| 
 | 
 | ||||||
|  | 		DEFINE_PACKET( | ||||||
|  | 			WindowSetMaxSize, | ||||||
|  | 			uint32_t, width, | ||||||
|  | 			uint32_t, height | ||||||
|  | 		); | ||||||
|  | 
 | ||||||
| 		DEFINE_PACKET( | 		DEFINE_PACKET( | ||||||
| 			WindowSetFullscreen, | 			WindowSetFullscreen, | ||||||
| 			bool, fullscreen | 			bool, fullscreen | ||||||
|  |  | ||||||
|  | @ -47,6 +47,7 @@ namespace LibGUI | ||||||
| 		void set_attributes(Attributes attributes); | 		void set_attributes(Attributes attributes); | ||||||
| 
 | 
 | ||||||
| 		void set_min_size(uint32_t width, uint32_t height); | 		void set_min_size(uint32_t width, uint32_t height); | ||||||
|  | 		void set_max_size(uint32_t width, uint32_t height); | ||||||
| 
 | 
 | ||||||
| 		// send resize request to window server
 | 		// send resize request to window server
 | ||||||
| 		// actual resize is only done after resize callback is called
 | 		// actual resize is only done after resize callback is called
 | ||||||
|  |  | ||||||
|  | @ -55,6 +55,9 @@ public: | ||||||
| 	Rectangle get_min_size() const { return m_min_size; } | 	Rectangle get_min_size() const { return m_min_size; } | ||||||
| 	void set_min_size(Rectangle min_size) { m_min_size = min_size.get_bounding_box({ 0, 0, m_title_bar_height, 0 }); } | 	void set_min_size(Rectangle min_size) { m_min_size = min_size.get_bounding_box({ 0, 0, m_title_bar_height, 0 }); } | ||||||
| 
 | 
 | ||||||
|  | 	Rectangle get_max_size() const { return m_max_size; } | ||||||
|  | 	void set_max_size(Rectangle max_size) { m_max_size = max_size; } | ||||||
|  | 
 | ||||||
| 	BAN::ErrorOr<void> set_title(BAN::StringView title) { m_title.clear(); TRY(m_title.append(title)); TRY(prepare_title_bar()); return {}; } | 	BAN::ErrorOr<void> set_title(BAN::StringView title) { m_title.clear(); TRY(m_title.append(title)); TRY(prepare_title_bar()); return {}; } | ||||||
| 
 | 
 | ||||||
| 	const uint32_t* framebuffer() const { return m_fb_addr; } | 	const uint32_t* framebuffer() const { return m_fb_addr; } | ||||||
|  | @ -88,6 +91,7 @@ private: | ||||||
| 	const int   m_client_fd      { -1 }; | 	const int   m_client_fd      { -1 }; | ||||||
| 	Rectangle   m_client_area    { 0, 0, 0, 0 }; | 	Rectangle   m_client_area    { 0, 0, 0, 0 }; | ||||||
| 	Rectangle   m_min_size       { 0, 0, m_title_bar_height, 0 }; | 	Rectangle   m_min_size       { 0, 0, m_title_bar_height, 0 }; | ||||||
|  | 	Rectangle   m_max_size       { 0, 0, 10'000, 10'000 }; | ||||||
| 	long        m_smo_key        { 0 }; | 	long        m_smo_key        { 0 }; | ||||||
| 	uint32_t*   m_fb_addr        { nullptr }; | 	uint32_t*   m_fb_addr        { nullptr }; | ||||||
| 	BAN::String m_title; | 	BAN::String m_title; | ||||||
|  |  | ||||||
|  | @ -278,9 +278,31 @@ void WindowServer::on_window_set_min_size(int fd, const LibGUI::WindowPacket::Wi | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// FIXME: should this resize window
 | ||||||
| 	target_window->set_min_size({ 0, 0, static_cast<int32_t>(packet.width), static_cast<int32_t>(packet.height) }); | 	target_window->set_min_size({ 0, 0, static_cast<int32_t>(packet.width), static_cast<int32_t>(packet.height) }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void WindowServer::on_window_set_max_size(int fd, const LibGUI::WindowPacket::WindowSetMaxSize& packet) | ||||||
|  | { | ||||||
|  | 	BAN::RefPtr<Window> target_window; | ||||||
|  | 	for (auto& window : m_client_windows) | ||||||
|  | 	{ | ||||||
|  | 		if (window->client_fd() != fd) | ||||||
|  | 			continue; | ||||||
|  | 		target_window = window; | ||||||
|  | 		break; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if (!target_window) | ||||||
|  | 	{ | ||||||
|  | 		dwarnln("client tried to set window max size while not owning a window"); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// FIXME: should this resize window
 | ||||||
|  | 	target_window->set_max_size({ 0, 0, static_cast<int32_t>(packet.width), static_cast<int32_t>(packet.height) }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::WindowSetFullscreen& packet) | void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::WindowSetFullscreen& packet) | ||||||
| { | { | ||||||
| 	if (m_state == State::Fullscreen) | 	if (m_state == State::Fullscreen) | ||||||
|  | @ -1213,16 +1235,23 @@ Rectangle WindowServer::cursor_area() const | ||||||
| Rectangle WindowServer::resize_area(Position cursor) const | Rectangle WindowServer::resize_area(Position cursor) const | ||||||
| { | { | ||||||
| 	const auto min_size = m_focused_window->get_min_size(); | 	const auto min_size = m_focused_window->get_min_size(); | ||||||
|  | 	const auto max_size = m_focused_window->get_max_size(); | ||||||
| 
 | 
 | ||||||
| 	int32_t diff_x = m_resize_start.x - cursor.x; | 	int32_t diff_x = m_resize_start.x - cursor.x; | ||||||
| 	if (m_resize_quadrant % 2) | 	if (m_resize_quadrant % 2) | ||||||
| 		diff_x = -diff_x; | 		diff_x = -diff_x; | ||||||
| 	diff_x = BAN::Math::max(diff_x, -m_focused_window->client_width() + min_size.width); | 	diff_x = BAN::Math::clamp(diff_x, | ||||||
|  | 		-m_focused_window->client_width() + min_size.width, | ||||||
|  | 		-m_focused_window->client_width() + max_size.width | ||||||
|  | 	); | ||||||
| 
 | 
 | ||||||
| 	int32_t diff_y = m_resize_start.y - cursor.y; | 	int32_t diff_y = m_resize_start.y - cursor.y; | ||||||
| 	if (m_resize_quadrant / 2) | 	if (m_resize_quadrant / 2) | ||||||
| 		diff_y = -diff_y; | 		diff_y = -diff_y; | ||||||
| 	diff_y = BAN::Math::max(diff_y, -m_focused_window->client_height() + min_size.height); | 	diff_y = BAN::Math::clamp(diff_y, | ||||||
|  | 		-m_focused_window->client_height() + min_size.height, | ||||||
|  | 		-m_focused_window->client_height() + max_size.height | ||||||
|  | 	); | ||||||
| 
 | 
 | ||||||
| 	int32_t off_x = 0; | 	int32_t off_x = 0; | ||||||
| 	if (m_resize_quadrant % 2 == 0) | 	if (m_resize_quadrant % 2 == 0) | ||||||
|  |  | ||||||
|  | @ -38,6 +38,7 @@ public: | ||||||
| 	void on_window_set_mouse_capture(int fd, const LibGUI::WindowPacket::WindowSetMouseCapture&); | 	void on_window_set_mouse_capture(int fd, const LibGUI::WindowPacket::WindowSetMouseCapture&); | ||||||
| 	void on_window_set_size(int fd, const LibGUI::WindowPacket::WindowSetSize&); | 	void on_window_set_size(int fd, const LibGUI::WindowPacket::WindowSetSize&); | ||||||
| 	void on_window_set_min_size(int fd, const LibGUI::WindowPacket::WindowSetMinSize&); | 	void on_window_set_min_size(int fd, const LibGUI::WindowPacket::WindowSetMinSize&); | ||||||
|  | 	void on_window_set_max_size(int fd, const LibGUI::WindowPacket::WindowSetMaxSize&); | ||||||
| 	void on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::WindowSetFullscreen&); | 	void on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::WindowSetFullscreen&); | ||||||
| 	void on_window_set_title(int fd, const LibGUI::WindowPacket::WindowSetTitle&); | 	void on_window_set_title(int fd, const LibGUI::WindowPacket::WindowSetTitle&); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -379,6 +379,10 @@ int main() | ||||||
| 						if (auto ret = LibGUI::WindowPacket::WindowSetMinSize::deserialize(client_data.packet_buffer.span()); !ret.is_error()) | 						if (auto ret = LibGUI::WindowPacket::WindowSetMinSize::deserialize(client_data.packet_buffer.span()); !ret.is_error()) | ||||||
| 							window_server.on_window_set_min_size(fd, ret.release_value()); | 							window_server.on_window_set_min_size(fd, ret.release_value()); | ||||||
| 						break; | 						break; | ||||||
|  | 					case LibGUI::PacketType::WindowSetMaxSize: | ||||||
|  | 						if (auto ret = LibGUI::WindowPacket::WindowSetMaxSize::deserialize(client_data.packet_buffer.span()); !ret.is_error()) | ||||||
|  | 							window_server.on_window_set_max_size(fd, ret.release_value()); | ||||||
|  | 						break; | ||||||
| 					case LibGUI::PacketType::WindowSetFullscreen: | 					case LibGUI::PacketType::WindowSetFullscreen: | ||||||
| 						if (auto ret = LibGUI::WindowPacket::WindowSetFullscreen::deserialize(client_data.packet_buffer.span()); !ret.is_error()) | 						if (auto ret = LibGUI::WindowPacket::WindowSetFullscreen::deserialize(client_data.packet_buffer.span()); !ret.is_error()) | ||||||
| 							window_server.on_window_set_fullscreen(fd, ret.release_value()); | 							window_server.on_window_set_fullscreen(fd, ret.release_value()); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue