blob: 4be87e5b8405a61efa3ba2c0c8bdc3413e80d58a [file] [log] [blame]
Giulio Camuffo9c764df2016-06-29 11:54:27 +02001/*
2 * Copyright © 2016 Giulio Camuffo
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#ifndef XWAYLAND_API_H
27#define XWAYLAND_API_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <unistd.h>
34
35#include "plugin-registry.h"
36
37struct weston_compositor;
38struct weston_xwayland;
39
40#define WESTON_XWAYLAND_API_NAME "weston_xwayland_v1"
41
42typedef pid_t
43(*weston_xwayland_spawn_xserver_func_t)(
44 void *user_data, const char *display, int abstract_fd, int unix_fd);
45
46/** The libweston Xwayland API
47 *
48 * This API allows to control the Xwayland libweston module.
49 * The module must be loaded at runtime with \a weston_compositor_load_xwayland,
50 * after which the API can be retrieved by using \a weston_xwayland_get_api.
51 */
52struct weston_xwayland_api {
53 /** Retrieve the Xwayland context object.
54 *
55 * Note that this function does not create a new object, but returns
56 * always the same object per compositor instance.
57 * This function cannot fail, if this API object is valid.
58 *
59 * \param compositor The compositor instance.
60 */
61 struct weston_xwayland *
62 (*get)(struct weston_compositor *compositor);
63
64 /** Listen for X connections.
65 *
66 * This function tells the Xwayland module to start create a X socket
67 * and to listen for client connections. When one such connection is
68 * detected the given \a spawn_func callback will be called to start
69 * the Xwayland process.
70 *
71 * \param xwayland The Xwayland context object.
72 * \param user_data The user data pointer to be passed to \a spawn_func.
73 * \param spawn_func The callback function called to start the Xwayland
74 * server process.
75 *
76 * \return 0 on success, a negative number otherwise.
77 */
78 int
79 (*listen)(struct weston_xwayland *xwayland, void *user_data,
80 weston_xwayland_spawn_xserver_func_t spawn_func);
81
82 /** Notify the Xwayland module the Xwayland server is loaded.
83 *
84 * After the Xwayland server process has been spawned it will notify
85 * the parent that is has finished the initialization by sending a
86 * SIGUSR1 signal.
87 * The caller should listen for that signal and call this function
88 * when it is received.
89 *
90 * \param xwayland The Xwayland context object.
91 * \param client The wl_client object representing the connection of
92 * the Xwayland server process.
93 * \param wm_fd The file descriptor for the wm.
94 */
95 void
96 (*xserver_loaded)(struct weston_xwayland *xwayland,
97 struct wl_client *client, int wm_fd);
98
99 /** Notify the Xwayland module the Xwayland server has exited.
100 *
101 * Whenever the Xwayland server process quits this function should be
102 * called.
103 * The Xwayland module will keep listening for X connections on the
104 * socket, and may call the spawn function again.
105 *
106 * \param xwayland The Xwayland context object.
107 * \param exit_status The exit status of the Xwayland server process.
108 */
109 void
110 (*xserver_exited)(struct weston_xwayland *xwayland, int exit_status);
111};
112
113/** Retrieve the API object for the libweston Xwayland module.
114 *
115 * The module must have been previously loaded by calling
116 * \a weston_compositor_load_xwayland.
117 *
118 * \param compositor The compositor instance.
119 */
120static inline const struct weston_xwayland_api *
121weston_xwayland_get_api(struct weston_compositor *compositor)
122{
123 const void *api;
124 api = weston_plugin_api_get(compositor, WESTON_XWAYLAND_API_NAME,
125 sizeof(struct weston_xwayland_api));
126 /* The cast is necessary to use this function in C++ code */
127 return (const struct weston_xwayland_api *)api;
128}
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif