2017-09-23 10:26:01 +02:00
|
|
|
#ifndef WLR_BACKEND_SESSION_H
|
|
|
|
#define WLR_BACKEND_SESSION_H
|
2017-05-03 04:11:22 +02:00
|
|
|
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdbool.h>
|
2017-05-14 03:07:34 +02:00
|
|
|
#include <sys/types.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2017-05-13 13:56:40 +02:00
|
|
|
|
2021-04-11 16:27:46 +02:00
|
|
|
struct libseat;
|
2017-05-13 15:12:47 +02:00
|
|
|
|
2024-01-31 19:01:13 +01:00
|
|
|
/**
|
|
|
|
* An opened physical device.
|
|
|
|
*/
|
2017-08-26 04:50:16 +02:00
|
|
|
struct wlr_device {
|
|
|
|
int fd;
|
2021-04-11 16:27:46 +02:00
|
|
|
int device_id;
|
2017-08-26 04:50:16 +02:00
|
|
|
dev_t dev;
|
2024-01-31 19:01:13 +01:00
|
|
|
struct wl_list link; // wlr_session.devices
|
2020-11-06 10:16:07 +01:00
|
|
|
|
|
|
|
struct {
|
2021-06-09 11:48:25 +02:00
|
|
|
struct wl_signal change; // struct wlr_device_change_event
|
2020-12-27 12:54:35 +01:00
|
|
|
struct wl_signal remove;
|
2020-11-06 10:16:07 +01:00
|
|
|
} events;
|
2017-08-26 04:50:16 +02:00
|
|
|
};
|
|
|
|
|
2024-01-31 19:01:13 +01:00
|
|
|
/**
|
|
|
|
* A session manages access to physical devices (such as GPUs and input
|
|
|
|
* devices).
|
|
|
|
*
|
|
|
|
* A session is only required when running on bare metal (e.g. with the KMS or
|
|
|
|
* libinput backends).
|
|
|
|
*
|
|
|
|
* The session listens for device hotplug events, and relays that information
|
|
|
|
* via the add_drm_card event and the change/remove events on struct wlr_device.
|
|
|
|
* The session provides functions to gain access to physical device (which is a
|
|
|
|
* privileged operation), see wlr_session_open_file(). The session also keeps
|
|
|
|
* track of the virtual terminal state (allowing users to switch between
|
|
|
|
* compositors or TTYs), see wlr_session_change_vt() and the active event.
|
|
|
|
*/
|
2017-05-13 15:12:47 +02:00
|
|
|
struct wlr_session {
|
2017-07-09 13:02:41 +02:00
|
|
|
/*
|
|
|
|
* Signal for when the session becomes active/inactive.
|
|
|
|
* It's called when we swap virtual terminal.
|
|
|
|
*/
|
2017-07-09 07:53:13 +02:00
|
|
|
bool active;
|
|
|
|
|
2018-06-14 10:46:16 +02:00
|
|
|
/*
|
|
|
|
* 0 if virtual terminals are not supported
|
|
|
|
* i.e. seat != "seat0"
|
|
|
|
*/
|
2017-07-09 07:53:13 +02:00
|
|
|
unsigned vtnr;
|
2018-06-14 10:46:16 +02:00
|
|
|
char seat[256];
|
2017-08-26 04:02:04 +02:00
|
|
|
|
|
|
|
struct udev *udev;
|
|
|
|
struct udev_monitor *mon;
|
|
|
|
struct wl_event_source *udev_event;
|
|
|
|
|
2021-04-11 16:27:46 +02:00
|
|
|
struct libseat *seat_handle;
|
|
|
|
struct wl_event_source *libseat_event;
|
|
|
|
|
2024-01-31 19:01:13 +01:00
|
|
|
struct wl_list devices; // wlr_device.link
|
2017-12-08 11:17:56 +01:00
|
|
|
|
2023-08-11 19:28:07 +02:00
|
|
|
struct wl_event_loop *event_loop;
|
|
|
|
struct wl_listener event_loop_destroy;
|
2018-08-26 23:23:12 +02:00
|
|
|
|
|
|
|
struct {
|
2020-11-06 11:34:55 +01:00
|
|
|
struct wl_signal active;
|
2020-11-06 10:56:13 +01:00
|
|
|
struct wl_signal add_drm_card; // struct wlr_session_add_event
|
2018-08-26 23:23:12 +02:00
|
|
|
struct wl_signal destroy;
|
|
|
|
} events;
|
2017-05-13 15:12:47 +02:00
|
|
|
};
|
2017-05-03 04:11:22 +02:00
|
|
|
|
2020-11-06 10:56:13 +01:00
|
|
|
struct wlr_session_add_event {
|
|
|
|
const char *path;
|
|
|
|
};
|
|
|
|
|
2021-06-09 11:48:25 +02:00
|
|
|
enum wlr_device_change_type {
|
|
|
|
WLR_DEVICE_HOTPLUG = 1,
|
2021-11-03 13:37:24 +01:00
|
|
|
WLR_DEVICE_LEASE,
|
2021-06-09 11:48:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wlr_device_hotplug_event {
|
|
|
|
uint32_t connector_id;
|
|
|
|
uint32_t prop_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wlr_device_change_event {
|
|
|
|
enum wlr_device_change_type type;
|
|
|
|
union {
|
|
|
|
struct wlr_device_hotplug_event hotplug;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-07-09 13:02:41 +02:00
|
|
|
/*
|
|
|
|
* 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.).
|
|
|
|
*
|
|
|
|
* Returns NULL on error.
|
|
|
|
*/
|
2023-08-11 19:28:07 +02:00
|
|
|
struct wlr_session *wlr_session_create(struct wl_event_loop *loop);
|
2017-07-09 13:02:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Closes a previously opened session and restores the virtual terminal.
|
2022-05-24 18:46:59 +02:00
|
|
|
* You should call wlr_session_close_file() on each files you opened
|
|
|
|
* with wlr_session_open_file() before you call this.
|
2017-07-09 13:02:41 +02:00
|
|
|
*/
|
2017-08-26 01:56:43 +02:00
|
|
|
void wlr_session_destroy(struct wlr_session *session);
|
2017-07-09 13:02:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Opens the file at path.
|
2022-05-24 18:46:59 +02:00
|
|
|
*
|
|
|
|
* This can only be used to open DRM or evdev (input) devices. Files opened via
|
|
|
|
* this function must be closed by calling wlr_session_close_file().
|
2017-07-09 13:02:41 +02:00
|
|
|
*
|
|
|
|
* When the session becomes inactive:
|
2022-05-24 18:46:59 +02:00
|
|
|
*
|
2017-07-09 13:02:41 +02:00
|
|
|
* - DRM files lose their DRM master status
|
|
|
|
* - evdev files become invalid and should be closed
|
|
|
|
*/
|
2020-11-06 10:16:07 +01:00
|
|
|
struct wlr_device *wlr_session_open_file(struct wlr_session *session,
|
|
|
|
const char *path);
|
2017-07-09 13:02:41 +02:00
|
|
|
|
|
|
|
/*
|
2022-05-24 18:46:59 +02:00
|
|
|
* Closes a file previously opened with wlr_session_open_file().
|
2017-07-09 13:02:41 +02:00
|
|
|
*/
|
2020-11-06 10:16:07 +01:00
|
|
|
void wlr_session_close_file(struct wlr_session *session,
|
|
|
|
struct wlr_device *device);
|
2017-07-09 13:02:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Changes the virtual terminal.
|
|
|
|
*/
|
2017-07-09 07:53:13 +02:00
|
|
|
bool wlr_session_change_vt(struct wlr_session *session, unsigned vt);
|
2017-05-03 04:11:22 +02:00
|
|
|
|
2024-01-31 19:01:13 +01:00
|
|
|
/**
|
|
|
|
* Enumerate and open KMS devices.
|
|
|
|
*
|
|
|
|
* ret is filled with up to ret_len devices. The number of devices ret has been
|
|
|
|
* filled with is returned on success. If more devices than ret_len are probed,
|
|
|
|
* the extraneous ones are ignored. If there is no KMS device, the function
|
|
|
|
* will block until such device is detected up to a timeout. The first device
|
|
|
|
* returned is the default device (marked as "boot_vga" by the kernel).
|
|
|
|
*
|
|
|
|
* On error, or if no device was found, -1 is returned.
|
|
|
|
*/
|
2020-12-28 10:52:40 +01:00
|
|
|
ssize_t wlr_session_find_gpus(struct wlr_session *session,
|
2020-11-06 10:16:07 +01:00
|
|
|
size_t ret_len, struct wlr_device **ret);
|
2017-08-26 04:02:04 +02:00
|
|
|
|
2017-05-03 04:11:22 +02:00
|
|
|
#endif
|