Compare commits

...

1 Commits

Author SHA1 Message Date
Sergio Martins
6b90d912b2 WIP 2020-06-03 20:51:04 +01:00
5 changed files with 64 additions and 4 deletions

View File

@@ -154,6 +154,10 @@ if (NOT WIN32 AND NOT APPLE)
target_link_libraries(kddockwidgets PUBLIC Qt5::X11Extras)
endif()
if (WIN32)
target_link_libraries(kddockwidgets PUBLIC Qt5::GuiPrivate)
endif()
install (TARGETS kddockwidgets kddockwidgets_multisplitter
EXPORT kddockwidgetsTargets
RUNTIME DESTINATION bin

View File

@@ -32,6 +32,14 @@
# include <QtX11Extras/QX11Info>
#endif
#ifdef Q_OS_WIN
# include <QMargins>
# include <QWindow>
# include <QVariant>
# include <qpa/qplatformnativeinterface.h>
# include <Windows.h>
#endif
namespace KDDockWidgets {
inline bool isLeftButtonPressed()
@@ -92,6 +100,33 @@ inline int screenNumberForWidget(const QWidget *w)
return -1;
}
};
inline void extendClientAreaOverTitleBar(QWindow *window)
{
if (!window)
return;
#ifdef Q_OS_WIN
QPlatformWindow *platformWindow = window->handle();
if (!platformWindow)
return;
auto hwnd = HWND(window->winId());
const auto style = GetWindowLongPtr(hwnd, GWL_STYLE);
const auto exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
const RECT arbitraryClientRect = { 0, 0, 800, 800 };
RECT ncRect = arbitraryClientRect;
AdjustWindowRectEx(&ncRect, style, FALSE, exStyle);
const int titleBarHeight = arbitraryClientRect.top - ncRect.top;
const QVariant newMargins = QVariant::fromValue(QMargins(0, -titleBarHeight, 0, 0));
window->setProperty("_q_windowsCustomMargins", newMargins);
QGuiApplication::platformNativeInterface()->setWindowProperty(platformWindow, QStringLiteral("WindowsCustomMargins"), newMargins);
#endif
}
}
Q_DECLARE_METATYPE(QMargins);
#endif

View File

@@ -215,8 +215,8 @@ bool WidgetResizeHandler::handleWindowsNativeEvent(FloatingWindow *w, const QByt
auto msg = static_cast<MSG *>(message);
if (msg->message == WM_NCCALCSIZE) {
*result = 0;
return true;
// Let's use Qt's "WindowCustomMargins" instead, otherwise QWindow won't know
return false;
} else if (msg->message == WM_NCHITTEST) {
if (DragController::instance()->isInClientDrag()) {

View File

@@ -23,7 +23,6 @@
#include "Utils_p.h"
#include "DropArea_p.h"
#include "TitleBar_p.h"
#include <QApplication>
#include <QPainter>
#include <QVBoxLayout>
@@ -60,6 +59,21 @@ bool FloatingWindowWidget::event(QEvent *ev)
return FloatingWindow::event(ev);
}
#ifdef Q_OS_WIN
bool FloatingWindowWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (!KDDockWidgets::usesAeroSnapWithCustomDecos() || eventType != "windows_generic_MSG")
return QWidget::nativeEvent(eventType, message, result);
auto m = static_cast<MSG*>(message);
if (m->message != WM_DPICHANGED)
return QWidget::nativeEvent(eventType, message, result);
KDDockWidgets::extendClientAreaOverTitleBar(windowHandle());
return QWidget::nativeEvent(eventType, message, result);
}
#endif
void FloatingWindowWidget::init()
{
m_vlayout->setSpacing(0);
@@ -69,4 +83,7 @@ void FloatingWindowWidget::init()
if (!KDDockWidgets::usesNativeDraggingAndResizing())
m_vlayout->setContentsMargins(4, 4, 4, 4);
if (KDDockWidgets::usesAeroSnapWithCustomDecos())
KDDockWidgets::extendClientAreaOverTitleBar(windowHandle());
}

View File

@@ -39,6 +39,10 @@ public:
protected:
void paintEvent(QPaintEvent *) override;
bool event(QEvent *ev) override;
#ifdef Q_OS_WIN
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
#endif
private:
void init();
Q_DISABLE_COPY(FloatingWindowWidget)