/* TODO: */
#define PEPPER_ERROR(...)
+#define PEPPER_ASSERT(...)
/* Ping timeout value in ms. */
#define DESKTOP_SHELL_PING_TIMEOUT 200
-typedef struct shell shell_t;
+typedef struct desktop_shell desktop_shell_t;
+typedef struct shell_client shell_client_t;
typedef struct shell_surface shell_surface_t;
-struct shell
+
+struct desktop_shell
{
- pepper_object_t *compositor;
- struct wl_resource *resource;
- struct wl_list shell_surface_list;
+ pepper_object_t *compositor;
+
+ struct wl_list shell_client_list;
+ struct wl_list shell_surface_list;
+
+ /* TODO: */
+ struct wl_listener seat_create_listener;
+ struct wl_listener output_create_listener;
+ struct wl_listener output_change_listener;
};
-enum shell_surface_type
+struct shell_client
+{
+ desktop_shell_t *shell;
+ struct wl_resource *resource;
+ struct wl_list link;
+};
+
+typedef enum
{
SHELL_SURFACE_TYPE_NONE,
SHELL_SURFACE_TYPE_TOPLEVEL,
+ SHELL_SURFACE_TYPE_TRANSIENT,
SHELL_SURFACE_TYPE_FULLSCREEN,
SHELL_SURFACE_TYPE_POPUP,
SHELL_SURFACE_TYPE_MAXIMIZED
-};
+} shell_surface_type_t;
struct shell_surface
{
- shell_t *shell;
+ desktop_shell_t *shell;
- struct wl_client *client;
- struct wl_resource *resource;
+ shell_client_t *shell_client;
- pepper_object_t *parent;
- struct wl_list child_list; /* children surfaces of this */
- struct wl_list parent_link;
+ struct wl_client *client;
+ struct wl_resource *resource;
- pepper_object_t *surface;
- pepper_object_t *view;
+ /* Hierarchy */
+ pepper_object_t *parent;
+ struct wl_list child_list; /* children surfaces of this */
+ struct wl_list parent_link;
- enum shell_surface_type type;
+ /* Contents */
+ pepper_object_t *surface;
+ pepper_object_t *view;
- char *title, *class_;
+ char *title, *class_;
- struct
- {
- int32_t x, y, width, height;
- } geometry, saved;
+ /* Data structures per surface type */
+ shell_surface_type_t type;
/* Ping-Pong */
struct wl_event_source *ping_timer;
uint32_t ping_serial;
pepper_bool_t unresponsive;
+ /* Listeners */
struct wl_listener client_destroy_listener;
struct wl_listener surface_destroy_listener;
struct wl_list link; /* link */
};
-shell_t *
-shell_create(pepper_object_t *compositor, struct wl_client *client,
+shell_client_t *
+shell_client_create(desktop_shell_t *shell, struct wl_client *client,
const struct wl_interface *interface, const void *implementation,
uint32_t version, uint32_t id);
shell_surface_t *
-shell_surface_create(shell_t *shell, pepper_object_t *surface, struct wl_client *client,
+shell_surface_create(shell_client_t *shell, pepper_object_t *surface, struct wl_client *client,
const struct wl_interface *interface,
const void *implemenetation, uint32_t version, uint32_t id);
shell_surface_ping(shell_surface_t *shsurf);
void
-shell_surface_set_type(shell_surface_t *shsurf, enum shell_surface_type type);
+shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type);
void
shell_surface_set_parent(shell_surface_t *shsurf, pepper_object_t *parent_surface);
/* */
shell_surface_t *
-get_shsurf_from_surface(pepper_object_t *surface, shell_t *shell);
+get_shsurf_from_surface(pepper_object_t *surface, desktop_shell_t *shell);
void
set_shsurf_to_surface(pepper_object_t *surface, shell_surface_t *shsurf);
pepper_bool_t
-init_wl_shell(pepper_object_t *compositor);
+init_wl_shell(desktop_shell_t *shell);
}
shell_surface_t *
-shell_surface_create(shell_t *shell, pepper_object_t *surface, struct wl_client *client,
- const struct wl_interface *interface,
+shell_surface_create(shell_client_t *shell_client, pepper_object_t *surface,
+ struct wl_client *client, const struct wl_interface *interface,
const void *implementation, uint32_t version, uint32_t id)
{
- shell_surface_t *shsurf = NULL;
+ shell_surface_t *shsurf = NULL;
shsurf = calloc(1, sizeof(shell_surface_t));
if (!shsurf)
goto error;
}
- shsurf->shell = shell;
- shsurf->client = client;
- shsurf->surface = surface;
- shsurf->view = pepper_compositor_add_surface_view(shell->compositor, surface);
+ shsurf->shell_client = shell_client;
+ shsurf->shell = shell_client->shell;
+ shsurf->client = client;
+ shsurf->surface = surface;
+
+ shsurf->view = pepper_compositor_add_surface_view(shell_client->shell->compositor, surface);
if (!shsurf->view)
{
PEPPER_ERROR("pepper_compositor_add_view failed\n");
goto error;
}
- /* TODO: Need to know about output size */
- shsurf->geometry.x = rand()%10;
- shsurf->geometry.y = rand()%10;
- pepper_view_set_position(shsurf->view, shsurf->geometry.x, shsurf->geometry.y);
-
- wl_list_init(&shsurf->link);
- wl_list_insert(&shell->shell_surface_list, &shsurf->link);
-
wl_list_init(&shsurf->child_list);
wl_list_init(&shsurf->parent_link);
- /* Set shell_surface_t to pepper_surface_t */
- set_shsurf_to_surface(surface, shsurf);
-
wl_resource_set_implementation(shsurf->resource, implementation, shsurf, handle_resource_destroy);
shsurf->client_destroy_listener.notify = handle_client_destroy;
shsurf->surface_destroy_listener.notify = handle_surface_destroy;
pepper_object_add_destroy_listener(surface, &shsurf->surface_destroy_listener);
+ /* Set shell_surface_t to pepper_surface_t */
+ set_shsurf_to_surface(surface, shsurf);
+
return shsurf;
error:
if (shsurf)
free(shsurf);
- wl_client_post_no_memory(client);
return NULL;
}
}
void
-shell_surface_set_type(shell_surface_t *shsurf, enum shell_surface_type type)
+shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type)
{
shsurf->type = type;
}
shell_surface_t *
-get_shsurf_from_surface(pepper_object_t *surface, shell_t *shell)
+get_shsurf_from_surface(pepper_object_t *surface, desktop_shell_t *shell)
{
return pepper_object_get_user_data(surface, shell);
}
#include "desktop-shell-internal.h"
#include <stdlib.h>
-shell_t *
-shell_create(pepper_object_t *compositor, struct wl_client *client,
- const struct wl_interface *interface, const void *implementation,
- uint32_t version, uint32_t id)
+shell_client_t *
+shell_client_create(desktop_shell_t *shell, struct wl_client *client,
+ const struct wl_interface *interface, const void *implementation,
+ uint32_t version, uint32_t id)
{
- shell_t *shell;
+ shell_client_t *shell_client;
- shell = calloc(1, sizeof(shell_t));
- if (!shell)
+ shell_client = calloc(1, sizeof(shell_client_t));
+ if (!shell_client)
{
wl_client_post_no_memory(client);
return NULL;
}
- shell->resource = wl_resource_create(client, interface, version, id);
- if (!shell->resource)
+ shell_client->resource = wl_resource_create(client, interface, version, id);
+ if (!shell_client->resource)
{
wl_client_post_no_memory(client);
- free(shell);
+ free(shell_client);
return NULL;
}
+ wl_resource_set_implementation(shell_client->resource, implementation, shell_client, NULL);
- wl_resource_set_implementation(shell->resource, implementation, shell, NULL);
+ wl_list_insert(&shell->shell_client_list, &shell_client->link);
- shell->compositor = compositor;
-
- wl_list_init(&shell->shell_surface_list);
+ shell_client->shell = shell;
- return shell;
+ return shell_client;
}
PEPPER_API pepper_bool_t
pepper_desktop_shell_init(pepper_object_t *compositor)
{
- if (!init_wl_shell(compositor))
+ desktop_shell_t *shell;
+
+ shell = calloc(1, sizeof(desktop_shell_t));
+ if (!shell)
+ {
+ PEPPER_ERROR("Memory allocation failed\n");
+ return PEPPER_FALSE;
+ }
+
+ shell->compositor = compositor;
+
+ wl_list_init(&shell->shell_client_list);
+ wl_list_init(&shell->shell_surface_list);
+
+ if (!init_wl_shell(shell))
+ {
+ PEPPER_ERROR("wl_shell initialize failed\n");
+ free(shell);
return PEPPER_FALSE;
+ }
return PEPPER_TRUE;
}
#include "desktop-shell-internal.h"
static void
-shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
+wl_shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial)
{
shell_surface_t *shsurf = wl_resource_get_user_data(resource);
}
static void
-shell_surface_move(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_move(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *seat, uint32_t serial)
{
/* TODO */
}
static void
-shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_resize(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *seat, uint32_t serial, uint32_t edges)
{
/* TODO */
}
static void
-shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *resource)
+wl_shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *resource)
{
shell_surface_t *shsurf = wl_resource_get_user_data(resource);
}
static void
-shell_surface_set_transient(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_transient(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *parent, int32_t x, int32_t y, uint32_t flags)
{
/* TODO */
}
static void
-shell_surface_set_fullscreen(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_fullscreen(struct wl_client *client, struct wl_resource *resource,
uint32_t method, uint32_t framerate, struct wl_resource *output)
{
/* TODO */
}
static void
-shell_surface_set_popup(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_popup(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *seat, uint32_t serial, struct wl_resource *parent,
int32_t x, int32_t y, uint32_t flags)
{
}
static void
-shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *output_res)
{
/* TODO */
}
static void
-shell_surface_set_title(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_title(struct wl_client *client, struct wl_resource *resource,
const char *title)
{
shell_surface_t *shsurf = wl_resource_get_user_data(resource);
}
static void
-shell_surface_set_class(struct wl_client *client, struct wl_resource *resource,
+wl_shell_surface_set_class(struct wl_client *client, struct wl_resource *resource,
const char *class_)
{
shell_surface_t *shsurf = wl_resource_get_user_data(resource);
static const struct wl_shell_surface_interface shell_surface_implementation =
{
- shell_surface_pong,
- shell_surface_move,
- shell_surface_resize,
- shell_surface_set_toplevel,
- shell_surface_set_transient,
- shell_surface_set_fullscreen,
- shell_surface_set_popup,
- shell_surface_set_maximized,
- shell_surface_set_title,
- shell_surface_set_class,
+ wl_shell_surface_pong,
+ wl_shell_surface_move,
+ wl_shell_surface_resize,
+ wl_shell_surface_set_toplevel,
+ wl_shell_surface_set_transient,
+ wl_shell_surface_set_fullscreen,
+ wl_shell_surface_set_popup,
+ wl_shell_surface_set_maximized,
+ wl_shell_surface_set_title,
+ wl_shell_surface_set_class,
};
static void
-shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
- uint32_t id, struct wl_resource *surface_resource)
+wl_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource,
+ uint32_t id, struct wl_resource *surface_resource)
{
- pepper_object_t *surface = wl_resource_get_user_data(surface_resource);
- shell_t *shell = wl_resource_get_user_data(resource);
+ shell_client_t *shell_client = wl_resource_get_user_data(resource);
+ pepper_object_t *surface = wl_resource_get_user_data(surface_resource);
+ shell_surface_t *shsurf;
+ /* Only one shell surface can be associated with a given surface.*/
if (!pepper_surface_set_role(surface, "wl_shell_surface"))
{
wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE,
return ;
}
- shell_surface_create(shell, surface, client, &wl_shell_surface_interface,
- &shell_surface_implementation, 1, id);
+ shsurf = shell_surface_create(shell_client, surface, client, &wl_shell_surface_interface,
+ &shell_surface_implementation, 1, id);
+ if (!shsurf)
+ wl_client_post_no_memory(client);
}
static const struct wl_shell_interface shell_implementation =
{
- shell_get_shell_surface,
+ wl_shell_get_shell_surface,
};
static void
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
- shell_create((pepper_object_t *)data, client,
- &wl_shell_interface, &shell_implementation, version, id);
+ shell_client_create((desktop_shell_t *)data, client,
+ &wl_shell_interface, &shell_implementation, version, id);
}
pepper_bool_t
-init_wl_shell(pepper_object_t *compositor)
+init_wl_shell(desktop_shell_t *shell)
{
- struct wl_display *display = pepper_compositor_get_display(compositor);
+ struct wl_display *display = pepper_compositor_get_display(shell->compositor);
struct wl_global *global;
- global = wl_global_create(display, &wl_shell_interface, 1, compositor, bind_shell);
+ global = wl_global_create(display, &wl_shell_interface, 1, shell, bind_shell);
if (!global)
return PEPPER_FALSE;