Commit 82cf6f3c authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

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


(cherry picked from commit 7b3ae310)
parent 761cea04
Pipeline #235623 passed with stage
in 17 minutes and 3 seconds
......@@ -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,
......
......@@ -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;
}
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment