[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.
This commit is contained in:
Martin Gräßlin 2015-06-18 23:19:13 +02:00
parent 7b842ccc81
commit 97588faea2
3 changed files with 23 additions and 2 deletions

View file

@ -1011,6 +1011,15 @@ bool InputRedirection::areButtonsPressed() const
return false; 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) Toplevel *InputRedirection::findToplevel(const QPoint &pos)
{ {
if (!Workspace::self()) { if (!Workspace::self()) {
@ -1019,7 +1028,7 @@ Toplevel *InputRedirection::findToplevel(const QPoint &pos)
// TODO: check whether the unmanaged wants input events at all // TODO: check whether the unmanaged wants input events at all
const UnmanagedList &unmanaged = Workspace::self()->unmanagedList(); const UnmanagedList &unmanaged = Workspace::self()->unmanagedList();
foreach (Unmanaged *u, unmanaged) { foreach (Unmanaged *u, unmanaged) {
if (u->geometry().contains(pos)) { if (u->geometry().contains(pos) && acceptsInput(u, pos)) {
return u; return u;
} }
} }
@ -1044,7 +1053,7 @@ Toplevel *InputRedirection::findToplevel(const QPoint &pos)
if (!t->readyForPainting()) { if (!t->readyForPainting()) {
continue; continue;
} }
if (t->geometry().contains(pos)) { if (t->geometry().contains(pos) && acceptsInput(t, pos)) {
return t; return t;
} }
} while (it != stacking.begin()); } while (it != stacking.begin());

View file

@ -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 } // namespace
#include "toplevel.moc" #include "toplevel.moc"

View file

@ -268,6 +268,7 @@ public:
bool readyForPainting() const; // true if the window has been already painted its contents bool readyForPainting() const; // true if the window has been already painted its contents
xcb_visualid_t visual() const; xcb_visualid_t visual() const;
bool shape() const; bool shape() const;
QRegion inputShape() const;
virtual void setOpacity(double opacity); virtual void setOpacity(double opacity);
virtual double opacity() const; virtual double opacity() const;
int depth() const; int depth() const;