[PATCH RFC xserver] xwayland: Add xdg-output support

Olivier Fourdan ofourdan at redhat.com
Tue Aug 1 08:26:54 UTC 2017


This was added in  wayland-protocols 1.10.

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 Note: This has not been tested with an actual compositor supporting xdg-output

 configure.ac                  |  2 +-
 hw/xwayland/Makefile.am       |  9 +++++-
 hw/xwayland/xwayland-output.c | 71 +++++++++++++++++++++++++++++++++++++++----
 hw/xwayland/xwayland.c        |  4 +++
 hw/xwayland/xwayland.h        |  3 ++
 meson.build                   |  2 +-
 6 files changed, 82 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8d3c3b55b..3a8c61f69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2353,7 +2353,7 @@ AM_CONDITIONAL(XEPHYR, [test "x$KDRIVE" = xyes && test "x$XEPHYR" = xyes])
 
 dnl Xwayland DDX
 
-XWAYLANDMODULES="wayland-client >= 1.3.0 wayland-protocols >= 1.9 $LIBDRM epoxy"
+XWAYLANDMODULES="wayland-client >= 1.3.0 wayland-protocols >= 1.10 $LIBDRM epoxy"
 if test "x$XF86VIDMODE" = xyes; then
 	XWAYLANDMODULES="$XWAYLANDMODULES $VIDMODEPROTO"
 fi
diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index c14b95b7c..a1eee3e8e 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -59,7 +59,10 @@ Xwayland_built_sources +=					\
 	tablet-unstable-v2-client-protocol.h			\
 	tablet-unstable-v2-protocol.c				\
 	xwayland-keyboard-grab-unstable-v1-protocol.c		\
-	xwayland-keyboard-grab-unstable-v1-client-protocol.h
+	xwayland-keyboard-grab-unstable-v1-client-protocol.h	\
+	xdg-output-unstable-v1-protocol.c			\
+	xdg-output-unstable-v1-client-protocol.h
+
 
 nodist_Xwayland_SOURCES = $(Xwayland_built_sources)
 CLEANFILES = $(Xwayland_built_sources)
@@ -89,6 +92,10 @@ xwayland-keyboard-grab-unstable-v1-protocol.c : $(WAYLAND_PROTOCOLS_DATADIR)/uns
 	$(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
 xwayland-keyboard-grab-unstable-v1-client-protocol.h : $(WAYLAND_PROTOCOLS_DATADIR)/unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml
 	$(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
+xdg-output-unstable-v1-protocol.c : $(WAYLAND_PROTOCOLS_DATADIR)/unstable/xdg-output/xdg-output-unstable-v1.xml
+	$(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
+xdg-output-unstable-v1-client-protocol.h : $(WAYLAND_PROTOCOLS_DATADIR)/unstable/xdg-output/xdg-output-unstable-v1.xml
+	$(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
 
 %-protocol.c : %.xml
 	$(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 460caaf56..1f3eb4f59 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -93,9 +93,12 @@ output_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
                             physical_width, physical_height);
     RROutputSetSubpixelOrder(xwl_output->randr_output,
                              wl_subpixel_to_xrandr(subpixel));
-    xwl_output->x = x;
-    xwl_output->y = y;
 
+    /* Apply the change from wl_output only if xdg-output is not supported */
+    if (!xwl_output->xdg_output) {
+        xwl_output->x = x;
+        xwl_output->y = y;
+    }
     xwl_output->rotation = wl_transform_to_xrandr(transform);
 }
 
@@ -108,8 +111,11 @@ output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
     if (!(flags & WL_OUTPUT_MODE_CURRENT))
         return;
 
-    xwl_output->width = width;
-    xwl_output->height = height;
+    /* Apply the change from wl_output only if xdg-output is not supported */
+    if (!xwl_output->xdg_output) {
+        xwl_output->width = width;
+        xwl_output->height = height;
+    }
     xwl_output->refresh = refresh;
 }
 
@@ -200,10 +206,10 @@ update_screen_size(struct xwl_output *xwl_output, int width, int height)
 }
 
 static void
-output_handle_done(void *data, struct wl_output *wl_output)
+apply_output_change(struct xwl_output *xwl_output)
 {
-    struct xwl_output *it, *xwl_output = data;
     struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
+    struct xwl_output *it;
     int width = 0, height = 0, has_this_output = 0;
     RRModePtr randr_mode;
 
@@ -238,6 +244,16 @@ output_handle_done(void *data, struct wl_output *wl_output)
 }
 
 static void
+output_handle_done(void *data, struct wl_output *wl_output)
+{
+    struct xwl_output *xwl_output = data;
+
+    /* Apply the change from wl_output only if xdg-output is not supported */
+    if (!xwl_output->xdg_output)
+        apply_output_change(xwl_output);
+}
+
+static void
 output_handle_scale(void *data, struct wl_output *wl_output, int32_t factor)
 {
 }
@@ -249,6 +265,40 @@ static const struct wl_output_listener output_listener = {
     output_handle_scale
 };
 
+static void
+xdg_output_handle_logical_position(void *data, struct zxdg_output_v1 *xdg_output,
+                                   int32_t x, int32_t y)
+{
+    struct xwl_output *xwl_output = data;
+
+    xwl_output->x = x;
+    xwl_output->y = y;
+}
+
+static void
+xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output,
+                               int32_t width, int32_t height)
+{
+    struct xwl_output *xwl_output = data;
+
+    xwl_output->width = width;
+    xwl_output->height = height;
+}
+
+static void
+xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output)
+{
+    struct xwl_output *xwl_output = data;
+
+    apply_output_change(xwl_output);
+}
+
+static const struct zxdg_output_v1_listener xdg_output_listener = {
+    xdg_output_handle_logical_position,
+    xdg_output_handle_logical_size,
+    xdg_output_handle_done,
+};
+
 struct xwl_output *
 xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
 {
@@ -293,6 +343,15 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
     RROutputSetCrtcs(xwl_output->randr_output, &xwl_output->randr_crtc, 1);
     RROutputSetConnection(xwl_output->randr_output, RR_Connected);
 
+    if (xwl_screen->xdg_output_manager) {
+        xwl_output->xdg_output =
+            zxdg_output_manager_v1_get_xdg_output (xwl_screen->xdg_output_manager,
+                                                   xwl_output->output);
+        zxdg_output_v1_add_listener(xwl_output->xdg_output,
+                                    &xdg_output_listener,
+                                    xwl_output);
+    }
+
     return xwl_output;
 
 err:
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index cb929cad5..30c99d4d0 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -675,6 +675,10 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id,
         if (xwl_output_create(xwl_screen, id))
             xwl_screen->expecting_event++;
     }
