diff --git a/main_unix.cpp b/main_unix.cpp index 482b2c0..4136861 100644 --- a/main_unix.cpp +++ b/main_unix.cpp @@ -1,7 +1,20 @@ #include "framelesshelper.h" #include +#include #include +static void moveWindowToDesktopCenter(QWidget *const widget) { + if (widget) { + const QRect sg = widget->screen()->geometry(); + const int sw = sg.width(); + const int sh = sg.height(); + const int ww = widget->width(); + const int wh = widget->height(); + widget->move(qRound(static_cast(sw - ww) / 2.0), + qRound(static_cast(sh - wh) / 2.0)); + } +} + int main(int argc, char *argv[]) { // High DPI scaling is enabled by default from Qt 6 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -27,6 +40,8 @@ int main(int argc, char *argv[]) { QWidget widget; helper.removeWindowFrame(&widget); + widget.resize(800, 600); + moveWindowToDesktopCenter(&widget); widget.show(); return QApplication::exec(); diff --git a/main_windows.cpp b/main_windows.cpp index 8db3f52..26063fa 100644 --- a/main_windows.cpp +++ b/main_windows.cpp @@ -132,16 +132,19 @@ int main(int argc, char *argv[]) { mainLayout->addLayout(tbLayout); mainLayout->addStretch(); widget.setLayout(mainLayout); - WinNativeEventFilter::WINDOWDATA data_widget; - data_widget.ignoreObjects << minimizeButton << maximizeButton - << closeButton; const auto hWnd_widget = reinterpret_cast(widget.winId()); + WinNativeEventFilter::addFramelessWindow(hWnd_widget); + const auto data_widget = WinNativeEventFilter::windowData(hWnd_widget); + if (data_widget) { + data_widget->ignoreObjects << minimizeButton << maximizeButton + << closeButton; + } const int tbh_widget = WinNativeEventFilter::getSystemMetric( hWnd_widget, WinNativeEventFilter::SystemMetric::TitleBarHeight, false); updateQtFrame(widget.windowHandle(), (tbh_widget > 0 ? tbh_widget : m_defaultTitleBarHeight)); widget.resize(800, 600); - WinNativeEventFilter::addFramelessWindow(hWnd_widget, &data_widget, true); + WinNativeEventFilter::moveWindowToDesktopCenter(hWnd_widget); widget.show(); #ifdef QT_QUICK_LIB @@ -151,18 +154,17 @@ int main(int argc, char *argv[]) { const int tbh_qml_sys = WinNativeEventFilter::getSystemMetric( hWnd_qml, WinNativeEventFilter::SystemMetric::TitleBarHeight, false); const int tbh_qml = tbh_qml_sys > 0 ? tbh_qml_sys : m_defaultTitleBarHeight; - updateQtFrame(&view, tbh_qml); view.rootContext()->setContextProperty(QString::fromUtf8("$TitleBarHeight"), tbh_qml); view.setSource(QUrl(QString::fromUtf8("qrc:///qml/main.qml"))); QObject::connect( &view, &MyQuickView::windowSizeChanged, [hWnd_qml](const QSize &size) { - const auto data = WinNativeEventFilter::windowData(hWnd_qml); - if (data) { + const auto data_qml = WinNativeEventFilter::windowData(hWnd_qml); + if (data_qml) { const int tbh_qml = WinNativeEventFilter::getSystemMetric( hWnd_qml, WinNativeEventFilter::SystemMetric::TitleBarHeight, false); - data->draggableAreas = { + data_qml->draggableAreas = { {0, 0, (size.width() - (m_defaultButtonWidth * 3)), tbh_qml}}; } @@ -179,8 +181,10 @@ int main(int argc, char *argv[]) { SLOT(showNormal())); QObject::connect(rootObject, SIGNAL(closeButtonClicked()), &view, SLOT(close())); + WinNativeEventFilter::addFramelessWindow(hWnd_qml); + updateQtFrame(&view, tbh_qml); view.resize(800, 600); - WinNativeEventFilter::addFramelessWindow(hWnd_qml, nullptr, true); + WinNativeEventFilter::moveWindowToDesktopCenter(hWnd_qml); view.show(); #endif diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 1a96036..68efed1 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -1358,15 +1358,12 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, return HTCLIENT; } const bool isTop = (mouse.y <= bh) && isResizePermitted; - const bool isBottom = - (mouse.y >= (wh - bh)) && isResizePermitted; + const bool isBottom = (mouse.y >= (wh - bh)); // Make the border a little wider to let the user easy to resize // on corners. const int factor = (isTop || isBottom) ? 2 : 1; - const bool isLeft = - (mouse.x <= (bw * factor)) && isResizePermitted; - const bool isRight = - (mouse.x >= (ww - (bw * factor))) && isResizePermitted; + const bool isLeft = (mouse.x <= (bw * factor)); + const bool isRight = (mouse.x >= (ww - (bw * factor))); const bool fixedSize = _data->windowData.fixedSize; const auto getBorderValue = [fixedSize](int value) -> int { // HTBORDER: non-resizeable window border.