kwin/toplevel.h

455 lines
11 KiB
C
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <l.lunak@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_TOPLEVEL_H
#define KWIN_TOPLEVEL_H
#include <config-X11.h>
#include <assert.h>
#include <QObject>
#include <kdecoration.h>
#include <kdebug.h>
#include "kactivityconsumer.h"
#include "utils.h"
#include "workspace.h"
#ifdef HAVE_XDAMAGE
#include <X11/extensions/Xdamage.h>
#endif
class NETWinInfo2;
namespace KWin
{
class Workspace;
class EffectWindowImpl;
class Toplevel
: public QObject, public KDecorationDefines
2011-01-30 14:34:42 +00:00
{
Q_OBJECT
2011-01-30 14:34:42 +00:00
public:
Toplevel(Workspace *ws);
Window frameId() const;
Window window() const;
Workspace* workspace() const;
QRect geometry() const;
QSize size() const;
QPoint pos() const;
QRect rect() const;
int x() const;
int y() const;
int width() const;
int height() const;
bool isOnScreen(int screen) const; // true if it's at least partially there
int screen() const; // the screen where the center is
virtual QPoint clientPos() const = 0; // inside of geometry()
virtual QSize clientSize() const = 0;
virtual QRect visibleRect() const; // the area the window occupies on the screen
virtual QRect decorationRect() const; // rect including the decoration shadows
virtual QRect transparentRect() const = 0;
virtual QRegion decorationPendingRegion() const; // decoration region that needs to be repainted
// prefer isXXX() instead
// 0 for supported types means default for managed/unmanaged types
NET::WindowType windowType(bool direct = false, int supported_types = 0) const;
bool hasNETSupport() const;
bool isDesktop() const;
bool isDock() const;
bool isToolbar() const;
bool isTopMenu() const;
bool isMenu() const;
bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient'
bool isDialog() const;
bool isSplash() const;
bool isUtility() const;
bool isDropdownMenu() const;
bool isPopupMenu() const; // a context popup, not dropdown, not torn-off
bool isTooltip() const;
bool isNotification() const;
bool isComboBox() const;
bool isDNDIcon() const;
virtual int desktop() const = 0;
virtual QStringList activities() const = 0;
bool isOnDesktop(int d) const;
bool isOnActivity(const QString &activity) const;
bool isOnCurrentDesktop() const;
bool isOnCurrentActivity() const;
bool isOnAllDesktops() const;
bool isOnAllActivities() const;
QByteArray windowRole() const;
QByteArray sessionId();
QByteArray resourceName() const;
QByteArray resourceClass() const;
QByteArray wmCommand();
QByteArray wmClientMachine(bool use_localhost) const;
Window wmClientLeader() const;
pid_t pid() const;
static bool resourceMatch(const Toplevel* c1, const Toplevel* c2);
Pixmap windowPixmap(bool allow_create = true); // may return None (e.g. at a bad moment while resizing)
bool readyForPainting() const; // true if the window has been already painted its contents
Visual* visual() const;
bool shape() const;
void setOpacity(double opacity);
double opacity() const;
int depth() const;
bool hasAlpha() const;
virtual void setupCompositing();
virtual void finishCompositing();
bool updateUnredirectedState();
bool unredirected() const;
void suspendUnredirect(bool suspend);
void addRepaint(const QRect& r);
void addRepaint(int x, int y, int w, int h);
virtual void addRepaintFull();
// these call workspace->addRepaint(), but first transform the damage if needed
void addWorkspaceRepaint(const QRect& r);
void addWorkspaceRepaint(int x, int y, int w, int h);
QRegion repaints() const;
void resetRepaints(const QRect& r);
QRegion damage() const;
void resetDamage(const QRect& r);
EffectWindowImpl* effectWindow();
protected:
virtual ~Toplevel();
void setWindowHandles(Window client, Window frame);
void detectShape(Window id);
virtual void propertyNotifyEvent(XPropertyEvent* e);
#ifdef HAVE_XDAMAGE
2011-01-30 14:34:42 +00:00
virtual void damageNotifyEvent(XDamageNotifyEvent* e);
#endif
2011-01-30 14:34:42 +00:00
Pixmap createWindowPixmap();
void discardWindowPixmap();
void addDamage(const QRect& r);
void addDamage(int x, int y, int w, int h);
void addDamageFull();
void getWmClientLeader();
void getWmClientMachine();
void getResourceClass();
void getWindowRole();
virtual void debug(QDebug& stream) const = 0;
void copyToDeleted(Toplevel* c);
void disownDataPassedToDeleted();
friend QDebug& operator<<(QDebug& stream, const Toplevel*);
void deleteEffectWindow();
virtual bool shouldUnredirect() const = 0;
QRect geom;
Visual* vis;
int bit_depth;
NETWinInfo2* info;
bool ready_for_painting;
QRegion repaints_region; // updating, repaint just requires repaint of that area
private:
static QByteArray staticWindowRole(WId);
static QByteArray staticSessionId(WId);
static QByteArray staticWmCommand(WId);
static QByteArray staticWmClientMachine(WId);
static Window staticWmClientLeader(WId);
// when adding new data members, check also copyToDeleted()
Window client;
Window frame;
Workspace* wspace;
Pixmap window_pix;
#ifdef HAVE_XDAMAGE
2011-01-30 14:34:42 +00:00
Damage damage_handle;
#endif
2011-01-30 14:34:42 +00:00
QRegion damage_region; // damage is really damaged window (XDamage) and texture needs
bool is_shape;
EffectWindowImpl* effect_window;
QByteArray resource_name;
QByteArray resource_class;
QByteArray client_machine;
WId wmClientLeaderWin;
QByteArray window_role;
bool unredirect;
bool unredirectSuspend; // when unredirected, but pixmap is needed temporarily
// when adding new data members, check also copyToDeleted()
};
inline Window Toplevel::window() const
2011-01-30 14:34:42 +00:00
{
return client;
2011-01-30 14:34:42 +00:00
}
inline Window Toplevel::frameId() const
2011-01-30 14:34:42 +00:00
{
return frame;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
inline void Toplevel::setWindowHandles(Window w, Window f)
{
assert(client == None && w != None);
client = w;
2011-01-30 14:34:42 +00:00
assert(frame == None && f != None);
frame = f;
2011-01-30 14:34:42 +00:00
}
inline Workspace* Toplevel::workspace() const
2011-01-30 14:34:42 +00:00
{
return wspace;
2011-01-30 14:34:42 +00:00
}
inline QRect Toplevel::geometry() const
2011-01-30 14:34:42 +00:00
{
return geom;
2011-01-30 14:34:42 +00:00
}
inline QSize Toplevel::size() const
2011-01-30 14:34:42 +00:00
{
return geom.size();
2011-01-30 14:34:42 +00:00
}
inline QPoint Toplevel::pos() const
2011-01-30 14:34:42 +00:00
{
return geom.topLeft();
2011-01-30 14:34:42 +00:00
}
inline int Toplevel::x() const
2011-01-30 14:34:42 +00:00
{
return geom.x();
2011-01-30 14:34:42 +00:00
}
inline int Toplevel::y() const
2011-01-30 14:34:42 +00:00
{
return geom.y();
2011-01-30 14:34:42 +00:00
}
inline int Toplevel::width() const
2011-01-30 14:34:42 +00:00
{
return geom.width();
2011-01-30 14:34:42 +00:00
}
inline int Toplevel::height() const
2011-01-30 14:34:42 +00:00
{
return geom.height();
2011-01-30 14:34:42 +00:00
}
inline QRect Toplevel::rect() const
2011-01-30 14:34:42 +00:00
{
return QRect(0, 0, width(), height());
}
inline QRect Toplevel::decorationRect() const
2011-01-30 14:34:42 +00:00
{
return rect();
2011-01-30 14:34:42 +00:00
}
inline QRegion Toplevel::decorationPendingRegion() const
2011-01-30 14:34:42 +00:00
{
return QRegion();
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::readyForPainting() const
2011-01-30 14:34:42 +00:00
{
return ready_for_painting;
2011-01-30 14:34:42 +00:00
}
inline Visual* Toplevel::visual() const
2011-01-30 14:34:42 +00:00
{
return vis;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isDesktop() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Desktop;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isDock() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Dock;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isTopMenu() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::TopMenu;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isMenu() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Menu && !isTopMenu(); // because of backwards comp.
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isToolbar() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Toolbar;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isSplash() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Splash;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isUtility() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Utility;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isDialog() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Dialog;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isNormalWindow() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Normal;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isDropdownMenu() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::DropdownMenu;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isPopupMenu() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::PopupMenu;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isTooltip() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Tooltip;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isNotification() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::Notification;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isComboBox() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::ComboBox;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isDNDIcon() const
2011-01-30 14:34:42 +00:00
{
return windowType() == NET::DNDIcon;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
inline Pixmap Toplevel::windowPixmap(bool allow_create)
{
if (window_pix == None && allow_create)
window_pix = createWindowPixmap();
return window_pix;
2011-01-30 14:34:42 +00:00
}
inline QRegion Toplevel::damage() const
2011-01-30 14:34:42 +00:00
{
return damage_region;
2011-01-30 14:34:42 +00:00
}
inline QRegion Toplevel::repaints() const
2011-01-30 14:34:42 +00:00
{
return repaints_region;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::shape() const
2011-01-30 14:34:42 +00:00
{
return is_shape;
2011-01-30 14:34:42 +00:00
}
inline int Toplevel::depth() const
2011-01-30 14:34:42 +00:00
{
return bit_depth;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::hasAlpha() const
2011-01-30 14:34:42 +00:00
{
return depth() == 32;
2011-01-30 14:34:42 +00:00
}
inline
EffectWindowImpl* Toplevel::effectWindow()
2011-01-30 14:34:42 +00:00
{
return effect_window;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isOnAllDesktops() const
2011-01-30 14:34:42 +00:00
{
return desktop() == NET::OnAllDesktops;
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isOnAllActivities() const
2011-01-30 14:34:42 +00:00
{
return activities().isEmpty();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
inline bool Toplevel::isOnDesktop(int d) const
{
return desktop() == d || /*desk == 0 ||*/ isOnAllDesktops();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
inline bool Toplevel::isOnActivity(const QString &activity) const
{
return activities().isEmpty() || activities().contains(activity);
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::isOnCurrentDesktop() const
2011-01-30 14:34:42 +00:00
{
return isOnDesktop(workspace()->currentDesktop());
}
inline bool Toplevel::isOnCurrentActivity() const
2011-01-30 14:34:42 +00:00
{
return isOnActivity(Workspace::self()->currentActivity());
}
inline QByteArray Toplevel::resourceName() const
2011-01-30 14:34:42 +00:00
{
return resource_name; // it is always lowercase
2011-01-30 14:34:42 +00:00
}
inline QByteArray Toplevel::resourceClass() const
2011-01-30 14:34:42 +00:00
{
return resource_class; // it is always lowercase
2011-01-30 14:34:42 +00:00
}
inline QByteArray Toplevel::windowRole() const
2011-01-30 14:34:42 +00:00
{
return window_role;
2011-01-30 14:34:42 +00:00
}
inline pid_t Toplevel::pid() const
2011-01-30 14:34:42 +00:00
{
return info->pid();
2011-01-30 14:34:42 +00:00
}
inline bool Toplevel::unredirected() const
2011-01-30 14:34:42 +00:00
{
return unredirect;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
QDebug& operator<<(QDebug& stream, const Toplevel*);
QDebug& operator<<(QDebug& stream, const ToplevelList&);
QDebug& operator<<(QDebug& stream, const ConstToplevelList&);
2011-01-30 14:34:42 +00:00
KWIN_COMPARE_PREDICATE(WindowMatchPredicate, Toplevel, Window, cl->window() == value);
KWIN_COMPARE_PREDICATE(FrameIdMatchPredicate, Toplevel, Window, cl->frameId() == value);
} // namespace
#endif