Commit 07c972b6 authored by Martin Flöser's avatar Martin Flöser

[wayland] Add a SurfaceInterface to Toplevel

Adds the SurfaceInterface identified by the surface id we get from
Xwayland. This allows in an easier way to map a Toplevel to a
Wayland surface and will also be useful for Wayland clients.
parent e463905f
......@@ -66,6 +66,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "killwindow.h"
#include "x11eventfilter.h"
#if HAVE_WAYLAND
#include <KWayland/Server/surface_interface.h>
#endif
#ifndef XCB_GE_GENERIC
#define XCB_GE_GENERIC 35
typedef struct xcb_ge_generic_event_t {
......@@ -1693,6 +1697,9 @@ void Toplevel::clientMessageEvent(xcb_client_message_event_t *e)
{
if (e->type == atoms->wl_surface_id) {
m_surfaceId = e->data.data32[0];
#if HAVE_WAYLAND
m_surface = KWayland::Server::SurfaceInterface::get(m_surfaceId);
#endif
emit surfaceIdChanged(m_surfaceId);
}
}
......
......@@ -41,6 +41,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// c++
#include <functional>
#if HAVE_WAYLAND
namespace KWayland
{
namespace Server
{
class SurfaceInterface;
}
}
#endif
namespace KWin
{
......@@ -344,6 +354,10 @@ public:
void setSkipCloseAnimation(bool set);
quint32 surfaceId() const;
#if HAVE_WAYLAND
KWayland::Server::SurfaceInterface *surface() const;
void setSurface(KWayland::Server::SurfaceInterface *surface);
#endif
virtual void sendPointerMoveEvent(const QPointF &globalPos);
virtual void sendPointerEnterEvent(const QPointF &globalPos);
......@@ -482,6 +496,9 @@ private:
int m_screen;
bool m_skipCloseAnimation;
quint32 m_surfaceId = 0;
#if HAVE_WAYLAND
KWayland::Server::SurfaceInterface *m_surface = nullptr;
#endif
// when adding new data members, check also copyToDeleted()
};
......@@ -718,6 +735,18 @@ inline quint32 Toplevel::surfaceId() const
return m_surfaceId;
}
#if HAVE_WAYLAND
inline KWayland::Server::SurfaceInterface *Toplevel::surface() const
{
return m_surface;
}
inline void Toplevel::setSurface(KWayland::Server::SurfaceInterface *surface)
{
m_surface = surface;
}
#endif
template <class T, class U>
inline T *Toplevel::findInList(const QList<T*> &list, std::function<bool (const U*)> func)
{
......
......@@ -18,6 +18,8 @@ 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 "wayland_server.h"
#include "toplevel.h"
#include "workspace.h"
#include <KWayland/Server/compositor_interface.h>
#include <KWayland/Server/display.h>
......@@ -47,6 +49,22 @@ void WaylandServer::init(const QByteArray &socketName)
m_display->start();
m_compositor = m_display->createCompositor(m_display);
m_compositor->create();
connect(m_compositor, &CompositorInterface::surfaceCreated, this,
[this] (SurfaceInterface *surface) {
// check whether we have a Toplevel with the Surface's id
Workspace *ws = Workspace::self();
if (!ws) {
// it's possible that a Surface gets created before Workspace is created
return;
}
auto check = [surface] (const Toplevel *t) {
return t->surfaceId() == surface->id();
};
if (Toplevel *t = ws->findToplevel(check)) {
t->setSurface(surface);
}
}
);
m_shell = m_display->createShell(m_display);
m_shell->create();
m_display->createShm();
......
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