Some interface cleaning#

This commit is contained in:
James Grogan 2022-11-10 17:10:18 +00:00
parent 918c1d3046
commit c10c5412b9
9 changed files with 72 additions and 39 deletions

View file

@ -87,15 +87,15 @@ void GuiApplication::Run()
bool useOpenGl = false; bool useOpenGl = false;
XcbInterface window_interface; XcbInterface window_interface;
window_interface.SetUseOpenGl(useOpenGl); window_interface.SetUseOpenGl(useOpenGl);
window_interface.Initialize(mDesktopManager.get()); window_interface.initialize(mDesktopManager.get());
window_interface.AddWindow(mainWindow, mDesktopManager.get()); window_interface.addWindow(mainWindow, mDesktopManager.get());
window_interface.ShowWindow(mainWindow); window_interface.showWindow(mainWindow);
if (useOpenGl) if (useOpenGl)
{ {
window_interface.CreateOpenGlDrawable(mainWindow); window_interface.CreateOpenGlDrawable(mainWindow);
} }
window_interface.Loop(mDesktopManager.get()); window_interface.loop(mDesktopManager.get());
window_interface.ShutDown(); window_interface.shutDown();
#else #else
mDesktopManager->SetKeyboard(Keyboard::Create()); mDesktopManager->SetKeyboard(Keyboard::Create());

View file

