Merge branch 'master' into feature/data-device-selection

This commit is contained in:
Tony Crisci 2017-10-24 07:28:04 -04:00
commit 1dbe314937
55 changed files with 521 additions and 426 deletions

View File

@ -9,9 +9,9 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include "backend/drm/drm.h" #include "backend/drm/drm.h"
static bool wlr_drm_backend_start(struct wlr_backend *backend) { static bool wlr_drm_backend_start(struct wlr_backend *backend) {
@ -29,8 +29,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_drm_restore_outputs(drm); wlr_drm_restore_outputs(drm);
for (size_t i = 0; drm->outputs && i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link) {
wlr_output_destroy(&conn->output); wlr_output_destroy(&conn->output);
} }
@ -38,7 +38,6 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_drm_renderer_finish(&drm->renderer); wlr_drm_renderer_finish(&drm->renderer);
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(drm->session, drm->fd);
wl_event_source_remove(drm->drm_event); wl_event_source_remove(drm->drm_event);
list_free(drm->outputs);
free(drm); free(drm);
} }
@ -63,10 +62,13 @@ static void session_signal(struct wl_listener *listener, void *data) {
if (session->active) { if (session->active) {
wlr_log(L_INFO, "DRM fd resumed"); wlr_log(L_INFO, "DRM fd resumed");
wlr_drm_scan_connectors(drm);
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link){
wlr_drm_connector_start_renderer(conn); if (conn->output.current_mode) {
wlr_output_set_mode(&conn->output, conn->output.current_mode);
}
if (!conn->crtc) { if (!conn->crtc) {
continue; continue;
@ -110,11 +112,7 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
wlr_backend_init(&drm->backend, &backend_impl); wlr_backend_init(&drm->backend, &backend_impl);
drm->session = session; drm->session = session;
drm->outputs = list_create(); wl_list_init(&drm->outputs);
if (!drm->outputs) {
wlr_log(L_ERROR, "Failed to allocate list");
goto error_backend;
}
drm->fd = gpu_fd; drm->fd = gpu_fd;
drm->parent = (struct wlr_drm_backend *)parent; drm->parent = (struct wlr_drm_backend *)parent;
@ -158,8 +156,6 @@ error_event:
wl_event_source_remove(drm->drm_event); wl_event_source_remove(drm->drm_event);
error_fd: error_fd:
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(drm->session, drm->fd);
list_free(drm->outputs);
error_backend:
free(drm); free(drm);
return NULL; return NULL;
} }

View File

@ -177,9 +177,6 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) {
if (plane->wlr_tex) { if (plane->wlr_tex) {
wlr_texture_destroy(plane->wlr_tex); wlr_texture_destroy(plane->wlr_tex);
} }
if (plane->wlr_rend) {
wlr_renderer_destroy(plane->wlr_rend);
}
} }
free(drm->crtcs); free(drm->crtcs);
@ -193,7 +190,7 @@ static void wlr_drm_connector_make_current(struct wlr_output *output) {
static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { static void wlr_drm_connector_swap_buffers(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_plane *plane = crtc->primary;
@ -214,12 +211,13 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) {
} }
static void wlr_drm_connector_set_gamma(struct wlr_output *output, static void wlr_drm_connector_set_gamma(struct wlr_output *output,
uint16_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 = (struct wlr_drm_connector *)output;
drmModeCrtcSetGamma(conn->drm->fd, conn->crtc->id, size, r, g, b); struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
drmModeCrtcSetGamma(drm->fd, conn->crtc->id, size, r, g, b);
} }
static uint16_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) { static uint32_t wlr_drm_connector_get_gamma_size(struct wlr_output *output) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
drmModeCrtc *crtc = conn->old_crtc; drmModeCrtc *crtc = conn->old_crtc;
return crtc ? crtc->gamma_size : 0; return crtc ? crtc->gamma_size : 0;
@ -230,7 +228,7 @@ void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn) {
return; return;
} }
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_plane *plane = crtc->primary;
@ -253,7 +251,7 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) {
return; return;
} }
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
drm->iface->conn_enable(drm, conn, enable); drm->iface->conn_enable(drm, conn, enable);
if (enable) { if (enable) {
@ -261,7 +259,8 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) {
} }
} }
static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in) { static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in,
bool *changed_outputs) {
// overlay, primary, cursor // overlay, primary, cursor
for (int type = 0; type < 3; ++type) { for (int type = 0; type < 3; ++type) {
if (drm->num_type_planes[type] == 0) { if (drm->num_type_planes[type] == 0) {
@ -300,6 +299,7 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in)
struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]]; struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]];
if (*old != new) { if (*old != new) {
changed_outputs[crtc_res[i]] = true;
if (*old) { if (*old) {
wlr_drm_surface_finish(&(*old)->surf); wlr_drm_surface_finish(&(*old)->surf);
} }
@ -310,10 +310,12 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in)
} }
} }
static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) { static void realloc_crtcs(struct wlr_drm_backend *drm,
struct wlr_drm_connector *conn, bool *changed_outputs) {
uint32_t crtc[drm->num_crtcs]; uint32_t crtc[drm->num_crtcs];
uint32_t crtc_res[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs];
uint32_t possible_crtc[drm->outputs->length]; ssize_t num_outputs = wl_list_length(&drm->outputs);
uint32_t possible_crtc[num_outputs];
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
crtc[i] = UNMATCHED; crtc[i] = UNMATCHED;
@ -321,54 +323,71 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
memset(possible_crtc, 0, sizeof(possible_crtc)); memset(possible_crtc, 0, sizeof(possible_crtc));
ssize_t index = -1; ssize_t index = -1, i = -1;
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *c;
struct wlr_drm_connector *c = drm->outputs->items[i]; wl_list_for_each(c, &drm->outputs, link) {
i++;
if (c == conn) { if (c == conn) {
index = i; index = i;
} }
if (c->state != WLR_DRM_CONN_CONNECTED) { if (c->crtc) {
continue; crtc[c->crtc - drm->crtcs] = i;
} }
if (c->state == WLR_DRM_CONN_CONNECTED) {
possible_crtc[i] = c->possible_crtc; possible_crtc[i] = c->possible_crtc;
crtc[c->crtc - drm->crtcs] = i; }
} }
assert(index != -1); assert(index != -1);
possible_crtc[index] = conn->possible_crtc; possible_crtc[index] = conn->possible_crtc;
match_obj(drm->outputs->length, possible_crtc, drm->num_crtcs, match_obj(wl_list_length(&drm->outputs), possible_crtc,
crtc, crtc_res); drm->num_crtcs, crtc, crtc_res);
bool matched = false; bool matched[num_outputs];
memset(matched, false, sizeof(matched));
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
// We don't want any of the current monitors to be deactivated. if (crtc_res[i] != UNMATCHED) {
if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) { matched[crtc_res[i]] = true;
return;
}
if (crtc_res[i] == index) {
matched = true;
} }
} }
// There is no point doing anything if this monitor doesn't get activated // There is no point doing anything if this monitor doesn't get activated
if (!matched) { if (!matched[index]) {
return; return;
} }
for (size_t i = 0; i < drm->num_crtcs; ++i) {
// We don't want any of the current monitors to be deactivated.
if (crtc[i] != UNMATCHED && !matched[crtc[i]]) {
return;
}
}
changed_outputs[index] = true;
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
if (crtc_res[i] == UNMATCHED) { if (crtc_res[i] == UNMATCHED) {
continue; continue;
} }
if (crtc_res[i] != crtc[i]) { if (crtc_res[i] != crtc[i]) {
struct wlr_drm_connector *c = drm->outputs->items[crtc_res[i]]; changed_outputs[crtc_res[i]] = true;
struct wlr_drm_connector *c;
size_t pos = 0;
wl_list_for_each(c, &drm->outputs, link) {
if (pos == crtc_res[i]) {
break;
}
pos++;
}
c->crtc = &drm->crtcs[i]; c->crtc = &drm->crtcs[i];
} }
} }
realloc_planes(drm, crtc_res); realloc_planes(drm, crtc_res, changed_outputs);
} }
static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) { static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) {
@ -406,7 +425,8 @@ error_conn:
static bool wlr_drm_connector_set_mode(struct wlr_output *output, static bool wlr_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 = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
bool changed_outputs[wl_list_length(&drm->outputs)];
wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name, wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", conn->output.name,
mode->width, mode->height, mode->refresh); mode->width, mode->height, mode->refresh);
@ -416,7 +436,8 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
goto error_conn; goto error_conn;
} }
realloc_crtcs(drm, conn); memset(changed_outputs, false, sizeof(changed_outputs));
realloc_crtcs(drm, conn, changed_outputs);
if (!conn->crtc) { if (!conn->crtc) {
wlr_log(L_ERROR, "Unable to match %s with a CRTC", conn->output.name); wlr_log(L_ERROR, "Unable to match %s with a CRTC", conn->output.name);
@ -431,19 +452,23 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
crtc->cursor ? crtc->cursor - drm->cursor_planes : -1); crtc->cursor ? crtc->cursor - drm->cursor_planes : -1);
conn->state = WLR_DRM_CONN_CONNECTED; conn->state = WLR_DRM_CONN_CONNECTED;
conn->output.current_mode = mode;
if (conn->output.width != mode->width || conn->output.height != mode->height) {
conn->output.width = mode->width; conn->output.width = mode->width;
conn->output.height = mode->height; conn->output.height = mode->height;
conn->output.current_mode = mode;
wl_signal_emit(&conn->output.events.resolution, &conn->output); wl_signal_emit(&conn->output.events.resolution, &conn->output);
}
// Since realloc_crtcs can deallocate planes on OTHER outputs, // Since realloc_crtcs can deallocate planes on OTHER outputs,
// we actually need to reinitalise all of them // we actually need to reinitalise any than has changed
for (size_t i = 0; i < drm->outputs->length; ++i) { ssize_t output_index = -1;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link) {
output_index += 1;
struct wlr_output_mode *mode = conn->output.current_mode; struct wlr_output_mode *mode = conn->output.current_mode;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (conn->state != WLR_DRM_CONN_CONNECTED) { if (conn->state != WLR_DRM_CONN_CONNECTED ||
!changed_outputs[output_index]) {
continue; continue;
} }
@ -472,7 +497,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y, bool update_pixels) { int32_t hotspot_x, int32_t hotspot_y, bool update_pixels) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
struct wlr_drm_renderer *renderer = &drm->renderer; struct wlr_drm_renderer *renderer = &drm->renderer;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
@ -525,12 +550,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
// TODO the image needs to be rotated depending on the output rotation // TODO the image needs to be rotated depending on the output rotation
plane->wlr_rend = wlr_gles2_renderer_create(&drm->backend); plane->wlr_tex = wlr_render_texture_create(plane->surf.renderer->wlr_rend);
if (!plane->wlr_rend) {
return false;
}
plane->wlr_tex = wlr_render_texture_create(plane->wlr_rend);
if (!plane->wlr_tex) { if (!plane->wlr_tex) {
return false; return false;
} }
@ -595,7 +615,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
float matrix[16]; float matrix[16];
wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0); wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0);
wlr_render_with_matrix(plane->wlr_rend, plane->wlr_tex, &matrix); wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, &matrix);
glFinish(); glFinish();
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);
@ -612,7 +632,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
static bool wlr_drm_connector_move_cursor(struct wlr_output *output, static bool wlr_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 = (struct wlr_drm_connector *)output;
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
int width, height, tmp; int width, height, tmp;
wlr_output_effective_resolution(output, &width, &height); wlr_output_effective_resolution(output, &width, &height);
@ -667,13 +687,6 @@ static int retry_pageflip(void *data) {
return 0; return 0;
} }
static int find_id(const void *item, const void *cmp_to) {
const struct wlr_drm_connector *conn = item;
const uint32_t *id = cmp_to;
return (int)conn->id - (int)*id;
}
static const int32_t subpixel_map[] = { static const int32_t subpixel_map[] = {
[DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN, [DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN,
[DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, [DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB,
@ -692,8 +705,9 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
return; return;
} }
size_t seen_len = drm->outputs->length; size_t seen_len = wl_list_length(&drm->outputs);
// +1 so it can never be 0 // +1 so length can never be 0, which is undefined behaviour.
// Last element isn't used.
bool seen[seen_len + 1]; bool seen[seen_len + 1];
memset(seen, 0, sizeof(seen)); memset(seen, 0, sizeof(seen));
@ -704,33 +718,39 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); wlr_log_errno(L_ERROR, "Failed to get DRM connector");
continue; continue;
} }
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
struct wlr_drm_connector *wlr_conn; int index = -1;
int index = list_seq_find(drm->outputs, find_id, &drm_conn->connector_id); struct wlr_drm_connector *c, *wlr_conn = NULL;
wl_list_for_each(c, &drm->outputs, link) {
index++;
if (c->id == drm_conn->connector_id) {
wlr_conn = c;
break;
}
}
if (index == -1) { if (!wlr_conn) {
wlr_conn = calloc(1, sizeof(*wlr_conn)); wlr_conn = calloc(1, sizeof(*wlr_conn));
if (!wlr_conn) { if (!wlr_conn) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
drmModeFreeEncoder(curr_enc);
drmModeFreeConnector(drm_conn); drmModeFreeConnector(drm_conn);
continue; continue;
} }
wlr_output_init(&wlr_conn->output, &output_impl); wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl);
struct wl_event_loop *ev = wl_display_get_event_loop(drm->display); struct wl_event_loop *ev = wl_display_get_event_loop(drm->display);
wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip,
wlr_conn); wlr_conn);
wlr_conn->drm = drm;
wlr_conn->state = WLR_DRM_CONN_DISCONNECTED; wlr_conn->state = WLR_DRM_CONN_DISCONNECTED;
wlr_conn->id = drm_conn->connector_id; wlr_conn->id = drm_conn->connector_id;
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
if (curr_enc) { if (curr_enc) {
wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id); wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id);
drmModeFreeEncoder(curr_enc);
} }
wlr_conn->output.phys_width = drm_conn->mmWidth; wlr_conn->output.phys_width = drm_conn->mmWidth;
@ -749,23 +769,25 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
parse_edid(&wlr_conn->output, edid_len, edid); parse_edid(&wlr_conn->output, edid_len, edid);
free(edid); free(edid);
if (list_add(drm->outputs, wlr_conn) == -1) { wl_list_insert(&drm->outputs, &wlr_conn->link);
wlr_log_errno(L_ERROR, "Allocation failed");
drmModeFreeConnector(drm_conn);
wl_event_source_remove(wlr_conn->retry_pageflip);
free(wlr_conn);
continue;
}
wlr_output_create_global(&wlr_conn->output, drm->display);
wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name); wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name);
} else { } else {
wlr_conn = drm->outputs->items[index];
seen[index] = true; seen[index] = true;
} }
if (curr_enc) {
for (size_t i = 0; i < drm->num_crtcs; ++i) {
if (drm->crtcs[i].id == curr_enc->crtc_id) {
wlr_conn->crtc = &drm->crtcs[i];
break;
}
}
} else {
wlr_conn->crtc = NULL;
}
if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED && if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED &&
drm_conn->connection == DRM_MODE_CONNECTED) { drm_conn->connection == DRM_MODE_CONNECTED) {
wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name); wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name);
wlr_log(L_INFO, "Detected modes:"); wlr_log(L_INFO, "Detected modes:");
@ -784,51 +806,50 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
mode->wlr_mode.width, mode->wlr_mode.height, mode->wlr_mode.width, mode->wlr_mode.height,
mode->wlr_mode.refresh); mode->wlr_mode.refresh);
if (list_add(wlr_conn->output.modes, mode) == -1) { wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link);
wlr_log_errno(L_ERROR, "Allocation failed");
free(mode);
continue;
}
} }
wlr_output_create_global(&wlr_conn->output, drm->display);
wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET;
wlr_log(L_INFO, "Sending modesetting signal for '%s'", wlr_log(L_INFO, "Sending modesetting signal for '%s'",
wlr_conn->output.name); wlr_conn->output.name);
wl_signal_emit(&drm->backend.events.output_add, &wlr_conn->output); wl_signal_emit(&drm->backend.events.output_add, &wlr_conn->output);
} else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED && } else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED &&
drm_conn->connection != DRM_MODE_CONNECTED) { drm_conn->connection != DRM_MODE_CONNECTED) {
wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name);
wlr_output_destroy_global(&wlr_conn->output);
wlr_drm_connector_cleanup(wlr_conn); wlr_drm_connector_cleanup(wlr_conn);
} }
drmModeFreeEncoder(curr_enc);
drmModeFreeConnector(drm_conn); drmModeFreeConnector(drm_conn);
} }
drmModeFreeResources(res); drmModeFreeResources(res);
for (size_t i = seen_len; i-- > 0;) { struct wlr_drm_connector *conn, *tmp_conn;
if (seen[i]) { size_t index = wl_list_length(&drm->outputs);
wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) {
index--;
if (index >= seen_len || seen[index]) {
continue; continue;
} }
struct wlr_drm_connector *conn = drm->outputs->items[i];
wlr_log(L_INFO, "'%s' disappeared", conn->output.name); wlr_log(L_INFO, "'%s' disappeared", conn->output.name);
wlr_drm_connector_cleanup(conn); wlr_drm_connector_cleanup(conn);
drmModeFreeCrtc(conn->old_crtc); drmModeFreeCrtc(conn->old_crtc);
wl_event_source_remove(conn->retry_pageflip); wl_event_source_remove(conn->retry_pageflip);
free(conn); free(conn);
list_del(drm->outputs, i);
} }
} }
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 = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend;
conn->pageflip_pending = false; conn->pageflip_pending = false;
if (conn->state != WLR_DRM_CONN_CONNECTED) { if (conn->state != WLR_DRM_CONN_CONNECTED) {
@ -856,10 +877,10 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) {
} }
void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
uint64_t to_close = (1 << drm->outputs->length) - 1; uint64_t to_close = (1 << wl_list_length(&drm->outputs)) - 1;
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link) {
if (conn->state == WLR_DRM_CONN_CONNECTED) { if (conn->state == WLR_DRM_CONN_CONNECTED) {
conn->state = WLR_DRM_CONN_CLEANUP; conn->state = WLR_DRM_CONN_CLEANUP;
} }
@ -869,11 +890,13 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
while (to_close && time(NULL) < timeout) { while (to_close && time(NULL) < timeout) {
wlr_drm_event(drm->fd, 0, NULL); wlr_drm_event(drm->fd, 0, NULL);
for (size_t i = 0; i < drm->outputs->length; ++i) { size_t i = 0;
struct wlr_drm_connector *conn = drm->outputs->items[i]; struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link) {
if (conn->state != WLR_DRM_CONN_CLEANUP || !conn->pageflip_pending) { if (conn->state != WLR_DRM_CONN_CLEANUP || !conn->pageflip_pending) {
to_close &= ~(1 << i); to_close &= ~(1 << i);
} }
i++;
} }
} }
@ -881,8 +904,7 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
wlr_log(L_ERROR, "Timed out stopping output renderers"); wlr_log(L_ERROR, "Timed out stopping output renderers");
} }
for (size_t i = 0; i < drm->outputs->length; ++i) { wl_list_for_each(conn, &drm->outputs, link) {
struct wlr_drm_connector *conn = drm->outputs->items[i];
drmModeCrtc *crtc = conn->old_crtc; drmModeCrtc *crtc = conn->old_crtc;
if (!crtc) { if (!crtc) {
continue; continue;
@ -899,7 +921,7 @@ void wlr_drm_connector_cleanup(struct wlr_drm_connector *conn) {
return; return;
} }
struct wlr_drm_backend *drm = conn->drm; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend;
switch (conn->state) { switch (conn->state) {
case WLR_DRM_CONN_CONNECTED: case WLR_DRM_CONN_CONNECTED:

View File

@ -8,8 +8,8 @@
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wlr/egl.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/render/egl.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/render/gles2.h> #include <wlr/render/gles2.h>
#include <wlr/render.h> #include <wlr/render.h>

View File

@ -99,15 +99,15 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) {
} }
struct wlr_libinput_backend *backend = (struct wlr_libinput_backend *)_backend; struct wlr_libinput_backend *backend = (struct wlr_libinput_backend *)_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++) {
list_t *wlr_devices = backend->wlr_device_lists->items[i]; struct wlr_list *wlr_devices = backend->wlr_device_lists->items[i];
for (size_t j = 0; j < wlr_devices->length; j++) { for (size_t j = 0; j < wlr_devices->length; j++) {
struct wlr_input_device *wlr_dev = wlr_devices->items[j]; struct wlr_input_device *wlr_dev = wlr_devices->items[j];
wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wl_signal_emit(&backend->backend.events.input_remove, wlr_dev);
wlr_input_device_destroy(wlr_dev); wlr_input_device_destroy(wlr_dev);
} }
list_free(wlr_devices); wlr_list_free(wlr_devices);
} }
list_free(backend->wlr_device_lists); wlr_list_free(backend->wlr_device_lists);
wl_event_source_remove(backend->input_event); wl_event_source_remove(backend->input_event);
libinput_unref(backend->libinput_context); libinput_unref(backend->libinput_context);
free(backend); free(backend);
@ -148,7 +148,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
} }
wlr_backend_init(&backend->backend, &backend_impl); wlr_backend_init(&backend->backend, &backend_impl);
if (!(backend->wlr_device_lists = list_create())) { if (!(backend->wlr_device_lists = wlr_list_create())) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
goto error_backend; goto error_backend;
} }

