2022-07-21

Published: Nov 08, 2022Last modified: Apr 05, 2023
Word count: 841

TODO consider adding no-window option to gut's cli and gui options

here's spec for what this would look like: https://github.com/bitwes/Gut/issues/360 related: https://github.com/bitwes/Gut/issues/357 maintainer hasn't tried it!

if we hold to 3.4, slightly different approach: https://github.com/godotengine/godot/blob/3.4/editor/editor_node.cpp#L516

could use get_window_position() ... ?

       print("window position: ", OS.get_window_position())

with --no-window, it's 0,0 ... but that won't work in CI.... tho maybe the use-cases are the same?

> issue comment

Apologies for the large comment here - I was hoping to turn this into a PR, but couldn't find a way to make it work, so here's my notes instead.

I was curious about enabling `--no-window` from the GUT panel, to prevent an extra window from opening when running tests through the editor, but once I found this issue, I thought I'd dig in. I'm pretty new to digging into godot internals, so take all this with a grain of salt!

One thing is that `--no-window` has been removed in favor of `--headless` in this commit: https://github.com/godotengine/godot/commit/09386ba9fd6abddb3b9be723ae3650c6d15bc440 So that command line option shift at some point (maybe in 3.5?).

It looks like `DisplayServer` - `window_can_draw` will soon be a preferred way to check for this: https://github.com/godotengine/godot/commit/39efccf3b8298e30aa67a726ffd8752b3dff4c66 In the meantime: `OS::get_singleton()->can_draw() && !OS::get_singleton()->is_no_window_mode_enabled()` seems to be the 3.x compatible version (https://github.com/godotengine/godot/pull/50767#discussion_r688335782).

I couldn't find anything like this available in gdscript, expect for `OS.can_draw()`, which unfortunately seems to return `true` regardless of `--no-window`.

I thought maybe `OS.get_cmdline_args()` would include `--no-window`, but it seems to be cleared/removed before the shell script runs, so it doesn't show up in that array.

The Godot OS class itself does not expose anything directly helpful, despite the OS singleton in godot's source maintaining a `_no_window` bool - perhaps this has just never been requested, so it's not exposed? Or maybe there's some idea that people will use the "headless" godot builds directly for cases like this?

I tried a few different things in a script:

```

func _init():

print("os can draw: ", OS.can_draw())

print("os props: ", OS.get_property_list())

# for p in OS.get_property_list():

# print(p.name)

# print(" " + p.name + ": ", OS.get(p.name))

print("window position: ", OS.get_window_position())

print("no window: ", OS.get_window_position() == Vector2.ZERO)

# print("minimized: ", OS.window_minimized)

quit()

```

One hacky option is something like: `OS.get_window_position() == Vector2.ZERO`, which isn't perfect but might be right in most cases, and probably in CI? But, not the best solution, there might be weird cases that break it.

It seems there's no way to opt-in to `--no-window` behavior from a gdscript, at least not without a PR to godot itself that exposes more of the OS singleton. If there are workarounds for doing this, I'm very interested! I'm trying to get a better grasp of gdscript + godot in general, especially for more command-line tools like this.

TODO godot 3.4 crashes when os.window_minimized and --no-window are combined

#!/usr/bin/env -S godot -s --no-window
extends SceneTree


func _init():
        print("hello")
        print("os can draw: ", OS.can_draw())
        print("os props: ", OS.get_property_list())
        print("minimized: ", OS.window_minimized)
        quit()

TODO this GUT guy rules

check out these tutorials!

TODO create a sherlock sprite

TODO create a dumbledore sprite