Introduce an AbstractClient base class for Client (and ShellClient)

The idea for this base class is to provide access to all elements which
make up a managed "Client" being it X11 or Wayland. They share a lot,
like they have a caption, they can be minimized, etc. etc.

Of course it would have also been possible to derive a new class from
Client, but that looks like the more difficult task as Client is very
X11 specific.

So far only a very small interface is extracted with pure-virtual
methods. This is going to change by moving the functionality up into
the AbstractClient.

The interface extracted so far is inspired by the usage of FocusChain
and users of FocusChain.
icc-effect-5.14.5
Martin Gräßlin 2015-03-05 10:21:03 +01:00
parent d60c377890
commit 0f54da9dde
5 changed files with 134 additions and 19 deletions

View File

@ -349,6 +349,7 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1212)
set(kwin_KDEINIT_SRCS
workspace.cpp
dbusinterface.cpp
abstract_client.cpp
client.cpp
client_machine.cpp
cursor.cpp

41
abstract_client.cpp Normal file
View File

@ -0,0 +1,41 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "abstract_client.h"
namespace KWin
{
AbstractClient::AbstractClient()
: Toplevel()
{
}
AbstractClient::~AbstractClient() = default;
void AbstractClient::updateMouseGrab()
{
}
bool AbstractClient::belongToSameApplication(const AbstractClient *c1, const AbstractClient *c2, bool active_hack)
{
return c1->belongsToSameApplication(c2, active_hack);
}
}

68
abstract_client.h Normal file
View File

@ -0,0 +1,68 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_ABSTRACT_CLIENT_H
#define KWIN_ABSTRACT_CLIENT_H
#include "toplevel.h"
namespace KWin
{
namespace TabBox
{
class TabBoxClientImpl;
}
class AbstractClient : public Toplevel
{
Q_OBJECT
public:
virtual ~AbstractClient();
virtual QWeakPointer<TabBox::TabBoxClientImpl> tabBoxClient() const = 0;
virtual void updateMouseGrab();
virtual QString caption(bool full = true, bool stripped = false) const = 0;
virtual bool isMinimized() const = 0;
virtual bool isCloseable() const = 0;
virtual bool isFirstInTabBox() const = 0;
// TODO: remove boolean trap
virtual bool isShown(bool shaded_is_shown) const = 0;
virtual bool wantsTabFocus() const = 0;
virtual bool isFullScreen() const = 0;
virtual const QIcon &icon() const = 0;
// TODO: remove boolean trap
static bool belongToSameApplication(const AbstractClient* c1, const AbstractClient* c2, bool active_hack = false);
public Q_SLOTS:
virtual void closeWindow() = 0;
protected:
AbstractClient();
// TODO: remove boolean trap
virtual bool belongsToSameApplication(const AbstractClient *other, bool active_hack) const = 0;
};
}
Q_DECLARE_METATYPE(KWin::AbstractClient*)
Q_DECLARE_METATYPE(QList<KWin::AbstractClient*>)
#endif

View File

@ -100,7 +100,7 @@ std::shared_ptr<Decoration::DecorationPalette> Client::s_defaultPalette;
* is done in manage().
*/
Client::Client()
: Toplevel()
: AbstractClient()
, m_client()
, m_wrapper()
, m_frame()
@ -2441,6 +2441,15 @@ void Client::addDamage(const QRegion &damage)
Toplevel::addDamage(damage);
}
bool Client::belongsToSameApplication(const AbstractClient *other, bool active_hack) const
{
const Client *c2 = dynamic_cast<const Client*>(other);
if (!c2) {
return false;
}
return Client::belongToSameApplication(this, c2, active_hack);
}
} // namespace
#include "client.moc"

View File

@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "options.h"
#include "rules.h"
#include "tabgroup.h"
#include "toplevel.h"
#include "abstract_client.h"
#include "xcbutils.h"
#include "decorations/decorationpalette.h"
// Qt
@ -53,11 +53,6 @@ class Decoration;
namespace KWin
{
namespace TabBox
{
class TabBoxClientImpl;
}
namespace Decoration
{
@ -78,7 +73,7 @@ enum class Predicate {
};
class Client
: public Toplevel
: public AbstractClient
{
Q_OBJECT
/**
@ -354,7 +349,7 @@ public:
QSize adjustedSize(const QSize&, Sizemode mode = SizemodeAny) const;
QSize adjustedSize() const;
const QIcon &icon() const;
const QIcon &icon() const override;
bool isActive() const;
void setActive(bool);
@ -373,7 +368,7 @@ public:
void blockActivityUpdates(bool b = true);
/// Is not minimized and not hidden. I.e. normally visible on some virtual desktop.
bool isShown(bool shaded_is_shown) const;
bool isShown(bool shaded_is_shown) const override;
bool isHiddenInternal() const; // For compositing
bool isShade() const; // True only for ShadeNormal
@ -382,7 +377,7 @@ public:
void setShade(ShadeMode mode);
bool isShadeable() const;
bool isMinimized() const;
bool isMinimized() const override;
bool isMaximizable() const;
QRect geometryRestore() const;
MaximizeMode maximizeMode() const;
@ -405,7 +400,7 @@ public:
QRect iconGeometry() const;
void setFullScreen(bool set, bool user = true);
bool isFullScreen() const;
bool isFullScreen() const override;
bool isFullScreenable(bool fullscreen_hack = false) const;
bool isActiveFullScreen() const;
bool userCanSetFullScreen() const;
@ -444,13 +439,13 @@ public:
bool isModal() const;
// Auxiliary functions, depend on the windowType
bool wantsTabFocus() const;
bool wantsTabFocus() const override;
bool wantsInput() const;
bool isResizable() const;
bool isMovable() const;
bool isMovableAcrossScreens() const;
bool isCloseable() const; ///< May be closed by the user (May have a close button)
bool isCloseable() const override; ///< May be closed by the user (May have a close button)
void takeFocus();
bool isDemandingAttention() const {
@ -515,10 +510,10 @@ public:
void setBlockingCompositing(bool block);
inline bool isBlockingCompositing() { return blocks_compositing; }
QString caption(bool full = true, bool stripped = false) const;
QString caption(bool full = true, bool stripped = false) const override;
void keyPressEvent(uint key_code, xcb_timestamp_t time = XCB_TIME_CURRENT_TIME); // FRAME ??
void updateMouseGrab();
void updateMouseGrab() override;
xcb_window_t moveResizeGrabWindow() const;
const QPoint calculateGravitation(bool invert, int gravity = 0) const; // FRAME public?
@ -644,10 +639,10 @@ public:
void layoutDecorationRects(QRect &left, QRect &top, QRect &right, QRect &bottom) const;
QWeakPointer<TabBox::TabBoxClientImpl> tabBoxClient() const {
QWeakPointer<TabBox::TabBoxClientImpl> tabBoxClient() const override {
return m_tabBoxClient.toWeakRef();
}
bool isFirstInTabBox() const {
bool isFirstInTabBox() const override {
return m_firstInTabBox;
}
void setFirstInTabBox(bool enable) {
@ -681,7 +676,7 @@ public:
void showOnScreenEdge();
public Q_SLOTS:
void closeWindow();
void closeWindow() override;
void updateCaption();
private Q_SLOTS:
@ -723,6 +718,7 @@ protected:
virtual void debug(QDebug& stream) const;
virtual bool shouldUnredirect() const;
void addDamage(const QRegion &damage) override;
bool belongsToSameApplication(const AbstractClient *other, bool active_hack) const override;
private Q_SLOTS:
void delayedSetShortcut();