View File

@ -3,19 +3,19 @@
#include <libinput.h> #include <libinput.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/util/list.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wayland-util.h>
#include "backend/libinput.h" #include "backend/libinput.h"
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) {
list_t *wlr_devices = libinput_device_get_user_data(libinput_dev); struct wl_list *wlr_devices = libinput_device_get_user_data(libinput_dev);
if (!wlr_devices) { if (!wlr_devices) {
return NULL; return NULL;
} }
for (size_t i = 0; i < wlr_devices->length; ++i) { struct wlr_input_device *dev;
struct wlr_input_device *dev = wlr_devices->items[i]; wl_list_for_each(dev, wlr_devices, link) {
if (dev->type == desired_type) { if (dev->type == desired_type) {
return dev; return dev;
} }
@ -35,7 +35,7 @@ static 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 libinput_device *libinput_dev,
list_t *wlr_devices, enum wlr_input_device_type type) { 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);
@ -44,10 +44,7 @@ static struct wlr_input_device *allocate_device(
return NULL; return NULL;
} }
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device;
if (list_add(wlr_devices, wlr_dev) == -1) { wl_list_insert(wlr_devices, &wlr_dev->link);
free(wlr_libinput_dev);
return NULL;
}
wlr_libinput_dev->handle = libinput_dev; wlr_libinput_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,
@ -67,7 +64,8 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
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);
list_t *wlr_devices = list_create(); struct wl_list *wlr_devices = calloc(1, sizeof(struct wl_list));
wl_list_init(wlr_devices);
if (!wlr_devices) { if (!wlr_devices) {
goto fail; goto fail;
} }
@ -145,23 +143,26 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
// TODO // TODO
} }
if (wlr_devices->length > 0) { if (wl_list_length(wlr_devices) > 0) {
libinput_device_set_user_data(libinput_dev, wlr_devices); libinput_device_set_user_data(libinput_dev, wlr_devices);
list_add(backend->wlr_device_lists, wlr_devices); wlr_list_add(backend->wlr_device_lists, wlr_devices);
} else { } else {
list_free(wlr_devices); free(wlr_devices);
} }
return; return;
fail: fail:
wlr_log(L_ERROR, "Could not allocate new device"); wlr_log(L_ERROR, "Could not allocate new device");
list_foreach(wlr_devices, free); struct wlr_input_device *dev, *tmp_dev;
list_free(wlr_devices); wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
free(dev);
}
free(wlr_devices);
} }
static void handle_device_removed(struct wlr_libinput_backend *backend, static void handle_device_removed(struct wlr_libinput_backend *backend,
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
list_t *wlr_devices = libinput_device_get_user_data(libinput_dev); struct wl_list *wlr_devices = libinput_device_get_user_data(libinput_dev);
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);
@ -169,18 +170,18 @@ static void handle_device_removed(struct wlr_libinput_backend *backend,
if (!wlr_devices) { if (!wlr_devices) {
return; return;
} }
for (size_t i = 0; i < wlr_devices->length; i++) { struct wlr_input_device *dev, *tmp_dev;
struct wlr_input_device *wlr_dev = wlr_devices->items[i]; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) {
wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wl_signal_emit(&backend->backend.events.input_remove, dev);
wlr_input_device_destroy(wlr_dev); wlr_input_device_destroy(dev);
} }
for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { for (size_t i = 0; i < backend->wlr_device_lists->length; i++) {
if (backend->wlr_device_lists->items[i] == wlr_devices) { if (backend->wlr_device_lists->items[i] == wlr_devices) {
list_del(backend->wlr_device_lists, i); wlr_list_del(backend->wlr_device_lists, i);
break; break;
} }
} }
list_free(wlr_devices); free(wlr_devices);
} }
void wlr_libinput_event(struct wlr_libinput_backend *backend, void wlr_libinput_event(struct wlr_libinput_backend *backend,

View File

@ -13,14 +13,15 @@ struct subbackend_state {
struct wl_listener input_remove; struct wl_listener input_remove;
struct wl_listener output_add; struct wl_listener output_add;
struct wl_listener output_remove; struct wl_listener output_remove;
struct wl_list link;
}; };
static bool multi_backend_start(struct wlr_backend *_backend) { static bool multi_backend_start(struct wlr_backend *_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
for (size_t i = 0; i < backend->backends->length; ++i) { struct subbackend_state *sub;
struct subbackend_state *sub = backend->backends->items[i]; wl_list_for_each(sub, &backend->backends, link) {
if (!wlr_backend_start(sub->backend)) { if (!wlr_backend_start(sub->backend)) {
wlr_log(L_ERROR, "Failed to initialize backend %zd", i); wlr_log(L_ERROR, "Failed to initialize backend.");
return false; return false;
} }
} }
@ -29,20 +30,19 @@ static bool multi_backend_start(struct wlr_backend *_backend) {
static void multi_backend_destroy(struct wlr_backend *_backend) { static void multi_backend_destroy(struct wlr_backend *_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
for (size_t i = 0; i < backend->backends->length; ++i) { struct subbackend_state *sub;
struct subbackend_state *sub = backend->backends->items[i]; wl_list_for_each(sub, &backend->backends, link) {
wlr_backend_destroy(sub->backend); wlr_backend_destroy(sub->backend);
free(sub); free(sub);
} }
list_free(backend->backends);
wlr_session_destroy(backend->session); wlr_session_destroy(backend->session);
free(backend); free(backend);
} }
static struct wlr_egl *multi_backend_get_egl(struct wlr_backend *_backend) { static struct wlr_egl *multi_backend_get_egl(struct wlr_backend *_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend;
for (size_t i = 0; i < backend->backends->length; ++i) { struct subbackend_state *sub;
struct subbackend_state *sub = backend->backends->items[i]; wl_list_for_each(sub, &backend->backends, link) {
struct wlr_egl *egl = wlr_backend_get_egl(sub->backend); struct wlr_egl *egl = wlr_backend_get_egl(sub->backend);
if (egl) { if (egl) {
return egl; return egl;
@ -65,13 +65,7 @@ struct wlr_backend *wlr_multi_backend_create(struct wlr_session *session) {
return NULL; return NULL;
} }
backend->backends = list_create(); wl_list_init(&backend->backends);
if (!backend->backends) {
free(backend);
wlr_log(L_ERROR, "Backend allocation failed");
return NULL;
}
wlr_backend_init(&backend->backend, &backend_impl); wlr_backend_init(&backend->backend, &backend_impl);
backend->session = session; backend->session = session;
@ -116,11 +110,7 @@ void wlr_multi_backend_add(struct wlr_backend *_multi,
wlr_log(L_ERROR, "Could not add backend: allocation failed"); wlr_log(L_ERROR, "Could not add backend: allocation failed");
return; return;
} }
if (list_add(multi->backends, sub) == -1) { wl_list_insert(&multi->backends, &sub->link);
wlr_log(L_ERROR, "Could not add backend: allocation failed");
free(sub);
return;
}
sub->backend = backend; sub->backend = backend;
sub->container = &multi->backend; sub->container = &multi->backend;

View File

@ -4,7 +4,7 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
@ -64,16 +64,16 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) {
return; return;
} }
for (size_t i = 0; i < backend->outputs->length; ++i) { struct wlr_wl_backend_output *output, *tmp_output;
wlr_output_destroy(backend->outputs->items[i]); wl_list_for_each_safe(output, tmp_output, &backend->outputs, link) {
wlr_output_destroy(&output->wlr_output);
} }
for (size_t i = 0; i < backend->devices->length; ++i) { struct wlr_input_device *input_device, *tmp_input_device;
wlr_input_device_destroy(backend->devices->items[i]); wl_list_for_each_safe(input_device, tmp_input_device, &backend->devices, link) {
wlr_input_device_destroy(input_device);
} }
list_free(backend->devices);
list_free(backend->outputs);
free(backend->seat_name); free(backend->seat_name);
wl_event_source_remove(backend->remote_display_src); wl_event_source_remove(backend->remote_display_src);
@ -104,8 +104,8 @@ bool wlr_backend_is_wl(struct wlr_backend *b) {
struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend_output *wlr_wl_output_for_surface(
struct wlr_wl_backend *backend, struct wl_surface *surface) { struct wlr_wl_backend *backend, struct wl_surface *surface) {
for (size_t i = 0; i < backend->outputs->length; ++i) { struct wlr_wl_backend_output *output;
struct wlr_wl_backend_output *output = backend->outputs->items[i]; wl_list_for_each(output, &backend->outputs, link) {
if (output->surface == surface) { if (output->surface == surface) {
return output; return output;
} }
@ -123,15 +123,8 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
} }
wlr_backend_init(&backend->backend, &backend_impl); wlr_backend_init(&backend->backend, &backend_impl);
if (!(backend->devices = list_create())) { wl_list_init(&backend->devices);
wlr_log(L_ERROR, "Could not allocate devices list"); wl_list_init(&backend->outputs);
goto error;
}
if (!(backend->outputs = list_create())) {
wlr_log(L_ERROR, "Could not allocate outputs list");
goto error;
}
backend->local_display = display; backend->local_display = display;
@ -150,12 +143,4 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
wlr_egl_bind_display(&backend->egl, backend->local_display); wlr_egl_bind_display(&backend->egl, backend->local_display);
return &backend->backend; return &backend->backend;
error:
if (backend) {
list_free(backend->devices);
list_free(backend->outputs);
}
free(backend);
return NULL;
} }

View File

@ -210,9 +210,7 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x
} }
// loop over states for maximized etc? // loop over states for maximized etc?
wl_egl_window_resize(output->egl_window, width, height, 0, 0); wl_egl_window_resize(output->egl_window, width, height, 0, 0);
output->wlr_output.width = width; wlr_output_update_size(&output->wlr_output, width, height);
output->wlr_output.height = height;
wlr_output_update_matrix(&output->wlr_output);
wl_signal_emit(&output->wlr_output.events.resolution, output); wl_signal_emit(&output->wlr_output.events.resolution, output);
} }
@ -241,16 +239,14 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
wlr_log(L_ERROR, "Failed to allocate wlr_wl_backend_output"); wlr_log(L_ERROR, "Failed to allocate wlr_wl_backend_output");
return NULL; return NULL;
} }
wlr_output_init(&output->wlr_output, &output_impl); wlr_output_init(&output->wlr_output, &backend->backend, &output_impl);
struct wlr_output *wlr_output = &output->wlr_output; struct wlr_output *wlr_output = &output->wlr_output;
wlr_output->width = 640; wlr_output_update_size(wlr_output, 640, 480);
wlr_output->height = 480;
strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make)); strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make));
strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model)); strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%zd", snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%d",
backend->outputs->length + 1); wl_list_length(&backend->outputs) + 1);
wlr_output_update_matrix(wlr_output);
output->backend = backend; output->backend = backend;
@ -306,10 +302,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
goto error; goto error;
} }
if (list_add(backend->outputs, wlr_output) == -1) { wl_list_insert(&backend->outputs, &output->link);
wlr_log(L_ERROR, "Allocation failed");
goto error;
}
wlr_output_create_global(wlr_output, backend->local_display); wlr_output_create_global(wlr_output, backend->local_display);
wl_signal_emit(&backend->backend.events.output_add, wlr_output); wl_signal_emit(&backend->backend.events.output_add, wlr_output);
return wlr_output; return wlr_output;