@ -74,6 +74,7 @@ add_library(windows SHARED ${windows_LIB_INCLUDES} ${platform_INCLUDES})
target_include_directories(windows PUBLIC target_include_directories(windows PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/managers" "${CMAKE_CURRENT_SOURCE_DIR}/managers"
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces"
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/x11" "${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/x11"
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/wayland" "${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/wayland"
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/win32" "${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/win32"

View file

@ -0,0 +1,23 @@
#pragma once
class DesktopManager;
namespace mt
{
class Window;
}
class AbstractUIInterface
{
public:
virtual ~AbstractUIInterface() = default;
virtual void initialize(DesktopManager* desktopManager) = 0;
virtual void loop(DesktopManager* desktopManager) = 0;
virtual void shutDown() = 0;
virtual void showWindow(mt::Window* window) = 0;
virtual void addWindow(mt::Window* window, DesktopManager* desktopManager) = 0;
};

View file

@ -32,7 +32,6 @@ void WaylandWindowInterface::registryHandleGlobalEvent(void *data, struct wl_reg
else if (strcmp(interface, wl_seat_interface.name) == 0) else if (strcmp(interface, wl_seat_interface.name) == 0)
{ {
thisClass->setSeat(static_cast<wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, 5))); thisClass->setSeat(static_cast<wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, 5)));
} }
} }
@ -54,7 +53,7 @@ WaylandWindowInterface::~WaylandWindowInterface()
} }
void WaylandWindowInterface::connect() void WaylandWindowInterface::initialize(DesktopManager* desktopManager)
{ {
mDisplay = wl_display_connect(nullptr); mDisplay = wl_display_connect(nullptr);
@ -107,13 +106,13 @@ void WaylandWindowInterface::doXdgPong(uint32_t serial)
xdg_wm_base_pong(mXdgBase, serial); xdg_wm_base_pong(mXdgBase, serial);
} }
void WaylandWindowInterface::addWindow(mt::Window* window) void WaylandWindowInterface::addWindow(mt::Window* window, DesktopManager* desktopManager)
{ {
auto surface = std::make_unique<WaylandSurface>(window); auto surface = std::make_unique<WaylandSurface>(window);
mSurfaces.push_back(std::move(surface)); mSurfaces.push_back(std::move(surface));
} }
void WaylandWindowInterface::mapWindow(mt::Window* window) void WaylandWindowInterface::showWindow(mt::Window* window)
{ {
if (mSurfaces.empty()) if (mSurfaces.empty())
{ {
@ -123,7 +122,7 @@ void WaylandWindowInterface::mapWindow(mt::Window* window)
mSurfaces[0]->initialize(mCompositor, mXdgBase, mBuffer); mSurfaces[0]->initialize(mCompositor, mXdgBase, mBuffer);
} }
void WaylandWindowInterface::disconnect() void WaylandWindowInterface::shutDown()
{ {
if (mDisplay) if (mDisplay)
{ {
@ -131,7 +130,7 @@ void WaylandWindowInterface::disconnect()
} }
} }
void WaylandWindowInterface::run() void WaylandWindowInterface::loop(DesktopManager* desktopManager)
{ {
while (wl_display_dispatch(mDisplay) != -1) while (wl_display_dispatch(mDisplay) != -1)
{ {

View file

@ -2,6 +2,7 @@
#include "Window.h" #include "Window.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "AbstractUiInterface.h"
#include "wayland-client.h" #include "wayland-client.h"
#include "xdg-shell-client-protocol.h" #include "xdg-shell-client-protocol.h"
@ -13,7 +14,7 @@ class WaylandSurface;
class WaylandBuffer; class WaylandBuffer;
class WaylandSeatInterface; class WaylandSeatInterface;
class WaylandWindowInterface class WaylandWindowInterface : public AbstractUIInterface
{ {
public: public:
@ -21,15 +22,15 @@ public:
~WaylandWindowInterface(); ~WaylandWindowInterface();
void connect(); void loop(DesktopManager* desktopManager) override;
void disconnect(); void addWindow(mt::Window* window, DesktopManager* desktopManager) override;
void run(); void showWindow(mt::Window* window) override;
void addWindow(mt::Window* window); void initialize(DesktopManager* desktopManager) override;
void mapWindow(mt::Window* window); void shutDown() override;
private: private:
static void registryHandleGlobalEvent(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); static void registryHandleGlobalEvent(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);

View file

@ -41,7 +41,7 @@ void XcbInterface::SetUseOpenGl(bool use)
mUseOpenGl = use; mUseOpenGl = use;
} }
void XcbInterface::Initialize(DesktopManager* desktopManager) void XcbInterface::initialize(DesktopManager* desktopManager)
{ {
Connect(); Connect();
UpdateScreen(desktopManager); UpdateScreen(desktopManager);
@ -149,7 +149,7 @@ void XcbInterface::MapWindow(mt::Window* window)
mXcbWindowInterface->Map(window, mConnection); mXcbWindowInterface->Map(window, mConnection);
} }
void XcbInterface::ShowWindow(mt::Window* window) void XcbInterface::showWindow(mt::Window* window)
{ {
mXcbWindowInterface->Show(window, mConnection); mXcbWindowInterface->Show(window, mConnection);
} }
@ -162,7 +162,7 @@ uint32_t XcbInterface::GetEventMask()
XCB_EVENT_MASK_EXPOSURE; XCB_EVENT_MASK_EXPOSURE;
} }
void XcbInterface::AddWindow(mt::Window* window, DesktopManager* desktopManager) void XcbInterface::addWindow(mt::Window* window, DesktopManager* desktopManager)
{ {
auto screen = desktopManager->GetDefaultScreen(); auto screen = desktopManager->GetDefaultScreen();
mXcbWindowInterface->Add(window, mConnection, screen, GetEventMask()); mXcbWindowInterface->Add(window, mConnection, screen, GetEventMask());
@ -195,7 +195,7 @@ void XcbInterface::OnExposeEvent(xcb_expose_event_t* event, DesktopManager* desk
} }
} }
void XcbInterface::Loop(DesktopManager* desktopManager) void XcbInterface::loop(DesktopManager* desktopManager)
{ {
if (!mConnection) if (!mConnection)
{ {
@ -264,7 +264,7 @@ void XcbInterface::onEventsDispatched(DesktopManager* desktopManager)
} }
} }
void XcbInterface::ShutDown() void XcbInterface::shutDown()
{ {
if (!mConnection) if (!mConnection)
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Window.h" #include "AbstractUiInterface.h"
#include <memory> #include <memory>
#include <map> #include <map>
@ -19,7 +19,12 @@ struct xcb_connection_t;
struct xcb_expose_event_t; struct xcb_expose_event_t;
struct _XDisplay; struct _XDisplay;
class XcbInterface namespace mt
{
class Window;
}
class XcbInterface : public AbstractUIInterface
{ {
public: public:
XcbInterface(); XcbInterface();
@ -28,15 +33,15 @@ public:
void SetUseOpenGl(bool use); void SetUseOpenGl(bool use);
void Initialize(DesktopManager* desktopManager); void initialize(DesktopManager* desktopManager) override;
void Loop(DesktopManager* desktopManager); void loop(DesktopManager* desktopManager) override;
void ShutDown(); void shutDown() override;
void ShowWindow(mt::Window* window); void showWindow(mt::Window* window) override;
void AddWindow(mt::Window* window, DesktopManager* desktopManager); void addWindow(mt::Window* window, DesktopManager* desktopManager) override;
void CreateOpenGlDrawable(mt::Window* window); void CreateOpenGlDrawable(mt::Window* window);

View file

@ -21,12 +21,12 @@ public:
bool useOpenGl = true; bool useOpenGl = true;
XcbInterface window_interface; XcbInterface window_interface;
window_interface.SetUseOpenGl(true); window_interface.SetUseOpenGl(true);
window_interface.Initialize(desktopManager.get()); window_interface.initialize(desktopManager.get());
window_interface.AddWindow(mainWindow, desktopManager.get()); window_interface.addWindow(mainWindow, desktopManager.get());
window_interface.ShowWindow(mainWindow); window_interface.showWindow(mainWindow);
window_interface.CreateOpenGlDrawable(mainWindow); window_interface.CreateOpenGlDrawable(mainWindow);
window_interface.Loop(desktopManager.get()); window_interface.loop(desktopManager.get());
window_interface.ShutDown(); window_interface.shutDown();
return true; return true;
} }

View file

@ -3,22 +3,26 @@
#include "Window.h" #include "Window.h"
#include "FileLogger.h" #include "FileLogger.h"
#include "DesktopManager.h"
int main() int main()
{ {
FileLogger::GetInstance().Open(); FileLogger::GetInstance().Open();
auto desktop_manager = std::make_unique<DesktopManager>();
WaylandWindowInterface window_interface; WaylandWindowInterface window_interface;
window_interface.connect(); window_interface.initialize(desktop_manager.get());
auto window = mt::Window::Create(); auto window = mt::Window::Create();
window->SetSize(800, 600); window->SetSize(800, 600);
window_interface.addWindow(window.get()); window_interface.addWindow(window.get(), desktop_manager.get());
window_interface.mapWindow(window.get()); window_interface.showWindow(window.get());
window_interface.run(); window_interface.loop(desktop_manager.get());
window_interface.disconnect(); window_interface.shutDown();
return 0; return 0;
} }