mouse misalignment when changing viewport size.

So, I want to change the resolution of the game like any other game does. But I simply find any tutorial related on this and when I tried doing it my self, the whole canvas does not get stretched to the current res and the mouse gets mouse misalignment.

THIS IS AN EXAMPLE OF A GAME WHERE YOU CHANGE THE RESOLUTION:

Here the code that I have. I need help btw… Thanks for reading!

func _on_resolutions_item_selected(index: int) -> void:
	var current_viewport_rid = get_viewport().get_viewport_rid()
	match index:
		0:
			RenderingServer.viewport_set_size(current_viewport_rid, 1152, 648)
			$Panel.size = Vector2(1152, 648)
		1:
			RenderingServer.viewport_set_size(current_viewport_rid, 1920, 1080)
			$Panel.size = Vector2(1920, 1080)

See the Multiple resolutions documentation for accomodating various screen sizes:

Resolution selectors are generally not needed nowadays. Use Resolution scaling if performance is a problem, or the viewport stretch mode in 2D (especially for pixel art games). Changing the viewport size independently of the window size is only possible with the viewport stretch mode.