View File

@ -204,11 +204,7 @@ static struct wlr_input_device *allocate_device(struct wlr_wl_backend *backend,
struct wlr_input_device *wlr_device = &wlr_wl_dev->wlr_input_device; struct wlr_input_device *wlr_device = &wlr_wl_dev->wlr_input_device;
wlr_input_device_init(wlr_device, type, &input_device_impl, wlr_input_device_init(wlr_device, type, &input_device_impl,
name, vendor, product); name, vendor, product);
if (list_add(backend->devices, wlr_device) == -1) { wl_list_insert(&backend->devices, &wlr_device->link);
wlr_log_errno(L_ERROR, "Allocation failed");
free(wlr_wl_dev);
return NULL;
}
return wlr_device; return wlr_device;
} }

View File

@ -15,7 +15,7 @@
#endif #endif
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/x11.h> #include <wlr/backend/x11.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.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>
@ -121,9 +121,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
case XCB_CONFIGURE_NOTIFY: { case XCB_CONFIGURE_NOTIFY: {
xcb_configure_notify_event_t *ev = (xcb_configure_notify_event_t *)event; xcb_configure_notify_event_t *ev = (xcb_configure_notify_event_t *)event;
output->wlr_output.width = ev->width; wlr_output_update_size(&output->wlr_output, ev->width, ev->height);
output->wlr_output.height = ev->height;
wlr_output_update_matrix(&output->wlr_output);
wl_signal_emit(&output->wlr_output.events.resolution, output); wl_signal_emit(&output->wlr_output.events.resolution, output);
// Move the pointer to its new location // Move the pointer to its new location
@ -264,7 +262,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) {
output->x11 = x11; output->x11 = x11;
wlr_output_init(&output->wlr_output, &output_impl); wlr_output_init(&output->wlr_output, &x11->backend, &output_impl);
snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1");
output->win = xcb_generate_id(x11->xcb_conn); output->win = xcb_generate_id(x11->xcb_conn);

View File

@ -21,6 +21,7 @@
#include <wlr/xcursor.h> #include <wlr/xcursor.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/types/wlr_list.h>
#include "shared.h" #include "shared.h"
#include "config.h" #include "config.h"
#include "cat.h" #include "cat.h"
@ -45,7 +46,7 @@ struct sample_state {
struct wl_listener touch_up; struct wl_listener touch_up;
struct wl_listener touch_down; struct wl_listener touch_down;
struct wl_listener touch_cancel; struct wl_listener touch_cancel;
list_t *touch_points; struct wlr_list *touch_points;
struct wl_listener tablet_tool_axis; struct wl_listener tablet_tool_axis;
struct wl_listener tablet_tool_proxmity; struct wl_listener tablet_tool_proxmity;
@ -212,7 +213,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
for (size_t i = 0; i < sample->touch_points->length; ++i) { for (size_t i = 0; i < sample->touch_points->length; ++i) {
struct touch_point *point = sample->touch_points->items[i]; struct touch_point *point = sample->touch_points->items[i];
if (point->slot == event->slot) { if (point->slot == event->slot) {
list_del(sample->touch_points, i); wlr_list_del(sample->touch_points, i);
break; break;
} }
} }
@ -227,7 +228,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
point->slot = event->slot; point->slot = event->slot;
point->x = event->x_mm / event->width_mm; point->x = event->x_mm / event->width_mm;
point->y = event->y_mm / event->height_mm; point->y = event->y_mm / event->height_mm;
if (list_add(sample->touch_points, point) == -1) { if (wlr_list_add(sample->touch_points, point) == -1) {
free(point); free(point);
} }
@ -269,7 +270,7 @@ int main(int argc, char *argv[]) {
struct sample_state state = { struct sample_state state = {
.default_color = { 0.25f, 0.25f, 0.25f, 1 }, .default_color = { 0.25f, 0.25f, 0.25f, 1 },
.clear_color = { 0.25f, 0.25f, 0.25f, 1 }, .clear_color = { 0.25f, 0.25f, 0.25f, 1 },
.touch_points = list_create(), .touch_points = wlr_list_create(),
}; };
state.config = parse_args(argc, argv); state.config = parse_args(argc, argv);

View File

@ -267,10 +267,6 @@ int main(int argc, char *argv[]) {
struct screenshooter_output *output; struct screenshooter_output *output;
wl_list_for_each(output, &output_list, link) { wl_list_for_each(output, &output_list, link) {
if (output->width == 0 || output->height == 0) {
continue;
}
output->buffer = create_shm_buffer(output->width, output->height, &output->data); output->buffer = create_shm_buffer(output->width, output->height, &output->data);
if (output->buffer == NULL) { if (output->buffer == NULL) {
return -1; return -1;

View File

@ -413,8 +413,10 @@ static void output_add_notify(struct wl_listener *listener, void *data) {
wlr_log(L_DEBUG, "Output '%s' added", output->name); wlr_log(L_DEBUG, "Output '%s' added", output->name);
wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", output->make, output->model, wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", output->make, output->model,
output->phys_width, output->phys_height); output->phys_width, output->phys_height);
if (output->modes->length > 0) { if (wl_list_length(&output->modes) > 0) {
wlr_output_set_mode(output, output->modes->items[0]); struct wlr_output_mode *mode;
mode = wl_container_of((&output->modes)->prev, mode, link);
wlr_output_set_mode(output, mode);
} }
struct output_state *ostate = calloc(1, sizeof(struct output_state)); struct output_state *ostate = calloc(1, sizeof(struct output_state));
clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame); clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame);

View File

@ -16,7 +16,7 @@
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "shared.h" #include "shared.h"
#include "cat.h" #include "cat.h"
@ -24,7 +24,7 @@
struct sample_state { struct sample_state {
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wlr_texture *cat_texture; struct wlr_texture *cat_texture;
list_t *touch_points; struct wlr_list *touch_points;
}; };
struct touch_point { struct touch_point {
@ -65,7 +65,7 @@ static void handle_touch_down(struct touch_state *tstate, int32_t slot,
point->slot = slot; point->slot = slot;
point->x = x / width; point->x = x / width;
point->y = y / height; point->y = y / height;
if (list_add(sample->touch_points, point) == -1) { if (wlr_list_add(sample->touch_points, point) == -1) {
free(point); free(point);
} }
} }
@ -75,7 +75,7 @@ static void handle_touch_up(struct touch_state *tstate, int32_t slot) {
for (size_t i = 0; i < sample->touch_points->length; ++i) { for (size_t i = 0; i < sample->touch_points->length; ++i) {
struct touch_point *point = sample->touch_points->items[i]; struct touch_point *point = sample->touch_points->items[i];
if (point->slot == slot) { if (point->slot == slot) {
list_del(sample->touch_points, i); wlr_list_del(sample->touch_points, i);
break; break;
} }
} }
@ -96,7 +96,7 @@ static void handle_touch_motion(struct touch_state *tstate, int32_t slot,
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct sample_state state = { struct sample_state state = {
.touch_points = list_create() .touch_points = wlr_list_create()
}; };
struct compositor_state compositor = { 0, struct compositor_state compositor = { 0,
.data = &state, .data = &state,

View File

@ -8,12 +8,13 @@
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <gbm.h> #include <gbm.h>
#include <wayland-util.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/backend/drm.h> #include <wlr/backend/drm.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
#include "iface.h" #include "iface.h"
#include "properties.h" #include "properties.h"
@ -30,7 +31,6 @@ struct wlr_drm_plane {
// Only used by cursor // Only used by cursor
float matrix[16]; float matrix[16];
struct wlr_renderer *wlr_rend;
struct wlr_texture *wlr_tex; struct wlr_texture *wlr_tex;
struct gbm_bo *cursor_bo; struct gbm_bo *cursor_bo;
@ -93,7 +93,7 @@ struct wlr_drm_backend {
struct wl_listener session_signal; struct wl_listener session_signal;
struct wl_listener drm_invalidated; struct wl_listener drm_invalidated;
list_t *outputs; struct wl_list outputs;
struct wlr_drm_renderer renderer; struct wlr_drm_renderer renderer;
struct wlr_session *session; struct wlr_session *session;
@ -113,7 +113,6 @@ struct wlr_drm_mode {
struct wlr_drm_connector { struct wlr_drm_connector {
struct wlr_output output; struct wlr_output output;
struct wlr_drm_backend *drm;
enum wlr_drm_connector_state state; enum wlr_drm_connector_state state;
uint32_t id; uint32_t id;
@ -130,6 +129,7 @@ struct wlr_drm_connector {
bool pageflip_pending; bool pageflip_pending;
struct wl_event_source *retry_pageflip; struct wl_event_source *retry_pageflip;
struct wl_list link;
}; };
bool wlr_drm_check_features(struct wlr_drm_backend *drm); bool wlr_drm_check_features(struct wlr_drm_backend *drm);

View File

@ -5,7 +5,7 @@
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
struct wlr_libinput_backend { struct wlr_libinput_backend {
struct wlr_backend backend; struct wlr_backend backend;
@ -18,7 +18,7 @@ struct wlr_libinput_backend {
struct wl_listener session_signal; struct wl_listener session_signal;
list_t *wlr_device_lists; struct wlr_list *wlr_device_lists;
}; };
struct wlr_libinput_input_device { struct wlr_libinput_input_device {

View File

@ -3,14 +3,14 @@
#include <wlr/backend/interface.h> #include <wlr/backend/interface.h>
#include <wlr/backend/multi.h> #include <wlr/backend/multi.h>
#include <wlr/util/list.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wayland-util.h>
struct wlr_multi_backend { struct wlr_multi_backend {
struct wlr_backend backend; struct wlr_backend backend;
struct wlr_session *session; struct wlr_session *session;
list_t *backends; struct wl_list backends;
}; };
#endif #endif

View File

@ -5,11 +5,11 @@
#include <wayland-client.h> #include <wayland-client.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wayland-egl.h> #include <wayland-egl.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include <wlr/backend/wayland.h> #include <wlr/backend/wayland.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/util/list.h> #include <wayland-util.h>
struct wlr_wl_backend { struct wlr_wl_backend {
struct wlr_backend backend; struct wlr_backend backend;
@ -17,8 +17,8 @@ struct wlr_wl_backend {
/* local state */ /* local state */
bool started; bool started;
struct wl_display *local_display; struct wl_display *local_display;
list_t *devices; struct wl_list devices;
list_t *outputs; struct wl_list outputs;
struct wlr_egl egl; struct wlr_egl egl;
size_t requested_outputs; size_t requested_outputs;
/* remote state */ /* remote state */
@ -51,6 +51,7 @@ struct wlr_wl_backend_output {
uint32_t enter_serial; uint32_t enter_serial;
void *egl_surface; void *egl_surface;
struct wl_list link;
}; };
struct wlr_wl_input_device { struct wlr_wl_input_device {

View File

@ -5,7 +5,7 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <X11/Xlib-xcb.h> #include <X11/Xlib-xcb.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>

View File

@ -8,9 +8,9 @@
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <wlr/egl.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/render/egl.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>

View File

@ -9,7 +9,7 @@
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_screenshooter.h> #include <wlr/types/wlr_screenshooter.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
#include "rootston/view.h" #include "rootston/view.h"
#include "rootston/config.h" #include "rootston/config.h"
@ -22,7 +22,7 @@ struct roots_output {
}; };
struct roots_desktop { struct roots_desktop {
list_t *views; struct wlr_list *views;
struct wl_list outputs; struct wl_list outputs;
struct timespec last_frame; struct timespec last_frame;

View File

@ -3,7 +3,7 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
struct wlr_backend_impl; struct wlr_backend_impl;

View File

@ -3,7 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
struct wlr_backend_impl { struct wlr_backend_impl {
bool (*start)(struct wlr_backend *backend); bool (*start)(struct wlr_backend *backend);

View File

@ -1,8 +1,9 @@
#ifndef WLR_INTERFACES_WLR_OUTPUT_H #ifndef WLR_INTERFACES_WLR_OUTPUT_H
#define WLR_INTERFACES_WLR_OUTPUT_H #define WLR_INTERFACES_WLR_OUTPUT_H
#include <wlr/types/wlr_output.h>
#include <stdbool.h> #include <stdbool.h>
#include <wlr/types/wlr_output.h>
#include <wlr/backend.h>
struct wlr_output_impl { struct wlr_output_impl {
void (*enable)(struct wlr_output *output, bool enable); void (*enable)(struct wlr_output *output, bool enable);
@ -17,14 +18,17 @@ struct wlr_output_impl {
void (*make_current)(struct wlr_output *output); void (*make_current)(struct wlr_output *output);
void (*swap_buffers)(struct wlr_output *output); void (*swap_buffers)(struct wlr_output *output);
void (*set_gamma)(struct wlr_output *output, void (*set_gamma)(struct wlr_output *output,
uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint16_t (*get_gamma_size)(struct wlr_output *output); uint32_t (*get_gamma_size)(struct wlr_output *output);
}; };
void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl); void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl);
void wlr_output_free(struct wlr_output *output); void wlr_output_free(struct wlr_output *output);
void wlr_output_update_matrix(struct wlr_output *output); void wlr_output_update_size(struct wlr_output *output, int32_t width,
struct wl_global *wlr_output_create_global( int32_t height);
struct wlr_output *wlr_output, struct wl_display *display); struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
struct wl_display *display);
void wlr_output_destroy_global(struct wlr_output *wlr_output);
#endif #endif

View File

@ -5,18 +5,28 @@
struct wlr_gamma_control_manager { struct wlr_gamma_control_manager {
struct wl_global *wl_global; struct wl_global *wl_global;
struct wl_list controls; // list of wlr_gamma_control
void *data; void *data;
}; };
struct wlr_gamma_control { struct wlr_gamma_control {
struct wl_resource *resource; struct wl_resource *resource;
struct wl_resource *output; struct wlr_output *output;
struct wl_list link;
struct wl_listener output_destroy_listener;
struct {
struct wl_signal destroy;
} events;
void* data; void* data;
}; };
struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(struct wl_display *display); struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(
void wlr_gamma_control_manager_destroy(struct wlr_gamma_control_manager *gamma_control_manager); struct wl_display *display);
void wlr_gamma_control_manager_destroy(
struct wlr_gamma_control_manager *gamma_control_manager);
#endif #endif

View File

@ -45,6 +45,8 @@ struct wlr_input_device {
} events; } events;
void *data; void *data;
struct wl_list link;
}; };
#endif #endif

View File

@ -3,57 +3,57 @@
#include <stddef.h> #include <stddef.h>
typedef struct { struct wlr_list {
size_t capacity; size_t capacity;
size_t length; size_t length;
void **items; void **items;
} list_t; };
/** /**
* Creates a new list, may return `NULL` on failure * Creates a new list, may return `NULL` on failure
*/ */
list_t *list_create(void); struct wlr_list *wlr_list_create(void);
void list_free(list_t *list); void wlr_list_free(struct wlr_list *list);
void list_foreach(list_t *list, void (*callback)(void *item)); void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item));
/** /**
* Add `item` to the end of a list. * Add `item` to the end of a list.
* Returns: new list length or `-1` on failure * Returns: new list length or `-1` on failure
*/ */
int list_add(list_t *list, void *item); int wlr_list_add(struct wlr_list *list, void *item);
/** /**
* Add `item` to the end of a list. * Add `item` to the end of a list.
* Returns: new list length or `-1` on failure * Returns: new list length or `-1` on failure
*/ */
int list_push(list_t *list, void *item); int wlr_list_push(struct wlr_list *list, void *item);
/** /**
* Place `item` into index `index` in the list * Place `item` into index `index` in the list
* Returns: new list length or `-1` on failure * Returns: new list length or `-1` on failure
*/ */
int list_insert(list_t *list, size_t index, void *item); int wlr_list_insert(struct wlr_list *list, size_t index, void *item);
/** /**
* Remove an item from the list * Remove an item from the list
*/ */
void list_del(list_t *list, size_t index); void wlr_list_del(struct wlr_list *list, size_t index);
/** /**
* Remove and return an item from the end of the list * Remove and return an item from the end of the list
*/ */
void *list_pop(list_t *list); void *wlr_list_pop(struct wlr_list *list);
/** /**
* Get a reference to the last item of a list without removal * Get a reference to the last item of a list without removal
*/ */
void *list_peek(list_t *list); void *wlr_list_peek(struct wlr_list *list);
/** /**
* Append each item in `source` to `list` * Append each item in `source` to `list`
* Does not modify `source` * Does not modify `source`
* Returns: new list length or `-1` on failure * Returns: new list length or `-1` on failure
*/ */
int list_cat(list_t *list, list_t *source); int wlr_list_cat(struct wlr_list *list, struct wlr_list *source);
// See qsort. Remember to use *_qsort functions as compare functions, // See qsort. Remember to use *_qsort functions as compare functions,
// because they dereference the left and right arguments first! // because they dereference the left and right arguments first!
void list_qsort(list_t *list, int compare(const void *left, const void *right)); void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right));
// Return index for first item in list that returns 0 for given compare // Return index for first item in list that returns 0 for given compare
// function or -1 if none matches. // function or -1 if none matches.
int list_seq_find(list_t *list, int wlr_list_seq_find(struct wlr_list *list,
int compare(const void *item, const void *cmp_to), int compare(const void *item, const void *cmp_to),
const void *cmp_to); const void *cmp_to);

View File

@ -1,20 +1,22 @@
#ifndef WLR_TYPES_WLR_OUTPUT_H #ifndef WLR_TYPES_WLR_OUTPUT_H
#define WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H
#include <wayland-util.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/util/list.h>
#include <stdbool.h> #include <stdbool.h>
struct wlr_output_mode { struct wlr_output_mode {
uint32_t flags; // enum wl_output_mode uint32_t flags; // enum wl_output_mode
int32_t width, height; int32_t width, height;
int32_t refresh; // mHz int32_t refresh; // mHz
struct wl_list link;
}; };
struct wlr_output_impl; struct wlr_output_impl;
struct wlr_output { struct wlr_output {
const struct wlr_output_impl *impl; const struct wlr_output_impl *impl;
struct wlr_backend *backend;
struct wl_global *wl_global; struct wl_global *wl_global;
struct wl_list wl_resources; struct wl_list wl_resources;
@ -32,7 +34,7 @@ struct wlr_output {
float transform_matrix[16]; float transform_matrix[16];
/* Note: some backends may have zero modes */ /* Note: some backends may have zero modes */
list_t *modes; struct wl_list modes;
struct wlr_output_mode *current_mode; struct wlr_output_mode *current_mode;
struct { struct {
@ -82,7 +84,7 @@ void wlr_output_effective_resolution(struct wlr_output *output,
void wlr_output_make_current(struct wlr_output *output); void wlr_output_make_current(struct wlr_output *output);
void wlr_output_swap_buffers(struct wlr_output *output); void wlr_output_swap_buffers(struct wlr_output *output);
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
uint16_t wlr_output_get_gamma_size(struct wlr_output *output); uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
#endif #endif

View File

@ -109,6 +109,14 @@ void wlr_surface_get_matrix(struct wlr_surface *surface,
int wlr_surface_set_role(struct wlr_surface *surface, const char *role, int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
struct wl_resource *error_resource, uint32_t error_code); struct wl_resource *error_resource, uint32_t error_code);
/**
* Whether or not this surface currently has an attached buffer. A surface has
* an attached buffer when it commits with a non-null buffer in its pending
* state. A surface will not have a buffer if it has never committed one, has
* committed a null buffer, or something went wrong with uploading the buffer.
*/
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/** /**
* Create the subsurface implementation for this surface. * Create the subsurface implementation for this surface.
*/ */

View File

@ -5,6 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <wlr/types/wlr_list.h>
#ifdef HAS_XCB_ICCCM #ifdef HAS_XCB_ICCCM
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>
@ -78,7 +79,7 @@ struct wlr_xwayland_surface {
char *class; char *class;
char *instance; char *instance;
struct wlr_xwayland_surface *parent; struct wlr_xwayland_surface *parent;
list_t *state; // list of xcb_atom_t struct wlr_list *state; // list of xcb_atom_t
pid_t pid; pid_t pid;
xcb_atom_t *window_type; xcb_atom_t *window_type;

View File

@ -44,8 +44,8 @@ wayland_protos = dependency('wayland-protocols')
egl = dependency('egl') egl = dependency('egl')
glesv2 = dependency('glesv2') glesv2 = dependency('glesv2')
drm = dependency('libdrm') drm = dependency('libdrm')
gbm = dependency('gbm') gbm = dependency('gbm', version: '>=17.1.0')
libinput = dependency('libinput') libinput = dependency('libinput', version: '>=1.7.0')
xkbcommon = dependency('xkbcommon') xkbcommon = dependency('xkbcommon')
udev = dependency('libudev') udev = dependency('libudev')
pixman = dependency('pixman-1') pixman = dependency('pixman-1')

View File

@ -3,7 +3,7 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <stdlib.h> #include <stdlib.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/egl.h> #include <wlr/render/egl.h>
#include "render/glapi.h" #include "render/glapi.h"
// Extension documentation // Extension documentation

View File

@ -5,9 +5,9 @@
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/egl.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/render/egl.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -246,9 +246,8 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) {
return NULL; return NULL;
} }
wlr_renderer_init(&renderer->wlr_renderer, &wlr_renderer_impl); wlr_renderer_init(&renderer->wlr_renderer, &wlr_renderer_impl);
if (backend) {
struct wlr_egl *egl = wlr_backend_get_egl(backend); renderer->egl = wlr_backend_get_egl(backend);
renderer->egl = egl;
}
return &renderer->wlr_renderer; return &renderer->wlr_renderer;
} }

View File

@ -5,8 +5,8 @@
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/egl.h>
#include <wlr/render.h> #include <wlr/render.h>
#include <wlr/render/egl.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>

View File

@ -306,7 +306,7 @@ struct roots_config *parse_args(int argc, char *argv[]) {
if (result == -1) { if (result == -1) {
wlr_log(L_DEBUG, "No config file found. Using sensible defaults."); wlr_log(L_DEBUG, "No config file found. Using sensible defaults.");
config->keyboard.meta_key = WLR_MODIFIER_LOGO; config->keyboard.meta_key = WLR_MODIFIER_LOGO;
add_binding_config(&config->bindings, "Logo+Shift+e", "exit"); add_binding_config(&config->bindings, "Logo+Shift+E", "exit");
add_binding_config(&config->bindings, "Ctrl+q", "close"); add_binding_config(&config->bindings, "Ctrl+q", "close");
add_binding_config(&config->bindings, "Alt+Tab", "next_window"); add_binding_config(&config->bindings, "Alt+Tab", "next_window");
} else if (result == -2) { } else if (result == -2) {

View File

@ -185,8 +185,8 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop,
} }
view_activate(view, true); view_activate(view, true);
// TODO: list_swap // TODO: list_swap
list_del(desktop->views, index); wlr_list_del(desktop->views, index);
list_add(desktop->views, view); wlr_list_add(desktop->views, view);
} }
static void handle_cursor_motion(struct wl_listener *listener, void *data) { static void handle_cursor_motion(struct wl_listener *listener, void *data) {

View File

@ -29,7 +29,7 @@ void view_destroy(struct roots_view *view) {
for (size_t i = 0; i < desktop->views->length; ++i) { for (size_t i = 0; i < desktop->views->length; ++i) {
struct roots_view *_view = desktop->views->items[i]; struct roots_view *_view = desktop->views->items[i];
if (view == _view) { if (view == _view) {
list_del(desktop->views, i); wlr_list_del(desktop->views, i);
break; break;
} }
} }
@ -209,7 +209,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
return NULL; return NULL;
} }
desktop->views = list_create(); desktop->views = wlr_list_create();
if (desktop->views == NULL) { if (desktop->views == NULL) {
free(desktop); free(desktop);
return NULL; return NULL;

View File

@ -175,8 +175,10 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm",
wlr_output->make, wlr_output->model, wlr_output->make, wlr_output->model,
wlr_output->phys_width, wlr_output->phys_height); wlr_output->phys_width, wlr_output->phys_height);
if (wlr_output->modes->length > 0) { if (wl_list_length(&wlr_output->modes) > 0) {
wlr_output_set_mode(wlr_output, wlr_output->modes->items[0]); struct wlr_output_mode *mode = NULL;
mode = wl_container_of((&wlr_output->modes)->prev, mode, link);
wlr_output_set_mode(wlr_output, mode);
} }
struct roots_output *output = calloc(1, sizeof(struct roots_output)); struct roots_output *output = calloc(1, sizeof(struct roots_output));

View File

@ -40,6 +40,6 @@ meta-key = Logo
# - "close" to close the current view # - "close" to close the current view
# - "next_window" to cycle through windows # - "next_window" to cycle through windows
[bindings] [bindings]
Logo+Shift+e = exit Logo+Shift+E = exit
Logo+q = close Logo+q = close
Alt+Tab = next_window Alt+Tab = next_window

View File

@ -110,12 +110,12 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->close = close; view->close = close;
view->desktop = desktop; view->desktop = desktop;
roots_surface->view = view; roots_surface->view = view;
list_add(desktop->views, view); wlr_list_add(desktop->views, view);
view_initialize(view); view_initialize(view);
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
// we need to map it relative to the parent // we need to map it relative to the parent
int i = list_seq_find(desktop->views, shell_surface_compare_equals, int i = wlr_list_seq_find(desktop->views, shell_surface_compare_equals,
surface->parent); surface->parent);
if (i != -1) { if (i != -1) {
struct roots_view *parent = desktop->views->items[i]; struct roots_view *parent = desktop->views->items[i];

View File

@ -124,7 +124,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->close = close; view->close = close;
view->desktop = desktop; view->desktop = desktop;
roots_surface->view = view; roots_surface->view = view;
list_add(desktop->views, view); wlr_list_add(desktop->views, view);
view_initialize(view); view_initialize(view);
} }

View File

@ -98,7 +98,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->set_position = set_position; view->set_position = set_position;
view->close = close; view->close = close;
roots_surface->view = view; roots_surface->view = view;
list_add(desktop->views, view); wlr_list_add(desktop->views, view);
if (!surface->override_redirect) { if (!surface->override_redirect) {
view_initialize(view); view_initialize(view);

View File

@ -2,13 +2,18 @@ lib_wlr_types = static_library(
'wlr_types', 'wlr_types',
files( files(
'wlr_data_device.c', 'wlr_data_device.c',
'wlr_box.c',
'wlr_compositor.c',
'wlr_cursor.c',
'wlr_gamma_control.c',
'wlr_input_device.c', 'wlr_input_device.c',
'wlr_keyboard.c', 'wlr_keyboard.c',
'wlr_list.c',
'wlr_output.c', 'wlr_output.c',
'wlr_output_layout.c', 'wlr_output_layout.c',
'wlr_pointer.c', 'wlr_pointer.c',
'wlr_cursor.c',
'wlr_region.c', 'wlr_region.c',
'wlr_screenshooter.c',
'wlr_seat.c', 'wlr_seat.c',
'wlr_surface.c', 'wlr_surface.c',
'wlr_tablet_pad.c', 'wlr_tablet_pad.c',
@ -16,10 +21,6 @@ lib_wlr_types = static_library(
'wlr_touch.c', 'wlr_touch.c',
'wlr_xdg_shell_v6.c', 'wlr_xdg_shell_v6.c',
'wlr_wl_shell.c', 'wlr_wl_shell.c',
'wlr_compositor.c',
'wlr_box.c',
'wlr_gamma_control.c',
'wlr_screenshooter.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,
dependencies: [wayland_server, pixman, wlr_protos], dependencies: [wayland_server, pixman, wlr_protos],

View File

@ -53,12 +53,7 @@ static void wl_compositor_bind(struct wl_client *wl_client, void *_compositor,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_compositor *compositor = _compositor; struct wlr_compositor *compositor = _compositor;
assert(wl_client && compositor); assert(wl_client && compositor);
if (version > 4) {
wlr_log(L_ERROR, "Client requested unsupported wl_compositor version, "
"disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wl_resource *wl_resource = struct wl_resource *wl_resource =
wl_resource_create(wl_client, &wl_compositor_interface, version, id); wl_resource_create(wl_client, &wl_compositor_interface, version, id);
wl_resource_set_implementation(wl_resource, &wl_compositor_impl, wl_resource_set_implementation(wl_resource, &wl_compositor_impl,

View File

@ -6,100 +6,155 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "gamma-control-protocol.h" #include "gamma-control-protocol.h"
static void resource_destroy(struct wl_client *client, struct wl_resource *resource) { static void resource_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
static void gamma_control_destroy(struct wl_resource *resource) { static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) {
struct wlr_gamma_control *gamma_control = wl_resource_get_user_data(resource); wl_signal_emit(&gamma_control->events.destroy, gamma_control);
wl_list_remove(&gamma_control->output_destroy_listener.link);
wl_resource_set_user_data(gamma_control->resource, NULL);
free(gamma_control); free(gamma_control);
} }
static void gamma_control_destroy_resource(struct wl_resource *resource) {
struct wlr_gamma_control *gamma_control =
wl_resource_get_user_data(resource);
gamma_control_destroy(gamma_control);
}
static void gamma_control_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_gamma_control *gamma_control =
wl_container_of(listener, gamma_control, output_destroy_listener);
gamma_control_destroy(gamma_control);
}
static void gamma_control_set_gamma(struct wl_client *client, static void gamma_control_set_gamma(struct wl_client *client,
struct wl_resource *_gamma_control, struct wl_array *red, struct wl_resource *gamma_control_resource, struct wl_array *red,
struct wl_array *green, struct wl_array *blue) { struct wl_array *green, struct wl_array *blue) {
struct wlr_gamma_control *gamma_control =
wl_resource_get_user_data(gamma_control_resource);
if (red->size != green->size || red->size != blue->size) { if (red->size != green->size || red->size != blue->size) {
wl_resource_post_error(_gamma_control, GAMMA_CONTROL_ERROR_INVALID_GAMMA, wl_resource_post_error(gamma_control_resource,
GAMMA_CONTROL_ERROR_INVALID_GAMMA,
"The gamma ramps don't have the same size"); "The gamma ramps don't have the same size");
return; return;
} }
uint32_t size = red->size / sizeof(uint16_t);
uint16_t *r = (uint16_t *)red->data; uint16_t *r = (uint16_t *)red->data;
uint16_t *g = (uint16_t *)green->data; uint16_t *g = (uint16_t *)green->data;
uint16_t *b = (uint16_t *)blue->data; uint16_t *b = (uint16_t *)blue->data;
struct wlr_gamma_control *gamma_control = wl_resource_get_user_data(_gamma_control);
struct wlr_output *output = wl_resource_get_user_data(gamma_control->output); wlr_output_set_gamma(gamma_control->output, size, r, g, b);
wlr_output_set_gamma(output, red->size / sizeof(uint16_t), r, g, b);
} }
static void gamma_control_reset_gamma(struct wl_client *client, static void gamma_control_reset_gamma(struct wl_client *client,
struct wl_resource *_gamma_control) { struct wl_resource *gamma_control_resource) {
// TODO // TODO
} }
static const struct gamma_control_interface gamma_control_implementation = { static const struct gamma_control_interface gamma_control_impl = {
.destroy = resource_destroy, .destroy = resource_destroy,
.set_gamma = gamma_control_set_gamma, .set_gamma = gamma_control_set_gamma,
.reset_gamma = gamma_control_reset_gamma, .reset_gamma = gamma_control_reset_gamma,
}; };
static void gamma_control_manager_get_gamma_control(struct wl_client *client, static void gamma_control_manager_get_gamma_control(struct wl_client *client,
struct wl_resource *_gamma_control_manager, uint32_t id, struct wl_resource *gamma_control_manager_resource, uint32_t id,
struct wl_resource *_output) { struct wl_resource *output_resource) {
//struct wlr_gamma_control_manager *gamma_control_manager = struct wlr_gamma_control_manager *gamma_control_manager =
// wl_resource_get_user_data(_gamma_control_manager); wl_resource_get_user_data(gamma_control_manager_resource);
struct wlr_output *output = wl_resource_get_user_data(_output); struct wlr_output *output = wl_resource_get_user_data(output_resource);
struct wlr_gamma_control *gamma_control;
if (!(gamma_control = calloc(1, sizeof(struct wlr_gamma_control)))) { struct wlr_gamma_control *gamma_control =
calloc(1, sizeof(struct wlr_gamma_control));
if (gamma_control == NULL) {
wl_client_post_no_memory(client);
return; return;
} }
gamma_control->output = _output; gamma_control->output = output;
int version = wl_resource_get_version(gamma_control_manager_resource);
gamma_control->resource = wl_resource_create(client, gamma_control->resource = wl_resource_create(client,
&gamma_control_interface, wl_resource_get_version(_gamma_control_manager), id); &gamma_control_interface, version, id);
wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control, gamma_control->resource); if (gamma_control->resource == NULL) {
wl_client_post_no_memory(client);
free(gamma_control);
return;
}
wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control,
gamma_control->resource);
wl_resource_set_implementation(gamma_control->resource, wl_resource_set_implementation(gamma_control->resource,
&gamma_control_implementation, gamma_control, gamma_control_destroy); &gamma_control_impl, gamma_control, gamma_control_destroy_resource);
gamma_control_send_gamma_size(gamma_control->resource, wlr_output_get_gamma_size(output));
wl_signal_init(&gamma_control->events.destroy);
wl_signal_add(&output->events.destroy,
&gamma_control->output_destroy_listener);
gamma_control->output_destroy_listener.notify =
gamma_control_handle_output_destroy;
wl_list_insert(&gamma_control_manager->controls, &gamma_control->link);
gamma_control_send_gamma_size(gamma_control->resource,
wlr_output_get_gamma_size(output));
} }
static struct gamma_control_manager_interface gamma_control_manager_impl = { static struct gamma_control_manager_interface gamma_control_manager_impl = {
.get_gamma_control = gamma_control_manager_get_gamma_control, .get_gamma_control = gamma_control_manager_get_gamma_control,
}; };
static void gamma_control_manager_bind(struct wl_client *wl_client, static void gamma_control_manager_bind(struct wl_client *client,
void *_gamma_control_manager, uint32_t version, uint32_t id) { void *_gamma_control_manager, uint32_t version, uint32_t id) {
struct wlr_gamma_control_manager *gamma_control_manager = _gamma_control_manager; struct wlr_gamma_control_manager *gamma_control_manager =
assert(wl_client && gamma_control_manager); _gamma_control_manager;
if (version > 1) { assert(client && gamma_control_manager);
wlr_log(L_ERROR, "Client requested unsupported gamma_control version, disconnecting");
wl_client_destroy(wl_client); struct wl_resource *resource = wl_resource_create(client,
&gamma_control_manager_interface, version, id);
if (resource == NULL) {
wl_client_post_no_memory(client);
return; return;
} }
struct wl_resource *wl_resource = wl_resource_create( wl_resource_set_implementation(resource, &gamma_control_manager_impl,
wl_client, &gamma_control_manager_interface, version, id);
wl_resource_set_implementation(wl_resource, &gamma_control_manager_impl,
gamma_control_manager, NULL); gamma_control_manager, NULL);
} }
struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(struct wl_display *display) { struct wlr_gamma_control_manager *wlr_gamma_control_manager_create(
struct wl_display *display) {
struct wlr_gamma_control_manager *gamma_control_manager = struct wlr_gamma_control_manager *gamma_control_manager =
calloc(1, sizeof(struct wlr_gamma_control_manager)); calloc(1, sizeof(struct wlr_gamma_control_manager));
if (!gamma_control_manager) { if (!gamma_control_manager) {
return NULL; return NULL;
} }
struct wl_global *wl_global = wl_global_create(display, struct wl_global *wl_global = wl_global_create(display,
&gamma_control_manager_interface, 1, gamma_control_manager, gamma_control_manager_bind); &gamma_control_manager_interface, 1, gamma_control_manager,
gamma_control_manager_bind);
if (!wl_global) { if (!wl_global) {
free(gamma_control_manager); free(gamma_control_manager);
return NULL; return NULL;
} }
gamma_control_manager->wl_global = wl_global; gamma_control_manager->wl_global = wl_global;
wl_list_init(&gamma_control_manager->controls);
return gamma_control_manager; return gamma_control_manager;
} }
void wlr_gamma_control_manager_destroy(struct wlr_gamma_control_manager *gamma_control_manager) { void wlr_gamma_control_manager_destroy(
struct wlr_gamma_control_manager *gamma_control_manager) {
if (!gamma_control_manager) { if (!gamma_control_manager) {
return; return;
} }
struct wlr_gamma_control *gamma_control, *tmp;
wl_list_for_each_safe(gamma_control, tmp, &gamma_control_manager->controls,
link) {
gamma_control_destroy(gamma_control);
}
// TODO: this segfault (wl_display->registry_resource_list is not init) // TODO: this segfault (wl_display->registry_resource_list is not init)
// wl_global_destroy(gamma_control_manager->wl_global); // wl_global_destroy(gamma_control_manager->wl_global);
free(gamma_control_manager); free(gamma_control_manager);

View File

@ -3,10 +3,10 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <stddef.h> #include <stddef.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
list_t *list_create(void) { struct wlr_list *wlr_list_create(void) {
list_t *list = malloc(sizeof(list_t)); struct wlr_list *list = malloc(sizeof(struct wlr_list));
if (!list) { if (!list) {
return NULL; return NULL;
} }
@ -20,7 +20,7 @@ list_t *list_create(void) {
return list; return list;
} }
static bool list_resize(list_t *list) { static bool list_resize(struct wlr_list *list) {
if (list->length == list->capacity) { if (list->length == list->capacity) {
void *new_items = realloc(list->items, sizeof(void*) * (list->capacity + 10)); void *new_items = realloc(list->items, sizeof(void*) * (list->capacity + 10));
if (!new_items) { if (!new_items) {
@ -32,7 +32,7 @@ static bool list_resize(list_t *list) {
return true; return true;
} }
void list_free(list_t *list) { void wlr_list_free(struct wlr_list *list) {
if (list == NULL) { if (list == NULL) {
return; return;
} }
@ -40,7 +40,7 @@ void list_free(list_t *list) {
free(list); free(list);
} }
void list_foreach(list_t *list, void (*callback)(void *item)) { void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item)) {
if (list == NULL || callback == NULL) { if (list == NULL || callback == NULL) {
return; return;
} }
@ -49,7 +49,7 @@ void list_foreach(list_t *list, void (*callback)(void *item)) {
} }
} }
int list_add(list_t *list, void *item) { int wlr_list_add(struct wlr_list *list, void *item) {
if (!list_resize(list)) { if (!list_resize(list)) {
return -1; return -1;
} }
@ -57,11 +57,11 @@ int list_add(list_t *list, void *item) {
return list->length; return list->length;
} }
int list_push(list_t *list, void *item) { int wlr_list_push(struct wlr_list *list, void *item) {
return list_add(list, item); return wlr_list_add(list, item);
} }
int list_insert(list_t *list, size_t index, void *item) { int wlr_list_insert(struct wlr_list *list, size_t index, void *item) {
if (!list_resize(list)) { if (!list_resize(list)) {
return -1; return -1;
} }
@ -71,26 +71,26 @@ int list_insert(list_t *list, size_t index, void *item) {
return list->length; return list->length;
} }
void list_del(list_t *list, size_t index) { void wlr_list_del(struct wlr_list *list, size_t index) {
list->length--; list->length--;
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index)); memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
} }
void *list_pop(list_t *list) { void *wlr_list_pop(struct wlr_list *list) {
void *_ = list->items[list->length - 1]; void *_ = list->items[list->length - 1];
list_del(list, list->length - 1); wlr_list_del(list, list->length - 1);
return _; return _;
} }
void *list_peek(list_t *list) { void *wlr_list_peek(struct wlr_list *list) {
return list->items[list->length - 1]; return list->items[list->length - 1];
} }
int list_cat(list_t *list, list_t *source) { int wlr_list_cat(struct wlr_list *list, struct wlr_list *source) {
size_t old_len = list->length; size_t old_len = list->length;
size_t i; size_t i;
for (i = 0; i < source->length; ++i) { for (i = 0; i < source->length; ++i) {
if (list_add(list, source->items[i]) == -1) { if (wlr_list_add(list, source->items[i]) == -1) {
list->length = old_len; list->length = old_len;
return -1; return -1;
} }
@ -98,11 +98,11 @@ int list_cat(list_t *list, list_t *source) {
return list->length; return list->length;
} }
void list_qsort(list_t *list, int compare(const void *left, const void *right)) { void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)) {
qsort(list->items, list->length, sizeof(void *), compare); qsort(list->items, list->length, sizeof(void *), compare);
} }
int list_seq_find(list_t *list, int wlr_list_seq_find(struct wlr_list *list,
int compare(const void *item, const void *data), int compare(const void *item, const void *data),
const void *data) { const void *data) {
for (size_t i = 0; i < list->length; i++) { for (size_t i = 0; i < list->length; i++) {

View File

@ -8,7 +8,7 @@
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
#include <wlr/util/list.h> #include <wlr/types/wlr_list.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
@ -26,18 +26,18 @@ static void wl_output_send_to_resource(struct wl_resource *resource) {
output->make, output->model, output->transform); output->make, output->model, output->transform);
} }
if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { if (version >= WL_OUTPUT_MODE_SINCE_VERSION) {
for (size_t i = 0; i < output->modes->length; ++i) { struct wlr_output_mode *mode;
struct wlr_output_mode *mode = output->modes->items[i]; wl_list_for_each(mode, &output->modes, link) {
// TODO: mode->flags should just be preferred // TODO: mode->flags should just be preferred
uint32_t flags = mode->flags; uint32_t flags = mode->flags;
if (output->current_mode == mode) { if (output->current_mode == mode) {
flags |= WL_OUTPUT_MODE_CURRENT; flags |= WL_OUTPUT_MODE_CURRENT;
} }
wl_output_send_mode(resource, flags, wl_output_send_mode(resource, flags, mode->width, mode->height,
mode->width, mode->height, mode->refresh); mode->refresh);
} }
if (output->modes->length == 0) { if (wl_list_length(&output->modes) == 0) {
// Output has no mode, send the current width/height // Output has no mode, send the current width/height
wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT, wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT,
output->width, output->height, 0); output->width, output->height, 0);
@ -51,6 +51,25 @@ static void wl_output_send_to_resource(struct wl_resource *resource) {
} }
} }
static void wlr_output_send_current_mode_to_resource(
struct wl_resource *resource) {
struct wlr_output *output = wl_resource_get_user_data(resource);
assert(output);
const uint32_t version = wl_resource_get_version(resource);
if (version < WL_OUTPUT_MODE_SINCE_VERSION) {
return;
}
if (output->current_mode != NULL) {
struct wlr_output_mode *mode = output->current_mode;
wl_output_send_mode(resource, mode->flags | WL_OUTPUT_MODE_CURRENT,
mode->width, mode->height, mode->refresh);
} else {
// Output has no mode, send the current width/height
wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT, output->width,
output->height, 0);
}
}
static void wl_output_destroy(struct wl_resource *resource) { static void wl_output_destroy(struct wl_resource *resource) {
struct wlr_output *output = wl_resource_get_user_data(resource); struct wlr_output *output = wl_resource_get_user_data(resource);
struct wl_resource *_resource = NULL; struct wl_resource *_resource = NULL;
@ -75,21 +94,21 @@ static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_output *wlr_output = _wlr_output; struct wlr_output *wlr_output = _wlr_output;
assert(wl_client && wlr_output); assert(wl_client && wlr_output);
if (version > 3) {
wlr_log(L_ERROR, "Client requested unsupported wl_output version, disconnecting"); struct wl_resource *wl_resource = wl_resource_create(wl_client,
wl_client_destroy(wl_client); &wl_output_interface, version, id);
return; wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output,
} wl_output_destroy);
struct wl_resource *wl_resource = wl_resource_create( wl_list_insert(&wlr_output->wl_resources,
wl_client, &wl_output_interface, version, id); wl_resource_get_link(wl_resource));
wl_resource_set_implementation(wl_resource, &wl_output_impl,
wlr_output, wl_output_destroy);
wl_list_insert(&wlr_output->wl_resources, wl_resource_get_link(wl_resource));
wl_output_send_to_resource(wl_resource); wl_output_send_to_resource(wl_resource);
} }
struct wl_global *wlr_output_create_global( struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
struct wlr_output *wlr_output, struct wl_display *display) { struct wl_display *display) {
if (wlr_output->wl_global != NULL) {
return wlr_output->wl_global;
}
struct wl_global *wl_global = wl_global_create(display, struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind); &wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global; wlr_output->wl_global = wl_global;
@ -97,32 +116,65 @@ struct wl_global *wlr_output_create_global(
return wl_global; return wl_global;
} }
void wlr_output_update_matrix(struct wlr_output *output) { void wlr_output_destroy_global(struct wlr_output *wlr_output) {
wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform); if (wlr_output->wl_global == NULL) {
return;
}
struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) {
struct wl_list *link = wl_resource_get_link(resource);
wl_list_remove(link);
}
wl_global_destroy(wlr_output->wl_global);
wlr_output->wl_global = NULL;
}
static void wlr_output_update_matrix(struct wlr_output *output) {
wlr_matrix_texture(output->transform_matrix, output->width, output->height,
output->transform);
} }
void wlr_output_enable(struct wlr_output *output, bool enable) { void wlr_output_enable(struct wlr_output *output, bool enable) {
output->impl->enable(output, enable); output->impl->enable(output, enable);
} }
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) { bool wlr_output_set_mode(struct wlr_output *output,
struct wlr_output_mode *mode) {
if (!output->impl || !output->impl->set_mode) { if (!output->impl || !output->impl->set_mode) {
return false; return false;
} }
bool result = output->impl->set_mode(output, mode); bool result = output->impl->set_mode(output, mode);
if (result) { if (result) {
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource);
}
} }
return result; return result;
} }
void wlr_output_update_size(struct wlr_output *output, int32_t width,
int32_t height) {
output->width = width;
output->height = height;
wlr_output_update_matrix(output);
if (output->wl_global != NULL) {
struct wl_resource *resource;
wl_resource_for_each(resource, &output->wl_resources) {
wlr_output_send_current_mode_to_resource(resource);
}
}
}
void wlr_output_transform(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output,
enum wl_output_transform transform) { enum wl_output_transform transform) {
output->impl->transform(output, transform); output->impl->transform(output, transform);
wlr_output_update_matrix(output); wlr_output_update_matrix(output);
} }
void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly) { void wlr_output_set_position(struct wlr_output *output, int32_t lx,
int32_t ly) {
if (lx == output->lx && ly == output->ly) { if (lx == output->lx && ly == output->ly) {
return; return;
} }
@ -153,8 +205,7 @@ static bool set_cursor(struct wlr_output *output, const uint8_t *buf,
output->cursor.height = height; output->cursor.height = height;
if (!output->cursor.renderer) { if (!output->cursor.renderer) {
/* NULL egl is okay given that we are only using pixel buffers */ output->cursor.renderer = wlr_gles2_renderer_create(output->backend);
output->cursor.renderer = wlr_gles2_renderer_create(NULL);
if (!output->cursor.renderer) { if (!output->cursor.renderer) {
return false; return false;
} }
@ -307,10 +358,11 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
return output->impl->move_cursor(output, x, y); return output->impl->move_cursor(output, x, y);
} }
void wlr_output_init(struct wlr_output *output, void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl) { const struct wlr_output_impl *impl) {
output->backend = backend;
output->impl = impl; output->impl = impl;
output->modes = list_create(); wl_list_init(&output->modes);
output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->scale = 1; output->scale = 1;
wl_signal_init(&output->events.frame); wl_signal_init(&output->events.frame);
@ -334,11 +386,11 @@ void wlr_output_destroy(struct wlr_output *output) {
wlr_texture_destroy(output->cursor.texture); wlr_texture_destroy(output->cursor.texture);
wlr_renderer_destroy(output->cursor.renderer); wlr_renderer_destroy(output->cursor.renderer);
for (size_t i = 0; output->modes && i < output->modes->length; ++i) { struct wlr_output_mode *mode, *tmp_mode;
struct wlr_output_mode *mode = output->modes->items[i]; wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) {
free(mode); free(mode);
} }
list_free(output->modes); wl_list_remove(&output->modes);
if (output->impl && output->impl->destroy) { if (output->impl && output->impl->destroy) {
output->impl->destroy(output); output->impl->destroy(output);
} else { } else {
@ -391,13 +443,13 @@ void wlr_output_swap_buffers(struct wlr_output *output) {
} }
void wlr_output_set_gamma(struct wlr_output *output, void wlr_output_set_gamma(struct wlr_output *output,
uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b) { uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) {
if (output->impl->set_gamma) { if (output->impl->set_gamma) {
output->impl->set_gamma(output, size, r, g, b); output->impl->set_gamma(output, size, r, g, b);
} }
} }
uint16_t wlr_output_get_gamma_size(struct wlr_output *output) { uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
if (!output->impl->get_gamma_size) { if (!output->impl->get_gamma_size) {
return 0; return 0;
} }

View File

@ -121,12 +121,7 @@ static void screenshooter_bind(struct wl_client *wl_client,
void *_screenshooter, uint32_t version, uint32_t id) { void *_screenshooter, uint32_t version, uint32_t id) {
struct wlr_screenshooter *screenshooter = _screenshooter; struct wlr_screenshooter *screenshooter = _screenshooter;
assert(wl_client && screenshooter); assert(wl_client && screenshooter);
if (version > 1) {
wlr_log(L_ERROR, "Client requested unsupported screenshooter version,"
"disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&orbital_screenshooter_interface, version, id); &orbital_screenshooter_interface, version, id);
wl_resource_set_implementation(wl_resource, &screenshooter_impl, wl_resource_set_implementation(wl_resource, &screenshooter_impl,

View File

@ -177,12 +177,7 @@ static void wl_seat_bind(struct wl_client *wl_client, void *_wlr_seat,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_seat *wlr_seat = _wlr_seat; struct wlr_seat *wlr_seat = _wlr_seat;
assert(wl_client && wlr_seat); assert(wl_client && wlr_seat);
if (version > 6) {
wlr_log(L_ERROR,
"Client requested unsupported wl_seat version, disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wlr_seat_handle *handle = calloc(1, sizeof(struct wlr_seat_handle)); struct wlr_seat_handle *handle = calloc(1, sizeof(struct wlr_seat_handle));
handle->wl_resource = wl_resource_create( handle->wl_resource = wl_resource_create(
wl_client, &wl_seat_interface, version, id); wl_client, &wl_seat_interface, version, id);

View File

@ -2,9 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/egl.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/render/egl.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
static void wlr_surface_state_reset_buffer(struct wlr_surface_state *state) { static void wlr_surface_state_reset_buffer(struct wlr_surface_state *state) {
@ -408,7 +408,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) {
wlr_surface_move_state(surface, surface->pending, surface->current); wlr_surface_move_state(surface, surface->pending, surface->current);
if (null_buffer_commit) { if (null_buffer_commit) {
surface->texture->valid = false; wlr_texture_destroy(surface->texture);
surface->texture = NULL;
} }
bool reupload_buffer = oldw != surface->current->buffer_width || bool reupload_buffer = oldw != surface->current->buffer_width ||
@ -657,6 +658,10 @@ void wlr_surface_get_matrix(struct wlr_surface *surface,
wlr_matrix_mul(projection, matrix, matrix); wlr_matrix_mul(projection, matrix, matrix);
} }
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
return surface->texture && surface->texture->valid;
}
int wlr_surface_set_role(struct wlr_surface *surface, const char *role, int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
struct wl_resource *error_resource, uint32_t error_code) { struct wl_resource *error_resource, uint32_t error_code) {
assert(role); assert(role);

View File

@ -8,7 +8,6 @@
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wlr/render/interface.h>
static const char *wlr_wl_shell_surface_role = "wl-shell-surface"; static const char *wlr_wl_shell_surface_role = "wl-shell-surface";
@ -482,7 +481,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
struct wlr_wl_shell_surface *surface = struct wlr_wl_shell_surface *surface =
wl_container_of(listener, surface, surface_commit_listener); wl_container_of(listener, surface, surface_commit_listener);
if (!surface->configured && if (!surface->configured &&
surface->surface->texture->valid && wlr_surface_has_buffer(surface->surface) &&
surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) { surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) {
surface->configured = true; surface->configured = true;
wl_signal_emit(&surface->shell->events.new_surface, surface); wl_signal_emit(&surface->shell->events.new_surface, surface);
@ -490,7 +489,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
if (surface->popup_mapped && if (surface->popup_mapped &&
surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP && surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP &&
!surface->surface->texture->valid) { !wlr_surface_has_buffer(surface->surface)) {
surface->popup_mapped = false; surface->popup_mapped = false;
struct wlr_wl_shell_popup_grab *grab = struct wlr_wl_shell_popup_grab *grab =
shell_popup_grab_from_seat(surface->shell, shell_popup_grab_from_seat(surface->shell,
@ -580,12 +579,7 @@ static void shell_bind(struct wl_client *wl_client, void *_wl_shell,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_wl_shell *wl_shell = _wl_shell; struct wlr_wl_shell *wl_shell = _wl_shell;
assert(wl_client && wl_shell); assert(wl_client && wl_shell);
if (version > 1) {
wlr_log(L_ERROR,
"Client requested unsupported wl_shell version, disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&wl_shell_interface, version, id); &wl_shell_interface, version, id);
wl_resource_set_implementation(wl_resource, &shell_impl, wl_shell, wl_resource_set_implementation(wl_resource, &shell_impl, wl_shell,

View File

@ -9,7 +9,6 @@
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/render/interface.h>
#include "xdg-shell-unstable-v6-protocol.h" #include "xdg-shell-unstable-v6-protocol.h"
static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel";
@ -1018,7 +1017,8 @@ static void wlr_xdg_surface_v6_toplevel_committed(
struct wlr_xdg_surface_v6 *surface) { struct wlr_xdg_surface_v6 *surface) {
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
if (!surface->surface->texture->valid && !surface->toplevel_state->added) { if (!wlr_surface_has_buffer(surface->surface)
&& !surface->toplevel_state->added) {
// on the first commit, send a configure request to tell the client it // on the first commit, send a configure request to tell the client it
// is added // is added
wlr_xdg_surface_v6_schedule_configure(surface); wlr_xdg_surface_v6_schedule_configure(surface);
@ -1026,7 +1026,7 @@ static void wlr_xdg_surface_v6_toplevel_committed(
return; return;
} }
if (!surface->surface->texture->valid) { if (!wlr_surface_has_buffer(surface->surface)) {
return; return;
} }
@ -1048,7 +1048,7 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
struct wlr_xdg_surface_v6 *surface = struct wlr_xdg_surface_v6 *surface =
wl_container_of(listener, surface, surface_commit_listener); wl_container_of(listener, surface, surface_commit_listener);
if (surface->surface->texture->valid && !surface->configured) { if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
wl_resource_post_error(surface->resource, wl_resource_post_error(surface->resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
"xdg_surface has never been configured"); "xdg_surface has never been configured");
@ -1117,7 +1117,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
&zxdg_surface_v6_interface, wl_resource_get_version(client_resource), &zxdg_surface_v6_interface, wl_resource_get_version(client_resource),
id); id);
if (surface->surface->texture->valid) { if (wlr_surface_has_buffer(surface->surface)) {
wl_resource_post_error(surface->resource, wl_resource_post_error(surface->resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
"xdg_surface must not have a buffer at creation"); "xdg_surface must not have a buffer at creation");
@ -1201,12 +1201,7 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_xdg_shell_v6 *xdg_shell = _xdg_shell; struct wlr_xdg_shell_v6 *xdg_shell = _xdg_shell;
assert(wl_client && xdg_shell); assert(wl_client && xdg_shell);
if (version > 1) {
wlr_log(L_ERROR,
"Client requested unsupported xdg_shell_v6 version, disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wlr_xdg_client_v6 *client = struct wlr_xdg_client_v6 *client =
calloc(1, sizeof(struct wlr_xdg_client_v6)); calloc(1, sizeof(struct wlr_xdg_client_v6));
if (client == NULL) { if (client == NULL) {

View File

@ -1,7 +1,6 @@
lib_wlr_util = static_library( lib_wlr_util = static_library(
'wlr_util', 'wlr_util',
files( files(
'list.c',
'log.c', 'log.c',
), ),
include_directories: wlr_inc, include_directories: wlr_inc,

View File

@ -72,7 +72,7 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create(
surface->height = height; surface->height = height;
surface->override_redirect = override_redirect; surface->override_redirect = override_redirect;
wl_list_insert(&xwm->new_surfaces, &surface->link); wl_list_insert(&xwm->new_surfaces, &surface->link);
surface->state = list_create(); surface->state = wlr_list_create();
wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.destroy);
wl_signal_init(&surface->events.request_configure); wl_signal_init(&surface->events.request_configure);
wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_class);
@ -93,7 +93,7 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) {
free(surface->title); free(surface->title);
free(surface->class); free(surface->class);
free(surface->instance); free(surface->instance);
list_free(surface->state); wlr_list_free(surface->state);
free(surface->window_type); free(surface->window_type);
free(surface->protocols); free(surface->protocols);
free(surface->hints); free(surface->hints);
@ -200,7 +200,7 @@ static void handle_surface_state(struct wlr_xwm *xwm,
if (action == NET_WM_STATE_REMOVE || if (action == NET_WM_STATE_REMOVE ||
action == NET_WM_STATE_TOGGLE) { action == NET_WM_STATE_TOGGLE) {
free(surface->state->items[j]); free(surface->state->items[j]);
list_del(surface->state, j); wlr_list_del(surface->state, j);
} }
break; break;
} }
@ -210,7 +210,7 @@ static void handle_surface_state(struct wlr_xwm *xwm,
action == NET_WM_STATE_TOGGLE)) { action == NET_WM_STATE_TOGGLE)) {
xcb_atom_t *atom_ptr = malloc(sizeof(xcb_atom_t)); xcb_atom_t *atom_ptr = malloc(sizeof(xcb_atom_t));
*atom_ptr = atom; *atom_ptr = atom;
list_add(surface->state, atom_ptr); wlr_list_add(surface->state, atom_ptr);
} }
} }