NewtCanvasJFX not giving up focus

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

NewtCanvasJFX not giving up focus

Taylor
This post was updated on .
Apologies if I am confusing terms or concepts. The issue I am having is I have a GLWindow placed inside a JavaFX group. Then using DockFX I attach a bunch of different nodes around the main GLWindow.

The problem is when I click a textField in one of the other views, the GLWindow continues to consume KeyEvents so I cannot type in the other textfields.

If I pop-out one of the DockFX nodes so it is it's own window then I can type in them just fine, and even switch focus to other docked nodes. However, when I focus back on my GLWindow it will not give focus away.

I understand NewtCanvasJFX is a heavyweight window, and I am relatively positive I want to keep it this way as performance is important to me. I ask this question because I am able to get the focus in a desired state by popping out one of the nodes so I know it must be possible. I just can't find any information on how NewtCanvasJFX works.

Edit:
Barebones example demonstrating bug here: https://github.com/tpetrychyn/dockfx-newtcanvasjfx-example
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasJFX not giving up focus

gouessej
Administrator
Hello

Do you really need to call GLProfile.initSingleton() earlier? Can you provide a simpler example to demonstrate your problem?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasJFX not giving up focus

Taylor
Thanks for replying!

You are right, I have setup a barebones example which demonstrates the bug minimally. Please see:
https://github.com/tpetrychyn/dockfx-newtcanvasjfx-example


In the example please run Main. Click the JOGL canvas (black square) and then notice you are unable to type in any of the text fields or text area unless you undock them.


Edit: I now have noticed that DockFX is not related to the issue. I can reproduce it with just a very basic scene containing a Vbox, NewtCanvasJFX, and a TextField. The repo has been updated.
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasJFX not giving up focus

Taylor
I found a bad hack that allows it to work but there has got to be a better way. Essentially I listen to the real GLWindow for when it gains focus and tell Javafx to also give focus to something (glCanvas in my case). Then when glCanvas loses focus I quickly flip-flop visibility of the window which makes it give up focus.

Code wrote
        ...

        val window = GLWindow.create(screen, glCaps)
        val glCanvas = NewtCanvasJFX(window)

        window.addWindowListener(object : WindowAdapter() {
            override fun windowGainedFocus(e: WindowEvent) {
                // when heavyweight window gains focus, also tell javafx to give focus to glCanvas
                glCanvas.requestFocus()
            }
        })

        glCanvas.focusedProperty().addListener { _, _, newValue ->
            if (!newValue) {
                JFXAccessor.runOnJFXThread(false) {
                    window.isVisible = false
                    window.isVisible = true
                }
            }
        }
Reply | Threaded
Open this post in threaded view
|

Re: NewtCanvasJFX not giving up focus

gouessej
Administrator
If you can't live with such "hack", please fill a bug report. Nice finding :)
Julien Gouesse | Personal blog | Website