backend/x11: add assertions

master
emersion 6 years ago
parent e98cb7c5ab
commit 02231554c8

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@ -22,8 +23,8 @@
#include "backend/x11.h"
#include "util/signal.h"
struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11,
xcb_window_t window) {
struct wlr_x11_output *get_x11_output_from_window_id(
struct wlr_x11_backend *x11, xcb_window_t window) {
struct wlr_x11_output *output;
wl_list_for_each(output, &x11->outputs, link) {
if (output->win == window) {
@ -88,8 +89,14 @@ static int x11_event(int fd, uint32_t mask, void *data) {
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) {
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
x11->started = true;
struct {
@ -183,7 +190,7 @@ static void backend_destroy(struct wlr_backend *backend) {
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;
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(
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;
}
@ -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,
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));
if (!x11) {
return NULL;

@ -15,7 +15,8 @@ static int signal_frame(void *data) {
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);
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);
}
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) {
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) {
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,
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;
output_set_refresh(&output->wlr_output, refresh);
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_generic_error_t *error;
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);
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,
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;
}
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;
wlr_input_device_destroy(&output->pointer_dev);
@ -80,8 +89,9 @@ static void output_destroy(struct wlr_output *wlr_output) {
free(output);
}
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
static bool output_make_current(struct wlr_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;
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) {
assert(wlr_backend_is_x11(backend));
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
if (!x11->started) {
++x11->requested_outputs;
@ -198,7 +207,8 @@ void handle_x11_configure_notify(struct wlr_x11_output *output,
// Move the pointer to its new location
update_x11_pointer_position(output, output->x11->time);
} 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);
}
}

@ -72,8 +72,10 @@ struct wlr_x11_backend {
struct wl_listener display_destroy;
};
struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11,
xcb_window_t window);
struct wlr_x11_backend *get_x11_backend_from_backend(
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_pointer_impl pointer_impl;

Loading…
Cancel
Save