-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add an OS.is_window_focused()
getter
#33967
Conversation
a292478
to
b43923b
Compare
This is after switching from app to android desktop and back:
func _notification(what):
match what:
NOTIFICATION_WM_FOCUS_IN:
g.info("NOTIFICATION_WM_FOCUS_IN")
NOTIFICATION_WM_FOCUS_OUT:
g.info("NOTIFICATION_WM_FOCUS_OUT\n")
NOTIFICATION_WM_QUIT_REQUEST:
g.info("NOTIFICATION_WM_QUIT_REQUEST")
NOTIFICATION_WM_MOUSE_ENTER:
g.info("NOTIFICATION_WM_MOUSE_ENTER")
NOTIFICATION_WM_MOUSE_EXIT:
g.info("NOTIFICATION_WM_MOUSE_EXIT")
# Android
NOTIFICATION_APP_PAUSED :
g.info("NOTIFICATION_APP_PAUSED")
NOTIFICATION_APP_RESUMED :
g.info("NOTIFICATION_APP_RESUMED")
NOTIFICATION_WM_GO_BACK_REQUEST:
g.info("NOTIFICATION_WM_GO_BACK_REQUEST") |
This makes it possible to know whether the window is focused at a given time, without having to track the focus state manually using `NOTIFICATION_WM_FOCUS_IN` and `NOTIFICATION_WM_FOCUS_OUT`. This partially addresses godotengine#33928.
b43923b
to
21a3923
Compare
@capnm I see, it might not be very useful to implement it on Android then (unless I'm mistaken). |
I would agree. There doesn't seem to be any Godot support for the Andoid wake lock. I use this patch already without any issues on Linux. It's nice shortcut for focus dependent processing or in this case #16832 managing the game controller input.
The idle and physics loop is disabled when the app is out of focus.
var fr: int = 0
func _process(delta: float):
fr += 1
if fr % 100 == 0:
print("tick ", fr) |
Thanks! |
This makes it possible to know whether the window is focused at a given time, without having to track the focus state manually using
NOTIFICATION_WM_FOCUS_IN
andNOTIFICATION_WM_FOCUS_OUT
.PS: I noticed Android makes use of those constants, but does it make sense to implement
OS.is_window_focused()
there? Can you run code in the game loop while the app is minimized?This partially addresses #33928.