[vlc-commits] xdg-shell: merge wl_shell support

Rémi Denis-Courmont git at videolan.org
Sun May 20 19:52:37 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 20 20:18:25 2018 +0300| [5c16d65422f8b4a3883b275be93151b158d355a2] | committer: Rémi Denis-Courmont

xdg-shell: merge wl_shell support

Most of the code is still the same.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5c16d65422f8b4a3883b275be93151b158d355a2
---

 modules/video_output/Makefile.am         |  11 +-
 modules/video_output/wayland/shell.c     | 350 -------------------------------
 modules/video_output/wayland/xdg-shell.c |  86 +++++++-
 po/POTFILES.in                           |   1 -
 4 files changed, 87 insertions(+), 361 deletions(-)

diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index e8eeb91fdf..8108ac3ca3 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -202,7 +202,12 @@ video_output/wayland/viewporter-protocol.c: \
 		$(WAYLAND_PROTOCOLS)/stable/viewporter/viewporter.xml
 	$(AM_V_GEN)$(WAYLAND_SCANNER) private-code $< $@
 
-libwl_shell_plugin_la_SOURCES = video_output/wayland/shell.c
+libwl_shell_plugin_la_SOURCES = video_output/wayland/xdg-shell.c
+nodist_libwl_shell_plugin_la_SOURCES = \
+	video_output/wayland/server-decoration-client-protocol.h \
+	video_output/wayland/server-decoration-protocol.c
+libwl_shell_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
+	-I$(builddir)/video_output/wayland
 libwl_shell_plugin_la_CFLAGS = $(WAYLAND_CLIENT_CFLAGS)
 libwl_shell_plugin_la_LIBADD = $(WAYLAND_CLIENT_LIBS) $(LIBPTHREAD)
 
@@ -212,7 +217,7 @@ nodist_libxdg_shell_plugin_la_SOURCES = \
 	video_output/wayland/xdg-shell-protocol.c \
 	video_output/wayland/server-decoration-client-protocol.h \
 	video_output/wayland/server-decoration-protocol.c
-libxdg_shell_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
+libxdg_shell_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DXDG_SHELL \
 	-I$(builddir)/video_output/wayland
 libxdg_shell_plugin_la_CFLAGS = $(WAYLAND_CLIENT_CFLAGS)
 libxdg_shell_plugin_la_LIBADD = $(WAYLAND_CLIENT_LIBS) $(LIBPTHREAD)
@@ -239,7 +244,7 @@ nodist_libxdg_shell_v6_plugin_la_SOURCES = \
 	video_output/wayland/xdg-shell-unstable-v6-protocol.c \
 	video_output/wayland/server-decoration-client-protocol.h \
 	video_output/wayland/server-decoration-protocol.c
-libxdg_shell_v6_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
+libxdg_shell_v6_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DXDG_SHELL \
 	-I$(builddir)/video_output/wayland -DXDG_SHELL_UNSTABLE_VERSION=6
 libxdg_shell_v6_plugin_la_CFLAGS = $(libxdg_shell_plugin_la_CFLAGS)
 libxdg_shell_v6_plugin_la_LIBADD = $(libxdg_shell_plugin_la_LIBADD)
