commit f80b1e4a83aaa30612f8e883197d58c53b4e7c10
parent 47e58d0327d135426c868b91e2bb34e9afbc696a
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 24 Oct 2013 16:08:22 -0700
Add beginnings of public API
Diffstat:
13 files changed, 804 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -14,7 +14,7 @@ AC_USE_SYSTEM_EXTENSIONS
AM_PROG_AR
LT_INIT
-AC_CONFIG_SRCDIR([libswc/compositor.c])
+AC_CONFIG_SRCDIR([libswc/swc.c])
AC_CONFIG_MACRO_DIR([m4])
PKG_PROG_PKG_CONFIG([0.9.0])
diff --git a/libswc/Makefile.am b/libswc/Makefile.am
@@ -4,6 +4,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(PROTOCOL_DIR)
AM_CFLAGS = $(drm_CFLAGS) $(pixman_CFLAGS) $(wld_CFLAGS) $(libevdev_CFLAGS)
lib_LTLIBRARIES = libswc.la
+include_HEADERS = swc.h
libswc_la_SOURCES = \
compositor.c compositor.h \
@@ -29,6 +30,13 @@ libswc_la_SOURCES = \
drm_buffer.c drm_buffer.h \
../protocol/wayland-drm-protocol.c
+# Public interface
+libswc_la_SOURCES += \
+ swc.c swc.h \
+ window.c window.h \
+ shell.c shell.h \
+ shell_surface.c shell_surface.h
+
libswc_la_LIBADD = $(wayland_server_LIBS) $(udev_LIBS) $(libevdev_LIBS) \
$(xkbcommon_LIBS) $(drm_LIBS) $(pixman_LIBS) $(wld_LIBS) \
../launch/liblaunch-protocol.la
diff --git a/libswc/event.h b/libswc/event.h
@@ -1,15 +1,11 @@
#ifndef SWC_EVENT_H
#define SWC_EVENT_H
+#include "swc.h"
+
#include <stdint.h>
#include <wayland-server.h>
-struct swc_event
-{
- uint32_t type;
- void * data;
-};
-
static inline void swc_send_event(struct wl_signal * signal, uint32_t type,
void * event_data)
{
diff --git a/libswc/internal.h b/libswc/internal.h
@@ -0,0 +1,71 @@
+/* swc: swc/internal.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_INTERNAL_H
+#define SWC_INTERNAL_H
+
+#include "util.h"
+
+#define INTERNAL_DECL(type, name) \
+ struct \
+ { \
+ struct swc_ ## type name; \
+ struct swc_ ## type ## _internal _ ## name ## _internal; \
+ }
+
+#define INTERNAL_ASSOCIATIONS(ptr, base) \
+ INTERNAL_ASSOCIATION(window, ptr, \
+ base)
+
+#if defined(__has_feature)
+# define HAVE_GENERIC __has_extension(c_generic_selections)
+/* GCC doesn't have _Generic support, even with -std=c11 */
+#elif __STDC_VERSION >= 201112L && !defined(__GNUC__)
+# define HAVE_GENERIC 1
+#else
+# define HAVE_GENERIC 0
+#endif
+
+#if HAVE_GENERIC
+# define INTERNAL_ASSOCIATION(type, ptr, next) \
+ struct swc_ ## type *: \
+ &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal \
+ next
+# define INTERNAL(ptr) \
+ _Generic(ptr, INTERNAL_ASSOCIATIONS(ptr,))
+#else
+/* If we don't have _Generic, emulate it with __builtin_choose_expr. */
+# define INTERNAL_ASSOCIATION(type, ptr, next) \
+ __builtin_choose_expr( \
+ __builtin_types_compatible_p(typeof(ptr), struct swc_ ## type *), \
+ &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal, next)
+# define INTERNAL(ptr) \
+ INTERNAL_ASSOCIATIONS(ptr, (void) 0)
+#endif
+
+#define CONTAINER_OF_INTERNAL(ptr, type, member) \
+ &CONTAINER_OF(ptr, INTERNAL_DECL(type, dummy), \
+ _dummy_internal.member)->dummy
+
+#endif
+
diff --git a/libswc/private.h b/libswc/private.h
@@ -0,0 +1,34 @@
+/* swc: swc/private.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_PRIVATE_H
+#define SWC_PRIVATE_H
+
+struct swc_compositor;
+struct swc_window_manager;
+
+extern struct swc_compositor * compositor;
+extern const struct swc_window_manager * window_manager;
+
+#endif
+
diff --git a/libswc/shell.c b/libswc/shell.c
@@ -0,0 +1,75 @@
+/* swc: libswc/shell.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "shell.h"
+#include "shell_surface.h"
+
+#include <wayland-server.h>
+
+static struct
+{
+ struct wl_global * global;
+} shell;
+
+static void get_shell_surface(struct wl_client * client,
+ struct wl_resource * resource, uint32_t id,
+ struct wl_resource * surface_resource)
+{
+ struct swc_surface * surface = wl_resource_get_user_data(surface_resource);
+ struct swc_shell_surface * shell_surface;
+
+ shell_surface = swc_shell_surface_new(client, id, surface);
+
+ if (!shell_surface)
+ wl_resource_post_no_memory(resource);
+}
+
+static const struct wl_shell_interface shell_implementation = {
+ &get_shell_surface
+};
+
+static void bind_shell(struct wl_client * client, void * data,
+ uint32_t version, uint32_t id)
+{
+ struct wl_resource * resource;
+
+ if (version >= 1)
+ version = 1;
+
+ resource = wl_resource_create(client, &wl_shell_interface, version, id);
+ wl_resource_set_implementation(resource, &shell_implementation, NULL, NULL);
+}
+
+bool swc_shell_initialize(struct wl_display * display)
+{
+ shell.global = wl_global_create(display, &wl_shell_interface, 1, NULL,
+ &bind_shell);
+
+ return shell.global;
+}
+
+void swc_shell_finalize()
+{
+ wl_global_destroy(shell.global);
+}
+
diff --git a/libswc/shell.h b/libswc/shell.h
@@ -0,0 +1,35 @@
+/* swc: libswc/shell.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_SHELL_H
+#define SWC_SHELL_H
+
+#include <stdbool.h>
+
+struct wl_display;
+
+bool swc_shell_initialize(struct wl_display * display);
+void swc_shell_finalize();
+
+#endif
+
diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c
@@ -0,0 +1,191 @@
+/* swc: libswc/shell_surface.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "swc.h"
+#include "window.h"
+#include "internal.h"
+#include "shell_surface.h"
+#include "compositor_surface.h"
+
+#include <stdlib.h>
+
+struct swc_shell_surface
+{
+ INTERNAL_DECL(window, window);
+
+ struct wl_resource * resource;
+
+ enum
+ {
+ SHELL_SURFACE_TYPE_UNSPECIFIED,
+ SHELL_SURFACE_TYPE_TOPLEVEL,
+ SHELL_SURFACE_TYPE_TRANSIENT,
+ SHELL_SURFACE_TYPE_FULLSCREEN,
+ SHELL_SURFACE_TYPE_POPUP,
+ SHELL_SURFACE_TYPE_MAXIMIZED
+ } type;
+};
+
+static void pong(struct wl_client * client, struct wl_resource * resource,
+ uint32_t serial)
+{
+}
+
+static void move(struct wl_client * client, struct wl_resource * resource,
+ struct wl_resource * seat_resource, uint32_t serial)
+{
+}
+
+static void resize(struct wl_client * client, struct wl_resource * resource,
+ struct wl_resource * seat_resource, uint32_t serial,
+ uint32_t edges)
+{
+}
+
+static void set_toplevel(struct wl_client * client,
+ struct wl_resource * resource)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+
+ if (shell_surface->type == SHELL_SURFACE_TYPE_TOPLEVEL)
+ return;
+
+ shell_surface->type = SHELL_SURFACE_TYPE_TOPLEVEL;
+ swc_window_set_state(&shell_surface->window, SWC_WINDOW_STATE_TOPLEVEL);
+}
+
+static void set_transient(struct wl_client * client,
+ struct wl_resource * resource,
+ struct wl_resource * parent_resource,
+ int32_t x, int32_t y, uint32_t flags)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+ struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
+
+ swc_surface_move(INTERNAL(&shell_surface->window)->surface,
+ parent->geometry.x + x, parent->geometry.y + y);
+ swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
+
+ /* XXX: Handle transient */
+}
+
+static void set_fullscreen(struct wl_client * client,
+ struct wl_resource * resource,
+ uint32_t method, uint32_t framerate,
+ struct wl_resource * output_resource)
+{
+ /* XXX: Handle fullscreen */
+}
+
+static void set_popup(struct wl_client * client, struct wl_resource * resource,
+ struct wl_resource * seat_resource, uint32_t serial,
+ struct wl_resource * parent_resource,
+ int32_t x, int32_t y, uint32_t flags)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+ struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
+
+ swc_surface_move(INTERNAL(&shell_surface->window)->surface,
+ parent->geometry.x + x, parent->geometry.y + y);
+ swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
+
+ /* XXX: Handle popup */
+}
+
+static void set_maximized(struct wl_client * client,
+ struct wl_resource * resource,
+ struct wl_resource * output_resource)
+{
+ /* XXX: Handle maximized */
+}
+
+static void set_title(struct wl_client * client, struct wl_resource * resource,
+ const char * title)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+
+ swc_window_set_title(&shell_surface->window, title, -1);
+}
+
+static void set_class(struct wl_client * client, struct wl_resource * resource,
+ const char * class)
+{
+ struct swc_shell_surface * shell_surface
+ = wl_resource_get_user_data(resource);
+
+ swc_window_set_class(&shell_surface->window, class);
+}
+
+static const struct wl_shell_surface_interface shell_surface_implementation = {
+ .pong = &pong,
+ .move = &move,
+ .resize = &resize,
+ .set_toplevel = &set_toplevel,
+ .set_transient = &set_transient,
+ .set_fullscreen = &set_fullscreen,
+ .set_popup = &set_popup,
+ .set_maximized = &set_maximized,
+ .set_title = &set_title,
+ .set_class = &set_class
+};
+
+static void configure(struct swc_window * window, int32_t x, int32_t y,
+ uint32_t width, uint32_t height)
+{
+ struct swc_shell_surface * shell_surface
+ = CONTAINER_OF(window, typeof(*shell_surface), window);
+
+ wl_shell_surface_send_configure
+ (shell_surface->resource, WL_SHELL_SURFACE_RESIZE_NONE, width, height);
+}
+
+static const struct swc_window_impl shell_window_impl = {
+ .configure = &configure
+};
+
+struct swc_shell_surface * swc_shell_surface_new
+ (struct wl_client * client, uint32_t id, struct swc_surface * surface)
+{
+ struct swc_shell_surface * shell_surface;
+
+ shell_surface = malloc(sizeof *shell_surface);
+
+ if (!shell_surface)
+ return NULL;
+
+ shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
+ swc_window_initialize(&shell_surface->window, &shell_window_impl, surface);
+
+ shell_surface->resource = wl_resource_create
+ (client, &wl_shell_surface_interface, 1, id);
+ wl_resource_set_implementation(shell_surface->resource,
+ &shell_surface_implementation,
+ shell_surface, NULL);
+
+ return shell_surface;
+}
+
diff --git a/libswc/shell_surface.h b/libswc/shell_surface.h
@@ -0,0 +1,37 @@
+/* swc: libswc/shell_surface.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_SHELL_SURFACE_H
+#define SWC_SHELL_SURFACE_H
+
+#include <stdint.h>
+
+struct swc_shell_surface;
+struct swc_surface;
+struct wl_client;
+
+struct swc_shell_surface * swc_shell_surface_new
+ (struct wl_client * client, uint32_t id, struct swc_surface * surface);
+
+#endif
+
diff --git a/libswc/swc.c b/libswc/swc.c
@@ -0,0 +1,68 @@
+/* swc: libswc/swc.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "swc.h"
+#include "compositor.h"
+#include "shell.h"
+
+static struct
+{
+ struct swc_compositor compositor;
+} swc;
+
+struct swc_compositor * compositor = &swc.compositor;
+const struct swc_window_manager * window_manager;
+
+bool swc_initialize(struct wl_display * display,
+ const struct swc_window_manager * wm)
+{
+ window_manager = wm;
+
+ if (!swc_compositor_initialize(&swc.compositor, display))
+ {
+ fprintf(stderr, "Could not initialize compositor\n");
+ goto error0;
+ }
+
+ swc_compositor_add_globals(&swc.compositor, display);
+
+ if (!swc_shell_initialize(display))
+ {
+ fprintf(stderr, "Could not initialize shell\n");
+ goto error1;
+ }
+
+ return true;
+
+ error1:
+ swc_compositor_finish(&swc.compositor);
+ error0:
+ return false;
+}
+
+void swc_finalize()
+{
+ swc_shell_finalize();
+ swc_compositor_finish(&swc.compositor);
+}
+
diff --git a/libswc/swc.h b/libswc/swc.h
@@ -0,0 +1,85 @@
+/* swc: libswc/swc.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_H
+#define SWC_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <wayland-server.h>
+
+/* Windows {{{ */
+enum
+{
+ SWC_WINDOW_DESTROYED,
+ SWC_WINDOW_TITLE_CHANGED,
+ SWC_WINDOW_CLASS_CHANGED,
+ SWC_WINDOW_STATE_CHANGED,
+ SWC_WINDOW_ENTERED,
+ SWC_WINDOW_RESIZED
+};
+
+struct swc_window
+{
+ struct wl_signal event_signal;
+
+ char * title;
+ char * class;
+
+ enum
+ {
+ SWC_WINDOW_STATE_WITHDRAWN,
+ SWC_WINDOW_STATE_TOPLEVEL
+ } state;
+};
+
+struct swc_window_manager
+{
+ void (* new_window)(struct swc_window * window);
+};
+
+void swc_window_show(struct swc_window * window);
+void swc_window_hide(struct swc_window * window);
+void swc_window_focus(struct swc_window * window);
+void swc_window_set_geometry(struct swc_window * window, int32_t x, int32_t y,
+ uint32_t width, uint32_t height);
+void swc_window_set_border(struct swc_window * window,
+ uint32_t color, uint32_t width);
+/* }}} */
+
+/* Events {{{ */
+struct swc_event
+{
+ uint32_t type;
+ void * data;
+};
+/* }}} */
+
+bool swc_initialize(struct wl_display * display,
+ const struct swc_window_manager * window_manager);
+void swc_finalize();
+
+#endif
+
+/* vim: set fdm=marker : */
+
diff --git a/libswc/window.c b/libswc/window.c
@@ -0,0 +1,137 @@
+/* swc: libswc/window.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "swc.h"
+#include "window.h"
+#include "compositor.h"
+#include "compositor_surface.h"
+#include "internal.h"
+#include "private.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+void swc_window_show(struct swc_window * window)
+{
+ swc_compositor_surface_show(INTERNAL(window)->surface);
+}
+
+void swc_window_hide(struct swc_window * window)
+{
+ swc_compositor_surface_hide(INTERNAL(window)->surface);
+}
+
+void swc_window_focus(struct swc_window * window)
+{
+ if (INTERNAL(window)->impl->focus)
+ INTERNAL(window)->impl->focus(window);
+
+ swc_keyboard_set_focus(&compositor->seat.keyboard,
+ INTERNAL(window)->surface);
+}
+
+void swc_window_set_geometry(struct swc_window * window, int32_t x, int32_t y,
+ uint32_t width, uint32_t height)
+{
+ if (INTERNAL(window)->impl->configure)
+ INTERNAL(window)->impl->configure(window, x, y, width, height);
+
+ swc_surface_move(INTERNAL(window)->surface, x, y);
+}
+
+void swc_window_set_border(struct swc_window * window,
+ uint32_t border_color, uint32_t border_width)
+{
+ struct swc_surface * surface = INTERNAL(window)->surface;
+
+ swc_compositor_surface_set_border_color(surface, border_color);
+ swc_compositor_surface_set_border_width(surface, border_width);
+}
+
+static void destroy(struct wl_client * client, struct wl_resource * resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void handle_surface_destroy(struct wl_listener * listener, void * data)
+{
+ struct swc_window * window = CONTAINER_OF_INTERNAL
+ (listener, window, surface_destroy_listener);
+
+ swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
+ free(window);
+}
+
+bool swc_window_initialize(struct swc_window * window,
+ const struct swc_window_impl * impl,
+ struct swc_surface * surface)
+{
+ window->title = NULL;
+ window->class = NULL;
+ wl_signal_init(&window->event_signal);
+ INTERNAL(window)->surface = surface;
+ INTERNAL(window)->surface_destroy_listener.notify = &handle_surface_destroy;
+ INTERNAL(window)->impl = impl;
+
+ wl_resource_add_destroy_listener
+ (surface->resource, &INTERNAL(window)->surface_destroy_listener);
+ swc_surface_set_class(surface, &compositor->compositor_class);
+
+ window_manager->new_window(window);
+
+ return true;
+}
+
+struct swc_window * swc_window_get(struct swc_surface * surface)
+{
+ struct wl_listener * listener;
+
+ listener = wl_resource_get_destroy_listener(surface->resource,
+ &handle_surface_destroy);
+
+ return listener ? CONTAINER_OF_INTERNAL(listener, window,
+ surface_destroy_listener)
+ : NULL;
+}
+
+void swc_window_set_title(struct swc_window * window,
+ const char * title, size_t length)
+{
+ free(window->title);
+ window->title = strndup(title, length);
+ swc_send_event(&window->event_signal, SWC_WINDOW_TITLE_CHANGED, NULL);
+}
+
+void swc_window_set_class(struct swc_window * window, const char * class)
+{
+ free(window->class);
+ window->class = strdup(class);
+ swc_send_event(&window->event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
+}
+
+void swc_window_set_state(struct swc_window * window, uint32_t state)
+{
+ window->state = state;
+ swc_send_event(&window->event_signal, state, NULL);
+}
+
diff --git a/libswc/window.h b/libswc/window.h
@@ -0,0 +1,60 @@
+/* swc: libswc/window.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SWC_WINDOW_H
+#define SWC_WINDOW_H
+
+#include <stdint.h>
+#include <wayland-server.h>
+
+struct swc_window;
+
+struct swc_window_impl
+{
+ void (* configure)(struct swc_window * window, int32_t x, int32_t y,
+ uint32_t width, uint32_t height);
+ void (* focus)(struct swc_window * window);
+};
+
+struct swc_window_internal
+{
+ struct swc_surface * surface;
+ struct wl_listener surface_destroy_listener;
+ const struct swc_window_impl * impl;
+};
+
+bool swc_window_initialize(struct swc_window * window,
+ const struct swc_window_impl * impl,
+ struct swc_surface * surface);
+
+struct swc_window * swc_window_get(struct swc_surface * surface);
+
+void swc_window_set_title(struct swc_window * window,
+ const char * title, size_t length);
+
+void swc_window_set_class(struct swc_window * window, const char * class);
+
+void swc_window_set_state(struct swc_window * window, uint32_t state);
+
+#endif
+