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