2012-12-07 21:50:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "../src/compositor.h"
|
|
|
|
#include "wayland-test-server-protocol.h"
|
|
|
|
|
|
|
|
struct weston_test {
|
|
|
|
struct weston_compositor *compositor;
|
|
|
|
struct weston_layer layer;
|
|
|
|
struct weston_process process;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct weston_test_surface {
|
|
|
|
struct weston_surface *surface;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *view;
|
2012-12-07 21:50:29 +00:00
|
|
|
int32_t x, y;
|
|
|
|
struct weston_test *test;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_client_sigchld(struct weston_process *process, int status)
|
|
|
|
{
|
|
|
|
struct weston_test *test =
|
|
|
|
container_of(process, struct weston_test, process);
|
|
|
|
|
|
|
|
assert(status == 0);
|
|
|
|
|
|
|
|
wl_display_terminate(test->compositor->wl_display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct weston_seat *
|
|
|
|
get_seat(struct weston_test *test)
|
|
|
|
{
|
|
|
|
struct wl_list *seat_list;
|
|
|
|
struct weston_seat *seat;
|
|
|
|
|
|
|
|
seat_list = &test->compositor->seat_list;
|
|
|
|
assert(wl_list_length(seat_list) == 1);
|
|
|
|
seat = container_of(seat_list->next, struct weston_seat, link);
|
|
|
|
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notify_pointer_position(struct weston_test *test, struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
struct weston_seat *seat = get_seat(test);
|
2013-05-07 03:19:49 +00:00
|
|
|
struct weston_pointer *pointer = seat->pointer;
|
2012-12-07 21:50:29 +00:00
|
|
|
|
|
|
|
wl_test_send_pointer_position(resource, pointer->x, pointer->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-21 10:29:21 +00:00
|
|
|
test_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height)
|
2012-12-07 21:50:29 +00:00
|
|
|
{
|
2013-03-28 17:02:42 +00:00
|
|
|
struct weston_test_surface *test_surface = surface->configure_private;
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_test *test = test_surface->test;
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (wl_list_empty(&test_surface->view->layer_link))
|
|
|
|
wl_list_insert(&test->layer.view_list,
|
|
|
|
&test_surface->view->layer_link);
|
2012-12-07 21:50:29 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
weston_view_configure(test_surface->view,
|
|
|
|
test_surface->x, test_surface->y,
|
|
|
|
width, height);
|
2012-12-07 21:50:29 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (!weston_view_is_mapped(test_surface->view))
|
|
|
|
weston_view_update_transform(test_surface->view);
|
2012-12-07 21:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_surface(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
int32_t x, int32_t y)
|
|
|
|
{
|
2013-06-25 20:18:35 +00:00
|
|
|
struct weston_surface *surface =
|
|
|
|
wl_resource_get_user_data(surface_resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_test_surface *test_surface;
|
|
|
|
|
2013-03-28 17:02:42 +00:00
|
|
|
test_surface = surface->configure_private;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (!test_surface) {
|
|
|
|
test_surface = malloc(sizeof *test_surface);
|
|
|
|
if (!test_surface) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_surface->view = weston_view_create(surface);
|
|
|
|
if (!test_surface->view) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
free(test_surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->configure_private = test_surface;
|
|
|
|
surface->configure = test_surface_configure;
|
2012-12-07 21:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_surface->surface = surface;
|
2013-06-25 20:18:35 +00:00
|
|
|
test_surface->test = wl_resource_get_user_data(resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
test_surface->x = x;
|
|
|
|
test_surface->y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
move_pointer(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
int32_t x, int32_t y)
|
|
|
|
{
|
2013-06-25 20:18:35 +00:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
2013-05-07 03:19:49 +00:00
|
|
|
struct weston_pointer *pointer = seat->pointer;
|
2012-12-07 21:50:29 +00:00
|
|
|
|
2013-02-25 22:04:47 +00:00
|
|
|
notify_motion(seat, 100,
|
|
|
|
wl_fixed_from_int(x) - pointer->x,
|
|
|
|
wl_fixed_from_int(y) - pointer->y);
|
2012-12-07 21:50:29 +00:00
|
|
|
|
|
|
|
notify_pointer_position(test, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_button(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
int32_t button, uint32_t state)
|
|
|
|
{
|
2013-06-25 20:18:35 +00:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
|
|
|
|
notify_button(seat, 100, button, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_surface(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
|
|
|
struct weston_surface *surface = surface_resource ?
|
2013-06-25 20:18:35 +00:00
|
|
|
wl_resource_get_user_data(surface_resource) : NULL;
|
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_seat *seat;
|
|
|
|
|
|
|
|
seat = get_seat(test);
|
|
|
|
|
|
|
|
if (surface) {
|
|
|
|
weston_surface_activate(surface, seat);
|
2013-05-07 03:19:49 +00:00
|
|
|
notify_keyboard_focus_in(seat, &seat->keyboard->keys,
|
2012-12-07 21:50:29 +00:00
|
|
|
STATE_UPDATE_AUTOMATIC);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notify_keyboard_focus_out(seat);
|
|
|
|
weston_surface_activate(surface, seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_key(struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t key, enum wl_keyboard_key_state state)
|
|
|
|
{
|
2013-06-25 20:18:35 +00:00
|
|
|
struct weston_test *test = wl_resource_get_user_data(resource);
|
2012-12-07 21:50:29 +00:00
|
|
|
struct weston_seat *seat = get_seat(test);
|
|
|
|
|
|
|
|
notify_key(seat, 100, key, state, STATE_UPDATE_AUTOMATIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_test_interface test_implementation = {
|
|
|
|
move_surface,
|
|
|
|
move_pointer,
|
|
|
|
send_button,
|
|
|
|
activate_surface,
|
|
|
|
send_key
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
|
|
|
struct weston_test *test = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-07-03 22:13:33 +00:00
|
|
|
resource = wl_resource_create(client, &wl_test_interface, 1, id);
|
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
&test_implementation, test, NULL);
|
2012-12-07 21:50:29 +00:00
|
|
|
|
|
|
|
notify_pointer_position(test, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
idle_launch_client(void *data)
|
|
|
|
{
|
|
|
|
struct weston_test *test = data;
|
|
|
|
pid_t pid;
|
|
|
|
sigset_t allsigs;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
path = getenv("WESTON_TEST_CLIENT_PATH");
|
|
|
|
if (path == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
if (pid == 0) {
|
|
|
|
sigfillset(&allsigs);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
|
|
|
execl(path, path, NULL);
|
|
|
|
weston_log("compositor: executing '%s' failed: %m\n", path);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
test->process.pid = pid;
|
|
|
|
test->process.cleanup = test_client_sigchld;
|
|
|
|
weston_watch_process(&test->process);
|
|
|
|
}
|
|
|
|
|
|
|
|
WL_EXPORT int
|
2013-02-20 20:37:49 +00:00
|
|
|
module_init(struct weston_compositor *ec,
|
2013-05-14 16:48:26 +00:00
|
|
|
int *argc, char *argv[])
|
2012-12-07 21:50:29 +00:00
|
|
|
{
|
|
|
|
struct weston_test *test;
|
|
|
|
struct wl_event_loop *loop;
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
test = zalloc(sizeof *test);
|
2012-12-07 21:50:29 +00:00
|
|
|
if (test == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
test->compositor = ec;
|
|
|
|
weston_layer_init(&test->layer, &ec->cursor_layer.link);
|
|
|
|
|
2013-07-08 23:03:57 +00:00
|
|
|
if (wl_global_create(ec->wl_display, &wl_test_interface, 1,
|
|
|
|
test, bind_test) == NULL)
|
2012-12-07 21:50:29 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
loop = wl_display_get_event_loop(ec->wl_display);
|
|
|
|
wl_event_loop_add_idle(loop, idle_launch_client, test);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|