-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Emscripten focus / blur #7237
Emscripten focus / blur #7237
Conversation
I set a delay of 0 and now only the first frame is not recognized. |
Hmm, maybe this would be better: emscripten_set_blur_callback, emscripten_set_focus_callback, emscripten_set_focusin_callback, emscripten_set_focusout_callback... |
@ofTheo changed it, and it works quite well... |
Haha, I can print the correct result in |
@Jonathhhan - there isn't currently a good method to set focus in ofApp. The problem is that emscripten uses the standard ofApp class, so it would be weird to add something that is just for emscripten at that level. You could potentially make it a function of ofxAppEmscriptenWindow ie:
So from ofApp you would have to cast the So you could do this in ofApp.cpp
Neither is a super elegant solution but I think could be useful for the few cases people might need it. Also open to other ideas too! 🙂 |
@ofTheo thanks, thats very helpful. Yes, I want to get the focus callback in ofApp (in my case for detecting, if the filebrowser is canceled or if the mouse clicked outside of the filebrowser - but I am sure there are other cases, too). So in my case the focus status would be enough.
I was setting the status in |
Yeah, there could be a few different ways to do it. I could imagine doing something like ofAppEmscriptenWindow::enableEvents() and then you could do ofAddListener and register for different events with custom ofApp callback functions. eg: https://github.com/openframeworks/openFrameworks/blob/master/examples/events/simpleEventsExample/src/ofApp.cpp#L18-L21 For the file stuff I wonder if it could be integrated similar to the desktop dialogs: but for the load here: |
I tried your suggestion, but I get the error:
|
Quite a simple method for getting blur/focus and other callbacks, is to get them directly in ofApp.
In
And:
in |
Yeah, it would be great, if the filesystem stuff could be integrated like that. |
With this line you can get it in
ofApp.cpp
:int focused = EM_ASM_INT({console.log(canvas.hasFocus); return canvas.hasFocus});
.Not sure if it makes sense in
ofxAppEmscriptenWindow.cpp
, you can also set that line in the app. And a little drawback: I tried to initialize the value with true, but it does not work. So it is activated with the first interaction with the canvas (a mouse click). I guess, it would need a short delay, because the canvas does not exist yet?