[PATCH 1/4] xwayland: Fix the race condition when mapping a surface
Louis-Francis Ratté-Boulianne
lfrb at collabora.com
Tue Jul 30 09:13:43 PDT 2013
From: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Make sure XCB_MAP_NOTIFY has been received and the window id has been set before mapping the shell surface. It fixes race condition making the surface appears at wrong coordinates or with wrong size.
---
src/xwayland/window-manager.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/xwayland/window-manager.c b/src/xwayland/window-manager.c
index 257c108..76294fa 100644
--- a/src/xwayland/window-manager.c
+++ b/src/xwayland/window-manager.c
@@ -117,6 +117,8 @@ struct weston_wm_window {
int override_redirect;
int fullscreen;
int has_alpha;
+ int map_notified;
+ int mapped;
};
static struct weston_wm_window *
@@ -125,6 +127,9 @@ get_wm_window(struct weston_surface *surface);
static void
weston_wm_window_schedule_repaint(struct weston_wm_window *window);
+static void
+xserver_map_shell_surface(struct weston_wm *wm, struct weston_wm_window *window);
+
static int __attribute__ ((format (printf, 1, 2)))
wm_log(const char *fmt, ...)
{
@@ -159,7 +164,6 @@ wm_log_continue(const char *fmt, ...)
#endif
}
-
const char *
get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
{
@@ -585,6 +589,8 @@ weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *eve
weston_wm_window_get_child_position(window, &x, &y);
window->x = configure_notify->x - x;
window->y = configure_notify->y - y;
+
+ weston_log("handle_configure_notify: (%d, %d)\n", window->x, window->y);
}
static void
@@ -805,6 +811,14 @@ static void
weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event)
{
xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event;
+ struct weston_wm_window *window;
+
+ window = hash_table_lookup(wm->window_hash, map_notify->window);
+ weston_log("MAP SURFACE %d, %p\n", map_notify->window, window);
+
+ window->map_notified = 1;
+ if (window->surface != NULL)
+ xserver_map_shell_surface(wm, window);
if (our_resource(wm, map_notify->window)) {
wm_log("XCB_MAP_NOTIFY (window %d, ours)\n",
@@ -853,6 +867,7 @@ weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event)
wm->focus_window = NULL;
if (window->surface)
wl_list_remove(&window->surface_destroy_listener.link);
+ window->mapped = 0;
window->surface = NULL;
}
@@ -1008,6 +1023,9 @@ weston_wm_window_create(struct weston_wm *wm,
window->override_redirect = override;
window->width = width;
window->height = height;
+ window->surface = NULL;
+ window->map_notified = 0;
+ window->mapped = 0;
geometry_reply = xcb_get_geometry_reply(wm->conn, geometry_cookie, NULL);
/* technically we should use XRender and check the visual format's
@@ -1914,9 +1932,14 @@ xserver_map_shell_surface(struct weston_wm *wm,
&wm->server->compositor->shell_interface;
struct theme *t = window->wm->theme;
+ if (window->mapped)
+ return;
+
if (!shell_interface->create_shell_surface)
return;
+ weston_log("MAPPING SURFACE %p\n", window->surface);
+ window->mapped = 1;
window->shsurf =
shell_interface->create_shell_surface(shell_interface->shell,
window->surface,
@@ -1969,7 +1992,9 @@ xserver_set_window_id(struct wl_client *client, struct wl_resource *resource,
&window->surface_destroy_listener);
weston_wm_window_schedule_repaint(window);
- xserver_map_shell_surface(wm, window);
+
+ if (window->map_notified)
+ xserver_map_shell_surface(wm, window);
}
const struct xserver_interface xserver_implementation = {
--
1.8.3.1
More information about the wayland-devel
mailing list