[PATCH 1/3] Add wayland support

Pekka Paalanen ppaalanen at gmail.com
Thu Aug 23 23:52:51 PDT 2012


On Fri, 24 Aug 2012 08:08:22 +0200
Alexander Preisinger <alexander.preisinger at gmail.com> wrote:

> Implements shared routines for initialising wayland and keyboard/pointer input.
> Indepentend from the video output.

Hi,

I have some wayland protocol related comments below, inline.

> ---
>  libvo/wl_common.c | 634 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libvo/wl_common.h | 131 +++++++++++
>  2 files changed, 765 insertions(+)
>  create mode 100644 libvo/wl_common.c
>  create mode 100644 libvo/wl_common.h
> 
> diff --git a/libvo/wl_common.c b/libvo/wl_common.c
> new file mode 100644
> index 0000000..e271e5d
> --- /dev/null
> +++ b/libvo/wl_common.c
> @@ -0,0 +1,634 @@
> +/*
> + * This file is part of MPlayer.
> + *
> + * MPlayer is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * MPlayer is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with MPlayer; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <math.h>
> +#include <inttypes.h>
> +#include <limits.h>
> +#include <assert.h>
> +
> +#include <unistd.h>
> +#include <sys/mman.h>
> +#include <sys/timerfd.h>
> +
> +#include "config.h"
> +#include "bstr.h"
> +#include "options.h"
> +#include "mp_msg.h"
> +#include "mp_fifo.h"
> +#include "libavutil/common.h"
> +#include "talloc.h"
> +
> +#include "wl_common.h"
> +
> +#include "video_out.h"
> +#include "aspect.h"
> +#include "geometry.h"
> +#include "osdep/timer.h"
> +
> +#include "subopt-helper.h"
> +
> +#include "input/input.h"
> +#include "input/keycodes.h"
> +
> +#ifdef CONFIG_GL_WAYLAND
> +    #include <wayland-egl.h>
> +#endif
> +
> +static void create_display (struct wl_priv *wl);
> +static void create_window (struct wl_priv *wl, int width, int height);
> +
> +/* SHELL SURFACE LISTENER  */
> +static void ssurface_handle_ping (void *data,
> +        struct wl_shell_surface *shell_surface, uint32_t serial)
> +{
> +    wl_shell_surface_pong(shell_surface, serial);
> +}
> +
> +static void ssurface_handle_configure (void *data,
> +        struct wl_shell_surface *shell_surface,
> +        uint32_t edges, int32_t width, int32_t height)
> +{
> +}
> +
> +static void ssurface_handle_popup_done (void *data,
> +        struct wl_shell_surface *shell_surface)
> +{
> +}
> +
> +const struct wl_shell_surface_listener shell_surface_listener = {
> +    ssurface_handle_ping,
> +    ssurface_handle_configure,
> +    ssurface_handle_popup_done
> +};
> +
> +/* OUTPUT LISTENER */
> +static void output_handle_geometry (void *data, struct wl_output *wl_output,
> +        int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
> +        int32_t subpixel, const char *make, const char *model,
> +        int32_t transform)
> +{
> +    struct vo_wl_display *d = data;
> +
> +    d->pos_x = x;
> +    d->pos_y = y;

What are these x and y used for? They are leftovers from the global
coordinate system removal, and I don't think they should be used at all.

Doesn't mplayer use the physical dimensions for anything?

Later you would also want to take care of the transform, so that for a
rotated output, you can render a rotated image so that Weston is not
forced to rotate it. That would be especially useful for fullscreen
output, where weston might be able to scan out your image without
compositing it first.

> +}
> +
> +static void output_handle_mode (void *data, struct wl_output *wl_output,
> +        uint32_t flags, int32_t width, int32_t height, int32_t refresh)
> +{
> +    struct vo_wl_display *d = data;
> +
> +    d->output_height = height;
> +    d->output_width = width;
> +    d->mode_received = 1;

You will get a mode event for every possible video mode an output *may*
have. If you want the current mode, you need to pick the one which has
"current" flag set. Note, that the x11 backend of Weston does not
advertise more than one mode, but the DRM backend does.

I think this event is also sent, when the output mode is changed... or
at least when the default mode is changed, not sure if it is emitted
for fullscreen switches.

> +}
> +
> +const struct wl_output_listener output_listener = {
> +    output_handle_geometry,
> +    output_handle_mode
> +};

> +/* POINTER LISTENER */
> +static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
> +        uint32_t serial, struct wl_surface *surface,
> +        wl_fixed_t sx_w, wl_fixed_t sy_w)
> +{

I think you should set a cursor here, or set a NULL cursor if you want
to hide it. Otherwise you probably get whatever cursor another client
set earlier.

> +}
> +
> +static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
> +        uint32_t serial, struct wl_surface *surface)
> +{
> +}
> +
> +static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
> +        uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
> +{
> +}
> +
> +static void pointer_handle_button(void *data, struct wl_pointer *pointer,
> +        uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
> +{
> +    struct wl_priv *wl = data;
> +
> +    mplayer_put_key(wl->vo->key_fifo, MOUSE_BTN0 + (button - BTN_LEFT) |
> +        ((state == WL_POINTER_BUTTON_STATE_PRESSED) ? MP_KEY_DOWN : 0));
> +}
> +
> +static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
> +        uint32_t time, uint32_t axis, wl_fixed_t value)
> +{
> +    struct wl_priv *wl = data;
> +
> +    if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
> +        if (value > 0)
> +	        mplayer_put_key(wl->vo->key_fifo, MOUSE_BTN3);
> +        if (value < 0)
> +	        mplayer_put_key(wl->vo->key_fifo, MOUSE_BTN4);
> +    }

I wonder if you should use the value to determine, how many
"emulated button clicks" to give to mplayer.

> +}
> +
> +static const struct wl_pointer_listener pointer_listener = {
> +	pointer_handle_enter,
> +	pointer_handle_leave,
> +	pointer_handle_motion,
> +	pointer_handle_button,
> +	pointer_handle_axis,
> +};


Thanks,
pq


More information about the wayland-devel mailing list