diff --git a/win-linux/defaults.pri b/win-linux/defaults.pri index f1dec351c..4e5aa89e7 100644 --- a/win-linux/defaults.pri +++ b/win-linux/defaults.pri @@ -244,7 +244,6 @@ core_windows { # RC_ICONS += ./res/icons/desktop_icons.ico HEADERS += $$PWD/src/windows/platform_win/cwindowplatform.h \ - $$PWD/src/windows/platform_win/csnap.h \ $$PWD/src/windows/platform_win/caption.h \ $$PWD/src/platform_win/singleapplication.h \ $$PWD/src/platform_win/filechooser.h \ @@ -253,7 +252,6 @@ core_windows { $$PWD/src/platform_win/resource.h SOURCES += $$PWD/src/windows/platform_win/cwindowplatform.cpp \ - $$PWD/src/windows/platform_win/csnap.cpp \ $$PWD/src/platform_win/singleapplication.cpp \ $$PWD/src/platform_win/filechooser.cpp \ $$PWD/src/platform_win/printdialog.cpp \ diff --git a/win-linux/res/styles/editor.qss b/win-linux/res/styles/editor.qss index 8acebfda9..2400f595d 100644 --- a/win-linux/res/styles/editor.qss +++ b/win-linux/res/styles/editor.qss @@ -3,17 +3,20 @@ #box-title-tools QLabel {font-family: "Arial", "Helvetica", "Helvetica Neue", sans-serif;} #labelTitle {color: #444; font-weight: normal;} #iconuser {color: %1; background: #d9ffffff; font-size: 10px;} +QPushButton[act=tool][hovered=true], QPushButton[act=tool]:hover {background-color: rgba(0,0,0,20%);} QPushButton#toolButtonClose:hover {background-color: #d42b2b;} QPushButton#toolButtonClose:pressed {background-color: #d75050;} /* pretty */ +#mainPanel[window=pretty] QPushButton[act=tool][unix=false][hovered=true], #mainPanel[window=pretty] QPushButton[act=tool][unix=false]:hover {background-color: rgba(255,255,255,20%);} #mainPanel[window=pretty] QPushButton#toolButtonMinimize {image: url(:/minimize_light.svg);} #mainPanel[window=pretty] QPushButton#toolButtonClose {image: url(:/close_light.svg);} #mainPanel[window=pretty] QPushButton#toolButtonClose[unix=false]:hover {background-color: #d42b2b;} #mainPanel[window=pretty] QPushButton#toolButtonMaximize {image: url(:/restore_light.svg);} #mainPanel[window=pretty] QPushButton#toolButtonMaximize[class=min] {image: url(:/maximize_light.svg);} +#mainPanel[window=pretty] QPushButton#toolButtonMaximize[unix=false][pressed=true] {background-color: rgba(255,255,255,20%);} #mainPanel[window=pretty] #labelTitle {color: #fff; font-size: 12px;} /* dark style */ diff --git a/win-linux/res/styles/styles.qss b/win-linux/res/styles/styles.qss index 2a1b12334..5da6d1210 100644 --- a/win-linux/res/styles/styles.qss +++ b/win-linux/res/styles/styles.qss @@ -5,7 +5,9 @@ QPushButton {/*background-color:#d9d9d9;*/ padding:0 20px; font-weight: normal; height: 22px; font-size: 12px;} QPushButton[act=tool] {/*background-origin: content;*/ border: none; margin: 0; padding: 0; border-radius:0;} +QPushButton[act=tool][hovered=true], QPushButton[act=tool]:hover {background-color:#cecece;} +QPushButton[act=tool][pressed=true], QPushButton[act=tool]:pressed {background-color:#b7b7b7;} QPushButton#toolButtonMaximize, @@ -78,9 +80,11 @@ QPushButton#toolButtonDownload {border-left: 0px; border-right: 1px solid #dfdfd #mainPanel[uitheme=theme-dark] QPushButton#toolButtonMinimize:hover, #mainPanel[uitheme=theme-dark] QPushButton#toolButtonMaximize:hover, +#mainPanel[uitheme=theme-dark] QPushButton#toolButtonMaximize[hovered=true], #mainPanel[uitheme=theme-dark] QPushButton#toolButtonDownload:hover {background-color: #555;} #mainPanel[uitheme=theme-dark] QPushButton#toolButtonMinimize:pressed, #mainPanel[uitheme=theme-dark] QPushButton#toolButtonMaximize:pressed, +#mainPanel[uitheme=theme-dark] QPushButton#toolButtonMaximize[pressed=true], #mainPanel[uitheme=theme-dark] QPushButton#toolButtonDownload:pressed {background-color: #606060;} /* Contrast-Dark*/ @@ -98,6 +102,7 @@ QPushButton#toolButtonDownload {border-left: 0px; border-right: 1px solid #dfdfd #mainPanel[uitheme=theme-contrast-dark] QPushButton#toolButtonMinimize:hover, #mainPanel[uitheme=theme-contrast-dark] QPushButton#toolButtonMaximize:hover, +#mainPanel[uitheme=theme-contrast-dark] QPushButton#toolButtonMaximize[hovered=true], #mainPanel[uitheme=theme-contrast-dark] QPushButton#toolButtonDownload:hover {background-color: #555;} /***********************************/ diff --git a/win-linux/src/windows/cwindowbase.cpp b/win-linux/src/windows/cwindowbase.cpp index b139e5461..5b6e00131 100644 --- a/win-linux/src/windows/cwindowbase.cpp +++ b/win-linux/src/windows/cwindowbase.cpp @@ -37,9 +37,6 @@ #include "defines.h" #ifdef _WIN32 # include "windows/platform_win/caption.h" -# ifndef __OS_WIN_XP -# include "windows/platform_win/csnap.h" -# endif #endif #include #include @@ -181,12 +178,6 @@ QWidget* CWindowBase::createTopPanel(QWidget *parent) m_pTopButtons.push_back(btn); layoutBtns->addWidget(btn); } -#if defined (_WIN32) && !defined (__OS_WIN_XP) - if (Utils::getWinVersion() >= Utils::WinVer::Win11) { - CWin11Snap *snap = new CWin11Snap(m_pTopButtons[BtnType::Btn_Maximize]); - Q_UNUSED(snap) - } -#endif } return _boxTitleBtns; } diff --git a/win-linux/src/windows/platform_win/caption.h b/win-linux/src/windows/platform_win/caption.h index d18a57b1c..75a7da891 100644 --- a/win-linux/src/windows/platform_win/caption.h +++ b/win-linux/src/windows/platform_win/caption.h @@ -36,8 +36,11 @@ #include #include #include +#include +#include #include #include +#include "utils.h" class Caption: public QWidget @@ -45,18 +48,44 @@ class Caption: public QWidget public: Caption(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()): QWidget(parent, f) - {} + { + hwnd_root = ::GetAncestor((HWND)winId(), GA_ROOT); + snapLayoutAllowed = isArrangingAllowed(); + } private: + HWND hwnd_root; + bool snapLayoutAllowed = false; + + bool isArrangingAllowed() { + BOOL arranging = FALSE; + SystemParametersInfoA(SPI_GETWINARRANGING, 0, &arranging, 0); + return (arranging == TRUE); + } + + QPoint cursorPos() { + POINT pt; + ::GetCursorPos(&pt); + return mapFromGlobal(QPoint(pt.x, pt.y)); + } + + QPushButton* buttonAtPos(const QPoint &pos) { + QWidget *child = childAt(pos); + return child ? qobject_cast(child) : nullptr; + } + + QPushButton* buttonMaxUnderMouse() { + QPushButton *btn = buttonAtPos(cursorPos()); + return (btn && btn->objectName() == "toolButtonMaximize") ? btn : nullptr; + } + bool postMsg(DWORD cmd) { POINT pt; ::GetCursorPos(&pt); QPoint pos = mapFromGlobal(QPoint(int(pt.x), int(pt.y))); - QPushButton *pushButton = childAt(pos) ? qobject_cast(childAt(pos)) : nullptr; - if (!pushButton) { - HWND hWnd = ::GetAncestor((HWND)(window()->windowHandle()->winId()), GA_ROOT); + if (!buttonAtPos(pos)) { ::ReleaseCapture(); - ::PostMessage(hWnd, cmd, HTCAPTION, POINTTOPOINTS(pt)); + ::PostMessage(hwnd_root, cmd, HTCAPTION, POINTTOPOINTS(pt)); QCoreApplication::postEvent(parent(), new QEvent(QEvent::MouseButtonPress)); return true; } @@ -83,6 +112,54 @@ private: return true; break; } + case WM_NCLBUTTONDOWN: { + if (Utils::getWinVersion() < Utils::WinVer::Win11) + break; + if (QPushButton *btn = buttonMaxUnderMouse()) { + btn->setProperty("hovered", false); + btn->setProperty("pressed", true); + btn->style()->polish(btn); + btn->repaint(); + } + break; + } + case WM_TIMER: { + QPushButton *btn = buttonMaxUnderMouse(); + if (!btn) { + KillTimer(msg->hwnd, msg->wParam); + if (QPushButton *btn = findChild("toolButtonMaximize")) { + btn->setProperty("hovered", false); + btn->setProperty("pressed", false); + btn->style()->polish(btn); + } + } + break; + } + case WM_NCHITTEST: { + if (Utils::getWinVersion() < Utils::WinVer::Win11 || !snapLayoutAllowed) + break; + *result = 0; + if (QPushButton *btn = buttonMaxUnderMouse()) { + if (!btn->property("hovered").toBool()) { + btn->setProperty("hovered", true); + btn->style()->polish(btn); + SetTimer(msg->hwnd, 1, 200, NULL); + } + *result = HTMAXBUTTON; + } + return (*result != 0); + } + case WM_CAPTURECHANGED: { + if (Utils::getWinVersion() < Utils::WinVer::Win11) + break; + if (QPushButton *btn = buttonMaxUnderMouse()) + btn->click(); + break; + } + case WM_SETTINGCHANGE: { + snapLayoutAllowed = isArrangingAllowed(); + break; + } default: break; } diff --git a/win-linux/src/windows/platform_win/cwindowplatform.cpp b/win-linux/src/windows/platform_win/cwindowplatform.cpp index 3b7f528a1..5dec6f2ec 100644 --- a/win-linux/src/windows/platform_win/cwindowplatform.cpp +++ b/win-linux/src/windows/platform_win/cwindowplatform.cpp @@ -194,11 +194,13 @@ bool CWindowPlatform::nativeEvent(const QByteArray &eventType, void *message, lo { case WM_ACTIVATE: { #ifndef __OS_WIN_XP - MARGINS mrg; - mrg.cxLeftWidth = 4; - mrg.cxRightWidth = 4; - mrg.cyBottomHeight = 4; - mrg.cyTopHeight = 29; + MARGINS mrg = {4, 4, 29, 4}; + if (Utils::getWinVersion() > Utils::WinVer::Win10) { + mrg.cxLeftWidth = 1; + mrg.cxRightWidth = 0; + mrg.cyBottomHeight = 0; + mrg.cyTopHeight = 0; + } DwmExtendFrameIntoClientArea(m_hWnd, &mrg); #endif break; @@ -299,6 +301,10 @@ bool CWindowPlatform::nativeEvent(const QByteArray &eventType, void *message, lo } case WM_SETTINGCHANGE: { + if (msg->wParam == SPI_SETWINARRANGING) { + if (Utils::getWinVersion() > Utils::WinVer::Win10 && m_boxTitleBtns) + SendMessage((HWND)m_boxTitleBtns->winId(), WM_SETTINGCHANGE, 0, 0); + } else if (msg->wParam == SPI_SETWORKAREA) { static RECT oldWorkArea = {0,0,0,0}; RECT workArea; // Taskbar show/hide detection