summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2011-11-23 16:14:12 +0200
committerPekka Paalanen <ppaalanen@gmail.com>2011-11-23 16:14:12 +0200
commit56cdea96f067782b69e90573c7ec0dec3a9eb166 (patch)
tree2dcfb20572697f8c812c365c066998a895507c5b
parent02453dd699291cd6ef8f3e06ab24878cac9cc2aa (diff)
shell: add private surface struct
Add a pointer to wlsc_surface for shell-private data. This is a temporary solution. Add struct shell_surface, where you can add any shell-private data members related to a wlsc_surface. The getter function takes care of creating the private data if it does not exist yet. Not used anywhere yet. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
-rw-r--r--compositor/compositor.c2
-rw-r--r--compositor/compositor.h2
-rw-r--r--compositor/shell.c41
3 files changed, 44 insertions, 1 deletions
diff --git a/compositor/compositor.c b/compositor/compositor.c
index fe123f8..0ae71b6 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -248,7 +248,7 @@ wlsc_surface_create(struct wlsc_compositor *compositor,
{
struct wlsc_surface *surface;
- surface = malloc(sizeof *surface);
+ surface = calloc(1, sizeof *surface);
if (surface == NULL)
return NULL;
diff --git a/compositor/compositor.h b/compositor/compositor.h
index b66903a..4163d04 100644
--- a/compositor/compositor.h
+++ b/compositor/compositor.h
@@ -276,6 +276,8 @@ struct wlsc_surface {
struct wl_buffer *buffer;
struct wl_listener buffer_destroy_listener;
+
+ void *shell_priv;
};
void
diff --git a/compositor/shell.c b/compositor/shell.c
index f8305db..edef868 100644
--- a/compositor/shell.c
+++ b/compositor/shell.c
@@ -58,6 +58,10 @@ struct wl_shell {
struct wl_list hidden_surface_list;
};
+struct shell_surface {
+ struct wl_listener destroy_listener;
+};
+
struct wlsc_move_grab {
struct wl_grab grab;
struct wlsc_surface *surface;
@@ -65,6 +69,43 @@ struct wlsc_move_grab {
};
static void
+destroy_shell_surface(struct shell_surface *priv)
+{
+ wl_list_remove(&priv->destroy_listener.link);
+ free(priv);
+}
+
+static void
+handle_shell_surface_destroy(struct wl_listener *listener,
+ struct wl_resource *resource, uint32_t time)
+{
+ struct shell_surface *priv =
+ container_of(listener, struct shell_surface, destroy_listener);
+ destroy_shell_surface(priv);
+}
+
+static struct shell_surface *
+get_shell_surface(struct wlsc_surface *surface)
+{
+ struct shell_surface *priv;
+
+ if (surface->shell_priv)
+ return surface->shell_priv;
+
+ priv = calloc(1, sizeof *priv);
+ if (!priv)
+ return NULL;
+
+ priv->destroy_listener.func = handle_shell_surface_destroy;
+ wl_list_insert(surface->surface.resource.destroy_listener_list.prev,
+ &priv->destroy_listener.link);
+
+ surface->shell_priv = priv;
+
+ return priv;
+}
+
+static void
move_grab_motion(struct wl_grab *grab,
uint32_t time, int32_t x, int32_t y)
{