Godot Version
v4.7
Question
I don’t mean setting the position every frame which barely works and is glitchy as heck. Is there any way to just lock it in place properly? Thanks.
You can make it fullscreen.
Thanks, but I’m trying to do it while it’s maximized.
Probably not, the operating system’s window manager will strongly prefer to allow moving windows around one way or another. You can make your game window borderless (if supported by the window manager) which is potentially more difficult to drag around, but most hotkeys will still affect the window position. Ultimately the window size and position are not up to you, they are only requests to the great overlord window manager.
Instead of setting the position every frame you could use _notification or _input to detect window position changes specifically, and try moving it back.
func _notification(what: int) -> void:
if what == NOTIFICATION_WM_POSITION_CHANGED:
var window := get_window()
if window.position != MY_POSITION: # maybe avoid re-triggering this notification
window.position = MY_POSITION
On a desktop this would be very unwelcome.
Can you give an example of a program that locks itself in place (other than fullscreen)?
You’re right, but I’m trying to do this with maximized mode, which I think makes sense, and the resize button is turned off. I’m making something experimental/meta, playing around with window modes and sizes.
If you wish to build on what gertkenko said, you can try to compile a version of Godot that doesn’t show the title bar. On Windows, that would make it much more difficult to move the window (but not impossible). In that case, you would need to look into the display_server_windows.h and display_server_windows.cpp files, and begin from there.
This StackOverflow thread gives an example of how to initialise a Win32 window without a title bar.
You can also try to intercept some additional Win32 events, like the one resulting from MoveWindow. This would still allow the player to drag the window somewhere, but it would snap back. There’s probably also some weird and wonderful ways to stop the window from even being dragged using this method.
Note, this approach is Windows only. Its likely that you can do something like this in X11 and Wayland (Linux). I don’t know enough about MacOS to comment. On Android/iOS, it’s likely not possible (without jailbreaks).