[PATCH xserver 3/4] xwayland: Attach and configure window only when asked by Wayland

Tiago Vignatti tiago.vignatti at intel.com
Wed Dec 12 07:26:31 PST 2012


Previously, windows were all positioned at (0, 0). Now, with this new
protocol, Wayland can forward the global position to map them correctly.

Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 hw/xfree86/xwayland/xserver.xml        |   33 +++++++++++++++++
 hw/xfree86/xwayland/xwayland-input.c   |    8 +++--
 hw/xfree86/xwayland/xwayland-private.h |    3 ++
 hw/xfree86/xwayland/xwayland-window.c  |    7 +---
 hw/xfree86/xwayland/xwayland.c         |   61 +++++++++++++++++++++++++++++++-
 5 files changed, 102 insertions(+), 10 deletions(-)

diff --git a/hw/xfree86/xwayland/xserver.xml b/hw/xfree86/xwayland/xserver.xml
index 907c882..3779d1a 100644
--- a/hw/xfree86/xwayland/xserver.xml
+++ b/hw/xfree86/xwayland/xserver.xml
@@ -34,6 +34,29 @@
       </description>
       <arg name="fd" type="fd"/>
     </event>
+
+    <event name="map">
+      <description summary="notify X when window can be mapped">
+	Notify X that Window 'id' is ready to be mapped. Effectively this
+	happens after compositor receiving wm.map from WM.
+      </description>
+
+       <arg name="id" type="uint"/>
+    </event>
+
+    <event name="configure">
+      <description summary="notify X about new window configuration">
+	Worth to note that coordinates 'x' and 'y' are global.
+      </description>
+
+      <arg name="id" type="uint"/>
+      <arg name="x" type="int"/>
+      <arg name="y" type="int"/>
+      <arg name="width" type="int"/>
+      <arg name="height" type="int"/>
+      <arg name="edges" type="uint"/>
+    </event>
+
   </interface>
 
   <interface name="wm" version="1">
@@ -45,6 +68,16 @@
       </description>
     </request>
 
+    <request name="map">
+      <description summary="notify compositor when window can be mapped">
+	Notify compositor that Window 'id' is ready to be mapped via X.
+	Effectively this happens after a MapNotify hits the window manager and
+	the compositor in principle would proceed notifying X via xserver.map.
+      </description>
+
+      <arg name="id" type="uint"/>
+    </request>
+
     <request name="set_window">
       <description summary="specify window id, geometries and positioning">
 	Notifies the compositor about X Window id and its configuration
