From 97588faea2d79ed1208824cee3a25ca9ef41eeb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 18 Jun 2015 23:19:13 +0200 Subject: [PATCH] [wayland] Add support for input shape Toplevel provides the input shape forwarded from SurfaceInterface. The shape is evaluated in InputRedirection when finding the Toplevel at a given position. --- input.cpp | 13 +++++++++++-- toplevel.cpp | 11 +++++++++++ toplevel.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/input.cpp b/input.cpp index f4aefbb3c2..1c21d156f0 100644 --- a/input.cpp +++ b/input.cpp @@ -1011,6 +1011,15 @@ bool InputRedirection::areButtonsPressed() const return false; } +static bool acceptsInput(Toplevel *t, const QPoint &pos) +{ + const QRegion input = t->inputShape(); + if (input.isEmpty()) { + return true; + } + return input.translated(t->pos()).contains(pos); +} + Toplevel *InputRedirection::findToplevel(const QPoint &pos) { if (!Workspace::self()) { @@ -1019,7 +1028,7 @@ Toplevel *InputRedirection::findToplevel(const QPoint &pos) // TODO: check whether the unmanaged wants input events at all const UnmanagedList &unmanaged = Workspace::self()->unmanagedList(); foreach (Unmanaged *u, unmanaged) { - if (u->geometry().contains(pos)) { + if (u->geometry().contains(pos) && acceptsInput(u, pos)) { return u; } } @@ -1044,7 +1053,7 @@ Toplevel *InputRedirection::findToplevel(const QPoint &pos) if (!t->readyForPainting()) { continue; } - if (t->geometry().contains(pos)) { + if (t->geometry().contains(pos) && acceptsInput(t, pos)) { return t; } } while (it != stacking.begin()); diff --git a/toplevel.cpp b/toplevel.cpp index 4d86b09f5a..3b07a6658b 100644 --- a/toplevel.cpp +++ b/toplevel.cpp @@ -493,6 +493,17 @@ void Toplevel::setDepth(int depth) } } +QRegion Toplevel::inputShape() const +{ +#if HAVE_WAYLAND + if (m_surface) { + return m_surface->input(); + } else +#endif + // TODO: maybe also for X11? + return QRegion(); +} + } // namespace #include "toplevel.moc" diff --git a/toplevel.h b/toplevel.h index 027b089a4a..0e9afe94f5 100644 --- a/toplevel.h +++ b/toplevel.h @@ -268,6 +268,7 @@ public: bool readyForPainting() const; // true if the window has been already painted its contents xcb_visualid_t visual() const; bool shape() const; + QRegion inputShape() const; virtual void setOpacity(double opacity); virtual double opacity() const; int depth() const;