diff --git a/modules/video_output/wayland/shell.c b/modules/video_output/wayland/shell.c
deleted file mode 100644
index f9bd528326..0000000000
--- a/modules/video_output/wayland/shell.c
+++ /dev/null
@@ -1,350 +0,0 @@
-/**
- * @file shell.c
- * @brief Wayland shell surface provider module for VLC media player
- */
-/*****************************************************************************
- * Copyright © 2014 Rémi Denis-Courmont
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <assert.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <string.h>
-#include <poll.h>
-
-#include <wayland-client.h>
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_window.h>
-
-struct vout_window_sys_t
-{
-    struct wl_compositor *compositor;
-    struct wl_shell *shell;
-    struct wl_shell_surface *shell_surface;
-
-    uint32_t top_width;
-    uint32_t top_height;
-    uint32_t fs_width;
-    uint32_t fs_height;
-    bool fullscreen;
-
-    vlc_mutex_t lock;
-    vlc_thread_t thread;
-};
-
-static void cleanup_wl_display_read(void *data)
-{
-    struct wl_display *display = data;
-
-    wl_display_cancel_read(display);
-}
-
-/** Background thread for Wayland shell events handling */
-static void *Thread(void *data)
-{
-    vout_window_t *wnd = data;
-    struct wl_display *display = wnd->display.wl;
-    struct pollfd ufd[1];
-
-    int canc = vlc_savecancel();
-    vlc_cleanup_push(cleanup_wl_display_read, display);
-
-    ufd[0].fd = wl_display_get_fd(display);
-    ufd[0].events = POLLIN;
-
-    for (;;)
-    {
-        while (wl_display_prepare_read(display) != 0)
-            wl_display_dispatch_pending(display);
-
-        wl_display_flush(display);
-        vlc_restorecancel(canc);
-
-        while (poll(ufd, 1, -1) < 0);
-
-        canc = vlc_savecancel();
-        wl_display_read_events(display);
-        wl_display_dispatch_pending(display);
-    }
-    vlc_assert_unreachable();
-    vlc_cleanup_pop();
-    //vlc_restorecancel(canc);
-    //return NULL;
-}
-
-static int Control(vout_window_t *wnd, int cmd, va_list ap)
-{
-    vout_window_sys_t *sys = wnd->sys;
-    struct wl_display *display = wnd->display.wl;
-
-    switch (cmd)
-    {
-        case VOUT_WINDOW_SET_STATE:
-            return VLC_EGENERIC;
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            unsigned width = va_arg (ap, unsigned);
-            unsigned height = va_arg (ap, unsigned);
-
-            vlc_mutex_lock(&sys->lock);
-            sys->top_width = width;
-            sys->top_height = height;
-
-            if (!sys->fullscreen)
-                vout_window_ReportSize(wnd, width, height);
-            vlc_mutex_unlock(&sys->lock);
-            break;
-        }
-        case VOUT_WINDOW_SET_FULLSCREEN:
-            wl_shell_surface_set_fullscreen(sys->shell_surface, 1, 0, NULL);
-
-            vlc_mutex_lock(&sys->lock);
-            sys->fullscreen = true;
-            vout_window_ReportSize(wnd, sys->fs_width, sys->fs_height);
-            vlc_mutex_unlock(&sys->lock);
-            break;
-
-        case VOUT_WINDOW_UNSET_FULLSCREEN:
-            wl_shell_surface_set_toplevel(sys->shell_surface);
-
-            vlc_mutex_lock(&sys->lock);
-            sys->fullscreen = false;
-            vout_window_ReportSize(wnd, sys->top_width, sys->top_height);
-            vlc_mutex_unlock(&sys->lock);
-            break;
-
-        default:
-            msg_Err(wnd, "request %d not implemented", cmd);
-            return VLC_EGENERIC;
-    }
-
-    wl_display_flush(display);
-    return VLC_SUCCESS;
-}
-
-static void shell_surface_ping_cb(void *data,
-                                  struct wl_shell_surface *shell_surface,
-                                  uint32_t serial)
-{
-    (void) data;
-    wl_shell_surface_pong(shell_surface, serial);
-}
-
-static void shell_surface_configure_cb(void *data,
-                                       struct wl_shell_surface *shell_surface,
-                                       uint32_t edges,
-                                       int32_t width, int32_t height)
-{
-    vout_window_t *wnd = data;
-    vout_window_sys_t *sys = wnd->sys;
-
-    msg_Dbg(wnd, "new configuration: %"PRId32"x%"PRId32, width, height);
-    vlc_mutex_lock(&sys->lock);
-    sys->top_width = width;
-    sys->top_height = height;
-
-    if (!sys->fullscreen)
-        vout_window_ReportSize(wnd,  width, height);
-    vlc_mutex_unlock(&sys->lock);
-
-    (void) shell_surface;
-    (void) edges;
-}
-
-static void shell_surface_popup_done_cb(void *data,
-                                        struct wl_shell_surface *shell_surface)
-{
-    (void) data; (void) shell_surface;
-}
-
-static const struct wl_shell_surface_listener shell_surface_cbs =
-{
-    shell_surface_ping_cb,
-    shell_surface_configure_cb,
-    shell_surface_popup_done_cb,
-};
-
-static void registry_global_cb(void *data, struct wl_registry *registry,
-                               uint32_t name, const char *iface, uint32_t vers)
-{
-    vout_window_t *wnd = data;
-    vout_window_sys_t *sys = wnd->sys;
-
-    msg_Dbg(wnd, "global %3"PRIu32": %s version %"PRIu32, name, iface, vers);
-
-    if (!strcmp(iface, "wl_compositor"))
-        sys->compositor = wl_registry_bind(registry, name,
-                                           &wl_compositor_interface,
-                                           (vers < 2) ? vers : 2);
-    else
-    if (!strcmp(iface, "wl_shell"))
-        sys->shell = wl_registry_bind(registry, name, &wl_shell_interface, 1);
-}
-
-static void registry_global_remove_cb(void *data, struct wl_registry *registry,
-                                      uint32_t name)
-{
-    vout_window_t *wnd = data;
-
-    msg_Dbg(wnd, "global remove %3"PRIu32, name);
-    (void) registry;
-}
-
-static const struct wl_registry_listener registry_cbs =
-{
-    registry_global_cb,
-    registry_global_remove_cb,
-};
-
-/**
- * Creates a Wayland shell surface.
- */
-static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
-{
-    vout_window_sys_t *sys = malloc(sizeof (*sys));
-    if (unlikely(sys == NULL))
-        return VLC_ENOMEM;
-
-    sys->compositor = NULL;
-    sys->shell = NULL;
-    sys->shell_surface = NULL;
-    sys->top_width = cfg->width;
-    sys->top_height = cfg->height;
-    sys->fs_width = cfg->width;
-    sys->fs_height = cfg->height;
-    sys->fullscreen = false;
-    vlc_mutex_init(&sys->lock);
-    wnd->sys = sys;
-
-    /* Connect to the display server */
-    char *dpy_name = var_InheritString(wnd, "wl-display");
-    struct wl_display *display = wl_display_connect(dpy_name);
-
-    free(dpy_name);
-
-    if (display == NULL)
-    {
-        vlc_mutex_destroy(&sys->lock);
-        free(sys);
-        return VLC_EGENERIC;
-    }
-
-    /* Find the interesting singleton(s) */
-    struct wl_registry *registry = wl_display_get_registry(display);
-    if (registry == NULL)
-        goto error;
-
-    wl_registry_add_listener(registry, &registry_cbs, wnd);
-    wl_display_roundtrip(display);
-    wl_registry_destroy(registry);
-
-    if (sys->compositor == NULL || sys->shell == NULL)
-        goto error;
-
-    /* Create a surface */
-    struct wl_surface *surface = wl_compositor_create_surface(sys->compositor);
-    if (surface == NULL)
-        goto error;
-
-    struct wl_shell_surface *shell_surface =
-        wl_shell_get_shell_surface(sys->shell, surface);
-    if (shell_surface == NULL)
-        goto error;
-
-    sys->shell_surface = shell_surface;
-
-    wl_shell_surface_add_listener(shell_surface, &shell_surface_cbs, wnd);
-    wl_shell_surface_set_class(shell_surface, PACKAGE_NAME);
-    wl_shell_surface_set_toplevel(shell_surface);
-
-    char *title = var_InheritString(wnd, "video-title");
-    wl_shell_surface_set_title(shell_surface, title ? title
-                                                    : _("VLC media player"));
-    free(title);
-
-    //if (var_InheritBool (wnd, "keyboard-events"))
-    //    do_something();
-
-    wl_display_flush(display);
-
-    wnd->type = VOUT_WINDOW_TYPE_WAYLAND;
-    wnd->handle.wl = surface;
-    wnd->display.wl = display;
-    wnd->control = Control;
-
-    if (vlc_clone (&sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
-        goto error;
-
-    vout_window_ReportSize(wnd, cfg->width, cfg->height);
-    if (cfg->is_fullscreen)
-        vout_window_SetFullScreen(wnd, NULL);
-    return VLC_SUCCESS;
-
-error:
-    if (sys->shell_surface != NULL)
-        wl_shell_surface_destroy(sys->shell_surface);
-    if (sys->shell != NULL)
-        wl_shell_destroy(sys->shell);
-    if (sys->compositor != NULL)
-        wl_compositor_destroy(sys->compositor);
-    wl_display_disconnect(display);
-    vlc_mutex_destroy(&sys->lock);
-    free(sys);
-    return VLC_EGENERIC;
-}
-
-/**
- * Destroys a Wayland shell surface.
- */
-static void Close(vout_window_t *wnd)
-{
-    vout_window_sys_t *sys = wnd->sys;
-
-    vlc_cancel(sys->thread);
-    vlc_join(sys->thread, NULL);
-
-    wl_shell_surface_destroy(sys->shell_surface);
-    wl_surface_destroy(wnd->handle.wl);
-    wl_shell_destroy(sys->shell);
-    wl_compositor_destroy(sys->compositor);
-    wl_display_disconnect(wnd->display.wl);
-    vlc_mutex_destroy(&sys->lock);
-    free(sys);
-}
-
-
-#define DISPLAY_TEXT N_("Wayland display")
-#define DISPLAY_LONGTEXT N_( \
-    "Video will be rendered with this Wayland display. " \
-    "If empty, the default display will be used.")
-
-vlc_module_begin ()
-    set_shortname (N_("WL shell"))
-    set_description (N_("Wayland shell surface"))
-    set_category (CAT_VIDEO)
-    set_subcategory (SUBCAT_VIDEO_VOUT)
-    set_capability ("vout window", 10)
-    set_callbacks (Open, Close)
-
-    add_string ("wl-display", NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
-vlc_module_end ()
diff --git a/modules/video_output/wayland/xdg-shell.c b/modules/video_output/wayland/xdg-shell.c
index 64100e4517..8f056c1357 100644
--- a/modules/video_output/wayland/xdg-shell.c
+++ b/modules/video_output/wayland/xdg-shell.c
@@ -1,6 +1,6 @@
 /**
  * @file xdg-shell.c
- * @brief XDG shell surface provider module for VLC media player
+ * @brief Desktop shell surface provider module for VLC media player
  */
 /*****************************************************************************
  * Copyright © 2014, 2017 Rémi Denis-Courmont
@@ -33,6 +33,7 @@
 #include <poll.h>
 
 #include <wayland-client.h>
+#ifdef XDG_SHELL
 #ifndef XDG_SHELL_UNSTABLE_VERSION
 #include "xdg-shell-client-protocol.h"
 #else
@@ -61,6 +62,28 @@
 # define xdg_toplevel_unset_fullscreen zxdg_toplevel_v6_unset_fullscreen
 # define XDG_TOPLEVEL_STATE_FULLSCREEN ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN
 #endif
+#else
+# define xdg_wm_base wl_shell
+# define xdg_wm_base_interface wl_shell_interface
+# define xdg_wm_base_add_listener(s, l, q) (void)0
+# define xdg_wm_base_destroy wl_shell_destroy
+# define xdg_wm_base_get_xdg_surface wl_shell_get_shell_surface
+# define xdg_wm_base_pong wl_shell_pong
+# define xdg_surface wl_shell_surface
+# define xdg_surface_listener wl_shell_surface_listener
+# define xdg_surface_add_listener wl_shell_surface_add_listener
+# define xdg_surface_destroy wl_shell_surface_destroy
+# define xdg_surface_get_toplevel(s) (s)
+# define xdg_surface_set_window_geometry(s,x,y,w,h) (void)0
+# define xdg_toplevel wl_shell_surface
+# define xdg_toplevel_add_listener(s, l, q) (void)0
+# define xdg_toplevel_destroy(s) (void)0
+# define xdg_toplevel_set_title wl_shell_surface_set_title
+# define xdg_toplevel_set_app_id(s, i) (void)0
+# define xdg_toplevel_set_fullscreen(s, o) \
+         wl_shell_surface_set_fullscreen(s, 1, 0, o)
+# define xdg_toplevel_unset_fullscreen wl_shell_surface_set_toplevel
+#endif
 #include "server-decoration-client-protocol.h"
 
 #include <vlc_common.h>
@@ -199,6 +222,7 @@ static int Control(vout_window_t *wnd, int cmd, va_list ap)
     return VLC_SUCCESS;
 }
 
+#ifdef XDG_SHELL
 static void xdg_toplevel_configure_cb(void *data,
                                       struct xdg_toplevel *toplevel,
                                       int32_t width, int32_t height,
@@ -280,6 +304,41 @@ static const struct xdg_wm_base_listener xdg_wm_base_cbs =
 {
     xdg_wm_base_ping_cb,
 };
+#else
+static void wl_shell_surface_configure_cb(void *data,
+                                          struct wl_shell_surface *toplevel,
+                                          uint32_t edges,
+                                          int32_t width, int32_t height)
+{
+    vout_window_t *wnd = data;
+
+    msg_Dbg(wnd, "new configuration: %"PRId32"x%"PRId32, width, height);
+    vout_window_ReportSize(wnd, width, height);
+    (void) toplevel; (void) edges;
+}
+
+static void wl_shell_surface_ping_cb(void *data,
+                                     struct wl_shell_surface *surface,
+                                     uint32_t serial)
+{
+    (void) data;
+    wl_shell_surface_pong(surface, serial);
+}
+
+static void wl_shell_surface_popup_done_cb(void *data,
+                                           struct wl_shell_surface *surface)
+{
+    (void) data; (void) surface;
+}
+
+static const struct wl_shell_surface_listener wl_shell_surface_cbs =
+{
+    wl_shell_surface_ping_cb,
+    wl_shell_surface_configure_cb,
+    wl_shell_surface_popup_done_cb,
+};
+#define xdg_surface_cbs wl_shell_surface_cbs
+#endif
 
 static void output_geometry_cb(void *data, struct wl_output *output,
                                int32_t x, int32_t y, int32_t w, int32_t h,
@@ -368,10 +427,14 @@ static void registry_global_cb(void *data, struct wl_registry *registry,
         wl_output_add_listener(output, &output_cbs, dd);
     }
     else
-#ifndef XDG_SHELL_UNSTABLE_VERSION
+#ifdef XDG_SHELL
+# ifndef XDG_SHELL_UNSTABLE_VERSION
     if (!strcmp(iface, "xdg_wm_base"))
-#else
+# else
     if (!strcmp(iface, "zxdg_shell_v6"))
+# endif
+#else
+    if (!strcmp(iface, "wl_shell"))
 #endif
         sys->wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface,
                                         1);
@@ -580,19 +643,28 @@ static void Close(vout_window_t *wnd)
     "Fullscreen mode with use the output with this name by default.")
 
 vlc_module_begin()
-#ifndef XDG_SHELL_UNSTABLE_VERSION
+#ifdef XDG_SHELL
+# ifndef XDG_SHELL_UNSTABLE_VERSION
     set_shortname(N_("XDG shell"))
     set_description(N_("XDG shell surface"))
-#else
+# else
     set_shortname(N_("XDG shell v6"))
     set_description(N_("XDG shell (unstable version 6) surface"))
+# endif
+#else
+    set_shortname(N_("WL shell"))
+    set_description(N_("Wayland shell surface"))
 #endif
     set_category(CAT_VIDEO)
     set_subcategory(SUBCAT_VIDEO_VOUT)
-#ifndef XDG_SHELL_UNSTABLE_VERSION
+#ifdef XDG_SHELL
+# ifndef XDG_SHELL_UNSTABLE_VERSION
     set_capability("vout window", 20)
-#else
+# else
     set_capability("vout window", 19)
+# endif
+#else
+    set_capability("vout window", 10)
 #endif
     set_callbacks(Open, Close)
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a2dbb435e7..665e02002a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1178,7 +1178,6 @@ modules/video_output/win32/wingdi.c
 modules/video_output/win32/wgl.c
 modules/video_output/vdummy.c
 modules/video_output/vmem.c
-modules/video_output/wayland/shell.c
 modules/video_output/wayland/shm.c
 modules/video_output/wayland/xdg-shell.c
 modules/video_output/xcb/window.c



More information about the vlc-commits mailing list