Detect window focus (DEF-1994) (SOLVED)

Ability to detect if the game window is the active window on desktop clients or not.

1 Like

We have a ticket similar to this one related to detecting when the mobile apps are minimized/restored (DEF-1146) but we didn’t have one for desktop apps that covered both the case of minimize/restore and active/inactive so I went ahead and created a ticket for it: DEF-1994

2 Likes

This issue was fixed with DEF-1146 so I’m marking this as solved (http://www.defold.com/ref/window/)

3 Likes

Has anyone confirmed that this is working? In 1.2.89, I get an undefined symbol when trying to call window on an iOS device :frowning:

I tried it again now, and it works for me. What part actually goes wrong? Does the window module not exist? what function are you trying to call?

It crashes with an undefined symbol of “window” with the line:

window.set_listener(window_listener)

Also, I don’t get any autocompletion from window. in the Defold editor, as in the case of gui, go or push for example.

Is window_listener defined?

> ------------------------------------------------------------------------------
> local function window_listener(self, event, data)
> 	if event == window.WINDOW_EVENT_FOCUS_GAINED then
> 		if push then
> 			push.set_badge_count(0)
> 		end
> 	end
> end

Great. And where is that function defined in the source file? Before or after you reference it?

Can you test a blank project with just the single script on your iOS device?

local function window_listener(self, event, data) -- edited to fix mistake
     if event == window.WINDOW_EVENT_FOCUS_GAINED then
         print("focus has been gained")
     end
     if event == window.WINDOW_EVENT_RESIZED then -- edited to add example
         print(data.height, data.width)
     end
end

function init(self) -- edited to move after
    window.set_listener(window_listener)
end
1 Like

@Mathias_Westerdahl helped me with the issue and it boiled down to our build server grabbing an old version which didn’t include window.

4 Likes