fix: remove titlebar control buttons for top-level windows to enhance UI consistency

This commit is contained in:
mr. M
2024-12-06 15:30:49 +01:00
parent e7ed402b64
commit 359474e1ca

View File

@@ -1,53 +1,8 @@
diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp
index 00681c216c838efedbbcded9d6b843dbd8b5b0b6..b152037a396f198f926fa33eac82d886f0a8e4a0 100644
index 00681c216c838efedbbcded9d6b843dbd8b5b0b6..830ab9dd21790189b075e8553fbc4156a6a360e7 100644
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -857,6 +857,44 @@ void SetWindowStyles(HWND aWnd, const WindowStyles& aStyles) {
} // namespace mozilla::widget
+const DWORD kTitlebarItemsWindowStyles =
+ WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
+const DWORD kAllBorderStyles =
+ kTitlebarItemsWindowStyles | WS_THICKFRAME | WS_DLGFRAME;
+
+static DWORD WindowStylesRemovedForBorderStyle(BorderStyle aStyle) {
+ if (aStyle == BorderStyle::Default || aStyle == BorderStyle::All) {
+ return 0;
+ }
+ if (aStyle == BorderStyle::None) {
+ return kAllBorderStyles;
+ }
+ DWORD toRemove = 0;
+ if (!(aStyle & BorderStyle::Border)) {
+ toRemove |= WS_BORDER;
+ }
+ if (!(aStyle & BorderStyle::Title)) {
+ toRemove |= WS_DLGFRAME;
+ }
+ if (!(aStyle & (BorderStyle::Menu | BorderStyle::Close))) {
+ // Looks like getting rid of the system menu also does away with the close
+ // box. So, we only get rid of the system menu and the close box if you
+ // want neither. How does the Windows "Dialog" window class get just
+ // closebox and no sysmenu? Who knows.
+ toRemove |= WS_SYSMENU;
+ }
+ if (!(aStyle & BorderStyle::ResizeH)) {
+ toRemove |= WS_THICKFRAME;
+ }
+ if (!(aStyle & BorderStyle::Minimize)) {
+ toRemove |= WS_MINIMIZEBOX;
+ }
+ if (!(aStyle & BorderStyle::Maximize)) {
+ toRemove |= WS_MAXIMIZEBOX;
+ }
+ return toRemove;
+}
+
// Create the proper widget
nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
widget::InitData* aInitData) {
@@ -1078,6 +1116,14 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
@@ -1078,6 +1078,16 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
const DWM_SYSTEMBACKDROP_TYPE tabbedWindow = DWMSBT_TABBEDWINDOW;
DwmSetWindowAttribute(mWnd, DWMWA_SYSTEMBACKDROP_TYPE, &tabbedWindow,
sizeof tabbedWindow);
@@ -56,13 +11,15 @@ index 00681c216c838efedbbcded9d6b843dbd8b5b0b6..b152037a396f198f926fa33eac82d886
+ // Windows creates some sort of control buttons under the titlebar, which is
+ // annoying for us because it wont allow us to have those hiding animations.
+ // Let's just... remove them... and hope for the best.
+ LONG_PTR style = ::GetWindowLongPtr(mWnd, GWL_STYLE);
+ style &= ~WindowStylesRemovedForBorderStyle(mBorderStyle);
+ ::SetWindowLongPtr(mWnd, GWL_STYLE, style);
+ if (mWindowType == WindowType::TopLevel) {
+ LONG_PTR style = ::GetWindowLongPtr(mWnd, GWL_STYLE);
+ style &= ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
+ ::SetWindowLongPtr(mWnd, GWL_STYLE, style);
+ }
}
if (mOpeningAnimationSuppressed) {
@@ -1278,43 +1324,6 @@ static const wchar_t* ChooseWindowClass(WindowType aWindowType) {
@@ -1278,43 +1288,6 @@ static const wchar_t* ChooseWindowClass(WindowType aWindowType) {
*
**************************************************************/