Setting Window Focus

My Windows application is creating 2 windows.


wp = WindowProperties()
wp.setTitle('Window1')
wp.setSize(self.screenResolution[0], self.screenResolution[1])
wp.setUndecorated(True)
wp.setForeground(True)
wp.setOrigin(self.bufferXResolution*self.screenOffset,0)
base.win.requestProperties(wp)
			
# Create a second window for the right eye display
wp = WindowProperties()
wp.setTitle('Right Eye')
wp.setSize(self.screenResolution[0], self.screenResolution[1])
wp.setUndecorated(True)
wp.setForeground(False)
wp.setOrigin( (self.bufferXResolution * self.screenOffset) + self.screenResolution[0], 0)
window2=base.openWindow(props = wp, pipe = base.pipe, gsg = base.win.getGsg(), scene = render)

All of the keyboard events are handled only if the first window has focus, but the 2nd window always has focus by default. I have tried using WindowProperties::setForeground when the windows are created and after they are created to give focus to the first window, with no apparent effect.

Is there a way to set focus to the first window? Better yet, can we set up our keyboard event handling so they will listen to both windows?

Thanks in advance for any help.

It looks like a bug that setForeground() wasn’t working. I’ve just fixed that bug; it’ll be released in a future version of Panda.

But there is also a way to set up the keyboard handling for the auxiliary window. You need to create an additional MouseAndKeyboard node, as well as an additional ButtonThrower node (these nodes are created for you by code in ShowBase.py for the main window by default).

mk = base.dataRoot.attachNewNode(MouseAndKeyboard(window2, 0, 'w2mouse'))
bt = mk.attachNewNode(ButtonThrower('w2mouse'))
mods = ModifierButtons()
mods.addButton(KeyboardButton.shift())
mods.addButton(KeyboardButton.control())
mods.addButton(KeyboardButton.alt())
bt.node().setModifierButtons(mods)

David

Incidentally, some graphics cards are known to exhibit poor performance when they render to two different windows. Instead of rendering to two side-by-side windows, it may be better to create one double-wide window, with two DisplayRegions in it, dividing the window in half.

David

One more FYI: the bleeding-edge version of Panda, in the CVS tree, includes some built-in functions in support of stereo. In particular, you can define a stereo lens with an interocular distance and a convergence distance, and apply it to two different windows and/or display regions, one for each of the left and right eyes.

The stereo lens will automatically compute the appropriate transformations to the viewing frustum to make a correct stereo pair, and furthermore Panda will optimize the cull process so that it only traverses the scene graph once for both the left and the right eyes (rather than twice, as it would have to do if you had two separate, unrelated cameras).

David

Thanks for the tips. I do not have access to the latest code yet, but can you set the convergence distance so that the camera’s are essentially parallel?

The one window solution sounds nice, especially as it would solve our window focus problems.

Yes, a convergence distance of 0 means parallel. You can also, of course, set it to 100,000,000 or whatever ridiculously large distance you like, which amounts to the same thing.

David