1
0
Fork 0

src/Viewer/FGEventHandler.cxx: fixed multi-window event-handling bug.

Ever since support for CompositeViewer was added in f62e5b9ce3,
FGEventHandler::eventToViewport() has been always calling
window_builder->getDefaultWindow() so it could decide whether an event was for
the main window or not. But if a custom camera-group was specified, there would
be no existing window called 'FlightGear' so getDefaultWindow() would create
one, which then interfered with event handling.

The fix is to change the global WindowBuilder::defaultWindowName to match
sim/rendering/camera-group/gui/window/name when we are handling a custom
camera-group, which ensures that when FGEventHandler::eventToViewport() calls
window_builder->getDefaultWindow(), it gets the main window, not a new window
called 'FlightGear'.
This commit is contained in:
Julian Smith 2021-08-02 16:25:48 +01:00
parent c542e0d427
commit 17d40cdd80
3 changed files with 10 additions and 5 deletions

View file

@ -728,7 +728,7 @@ void CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
: 0);
if (!window && windowNode) {
// New style window declaration / definition
window = wBuild->buildWindow(windowNode);
window = wBuild->buildWindow(windowNode, true /*isMainWindow*/);
}
if (!window) { // buildWindow can fail

View file

@ -44,7 +44,7 @@ string makeName(const string& prefix, int num)
ref_ptr<WindowBuilder> WindowBuilder::windowBuilder;
const string WindowBuilder::defaultWindowName("FlightGear");
string WindowBuilder::defaultWindowName("FlightGear");
// default to true (historical behaviour), we will clear the flag if
// we run another GUI.
@ -228,7 +228,7 @@ void WindowBuilder::setMacPoseAsStandaloneApp(GraphicsContext::Traits* traits)
#endif
}
GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode, bool isMainWindow)
{
WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
string windowName;
@ -236,6 +236,11 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode)
windowName = winNode->getStringValue("window-name");
else if (winNode->hasChild("name"))
windowName = winNode->getStringValue("name");
if (isMainWindow) {
SG_LOG(SG_GENERAL, SG_DEBUG, "Changing defaultWindowName from "
<< defaultWindowName << " to " << windowName);
defaultWindowName = windowName;
}
GraphicsWindow* result = 0;
if (!windowName.empty()) {
// look for an existing window and return that

View file

@ -47,7 +47,7 @@ public:
* @param winNode The window's root property node
* @return a graphics window.
*/
GraphicsWindow* buildWindow(const SGPropertyNode* winNode);
GraphicsWindow* buildWindow(const SGPropertyNode* winNode, bool isMainWindow=false);
/** Get a window whose properties come from FlightGear's
* command line arguments and their defaults. The window is opened
* if it has not been already.
@ -74,7 +74,7 @@ protected:
bool usingQtGraphicsWindow = false;
static osg::ref_ptr<WindowBuilder> windowBuilder;
static const std::string defaultWindowName;
static std::string defaultWindowName;
static bool poseAsStandaloneApp;
};