xwm: move set_title and set_pid

Move the calls to set_title() and set_pid() out of
weston_wm_window_read_properties() and into the three callers, each
slightly different.

xserver_map_shell_surface(): already calls these functions after
creating the shell surface, so no need to add calls.

weston_wm_handle_map_request(): can be called only on unmapped (in X11)
Windows, so no need to add calls.

weston_wm_window_draw_decoration(): window->shsurf and window->surface
are either both set or both NULL, so the check for window->shsurf is
removed when moving the set_title() and set_pid() calls under a
window->surface check.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
index ef003a3..5e94bdc 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -452,8 +452,6 @@
 weston_wm_window_read_properties(struct weston_wm_window *window)
 {
 	struct weston_wm *wm = window->wm;
-	const struct weston_desktop_xwayland_interface *xwayland_interface =
-		wm->server->compositor->xwayland_interface;
 
 #define F(field) (&window->field)
 	const struct {
@@ -595,11 +593,6 @@
 		if (!window->machine || strcmp(window->machine, name))
 			window->pid = 0;
 	}
-
-	if (window->shsurf && window->name)
-		xwayland_interface->set_title(window->shsurf, window->name);
-	if (window->shsurf && window->pid > 0)
-		xwayland_interface->set_pid(window->shsurf, window->pid);
 }
 
 #undef TYPE_WM_PROTOCOLS
@@ -1023,6 +1016,19 @@
 
 	weston_wm_window_read_properties(window);
 
+	/* For a new Window, MapRequest happens before the Window is realized
+	 * in Xwayland. We do the real xcb_map_window() here as a response to
+	 * MapRequest. The Window will get realized (wl_surface created in
+	 * Wayland and WL_SURFACE_ID sent in X11) when it has been mapped for
+	 * real.
+	 *
+	 * MapRequest only happens for (X11) unmapped Windows. On UnmapNotify,
+	 * we reset shsurf to NULL, so even if X11 connection races far ahead
+	 * of the Wayland connection and the X11 client is repeatedly mapping
+	 * and unmapping, we will never have shsurf set on MapRequest.
+	 */
+	assert(!window->shsurf);
+
 	if (window->frame_id == XCB_WINDOW_NONE)
 		weston_wm_window_create_frame(window);
 
@@ -1182,6 +1188,10 @@
 
 		xwayland_interface->set_window_geometry(window->shsurf,
 							input_x, input_y, input_w, input_h);
+		if (window->name)
+			xwayland_interface->set_title(window->shsurf, window->name);
+		if (window->pid > 0)
+			xwayland_interface->set_pid(window->shsurf, window->pid);
 	}
 }