commit f80b1e4

Michael Forney  ·  2013-10-24 23:08:22 +0000 UTC
parent 47e58d0
Add beginnings of public API
13 files changed,  +804, -7
+1, -1
1@@ -14,7 +14,7 @@ AC_USE_SYSTEM_EXTENSIONS
2 AM_PROG_AR
3 LT_INIT
4 
5-AC_CONFIG_SRCDIR([libswc/compositor.c])
6+AC_CONFIG_SRCDIR([libswc/swc.c])
7 AC_CONFIG_MACRO_DIR([m4])
8 
9 PKG_PROG_PKG_CONFIG([0.9.0])
+8, -0
 1@@ -4,6 +4,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(PROTOCOL_DIR)
 2 AM_CFLAGS = $(drm_CFLAGS) $(pixman_CFLAGS) $(wld_CFLAGS) $(libevdev_CFLAGS)
 3 
 4 lib_LTLIBRARIES = libswc.la
 5+include_HEADERS = swc.h
 6 
 7 libswc_la_SOURCES = \
 8     compositor.c compositor.h \
 9@@ -29,6 +30,13 @@ libswc_la_SOURCES = \
10     drm_buffer.c drm_buffer.h \
11     ../protocol/wayland-drm-protocol.c
12 
13+# Public interface
14+libswc_la_SOURCES += \
15+    swc.c swc.h \
16+    window.c window.h \
17+    shell.c shell.h \
18+    shell_surface.c shell_surface.h
19+
20 libswc_la_LIBADD = $(wayland_server_LIBS) $(udev_LIBS) $(libevdev_LIBS) \
21                    $(xkbcommon_LIBS) $(drm_LIBS) $(pixman_LIBS) $(wld_LIBS) \
22                    ../launch/liblaunch-protocol.la
+2, -6
 1@@ -1,15 +1,11 @@
 2 #ifndef SWC_EVENT_H
 3 #define SWC_EVENT_H
 4 
 5+#include "swc.h"
 6+
 7 #include <stdint.h>
 8 #include <wayland-server.h>
 9 
