From b66d2a3434ebb4193cea22a13f9da2f1597cab52 Mon Sep 17 00:00:00 2001 From: "U. Artie Eoff" Date: Fri, 25 Jan 2013 12:33:57 -0800 Subject: [PATCH] core: add shell_surface wrapper and tests Signed-off-by: U. Artie Eoff --- src/core/Makefile.am | 1 + src/core/shell_surface.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/shell_surface.h | 31 ++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/core/shell_surface.cpp create mode 100644 src/core/shell_surface.h diff --git a/src/core/Makefile.am b/src/core/Makefile.am index e38ee8e..5f3fe8e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -10,6 +10,7 @@ libwfits_core_la_SOURCES = \ pointer.cpp \ surface.cpp \ shm.cpp \ + shell_surface.cpp \ harness.cpp \ test_bind_interface.cpp \ test_cursor.cpp \ diff --git a/src/core/shell_surface.cpp b/src/core/shell_surface.cpp new file mode 100644 index 0000000..d7b49dd --- /dev/null +++ b/src/core/shell_surface.cpp @@ -0,0 +1,65 @@ +#include "shell_surface.h" + +ShellSurface::ShellSurface(const Shell& shell, const Surface& surface) + : shell_(shell) + , surface_(surface) + , wl_shell_surface_( + wl_shell_get_shell_surface(shell, surface)) +{ + ASSERT(wl_shell_surface_ != NULL); + + wl_shell_surface_set_user_data(*this, this); + + static const wl_shell_surface_listener listener = { + ping, configure, popupDone}; + + wl_shell_surface_add_listener(*this, &listener, this); + + wl_shell_surface_set_toplevel(*this); + + shell.display().roundtrip(); +} + +ShellSurface::~ShellSurface() +{ + wl_shell_surface_destroy(*this); +} + +/*static*/ void ShellSurface::ping( + void *data, wl_shell_surface *wl_shell_surface, uint32_t serial) +{ + ShellSurface* shellSurface = static_cast(data); + ASSERT(wl_shell_surface == *shellSurface); + + wl_shell_surface_pong(wl_shell_surface, serial); +} + +/*static*/ void ShellSurface::configure( + void *data, wl_shell_surface *wl_shell_surface, uint32_t edges, + int32_t width, int32_t height) +{ + ShellSurface* shellSurface = static_cast(data); + ASSERT(wl_shell_surface == *shellSurface); +} + +/*static*/ void ShellSurface::popupDone( + void *data, wl_shell_surface *wl_shell_surface) +{ + ShellSurface* shellSurface = static_cast(data); + ASSERT(wl_shell_surface == *shellSurface); +} + +TEST(ShellSurface, "Core/Wrapper") +{ + Display display; + Compositor compositor(display); + Shell shell(display); + Surface surface(compositor); + ShellSurface ss(shell, surface); + + FAIL_UNLESS_EQUAL(&ss.shell(), &shell); + FAIL_UNLESS_EQUAL(&ss.surface(), &surface); + FAIL_IF((wl_shell_surface*)ss == NULL); + FAIL_UNLESS_EQUAL(wl_shell_surface_get_user_data(ss), &ss); +} + diff --git a/src/core/shell_surface.h b/src/core/shell_surface.h new file mode 100644 index 0000000..eba9dd1 --- /dev/null +++ b/src/core/shell_surface.h @@ -0,0 +1,31 @@ +#ifndef __WFITS_CORE_SHELLSURFACE_H__ +#define __WFITS_CORE_SHELLSURFACE_H__ + +#include "shell.h" +#include "surface.h" + +class ShellSurface +{ +public: + ShellSurface(const Shell&, const Surface&); + + virtual ~ShellSurface(); + + operator wl_shell_surface*() const { return wl_shell_surface_; } + const Shell& shell() const { return shell_; } + const Surface& surface() const { return surface_; } + +private: + static void ping( + void*, wl_shell_surface*, uint32_t); + static void configure( + void*, wl_shell_surface*, uint32_t, int32_t, int32_t); + static void popupDone( + void*, wl_shell_surface*); + + const Shell& shell_; + const Surface& surface_; + wl_shell_surface *wl_shell_surface_; +}; + +#endif -- 2.7.4