core: add shell_surface wrapper and tests
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Fri, 25 Jan 2013 20:33:57 +0000 (12:33 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Fri, 25 Jan 2013 20:33:57 +0000 (12:33 -0800)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/core/Makefile.am
src/core/shell_surface.cpp [new file with mode: 0644]
src/core/shell_surface.h [new file with mode: 0644]

index e38ee8e..5f3fe8e 100644 (file)
@@ -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 (file)
index 0000000..d7b49dd
--- /dev/null
@@ -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<ShellSurface*>(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<ShellSurface*>(data);
+       ASSERT(wl_shell_surface == *shellSurface);
+}
+
+/*static*/ void ShellSurface::popupDone(
+       void *data, wl_shell_surface *wl_shell_surface)
+{
+       ShellSurface* shellSurface = static_cast<ShellSurface*>(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 (file)
index 0000000..eba9dd1
--- /dev/null
@@ -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