10-struct swc_event
11-{
12-    uint32_t type;
13-    void * data;
14-};
15-
16 static inline void swc_send_event(struct wl_signal * signal, uint32_t type,
17                                   void * event_data)
18 {
+71, -0
 1@@ -0,0 +1,71 @@
 2+/* swc: swc/internal.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_INTERNAL_H
26+#define SWC_INTERNAL_H
27+
28+#include "util.h"
29+
30+#define INTERNAL_DECL(type, name)                                           \
31+    struct                                                                  \
32+    {                                                                       \
33+        struct swc_ ## type name;                                           \
34+        struct swc_ ## type ## _internal _ ## name ## _internal;            \
35+    }
36+
37+#define INTERNAL_ASSOCIATIONS(ptr, base)                                    \
38+    INTERNAL_ASSOCIATION(window, ptr,                                       \
39+    base)
40+
41+#if defined(__has_feature)
42+#   define HAVE_GENERIC __has_extension(c_generic_selections)
43+/* GCC doesn't have _Generic support, even with -std=c11 */
44+#elif __STDC_VERSION >= 201112L && !defined(__GNUC__)
45+#   define HAVE_GENERIC 1
46+#else
47+#   define HAVE_GENERIC 0
48+#endif
49+
50+#if HAVE_GENERIC
51+#   define INTERNAL_ASSOCIATION(type, ptr, next)                            \
52+        struct swc_ ## type *:                                              \
53+            &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal          \
54+        next
55+#   define INTERNAL(ptr)                                                    \
56+        _Generic(ptr, INTERNAL_ASSOCIATIONS(ptr,))
57+#else
58+/* If we don't have _Generic, emulate it with __builtin_choose_expr. */
59+#   define INTERNAL_ASSOCIATION(type, ptr, next)                            \
60+        __builtin_choose_expr(                                              \
61+        __builtin_types_compatible_p(typeof(ptr), struct swc_ ## type *),   \
62+        &((INTERNAL_DECL(type, dummy) *) ptr)->_dummy_internal, next)
63+#   define INTERNAL(ptr) \
64+        INTERNAL_ASSOCIATIONS(ptr, (void) 0)
65+#endif
66+
67+#define CONTAINER_OF_INTERNAL(ptr, type, member)                            \
68+    &CONTAINER_OF(ptr, INTERNAL_DECL(type, dummy),                          \
69+                  _dummy_internal.member)->dummy
70+
71+#endif
72+
+34, -0
 1@@ -0,0 +1,34 @@
 2+/* swc: swc/private.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_PRIVATE_H
26+#define SWC_PRIVATE_H
27+
28+struct swc_compositor;
29+struct swc_window_manager;
30+
31+extern struct swc_compositor * compositor;
32+extern const struct swc_window_manager * window_manager;
33+
34+#endif
35+
+75, -0
 1@@ -0,0 +1,75 @@
 2+/* swc: libswc/shell.c
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#include "shell.h"
26+#include "shell_surface.h"
27+
28+#include <wayland-server.h>
29+
30+static struct
31+{
32+    struct wl_global * global;
33+} shell;
34+
35+static void get_shell_surface(struct wl_client * client,
36+                              struct wl_resource * resource, uint32_t id,
37+                              struct wl_resource * surface_resource)
38+{
39+    struct swc_surface * surface = wl_resource_get_user_data(surface_resource);
40+    struct swc_shell_surface * shell_surface;
41+
42+    shell_surface = swc_shell_surface_new(client, id, surface);
43+
44+    if (!shell_surface)
45+        wl_resource_post_no_memory(resource);
46+}
47+
48+static const struct wl_shell_interface shell_implementation = {
49+    &get_shell_surface
50+};
51+
52+static void bind_shell(struct wl_client * client, void * data,
53+                       uint32_t version, uint32_t id)
54+{
55+    struct wl_resource * resource;
56+
57+    if (version >= 1)
58+        version = 1;
59+
60+    resource = wl_resource_create(client, &wl_shell_interface, version, id);
61+    wl_resource_set_implementation(resource, &shell_implementation, NULL, NULL);
62+}
63+
64+bool swc_shell_initialize(struct wl_display * display)
65+{
66+    shell.global = wl_global_create(display, &wl_shell_interface, 1, NULL,
67+                                    &bind_shell);
68+
69+    return shell.global;
70+}
71+
72+void swc_shell_finalize()
73+{
74+    wl_global_destroy(shell.global);
75+}
76+
+35, -0
 1@@ -0,0 +1,35 @@
 2+/* swc: libswc/shell.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_SHELL_H
26+#define SWC_SHELL_H
27+
28+#include <stdbool.h>
29+
30+struct wl_display;
31+
32+bool swc_shell_initialize(struct wl_display * display);
33+void swc_shell_finalize();
34+
35+#endif
36+
+191, -0
  1@@ -0,0 +1,191 @@
  2+/* swc: libswc/shell_surface.c
  3+ *
  4+ * Copyright (c) 2013 Michael Forney
  5+ *
  6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
  7+ * of this software and associated documentation files (the "Software"), to deal
  8+ * in the Software without restriction, including without limitation the rights
  9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10+ * copies of the Software, and to permit persons to whom the Software is
 11+ * furnished to do so, subject to the following conditions:
 12+ *
 13+ * The above copyright notice and this permission notice shall be included in
 14+ * all copies or substantial portions of the Software.
 15+ *
 16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 22+ * SOFTWARE.
 23+ */
 24+
 25+#include "swc.h"
 26+#include "window.h"
 27+#include "internal.h"
 28+#include "shell_surface.h"
 29+#include "compositor_surface.h"
 30+
 31+#include <stdlib.h>
 32+
 33+struct swc_shell_surface
 34+{
 35+    INTERNAL_DECL(window, window);
 36+
 37+    struct wl_resource * resource;
 38+
 39+    enum
 40+    {
 41+        SHELL_SURFACE_TYPE_UNSPECIFIED,
 42+        SHELL_SURFACE_TYPE_TOPLEVEL,
 43+        SHELL_SURFACE_TYPE_TRANSIENT,
 44+        SHELL_SURFACE_TYPE_FULLSCREEN,
 45+        SHELL_SURFACE_TYPE_POPUP,
 46+        SHELL_SURFACE_TYPE_MAXIMIZED
 47+    } type;
 48+};
 49+
 50+static void pong(struct wl_client * client, struct wl_resource * resource,
 51+                 uint32_t serial)
 52+{
 53+}
 54+
 55+static void move(struct wl_client * client, struct wl_resource * resource,
 56+                 struct wl_resource * seat_resource, uint32_t serial)
 57+{
 58+}
 59+
 60+static void resize(struct wl_client * client, struct wl_resource * resource,
 61+                   struct wl_resource * seat_resource, uint32_t serial,
 62+                   uint32_t edges)
 63+{
 64+}
 65+
 66+static void set_toplevel(struct wl_client * client,
 67+                         struct wl_resource * resource)
 68+{
 69+    struct swc_shell_surface * shell_surface
 70+        = wl_resource_get_user_data(resource);
 71+
 72+    if (shell_surface->type == SHELL_SURFACE_TYPE_TOPLEVEL)
 73+        return;
 74+
 75+    shell_surface->type = SHELL_SURFACE_TYPE_TOPLEVEL;
 76+    swc_window_set_state(&shell_surface->window, SWC_WINDOW_STATE_TOPLEVEL);
 77+}
 78+
 79+static void set_transient(struct wl_client * client,
 80+                          struct wl_resource * resource,
 81+                          struct wl_resource * parent_resource,
 82+                          int32_t x, int32_t y, uint32_t flags)
 83+{
 84+    struct swc_shell_surface * shell_surface
 85+        = wl_resource_get_user_data(resource);
 86+    struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
 87+
 88+    swc_surface_move(INTERNAL(&shell_surface->window)->surface,
 89+                     parent->geometry.x + x, parent->geometry.y + y);
 90+    swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
 91+
 92+    /* XXX: Handle transient */
 93+}
 94+
 95+static void set_fullscreen(struct wl_client * client,
 96+                           struct wl_resource * resource,
 97+                           uint32_t method, uint32_t framerate,
 98+                           struct wl_resource * output_resource)
 99+{
100+    /* XXX: Handle fullscreen */
101+}
102+
103+static void set_popup(struct wl_client * client, struct wl_resource * resource,
104+                      struct wl_resource * seat_resource, uint32_t serial,
105+                      struct wl_resource * parent_resource,
106+                      int32_t x, int32_t y, uint32_t flags)
107+{
108+    struct swc_shell_surface * shell_surface
109+        = wl_resource_get_user_data(resource);
110+    struct swc_surface * parent = wl_resource_get_user_data(parent_resource);
111+
112+    swc_surface_move(INTERNAL(&shell_surface->window)->surface,
113+                     parent->geometry.x + x, parent->geometry.y + y);
114+    swc_compositor_surface_show(INTERNAL(&shell_surface->window)->surface);
115+
116+    /* XXX: Handle popup */
117+}
118+
119+static void set_maximized(struct wl_client * client,
120+                          struct wl_resource * resource,
121+                          struct wl_resource * output_resource)
122+{
123+    /* XXX: Handle maximized */
124+}
125+
126+static void set_title(struct wl_client * client, struct wl_resource * resource,
127+                      const char * title)
128+{
129+    struct swc_shell_surface * shell_surface
130+        = wl_resource_get_user_data(resource);
131+
132+    swc_window_set_title(&shell_surface->window, title, -1);
133+}
134+
135+static void set_class(struct wl_client * client, struct wl_resource * resource,
136+                      const char * class)
137+{
138+    struct swc_shell_surface * shell_surface
139+        = wl_resource_get_user_data(resource);
140+
141+    swc_window_set_class(&shell_surface->window, class);
142+}
143+
144+static const struct wl_shell_surface_interface shell_surface_implementation = {
145+    .pong = &pong,
146+    .move = &move,
147+    .resize = &resize,
148+    .set_toplevel = &set_toplevel,
149+    .set_transient = &set_transient,
150+    .set_fullscreen = &set_fullscreen,
151+    .set_popup = &set_popup,
152+    .set_maximized = &set_maximized,
153+    .set_title = &set_title,
154+    .set_class = &set_class
155+};
156+
157+static void configure(struct swc_window * window, int32_t x, int32_t y,
158+                      uint32_t width, uint32_t height)
159+{
160+    struct swc_shell_surface * shell_surface
161+        = CONTAINER_OF(window, typeof(*shell_surface), window);
162+
163+    wl_shell_surface_send_configure
164+        (shell_surface->resource, WL_SHELL_SURFACE_RESIZE_NONE, width, height);
165+}
166+
167+static const struct swc_window_impl shell_window_impl = {
168+    .configure = &configure
169+};
170+
171+struct swc_shell_surface * swc_shell_surface_new
172+    (struct wl_client * client, uint32_t id, struct swc_surface * surface)
173+{
174+    struct swc_shell_surface * shell_surface;
175+
176+    shell_surface = malloc(sizeof *shell_surface);
177+
178+    if (!shell_surface)
179+        return NULL;
180+
181+    shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED;
182+    swc_window_initialize(&shell_surface->window, &shell_window_impl, surface);
183+
184+    shell_surface->resource = wl_resource_create
185+        (client, &wl_shell_surface_interface, 1, id);
186+    wl_resource_set_implementation(shell_surface->resource,
187+                                   &shell_surface_implementation,
188+                                   shell_surface, NULL);
189+
190+    return shell_surface;
191+}
192+
+37, -0
 1@@ -0,0 +1,37 @@
 2+/* swc: libswc/shell_surface.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_SHELL_SURFACE_H
26+#define SWC_SHELL_SURFACE_H
27+
28+#include <stdint.h>
29+
30+struct swc_shell_surface;
31+struct swc_surface;
32+struct wl_client;
33+
34+struct swc_shell_surface * swc_shell_surface_new
35+    (struct wl_client * client, uint32_t id, struct swc_surface * surface);
36+
37+#endif
38+
+68, -0
 1@@ -0,0 +1,68 @@
 2+/* swc: libswc/swc.c
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#include "swc.h"
26+#include "compositor.h"
27+#include "shell.h"
28+
29+static struct
30+{
31+    struct swc_compositor compositor;
32+} swc;
33+
34+struct swc_compositor * compositor = &swc.compositor;
35+const struct swc_window_manager * window_manager;
36+
37+bool swc_initialize(struct wl_display * display,
38+                    const struct swc_window_manager * wm)
39+{
40+    window_manager = wm;
41+
42+    if (!swc_compositor_initialize(&swc.compositor, display))
43+    {
44+        fprintf(stderr, "Could not initialize compositor\n");
45+        goto error0;
46+    }
47+
48+    swc_compositor_add_globals(&swc.compositor, display);
49+
50+    if (!swc_shell_initialize(display))
51+    {
52+        fprintf(stderr, "Could not initialize shell\n");
53+        goto error1;
54+    }
55+
56+    return true;
57+
58+  error1:
59+    swc_compositor_finish(&swc.compositor);
60+  error0:
61+    return false;
62+}
63+
64+void swc_finalize()
65+{
66+    swc_shell_finalize();
67+    swc_compositor_finish(&swc.compositor);
68+}
69+
+85, -0
 1@@ -0,0 +1,85 @@
 2+/* swc: libswc/swc.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_H
26+#define SWC_H
27+
28+#include <stdbool.h>
29+#include <stdint.h>
30+#include <wayland-server.h>
31+
32+/* Windows {{{ */
33+enum
34+{
35+    SWC_WINDOW_DESTROYED,
36+    SWC_WINDOW_TITLE_CHANGED,
37+    SWC_WINDOW_CLASS_CHANGED,
38+    SWC_WINDOW_STATE_CHANGED,
39+    SWC_WINDOW_ENTERED,
40+    SWC_WINDOW_RESIZED
41+};
42+
43+struct swc_window
44+{
45+    struct wl_signal event_signal;
46+
47+    char * title;
48+    char * class;
49+
50+    enum
51+    {
52+        SWC_WINDOW_STATE_WITHDRAWN,
53+        SWC_WINDOW_STATE_TOPLEVEL
54+    } state;
55+};
56+
57+struct swc_window_manager
58+{
59+    void (* new_window)(struct swc_window * window);
60+};
61+
62+void swc_window_show(struct swc_window * window);
63+void swc_window_hide(struct swc_window * window);
64+void swc_window_focus(struct swc_window * window);
65+void swc_window_set_geometry(struct swc_window * window, int32_t x, int32_t y,
66+                             uint32_t width, uint32_t height);
67+void swc_window_set_border(struct swc_window * window,
68+                           uint32_t color, uint32_t width);
69+/* }}} */
70+
71+/* Events {{{ */
72+struct swc_event
73+{
74+    uint32_t type;
75+    void * data;
76+};
77+/* }}} */
78+
79+bool swc_initialize(struct wl_display * display,
80+                    const struct swc_window_manager * window_manager);
81+void swc_finalize();
82+
83+#endif
84+
85+/* vim: set fdm=marker : */
86+
+137, -0
  1@@ -0,0 +1,137 @@
  2+/* swc: libswc/window.c
  3+ *
  4+ * Copyright (c) 2013 Michael Forney
  5+ *
  6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
  7+ * of this software and associated documentation files (the "Software"), to deal
  8+ * in the Software without restriction, including without limitation the rights
  9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10+ * copies of the Software, and to permit persons to whom the Software is
 11+ * furnished to do so, subject to the following conditions:
 12+ *
 13+ * The above copyright notice and this permission notice shall be included in
 14+ * all copies or substantial portions of the Software.
 15+ *
 16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 22+ * SOFTWARE.
 23+ */
 24+
 25+#include "swc.h"
 26+#include "window.h"
 27+#include "compositor.h"
 28+#include "compositor_surface.h"
 29+#include "internal.h"
 30+#include "private.h"
 31+
 32+#include <stdlib.h>
 33+#include <string.h>
 34+
 35+void swc_window_show(struct swc_window * window)
 36+{
 37+    swc_compositor_surface_show(INTERNAL(window)->surface);
 38+}
 39+
 40+void swc_window_hide(struct swc_window * window)
 41+{
 42+    swc_compositor_surface_hide(INTERNAL(window)->surface);
 43+}
 44+
 45+void swc_window_focus(struct swc_window * window)
 46+{
 47+    if (INTERNAL(window)->impl->focus)
 48+        INTERNAL(window)->impl->focus(window);
 49+
 50+    swc_keyboard_set_focus(&compositor->seat.keyboard,
 51+                           INTERNAL(window)->surface);
 52+}
 53+
 54+void swc_window_set_geometry(struct swc_window * window, int32_t x, int32_t y,
 55+                             uint32_t width, uint32_t height)
 56+{
 57+    if (INTERNAL(window)->impl->configure)
 58+        INTERNAL(window)->impl->configure(window, x, y, width, height);
 59+
 60+    swc_surface_move(INTERNAL(window)->surface, x, y);
 61+}
 62+
 63+void swc_window_set_border(struct swc_window * window,
 64+                           uint32_t border_color, uint32_t border_width)
 65+{
 66+    struct swc_surface * surface = INTERNAL(window)->surface;
 67+
 68+    swc_compositor_surface_set_border_color(surface, border_color);
 69+    swc_compositor_surface_set_border_width(surface, border_width);
 70+}
 71+
 72+static void destroy(struct wl_client * client, struct wl_resource * resource)
 73+{
 74+    wl_resource_destroy(resource);
 75+}
 76+
 77+static void handle_surface_destroy(struct wl_listener * listener, void * data)
 78+{
 79+    struct swc_window * window = CONTAINER_OF_INTERNAL
 80+        (listener, window, surface_destroy_listener);
 81+
 82+    swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL);
 83+    free(window);
 84+}
 85+
 86+bool swc_window_initialize(struct swc_window * window,
 87+                           const struct swc_window_impl * impl,
 88+                           struct swc_surface * surface)
 89+{
 90+    window->title = NULL;
 91+    window->class = NULL;
 92+    wl_signal_init(&window->event_signal);
 93+    INTERNAL(window)->surface = surface;
 94+    INTERNAL(window)->surface_destroy_listener.notify = &handle_surface_destroy;
 95+    INTERNAL(window)->impl = impl;
 96+
 97+    wl_resource_add_destroy_listener
 98+        (surface->resource, &INTERNAL(window)->surface_destroy_listener);
 99+    swc_surface_set_class(surface, &compositor->compositor_class);
100+
101+    window_manager->new_window(window);
102+
103+    return true;
104+}
105+
106+struct swc_window * swc_window_get(struct swc_surface * surface)
107+{
108+    struct wl_listener * listener;
109+
110+    listener = wl_resource_get_destroy_listener(surface->resource,
111+                                                &handle_surface_destroy);
112+
113+    return listener ? CONTAINER_OF_INTERNAL(listener, window,
114+                                            surface_destroy_listener)
115+                    : NULL;
116+}
117+
118+void swc_window_set_title(struct swc_window * window,
119+                          const char * title, size_t length)
120+{
121+    free(window->title);
122+    window->title = strndup(title, length);
123+    swc_send_event(&window->event_signal, SWC_WINDOW_TITLE_CHANGED, NULL);
124+}
125+
126+void swc_window_set_class(struct swc_window * window, const char * class)
127+{
128+    free(window->class);
129+    window->class = strdup(class);
130+    swc_send_event(&window->event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
131+}
132+
133+void swc_window_set_state(struct swc_window * window, uint32_t state)
134+{
135+    window->state = state;
136+    swc_send_event(&window->event_signal, state, NULL);
137+}
138+
+60, -0
 1@@ -0,0 +1,60 @@
 2+/* swc: libswc/window.h
 3+ *
 4+ * Copyright (c) 2013 Michael Forney
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_WINDOW_H
26+#define SWC_WINDOW_H
27+
28+#include <stdint.h>
29+#include <wayland-server.h>
30+
31+struct swc_window;
32+
33+struct swc_window_impl
34+{
35+    void (* configure)(struct swc_window * window, int32_t x, int32_t y,
36+                       uint32_t width, uint32_t height);
37+    void (* focus)(struct swc_window * window);
38+};
39+
40+struct swc_window_internal
41+{
42+    struct swc_surface * surface;
43+    struct wl_listener surface_destroy_listener;
44+    const struct swc_window_impl * impl;
45+};
46+
47+bool swc_window_initialize(struct swc_window * window,
48+                           const struct swc_window_impl * impl,
49+                           struct swc_surface * surface);
50+
51+struct swc_window * swc_window_get(struct swc_surface * surface);
52+
53+void swc_window_set_title(struct swc_window * window,
54+                          const char * title, size_t length);
55+
56+void swc_window_set_class(struct swc_window * window, const char * class);
57+
58+void swc_window_set_state(struct swc_window * window, uint32_t state);
59+
60+#endif
61+