inside boolean for when the cursor is over the title bar is not the right way to do this. You want to use a proper input event so you can track where the mouse was when the user pressed their mouse.
You want to hook
_gui_input on the title bar, and track when the user presses down the mouse on the title bar and when they release it. Store the position of the mouse when they pressed down in a variable, and unset it when the user releases. Then you can determine how the window was moved by the difference between the current mouse position and the position when the window was grabbed.
var dragPoint = null
if ev is InputEventMouseButton:
if ev.button_index == BUTTON_LEFT:
# Grab it.
dragPoint = get_global_mouse_position() - get_position()
# Release it.
dragPoint = null
if ev is InputEventMouseMotion and dragPoint != null:
set_position(get_global_mouse_position() - dragPoint)
For reference, this is pretty much a reimplementation of the built-in
WindowDialog dragging code