diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 68b605e5d..0fcf70052 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -3,7 +3,6 @@ add_library(gui SHARED showhidebar.cpp - foreignwindows.h dockwidget.cpp labelandicon.cpp altitudeedit.cpp @@ -794,7 +793,6 @@ add_library(gui SHARED elidedpushbutton.h enableforframelesswindow.cpp overlaymessages.cpp - foreignwindows.cpp stylesheetutility.cpp dropbase.h eventfilter.cpp diff --git a/src/gui/enableforframelesswindow.cpp b/src/gui/enableforframelesswindow.cpp index 4865f0180..235b8e87c 100644 --- a/src/gui/enableforframelesswindow.cpp +++ b/src/gui/enableforframelesswindow.cpp @@ -21,7 +21,6 @@ #include #include -#include "gui/foreignwindows.h" #include "gui/guiutility.h" #include "misc/icons.h" #include "misc/stringutils.h" diff --git a/src/gui/foreignwindows.cpp b/src/gui/foreignwindows.cpp deleted file mode 100644 index fc5bd3de4..000000000 --- a/src/gui/foreignwindows.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "gui/foreignwindows.h" - -#include -#include -#include - -#include "gui/windowfinder.h" - -using namespace swift::misc::simulation; - -namespace swift::gui -{ - QScopedPointer CForeignWindows::m_windowFinder(IWindowFinder::create()); - - QWindow *CForeignWindows::getFS9Window() - { - if (!m_windowFinder) { return nullptr; } - QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN"); - return simulatorWindow; - } - - QWindow *CForeignWindows::getFSXWindow() - { - if (!m_windowFinder) { return nullptr; } - QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN"); - return simulatorWindow; - } - - QWindow *CForeignWindows::getP3DWindow() - { - if (!m_windowFinder) { return nullptr; } - QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN"); - return simulatorWindow; - } - - QWindow *CForeignWindows::getXPlaneWindow() - { - QWindow *simulatorWindow = nullptr; - - // FIXME: - // Use datarefs Sim/operation/windows/system window via xswiftbus 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/MacOS. - if (!m_windowFinder.isNull()) simulatorWindow = m_windowFinder->findForeignWindow("X-System", ""); - return simulatorWindow; - } - - QWindow *CForeignWindows::getFirstFoundSimulatorWindow() - { - QWindow *w = CForeignWindows::getP3DWindow(); - if (w) { return w; } - w = CForeignWindows::getXPlaneWindow(); - if (w) { return w; } - w = CForeignWindows::getFSXWindow(); - if (w) { return w; } - w = CForeignWindows::getFS9Window(); - return w; - } - - QWindow *CForeignWindows::getSimulatorWindow(const CSimulatorInfo &simulator) - { - switch (simulator.getSimulator()) - { - case CSimulatorInfo::FS9: return CForeignWindows::getFS9Window(); - case CSimulatorInfo::FSX: return CForeignWindows::getFSXWindow(); - case CSimulatorInfo::P3D: return CForeignWindows::getP3DWindow(); - case CSimulatorInfo::XPLANE: return CForeignWindows::getXPlaneWindow(); - default: break; - } - return nullptr; - } - - bool CForeignWindows::setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child) - { - if (!simulatorWindow) { return false; } - if (!child) { return false; } - - // If visible, hide it during the reparent. Otherwise setting the parent will have no effect. - const bool isVisible = child->isVisible(); - if (isVisible) { child->hide(); } - - QWindow *childWindow = child->windowHandle(); - Q_ASSERT_X( - childWindow, Q_FUNC_INFO, - "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(); } - return true; - } - - bool CForeignWindows::unsetSimulatorAsParent(QWidget *child) - { - if (!child) { return false; } - if (!child->windowHandle()) { return false; } - if (!child->windowHandle()->transientParent()) { return false; } - child->windowHandle()->setTransientParent(nullptr); - return true; - } -} // namespace swift::gui diff --git a/src/gui/foreignwindows.h b/src/gui/foreignwindows.h deleted file mode 100644 index 1b135f6c1..000000000 --- a/src/gui/foreignwindows.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef SWIFT_GUI_FOREIGNWINDOWS_H -#define SWIFT_GUI_FOREIGNWINDOWS_H - -#include - -#include "gui/swiftguiexport.h" -#include "misc/simulation/simulatorinfo.h" - -class QWidget; -class QWindow; - -namespace swift::gui -{ - class IWindowFinder; - - //! Foreign windows - class SWIFT_GUI_EXPORT CForeignWindows - { - public: - //! FS9 window - static QWindow *getFS9Window(); - - //! FSX window - static QWindow *getFSXWindow(); - - //! P3D window - static QWindow *getP3DWindow(); - - //! X-Plane window - static QWindow *getXPlaneWindow(); - - //! First simulator window found - static QWindow *getFirstFoundSimulatorWindow(); - - //! Simulator window - static QWindow *getSimulatorWindow(const swift::misc::simulation::CSimulatorInfo &simulator); - - //! Set simulator as transient parent for child widget - static bool setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child); - - //! Unset the parent - static bool unsetSimulatorAsParent(QWidget *child); - - private: - //! Constructor, use static methods only - CForeignWindows() {} - - static QScopedPointer m_windowFinder; - }; -} // namespace swift::gui - -#endif // SWIFT_GUI_FOREIGNWINDOWS_H diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index 12e23267d..bdb25c392 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -240,12 +240,6 @@ class SwiftGuiStd : //! Menu item clicked void onMenuClicked(); - //! Attach the simulator window - void attachSimulatorWindow(); - - //! Detach simulator window - void detachSimulatorWindow(); - //! Kicked from network void onKickedFromNetwork(const QString &kickMessage); diff --git a/src/swiftguistandard/swiftguistdmenus.cpp b/src/swiftguistandard/swiftguistdmenus.cpp index ea6cdccca..623a7eb73 100644 --- a/src/swiftguistandard/swiftguistdmenus.cpp +++ b/src/swiftguistandard/swiftguistdmenus.cpp @@ -18,7 +18,6 @@ #include "gui/components/maininfoareacomponent.h" #include "gui/components/settingscomponent.h" #include "gui/copyxswiftbusdialog.h" -#include "gui/foreignwindows.h" #include "gui/guiactionbind.h" #include "gui/guiapplication.h" #include "misc/aviation/altitude.h" @@ -86,26 +85,6 @@ void SwiftGuiStd::onMenuClicked() } } -void SwiftGuiStd::attachSimulatorWindow() -{ - this->activateWindow(); // attaching requires active window - QWindow *w = CForeignWindows::getFirstFoundSimulatorWindow(); - if (!w) - { - CLogMessage(this).warning(u"No simulator window found"); - return; - } - const bool a = CForeignWindows::setSimulatorAsParent(w, this); - if (a) { CLogMessage(this).info(u"Attached to simulator"); } - else { CLogMessage(this).warning(u"No simulator window found"); } -} - -void SwiftGuiStd::detachSimulatorWindow() -{ - if (CForeignWindows::unsetSimulatorAsParent(this)) { CLogMessage(this).info(u"Detached simulator window"); } - else { CLogMessage(this).info(u"No simulator window to detach"); } -} - void SwiftGuiStd::initMenus() { Q_ASSERT_X(ui->menu_InfoAreas, Q_FUNC_INFO, "No menu"); @@ -114,13 +93,6 @@ void SwiftGuiStd::initMenus() sGui->addMenuFile(*ui->menu_File); sGui->addMenuInternals(*ui->menu_Internals); sGui->addMenuWindow(*ui->menu_Window); - ui->menu_Window->addSeparator(); - QAction *a = ui->menu_Window->addAction("Attach simulator window"); - bool c = connect(a, &QAction::triggered, this, &SwiftGuiStd::attachSimulatorWindow); - Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed"); - a = ui->menu_Window->addAction("Detach simulator window"); - c = connect(a, &QAction::triggered, this, &SwiftGuiStd::detachSimulatorWindow); - Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed"); sGui->addMenuHelp(*ui->menu_Help); ui->menu_InfoAreas->addActions(ui->comp_MainInfoArea->getInfoAreaSelectActions(true, ui->menu_InfoAreas)); @@ -130,7 +102,7 @@ void SwiftGuiStd::initMenus() QAction *act = new QAction(CIcons::swift16(), "Copy xswiftbus dialog"); ui->menu_File->insertAction(ui->menu_File->actions().at(5), act); // clang-format off - c = connect(act, &QAction::triggered, this, + bool c = connect(act, &QAction::triggered, this, [=] { this->copyXSwiftBusDialog(false); }, Qt::QueuedConnection); // clang-format on Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed");