[RFC weston 2/2] RFC: Example of using plugin-registry
Pekka Paalanen
ppaalanen at gmail.com
Wed Mar 23 13:56:37 UTC 2016
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
The desktop shell plugin exports what is essentially the struct
weston_shell_interface API. Xwayland is modified to show how it could
find that API.
This patch does not compile, it is merely a demonstration of the
concept: the intended way to use the plugin registry.
Noteworthy things:
- shell-api.h is a model for how to write public API headers
- no specific fields are needed in struct weston_compositor
- the module context, struct desktop_shell, can be found through
weston_compositor in desktop_shell_get()
- when is weston_plugin_api_register() called
- when is weston_pluhin_api_get() called (via
weston_get_desktop_shell_api())
- what needs to be stored in the importer context (struct
weston_xserver)
---
desktop-shell/shell-api.h | 125 ++++++++++++++++++++++++++++++++++++++++++++++
desktop-shell/shell.c | 27 ++++++++++
xwayland/launcher.c | 16 ++++++
xwayland/xwayland.h | 3 ++
4 files changed, 171 insertions(+)
create mode 100644 desktop-shell/shell-api.h
diff --git a/desktop-shell/shell-api.h b/desktop-shell/shell-api.h
new file mode 100644
index 0000000..3896950
--- /dev/null
+++ b/desktop-shell/shell-api.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright © 2008-2011 Kristian Høgsberg
+ * Copyright © 2012 Collabora, Ltd.
+ * Copyright (C) 2016 DENSO CORPORATION
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WESTON_DESKTOP_SHELL_API_H
+#define WESTON_DESKTOP_SHELL_API_H
+
+#include "plugin-registry.h"
+
+#include <stdint.h>
+#include <sys/types.h>
+
+/** \file
+ *
+ * This is the API exported by the desktop shell plugin for transplanting
+ * windows from other window systems. It is published through
+ * weston_plugin_api_register().
+ */
+
+struct desktop_shell;
+
+struct weston_surface;
+struct weston_pointer;
+struct weston_output;
+struct shell_surface;
+
+struct weston_shell_client {
+ void
+ (*send_configure)(struct weston_surface *surface,
+ int32_t width, int32_t height);
+
+ void
+ (*send_position)(struct weston_surface *surface,
+ int32_t x, int32_t y);
+};
+
+#define WESTON_DESKTOP_SHELL_API_NAME "desktop-shell-v1"
+
+/** The desktop shell window API
+ *
+ * Desktop shell is a Weston plugin that provides window management for
+ * desktop applications. Other plugins can use this API to transplant
+ * windows from other window systems, provided there is a conversion
+ * application already creating wl_surfaces.
+ */
+struct weston_shell_api {
+ struct desktop_shell *
+ get_desktop_shell(struct weston_compositor *compositor);
+
+ struct shell_surface *
+ (*create_shell_surface)(struct desktop_shell *shell,
+ struct weston_surface *surface,
+ const struct weston_shell_client *client);
+
+ void
+ (*set_toplevel)(struct shell_surface *shsurf);
+
+ void
+ (*set_transient)(struct shell_surface *shsurf,
+ struct weston_surface *parent,
+ int x, int y, uint32_t flags);
+
+ void
+ (*set_fullscreen)(struct shell_surface *shsurf,
+ uint32_t method,
+ uint32_t framerate,
+ struct weston_output *output);
+
+ void
+ (*set_xwayland)(struct shell_surface *shsurf,
+ int x, int y, uint32_t flags);
+
+ int
+ (*move)(struct shell_surface *shsurf, struct weston_pointer *pointer);
+
+ int
+ (*resize)(struct shell_surface *shsurf,
+ struct weston_pointer *pointer, uint32_t edges);
+
+ void
+ (*set_title)(struct shell_surface *shsurf, const char *title);
+
+ void
+ (*set_window_geometry)(struct shell_surface *shsurf,
+ int32_t x, int32_t y,
+ int32_t width, int32_t height);
+
+ void
+ (*set_maximized)(struct shell_surface *shsurf);
+
+ void
+ (*set_pid)(struct shell_surface *shsurf, pid_t pid);
+};
+
+static inline const struct weston_shell_api *
+weston_get_desktop_shell_api(struct weston_compositor *compositor)
+{
+ return weston_plugin_api_get(compositor, WESTON_DESKTOP_SHELL_API_NAME,
+ sizeof(struct weston_shell_api));
+}
+
+#endif /* WESTON_DESKTOP_SHELL_API_H */
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 24437d8..ff7977d 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -36,6 +36,7 @@
#include <sys/types.h>
#include "shell.h"
+#include "shell-api.h"
#include "weston-desktop-shell-server-protocol.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
@@ -6588,6 +6589,27 @@ handle_seat_created(struct wl_listener *listener, void *data)
create_shell_seat(seat);
}
+static struct desktop_shell *
+desktop_shell_get(struct weston_compositor *compositor)
+{
+ struct wl_listener *listener;
+ struct desktop_shell *shell;
+
+ listener = wl_signal_get(&compositor->destroy_signal, shell_destroy);
+ if (!listener)
+ return NULL;
+
+ shell = container_of(listener, struct desktop_shell, destroy_listener);
+ assert(compositor == shell->compositor);
+
+ return shell;
+}
+
+static const struct weston_shell_api shell_api_impl = {
+ desktop_shell_get,
+ ...
+};
+
WL_EXPORT int
module_init(struct weston_compositor *ec,
int *argc, char *argv[])
@@ -6626,6 +6648,11 @@ module_init(struct weston_compositor *ec,
ec->shell_interface.set_maximized = shell_interface_set_maximized;
ec->shell_interface.set_pid = set_pid;
+ if (weston_plugin_api_register(ec, WESTON_DESKTOP_SHELL_API_NAME,
+ &shell_api_impl,
+ sizeof(shell_api_impl)) < 0)
+ return -1;
+
weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link);
weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link);
weston_layer_init(&shell->background_layer, &shell->panel_layer.link);
diff --git a/xwayland/launcher.c b/xwayland/launcher.c
index db5e1d0..2b086b2 100644
--- a/xwayland/launcher.c
+++ b/xwayland/launcher.c
@@ -348,6 +348,20 @@ weston_xserver_destroy(struct wl_listener *l, void *data)
free(wxs);
}
+static void
+post_init(void *data)
+{
+ struct weston_xserver *wxs = data;
+
+ wxs->shell = NULL;
+ wxs->shell_api = weston_get_desktop_shell_api(wxs->compositor);
+ if (wxs->shell_api)
+ wxs->shell = wxs->shell_api->get_desktop_shell(wxs->compositor);
+
+ if (!wxs->shell)
+ weston_log("Oh noes!\n");
+}
+
WL_EXPORT int
module_init(struct weston_compositor *compositor,
int *argc, char *argv[])
@@ -413,5 +427,7 @@ module_init(struct weston_compositor *compositor,
wxs->destroy_listener.notify = weston_xserver_destroy;
wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener);
+ wl_event_loop_add_idle(wxs->loop, post_init, wxs);
+
return 0;
}
diff --git a/xwayland/xwayland.h b/xwayland/xwayland.h
index b1fd904..175b4d2 100644
--- a/xwayland/xwayland.h
+++ b/xwayland/xwayland.h
@@ -51,6 +51,9 @@ struct weston_xserver {
struct weston_compositor *compositor;
struct weston_wm *wm;
struct wl_listener destroy_listener;
+
+ struct desktop_shell *shell;
+ struct weston_shell_api *shell_api;
};
struct weston_wm {
--
2.7.3
More information about the wayland-devel
mailing list