-
Notifications
You must be signed in to change notification settings - Fork 3
Add multimonitor configuration #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JezSonic
wants to merge
1
commit into
main
Choose a base branch
from
dev/multi-mon-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| @tool | ||
| extends SpinBox | ||
|
|
||
| @export var section: String | ||
| @export var key: String | ||
| @export var default: float = 0.0 | ||
|
|
||
| func _ready(): | ||
| UserSettings.config_changed.connect(_load_from_settings) | ||
| value_changed.connect(_on_value_changed) | ||
| _load_from_settings() | ||
|
|
||
| func _load_from_settings(): | ||
| value = UserSettings.get_setting(section, key, default) | ||
|
|
||
| func _on_value_changed(new_value: float): | ||
| UserSettings.save_setting(section, key, new_value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://dsysphlfnqhm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| extends Node | ||
| class_name MultiMonitorManager | ||
|
|
||
| var windows: Array[Window] = [] | ||
| var cameras: Array[Dictionary] = [] | ||
|
|
||
| @onready var player: Node = get_parent() | ||
| @onready var main_camera: Camera3D = get_viewport().get_camera_3d() | ||
|
|
||
| var _last_mode: int = -1 | ||
|
|
||
| func _ready() -> void: | ||
| process_priority = 100 | ||
| UserSettings.config_changed.connect(_update_windows) | ||
| # Wait a bit for the main camera to be initialized if needed | ||
| _update_windows() | ||
|
|
||
| func _exit_tree() -> void: | ||
| _clear_windows() | ||
|
|
||
| func _clear_windows() -> void: | ||
| for win in windows: | ||
| win.queue_free() | ||
| windows.clear() | ||
| cameras.clear() | ||
|
|
||
| func _update_windows() -> void: | ||
| var mode: int = UserSettings.get_setting("window", "multi_monitor_mode", 0) | ||
|
|
||
| # Ensure windows are not embedded | ||
| var main_vp: Viewport = get_viewport() | ||
| main_vp.gui_embed_subwindows = false | ||
|
|
||
| if mode > 0: | ||
| var main_win: Window = main_vp.get_window() | ||
| if main_win: | ||
| # Only maximize if not already in a windowed mode | ||
| if main_win.mode != Window.MODE_WINDOWED: | ||
| main_win.mode = Window.MODE_MAXIMIZED | ||
|
|
||
| if mode == _last_mode: | ||
| # Just sync settings for existing windows | ||
| for win: Window in windows: | ||
| _sync_window_settings(win) | ||
| return | ||
|
|
||
| _last_mode = mode | ||
| _clear_windows() | ||
|
|
||
| if mode == 0: | ||
| return | ||
|
|
||
| var screen_count: int = DisplayServer.get_screen_count() | ||
| # if screen_count < 2: | ||
| # return | ||
|
|
||
| if mode == 1: # 2 Screens: Front, Right | ||
| _create_window(1, 1) # monitor 1, side 1 (Right) | ||
| elif mode == 2: # 3 Screens: Left, Front, Right | ||
| _create_window(1 if screen_count > 1 else 0, -1) # Left | ||
| _create_window(2 if screen_count > 2 else 0, 1) # Right | ||
|
|
||
| func _create_window(screen_index: int, side: int) -> void: | ||
| var win: Window = Window.new() | ||
| win.title = "MaSzyna - Screen " + str(screen_index) + (" (Right)" if side > 0 else " (Left)") | ||
|
|
||
| # Set position to the target screen | ||
| win.current_screen = screen_index | ||
| win.mode = Window.MODE_WINDOWED | ||
| win.size = Vector2i(1280, 720) | ||
|
JezSonic marked this conversation as resolved.
|
||
|
|
||
| # Share the world | ||
| win.world_3d = get_viewport().world_3d | ||
|
|
||
| var cam: Camera3D = Camera3D.new() | ||
| # Copy main camera settings | ||
| cam.fov = main_camera.fov | ||
| cam.near = main_camera.near | ||
| cam.far = main_camera.far | ||
|
|
||
| win.add_child(cam) | ||
| get_tree().root.add_child(win) | ||
|
|
||
| # Forward input to main camera | ||
| win.window_input.connect(_on_window_input) | ||
|
|
||
| # Sync render settings | ||
| _sync_window_settings(win) | ||
|
|
||
| windows.append(win) | ||
| cameras.append({"camera": cam, "side": side}) | ||
|
|
||
| win.show() | ||
|
|
||
| func _sync_window_settings(win: Window) -> void: | ||
| var main_vp: Viewport = get_viewport() | ||
| win.msaa_3d = main_vp.msaa_3d | ||
|
JezSonic marked this conversation as resolved.
|
||
| win.screen_space_aa = main_vp.screen_space_aa | ||
| win.use_debanding = main_vp.use_debanding | ||
| win.use_occlusion_culling = main_vp.use_occlusion_culling | ||
| win.mesh_lod_threshold = main_vp.mesh_lod_threshold | ||
|
|
||
| func _on_window_input(event: InputEvent) -> void: | ||
| get_viewport().push_input(event) | ||
|
|
||
| func _process(_delta: float) -> void: | ||
| if cameras.is_empty(): | ||
| return | ||
|
|
||
| main_camera = get_viewport().get_camera_3d() | ||
| if not main_camera: | ||
| return | ||
|
|
||
| var main_vp: Viewport = get_viewport() | ||
| var main_vp_size: Vector2 = main_vp.get_visible_rect().size | ||
|
|
||
| var main_v_fov: float = 0.0 | ||
| var main_h_fov: float = 0.0 | ||
| var focal_length: float = 0.0 | ||
|
|
||
| if main_camera.keep_aspect == Camera3D.KEEP_WIDTH: | ||
| main_h_fov = deg_to_rad(main_camera.fov) | ||
| focal_length = (main_vp_size.x / 2.0) / tan(main_h_fov / 2.0) | ||
| main_v_fov = 2.0 * atan((main_vp_size.y / 2.0) / focal_length) | ||
| else: | ||
| main_v_fov = deg_to_rad(main_camera.fov) | ||
| focal_length = (main_vp_size.y / 2.0) / tan(main_v_fov / 2.0) | ||
| main_h_fov = 2.0 * atan((main_vp_size.x / 2.0) / focal_length) | ||
|
|
||
| for cam_info: Dictionary in cameras: | ||
| var cam: Camera3D = cam_info["camera"] | ||
| var side: int = cam_info["side"] | ||
| var win: Window = cam.get_window() | ||
| var win_size: Vector2 = Vector2(win.size) | ||
|
|
||
| # Adjust side camera FOV to match main camera's pixel scale | ||
| # This ensures objects have the same size across screens regardless of window resolution | ||
| var side_v_fov: float = 2.0 * atan((win_size.y / 2.0) / focal_length) | ||
| var side_h_fov: float = 2.0 * atan((win_size.x / 2.0) / focal_length) | ||
|
|
||
| var rot_deg: float = 0.0 | ||
| var offset: float = 0.0 | ||
| var tilt: float = 0.0 | ||
| if side > 0: | ||
| rot_deg = UserSettings.get_setting("window", "monitor_rotation_right", 0.0) | ||
| offset = UserSettings.get_setting("window", "monitor_offset_right", 0.0) | ||
| tilt = UserSettings.get_setting("window", "monitor_tilt_right", 0.0) | ||
| else: | ||
| rot_deg = UserSettings.get_setting("window", "monitor_rotation_left", 0.0) | ||
| offset = UserSettings.get_setting("window", "monitor_offset_left", 0.0) | ||
| tilt = UserSettings.get_setting("window", "monitor_tilt_left", 0.0) | ||
|
|
||
| var angle: float = 0.0 | ||
| if rot_deg != 0.0: | ||
| angle = deg_to_rad(rot_deg) | ||
| else: | ||
| # Auto-calculate angle to match edges perfectly | ||
| angle = (main_h_fov + side_h_fov) / 2.0 | ||
|
|
||
| cam.global_transform = main_camera.global_transform | ||
|
|
||
| # Use world-space rotation to keep the horizon level and the locomotive straight | ||
| # across physically vertical monitors even when looking up or down. | ||
| cam.global_rotate(Vector3.UP, -angle * side) | ||
|
|
||
| # Apply manual tilt (roll) if specified | ||
| if tilt != 0.0: | ||
| cam.rotate_object_local(Vector3.FORWARD, deg_to_rad(tilt) * side) | ||
|
|
||
| cam.fov = rad_to_deg(side_v_fov) | ||
| cam.h_offset = main_camera.h_offset + (offset * side) | ||
| cam.v_offset = main_camera.v_offset | ||
| cam.near = main_camera.near | ||
| cam.far = main_camera.far | ||
| cam.keep_aspect = main_camera.keep_aspect | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://dgyswajs3fyny |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.