godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add a "window position changed" signal #2992

Open Sooshiko opened 3 years ago

Sooshiko commented 3 years ago

Describe the project you are working on

First time using GitHub so sorry if i mess up. I am working on a small platformer game but this will be useful in all my future projects.

Describe the problem or limitation you are having in your project

I have a system where the window is resized and moved to where/how the window was last session, so for instance if you make your window half the size of the screen so you can watch youtube videos on the other half then it will remember it's location/size next time you open the program.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

To save the size and position of the window i hooked the "size_changed" of the root viewport to a function that saves the window's data. This means if you move the window without resizing it the window will not save. There is no such function or signal as "Window.position_changed". I tried looking into overwriting the window's vector2's setter function but that doesn't seem possible either.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I'm not sure where you would put it but some sort of signal like "OS.window_position_changed" would work nicely i think.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Technically you can loop every frame in an autoloaded singleton to check if the window position changed which is what i am doing currently but this seems overkill.

Is there a reason why this should be core and not an add-on in the asset library?

I don't even think it's possible to make it an add-on. But even if it can it should be a core functionality.

KoBeWi commented 3 years ago

Technically you can loop every frame in an autoloaded singleton to check if the window position changed which is what i am doing currently but this seems overkill.

Or you can just store it on exit?

Sooshiko commented 3 years ago

Technically you can loop every frame in an autoloaded singleton to check if the window position changed which is what i am doing currently but this seems overkill.

Or you can just store it on exit?

That's also something i used to do. I believe i stopped doing that because my program crash-exited so often it was a problem. i actually forgot i could do that now >_<

KoBeWi commented 3 years ago

Well, another option would be having a Timer in your autoload, so instead of checking every frame, you could check every second or every few seconds. Timers are much cheaper than using _process(), so it wouldn't be a problem (I have some plugins like this myself).

Sooshiko commented 3 years ago

Well, another option would be having a Timer in your autoload, so instead of checking every frame, you could check every second or every few seconds. Timers are much cheaper than using _process(), so it wouldn't be a problem (I have some plugins like this myself).

To have a sort of 5 second "autosave" feature like that would do the trick, i suppose. I was very confused when i was searching the internet on how to detect if the window's position changed and i was baffled to find there is no way to do this with signals. I tried doing it by modifying the Vector2's setter but idk how feasible that is. i couldn't figure it out. I still think it would be worth implementing just so it's more intuitive. I can imagine projects requiring to change a shader's parameters based on the window's position like a magnifying glass program or some meta game where you must move the window to beat a puzzle. But it's not as required as i first thought, i suppose.