libweston-desktop: add set_xwayland_position API

X11 applications expect -geometry command line option to work for
setting the initial window position, but currently this does not work.

Add provision to relay the initial position through libweston-desktop:
- weston_desktop_api gains a new entry set_xwayland_position
- implement set_toplevel_with_position() in xwayland internal interface

Once xwayland plugin starts calling set_toplevel_with_position(),
libweston-desktop can relay that information to a shell if the shell
wants to hear it.

If a shell does not implement the set_xwayland_position hook, the
old behaviour remains: the shell positions xwayland toplevels like any
other.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
diff --git a/libweston-desktop/libweston-desktop.h b/libweston-desktop/libweston-desktop.h
index f77ab55..03b04c7 100644
--- a/libweston-desktop/libweston-desktop.h
+++ b/libweston-desktop/libweston-desktop.h
@@ -80,6 +80,39 @@
 				    bool maximized, void *user_data);
 	void (*minimized_requested)(struct weston_desktop_surface *surface,
 				    void *user_data);
+
+	/** Position suggestion for an Xwayland window
+	 *
+	 * X11 applications assume they can position their windows as necessary,
+	 * which is not possible in Wayland where positioning is driven by the
+	 * shell alone. This function is used to relay absolute position wishes
+	 * from Xwayland clients to the shell.
+	 *
+	 * This is particularly used for mapping windows at specified locations,
+	 * e.g. via the commonly used '-geometry' command line option. In such
+	 * case, a call to surface_added() is immediately followed by
+	 * xwayland_position() if the X11 application specified a position.
+	 * The committed() call that will map the window occurs later, so it
+	 * is recommended to usually store and honour the given position for
+	 * windows that are not yet mapped.
+	 *
+	 * Calls to this function may happen also at other times.
+	 *
+	 * The given coordinates are in the X11 window system coordinate frame
+	 * relative to the X11 root window. Care should be taken to ensure the
+	 * window gets mapped to coordinates that correspond to the proposed
+	 * position from the X11 client perspective.
+	 *
+	 * \param surface The surface in question.
+	 * \param x The absolute X11 coordinate for x.
+	 * \param y The absolute X11 coordinate for y.
+	 * \param user_data The user_data argument passed in to
+	 * weston_desktop_create().
+	 *
+	 * This callback can be NULL.
+	 */
+	void (*set_xwayland_position)(struct weston_desktop_surface *surface,
+				      int32_t x, int32_t y, void *user_data);
 };
 
 void