+    else if (strcmp(interface, "zxdg_output_manager_v1") == 0) {
+        xwl_screen->xdg_output_manager =
+            wl_registry_bind(registry, id, &wl_shell_interface, 1);
+    }
 #ifdef GLAMOR_HAS_GBM
     else if (xwl_screen->glamor &&
              strcmp(interface, "wl_drm") == 0 && version >= 2) {
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 6d3edf33b..8f3992660 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -46,6 +46,7 @@
 #include "pointer-constraints-unstable-v1-client-protocol.h"
 #include "tablet-unstable-v2-client-protocol.h"
 #include "xwayland-keyboard-grab-unstable-v1-client-protocol.h"
+#include "xdg-output-unstable-v1-client-protocol.h"
 
 struct xwl_screen {
     int width;
@@ -82,6 +83,7 @@ struct xwl_screen {
     struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
     struct zwp_pointer_constraints_v1 *pointer_constraints;
     struct zwp_xwayland_keyboard_grab_manager_v1 *wp_grab;
+    struct zxdg_output_manager_v1 *xdg_output_manager;
     uint32_t serial;
 
 #define XWL_FORMAT_ARGB8888 (1 << 0)
@@ -258,6 +260,7 @@ struct xwl_tablet_pad {
 struct xwl_output {
     struct xorg_list link;
     struct wl_output *output;
+    struct zxdg_output_v1 *xdg_output;
     uint32_t server_output_id;
     struct xwl_screen *xwl_screen;
     RROutputPtr randr_output;
diff --git a/meson.build b/meson.build
index a36ae9da7..ae65ad2ae 100644
--- a/meson.build
+++ b/meson.build
@@ -98,7 +98,7 @@ if (host_machine.system() != 'darwin' and
 
         xwayland_dep = [
             dependency('wayland-client', version: '>= 1.3.0', required: xwayland_required),
-            dependency('wayland-protocols', version: '>= 1.9.0', required: xwayland_required),
+            dependency('wayland-protocols', version: '>= 1.10.0', required: xwayland_required),
             dependency('libdrm', version: '>= 2.3.1', required: xwayland_required),
             dependency('epoxy', required: xwayland_required),
         ]
-- 
2.13.3



More information about the wayland-devel mailing list