blob: 317533ef8f74194130a8fb87b9394acad5f96752 [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"
Quentin Glidic955cec02016-08-12 10:41:35 +020041#define WESTON_XWAYLAND_SURFACE_API_NAME "weston_xwayland_surface_v1"
Giulio Camuffo9c764df2016-06-29 11:54:27 +020042
43typedef pid_t
44(*weston_xwayland_spawn_xserver_func_t)(
45 void *user_data, const char *display, int abstract_fd, int unix_fd);
46
47/** The libweston Xwayland API
48 *
Bryce Harrington1e6c0fb2016-07-06 15:25:19 -070049 * This API allows control of the Xwayland libweston module.
Giulio Camuffo9c764df2016-06-29 11:54:27 +020050 * The module must be loaded at runtime with \a weston_compositor_load_xwayland,
51 * after which the API can be retrieved by using \a weston_xwayland_get_api.
52 */
53struct weston_xwayland_api {
54 /** Retrieve the Xwayland context object.
55 *
Bryce Harrington1e6c0fb2016-07-06 15:25:19 -070056 * Note that this function does not create a new object, but always
57 * returns the same object per compositor instance.
58 * This function cannot fail while this API object is valid.
Giulio Camuffo9c764df2016-06-29 11:54:27 +020059 *
60 * \param compositor The compositor instance.
61 */
62 struct weston_xwayland *
63 (*get)(struct weston_compositor *compositor);
64
65 /** Listen for X connections.
66 *
Bryce Harrington1e6c0fb2016-07-06 15:25:19 -070067 * This function tells the Xwayland module to begin creating an X socket
68 * and start listening for client connections. When one such connection is
Giulio Camuffo9c764df2016-06-29 11:54:27 +020069 * detected the given \a spawn_func callback will be called to start
70 * the Xwayland process.
71 *
72 * \param xwayland The Xwayland context object.
73 * \param user_data The user data pointer to be passed to \a spawn_func.
74 * \param spawn_func The callback function called to start the Xwayland
75 * server process.
76 *
77 * \return 0 on success, a negative number otherwise.
78 */
79 int
80 (*listen)(struct weston_xwayland *xwayland, void *user_data,
81 weston_xwayland_spawn_xserver_func_t spawn_func);
82
Bryce Harrington1e6c0fb2016-07-06 15:25:19 -070083 /** Notify the Xwayland module that the Xwayland server is loaded.
Giulio Camuffo9c764df2016-06-29 11:54:27 +020084 *
85 * After the Xwayland server process has been spawned it will notify
86 * the parent that is has finished the initialization by sending a
87 * SIGUSR1 signal.
88 * The caller should listen for that signal and call this function
89 * when it is received.
90 *
91 * \param xwayland The Xwayland context object.
92 * \param client The wl_client object representing the connection of
93 * the Xwayland server process.
94 * \param wm_fd The file descriptor for the wm.
95 */
96 void
97 (*xserver_loaded)(struct weston_xwayland *xwayland,
98 struct wl_client *client, int wm_fd);
99
Bryce Harrington1e6c0fb2016-07-06 15:25:19 -0700100 /** Notify the Xwayland module that the Xwayland server has exited.
Giulio Camuffo9c764df2016-06-29 11:54:27 +0200101 *
102 * Whenever the Xwayland server process quits this function should be
103 * called.
104 * The Xwayland module will keep listening for X connections on the
105 * socket, and may call the spawn function again.
106 *
107 * \param xwayland The Xwayland context object.
108 * \param exit_status The exit status of the Xwayland server process.
109 */
110 void
111 (*xserver_exited)(struct weston_xwayland *xwayland, int exit_status);
112};
113
114/** Retrieve the API object for the libweston Xwayland module.
115 *
116 * The module must have been previously loaded by calling
117 * \a weston_compositor_load_xwayland.
118 *
119 * \param compositor The compositor instance.
120 */
121static inline const struct weston_xwayland_api *
122weston_xwayland_get_api(struct weston_compositor *compositor)
123{
124 const void *api;
125 api = weston_plugin_api_get(compositor, WESTON_XWAYLAND_API_NAME,
126 sizeof(struct weston_xwayland_api));
127 /* The cast is necessary to use this function in C++ code */
128 return (const struct weston_xwayland_api *)api;
129}
130
Quentin Glidic955cec02016-08-12 10:41:35 +0200131/** The libweston Xwayland surface API
132 *
133 * This API allows control of the Xwayland libweston module surfaces.
134 * The module must be loaded at runtime with \a weston_compositor_load_xwayland,
135 * after which the API can be retrieved by using
136 * \a weston_xwayland_surface_get_api.
137 */
138struct weston_xwayland_surface_api {
139 /** Check if the surface is an Xwayland surface
140 *
141 * \param surface The surface.
142 */
143 bool
144 (*is_xwayland_surface)(struct weston_surface *surface);
145 /** Notify the Xwayland surface that its position changed.
146 *
147 * \param surface The Xwayland surface.
148 * \param x The x-axis position.
149 * \param y The y-axis position.
150 */
151 void
152 (*send_position)(struct weston_surface *surface, int32_t x, int32_t y);
153};
154
155/** Retrieve the API object for the libweston Xwayland surface.
156 *
157 * The module must have been previously loaded by calling
158 * \a weston_compositor_load_xwayland.
159 *
160 * \param compositor The compositor instance.
161 */
162static inline const struct weston_xwayland_surface_api *
163weston_xwayland_surface_get_api(struct weston_compositor *compositor)
164{
165 const void *api;
166 api = weston_plugin_api_get(compositor, WESTON_XWAYLAND_SURFACE_API_NAME,
167 sizeof(struct weston_xwayland_surface_api));
168 /* The cast is necessary to use this function in C++ code */
169 return (const struct weston_xwayland_surface_api *)api;
170}
171
Giulio Camuffo9c764df2016-06-29 11:54:27 +0200172#ifdef __cplusplus
173}
174#endif
175
176#endif