From 6adc441e6fd026982e92882fe1fdabfeff469789 Mon Sep 17 00:00:00 2001 From: James Grogan Date: Fri, 11 Nov 2022 11:48:42 +0000 Subject: [PATCH] More cleaning --- apps/console-main.cpp | 2 +- apps/sample-gui/CMakeLists.txt | 47 +++++++---- apps/sample-gui/MediaTool.cpp | 54 ++++++++++++ apps/sample-gui/MediaTool.h | 12 +++ .../audio_editor/AudioEditorView.cpp | 0 .../audio_editor/AudioEditorView.h | 0 apps/sample-gui/gui-main.cpp | 12 +-- .../image_editor/ImageEditorView.cpp | 0 .../image_editor/ImageEditorView.h | 0 .../text_editor/PlainTextDocument.cpp | 0 .../text_editor/PlainTextDocument.h | 0 .../text_editor/TextEditorController.cpp | 0 .../text_editor/TextEditorController.h | 0 .../text_editor/TextEditorModel.cpp | 0 .../sample-gui}/text_editor/TextEditorModel.h | 0 .../text_editor/TextEditorView.cpp | 0 .../sample-gui}/text_editor/TextEditorView.h | 0 .../sample-gui}/web_client/WebClientView.cpp | 0 .../sample-gui}/web_client/WebClientView.h | 0 src/client/CMakeLists.txt | 18 +--- src/client/GuiApplication.cpp | 82 ++++++------------- src/client/GuiApplication.h | 33 +++++--- src/console/MainApplication.cpp | 6 +- src/console/MainApplication.h | 5 +- src/ui_elements/desktop_elements/Window.cpp | 10 ++- src/windows/AbstractDesktopApp.h | 5 +- src/windows/managers/DesktopManager.cpp | 19 ++--- src/windows/managers/DesktopManager.h | 12 +-- .../ui_interfaces/AbstractUiInterface.h | 10 +++ .../ui_interfaces/UiInterfaceFactory.cpp | 8 +- .../ui_interfaces/UiInterfaceFactory.h | 2 + .../wayland/WaylandInterface.cpp | 5 +- .../ui_interfaces/wayland/WaylandInterface.h | 5 +- .../ui_interfaces/x11/XcbInterface.cpp | 4 +- src/windows/ui_interfaces/x11/XcbInterface.h | 4 +- test/graphics/TestOpenGlRendering.cpp | 20 ++--- test/windows/TestWaylandWindow.cpp | 19 ++--- 37 files changed, 213 insertions(+), 181 deletions(-) create mode 100644 apps/sample-gui/MediaTool.cpp create mode 100644 apps/sample-gui/MediaTool.h rename {src/client => apps/sample-gui}/audio_editor/AudioEditorView.cpp (100%) rename {src/client => apps/sample-gui}/audio_editor/AudioEditorView.h (100%) rename {src/client => apps/sample-gui}/image_editor/ImageEditorView.cpp (100%) rename {src/client => apps/sample-gui}/image_editor/ImageEditorView.h (100%) rename {src/client => apps/sample-gui}/text_editor/PlainTextDocument.cpp (100%) rename {src/client => apps/sample-gui}/text_editor/PlainTextDocument.h (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorController.cpp (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorController.h (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorModel.cpp (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorModel.h (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorView.cpp (100%) rename {src/client => apps/sample-gui}/text_editor/TextEditorView.h (100%) rename {src/client => apps/sample-gui}/web_client/WebClientView.cpp (100%) rename {src/client => apps/sample-gui}/web_client/WebClientView.h (100%) diff --git a/apps/console-main.cpp b/apps/console-main.cpp index 8679397..d8239db 100644 --- a/apps/console-main.cpp +++ b/apps/console-main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) // Start the main app auto main_app = MainApplication::Create(); - main_app->Initialize(std::move(command_line_args)); + main_app->initialize(std::move(command_line_args)); main_app->Run(); diff --git a/apps/sample-gui/CMakeLists.txt b/apps/sample-gui/CMakeLists.txt index f774b34..f148e10 100644 --- a/apps/sample-gui/CMakeLists.txt +++ b/apps/sample-gui/CMakeLists.txt @@ -1,27 +1,42 @@ +list(APPEND client_HEADERS + MediaTool.h + text_editor/TextEditorView.h + text_editor/TextEditorModel.h + text_editor/TextEditorController.h + text_editor/PlainTextDocument.h + audio_editor/AudioEditorView.h + image_editor/ImageEditorView.h + web_client/WebClientView.h) + + +list(APPEND client_LIB_INCLUDES + text_editor/TextEditorView.cpp + text_editor/TextEditorModel.cpp + text_editor/TextEditorController.cpp + text_editor/PlainTextDocument.cpp + audio_editor/AudioEditorView.cpp + image_editor/ImageEditorView.cpp + web_client/WebClientView.cpp + MediaTool.cpp) if(WIN32) - add_executable(sample_gui_win WIN32 gui-main-win.cpp) - target_include_directories(sample_gui PUBLIC - "${PROJECT_SOURCE_DIR}/src/console" - "${PROJECT_SOURCE_DIR}/src/client" - ) - target_link_libraries(sample_gui_win PUBLIC client windows console core - network database geometry audio web) - set_property(TARGET sample_gui_win PROPERTY FOLDER apps) + add_executable(sample_gui WIN32 gui-main-win.cpp ${client_LIB_INCLUDES}) else() find_package(X11 QUIET) if(X11_FOUND) - add_executable(sample_gui gui-main.cpp) - target_include_directories(sample_gui PUBLIC - "${PROJECT_SOURCE_DIR}/src/console" - "${PROJECT_SOURCE_DIR}/src/client" - ) - target_link_libraries(sample_gui PUBLIC client windows console core - network database geometry audio web) - set_property(TARGET sample_gui PROPERTY FOLDER apps) + add_executable(sample_gui gui-main.cpp ${client_LIB_INCLUDES} ${client_HEADERS}) else() message(STATUS "Skipping sample GUI as no X11 dev support") endif() endif() +target_include_directories(sample_gui PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/text_editor" + "${CMAKE_CURRENT_SOURCE_DIR}/audio_editor" + "${CMAKE_CURRENT_SOURCE_DIR}/image_editor" + "${CMAKE_CURRENT_SOURCE_DIR}/web_client" + ) +target_link_libraries(sample_gui PUBLIC client windows console core network database geometry audio web) +set_property(TARGET sample_gui PROPERTY FOLDER apps) + diff --git a/apps/sample-gui/MediaTool.cpp b/apps/sample-gui/MediaTool.cpp new file mode 100644 index 0000000..45e39a6 --- /dev/null +++ b/apps/sample-gui/MediaTool.cpp @@ -0,0 +1,54 @@ +#include "MediaTool.h" + +#include "TextEditorView.h" +#include "AudioEditorView.h" +#include "ImageEditorView.h" +#include "WebClientView.h" +#include "TabbedPanelWidget.h" +#include "TopBar.h" +#include "StatusBar.h" +#include "HorizontalSpacer.h" + +#include "DesktopManager.h" +#include "MainApplication.h" + +MediaTool::MediaTool(std::unique_ptr args) + : GuiApplication(std::move(args)) +{ + +} + +void MediaTool::initializeViews() +{ + auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); + mainWindow->SetSize(800, 600); + + auto tabbedPanel = TabbedPanelWidget::Create(); + + auto textEditor = TextEditorView::Create(); + auto path = mMainApplication->GetCommandLineArgs()->getLaunchPath(); + path /= "out.txt"; + textEditor->GetController()->SetSavePath(path); + textEditor->GetController()->SetLoadPath(path); + textEditor->Initialize(); + tabbedPanel->AddPanel(std::move(textEditor), "Text Editor"); + + auto audioEditor = AudioEditorView::Create(); + tabbedPanel->AddPanel(std::move(audioEditor), "Audio Editor"); + + auto imageEditor = ImageEditorView::Create(); + tabbedPanel->AddPanel(std::move(imageEditor), "Image Editor"); + + auto webClient = WebClientView::Create(); + tabbedPanel->AddPanel(std::move(webClient), "Web Client"); + + auto topBar = TopBar::Create(); + auto statusBar = StatusBar::Create(); + + auto horizontalSpace = HorizontalSpacer::Create(); + horizontalSpace->AddWidgetWithScale(std::move(topBar), 1); + horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20); + horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1); + + mainWindow->AddWidget(std::move(horizontalSpace)); +} diff --git a/apps/sample-gui/MediaTool.h b/apps/sample-gui/MediaTool.h new file mode 100644 index 0000000..13541d0 --- /dev/null +++ b/apps/sample-gui/MediaTool.h @@ -0,0 +1,12 @@ +#pragma once + +#include "GuiApplication.h" + +class MediaTool : public GuiApplication +{ +public: + MediaTool(std::unique_ptr args); + +protected: + void initializeViews() override; +}; diff --git a/src/client/audio_editor/AudioEditorView.cpp b/apps/sample-gui/audio_editor/AudioEditorView.cpp similarity index 100% rename from src/client/audio_editor/AudioEditorView.cpp rename to apps/sample-gui/audio_editor/AudioEditorView.cpp diff --git a/src/client/audio_editor/AudioEditorView.h b/apps/sample-gui/audio_editor/AudioEditorView.h similarity index 100% rename from src/client/audio_editor/AudioEditorView.h rename to apps/sample-gui/audio_editor/AudioEditorView.h diff --git a/apps/sample-gui/gui-main.cpp b/apps/sample-gui/gui-main.cpp index 0272962..3a2d324 100644 --- a/apps/sample-gui/gui-main.cpp +++ b/apps/sample-gui/gui-main.cpp @@ -1,6 +1,6 @@ #include -#include "GuiApplication.h" +#include "MediaTool.h" #include "MainApplication.h" #include "CommandLineArgs.h" @@ -10,15 +10,9 @@ int main(int argc, char *argv[]) args->process(argc, argv); args->recordLaunchPath(); - // Start the main app - auto main_app = MainApplication::Create(); - main_app->Initialize(std::move(args)); - // Start the gui app - auto gui_app = GuiApplication(); - gui_app.SetMainApplication(main_app); - gui_app.Run(); + auto gui_app = GuiApplication(std::move(args)); + gui_app.run(); - main_app->ShutDown(); return 0; } diff --git a/src/client/image_editor/ImageEditorView.cpp b/apps/sample-gui/image_editor/ImageEditorView.cpp similarity index 100% rename from src/client/image_editor/ImageEditorView.cpp rename to apps/sample-gui/image_editor/ImageEditorView.cpp diff --git a/src/client/image_editor/ImageEditorView.h b/apps/sample-gui/image_editor/ImageEditorView.h similarity index 100% rename from src/client/image_editor/ImageEditorView.h rename to apps/sample-gui/image_editor/ImageEditorView.h diff --git a/src/client/text_editor/PlainTextDocument.cpp b/apps/sample-gui/text_editor/PlainTextDocument.cpp similarity index 100% rename from src/client/text_editor/PlainTextDocument.cpp rename to apps/sample-gui/text_editor/PlainTextDocument.cpp diff --git a/src/client/text_editor/PlainTextDocument.h b/apps/sample-gui/text_editor/PlainTextDocument.h similarity index 100% rename from src/client/text_editor/PlainTextDocument.h rename to apps/sample-gui/text_editor/PlainTextDocument.h diff --git a/src/client/text_editor/TextEditorController.cpp b/apps/sample-gui/text_editor/TextEditorController.cpp similarity index 100% rename from src/client/text_editor/TextEditorController.cpp rename to apps/sample-gui/text_editor/TextEditorController.cpp diff --git a/src/client/text_editor/TextEditorController.h b/apps/sample-gui/text_editor/TextEditorController.h similarity index 100% rename from src/client/text_editor/TextEditorController.h rename to apps/sample-gui/text_editor/TextEditorController.h diff --git a/src/client/text_editor/TextEditorModel.cpp b/apps/sample-gui/text_editor/TextEditorModel.cpp similarity index 100% rename from src/client/text_editor/TextEditorModel.cpp rename to apps/sample-gui/text_editor/TextEditorModel.cpp diff --git a/src/client/text_editor/TextEditorModel.h b/apps/sample-gui/text_editor/TextEditorModel.h similarity index 100% rename from src/client/text_editor/TextEditorModel.h rename to apps/sample-gui/text_editor/TextEditorModel.h diff --git a/src/client/text_editor/TextEditorView.cpp b/apps/sample-gui/text_editor/TextEditorView.cpp similarity index 100% rename from src/client/text_editor/TextEditorView.cpp rename to apps/sample-gui/text_editor/TextEditorView.cpp diff --git a/src/client/text_editor/TextEditorView.h b/apps/sample-gui/text_editor/TextEditorView.h similarity index 100% rename from src/client/text_editor/TextEditorView.h rename to apps/sample-gui/text_editor/TextEditorView.h diff --git a/src/client/web_client/WebClientView.cpp b/apps/sample-gui/web_client/WebClientView.cpp similarity index 100% rename from src/client/web_client/WebClientView.cpp rename to apps/sample-gui/web_client/WebClientView.cpp diff --git a/src/client/web_client/WebClientView.h b/apps/sample-gui/web_client/WebClientView.h similarity index 100% rename from src/client/web_client/WebClientView.h rename to apps/sample-gui/web_client/WebClientView.h diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 6359d9b..0dcf0cf 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -2,27 +2,13 @@ list(APPEND client_HEADERS TopBar.h StatusBar.h GuiApplication.h - TabbedPanelWidget.h - text_editor/TextEditorView.h - text_editor/TextEditorModel.h - text_editor/TextEditorController.h - text_editor/PlainTextDocument.h - audio_editor/AudioEditorView.h - image_editor/ImageEditorView.h - web_client/WebClientView.h) + TabbedPanelWidget.h) list(APPEND client_LIB_INCLUDES TopBar.cpp StatusBar.cpp GuiApplication.cpp - TabbedPanelWidget.cpp - text_editor/TextEditorView.cpp - text_editor/TextEditorModel.cpp - text_editor/TextEditorController.cpp - text_editor/PlainTextDocument.cpp - audio_editor/AudioEditorView.cpp - image_editor/ImageEditorView.cpp - web_client/WebClientView.cpp) + TabbedPanelWidget.cpp) add_library(client SHARED ${client_LIB_INCLUDES} ${client_HEADERS}) diff --git a/src/client/GuiApplication.cpp b/src/client/GuiApplication.cpp index 3b73326..52d3f47 100644 --- a/src/client/GuiApplication.cpp +++ b/src/client/GuiApplication.cpp @@ -1,26 +1,20 @@ #include "GuiApplication.h" -#include "Widget.h" #include "UiInterfaceFactory.h" #include "Window.h" -#include "TextElement.h" #include "WindowManager.h" -#include "TextEditorView.h" -#include "AudioEditorView.h" -#include "ImageEditorView.h" -#include "WebClientView.h" -#include "TabbedPanelWidget.h" -#include "TopBar.h" -#include "StatusBar.h" -#include "HorizontalSpacer.h" +#include "DesktopManager.h" +#include "MainApplication.h" +#include "AbstractUiInterface.h" + #include "FileLogger.h" -GuiApplication::GuiApplication() +GuiApplication::GuiApplication(std::unique_ptr args) : AbstractDesktopApp(), - mMainApplication(), - mDesktopManager(DesktopManager::Create()) + mMainApplication(MainApplication::Create()), + mDesktopManager(DesktopManager::Create(this)) { - + mMainApplication->initialize(args ? std::move(args) : CommandLineArgs::Create()); } GuiApplication::~GuiApplication() @@ -28,61 +22,37 @@ GuiApplication::~GuiApplication() } -void GuiApplication::SetMainApplication(MainApplicationPtr app) +AbstractApp* GuiApplication::getMainApplication() const { - mMainApplication = app; - mDesktopManager->SetMainApp(app); + return mMainApplication.get(); } -void GuiApplication::SetUpWidget() +void GuiApplication::initializeViews() { - auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); - mainWindow->SetSize(800, 600); - auto tabbedPanel = TabbedPanelWidget::Create(); - - auto textEditor = TextEditorView::Create(); - auto path = mMainApplication->GetCommandLineArgs()->getLaunchPath(); - path /= "out.txt"; - textEditor->GetController()->SetSavePath(path); - textEditor->GetController()->SetLoadPath(path); - textEditor->Initialize(); - tabbedPanel->AddPanel(std::move(textEditor), "Text Editor"); - - auto audioEditor = AudioEditorView::Create(); - tabbedPanel->AddPanel(std::move(audioEditor), "Audio Editor"); - - auto imageEditor = ImageEditorView::Create(); - tabbedPanel->AddPanel(std::move(imageEditor), "Image Editor"); - - auto webClient = WebClientView::Create(); - tabbedPanel->AddPanel(std::move(webClient), "Web Client"); - - auto topBar = TopBar::Create(); - auto statusBar = StatusBar::Create(); - - auto horizontalSpace = HorizontalSpacer::Create(); - horizontalSpace->AddWidgetWithScale(std::move(topBar), 1); - horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20); - horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1); - - mainWindow->AddWidget(std::move(horizontalSpace)); } -void GuiApplication::Run() +void GuiApplication::setUiInterfaceBackend(UiInterfaceFactory::Backend backend) +{ + mUiInterfaceBackend = backend; +} + +void GuiApplication::run() { auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow(); - SetUpWidget(); + initializeViews(); MLOG_INFO("Creating Window Interface"); - auto window_interface = UiInterfaceFactory::create(mDesktopManager.get()); + mUiInterface = UiInterfaceFactory::create(mDesktopManager.get(), mUiInterfaceBackend); - window_interface->initialize(); - window_interface->addWindow(mainWindow); - window_interface->showWindow(mainWindow); - window_interface->loop(); + mUiInterface->initialize(); + mUiInterface->addWindow(mainWindow); + mUiInterface->showWindow(mainWindow); + mUiInterface->loop(); - window_interface->shutDown(); + mUiInterface->shutDown(); MLOG_INFO("Window Interface Shut Down"); + + mMainApplication->ShutDown(); } diff --git a/src/client/GuiApplication.h b/src/client/GuiApplication.h index d5eb1db..bd99a3a 100644 --- a/src/client/GuiApplication.h +++ b/src/client/GuiApplication.h @@ -1,28 +1,35 @@ #pragma once -#include "MainApplication.h" #include "AbstractDesktopApp.h" -#include "DesktopManager.h" +#include "UiInterfaceFactory.h" +#include "CommandLineArgs.h" #include +class MainApplication; +class DesktopManager; +class AbstractUiInterface; + class GuiApplication : public AbstractDesktopApp { - -private: - - DesktopManagerUPtr mDesktopManager; - MainApplicationPtr mMainApplication; - public: - - GuiApplication(); + GuiApplication(std::unique_ptr args = nullptr); ~GuiApplication(); - void SetMainApplication(MainApplicationPtr app); + AbstractApp* getMainApplication() const override; - void Run(); + void run(); - void SetUpWidget(); + void setUiInterfaceBackend(UiInterfaceFactory::Backend backend); + +protected: + virtual void initializeViews(); + + std::unique_ptr mDesktopManager; + std::unique_ptr mMainApplication; + +private: + UiInterfaceFactory::Backend mUiInterfaceBackend = UiInterfaceFactory::Backend::UNSET; + std::unique_ptr mUiInterface; }; diff --git a/src/console/MainApplication.cpp b/src/console/MainApplication.cpp index ca2bee2..ca2aa18 100644 --- a/src/console/MainApplication.cpp +++ b/src/console/MainApplication.cpp @@ -28,7 +28,7 @@ MainApplication::~MainApplication() } -void MainApplication::Initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext) +void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext) { if (applicationContext) { @@ -137,7 +137,7 @@ void MainApplication::ShutDown() FileLogger::GetInstance().Close(); } -std::shared_ptr MainApplication::Create() +std::unique_ptr MainApplication::Create() { - return std::make_shared(); + return std::make_unique(); } diff --git a/src/console/MainApplication.h b/src/console/MainApplication.h index 327f527..9045f0b 100644 --- a/src/console/MainApplication.h +++ b/src/console/MainApplication.h @@ -13,12 +13,11 @@ class MainApplication : public AbstractApp { public: - MainApplication(); ~MainApplication(); - void Initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext=nullptr); + void initialize(CommandLineArgsUPtr commandLineArgs, std::unique_ptr applicationContext=nullptr); void Run(); @@ -26,7 +25,7 @@ public: CommandLineArgs* GetCommandLineArgs() const; - static std::shared_ptr Create(); + static std::unique_ptr Create(); private: void RunServer(); diff --git a/src/ui_elements/desktop_elements/Window.cpp b/src/ui_elements/desktop_elements/Window.cpp index 4a32aee..37186f2 100644 --- a/src/ui_elements/desktop_elements/Window.cpp +++ b/src/ui_elements/desktop_elements/Window.cpp @@ -10,9 +10,9 @@ namespace mt { Window::Window() - :mWidth(400), - mHeight(300), - mWidget() + :mWidth(800), + mHeight(600), + mWidget(Widget::Create()) { } @@ -50,6 +50,10 @@ void Window::OnPaint(const PaintEvent* event) void Window::AddWidget(WidgetUPtr widget) { + if (mWidget) + { + mWidget.reset(); + } mWidget = std::move(widget); } diff --git a/src/windows/AbstractDesktopApp.h b/src/windows/AbstractDesktopApp.h index 241d495..9e4f3d1 100644 --- a/src/windows/AbstractDesktopApp.h +++ b/src/windows/AbstractDesktopApp.h @@ -2,12 +2,15 @@ #include +#include "AbstractApp.h" + class AbstractDesktopApp { public: - AbstractDesktopApp() = default; virtual ~AbstractDesktopApp() = default; + + virtual AbstractApp* getMainApplication() const = 0; }; using AbstractDesktopAppPtr = std::shared_ptr; diff --git a/src/windows/managers/DesktopManager.cpp b/src/windows/managers/DesktopManager.cpp index 045f4ef..845dfec 100644 --- a/src/windows/managers/DesktopManager.cpp +++ b/src/windows/managers/DesktopManager.cpp @@ -1,12 +1,14 @@ #include "DesktopManager.h" +#include "AbstractDesktopApp.h" + #include "FileLogger.h" -DesktopManager::DesktopManager() +DesktopManager::DesktopManager(AbstractDesktopApp* application) : mScreens(), mWindowManager(WindowManager::Create()), mKeyboard(Keyboard::Create()), - mMainApplication(), + mUiApplication(application), mModified(false), mEventManager(EventManager::Create()) { @@ -18,9 +20,9 @@ DesktopManager::~DesktopManager() } -std::unique_ptr DesktopManager::Create() +std::unique_ptr DesktopManager::Create(AbstractDesktopApp* application) { - return std::make_unique(); + return std::make_unique(application); } void DesktopManager::ClearEvents() @@ -100,14 +102,9 @@ void DesktopManager::SetKeyboard(KeyboardUPtr keyboard) mKeyboard = std::move(keyboard); } -void DesktopManager::SetMainApp(std::shared_ptr mainApp) +AbstractApp* DesktopManager::getMainApp() const { - mMainApplication = mainApp; -} - -AbstractApp* DesktopManager::GetMainApp() -{ - return mMainApplication.get(); + return mUiApplication->getMainApplication(); } void DesktopManager::AddScreen(ScreenPtr screen) diff --git a/src/windows/managers/DesktopManager.h b/src/windows/managers/DesktopManager.h index e43c817..932955e 100644 --- a/src/windows/managers/DesktopManager.h +++ b/src/windows/managers/DesktopManager.h @@ -13,21 +13,21 @@ #include "AbstractApp.h" #include "EventManager.h" +class AbstractDesktopApp; + class DesktopManager { public: - DesktopManager(); + DesktopManager(AbstractDesktopApp* application); ~DesktopManager(); - static std::unique_ptr Create(); + static std::unique_ptr Create(AbstractDesktopApp* application); void SetWindowManager(WindowManagerUPtr windowManager); - void SetMainApp(std::shared_ptr mainApp); - - AbstractApp* GetMainApp(); + AbstractApp* getMainApp() const; WindowManager* GetWindowManager() const; @@ -58,7 +58,7 @@ private: WindowManagerUPtr mWindowManager; KeyboardUPtr mKeyboard; EventManagerUPtr mEventManager; - std::shared_ptr mMainApplication; + AbstractDesktopApp* mUiApplication; bool mModified; }; diff --git a/src/windows/ui_interfaces/AbstractUiInterface.h b/src/windows/ui_interfaces/AbstractUiInterface.h index f9d7d36..8b27e5b 100644 --- a/src/windows/ui_interfaces/AbstractUiInterface.h +++ b/src/windows/ui_interfaces/AbstractUiInterface.h @@ -5,9 +5,18 @@ namespace mt class Window; } +class DesktopManager; + class AbstractUIInterface { public: + + AbstractUIInterface(DesktopManager* desktopManager, bool useHardware = false) + : mDesktopManager(desktopManager), + mUseHardwareRendering(useHardware) + { + } + virtual ~AbstractUIInterface() = default; virtual void initialize() = 0; @@ -26,5 +35,6 @@ public: } protected: + DesktopManager* mDesktopManager{nullptr}; bool mUseHardwareRendering{false}; }; diff --git a/src/windows/ui_interfaces/UiInterfaceFactory.cpp b/src/windows/ui_interfaces/UiInterfaceFactory.cpp index d0a189a..88479f0 100644 --- a/src/windows/ui_interfaces/UiInterfaceFactory.cpp +++ b/src/windows/ui_interfaces/UiInterfaceFactory.cpp @@ -10,13 +10,15 @@ std::unique_ptr UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend) { #ifdef __linux__ - if (backend == Backend::UNSET || backend == Backend::X11) + if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER) { - return std::make_unique(desktopManager); + const bool use_hardware = (backend != Backend::X11_RASTER); + return std::make_unique(desktopManager, use_hardware); } else { - return std::make_unique(desktopManager); + const bool use_hardware = (backend != Backend::WAYLAND_RASTER); + return std::make_unique(desktopManager, use_hardware); } #else return std::make_unique(); diff --git a/src/windows/ui_interfaces/UiInterfaceFactory.h b/src/windows/ui_interfaces/UiInterfaceFactory.h index 06f8885..4e89839 100644 --- a/src/windows/ui_interfaces/UiInterfaceFactory.h +++ b/src/windows/ui_interfaces/UiInterfaceFactory.h @@ -12,7 +12,9 @@ public: enum class Backend { UNSET, + X11_RASTER, X11, + WAYLAND_RASTER, WAYLAND }; diff --git a/src/windows/ui_interfaces/wayland/WaylandInterface.cpp b/src/windows/ui_interfaces/wayland/WaylandInterface.cpp index 0c8842c..30e97cf 100644 --- a/src/windows/ui_interfaces/wayland/WaylandInterface.cpp +++ b/src/windows/ui_interfaces/wayland/WaylandInterface.cpp @@ -41,9 +41,8 @@ void WaylandInterface::registryHandleGlobalRemoveEvent(void *data, struct wl_reg } - -WaylandInterface::WaylandInterface(DesktopManager* desktopManager) - : mDesktopManager(desktopManager), +WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware) + : AbstractUIInterface(desktopManager, useHardware), mBuffer(std::make_shared()) { mRegistryListener.global = registryHandleGlobalEvent; diff --git a/src/windows/ui_interfaces/wayland/WaylandInterface.h b/src/windows/ui_interfaces/wayland/WaylandInterface.h index 1c7f913..aba7668 100644 --- a/src/windows/ui_interfaces/wayland/WaylandInterface.h +++ b/src/windows/ui_interfaces/wayland/WaylandInterface.h @@ -14,13 +14,12 @@ class WaylandSurface; class WaylandBuffer; class WaylandSeatInterface; class WaylandEglInterface; -class DesktopManager; class WaylandInterface : public AbstractUIInterface { public: - WaylandInterface(DesktopManager* desktopManager); + WaylandInterface(DesktopManager* desktopManager, bool useHardware = true); ~WaylandInterface(); @@ -48,8 +47,6 @@ private: void setXdgBase(xdg_wm_base* xdg_base); - DesktopManager* mDesktopManager{nullptr}; - wl_display* mDisplay{nullptr}; wl_compositor* mCompositor{nullptr}; wl_registry_listener mRegistryListener; diff --git a/src/windows/ui_interfaces/x11/XcbInterface.cpp b/src/windows/ui_interfaces/x11/XcbInterface.cpp index f4e665b..1734008 100644 --- a/src/windows/ui_interfaces/x11/XcbInterface.cpp +++ b/src/windows/ui_interfaces/x11/XcbInterface.cpp @@ -20,8 +20,8 @@ #include "FileLogger.h" -XcbInterface::XcbInterface(DesktopManager* desktopManager) - : mDesktopManager(desktopManager), +XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware) + : AbstractUIInterface(desktopManager, useHardware), mConnection(nullptr), mX11Display(), mGlxInterface(), diff --git a/src/windows/ui_interfaces/x11/XcbInterface.h b/src/windows/ui_interfaces/x11/XcbInterface.h index c379a61..a4e1294 100644 --- a/src/windows/ui_interfaces/x11/XcbInterface.h +++ b/src/windows/ui_interfaces/x11/XcbInterface.h @@ -4,7 +4,6 @@ #include -class DesktopManager; class GlxInterface; using GlxInterfacePtr = std::unique_ptr; @@ -26,7 +25,7 @@ namespace mt class XcbInterface : public AbstractUIInterface { public: - XcbInterface(DesktopManager* desktopManager); + XcbInterface(DesktopManager* desktopManager, bool useHardware = true); ~XcbInterface(); @@ -57,7 +56,6 @@ private: uint32_t getEventMask(); private: - DesktopManager* mDesktopManager{nullptr}; xcb_connection_t* mConnection; _XDisplay* mX11Display; GlxInterfacePtr mGlxInterface; diff --git a/test/graphics/TestOpenGlRendering.cpp b/test/graphics/TestOpenGlRendering.cpp index c10bb2c..f6f8cab 100644 --- a/test/graphics/TestOpenGlRendering.cpp +++ b/test/graphics/TestOpenGlRendering.cpp @@ -1,9 +1,8 @@ -#include "DesktopManager.h" -#include "XcbInterface.h" - #include "TestCase.h" #include "TestCaseRunner.h" +#include "GuiApplication.h" + #include #include #include @@ -13,18 +12,11 @@ class TestOpenGlRendering : public TestCase public: bool Run() override { - auto desktopManager = DesktopManager::Create(); + auto app = std::make_unique(); - auto mainWindow = desktopManager->GetWindowManager()->GetMainWindow(); - mainWindow->SetSize(800, 600); - - XcbInterface window_interface(desktopManager.get()); - window_interface.setUseHardwareRendering(true); - window_interface.initialize(); - window_interface.addWindow(mainWindow); - window_interface.showWindow(mainWindow); - window_interface.loop(); - window_interface.shutDown(); + //app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11); + app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER); + app->run(); return true; } diff --git a/test/windows/TestWaylandWindow.cpp b/test/windows/TestWaylandWindow.cpp index 2d9aaf9..ddc3a35 100644 --- a/test/windows/TestWaylandWindow.cpp +++ b/test/windows/TestWaylandWindow.cpp @@ -3,27 +3,18 @@ #include "Window.h" #include "FileLogger.h" -#include "DesktopManager.h" +#include "GuiApplication.h" int main() { FileLogger::GetInstance().Open(); - auto desktop_manager = DesktopManager::Create(); + auto app = std::make_unique(); - auto window = desktop_manager->GetWindowManager()->GetMainWindow(); - window->SetSize(800, 600); + //app->setUiInterfaceBackend(UiInterfaceFactory::Backend::WAYLAND); + app->setUiInterfaceBackend(UiInterfaceFactory::Backend::WAYLAND_RASTER); - WaylandInterface window_interface(desktop_manager.get()); - window_interface.setUseHardwareRendering(true); - window_interface.initialize(); + app->run(); - window_interface.addWindow(window); - - window_interface.showWindow(window); - - window_interface.loop(); - - window_interface.shutDown(); return 0; }