diff --git a/hw/xfree86/xwayland/xwayland-input.c b/hw/xfree86/xwayland/xwayland-input.c
index c78db36..d9872c2 100644
--- a/hw/xfree86/xwayland/xwayland-input.c
+++ b/hw/xfree86/xwayland/xwayland-input.c
@@ -274,6 +274,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
 {
     struct xwl_seat *xwl_seat = data;
     DeviceIntPtr dev = xwl_seat->pointer;
+    int32_t dx, dy;
     int i;
     int sx = wl_fixed_to_int(sx_w);
     int sy = wl_fixed_to_int(sy_w);
@@ -284,7 +285,9 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
 
     xwl_seat->focus_window = wl_surface_get_user_data(surface);
 
-    (*pScreen->SetCursorPosition) (dev, pScreen, sx, sy, TRUE);
+    dx = xwl_seat->focus_window->window->drawable.x;
+    dy = xwl_seat->focus_window->window->drawable.y;
+    (*pScreen->SetCursorPosition) (dev, pScreen, sx + dx, sy + dy, TRUE);
 
     SetDeviceRedirectWindow(xwl_seat->pointer, xwl_seat->focus_window->window);
 
@@ -325,8 +328,7 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
 		      uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
 {
     struct xwl_seat *xwl_seat = data;
-    struct xwl_screen *xwl_screen = xwl_seat->xwl_screen;
-    int32_t dx, dy, lx, ly;
+    int32_t dx, dy;
     int sx = wl_fixed_to_int(sx_w);
     int sy = wl_fixed_to_int(sy_w);
     ValuatorMask mask;
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
index 2716ebe..2ec8981 100644
--- a/hw/xfree86/xwayland/xwayland-private.h
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -113,6 +113,9 @@ xwl_global_get(struct xwl_screen *xwl_screen, const char *interface);
 
 struct xwl_screen *xwl_screen_get(ScreenPtr screen);
 
+void
+xwl_window_attach(struct xwl_window *xwl_window, PixmapPtr pixmap);
+
 void xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrninfo);
 
 int xwl_screen_init_cursor(struct xwl_screen *xwl_screen, ScreenPtr screen);
diff --git a/hw/xfree86/xwayland/xwayland-window.c b/hw/xfree86/xwayland/xwayland-window.c
index 09ebb99..11d3416 100644
--- a/hw/xfree86/xwayland/xwayland-window.c
+++ b/hw/xfree86/xwayland/xwayland-window.c
@@ -59,7 +59,7 @@ static const struct wl_callback_listener free_pixmap_listener = {
 	free_pixmap,
 };
 
-static void
+void
 xwl_window_attach(struct xwl_window *xwl_window, PixmapPtr pixmap)
 {
     struct xwl_screen *xwl_screen = xwl_window->xwl_screen;
@@ -193,12 +193,7 @@ xwl_realize_window(WindowPtr window)
 	return FALSE;
     }
 
-    if (xwl_screen->xorg_server)
-	xserver_set_window_surface(xwl_screen->xorg_server,
-			      xwl_window->surface, window->drawable.id);
-
     wl_surface_set_user_data(xwl_window->surface, xwl_window);
-    xwl_window_attach(xwl_window, (*screen->GetWindowPixmap)(window));
 
     dixSetPrivate(&window->devPrivates,
 		  &xwl_window_private_key, xwl_window);
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index bf90826..a22ee58 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -68,9 +68,68 @@ xserver_listen_socket(void *data, struct xserver *xserver, int fd)
     ListenOnOpenFD(fd, TRUE);
 }
 
+static void
+xserver_handle_map(void *data, struct xserver *xserver, uint32_t id)
+{
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_window *xwl_window, *wtmp;
+    ScreenPtr screen = xwl_screen->screen;
+    WindowPtr pWin;
+
+    xorg_list_for_each_entry_safe(xwl_window, wtmp,
+	                          &xwl_screen->window_list, link) {
+	pWin = xwl_window->window;
+	if (pWin->drawable.id == id) {
+	    xserver_set_window_surface(xwl_screen->xorg_server,
+	                               xwl_window->surface,
+	                               pWin->drawable.id);
+	    xwl_window_attach(xwl_window, (*screen->GetWindowPixmap)(pWin));
+	    return;
+	}
+    }
+}
+
+static void
+xserver_handle_configure(void *data, struct xserver *xserver, uint32_t id,
+			 int x, int y, int32_t width, int32_t height,
+			 uint32_t edges)
+{
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_window *xwl_window, *wtmp;
+    WindowPtr pWin;
+    ClientPtr pClient;
+    int err;
+    uint32_t mask = CWX | CWY;
+    XID vlist[2];
+
+    /* TODO: width and height are unused at moment */
+    vlist[0] = x;
+    vlist[1] = y;
+
+    xorg_list_for_each_entry_safe(xwl_window, wtmp,
+	                          &xwl_screen->window_list, link) {
+	pWin = xwl_window->window;
+	if (pWin->drawable.id == id) {
+	    err =
+	    dixLookupClient(&pClient, pWin->drawable.id, serverClient,
+	                    DixUnknownAccess);
+	    if (err != Success) {
+		ErrorF("Failed to lookup window: 0x%x\n",
+		       (unsigned int) pWin->drawable.id);
+		return;
+	    }
+
+	    ConfigureWindow(pWin, mask, vlist, pClient);
+	    return;
+	}
+    }
+}
+
 static const struct xserver_listener xwl_server_listener = {
     xserver_client,
-    xserver_listen_socket
+    xserver_listen_socket,
+    xserver_handle_map,
+    xserver_handle_configure
 };
 
 static void
-- 
1.7.9.5



More information about the wayland-devel mailing list