forked from Bananymous/banan-os
				
			WindowServer: Send mouse release to same window as mouse press
This commit is contained in:
		
							parent
							
								
									c18fefd5f3
								
							
						
					
					
						commit
						a8844ddd28
					
				|  | @ -475,15 +475,19 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event) | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	const size_t button_idx = static_cast<size_t>(event.button); | ||||||
|  | 	if (button_idx >= m_mouse_button_windows.size()) | ||||||
|  | 	{ | ||||||
|  | 		dwarnln("invalid mouse button {}", button_idx); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	BAN::RefPtr<Window> target_window; | 	BAN::RefPtr<Window> target_window; | ||||||
| 	for (size_t i = m_client_windows.size(); i > 0; i--) | 	if (!event.pressed) | ||||||
| 	{ | 		target_window = m_mouse_button_windows[button_idx]; | ||||||
|  | 	for (size_t i = m_client_windows.size(); i > 0 && !target_window; i--) | ||||||
| 		if (m_client_windows[i - 1]->full_area().contains(m_cursor)) | 		if (m_client_windows[i - 1]->full_area().contains(m_cursor)) | ||||||
| 		{ |  | ||||||
| 			target_window = m_client_windows[i - 1]; | 			target_window = m_client_windows[i - 1]; | ||||||
| 			break; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	switch (m_state) | 	switch (m_state) | ||||||
| 	{ | 	{ | ||||||
|  | @ -530,7 +534,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event) | ||||||
| 
 | 
 | ||||||
| 			[[fallthrough]]; | 			[[fallthrough]]; | ||||||
| 		case State::Fullscreen: | 		case State::Fullscreen: | ||||||
| 			if (target_window && target_window->client_area().contains(m_cursor)) | 			if (target_window && (!event.pressed || target_window->client_area().contains(m_cursor))) | ||||||
| 			{ | 			{ | ||||||
| 				LibGUI::EventPacket::MouseButtonEvent packet; | 				LibGUI::EventPacket::MouseButtonEvent packet; | ||||||
| 				packet.event.button = event.button; | 				packet.event.button = event.button; | ||||||
|  | @ -542,6 +546,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event) | ||||||
| 					dwarnln("could not send mouse button event: {}", ret.error()); | 					dwarnln("could not send mouse button event: {}", ret.error()); | ||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
|  | 				m_mouse_button_windows[button_idx] = event.pressed ? target_window : nullptr; | ||||||
| 			} | 			} | ||||||
| 			break; | 			break; | ||||||
| 		case State::Moving: | 		case State::Moving: | ||||||
|  |  | ||||||
|  | @ -96,6 +96,7 @@ private: | ||||||
| 	State m_state { State::Normal }; | 	State m_state { State::Normal }; | ||||||
| 	bool m_is_mod_key_held { false }; | 	bool m_is_mod_key_held { false }; | ||||||
| 	BAN::RefPtr<Window> m_focused_window; | 	BAN::RefPtr<Window> m_focused_window; | ||||||
|  | 	BAN::Array<BAN::RefPtr<Window>, 5> m_mouse_button_windows; | ||||||
| 	Position m_cursor; | 	Position m_cursor; | ||||||
| 
 | 
 | ||||||
| 	Rectangle m_non_full_screen_rect; | 	Rectangle m_non_full_screen_rect; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue