From 38b418887aea2f84360d3d1d6004ab77e59e8f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 13 Mar 2015 14:45:21 +0100 Subject: [PATCH] Move minimize implementation to AbstractClient --- abstract_client.cpp | 49 +++++++++++++++++++++++++++++++ abstract_client.h | 32 ++++++++++++++++++-- client.cpp | 52 ++------------------------------- client.h | 23 +-------------- effects.cpp | 4 +-- scripting/workspace_wrapper.cpp | 4 +-- scripting/workspace_wrapper.h | 4 +-- 7 files changed, 87 insertions(+), 81 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index c492b5d78c..d00bf21426 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -306,4 +306,53 @@ AbstractClient::Position AbstractClient::titlebarPosition() const return PositionTop; } +void AbstractClient::setMinimized(bool set) +{ + set ? minimize() : unminimize(); +} + +void AbstractClient::minimize(bool avoid_animation) +{ + if (!isMinimizable() || isMinimized()) + return; + + if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded + info->setState(0, NET::Shaded); + + m_minimized = true; + + doMinimize(); + + updateWindowRules(Rules::Minimize); + FocusChain::self()->update(this, FocusChain::MakeFirstMinimized); + // TODO: merge signal with s_minimized + emit clientMinimized(this, !avoid_animation); + emit minimizedChanged(); +} + +void AbstractClient::unminimize(bool avoid_animation) +{ + if (!isMinimized()) + return; + + if (rules()->checkMinimize(false)) { + return; + } + + if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded + info->setState(NET::Shaded, NET::Shaded); + + m_minimized = false; + + doMinimize(); + + updateWindowRules(Rules::Minimize); + emit clientUnminimized(this, !avoid_animation); + emit minimizedChanged(); +} + +void AbstractClient::doMinimize() +{ +} + } diff --git a/abstract_client.h b/abstract_client.h index a4a7308ba9..6411e7e978 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -82,6 +82,15 @@ class AbstractClient : public Toplevel * Whether the Client is shaded. **/ Q_PROPERTY(bool shade READ isShade WRITE setShade NOTIFY shadeChanged) + /** + * Whether the Client can be minimized. The property is evaluated each time it is invoked. + * Because of that there is no notify signal. + **/ + Q_PROPERTY(bool minimizable READ isMinimizable) + /** + * Whether the Client is minimized. + **/ + Q_PROPERTY(bool minimized READ isMinimized WRITE setMinimized NOTIFY minimizedChanged) /** * Returns whether the window is any of special windows types (desktop, dock, splash, ...), * i.e. window types that usually don't have a window frame and the user does not use window @@ -152,7 +161,6 @@ public: virtual void updateMouseGrab(); virtual QString caption(bool full = true, bool stripped = false) const = 0; - virtual bool isMinimized() const = 0; virtual bool isCloseable() const = 0; // TODO: remove boolean trap virtual bool isShown(bool shaded_is_shown) const = 0; @@ -176,8 +184,15 @@ public: int desktop() const override { return m_desktop; } - virtual void minimize(bool avoid_animation = false) = 0; - virtual void unminimize(bool avoid_animation = false)= 0; + void setMinimized(bool set); + /** + * Minimizes this client plus its transients + */ + void minimize(bool avoid_animation = false); + void unminimize(bool avoid_animation = false); + bool isMinimized() const { + return m_minimized; + } virtual void setFullScreen(bool set, bool user = true) = 0; virtual TabGroup *tabGroup() const; Q_INVOKABLE virtual bool untab(const QRect &toGeometry = QRect(), bool clientRemoved = false); @@ -284,6 +299,9 @@ Q_SIGNALS: void desktopPresenceChanged(KWin::AbstractClient*, int); // to be forwarded by Workspace void desktopChanged(); void shadeChanged(); + void minimizedChanged(); + void clientMinimized(KWin::AbstractClient* client, bool animate); + void clientUnminimized(KWin::AbstractClient* client, bool animate); protected: AbstractClient(); @@ -323,6 +341,13 @@ protected: * @param was_desk The desktop the Client was on before **/ virtual void doSetDesktop(int desktop, int was_desk); + /** + * Called from ::minimize and ::unminimize once the minimized value got updated, but before the + * changed signal is emitted. + * + * Default implementation does nothig. + **/ + virtual void doMinimize(); // TODO: remove boolean trap virtual bool belongsToSameApplication(const AbstractClient *other, bool active_hack) const = 0; @@ -335,6 +360,7 @@ private: bool m_keepAbove = false; bool m_keepBelow = false; bool m_demandsAttention = false; + bool m_minimized = false; QTimer *m_autoRaiseTimer = nullptr; int m_desktop = 0; // 0 means not on any desktop yet }; diff --git a/client.cpp b/client.cpp index 09184eb424..5b789cb227 100644 --- a/client.cpp +++ b/client.cpp @@ -159,7 +159,6 @@ Client::Client() fullscreen_mode = FullScreenNone; skip_taskbar = false; original_skip_taskbar = false; - minimized = false; hidden = false; modal = false; noborder = false; @@ -729,61 +728,14 @@ bool Client::isMinimizable() const return true; } -void Client::setMinimized(bool set) +void Client::doMinimize() { - set ? minimize() : unminimize(); -} - -/** - * Minimizes this client plus its transients - */ -void Client::minimize(bool avoid_animation) -{ - if (!isMinimizable() || isMinimized()) - return; - - if (isShade()) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded - info->setState(0, NET::Shaded); - - minimized = true; - updateVisibility(); updateAllowedActions(); workspace()->updateMinimizedOfTransients(this); - updateWindowRules(Rules::Minimize); - FocusChain::self()->update(this, FocusChain::MakeFirstMinimized); - // TODO: merge signal with s_minimized - emit clientMinimized(this, !avoid_animation); - // Update states of all other windows in this group if (tabGroup()) tabGroup()->updateStates(this, TabGroup::Minimized); - emit minimizedChanged(); -} - -void Client::unminimize(bool avoid_animation) -{ - if (!isMinimized()) - return; - - if (rules()->checkMinimize(false)) { - return; - } - - if (isShade()) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded - info->setState(NET::Shaded, NET::Shaded); - - minimized = false; - updateVisibility(); - updateAllowedActions(); - workspace()->updateMinimizedOfTransients(this); - updateWindowRules(Rules::Minimize); - emit clientUnminimized(this, !avoid_animation); - - // Update states of all other windows in this group - if (tabGroup()) - tabGroup()->updateStates(this, TabGroup::Minimized); - emit minimizedChanged(); } QRect Client::iconGeometry() const @@ -945,7 +897,7 @@ void Client::updateVisibility() } if (isCurrentTab()) setSkipTaskbar(original_skip_taskbar, false); // Reset from 'hidden' - if (minimized) { + if (isMinimized()) { info->setState(NET::Hidden, NET::Hidden); if (compositing() && options->hiddenPreviews() == HiddenPreviewsAlways) internalKeep(); diff --git a/client.h b/client.h index c479936c63..4e4443ef4f 100644 --- a/client.h +++ b/client.h @@ -103,15 +103,6 @@ class Client * Because of that there is no notify signal. **/ Q_PROPERTY(bool maximizable READ isMaximizable) - /** - * Whether the Client can be minimized. The property is evaluated each time it is invoked. - * Because of that there is no notify signal. - **/ - Q_PROPERTY(bool minimizable READ isMinimizable) - /** - * Whether the Client is minimized. - **/ - Q_PROPERTY(bool minimized READ isMinimized WRITE setMinimized NOTIFY minimizedChanged) /** * Whether the Client represents a modal window. **/ @@ -299,7 +290,6 @@ public: void setShade(ShadeMode mode) override; bool isShadeable() const override; - bool isMinimized() const override; bool isMaximizable() const override; QRect geometryRestore() const; MaximizeMode maximizeMode() const override; @@ -434,9 +424,6 @@ public: static bool belongToSameApplication(const Client* c1, const Client* c2, bool active_hack = false); static bool sameAppWindowRoleMatch(const Client* c1, const Client* c2, bool active_hack); - void setMinimized(bool set); - void minimize(bool avoid_animation = false) override; - void unminimize(bool avoid_animation = false) override; void killWindow(); void maximize(MaximizeMode) override; void toggleShade(); @@ -593,6 +580,7 @@ protected: void doSetKeepAbove() override; void doSetKeepBelow() override; void doSetDesktop(int desktop, int was_desk) override; + void doMinimize() override; private Q_SLOTS: void delayedSetShortcut(); @@ -607,8 +595,6 @@ Q_SIGNALS: void clientFullScreenSet(KWin::Client*, bool, bool); void clientMaximizedStateChanged(KWin::Client*, MaximizeMode); void clientMaximizedStateChanged(KWin::Client* c, bool h, bool v); - void clientMinimized(KWin::Client* client, bool animate); - void clientUnminimized(KWin::Client* client, bool animate); void clientStartUserMovedResized(KWin::Client*); void clientStepUserMovedResized(KWin::Client *, const QRect&); void clientFinishUserMovedResized(KWin::Client*); @@ -616,7 +602,6 @@ Q_SIGNALS: void fullScreenChanged(); void transientChanged(); void modalChanged(); - void minimizedChanged(); void moveResizedChanged(); void skipTaskbarChanged(); void skipPagerChanged(); @@ -803,7 +788,6 @@ private: uint original_skip_taskbar : 1; ///< Unaffected by KWin uint skip_pager : 1; Xcb::MotifHints m_motif; - uint minimized : 1; uint hidden : 1; ///< Forcibly hidden by calling hide() uint modal : 1; ///< NET::Modal uint noborder : 1; @@ -961,11 +945,6 @@ inline TabGroup* Client::tabGroup() const return tab_group; } -inline bool Client::isMinimized() const -{ - return minimized; -} - inline bool Client::isShown(bool shaded_is_shown) const { return !isMinimized() && (!isShade() || shaded_is_shown) && !hidden && diff --git a/effects.cpp b/effects.cpp index 6bf4642c57..846fcf3c69 100644 --- a/effects.cpp +++ b/effects.cpp @@ -354,7 +354,7 @@ void EffectsHandlerImpl::setupClientConnections(Client* c) ); connect(c, &Client::opacityChanged, this, &EffectsHandlerImpl::slotOpacityChanged); connect(c, &Client::clientMinimized, this, - [this](Client *c, bool animate) { + [this](AbstractClient *c, bool animate) { // TODO: notify effects even if it should not animate? if (animate) { emit windowMinimized(c->effectWindow()); @@ -362,7 +362,7 @@ void EffectsHandlerImpl::setupClientConnections(Client* c) } ); connect(c, &Client::clientUnminimized, this, - [this](Client* c, bool animate) { + [this](AbstractClient* c, bool animate) { // TODO: notify effects even if it should not animate? if (animate) { emit windowUnminimized(c->effectWindow()); diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp index 5c94e4a045..065fa5e21e 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -244,8 +244,8 @@ QString WorkspaceWrapper::supportInformation() const void WorkspaceWrapper::setupClientConnections(KWin::Client *client) { - connect(client, SIGNAL(clientMinimized(KWin::Client*,bool)), SIGNAL(clientMinimized(KWin::Client*))); - connect(client, SIGNAL(clientUnminimized(KWin::Client*,bool)), SIGNAL(clientUnminimized(KWin::Client*))); + connect(client, &Client::clientMinimized, this, &WorkspaceWrapper::clientMinimized); + connect(client, &Client::clientUnminimized, this, &WorkspaceWrapper::clientUnminimized); connect(client, SIGNAL(clientManaging(KWin::Client*)), SIGNAL(clientManaging(KWin::Client*))); connect(client, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)), SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool))); connect(client, SIGNAL(clientMaximizedStateChanged(KWin::Client*,bool,bool)), SIGNAL(clientMaximizeSet(KWin::Client*,bool,bool))); diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h index 9761ec423f..592fb928b0 100644 --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -93,8 +93,8 @@ Q_SIGNALS: void clientAdded(KWin::Client *client); void clientRemoved(KWin::Client *client); void clientManaging(KWin::Client *client); - void clientMinimized(KWin::Client *client); - void clientUnminimized(KWin::Client *client); + void clientMinimized(KWin::AbstractClient *client); + void clientUnminimized(KWin::AbstractClient *client); void clientRestored(KWin::Client *client); void clientMaximizeSet(KWin::Client *client, bool h, bool v); void killWindowCalled(KWin::Client *client);