From 7b3ae310e6d354b449d0bc198169912134069110 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 22 Sep 2022 13:34:20 +0300 Subject: [PATCH] Emit clientMaximizedStateAboutToChange when maximized mode is actually about to change Window rules code can call maximize(requestedMaximizeMode()), in which case the Window will emit clientMaximizedStateAboutToChange but the maximize mode may not actually change. This change moves the emission of of the clientMaximizedStateAboutToChange signal to Window::changeMaximize(). The reason for doing so is that window rules have the final decision what the maximize mode will be. CCBUG: 459301 --- src/window.cpp | 2 -- src/x11window.cpp | 22 +++++++++++++--------- src/xdgshellwindow.cpp | 12 ++++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index 29612c8883..cb1f770522 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1587,8 +1587,6 @@ void Window::maximize(MaximizeMode m) void Window::setMaximize(bool vertically, bool horizontally) { - // changeMaximize() flips the state, so change from set->flip - Q_EMIT clientMaximizedStateAboutToChange(this, MaximizeMode((vertically ? MaximizeVertical : 0) | (horizontally ? MaximizeHorizontal : 0))); const MaximizeMode oldMode = requestedMaximizeMode(); changeMaximize( oldMode & MaximizeHorizontal ? !horizontally : horizontally, diff --git a/src/x11window.cpp b/src/x11window.cpp index f7b71d56c0..9cd83073a4 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -4307,39 +4307,43 @@ void X11Window::changeMaximize(bool horizontal, bool vertical, bool adjust) MaximizeMode old_mode = max_mode; // 'adjust == true' means to update the size only, e.g. after changing workspace size + MaximizeMode mode = max_mode; if (!adjust) { if (vertical) { - max_mode = MaximizeMode(max_mode ^ MaximizeVertical); + mode = MaximizeMode(mode ^ MaximizeVertical); } if (horizontal) { - max_mode = MaximizeMode(max_mode ^ MaximizeHorizontal); + mode = MaximizeMode(mode ^ MaximizeHorizontal); } } // if the client insist on a fix aspect ratio, we check whether the maximizing will get us // out of screen bounds and take that as a "full maximization with aspect check" then if (m_geometryHints.hasAspect() && // fixed aspect - (max_mode == MaximizeVertical || max_mode == MaximizeHorizontal) && // ondimensional maximization + (mode == MaximizeVertical || mode == MaximizeHorizontal) && // ondimensional maximization rules()->checkStrictGeometry(true)) { // obey aspect const QSize minAspect = m_geometryHints.minAspect(); const QSize maxAspect = m_geometryHints.maxAspect(); - if (max_mode == MaximizeVertical || (old_mode & MaximizeVertical)) { + if (mode == MaximizeVertical || (old_mode & MaximizeVertical)) { const double fx = minAspect.width(); // use doubles, because the values can be MAX_INT const double fy = maxAspect.height(); // use doubles, because the values can be MAX_INT if (fx * clientArea.height() / fy > clientArea.width()) { // too big - max_mode = old_mode & MaximizeHorizontal ? MaximizeRestore : MaximizeFull; + mode = old_mode & MaximizeHorizontal ? MaximizeRestore : MaximizeFull; } - } else { // max_mode == MaximizeHorizontal + } else { // mode == MaximizeHorizontal const double fx = maxAspect.width(); const double fy = minAspect.height(); if (fy * clientArea.width() / fx > clientArea.height()) { // too big - max_mode = old_mode & MaximizeVertical ? MaximizeRestore : MaximizeFull; + mode = old_mode & MaximizeVertical ? MaximizeRestore : MaximizeFull; } } } - max_mode = rules()->checkMaximize(max_mode); - if (!adjust && max_mode == old_mode) { + mode = rules()->checkMaximize(mode); + if (max_mode != mode) { + Q_EMIT clientMaximizedStateAboutToChange(this, mode); + max_mode = mode; + } else if (!adjust) { return; } diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index ca98b3350e..899c8ee3cb 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -1658,17 +1658,21 @@ void XdgToplevelWindow::changeMaximize(bool horizontal, bool vertical, bool adju const QRectF oldGeometry = moveResizeGeometry(); // 'adjust == true' means to update the size only, e.g. after changing workspace size + MaximizeMode mode = m_requestedMaximizeMode; if (!adjust) { if (vertical) { - m_requestedMaximizeMode = MaximizeMode(m_requestedMaximizeMode ^ MaximizeVertical); + mode = MaximizeMode(mode ^ MaximizeVertical); } if (horizontal) { - m_requestedMaximizeMode = MaximizeMode(m_requestedMaximizeMode ^ MaximizeHorizontal); + mode = MaximizeMode(mode ^ MaximizeHorizontal); } } - m_requestedMaximizeMode = rules()->checkMaximize(m_requestedMaximizeMode); - if (!adjust && m_requestedMaximizeMode == oldMode) { + mode = rules()->checkMaximize(mode); + if (m_requestedMaximizeMode != mode) { + Q_EMIT clientMaximizedStateAboutToChange(this, mode); + m_requestedMaximizeMode = mode; + } else if (!adjust) { return; }