From eacaf25acfa5a285a51413bc35a4011e74b22b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 13 Oct 2015 10:22:18 +0200 Subject: [PATCH] Improve sharing of maximize between Client and ShellClient The changeMaximize method is added as a pure virtual protected method to AbstractClient. This replaces the previous pure virtual maximize method. Which is now directly implemented in AbstractClient (reusing the implementation previously in Client). --- abstract_client.h | 4 +++- client.h | 4 +--- geometry.cpp | 15 ++++++++------- shell_client.cpp | 22 ++++++++++------------ shell_client.h | 2 +- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/abstract_client.h b/abstract_client.h index 688a5092d0..f99fe9f122 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -303,7 +303,8 @@ public: virtual bool isCurrentTab() const; virtual QRect geometryRestore() const = 0; virtual MaximizeMode maximizeMode() const = 0; - virtual void maximize(MaximizeMode) = 0; + void maximize(MaximizeMode); + void setMaximize(bool vertically, bool horizontally); virtual bool noBorder() const = 0; virtual void setNoBorder(bool set) = 0; virtual void blockActivityUpdates(bool b = true) = 0; @@ -550,6 +551,7 @@ protected: virtual int borderRight() const; virtual int borderTop() const; virtual int borderBottom() const; + virtual void changeMaximize(bool horizontal, bool vertical, bool adjust) = 0; private: void handlePaletteChange(); diff --git a/client.h b/client.h index d1880cb776..c6d4b5ec08 100644 --- a/client.h +++ b/client.h @@ -234,7 +234,6 @@ public: QuickTileMode quickTileMode() const override; bool isMinimizable() const override; - void setMaximize(bool vertically, bool horizontally); QRect iconGeometry() const; void setFullScreen(bool set, bool user = true) override; @@ -345,7 +344,6 @@ public: static bool sameAppWindowRoleMatch(const Client* c1, const Client* c2, bool active_hack); void killWindow(); - void maximize(MaximizeMode) override; void toggleShade(); void showContextHelp(); void cancelShadeHoverTimer(); @@ -563,7 +561,7 @@ private: bool isManaged() const; ///< Returns false if this client is not yet managed void updateAllowedActions(bool force = false); QRect fullscreenMonitorsArea(NETFullscreenMonitors topology) const; - void changeMaximize(bool horizontal, bool vertical, bool adjust); + void changeMaximize(bool horizontal, bool vertical, bool adjust) override; int checkFullScreenHack(const QRect& geom) const; // 0 - None, 1 - One xinerama screen, 2 - Full area void updateFullScreenHack(const QRect& geom); void getWmNormalHints(); diff --git a/geometry.cpp b/geometry.cpp index 68850f6f0b..b26475ef40 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -2111,7 +2111,7 @@ void Client::blockGeometryUpdates(bool block) } } -void Client::maximize(MaximizeMode m) +void AbstractClient::maximize(MaximizeMode m) { setMaximize(m & MaximizeVertical, m & MaximizeHorizontal); } @@ -2119,16 +2119,17 @@ void Client::maximize(MaximizeMode m) /*! Sets the maximization according to \a vertically and \a horizontally */ -void Client::setMaximize(bool vertically, bool horizontally) +void AbstractClient::setMaximize(bool vertically, bool horizontally) { // changeMaximize() flips the state, so change from set->flip - MaximizeMode oldMode = maximizeMode(); + const MaximizeMode oldMode = maximizeMode(); changeMaximize( - max_mode & MaximizeVertical ? !vertically : vertically, - max_mode & MaximizeHorizontal ? !horizontally : horizontally, + oldMode & MaximizeVertical ? !vertically : vertically, + oldMode & MaximizeHorizontal ? !horizontally : horizontally, false); - if (oldMode != maximizeMode()) { - emit clientMaximizedStateChanged(this, max_mode); + const MaximizeMode newMode = maximizeMode(); + if (oldMode != newMode) { + emit clientMaximizedStateChanged(this, newMode); emit clientMaximizedStateChanged(this, vertically, horizontally); } diff --git a/shell_client.cpp b/shell_client.cpp index fe1cd70f28..faef3d4451 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -367,16 +367,18 @@ void ShellClient::hideClient(bool hide) Q_UNUSED(hide) } -void ShellClient::maximize(MaximizeMode mode) +void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust) { - if (m_maximizeMode == mode) { - return; - } - // TODO: check rules StackingUpdatesBlocker blocker(workspace()); - const MaximizeMode oldMode = m_maximizeMode; - m_maximizeMode = mode; + // 'adjust == true' means to update the size only, e.g. after changing workspace size + if (!adjust) { + if (vertical) + m_maximizeMode = MaximizeMode(m_maximizeMode ^ MaximizeVertical); + if (horizontal) + m_maximizeMode = MaximizeMode(m_maximizeMode ^ MaximizeHorizontal); + } + // TODO: check rules if (m_maximizeMode == MaximizeFull) { m_geomMaximizeRestore = geometry(); requestGeometry(workspace()->clientArea(MaximizeArea, this)); @@ -388,11 +390,7 @@ void ShellClient::maximize(MaximizeMode mode) requestGeometry(workspace()->clientArea(PlacementArea, this)); } } - if (oldMode != maximizeMode()) { - emit clientMaximizedStateChanged(this, m_maximizeMode); - const bool set = m_maximizeMode == MaximizeFull; - emit clientMaximizedStateChanged(this, set, set); - } + // TODO: add more checks as in Client } MaximizeMode ShellClient::maximizeMode() const diff --git a/shell_client.h b/shell_client.h index c9af6e134b..6e69eab480 100644 --- a/shell_client.h +++ b/shell_client.h @@ -72,7 +72,6 @@ public: bool isResizable() const override; bool isShown(bool shaded_is_shown) const override; void hideClient(bool hide) override; - void maximize(MaximizeMode) override; MaximizeMode maximizeMode() const override; QRect geometryRestore() const override { return m_geomMaximizeRestore; @@ -122,6 +121,7 @@ protected: bool belongsToSameApplication(const AbstractClient *other, bool active_hack) const override; void doSetActive() override; Layer layerForDock() const override; + void changeMaximize(bool horizontal, bool vertical, bool adjust) override; private Q_SLOTS: void clientFullScreenChanged(bool fullScreen);