Re: [PATCH 2/2] Add a hacky client to test multiple pointer/keyboard resources
On Thu, Sep 19, 2013 at 05:32:01PM +0100, Neil Roberts wrote: > ** I don't expect this patch to be landed but it might be useful if >anyone wants to test the multi-resource stuff ** > > This adds a hacked version of simple-shm which can create multiple > pointer and keyboard resources. The resources are created with the > command line options -p and -k. Both take an integer argument which > specifies the time in seconds after the program is started when the > resource should be created. It can also take a second time with a > colon separator to specify when the resource should be released. > > For example: > > weston-multi-resource -p5 -p7 -k9 -p12:14 > > That would create a pointer after 5 seconds, a second pointer 2 > seconds later, a keyboard 2 seconds after that, a third pointer after > a further 3 seconds and finally after 2 more seconds it would release > that final pointer resource. > > This can be used along with WAYLAND_DEBUG to check that it gets the > right events for example if the pointer is created while the client's > surface already has focus and so on. No, I think this is exactly the kind of clients we have in weston. Most clients test a few specific features in a minimal way and that's that. And lacking a fully automated test case, at least having a simple client that makes it easy to test and verify the feature is critical. Looking through the code, it seems like we should try to find a way to share code a little better. window.c started out this way, but now it feels like too much of a framework and it's hard to pick out a few helper functions. Kristian > --- > clients/Makefile.am | 9 +- > clients/multi-resource.c | 596 > +++ > 2 files changed, 604 insertions(+), 1 deletion(-) > create mode 100644 clients/multi-resource.c > > diff --git a/clients/Makefile.am b/clients/Makefile.am > index 24c6489..d4bee2a 100644 > --- a/clients/Makefile.am > +++ b/clients/Makefile.am > @@ -32,7 +32,8 @@ AM_CPPFLAGS = \ > if BUILD_SIMPLE_CLIENTS > simple_clients_programs =\ > weston-simple-shm \ > - weston-simple-touch > + weston-simple-touch \ > + weston-multi-resource > > weston_simple_shm_SOURCES = simple-shm.c \ > ../shared/os-compatibility.c\ > @@ -45,6 +46,12 @@ weston_simple_touch_SOURCES = simple-touch.c \ > ../shared/os-compatibility.h > weston_simple_touch_CPPFLAGS = $(SIMPLE_CLIENT_CFLAGS) > weston_simple_touch_LDADD = $(SIMPLE_CLIENT_LIBS) > + > +weston_multi_resource_SOURCES = multi-resource.c \ > + ../shared/os-compatibility.c\ > + ../shared/os-compatibility.h > +weston_multi_resource_CPPFLAGS = $(SIMPLE_CLIENT_CFLAGS) > +weston_multi_resource_LDADD = $(SIMPLE_CLIENT_LIBS) > endif > > if BUILD_SIMPLE_EGL_CLIENTS > diff --git a/clients/multi-resource.c b/clients/multi-resource.c > new file mode 100644 > index 000..1c2e5c9 > --- /dev/null > +++ b/clients/multi-resource.c > @@ -0,0 +1,596 @@ > +/* > + * Copyright © 2011 Benjamin Franzke > + * Copyright © 2010, 2013 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 > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include "../shared/os-compatibility.h" > + > +struct device { > + enum { KEYBOARD, POINTER } type; > + > + int start_time; > + int end_time; > + struct wl_list link; > + > + union { > + struct wl_keyboard *keyboard; > + struct wl_pointer *pointer; > + } p; > +}; > + > +struct display { > + struct wl_d
[PATCH 2/2] Add a hacky client to test multiple pointer/keyboard resources
** I don't expect this patch to be landed but it might be useful if anyone wants to test the multi-resource stuff ** This adds a hacked version of simple-shm which can create multiple pointer and keyboard resources. The resources are created with the command line options -p and -k. Both take an integer argument which specifies the time in seconds after the program is started when the resource should be created. It can also take a second time with a colon separator to specify when the resource should be released. For example: weston-multi-resource -p5 -p7 -k9 -p12:14 That would create a pointer after 5 seconds, a second pointer 2 seconds later, a keyboard 2 seconds after that, a third pointer after a further 3 seconds and finally after 2 more seconds it would release that final pointer resource. This can be used along with WAYLAND_DEBUG to check that it gets the right events for example if the pointer is created while the client's surface already has focus and so on. --- clients/Makefile.am | 9 +- clients/multi-resource.c | 596 +++ 2 files changed, 604 insertions(+), 1 deletion(-) create mode 100644 clients/multi-resource.c diff --git a/clients/Makefile.am b/clients/Makefile.am index 24c6489..d4bee2a 100644 --- a/clients/Makefile.am +++ b/clients/Makefile.am @@ -32,7 +32,8 @@ AM_CPPFLAGS = \ if BUILD_SIMPLE_CLIENTS simple_clients_programs = \ weston-simple-shm \ - weston-simple-touch + weston-simple-touch \ + weston-multi-resource weston_simple_shm_SOURCES = simple-shm.c \ ../shared/os-compatibility.c\ @@ -45,6 +46,12 @@ weston_simple_touch_SOURCES = simple-touch.c \ ../shared/os-compatibility.h weston_simple_touch_CPPFLAGS = $(SIMPLE_CLIENT_CFLAGS) weston_simple_touch_LDADD = $(SIMPLE_CLIENT_LIBS) + +weston_multi_resource_SOURCES = multi-resource.c \ + ../shared/os-compatibility.c\ + ../shared/os-compatibility.h +weston_multi_resource_CPPFLAGS = $(SIMPLE_CLIENT_CFLAGS) +weston_multi_resource_LDADD = $(SIMPLE_CLIENT_LIBS) endif if BUILD_SIMPLE_EGL_CLIENTS diff --git a/clients/multi-resource.c b/clients/multi-resource.c new file mode 100644 index 000..1c2e5c9 --- /dev/null +++ b/clients/multi-resource.c @@ -0,0 +1,596 @@ +/* + * Copyright © 2011 Benjamin Franzke + * Copyright © 2010, 2013 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../shared/os-compatibility.h" + +struct device { + enum { KEYBOARD, POINTER } type; + + int start_time; + int end_time; + struct wl_list link; + + union { + struct wl_keyboard *keyboard; + struct wl_pointer *pointer; + } p; +}; + +struct display { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_shell *shell; + struct wl_seat *seat; + struct wl_shm *shm; + uint32_t formats; + struct wl_list devices; +}; + +struct window { + struct display *display; + int width, height; + struct wl_surface *surface; + struct wl_shell_surface *shell_surface; +}; + +static void +buffer_release(void *data, struct wl_buffer *buffer) +{ + wl_buffer_destroy(buffer); +} + +static const struct wl_buffer_listener buffer_listener = { + buffer_release +}; + +static int +attach_buffer(struct window *window, int width, int height) +{ + struct wl_shm_pool *pool; + struct wl_buffer *buffer; + int fd, size, stride; + + stride =