From 3cfe15a9c3db0993d8b8fef5d148625840e5a75c Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周二, 05 12月 2023 15:43:39 +0800 Subject: [PATCH] Add host interface --- src/core/corewindowagent.cpp | 35 ++++++++++++++++++++++------------- 1 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/core/corewindowagent.cpp b/src/core/corewindowagent.cpp index a4e4ac4..bea2239 100644 --- a/src/core/corewindowagent.cpp +++ b/src/core/corewindowagent.cpp @@ -1,42 +1,51 @@ #include "corewindowagent.h" #include "corewindowagent_p.h" +#include "qwkcoreglobal_p.h" + #ifdef Q_OS_WINDOWS -# include "handler/win32windowcontext_p.h" +# include "win32windowcontext_p.h" #else -# include "handler/qtwindowcontext_p.h" +# include "qtwindowcontext_p.h" #endif + +Q_LOGGING_CATEGORY(qWindowKitLog, "qwindowkit") namespace QWK { - CoreWindowAgentPrivate::CoreWindowAgentPrivate() { + CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) { } - CoreWindowAgentPrivate::~CoreWindowAgentPrivate() { - } + CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default; void CoreWindowAgentPrivate::init() { } - void CoreWindowAgentPrivate::setup(QWindow *window, WindowItemDelegate *delegate) { + bool CoreWindowAgentPrivate::setup(QObject *host, WindowItemDelegate *delegate) { + auto ctx = #ifdef Q_OS_WINDOWS - m_eventHandler = new Win32WindowContext(window, delegate); + std::make_unique<Win32WindowContext>(host, delegate) #else - m_eventHandler = new QtWindowContext(window, delegate); + std::make_unique<QtWindowContext>(host, window, delegate) #endif + ; + if (!ctx->setup()) { + return false; + } + context = std::move(ctx); + return true; } - CoreWindowAgent::~CoreWindowAgent() { - } + CoreWindowAgent::~CoreWindowAgent() = default; void CoreWindowAgent::showSystemMenu(const QPoint &pos) { Q_D(CoreWindowAgent); - d->m_eventHandler->showSystemMenu(pos); + d->context->showSystemMenu(pos); } void CoreWindowAgent::startSystemMove(const QPoint &pos) { Q_D(CoreWindowAgent); - auto win = d->m_eventHandler->window(); + auto win = d->context->window(); if (!win) { return; } @@ -47,7 +56,7 @@ void CoreWindowAgent::startSystemResize(Qt::Edges edges, const QPoint &pos) { Q_D(CoreWindowAgent); - auto win = d->m_eventHandler->window(); + auto win = d->context->window(); if (!win) { return; } -- Gitblit v1.9.1