Skip to content

macOS: Embedded window fixes#106166

Merged
akien-mga merged 1 commit intogodotengine:masterfrom
stuartcarnie:macos_embed_fixes
May 13, 2025
Merged

macOS: Embedded window fixes#106166
akien-mga merged 1 commit intogodotengine:masterfrom
stuartcarnie:macos_embed_fixes

Conversation

@stuartcarnie
Copy link
Copy Markdown
Contributor

@stuartcarnie stuartcarnie commented May 8, 2025

Fixes in this PR:

  • The separate embedded process window can be dismissed by clicking the 🔴 close button.
  • Running Godot from a terminal will shutdown gracefully when it receives SIGINT
  • When using Metal in Truck Town (Forward+/Mobile), the sky takes the background color of the game window
  • Return error if --embedded is specified on unsupported platforms
  • Fix display scaling noted in macOS: Additional improvements and fixes for embedded window support #106134 (comment)

@stuartcarnie stuartcarnie requested a review from a team as a code owner May 8, 2025 08:52
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

@Calinou

Unfortunately, handling CTRL-C and ensuring the child process terminates is a lot more challenging, as the macOS app terminates without cleanly tearing down.

I might be able to have the child process monitor the debugger connection and shutdown if it is terminated.

@akien-mga
Copy link
Copy Markdown
Member

Unfortunately, handling CTRL-C and ensuring the child process terminates is a lot more challenging, as the macOS app terminates without cleanly tearing down.

Doesn't it work with the SIGINT handler we register in

void OS_Unix::initialize_debugging() {
        if (EngineDebugger::is_active()) {
                struct sigaction action;
                memset(&action, 0, sizeof(action));
                action.sa_handler = handle_interrupt;
                sigaction(SIGINT, &action, nullptr);
        }
}

I'm not too familiar with macOS but I'd be surprised if it couldn't react to SIGINT in a customized way so we can clean up child processes before terminating the editor process.

@stuartcarnie
Copy link
Copy Markdown
Contributor Author

Doesn't it work with the SIGINT handler we register in

That is installed in the child (embedded) process. If we send SIGINT to the editor, when running via a terminal, it immediately terminates. I expect I can install a SIGINT handler that posts a quit to shut down gracefully.

I will try that!

@stuartcarnie stuartcarnie requested a review from a team as a code owner May 8, 2025 21:02
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

@Calinou / @akien-mga SIGINT is now properly handled and Godot terminates child processes

@stuartcarnie stuartcarnie force-pushed the macos_embed_fixes branch 3 times, most recently from 6ac8665 to 2823ff2 Compare May 9, 2025 02:09
@stuartcarnie stuartcarnie requested a review from a team as a code owner May 9, 2025 02:09
@stuartcarnie stuartcarnie force-pushed the macos_embed_fixes branch 2 times, most recently from 614c394 to 298b812 Compare May 9, 2025 02:11
@stuartcarnie stuartcarnie changed the title macOS: Embedded window can be dismissed by clicking close macOS: Embedded window fixes May 10, 2025
@stuartcarnie stuartcarnie marked this pull request as draft May 10, 2025 05:25
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

@Calinou temporarily moving to draft, until I fix the following issue:

#106134 (comment)

I can replicate it, so I'll be able to resolve it.

@stuartcarnie stuartcarnie marked this pull request as ready for review May 10, 2025 20:49
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

@Calinou I've now resolved the scaling issue described by a couple of our users, so this PR is ready for review

@Alex2782
Copy link
Copy Markdown
Member

It's better now. 24" Full HD (1920 x 1080)
It just needs to be initialized properly at startup.

test 1 (Floating)
Screen-2025-05-11-014948.mp4
test 2
Screen-2025-05-11-015202.mp4

@Alex2782
Copy link
Copy Markdown
Member

Alex2782 commented May 11, 2025

There are still minor issues, but not critical.
For example, in pause mode, it doesn't always scale correctly.

