diff options
Diffstat (limited to 'include/wlr/backend')
-rw-r--r-- | include/wlr/backend/drm.h | 37 | ||||
-rw-r--r-- | include/wlr/backend/headless.h | 40 | ||||
-rw-r--r-- | include/wlr/backend/interface.h | 32 | ||||
-rw-r--r-- | include/wlr/backend/libinput.h | 27 | ||||
-rw-r--r-- | include/wlr/backend/meson.build | 16 | ||||
-rw-r--r-- | include/wlr/backend/multi.h | 36 | ||||
-rw-r--r-- | include/wlr/backend/session.h | 94 | ||||
-rw-r--r-- | include/wlr/backend/session/interface.h | 22 | ||||
-rw-r--r-- | include/wlr/backend/session/meson.build | 1 | ||||
-rw-r--r-- | include/wlr/backend/wayland.h | 45 | ||||
-rw-r--r-- | include/wlr/backend/x11.h | 20 |
11 files changed, 370 insertions, 0 deletions
diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h new file mode 100644 index 00000000..3724adfb --- /dev/null +++ b/include/wlr/backend/drm.h @@ -0,0 +1,37 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_DRM_H +#define WLR_BACKEND_DRM_H + +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/backend/session.h> +#include <wlr/types/wlr_output.h> + +/** + * Creates a DRM backend using the specified GPU file descriptor (typically from + * a device node in /dev/dri). + * + * To slave this to another DRM backend, pass it as the parent (which _must_ be + * a DRM backend, other kinds of backends raise SIGABRT). + */ +struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, + struct wlr_session *session, int gpu_fd, struct wlr_backend *parent, + wlr_renderer_create_func_t create_renderer_func); + +bool wlr_backend_is_drm(struct wlr_backend *backend); +bool wlr_output_is_drm(struct wlr_output *output); + +/** + * Add mode to the list of available modes + */ +typedef struct _drmModeModeInfo drmModeModeInfo; +bool wlr_drm_connector_add_mode(struct wlr_output *output, const drmModeModeInfo *mode); + +#endif diff --git a/include/wlr/backend/headless.h b/include/wlr/backend/headless.h new file mode 100644 index 00000000..eab102e2 --- /dev/null +++ b/include/wlr/backend/headless.h @@ -0,0 +1,40 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_HEADLESS_H +#define WLR_BACKEND_HEADLESS_H + +#include <wlr/backend.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output.h> + +/** + * Creates a headless backend. A headless backend has no outputs or inputs by + * default. + */ +struct wlr_backend *wlr_headless_backend_create(struct wl_display *display, + wlr_renderer_create_func_t create_renderer_func); +/** + * Create a new headless output backed by an in-memory EGL framebuffer. You can + * read pixels from this framebuffer via wlr_renderer_read_pixels but it is + * otherwise not displayed. + */ +struct wlr_output *wlr_headless_add_output(struct wlr_backend *backend, + unsigned int width, unsigned int height); +/** + * Creates a new input device. The caller is responsible for manually raising + * any event signals on the new input device if it wants to simulate input + * events. + */ +struct wlr_input_device *wlr_headless_add_input_device( + struct wlr_backend *backend, enum wlr_input_device_type type); +bool wlr_backend_is_headless(struct wlr_backend *backend); +bool wlr_input_device_is_headless(struct wlr_input_device *device); +bool wlr_output_is_headless(struct wlr_output *output); + +#endif diff --git a/include/wlr/backend/interface.h b/include/wlr/backend/interface.h new file mode 100644 index 00000000..4a6a5cbb --- /dev/null +++ b/include/wlr/backend/interface.h @@ -0,0 +1,32 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_INTERFACE_H +#define WLR_BACKEND_INTERFACE_H + +#include <stdbool.h> +#include <time.h> +#include <wlr/backend.h> +#include <wlr/render/egl.h> + +struct wlr_backend_impl { + bool (*start)(struct wlr_backend *backend); + void (*destroy)(struct wlr_backend *backend); + struct wlr_renderer *(*get_renderer)(struct wlr_backend *backend); + struct wlr_session *(*get_session)(struct wlr_backend *backend); + clockid_t (*get_presentation_clock)(struct wlr_backend *backend); +}; + +/** + * Initializes common state on a wlr_backend and sets the implementation to the + * provided wlr_backend_impl reference. + */ +void wlr_backend_init(struct wlr_backend *backend, + const struct wlr_backend_impl *impl); + +#endif diff --git a/include/wlr/backend/libinput.h b/include/wlr/backend/libinput.h new file mode 100644 index 00000000..1a2ab294 --- /dev/null +++ b/include/wlr/backend/libinput.h @@ -0,0 +1,27 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_LIBINPUT_H +#define WLR_BACKEND_LIBINPUT_H + +#include <libinput.h> +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/backend/session.h> +#include <wlr/types/wlr_input_device.h> + +struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, + struct wlr_session *session); +/** Gets the underlying libinput_device handle for the given wlr_input_device */ +struct libinput_device *wlr_libinput_get_device_handle( + struct wlr_input_device *dev); + +bool wlr_backend_is_libinput(struct wlr_backend *backend); +bool wlr_input_device_is_libinput(struct wlr_input_device *device); + +#endif diff --git a/include/wlr/backend/meson.build b/include/wlr/backend/meson.build new file mode 100644 index 00000000..3d6f0e40 --- /dev/null +++ b/include/wlr/backend/meson.build @@ -0,0 +1,16 @@ +install_headers( + 'drm.h', + 'headless.h', + 'interface.h', + 'libinput.h', + 'multi.h', + 'session.h', + 'wayland.h', + subdir: 'wlr/backend', +) + +if conf_data.get('WLR_HAS_X11_BACKEND', 0) == 1 + install_headers('x11.h', subdir: 'wlr/backend') +endif + +subdir('session') diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h new file mode 100644 index 00000000..0687f4b6 --- /dev/null +++ b/include/wlr/backend/multi.h @@ -0,0 +1,36 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_MULTI_H +#define WLR_BACKEND_MULTI_H + +#include <wlr/backend.h> +#include <wlr/backend/session.h> + +/** + * Creates a multi-backend. Multi-backends wrap an arbitrary number of backends + * and aggregate their new_output/new_input signals. + */ +struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); +/** + * Adds the given backend to the multi backend. This should be done before the + * new backend is started. + */ +bool wlr_multi_backend_add(struct wlr_backend *multi, + struct wlr_backend *backend); + +void wlr_multi_backend_remove(struct wlr_backend *multi, + struct wlr_backend *backend); + +bool wlr_backend_is_multi(struct wlr_backend *backend); +bool wlr_multi_is_empty(struct wlr_backend *backend); + +void wlr_multi_for_each_backend(struct wlr_backend *backend, + void (*callback)(struct wlr_backend *backend, void *data), void *data); + +#endif diff --git a/include/wlr/backend/session.h b/include/wlr/backend/session.h new file mode 100644 index 00000000..7b26f34c --- /dev/null +++ b/include/wlr/backend/session.h @@ -0,0 +1,94 @@ +#ifndef WLR_BACKEND_SESSION_H +#define WLR_BACKEND_SESSION_H + +#include <libudev.h> +#include <stdbool.h> +#include <sys/types.h> +#include <wayland-server.h> + +struct session_impl; + +struct wlr_device { + int fd; + dev_t dev; + struct wl_signal signal; + + struct wl_list link; +}; + +struct wlr_session { + const struct session_impl *impl; + /* + * Signal for when the session becomes active/inactive. + * It's called when we swap virtual terminal. + */ + struct wl_signal session_signal; + bool active; + + /* + * 0 if virtual terminals are not supported + * i.e. seat != "seat0" + */ + unsigned vtnr; + char seat[256]; + + struct udev *udev; + struct udev_monitor *mon; + struct wl_event_source *udev_event; + + struct wl_list devices; + + struct wl_listener display_destroy; + + struct { + struct wl_signal destroy; + } events; +}; + +/* + * Opens a session, taking control of the current virtual terminal. + * This should not be called if another program is already in control + * of the terminal (Xorg, another Wayland compositor, etc.). + * + * If logind support is not enabled, you must have CAP_SYS_ADMIN or be root. + * It is safe to drop privileges after this is called. + * + * Returns NULL on error. + */ +struct wlr_session *wlr_session_create(struct wl_display *disp); + +/* + * Closes a previously opened session and restores the virtual terminal. + * You should call wlr_session_close_file on each files you opened + * with wlr_session_open_file before you call this. + */ +void wlr_session_destroy(struct wlr_session *session); + +/* + * Opens the file at path. + * This can only be used to open DRM or evdev (input) devices. + * + * When the session becomes inactive: + * - DRM files lose their DRM master status + * - evdev files become invalid and should be closed + * + * Returns -errno on error. + */ +int wlr_session_open_file(struct wlr_session *session, const char *path); + +/* + * Closes a file previously opened with wlr_session_open_file. + */ +void wlr_session_close_file(struct wlr_session *session, int fd); + +void wlr_session_signal_add(struct wlr_session *session, int fd, + struct wl_listener *listener); +/* + * Changes the virtual terminal. + */ +bool wlr_session_change_vt(struct wlr_session *session, unsigned vt); + +size_t wlr_session_find_gpus(struct wlr_session *session, + size_t ret_len, int *ret); + +#endif diff --git a/include/wlr/backend/session/interface.h b/include/wlr/backend/session/interface.h new file mode 100644 index 00000000..5ccf9c8a --- /dev/null +++ b/include/wlr/backend/session/interface.h @@ -0,0 +1,22 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_BACKEND_SESSION_INTERFACE_H +#define WLR_BACKEND_SESSION_INTERFACE_H + +#include <wlr/backend/session.h> + +struct session_impl { + struct wlr_session *(*create)(struct wl_display *disp); + void (*destroy)(struct wlr_session *session); + int (*open)(struct wlr_session *session, const char *path); + void (*close)(struct wlr_session *session, int fd); + bool (*change_vt)(struct wlr_session *session, unsigned vt); +}; + +#endif diff --git a/include/wlr/backend/session/meson.build b/include/wlr/backend/session/meson.build new file mode 100644 index 00000000..21b5a96b --- /dev/null +++ b/include/wlr/backend/session/meson.build @@ -0,0 +1 @@ +install_headers('interface.h', subdir: 'wlr/backend/session') diff --git a/include/wlr/backend/wayland.h b/include/wlr/backend/wayland.h new file mode 100644 index 00000000..119ea247 --- /dev/null +++ b/include/wlr/backend/wayland.h @@ -0,0 +1,45 @@ +#ifndef WLR_BACKEND_WAYLAND_H +#define WLR_BACKEND_WAYLAND_H + +#include <stdbool.h> +#include <wayland-client.h> +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output.h> + +/** + * Creates a new wlr_wl_backend. This backend will be created with no outputs; + * you must use wlr_wl_output_create to add them. + * + * The `remote` argument is the name of the host compositor wayland socket. Set + * to NULL for the default behaviour (WAYLAND_DISPLAY env variable or wayland-0 + * default) + */ +struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, const char *remote, + wlr_renderer_create_func_t create_renderer_func); + +/** + * Adds a new output to this backend. You may remove outputs by destroying them. + * Note that if called before initializing the backend, this will return NULL + * and your outputs will be created during initialization (and given to you via + * the output_add signal). + */ +struct wlr_output *wlr_wl_output_create(struct wlr_backend *backend); + +/** + * True if the given backend is a wlr_wl_backend. + */ +bool wlr_backend_is_wl(struct wlr_backend *backend); + +/** + * True if the given input device is a wlr_wl_input_device. + */ +bool wlr_input_device_is_wl(struct wlr_input_device *device); + +/** + * True if the given output is a wlr_wl_output. + */ +bool wlr_output_is_wl(struct wlr_output *output); + +#endif diff --git a/include/wlr/backend/x11.h b/include/wlr/backend/x11.h new file mode 100644 index 00000000..5793a3b9 --- /dev/null +++ b/include/wlr/backend/x11.h @@ -0,0 +1,20 @@ +#ifndef WLR_BACKEND_X11_H +#define WLR_BACKEND_X11_H + +#include <stdbool.h> + +#include <wayland-server.h> + +#include <wlr/backend.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output.h> + +struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, + const char *x11_display, wlr_renderer_create_func_t create_renderer_func); +struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend); + +bool wlr_backend_is_x11(struct wlr_backend *backend); +bool wlr_input_device_is_x11(struct wlr_input_device *device); +bool wlr_output_is_x11(struct wlr_output *output); + +#endif |