wip
This commit is contained in:
parent
b9238440e0
commit
3ffc5417ed
|
@ -134,7 +134,7 @@ struct FRAMELESSHELPER_CORE_API FramelessData
|
|||
{
|
||||
QObject *window = nullptr;
|
||||
WId windowId = 0;
|
||||
QObject *winIdUpdater = nullptr;
|
||||
QObject *eventFilter = nullptr;
|
||||
bool frameless = false;
|
||||
FramelessCallbacksPtr callbacks = nullptr;
|
||||
FramelessExtraDataHash extraData = {};
|
||||
|
|
|
@ -125,7 +125,6 @@ namespace Utils
|
|||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool bringWindowToFront(const WId windowId);
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API QPoint getWindowPlacementOffset(const WId windowId);
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API QRect getWindowRestoreGeometry(const WId windowId);
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool removeMicaWindow(const WId windowId);
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API quint64 getKeyState();
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isValidWindow(const WId windowId, const bool checkVisible, const bool checkTopLevel);
|
||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool updateFramebufferTransparency(const WId windowId);
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include <QtCore/qloggingcategory.h>
|
||||
#include <QtGui/qfontdatabase.h>
|
||||
#include <QtGui/qwindow.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
# include <QtGui/qguiapplication.h>
|
||||
# include <QtGui/qstylehints.h>
|
||||
|
@ -105,63 +106,55 @@ Q_GLOBAL_STATIC(InternalData, g_internalData)
|
|||
}
|
||||
#endif
|
||||
|
||||
class WinIdUpdater : public QObject
|
||||
class InternalEventFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(WinIdUpdater)
|
||||
Q_PROPERTY(QObject* window READ window WRITE setWindow NOTIFY windowChanged FINAL)
|
||||
Q_DISABLE_COPY_MOVE(InternalEventFilter)
|
||||
|
||||
public:
|
||||
explicit WinIdUpdater(QObject *parent = nullptr);
|
||||
~WinIdUpdater() override;
|
||||
|
||||
Q_NODISCARD QObject *window() const;
|
||||
void setWindow(QObject *window);
|
||||
|
||||
Q_SIGNALS:
|
||||
void windowChanged();
|
||||
explicit InternalEventFilter(const QObject *window, QObject *parent = nullptr);
|
||||
~InternalEventFilter() override;
|
||||
|
||||
protected:
|
||||
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
private:
|
||||
QObject *m_window = nullptr;
|
||||
const QObject *m_window = nullptr;
|
||||
};
|
||||
|
||||
WinIdUpdater::WinIdUpdater(QObject *parent) : QObject(parent)
|
||||
InternalEventFilter::InternalEventFilter(const QObject *window, QObject *parent) : QObject(parent), m_window(window)
|
||||
{
|
||||
Q_ASSERT(m_window);
|
||||
Q_ASSERT(m_window->isWidgetType() || m_window->isWindowType());
|
||||
}
|
||||
|
||||
WinIdUpdater::~WinIdUpdater() = default;
|
||||
InternalEventFilter::~InternalEventFilter() = default;
|
||||
|
||||
QObject *WinIdUpdater::window() const
|
||||
bool InternalEventFilter::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
void WinIdUpdater::setWindow(QObject *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
Q_ASSERT(window->isWidgetType() || window->isWindowType());
|
||||
if (!window || !(window->isWidgetType() || window->isWindowType()) || (m_window == window)) {
|
||||
return;
|
||||
if (!object || !m_window || (object != m_window)) {
|
||||
return false;
|
||||
}
|
||||
m_window = window;
|
||||
Q_EMIT windowChanged();
|
||||
}
|
||||
|
||||
bool WinIdUpdater::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if (m_window && object && (object == m_window) && (event->type() == QEvent::WinIdChange)) {
|
||||
if (const FramelessDataPtr data = FramelessManagerPrivate::getData(m_window)) {
|
||||
if (data->frameless && data->callbacks) {
|
||||
const FramelessDataPtr data = FramelessManagerPrivate::getData(m_window);
|
||||
if (!data || !data->frameless || !data->callbacks) {
|
||||
return false;
|
||||
}
|
||||
switch (event->type()) {
|
||||
case QEvent::WinIdChange: {
|
||||
const WId windowId = data->callbacks->getWindowId();
|
||||
Q_ASSERT(windowId);
|
||||
if (windowId) {
|
||||
FramelessManagerPrivate::updateWindowId(m_window, windowId);
|
||||
}
|
||||
} break;
|
||||
case QEvent::Close: {
|
||||
const auto ce = static_cast<QCloseEvent *>(event);
|
||||
if (ce->isAccepted()) {
|
||||
std::ignore = FramelessManager::instance()->removeWindow(m_window);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -324,10 +317,8 @@ FramelessDataPtr FramelessManagerPrivate::createData(const QObject *window, cons
|
|||
FramelessDataPtr data = FramelessData::create();
|
||||
data->window = win;
|
||||
data->windowId = windowId;
|
||||
const auto winIdUpdater = new WinIdUpdater(data->window);
|
||||
winIdUpdater->setWindow(data->window);
|
||||
data->window->installEventFilter(winIdUpdater);
|
||||
data->winIdUpdater = winIdUpdater;
|
||||
data->eventFilter = new InternalEventFilter(data->window, data->window);
|
||||
data->window->installEventFilter(data->eventFilter);
|
||||
it = g_internalData()->dataMap.insert(win, data);
|
||||
g_internalData()->windowMap.insert(windowId, win);
|
||||
}
|
||||
|
@ -508,11 +499,9 @@ bool FramelessManager::addWindow(const QObject *window, const WId windowId)
|
|||
g_internalData()->dataMap.insert(data->window, data);
|
||||
g_internalData()->windowMap.insert(windowId, data->window);
|
||||
}
|
||||
if (!data->winIdUpdater) {
|
||||
const auto winIdUpdater = new WinIdUpdater(data->window);
|
||||
winIdUpdater->setWindow(data->window);
|
||||
data->window->installEventFilter(winIdUpdater);
|
||||
data->winIdUpdater = winIdUpdater;
|
||||
if (!data->eventFilter) {
|
||||
data->eventFilter = new InternalEventFilter(data->window, data->window);
|
||||
data->window->installEventFilter(data->eventFilter);
|
||||
}
|
||||
#if FRAMELESSHELPER_CONFIG(native_impl)
|
||||
# ifdef Q_OS_WINDOWS
|
||||
|
@ -525,7 +514,6 @@ bool FramelessManager::addWindow(const QObject *window, const WId windowId)
|
|||
#else
|
||||
FramelessHelperQt::addWindow(window);
|
||||
#endif
|
||||
connect(window, &QObject::destroyed, FramelessManager::instance(), [this, window](){ std::ignore = removeWindow(window); });
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -546,16 +534,15 @@ bool FramelessManager::removeWindow(const QObject *window)
|
|||
if (!data || !data->window || !data->windowId) {
|
||||
return false;
|
||||
}
|
||||
if (data->winIdUpdater) {
|
||||
data->window->removeEventFilter(data->winIdUpdater);
|
||||
data->winIdUpdater->deleteLater();
|
||||
data->winIdUpdater = nullptr;
|
||||
if (data->eventFilter) {
|
||||
data->window->removeEventFilter(data->eventFilter);
|
||||
delete data->eventFilter;
|
||||
data->eventFilter = nullptr;
|
||||
}
|
||||
#if FRAMELESSHELPER_CONFIG(native_impl)
|
||||
# ifdef Q_OS_WINDOWS
|
||||
FramelessHelperWin::removeWindow(window);
|
||||
std::ignore = Utils::uninstallWindowProcHook(data->windowId);
|
||||
std::ignore = Utils::removeMicaWindow(data->windowId);
|
||||
# elif (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID))
|
||||
# elif defined(Q_OS_MACOS)
|
||||
# else
|
||||
|
|
|
@ -218,12 +218,10 @@ bool Utils::moveWindowToDesktopCenter(const WId windowId, const bool considerTas
|
|||
return false;
|
||||
}
|
||||
const QObject *window = FramelessManagerPrivate::getWindow(windowId);
|
||||
Q_ASSERT(window);
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
const FramelessDataPtr data = FramelessManagerPrivate::getData(window);
|
||||
Q_ASSERT(data);
|
||||
if (!data || !data->callbacks) {
|
||||
return false;
|
||||
}
|
||||
|
@ -587,7 +585,7 @@ quint32 Utils::defaultScreenDpi()
|
|||
QColor Utils::getAccentColor()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0))
|
||||
return QGuiApplication::palette().color(QPalette::AccentColor);
|
||||
return QGuiApplication::palette().color(QPalette::Accent);
|
||||
#else // (QT_VERSION < QT_VERSION_CHECK(6, 6, 0))
|
||||
# ifdef Q_OS_WINDOWS
|
||||
return getAccentColor_windows();
|
||||
|
|
|
@ -3049,29 +3049,6 @@ QRect Utils::getWindowRestoreGeometry(const WId windowId)
|
|||
return rect2qrect(wp.rcNormalPosition).translated(getWindowPlacementOffset(windowId));
|
||||
}
|
||||
|
||||
bool Utils::removeMicaWindow(const WId windowId)
|
||||
{
|
||||
Q_ASSERT(windowId);
|
||||
if (!windowId) {
|
||||
return false;
|
||||
}
|
||||
const QObject *window = FramelessManagerPrivate::getWindow(windowId);
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
const FramelessDataPtr data = FramelessManagerPrivate::getData(window);
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
const UtilsWinExtraDataPtr extraData = tryGetExtraData(data, false);
|
||||
Q_ASSERT(extraData);
|
||||
if (!extraData || !extraData->mica) {
|
||||
return false;
|
||||
}
|
||||
extraData->mica = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
quint64 Utils::getKeyState()
|
||||
{
|
||||
quint64 result = 0;
|
||||
|
|
Loading…
Reference in New Issue