From adc25f5f3d1798234a6c953ab8098650e6dda806 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 26 Aug 2014 22:51:07 +0200 Subject: [PATCH] refs #76 CForeignWindows Provides static methods to get QWindow pointers to known simulators --- src/blackgui/foreignwindows.cpp | 66 +++++++++++++++++++++++++++++++++ src/blackgui/foreignwindows.h | 50 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 src/blackgui/foreignwindows.cpp create mode 100644 src/blackgui/foreignwindows.h diff --git a/src/blackgui/foreignwindows.cpp b/src/blackgui/foreignwindows.cpp new file mode 100644 index 000000000..1f1f4f90c --- /dev/null +++ b/src/blackgui/foreignwindows.cpp @@ -0,0 +1,66 @@ +/* Copyright (C) 2014 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "foreignwindows.h" +#include +#include +#include + +namespace BlackGui +{ + QScopedPointer CForeignWindows::m_windowFinder(IWindowFinder::create()); + + QWindow *CForeignWindows::getFS9Window() + { + QWindow *simulatorWindow = nullptr; + simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN"); + + return simulatorWindow; + } + + QWindow *CForeignWindows::getFSXWindow() + { + QWindow *simulatorWindow = nullptr; + simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN"); + + return simulatorWindow; + } + + QWindow *CForeignWindows::getXPlaneWindow() + { + QWindow *simulatorWindow = nullptr; + // FIXME: + // Use datarefs Sim/operation/windows/system window via xbus to grab the OS's native window handle + // http://www.xsquawkbox.net/xpsdk/mediawiki/sim%252Foperation%252Fwindows%252Fsystem_window + // For the time being, use IWindowFinder. + // The if condition is to prevent a crash on Linux/OSX. + if (!m_windowFinder.isNull()) simulatorWindow = m_windowFinder->findForeignWindow("X-System", ""); + + return simulatorWindow; + } + + void CForeignWindows::setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child) + { + if (!simulatorWindow) return; + if (!child) return; + + bool isVisible = child->isVisible(); + + // If visible, hide it during the reparent. Otherwise setting the parent will have no effect. + if (isVisible) child->hide(); + + QWindow *childWindow = child->windowHandle(); + Q_ASSERT_X(childWindow, "CForeignWindows::setSimulatorAsParent", "Native resources for child widget have not yet been allocated. Did you call QWidget::show() before?"); + + childWindow->setTransientParent(simulatorWindow); + + // If it was visible before, make it visible again + if (isVisible) child->show(); + } +} diff --git a/src/blackgui/foreignwindows.h b/src/blackgui/foreignwindows.h new file mode 100644 index 000000000..3ad6b10fa --- /dev/null +++ b/src/blackgui/foreignwindows.h @@ -0,0 +1,50 @@ +/* Copyright (C) 2014 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_FOREIGNWINDOWS_H +#define BLACKGUI_FOREIGNWINDOWS_H + +#include "blacksim/simulatorinfo.h" +#include "windowfinder.h" +#include +#include +#include + +namespace BlackGui +{ + //! Foreign windows + class CForeignWindows + { + + public: + + //! FS9 window + static QWindow *getFS9Window(); + + //! FSX window + static QWindow *getFSXWindow(); + + //! X-Plane window + static QWindow *getXPlaneWindow(); + + //! Set simulator as transient parent for child widget + static void setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child); + + private: + + //! Constructor, use static methods only + CForeignWindows() {} + + static QScopedPointer m_windowFinder; + }; +} + +#endif // guard