Skip to content

Commit

Permalink
Multi monitor related fixes (#84)
Browse files Browse the repository at this point in the history
* Prevent GoZen from going out of 'visible' screen bounds

Like behind the taskbar
Or behind the Copilot sidebar

* Fix window disappearing when main screen's coordinates change

when the coordinates of the main screen were changed and the window was dragged, the window would get a huge offset from where it should be.

* Fix extra window offset on screen position change

This line did not get committed😅

* Unhide titlebar only & "freely" drag b/w monitors

* Fix multi-monitor issue for resize handles
  • Loading branch information
ManpreetXSingh authored Feb 23, 2024
1 parent 2ca0400 commit 5c647b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/ui/screen_main/scripts/main_resize_handles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ func _on_gui_input(event: InputEvent, node: Control):

func _process(_delta: float) -> void:
if resizing:
var current_scene = get_tree().current_scene
var relative_mouse_pos = (
DisplayServer.mouse_get_position()
- DisplayServer.window_get_position(get_window().get_window_id())
)
if resize_node in [$Bottom, $Corner]:
get_window().size.y = int(current_scene.get_global_mouse_position().y)
get_window().size.y = int(relative_mouse_pos.y)
if resize_node in [$Right, $Corner]:
get_window().size.x = int(current_scene.get_global_mouse_position().x)
get_window().size.x = int(relative_mouse_pos.x)

#endregion
###############################################################
36 changes: 29 additions & 7 deletions src/ui/screen_main/scripts/main_top_bar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extends PanelContainer
var menu_buttons := []

var move_window := false
var move_start: Vector2i
var move_win_offset: Vector2i


func _ready() -> void:
Expand Down Expand Up @@ -92,15 +92,37 @@ var win_mode: Window.Mode:

func _on_top_bar_dragging(event) -> void:
if event is InputEventMouseButton and event.button_index == 1:
move_window = event.is_pressed() and win_mode == Window.MODE_WINDOWED
if move_window:
move_start = get_viewport().get_mouse_position()

var mouse_pos := DisplayServer.mouse_get_position()
var win_pos := DisplayServer.window_get_position(get_window().get_window_id())
move_window = false

if win_mode == Window.MODE_WINDOWED:
if event.is_pressed():
move_win_offset = mouse_pos - win_pos
move_window = true

elif OS.get_name() == "Windows":
var screen_rect := DisplayServer.screen_get_usable_rect(
DisplayServer.SCREEN_WITH_MOUSE_FOCUS
)
var tb_top := Vector2i(mouse_pos.x, win_pos.y)
var tb_bottom := Vector2i(mouse_pos.x, win_pos.y + int(size.y))

if !screen_rect.encloses(Rect2i(tb_top, tb_bottom)):
if tb_top.y < screen_rect.position.y:
get_window().position = (
tb_top.clamp(screen_rect.position, screen_rect.end)
- Vector2i(move_win_offset.x, 0)
)
else:
get_window().position = (
tb_bottom.clamp(screen_rect.position, screen_rect.end)
- Vector2i(move_win_offset.x, int(size.y))
)

func _process(_delta: float) -> void:
if move_window:
var mouse_delta = Vector2i(get_viewport().get_mouse_position()) - move_start
get_window().position += mouse_delta
get_window().position = DisplayServer.mouse_get_position() - move_win_offset

#endregion
###############################################################
Expand Down

0 comments on commit 5c647b0

Please # to comment.