How to create better Edge Scrolling

Godot Version

Godot 4

Question

I created edge scrolling for the camera, but I don’t think it’s perfect because when the game is windowed, the camera moves even at the center of the game screen.
This is my code

var threshold = 10
var step = 50

func _process(delta):
	edge_scrolling()

func edge_scrolling() :
	var viewport_size = get_viewport().size
	var local_mouse_pos = get_viewport().get_mouse_position()
	if local_mouse_pos.x < threshold:
		position.x -= step
	elif local_mouse_pos.x > viewport_size.x - threshold:
		position.x += step
	if local_mouse_pos.y < threshold:
		position.y -= step
	elif local_mouse_pos.y > viewport_size.y - threshold:
		position.y += step

I attached the script at remotetransform2d

This is my edge-scrolling code. It only works with fullscreen tho:

func edgeScrolling() -> void:
    var viewportSize: Vector2 = camera.viewport.size;
	var local_mouse_pos = camera.viewport.get_mouse_position();
	var distance = local_mouse_pos - viewportSize
	
	if distance.x >= -1:
		camera.position.x += scrollSpeed
	elif distance.x <= -viewportSize.x:
		camera.position.x -= scrollSpeed
	if distance.y >= -1:
		camera.position.y += scrollSpeed
	elif distance.y <= -viewportSize.y:
		camera.position.y -= scrollSpeed

The only improvement i can see is to reduce the threshhold