Merge pull request #1248 from emersion/assert-all-the-things

Assert all the things!
This commit is contained in:
Drew DeVault 2018-09-18 14:44:46 -04:00 committed by GitHub
commit 3693fae0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 313 additions and 170 deletions

View File

@ -15,8 +15,14 @@
#include "backend/drm/drm.h" #include "backend/drm/drm.h"
#include "util/signal.h" #include "util/signal.h"
struct wlr_drm_backend *get_drm_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_drm(wlr_backend));
return (struct wlr_drm_backend *)wlr_backend;
}
static bool backend_start(struct wlr_backend *backend) { static bool backend_start(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
scan_drm_connectors(drm); scan_drm_connectors(drm);
return true; return true;
} }
@ -26,7 +32,7 @@ static void backend_destroy(struct wlr_backend *backend) {
return; return;
} }
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
restore_drm_outputs(drm); restore_drm_outputs(drm);
@ -50,7 +56,7 @@ static void backend_destroy(struct wlr_backend *backend) {
static struct wlr_renderer *backend_get_renderer( static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *backend) { struct wlr_backend *backend) {
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
if (drm->parent) { if (drm->parent) {
return drm->parent->renderer.wlr_rend; return drm->parent->renderer.wlr_rend;
@ -141,7 +147,9 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
wl_list_init(&drm->outputs); wl_list_init(&drm->outputs);
drm->fd = gpu_fd; drm->fd = gpu_fd;
drm->parent = (struct wlr_drm_backend *)parent; if (parent != NULL) {
drm->parent = get_drm_backend_from_backend(parent);
}
drm->drm_invalidated.notify = drm_invalidated; drm->drm_invalidated.notify = drm_invalidated;
wlr_session_signal_add(session, gpu_fd, &drm->drm_invalidated); wlr_session_signal_add(session, gpu_fd, &drm->drm_invalidated);
@ -187,6 +195,6 @@ error_fd:
} }
struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend) { struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
return drm->session; return drm->session;
} }

View File