Details

interface/editor/display_scale = 125% (maybe also reproducible with 100% scaling)

2m 27s video
https://drive.google.com/file/d/1sXm72ohgujjUEvvQkl4XdVY9ZpbMSUsS/view


  • 0:49 There is a minimum height (in stretch mode the lower tab windows could no longer be switched)

Bildschirmfoto 2025-05-11 um 02 41 16


Once, it was wide. When I tried to reduce the width, the inspector was overlapped, but I couldn’t reproduce the issue again. (It's a similar issue at 1:39, perhaps.)

  • 1:39

image

@stuartcarnie
Copy link
Copy Markdown
Contributor Author

Good feedback, @Alex2782, thanks for testing! We should be able to address both issues.

Pause Mode issue

We would need to re-render the frame, but I am not aware of an API in Godot we can use. I'll ask around. The alternative is to step by one frame to refresh the rendered output at the new resolution, but that is less than ideal, as the gameplay would be moving forward.

Initialised at startup

I'll check that out – it seems the startup parameters don't match when the display is 1x 👍🏻

- Installed a SIGINT handler to terminate the application gracefully.
- Handle varying display scaling
@stuartcarnie
Copy link
Copy Markdown
Contributor Author

@Alex2782 I haven't been able to reproduce the incorrect initial size. I've reordered the messages sent at startup, so that the window size should be correct, based on the current desktop window scaling.

The paused output is an issue when not embedding too, as the frame is not re-rendered. The difference is that the background colour is updated when the window redraws. We can probably do something similar, which I will look at.

@akien-mga akien-mga requested a review from bruvzg May 12, 2025 12:51
@akien-mga akien-mga assigned Calinou and unassigned Calinou May 12, 2025
@akien-mga akien-mga requested a review from Calinou May 12, 2025 12:51
Copy link
Copy Markdown
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found another resizing issue:

Screen.Recording.2025-05-12.at.22.50.50.mov

Should be fixable with something like this:

diff --git a/platform/macos/editor/embedded_process_macos.mm b/platform/macos/editor/embedded_process_macos.mm
index b2c80fb25a..e30031bf78 100644
--- a/platform/macos/editor/embedded_process_macos.mm
+++ b/platform/macos/editor/embedded_process_macos.mm
@@ -43,7 +43,10 @@
 
 void EmbeddedProcessMacOS::_notification(int p_what) {
 	switch (p_what) {
-		case NOTIFICATION_RESIZED:
+		case NOTIFICATION_ENTER_TREE: {
+			set_notify_transform(true);
+		} break;
+		case NOTIFICATION_TRANSFORM_CHANGED:
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 			update_embedded_process();
 		} break;

I'm not entirely convinced about graceful shutdown on Ctrl+C, I would expect it to kill process instantly, but I guess it's just my personal preference.

@stuartcarnie
Copy link
Copy Markdown
Contributor Author

stuartcarnie commented May 12, 2025

I'm not entirely convinced about graceful shutdown on Ctrl+C, I would expect it to kill process instantly, but I guess it's just my personal preference.

SIGINT and SIGTERM are expected to gracefully terminate, if possible, by handling the signal. SIGKILL can't be handled, so it always kills the process instantly. If we don't handle it, it results in unexpected and undesired behaviour, as the embedded process continues to run in the background, consuming CPU, and the user isn't aware. The user would have to manually kill the process, via Activity Monitor or other means.

@akien-mga akien-mga merged commit c0ebba6 into godotengine:master May 13, 2025
20 checks passed
@akien-mga
Copy link
Copy Markdown
Member

Thanks!

Merging now to include in 4.5-dev4, Stuart will work on the remaining points in a follow-up.

@bruvzg
Copy link
Copy Markdown
Member

bruvzg commented May 13, 2025

When using Metal in Truck Town (Forward+/Mobile), the sky takes the background color of the game window

I broke this in #106340, should be fixed by #106355 (while keeping transparency support).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants