Commit 24bdfc63 authored by Martin Flöser's avatar Martin Flöser
Browse files

Make Toplevel::window() no longer virtual and introduce ::windowId()

Summary:
Toplevel::window() is the actual X11 window. This makes it difficult
to use as the generic identifier for both X11 and Wayland. The Wayland
ShellClient already had a windowId() which is now added to Toplevel as
a virtual method. On X11 (Toplevel default) it returns the window().

The method window() now returns XCB_WINDOW_NONE for classes without
the Toplevel::m_client, such as ShellClient. Thus it allows to properly
check whether we are on Wayland or X11.

The code is adjusted to use windowId where a generic id is needed and
to properly check whether the window is valid before using it where
a window() is used.

This also fixes at least one additional unknown issue in
Workspace::setActiveClient

where the windowId of a Wayland client was passed to X11.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1527
parent d15d3a5f
......@@ -137,7 +137,7 @@ DELEGATE2(QIcon, icon)
DELEGATE(bool, isKeepAbove, keepAbove)
DELEGATE(bool, isKeepBelow, keepBelow)
DELEGATE(bool, isShaded, isShade)
DELEGATE(WId, windowId, window)
DELEGATE(WId, windowId, windowId)
DELEGATE(WId, decorationId, frameId)
#undef DELEGATE
......
......@@ -166,6 +166,9 @@ void ScreenLockerWatcher::setLocked(bool activated)
static QByteArray readWindowProperty(xcb_window_t win, xcb_atom_t atom, xcb_atom_t type, int format)
{
if (win == XCB_WINDOW_NONE) {
return QByteArray();
}
uint32_t len = 32768;
for (;;) {
Xcb::Property prop(false, win, atom, XCB_ATOM_ANY, 0, len);
......@@ -183,6 +186,9 @@ static QByteArray readWindowProperty(xcb_window_t win, xcb_atom_t atom, xcb_atom
static void deleteWindowProperty(Window win, long int atom)
{
if (win == XCB_WINDOW_NONE) {
return;
}
xcb_delete_property(connection(), win, atom);
}
......
......@@ -127,12 +127,14 @@ Shadow *Shadow::createShadowFromWayland(Toplevel *toplevel)
QVector< uint32_t > Shadow::readX11ShadowProperty(xcb_window_t id)
{
QVector<uint32_t> ret;
Xcb::Property property(false, id, atoms->kde_net_wm_shadow, XCB_ATOM_CARDINAL, 0, 12);
uint32_t *shadow = property.value<uint32_t*>();
if (shadow) {
ret.reserve(12);
for (int i=0; i<12; ++i) {
ret << shadow[i];
if (id != XCB_WINDOW) {
Xcb::Property property(false, id, atoms->kde_net_wm_shadow, XCB_ATOM_CARDINAL, 0, 12);
uint32_t *shadow = property.value<uint32_t*>();
if (shadow) {
ret.reserve(12);
for (int i=0; i<12; ++i) {
ret << shadow[i];
}
}
}
return ret;
......
......@@ -766,11 +766,6 @@ bool ShellClient::isInputMethod() const
return surface()->client() == waylandServer()->inputMethodConnection();
}
xcb_window_t ShellClient::window() const
{
return windowId();
}
void ShellClient::requestGeometry(const QRect &rect)
{
m_positionAfterResize.setPoint(rect.topLeft());
......
......@@ -90,7 +90,6 @@ public:
bool userCanSetFullScreen() const override;
bool userCanSetNoBorder() const override;
bool wantsInput() const override;
xcb_window_t window() const override;
using AbstractClient::resizeWithChecks;
void resizeWithChecks(int w, int h, ForceGeometry_t force = NormalGeometrySet) override;
using AbstractClient::setGeometry;
......@@ -99,7 +98,7 @@ public:
void setInternalFramebufferObject(const QSharedPointer<QOpenGLFramebufferObject> &fbo) override;
quint32 windowId() const {
quint32 windowId() const override {
return m_windowId;
}
bool isInternal() const;
......
......@@ -375,7 +375,7 @@ QIcon TabBoxClientImpl::icon() const
WId TabBoxClientImpl::window() const
{
return m_client->window();
return m_client->windowId();
}
bool TabBoxClientImpl::isMinimized() const
......
......@@ -159,7 +159,7 @@ void WindowThumbnailItem::setClient(AbstractClient *client)
}
m_client = client;
if (m_client) {
setWId(m_client->window());
setWId(m_client->windowId());
} else {
setWId(0);
}
......@@ -183,7 +183,7 @@ void WindowThumbnailItem::paint(QPainter *painter)
void WindowThumbnailItem::repaint(KWin::EffectWindow *w)
{
if (static_cast<KWin::EffectWindowImpl*>(w)->window()->window() == m_wId) {
if (static_cast<KWin::EffectWindowImpl*>(w)->window()->windowId() == m_wId) {
update();
}
}
......
......@@ -519,5 +519,10 @@ QMatrix4x4 Toplevel::inputTransformation() const
return m;
}
quint32 Toplevel::windowId() const
{
return window();
}
} // namespace
......@@ -82,7 +82,7 @@ class KWIN_EXPORT Toplevel
Q_PROPERTY(int screen READ screen NOTIFY screenChanged)
Q_PROPERTY(QSize size READ size)
Q_PROPERTY(int width READ width)
Q_PROPERTY(qulonglong windowId READ window CONSTANT)
Q_PROPERTY(qulonglong windowId READ windowId CONSTANT)
Q_PROPERTY(int x READ x)
Q_PROPERTY(int y READ y)
Q_PROPERTY(int desktop READ desktop)
......@@ -213,7 +213,11 @@ class KWIN_EXPORT Toplevel
public:
explicit Toplevel();
virtual xcb_window_t frameId() const;
virtual xcb_window_t window() const;
xcb_window_t window() const;
/**
* @return a unique identifier for the Toplevel. On X11 same as @link {window}
**/
virtual quint32 windowId() const;
QRect geometry() const;
QSize size() const;
QPoint pos() const;
......
......@@ -222,7 +222,7 @@ void UserActionsMenu::helperDialog(const QString& message, const QWeakPointer<Ab
args << QStringLiteral("--dontagain") << QLatin1String("kwin_dialogsrc:") + type;
}
if (!c.isNull())
args << QStringLiteral("--embed") << QString::number(c.data()->window());
args << QStringLiteral("--embed") << QString::number(c.data()->windowId());
QtConcurrent::run([args]() {
KProcess::startDetached(QStringLiteral("kdialog"), args);
});
......@@ -1704,7 +1704,7 @@ void Workspace::slotInvertScreen()
bool succeeded = false;
if (Xcb::Extensions::self()->isRandrAvailable()) {
ScreenResources res(active_client ? active_client->window() : rootWindow());
ScreenResources res((active_client && active_client->window() != XCB_WINDOW_NONE) ? active_client->window() : rootWindow());
if (!res.isNull()) {
for (int j = 0; j < res->num_crtcs; ++j) {
......
Markdown is supported
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