@ -205,16 +205,22 @@ void finish_drm_resources(struct wlr_drm_backend *drm) {
free(drm->planes); free(drm->planes);
} }
static struct wlr_drm_connector *get_drm_connector_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_drm(wlr_output));
return (struct wlr_drm_connector *)wlr_output;
}
static bool drm_connector_make_current(struct wlr_output *output, static bool drm_connector_make_current(struct wlr_output *output,
int *buffer_age) { int *buffer_age) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
return make_drm_surface_current(&conn->crtc->primary->surf, buffer_age); return make_drm_surface_current(&conn->crtc->primary->surf, buffer_age);
} }
static bool drm_connector_swap_buffers(struct wlr_output *output, static bool drm_connector_swap_buffers(struct wlr_output *output,
pixman_region32_t *damage) { pixman_region32_t *damage) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!drm->session->active) { if (!drm->session->active) {
return false; return false;
} }
@ -254,8 +260,8 @@ static void fill_empty_gamma_table(uint32_t size,
} }
static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->crtc) { if (conn->crtc) {
return drm->iface->crtc_get_gamma_size(drm, conn->crtc); return drm->iface->crtc_get_gamma_size(drm, conn->crtc);
@ -266,8 +272,8 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) {
static bool drm_connector_set_gamma(struct wlr_output *output, static bool drm_connector_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!conn->crtc) { if (!conn->crtc) {
return false; return false;
@ -297,8 +303,8 @@ static bool drm_connector_set_gamma(struct wlr_output *output,
static bool drm_connector_export_dmabuf(struct wlr_output *output, static bool drm_connector_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs) { struct wlr_dmabuf_attributes *attribs) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!drm->session->active) { if (!drm->session->active) {
return false; return false;
@ -321,7 +327,8 @@ static void drm_connector_start_renderer(struct wlr_drm_connector *conn) {
wlr_log(WLR_DEBUG, "Starting renderer on output '%s'", conn->output.name); wlr_log(WLR_DEBUG, "Starting renderer on output '%s'", conn->output.name);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend);
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (!crtc) { if (!crtc) {
return; return;
@ -361,8 +368,8 @@ static void attempt_enable_needs_modeset(struct wlr_drm_backend *drm) {
} }
bool enable_drm_connector(struct wlr_output *output, bool enable) { bool enable_drm_connector(struct wlr_output *output, bool enable) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->state != WLR_DRM_CONN_CONNECTED if (conn->state != WLR_DRM_CONN_CONNECTED
&& conn->state != WLR_DRM_CONN_NEEDS_MODESET) { && conn->state != WLR_DRM_CONN_NEEDS_MODESET) {
return false; return false;
@ -456,8 +463,8 @@ static void drm_connector_cleanup(struct wlr_drm_connector *conn);
static bool drm_connector_set_mode(struct wlr_output *output, static bool drm_connector_set_mode(struct wlr_output *output,
struct wlr_output_mode *mode) { struct wlr_output_mode *mode) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->crtc == NULL) { if (conn->crtc == NULL) {
// Maybe we can steal a CRTC from a disabled output // Maybe we can steal a CRTC from a disabled output
realloc_crtcs(drm, NULL); realloc_crtcs(drm, NULL);
@ -496,7 +503,7 @@ static bool drm_connector_set_mode(struct wlr_output *output,
bool wlr_drm_connector_add_mode(struct wlr_output *output, bool wlr_drm_connector_add_mode(struct wlr_output *output,
const drmModeModeInfo *modeinfo) { const drmModeModeInfo *modeinfo) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
assert(modeinfo); assert(modeinfo);
if (modeinfo->type != DRM_MODE_TYPE_USERDEF) { if (modeinfo->type != DRM_MODE_TYPE_USERDEF) {
@ -528,10 +535,10 @@ static void drm_connector_transform(struct wlr_output *output,
static bool drm_connector_set_cursor(struct wlr_output *output, static bool drm_connector_set_cursor(struct wlr_output *output,
struct wlr_texture *texture, int32_t scale, struct wlr_texture *texture, int32_t scale,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y, enum wl_output_transform transform,
bool update_texture) { int32_t hotspot_x, int32_t hotspot_y, bool update_texture) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (!crtc) { if (!crtc) {
@ -664,8 +671,8 @@ static bool drm_connector_set_cursor(struct wlr_output *output,
static bool drm_connector_move_cursor(struct wlr_output *output, static bool drm_connector_move_cursor(struct wlr_output *output,
int x, int y) { int x, int y) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!conn->crtc) { if (!conn->crtc) {
return false; return false;
} }
@ -700,7 +707,7 @@ static bool drm_connector_move_cursor(struct wlr_output *output,
} }
static void drm_connector_destroy(struct wlr_output *output) { static void drm_connector_destroy(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
drm_connector_cleanup(conn); drm_connector_cleanup(conn);
wl_event_source_remove(conn->retry_pageflip); wl_event_source_remove(conn->retry_pageflip);
wl_list_remove(&conn->link); wl_list_remove(&conn->link);
@ -742,7 +749,8 @@ static const int32_t subpixel_map[] = {
}; };
static void dealloc_crtc(struct wlr_drm_connector *conn) { static void dealloc_crtc(struct wlr_drm_connector *conn) {
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend);
if (conn->crtc == NULL) { if (conn->crtc == NULL) {
return; return;
} }
@ -1121,7 +1129,8 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
static void page_flip_handler(int fd, unsigned seq, static void page_flip_handler(int fd, unsigned seq,
unsigned tv_sec, unsigned tv_usec, void *user) { unsigned tv_sec, unsigned tv_usec, void *user) {
struct wlr_drm_connector *conn = user; struct wlr_drm_connector *conn = user;
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend);
conn->pageflip_pending = false; conn->pageflip_pending = false;
if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) { if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) {

View File

@ -1,4 +1,4 @@
#include "util/signal.h" #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
@ -7,10 +7,17 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "backend/headless.h" #include "backend/headless.h"
#include "glapi.h" #include "glapi.h"
#include "util/signal.h"
struct wlr_headless_backend *headless_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_headless(wlr_backend));
return (struct wlr_headless_backend *)wlr_backend;
}
static bool backend_start(struct wlr_backend *wlr_backend) { static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend = struct wlr_headless_backend *backend =
(struct wlr_headless_backend *)wlr_backend; headless_backend_from_backend(wlr_backend);
wlr_log(WLR_INFO, "Starting headless backend"); wlr_log(WLR_INFO, "Starting headless backend");
struct wlr_headless_output *output; struct wlr_headless_output *output;
@ -34,7 +41,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
static void backend_destroy(struct wlr_backend *wlr_backend) { static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend = struct wlr_headless_backend *backend =
(struct wlr_headless_backend *)wlr_backend; headless_backend_from_backend(wlr_backend);
if (!wlr_backend) { if (!wlr_backend) {
return; return;
} }
@ -62,7 +69,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
static struct wlr_renderer *backend_get_renderer( static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *wlr_backend) { struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend = struct wlr_headless_backend *backend =
(struct wlr_headless_backend *)wlr_backend; headless_backend_from_backend(wlr_backend);
return backend->renderer; return backend->renderer;
} }
@ -107,9 +114,8 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display,
create_renderer_func = wlr_renderer_autocreate; create_renderer_func = wlr_renderer_autocreate;
} }
backend->renderer = create_renderer_func(&backend->egl, EGL_PLATFORM_SURFACELESS_MESA, backend->renderer = create_renderer_func(&backend->egl,
NULL, (EGLint*)config_attribs, 0); EGL_PLATFORM_SURFACELESS_MESA, NULL, (EGLint*)config_attribs, 0);
if (!backend->renderer) { if (!backend->renderer) {
wlr_log(WLR_ERROR, "Failed to create renderer"); wlr_log(WLR_ERROR, "Failed to create renderer");
free(backend); free(backend);

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h> #include <wlr/interfaces/wlr_keyboard.h>
@ -18,7 +19,7 @@ bool wlr_input_device_is_headless(struct wlr_input_device *wlr_dev) {
struct wlr_input_device *wlr_headless_add_input_device( struct wlr_input_device *wlr_headless_add_input_device(
struct wlr_backend *wlr_backend, enum wlr_input_device_type type) { struct wlr_backend *wlr_backend, enum wlr_input_device_type type) {
struct wlr_headless_backend *backend = struct wlr_headless_backend *backend =
(struct wlr_headless_backend *)wlr_backend; headless_backend_from_backend(wlr_backend);
struct wlr_headless_input_device *device = struct wlr_headless_input_device *device =
calloc(1, sizeof(struct wlr_headless_input_device)); calloc(1, sizeof(struct wlr_headless_input_device));

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <stdlib.h> #include <stdlib.h>
@ -7,6 +8,12 @@
#include "backend/headless.h" #include "backend/headless.h"
#include "util/signal.h" #include "util/signal.h"
static struct wlr_headless_output *headless_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_headless(wlr_output));
return (struct wlr_headless_output *)wlr_output;
}
static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width, static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width,
unsigned int height) { unsigned int height) {
EGLint attribs[] = {EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE}; EGLint attribs[] = {EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE};
@ -22,7 +29,7 @@ static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width,
static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
int32_t height, int32_t refresh) { int32_t height, int32_t refresh) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; headless_output_from_output(wlr_output);
struct wlr_headless_backend *backend = output->backend; struct wlr_headless_backend *backend = output->backend;
if (refresh <= 0) { if (refresh <= 0) {
@ -47,13 +54,13 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
static void output_transform(struct wlr_output *wlr_output, static void output_transform(struct wlr_output *wlr_output,
enum wl_output_transform transform) { enum wl_output_transform transform) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; headless_output_from_output(wlr_output);
output->wlr_output.transform = transform; output->wlr_output.transform = transform;
} }
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; headless_output_from_output(wlr_output);
return wlr_egl_make_current(&output->backend->egl, output->egl_surface, return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
buffer_age); buffer_age);
} }
@ -65,7 +72,7 @@ static bool output_swap_buffers(struct wlr_output *wlr_output,
static void output_destroy(struct wlr_output *wlr_output) { static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_headless_output *output = struct wlr_headless_output *output =
(struct wlr_headless_output *)wlr_output; headless_output_from_output(wlr_output);
wl_list_remove(&output->link); wl_list_remove(&output->link);
@ -97,7 +104,7 @@ static int signal_frame(void *data) {
struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
unsigned int width, unsigned int height) { unsigned int width, unsigned int height) {
struct wlr_headless_backend *backend = struct wlr_headless_backend *backend =
(struct wlr_headless_backend *)wlr_backend; headless_backend_from_backend(wlr_backend);
struct wlr_headless_output *output = struct wlr_headless_output *output =
calloc(1, sizeof(struct wlr_headless_output)); calloc(1, sizeof(struct wlr_headless_output));

View File

@ -7,6 +7,12 @@
#include "backend/libinput.h" #include "backend/libinput.h"
#include "util/signal.h" #include "util/signal.h"
static struct wlr_libinput_backend *get_libinput_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_libinput(wlr_backend));
return (struct wlr_libinput_backend *)wlr_backend;
}
static int libinput_open_restricted(const char *path, static int libinput_open_restricted(const char *path,
int flags, void *_backend) { int flags, void *_backend) {
struct wlr_libinput_backend *backend = _backend; struct wlr_libinput_backend *backend = _backend;
@ -43,9 +49,9 @@ static void log_libinput(struct libinput *libinput_context,
_wlr_vlog(WLR_ERROR, fmt, args); _wlr_vlog(WLR_ERROR, fmt, args);
} }
static bool backend_start(struct wlr_backend *_backend) { static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_libinput_backend *backend = struct wlr_libinput_backend *backend =
(struct wlr_libinput_backend *)_backend; get_libinput_backend_from_backend(wlr_backend);
wlr_log(WLR_DEBUG, "Initializing libinput"); wlr_log(WLR_DEBUG, "Initializing libinput");
backend->libinput_context = libinput_udev_create_context(&libinput_impl, backend->libinput_context = libinput_udev_create_context(&libinput_impl,
@ -101,7 +107,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
return; return;
} }
struct wlr_libinput_backend *backend = struct wlr_libinput_backend *backend =
(struct wlr_libinput_backend *)wlr_backend; get_libinput_backend_from_backend(wlr_backend);
for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { for (size_t i = 0; i < backend->wlr_device_lists.length; i++) {
struct wl_list *wlr_devices = backend->wlr_device_lists.items[i]; struct wl_list *wlr_devices = backend->wlr_device_lists.items[i];
@ -158,9 +164,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
struct wlr_session *session) { struct wlr_session *session) {
assert(display && session); struct wlr_libinput_backend *backend =
calloc(1, sizeof(struct wlr_libinput_backend));
struct wlr_libinput_backend *backend = calloc(1, sizeof(struct wlr_libinput_backend));
if (!backend) { if (!backend) {
wlr_log(WLR_ERROR, "Allocation failed: %s", strerror(errno)); wlr_log(WLR_ERROR, "Allocation failed: %s", strerror(errno));
return NULL; return NULL;
@ -187,8 +192,10 @@ error_backend:
return NULL; return NULL;
} }
struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *_dev) { struct libinput_device *wlr_libinput_get_device_handle(
struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; struct wlr_input_device *wlr_dev) {
struct wlr_libinput_input_device *dev =
(struct wlr_libinput_input_device *)wlr_dev;
return dev->handle; return dev->handle;
} }

View File

@ -9,6 +9,12 @@
#include "backend/libinput.h" #include "backend/libinput.h"
#include "util/signal.h" #include "util/signal.h"
struct wlr_libinput_input_device *get_libinput_device_from_device(
struct wlr_input_device *wlr_dev) {
assert(wlr_input_device_is_libinput(wlr_dev));
return (struct wlr_libinput_input_device *)wlr_dev;
}
struct wlr_input_device *get_appropriate_device( struct wlr_input_device *get_appropriate_device(
enum wlr_input_device_type desired_type, enum wlr_input_device_type desired_type,
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
@ -25,8 +31,9 @@ struct wlr_input_device *get_appropriate_device(
return NULL; return NULL;
} }
static void input_device_destroy(struct wlr_input_device *_dev) { static void input_device_destroy(struct wlr_input_device *wlr_dev) {
struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; struct wlr_libinput_input_device *dev =
get_libinput_device_from_device(wlr_dev);
libinput_device_unref(dev->handle); libinput_device_unref(dev->handle);
wl_list_remove(&dev->wlr_input_device.link); wl_list_remove(&dev->wlr_input_device.link);
free(dev); free(dev);
@ -37,16 +44,18 @@ static const struct wlr_input_device_impl input_device_impl = {
}; };
static struct wlr_input_device *allocate_device( static struct wlr_input_device *allocate_device(
struct wlr_libinput_backend *backend, struct libinput_device *libinput_dev, struct wlr_libinput_backend *backend,
struct wl_list *wlr_devices, enum wlr_input_device_type type) { struct libinput_device *libinput_dev, struct wl_list *wlr_devices,
enum wlr_input_device_type type) {
int vendor = libinput_device_get_id_vendor(libinput_dev); int vendor = libinput_device_get_id_vendor(libinput_dev);
int product = libinput_device_get_id_product(libinput_dev); int product = libinput_device_get_id_product(libinput_dev);
const char *name = libinput_device_get_name(libinput_dev); const char *name = libinput_device_get_name(libinput_dev);
struct wlr_libinput_input_device *wlr_libinput_dev; struct wlr_libinput_input_device *dev =
if (!(wlr_libinput_dev = calloc(1, sizeof(struct wlr_libinput_input_device)))) { calloc(1, sizeof(struct wlr_libinput_input_device));
if (dev == NULL) {
return NULL; return NULL;
} }
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; struct wlr_input_device *wlr_dev = &dev->wlr_input_device;
libinput_device_get_size(libinput_dev, libinput_device_get_size(libinput_dev,
&wlr_dev->width_mm, &wlr_dev->height_mm); &wlr_dev->width_mm, &wlr_dev->height_mm);
const char *output_name = libinput_device_get_output_name(libinput_dev); const char *output_name = libinput_device_get_output_name(libinput_dev);
@ -54,7 +63,7 @@ static struct wlr_input_device *allocate_device(
wlr_dev->output_name = strdup(output_name); wlr_dev->output_name = strdup(output_name);
} }
wl_list_insert(wlr_devices, &wlr_dev->link); wl_list_insert(wlr_devices, &wlr_dev->link);
wlr_libinput_dev->handle = libinput_dev; dev->handle = libinput_dev;
libinput_device_ref(libinput_dev); libinput_device_ref(libinput_dev);
wlr_input_device_init(wlr_dev, type, &input_device_impl, wlr_input_device_init(wlr_dev, type, &input_device_impl,
name, vendor, product); name, vendor, product);
@ -67,7 +76,6 @@ bool wlr_input_device_is_libinput(struct wlr_input_device *wlr_dev) {
static void handle_device_added(struct wlr_libinput_backend *backend, static void handle_device_added(struct wlr_libinput_backend *backend,
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
assert(backend && libinput_dev);
/* /*
* Note: the wlr API exposes only devices with a single capability, because * Note: the wlr API exposes only devices with a single capability, because
* that meshes better with how Wayland does things and is a bit simpler. * that meshes better with how Wayland does things and is a bit simpler.
@ -85,7 +93,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
wl_list_init(wlr_devices); wl_list_init(wlr_devices);
wlr_log(WLR_DEBUG, "Added %s [%d:%d]", name, vendor, product); wlr_log(WLR_DEBUG, "Added %s [%d:%d]", name, vendor, product);
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_KEYBOARD); libinput_dev, wlr_devices, WLR_INPUT_DEVICE_KEYBOARD);
if (!wlr_dev) { if (!wlr_dev) {
@ -98,7 +107,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_POINTER); libinput_dev, wlr_devices, WLR_INPUT_DEVICE_POINTER);
if (!wlr_dev) { if (!wlr_dev) {
@ -111,7 +121,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TOUCH); libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TOUCH);
if (!wlr_dev) { if (!wlr_dev) {
@ -124,7 +135,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) { if (libinput_device_has_capability(libinput_dev,
LIBINPUT_DEVICE_CAP_TABLET_TOOL)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_TOOL); libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_TOOL);
if (!wlr_dev) { if (!wlr_dev) {
@ -137,7 +149,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) {
struct wlr_input_device *wlr_dev = allocate_device(backend, struct wlr_input_device *wlr_dev = allocate_device(backend,
libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_PAD); libinput_dev, wlr_devices, WLR_INPUT_DEVICE_TABLET_PAD);
if (!wlr_dev) { if (!wlr_dev) {
@ -150,14 +163,16 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
} }
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) {
// TODO // TODO
} }
if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) { if (libinput_device_has_capability(
libinput_dev, LIBINPUT_DEVICE_CAP_SWITCH)) {
// TODO // TODO
} }
if (wl_list_length(wlr_devices) > 0) { if (!wl_list_empty(wlr_devices)) {
libinput_device_set_user_data(libinput_dev, wlr_devices); libinput_device_set_user_data(libinput_dev, wlr_devices);
wlr_list_push(&backend->wlr_device_lists, wlr_devices); wlr_list_push(&backend->wlr_device_lists, wlr_devices);
} else { } else {
@ -199,7 +214,6 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
void handle_libinput_event(struct wlr_libinput_backend *backend, void handle_libinput_event(struct wlr_libinput_backend *backend,
struct libinput_event *event) { struct libinput_event *event) {
assert(backend && event);
struct libinput_device *libinput_dev = libinput_event_get_device(event); struct libinput_device *libinput_dev = libinput_event_get_device(event);
enum libinput_event_type event_type = libinput_event_get_type(event); enum libinput_event_type event_type = libinput_event_get_type(event);
switch (event_type) { switch (event_type) {

View File

@ -12,35 +12,43 @@ struct wlr_libinput_keyboard {
struct libinput_device *libinput_dev; struct libinput_device *libinput_dev;
}; };
static const struct wlr_keyboard_impl impl;
static struct wlr_libinput_keyboard *get_libinput_keyboard_from_keyboard(
struct wlr_keyboard *wlr_kb) {
assert(wlr_kb->impl == &impl);
return (struct wlr_libinput_keyboard *)wlr_kb;
}
static void keyboard_set_leds(struct wlr_keyboard *wlr_kb, uint32_t leds) { static void keyboard_set_leds(struct wlr_keyboard *wlr_kb, uint32_t leds) {
struct wlr_libinput_keyboard *wlr_libinput_kb = struct wlr_libinput_keyboard *kb =
(struct wlr_libinput_keyboard *)wlr_kb; get_libinput_keyboard_from_keyboard(wlr_kb);
libinput_device_led_update(wlr_libinput_kb->libinput_dev, leds); libinput_device_led_update(kb->libinput_dev, leds);
} }
static void keyboard_destroy(struct wlr_keyboard *wlr_kb) { static void keyboard_destroy(struct wlr_keyboard *wlr_kb) {
struct wlr_libinput_keyboard *wlr_libinput_kb = struct wlr_libinput_keyboard *kb =
(struct wlr_libinput_keyboard *)wlr_kb; get_libinput_keyboard_from_keyboard(wlr_kb);
libinput_device_unref(wlr_libinput_kb->libinput_dev); libinput_device_unref(kb->libinput_dev);
free(wlr_libinput_kb); free(kb);
} }
struct wlr_keyboard_impl impl = { static const struct wlr_keyboard_impl impl = {
.destroy = keyboard_destroy, .destroy = keyboard_destroy,
.led_update = keyboard_set_leds .led_update = keyboard_set_leds
}; };
struct wlr_keyboard *create_libinput_keyboard( struct wlr_keyboard *create_libinput_keyboard(
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
assert(libinput_dev); struct wlr_libinput_keyboard *kb =
struct wlr_libinput_keyboard *wlr_libinput_kb; calloc(1, sizeof(struct wlr_libinput_keyboard));
if (!(wlr_libinput_kb= calloc(1, sizeof(struct wlr_libinput_keyboard)))) { if (kb == NULL) {
return NULL; return NULL;
} }
wlr_libinput_kb->libinput_dev = libinput_dev; kb->libinput_dev = libinput_dev;
libinput_device_ref(libinput_dev); libinput_device_ref(libinput_dev);
libinput_device_led_update(libinput_dev, 0); libinput_device_led_update(libinput_dev, 0);
struct wlr_keyboard *wlr_kb = &wlr_libinput_kb->wlr_keyboard; struct wlr_keyboard *wlr_kb = &kb->wlr_keyboard;
wlr_keyboard_init(wlr_kb, &impl); wlr_keyboard_init(wlr_kb, &impl);
return wlr_kb; return wlr_kb;
} }
@ -50,7 +58,8 @@ void handle_keyboard_key(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a keyboard event for a device with no keyboards?"); wlr_log(WLR_DEBUG,
"Got a keyboard event for a device with no keyboards?");
return; return;
} }
struct libinput_event_keyboard *kbevent = struct libinput_event_keyboard *kbevent =

View File

@ -69,7 +69,8 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
struct wlr_tablet_pad *create_libinput_tablet_pad( struct wlr_tablet_pad *create_libinput_tablet_pad(
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
assert(libinput_dev); assert(libinput_dev);
struct wlr_tablet_pad *wlr_tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); struct wlr_tablet_pad *wlr_tablet_pad =
calloc(1, sizeof(struct wlr_tablet_pad));
if (!wlr_tablet_pad) { if (!wlr_tablet_pad) {
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad"); wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad");
return NULL; return NULL;
@ -101,7 +102,8 @@ void handle_tablet_pad_button(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); wlr_log(WLR_DEBUG,
"Got a tablet pad event for a device with no tablet pad?");
return; return;
} }
struct libinput_event_tablet_pad *pevent = struct libinput_event_tablet_pad *pevent =
@ -129,7 +131,8 @@ void handle_tablet_pad_ring(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); wlr_log(WLR_DEBUG,
"Got a tablet pad event for a device with no tablet pad?");
return; return;
} }
struct libinput_event_tablet_pad *pevent = struct libinput_event_tablet_pad *pevent =
@ -156,7 +159,8 @@ void handle_tablet_pad_strip(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet pad event for a device with no tablet pad?"); wlr_log(WLR_DEBUG,
"Got a tablet pad event for a device with no tablet pad?");
return; return;
} }
struct libinput_event_tablet_pad *pevent = struct libinput_event_tablet_pad *pevent =

View File

@ -156,7 +156,8 @@ static struct wlr_libinput_tablet_tool *get_wlr_tablet_tool(
static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool, static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
struct wlr_tablet *wlr_dev) { struct wlr_tablet *wlr_dev) {
assert(tablet_is_libinput(wlr_dev)); assert(tablet_is_libinput(wlr_dev));
struct wlr_libinput_tablet *tablet = wl_container_of(wlr_dev, tablet, wlr_tablet); struct wlr_libinput_tablet *tablet =
wl_container_of(wlr_dev, tablet, wlr_tablet);
struct tablet_tool_list_elem *pos; struct tablet_tool_list_elem *pos;
wl_list_for_each(pos, &tablet->tools, link) { wl_list_for_each(pos, &tablet->tools, link) {
@ -188,7 +189,8 @@ void handle_tablet_tool_axis(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
return; return;
} }
struct libinput_event_tablet_tool *tevent = struct libinput_event_tablet_tool *tevent =
@ -248,7 +250,8 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
return; return;
} }
struct libinput_event_tablet_tool *tevent = struct libinput_event_tablet_tool *tevent =
@ -272,14 +275,16 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
} }
wlr_signal_emit_safe(&wlr_dev->tablet->events.proximity, &wlr_event); wlr_signal_emit_safe(&wlr_dev->tablet->events.proximity, &wlr_event);
if (libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { if (libinput_event_tablet_tool_get_proximity_state(tevent) ==
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) {
handle_tablet_tool_axis(event, libinput_dev); handle_tablet_tool_axis(event, libinput_dev);
} }
// If the tool is not unique, libinput will not find it again after the // If the tool is not unique, libinput will not find it again after the
// proximity out, so we should destroy it // proximity out, so we should destroy it
if (!tool->unique && if (!tool->unique &&
libinput_event_tablet_tool_get_proximity_state(tevent) == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { libinput_event_tablet_tool_get_proximity_state(tevent) ==
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) {
// The tool isn't unique, it can't be on multiple tablets // The tool isn't unique, it can't be on multiple tablets
assert(tool->pad_refs == 1); assert(tool->pad_refs == 1);
assert(tablet_is_libinput(wlr_dev->tablet)); assert(tablet_is_libinput(wlr_dev->tablet));
@ -305,7 +310,8 @@ void handle_tablet_tool_tip(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
return; return;
} }
handle_tablet_tool_axis(event, libinput_dev); handle_tablet_tool_axis(event, libinput_dev);
@ -336,7 +342,8 @@ void handle_tablet_tool_button(struct libinput_event *event,
struct wlr_input_device *wlr_dev = struct wlr_input_device *wlr_dev =
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev); get_appropriate_device(WLR_INPUT_DEVICE_TABLET_TOOL, libinput_dev);
if (!wlr_dev) { if (!wlr_dev) {
wlr_log(WLR_DEBUG, "Got a tablet tool event for a device with no tablet tools?"); wlr_log(WLR_DEBUG,
"Got a tablet tool event for a device with no tablet tools?");
return; return;
} }
handle_tablet_tool_axis(event, libinput_dev); handle_tablet_tool_axis(event, libinput_dev);

View File

@ -17,8 +17,14 @@ struct subbackend_state {
struct wl_list link; struct wl_list link;
}; };
static struct wlr_multi_backend *multi_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_multi(wlr_backend));
return (struct wlr_multi_backend *)wlr_backend;
}
static bool multi_backend_start(struct wlr_backend *wlr_backend) { static bool multi_backend_start(struct wlr_backend *wlr_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; struct wlr_multi_backend *backend = multi_backend_from_backend(wlr_backend);
struct subbackend_state *sub; struct subbackend_state *sub;
wl_list_for_each(sub, &backend->backends, link) { wl_list_for_each(sub, &backend->backends, link) {
if (!wlr_backend_start(sub->backend)) { if (!wlr_backend_start(sub->backend)) {
@ -38,7 +44,7 @@ static void subbackend_state_destroy(struct subbackend_state *sub) {
} }
static void multi_backend_destroy(struct wlr_backend *wlr_backend) { static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend; struct wlr_multi_backend *backend = multi_backend_from_backend(wlr_backend);
wl_list_remove(&backend->display_destroy.link); wl_list_remove(&backend->display_destroy.link);
@ -54,7 +60,8 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
static struct wlr_renderer *multi_backend_get_renderer( static struct wlr_renderer *multi_backend_get_renderer(
struct wlr_backend *backend) { struct wlr_backend *backend) {
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)backend; struct wlr_multi_backend *multi = multi_backend_from_backend(backend);
struct subbackend_state *sub; struct subbackend_state *sub;
wl_list_for_each(sub, &multi->backends, link) { wl_list_for_each(sub, &multi->backends, link) {
struct wlr_renderer *rend = wlr_backend_get_renderer(sub->backend); struct wlr_renderer *rend = wlr_backend_get_renderer(sub->backend);
@ -132,8 +139,7 @@ static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_ba
bool wlr_multi_backend_add(struct wlr_backend *_multi, bool wlr_multi_backend_add(struct wlr_backend *_multi,
struct wlr_backend *backend) { struct wlr_backend *backend) {
assert(wlr_backend_is_multi(_multi)); struct wlr_multi_backend *multi = multi_backend_from_backend(_multi);
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi;
if (multi_backend_get_subbackend(multi, backend)) { if (multi_backend_get_subbackend(multi, backend)) {
// already added // already added
@ -174,8 +180,7 @@ bool wlr_multi_backend_add(struct wlr_backend *_multi,
void wlr_multi_backend_remove(struct wlr_backend *_multi, void wlr_multi_backend_remove(struct wlr_backend *_multi,
struct wlr_backend *backend) { struct wlr_backend *backend) {
assert(wlr_backend_is_multi(_multi)); struct wlr_multi_backend *multi = multi_backend_from_backend(_multi);
struct wlr_multi_backend *multi = (struct wlr_multi_backend *)_multi;
struct subbackend_state *sub = struct subbackend_state *sub =
multi_backend_get_subbackend(multi, backend); multi_backend_get_subbackend(multi, backend);
@ -187,9 +192,7 @@ void wlr_multi_backend_remove(struct wlr_backend *_multi,
} }
struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) { struct wlr_session *wlr_multi_get_session(struct wlr_backend *_backend) {
assert(wlr_backend_is_multi(_backend)); struct wlr_multi_backend *backend = multi_backend_from_backend(_backend);
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
struct subbackend_state *sub; struct subbackend_state *sub;
wl_list_for_each(sub, &backend->backends, link) { wl_list_for_each(sub, &backend->backends, link) {
if (wlr_backend_is_drm(sub->backend)) { if (wlr_backend_is_drm(sub->backend)) {

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <dev/evdev/input.h> #include <dev/evdev/input.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -32,8 +33,14 @@ struct direct_session {
struct wl_event_source *vt_source; struct wl_event_source *vt_source;
}; };
static struct direct_session *direct_session_from_session(
struct wlr_session *base) {
assert(base->impl == &session_direct);
return (struct direct_session *)base;
}
static int direct_session_open(struct wlr_session *base, const char *path) { static int direct_session_open(struct wlr_session *base, const char *path) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
int fd = direct_ipc_open(session->sock, path); int fd = direct_ipc_open(session->sock, path);
if (fd < 0) { if (fd < 0) {
@ -46,7 +53,7 @@ static int direct_session_open(struct wlr_session *base, const char *path) {
} }
static void direct_session_close(struct wlr_session *base, int fd) { static void direct_session_close(struct wlr_session *base, int fd) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
int ev; int ev;
struct drm_version dv = {0}; struct drm_version dv = {0};
@ -60,12 +67,12 @@ static void direct_session_close(struct wlr_session *base, int fd) {
} }
static bool direct_change_vt(struct wlr_session *base, unsigned vt) { static bool direct_change_vt(struct wlr_session *base, unsigned vt) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
return ioctl(session->tty_fd, VT_ACTIVATE, (int)vt) == 0; return ioctl(session->tty_fd, VT_ACTIVATE, (int)vt) == 0;
} }
static void direct_session_destroy(struct wlr_session *base) { static void direct_session_destroy(struct wlr_session *base) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
struct vt_mode mode = { struct vt_mode mode = {
.mode = VT_AUTO, .mode = VT_AUTO,
}; };
@ -157,7 +164,8 @@ static bool setup_tty(struct direct_session *session, struct wl_display *display
} }
if (ioctl(fd, KDSKBMODE, K_CODE)) { if (ioctl(fd, KDSKBMODE, K_CODE)) {
wlr_log_errno(WLR_ERROR, "Failed to set keyboard mode K_CODE on tty %d", tty); wlr_log_errno(WLR_ERROR,
"Failed to set keyboard mode K_CODE on tty %d", tty);
goto error; goto error;
} }

View File

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h> #include <linux/input.h>
@ -33,8 +34,14 @@ struct direct_session {
struct wl_event_source *vt_source; struct wl_event_source *vt_source;
}; };
static struct direct_session *direct_session_from_session(
struct wlr_session *base) {
assert(base->impl == &session_direct);
return (struct direct_session *)base;
}
static int direct_session_open(struct wlr_session *base, const char *path) { static int direct_session_open(struct wlr_session *base, const char *path) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
int fd = direct_ipc_open(session->sock, path); int fd = direct_ipc_open(session->sock, path);
if (fd < 0) { if (fd < 0) {
@ -57,7 +64,7 @@ static int direct_session_open(struct wlr_session *base, const char *path) {
} }
static void direct_session_close(struct wlr_session *base, int fd) { static void direct_session_close(struct wlr_session *base, int fd) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
struct stat st; struct stat st;
if (fstat(fd, &st) < 0) { if (fstat(fd, &st) < 0) {
@ -76,7 +83,7 @@ static void direct_session_close(struct wlr_session *base, int fd) {
} }
static bool direct_change_vt(struct wlr_session *base, unsigned vt) { static bool direct_change_vt(struct wlr_session *base, unsigned vt) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
// Only seat0 has VTs associated with it // Only seat0 has VTs associated with it
if (strcmp(session->base.seat, "seat0") != 0) { if (strcmp(session->base.seat, "seat0") != 0) {
@ -87,7 +94,7 @@ static bool direct_change_vt(struct wlr_session *base, unsigned vt) {
} }
static void direct_session_destroy(struct wlr_session *base) { static void direct_session_destroy(struct wlr_session *base) {
struct direct_session *session = wl_container_of(base, session, base); struct direct_session *session = direct_session_from_session(base);
if (strcmp(session->base.seat, "seat0") == 0) { if (strcmp(session->base.seat, "seat0") == 0) {
struct vt_mode mode = { struct vt_mode mode = {

View File

@ -37,8 +37,14 @@ struct logind_session {
char *path; char *path;
}; };
static struct logind_session *logind_session_from_session(
struct wlr_session *base) {
assert(base->impl == &session_logind);
return (struct logind_session *)base;
}
static int logind_take_device(struct wlr_session *base, const char *path) { static int logind_take_device(struct wlr_session *base, const char *path) {
struct logind_session *session = wl_container_of(base, session, base); struct logind_session *session = logind_session_from_session(base);
int ret; int ret;
int fd = -1; int fd = -1;
@ -83,7 +89,7 @@ error:
} }
static void logind_release_device(struct wlr_session *base, int fd) { static void logind_release_device(struct wlr_session *base, int fd) {
struct logind_session *session = wl_container_of(base, session, base); struct logind_session *session = logind_session_from_session(base);
int ret; int ret;
sd_bus_message *msg = NULL; sd_bus_message *msg = NULL;
@ -108,7 +114,7 @@ static void logind_release_device(struct wlr_session *base, int fd) {
} }
static bool logind_change_vt(struct wlr_session *base, unsigned vt) { static bool logind_change_vt(struct wlr_session *base, unsigned vt) {
struct logind_session *session = wl_container_of(base, session, base); struct logind_session *session = logind_session_from_session(base);
// Only seat0 has VTs associated with it // Only seat0 has VTs associated with it
if (strcmp(session->base.seat, "seat0") != 0) { if (strcmp(session->base.seat, "seat0") != 0) {
@ -212,7 +218,7 @@ static void release_control(struct logind_session *session) {
} }
static void logind_session_destroy(struct wlr_session *base) { static void logind_session_destroy(struct wlr_session *base) {
struct logind_session *session = wl_container_of(base, session, base); struct logind_session *session = logind_session_from_session(base);
release_control(session); release_control(session);

View File

@ -15,6 +15,12 @@
#include "util/signal.h" #include "util/signal.h"
#include "xdg-shell-unstable-v6-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h"
struct wlr_wl_backend *get_wl_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_wl(wlr_backend));
return (struct wlr_wl_backend *)wlr_backend;
}
static int dispatch_events(int fd, uint32_t mask, void *data) { static int dispatch_events(int fd, uint32_t mask, void *data) {
struct wlr_wl_backend *backend = data; struct wlr_wl_backend *backend = data;
int count = 0; int count = 0;
@ -39,8 +45,8 @@ static int dispatch_events(int fd, uint32_t mask, void *data) {
* compositor and creates surfaces for each output, then registers globals on * compositor and creates surfaces for each output, then registers globals on
* the specified display. * the specified display.
*/ */
static bool backend_start(struct wlr_backend *_backend) { static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
wlr_log(WLR_INFO, "Initializating wayland backend"); wlr_log(WLR_INFO, "Initializating wayland backend");
poll_wl_registry(backend); poll_wl_registry(backend);
@ -66,7 +72,7 @@ static bool backend_start(struct wlr_backend *_backend) {
} }
static void backend_destroy(struct wlr_backend *wlr_backend) { static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend; struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
if (backend == NULL) { if (backend == NULL) {
return; return;
} }
@ -118,7 +124,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
static struct wlr_renderer *backend_get_renderer( static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *wlr_backend) { struct wlr_backend *wlr_backend) {
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend; struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
return backend->renderer; return backend->renderer;
} }

View File

@ -15,7 +15,11 @@
#include "util/signal.h" #include "util/signal.h"
#include "xdg-shell-unstable-v6-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h"
int os_create_anonymous_file(off_t size); static struct wlr_wl_output *get_wl_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_wl(wlr_output));
return (struct wlr_wl_output *)wlr_output;
}
static struct wl_callback_listener frame_listener; static struct wl_callback_listener frame_listener;
@ -33,9 +37,9 @@ static struct wl_callback_listener frame_listener = {
.done = surface_frame_callback .done = surface_frame_callback
}; };
static bool output_set_custom_mode(struct wlr_output *_output, static bool output_set_custom_mode(struct wlr_output *wlr_output,
int32_t width, int32_t height, int32_t refresh) { int32_t width, int32_t height, int32_t refresh) {
struct wlr_wl_output *output = (struct wlr_wl_output *)_output; struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
wl_egl_window_resize(output->egl_window, width, height, 0, 0); wl_egl_window_resize(output->egl_window, width, height, 0, 0);
wlr_output_update_custom_mode(&output->wlr_output, width, height, 0); wlr_output_update_custom_mode(&output->wlr_output, width, height, 0);
return true; return true;
@ -44,7 +48,7 @@ static bool output_set_custom_mode(struct wlr_output *_output,
static bool output_make_current(struct wlr_output *wlr_output, static bool output_make_current(struct wlr_output *wlr_output,
int *buffer_age) { int *buffer_age) {
struct wlr_wl_output *output = struct wlr_wl_output *output =
(struct wlr_wl_output *)wlr_output; get_wl_output_from_output(wlr_output);
return wlr_egl_make_current(&output->backend->egl, output->egl_surface, return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
buffer_age); buffer_age);
} }
@ -52,7 +56,7 @@ static bool output_make_current(struct wlr_output *wlr_output,
static bool output_swap_buffers(struct wlr_output *wlr_output, static bool output_swap_buffers(struct wlr_output *wlr_output,
pixman_region32_t *damage) { pixman_region32_t *damage) {
struct wlr_wl_output *output = struct wlr_wl_output *output =
(struct wlr_wl_output *)wlr_output; get_wl_output_from_output(wlr_output);
if (output->frame_callback != NULL) { if (output->frame_callback != NULL) {
wlr_log(WLR_ERROR, "Skipping buffer swap"); wlr_log(WLR_ERROR, "Skipping buffer swap");
@ -66,21 +70,22 @@ static bool output_swap_buffers(struct wlr_output *wlr_output,
damage); damage);
} }
static void output_transform(struct wlr_output *_output, static void output_transform(struct wlr_output *wlr_output,
enum wl_output_transform transform) { enum wl_output_transform transform) {
struct wlr_wl_output *output = (struct wlr_wl_output *)_output; struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
output->wlr_output.transform = transform; output->wlr_output.transform = transform;
} }
static bool output_set_cursor(struct wlr_output *wlr_output, static bool output_set_cursor(struct wlr_output *wlr_output,
struct wlr_texture *texture, int32_t scale, struct wlr_texture *texture, int32_t scale,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y, enum wl_output_transform transform,
bool update_texture) { int32_t hotspot_x, int32_t hotspot_y, bool update_texture) {
struct wlr_wl_output *output = (struct wlr_wl_output *)wlr_output; struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
struct wlr_wl_backend *backend = output->backend; struct wlr_wl_backend *backend = output->backend;
struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y }; struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y };
wlr_box_transform(&hotspot, wlr_output_transform_invert(wlr_output->transform), wlr_box_transform(&hotspot,
wlr_output_transform_invert(wlr_output->transform),
output->cursor.width, output->cursor.height, &hotspot); output->cursor.width, output->cursor.height, &hotspot);
// TODO: use output->wlr_output.transform to transform pixels and hotpot // TODO: use output->wlr_output.transform to transform pixels and hotpot
@ -147,8 +152,7 @@ static bool output_set_cursor(struct wlr_output *wlr_output,
} }
static void output_destroy(struct wlr_output *wlr_output) { static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_wl_output *output = struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
(struct wlr_wl_output *)wlr_output;
if (output == NULL) { if (output == NULL) {
return; return;
} }
@ -215,7 +219,8 @@ static struct zxdg_surface_v6_listener xdg_surface_listener = {
.configure = xdg_surface_handle_configure, .configure = xdg_surface_handle_configure,
}; };
static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *xdg_toplevel, static void xdg_toplevel_handle_configure(void *data,
struct zxdg_toplevel_v6 *xdg_toplevel,
int32_t width, int32_t height, struct wl_array *states) { int32_t width, int32_t height, struct wl_array *states) {
struct wlr_wl_output *output = data; struct wlr_wl_output *output = data;
assert(output && output->xdg_toplevel == xdg_toplevel); assert(output && output->xdg_toplevel == xdg_toplevel);
@ -228,7 +233,8 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x
wlr_output_update_custom_mode(&output->wlr_output, width, height, 0); wlr_output_update_custom_mode(&output->wlr_output, width, height, 0);
} }
static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) { static void xdg_toplevel_handle_close(void *data,
struct zxdg_toplevel_v6 *xdg_toplevel) {
struct wlr_wl_output *output = data; struct wlr_wl_output *output = data;
assert(output && output->xdg_toplevel == xdg_toplevel); assert(output && output->xdg_toplevel == xdg_toplevel);
@ -240,9 +246,8 @@ static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
.close = xdg_toplevel_handle_close, .close = xdg_toplevel_handle_close,
}; };
struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_wl(_backend)); struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend;
if (!backend->started) { if (!backend->started) {
++backend->requested_outputs; ++backend->requested_outputs;
return NULL; return NULL;

View File

@ -122,11 +122,11 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
} }
static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) {
// This space is intentionally left blank
} }
static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_axis_source(void *data,
uint32_t axis_source) { struct wl_pointer *wl_pointer, uint32_t axis_source) {
struct wlr_wl_backend *backend = data; struct wlr_wl_backend *backend = data;
struct wlr_wl_pointer *pointer = backend->current_pointer; struct wlr_wl_pointer *pointer = backend->current_pointer;
if (pointer == NULL) { if (pointer == NULL) {
@ -138,11 +138,11 @@ static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer
static void pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis) { uint32_t time, uint32_t axis) {
// This space is intentionally left blank
} }
static void pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_axis_discrete(void *data,
uint32_t axis, int32_t discrete) { struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) {
struct wlr_wl_backend *backend = data; struct wlr_wl_backend *backend = data;
struct wlr_wl_pointer *pointer = backend->current_pointer; struct wlr_wl_pointer *pointer = backend->current_pointer;
if (pointer == NULL) { if (pointer == NULL) {
@ -239,9 +239,9 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar
mods_locked, group); mods_locked, group);
} }
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_handle_repeat_info(void *data,
int32_t rate, int32_t delay) { struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay) {
// This space is intentionally left blank
} }
static struct wl_keyboard_listener keyboard_listener = { static struct wl_keyboard_listener keyboard_listener = {
@ -253,8 +253,15 @@ static struct wl_keyboard_listener keyboard_listener = {
.repeat_info = keyboard_handle_repeat_info .repeat_info = keyboard_handle_repeat_info
}; };
static struct wlr_wl_input_device *get_wl_input_device_from_input_device(
struct wlr_input_device *wlr_dev) {
assert(wlr_input_device_is_wl(wlr_dev));
return (struct wlr_wl_input_device *)wlr_dev;
}
static void input_device_destroy(struct wlr_input_device *wlr_dev) { static void input_device_destroy(struct wlr_input_device *wlr_dev) {
struct wlr_wl_input_device *dev = (struct wlr_wl_input_device *)wlr_dev; struct wlr_wl_input_device *dev =
get_wl_input_device_from_input_device(wlr_dev);
if (dev->resource) { if (dev->resource) {
wl_proxy_destroy(dev->resource); wl_proxy_destroy(dev->resource);
} }
@ -399,7 +406,8 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
} }
} }
static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { static void seat_handle_name(void *data, struct wl_seat *wl_seat,
const char *name) {
struct wlr_wl_backend *backend = data; struct wlr_wl_backend *backend = data;
assert(backend->seat == wl_seat); assert(backend->seat == wl_seat);
// Do we need to check if seatName was previously set for name change? // Do we need to check if seatName was previously set for name change?

View File

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -22,8 +23,8 @@
#include "backend/x11.h" #include "backend/x11.h"
#include "util/signal.h" #include "util/signal.h"
struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11, struct wlr_x11_output *get_x11_output_from_window_id(
xcb_window_t window) { struct wlr_x11_backend *x11, xcb_window_t window) {
struct wlr_x11_output *output; struct wlr_x11_output *output;
wl_list_for_each(output, &x11->outputs, link) { wl_list_for_each(output, &x11->outputs, link) {
if (output->win == window) { if (output->win == window) {
@ -88,8 +89,14 @@ static int x11_event(int fd, uint32_t mask, void *data) {
return 0; return 0;
} }
struct wlr_x11_backend *get_x11_backend_from_backend(
struct wlr_backend *wlr_backend) {
assert(wlr_backend_is_x11(wlr_backend));
return (struct wlr_x11_backend *)wlr_backend;
}
static bool backend_start(struct wlr_backend *backend) { static bool backend_start(struct wlr_backend *backend) {
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
x11->started = true; x11->started = true;
struct { struct {
@ -183,7 +190,7 @@ static void backend_destroy(struct wlr_backend *backend) {
return; return;
} }
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
struct wlr_x11_output *output, *tmp; struct wlr_x11_output *output, *tmp;
wl_list_for_each_safe(output, tmp, &x11->outputs, link) { wl_list_for_each_safe(output, tmp, &x11->outputs, link) {
@ -213,7 +220,7 @@ static void backend_destroy(struct wlr_backend *backend) {
static struct wlr_renderer *backend_get_renderer( static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *backend) { struct wlr_backend *backend) {
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
return x11->renderer; return x11->renderer;
} }
@ -234,7 +241,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
} }
struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
const char *x11_display, wlr_renderer_create_func_t create_renderer_func) { const char *x11_display,
wlr_renderer_create_func_t create_renderer_func) {
struct wlr_x11_backend *x11 = calloc(1, sizeof(*x11)); struct wlr_x11_backend *x11 = calloc(1, sizeof(*x11));
if (!x11) { if (!x11) {
return NULL; return NULL;

View File

@ -15,7 +15,8 @@ static int signal_frame(void *data) {
return 0; return 0;
} }
static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_conn) { static void parse_xcb_setup(struct wlr_output *output,
xcb_connection_t *xcb_conn) {
const xcb_setup_t *xcb_setup = xcb_get_setup(xcb_conn); const xcb_setup_t *xcb_setup = xcb_get_setup(xcb_conn);
snprintf(output->make, sizeof(output->make), "%.*s", snprintf(output->make, sizeof(output->make), "%.*s",
@ -26,8 +27,14 @@ static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_con
xcb_setup->protocol_minor_version); xcb_setup->protocol_minor_version);
} }
static struct wlr_x11_output *get_x11_output_from_output(
struct wlr_output *wlr_output) {
assert(wlr_output_is_x11(wlr_output));
return (struct wlr_x11_output *)wlr_output;
}
static void output_set_refresh(struct wlr_output *wlr_output, int32_t refresh) { static void output_set_refresh(struct wlr_output *wlr_output, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
if (refresh <= 0) { if (refresh <= 0) {
refresh = X11_DEFAULT_REFRESH; refresh = X11_DEFAULT_REFRESH;
@ -41,18 +48,20 @@ static void output_set_refresh(struct wlr_output *wlr_output, int32_t refresh) {
static bool output_set_custom_mode(struct wlr_output *wlr_output, static bool output_set_custom_mode(struct wlr_output *wlr_output,
int32_t width, int32_t height, int32_t refresh) { int32_t width, int32_t height, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
output_set_refresh(&output->wlr_output, refresh); output_set_refresh(&output->wlr_output, refresh);
const uint32_t values[] = { width, height }; const uint32_t values[] = { width, height };
xcb_void_cookie_t cookie = xcb_configure_window_checked(x11->xcb_conn, output->win, xcb_void_cookie_t cookie = xcb_configure_window_checked(
x11->xcb_conn, output->win,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
xcb_generic_error_t *error; xcb_generic_error_t *error;
if ((error = xcb_request_check(x11->xcb_conn, cookie))) { if ((error = xcb_request_check(x11->xcb_conn, cookie))) {
wlr_log(WLR_ERROR, "Could not set window size to %dx%d\n", width, height); wlr_log(WLR_ERROR, "Could not set window size to %dx%d\n",
width, height);
free(error); free(error);
return false; return false;
} }
@ -62,12 +71,12 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output,
static void output_transform(struct wlr_output *wlr_output, static void output_transform(struct wlr_output *wlr_output,
enum wl_output_transform transform) { enum wl_output_transform transform) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
output->wlr_output.transform = transform; output->wlr_output.transform = transform;
} }
static void output_destroy(struct wlr_output *wlr_output) { static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
wlr_input_device_destroy(&output->pointer_dev); wlr_input_device_destroy(&output->pointer_dev);
@ -80,8 +89,9 @@ static void output_destroy(struct wlr_output *wlr_output) {
free(output); free(output);
} }
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { static bool output_make_current(struct wlr_output *wlr_output,
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; int *buffer_age) {
struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
return wlr_egl_make_current(&x11->egl, output->surf, buffer_age); return wlr_egl_make_current(&x11->egl, output->surf, buffer_age);
@ -104,8 +114,7 @@ static const struct wlr_output_impl output_impl = {
}; };
struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
assert(wlr_backend_is_x11(backend)); struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
if (!x11->started) { if (!x11->started) {
++x11->requested_outputs; ++x11->requested_outputs;
@ -198,7 +207,8 @@ void handle_x11_configure_notify(struct wlr_x11_output *output,
// Move the pointer to its new location // Move the pointer to its new location
update_x11_pointer_position(output, output->x11->time); update_x11_pointer_position(output, output->x11->time);
} else { } else {
wlr_log(WLR_DEBUG,"Ignoring X11 configure event for height=%d, width=%d", wlr_log(WLR_DEBUG,
"Ignoring X11 configure event for height=%d, width=%d",
ev->width, ev->height); ev->width, ev->height);
} }
} }

View File

@ -138,6 +138,8 @@ struct wlr_drm_connector {
struct wl_list link; struct wl_list link;
}; };
struct wlr_drm_backend *get_drm_backend_from_backend(
struct wlr_backend *wlr_backend);
bool check_drm_features(struct wlr_drm_backend *drm); bool check_drm_features(struct wlr_drm_backend *drm);
bool init_drm_resources(struct wlr_drm_backend *drm); bool init_drm_resources(struct wlr_drm_backend *drm);
void finish_drm_resources(struct wlr_drm_backend *drm); void finish_drm_resources(struct wlr_drm_backend *drm);

View File

@ -34,4 +34,7 @@ struct wlr_headless_input_device {
struct wlr_headless_backend *backend; struct wlr_headless_backend *backend;
}; };
struct wlr_headless_backend *headless_backend_from_backend(
struct wlr_backend *wlr_backend);
#endif #endif

View File

@ -4,6 +4,7 @@
#include <libinput.h> #include <libinput.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/libinput.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_list.h> #include <wlr/types/wlr_list.h>

View File

@ -78,6 +78,8 @@ struct wlr_wl_pointer {
struct wl_listener output_destroy; struct wl_listener output_destroy;
}; };
struct wlr_wl_backend *get_wl_backend_from_backend(
struct wlr_backend *wlr_backend);
void poll_wl_registry(struct wlr_wl_backend *backend); void poll_wl_registry(struct wlr_wl_backend *backend);
void update_wl_output_cursor(struct wlr_wl_output *output); void update_wl_output_cursor(struct wlr_wl_output *output);
struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer); struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer);

View File

@ -72,8 +72,10 @@ struct wlr_x11_backend {
struct wl_listener display_destroy; struct wl_listener display_destroy;
}; };
struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11, struct wlr_x11_backend *get_x11_backend_from_backend(
xcb_window_t window); struct wlr_backend *wlr_backend);
struct wlr_x11_output *get_x11_output_from_window_id(
struct wlr_x11_backend *x11, xcb_window_t window);
extern const struct wlr_keyboard_impl keyboard_impl; extern const struct wlr_keyboard_impl keyboard_impl;
extern const struct wlr_pointer_impl pointer_impl; extern const struct wlr_pointer_impl pointer_impl;