2017-06-20 16:27:05 +00:00
|
|
|
#include <assert.h>
|
2017-06-19 20:36:40 +00:00
|
|
|
#include <stdint.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <stdio.h>
|
2017-06-19 20:36:40 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-08-14 16:19:42 +00:00
|
|
|
#include <sys/mman.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2018-11-11 05:14:48 +00:00
|
|
|
|
2021-02-09 22:29:44 +00:00
|
|
|
#include <drm_fourcc.h>
|
2017-06-19 20:36:40 +00:00
|
|
|
#include <wayland-client.h>
|
2018-11-11 05:14:48 +00:00
|
|
|
|
2017-06-21 14:27:45 +00:00
|
|
|
#include <wlr/interfaces/wlr_output.h>
|
2018-03-20 22:10:42 +00:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2018-05-01 20:38:04 +00:00
|
|
|
#include <wlr/types/wlr_matrix.h>
|
2022-08-18 10:04:39 +00:00
|
|
|
#include <wlr/types/wlr_output_layer.h>
|
2017-06-21 16:10:07 +00:00
|
|
|
#include <wlr/util/log.h>
|
2018-11-11 05:14:48 +00:00
|
|
|
|
2017-06-19 20:36:40 +00:00
|
|
|
#include "backend/wayland.h"
|
2021-02-09 22:29:44 +00:00
|
|
|
#include "render/pixel_format.h"
|
2020-11-26 10:40:23 +00:00
|
|
|
#include "render/wlr_renderer.h"
|
|
|
|
|
2019-09-24 12:33:15 +00:00
|
|
|
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
2019-11-16 20:05:46 +00:00
|
|
|
#include "presentation-time-client-protocol.h"
|
2023-04-20 08:31:22 +00:00
|
|
|
#include "viewporter-client-protocol.h"
|
2021-10-26 06:31:48 +00:00
|
|
|
#include "xdg-activation-v1-client-protocol.h"
|
2019-05-06 16:06:31 +00:00
|
|
|
#include "xdg-decoration-unstable-v1-client-protocol.h"
|
2019-01-10 14:17:14 +00:00
|
|
|
#include "xdg-shell-client-protocol.h"
|
2017-06-19 20:36:40 +00:00
|
|
|
|
2021-06-18 10:15:08 +00:00
|
|
|
static const uint32_t SUPPORTED_OUTPUT_STATE =
|
|
|
|
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
|
|
|
|
WLR_OUTPUT_STATE_BUFFER |
|
2023-06-26 13:48:01 +00:00
|
|
|
WLR_OUTPUT_STATE_ENABLED |
|
2022-06-28 17:55:48 +00:00
|
|
|
WLR_OUTPUT_STATE_MODE |
|
|
|
|
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED;
|
2021-06-18 10:15:08 +00:00
|
|
|
|
2022-10-13 11:12:43 +00:00
|
|
|
static size_t last_output_num = 0;
|
|
|
|
|
2023-06-14 16:16:44 +00:00
|
|
|
static const char *surface_tag = "wlr_wl_output";
|
|
|
|
|
2018-09-17 20:10:34 +00:00
|
|
|
static struct wlr_wl_output *get_wl_output_from_output(
|
|
|
|
struct wlr_output *wlr_output) {
|
|
|
|
assert(wlr_output_is_wl(wlr_output));
|
2023-07-11 15:54:08 +00:00
|
|
|
struct wlr_wl_output *output = wl_container_of(wlr_output, output, wlr_output);
|
|
|
|
return output;
|
2018-09-17 20:10:34 +00:00
|
|
|
}
|
2017-08-14 16:19:42 +00:00
|
|
|
|
2023-06-14 16:16:44 +00:00
|
|
|
struct wlr_wl_output *get_wl_output_from_surface(struct wlr_wl_backend *wl,
|
|
|
|
struct wl_surface *surface) {
|
|
|
|
if (wl_proxy_get_tag((struct wl_proxy *)surface) != &surface_tag) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
struct wlr_wl_output *output = wl_surface_get_user_data(surface);
|
|
|
|
assert(output != NULL);
|
|
|
|
if (output->backend != wl) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2018-01-26 21:39:23 +00:00
|
|
|
static void surface_frame_callback(void *data, struct wl_callback *cb,
|
|
|
|
uint32_t time) {
|
2018-04-29 11:16:31 +00:00
|
|
|
struct wlr_wl_output *output = data;
|
2023-01-30 13:20:36 +00:00
|
|
|
|
|
|
|
if (cb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(output->frame_callback == cb);
|
2017-06-26 15:34:22 +00:00
|
|
|
wl_callback_destroy(cb);
|
2018-01-18 12:06:57 +00:00
|
|
|
output->frame_callback = NULL;
|
2018-01-30 13:45:02 +00:00
|
|
|
|
|
|
|
wlr_output_send_frame(&output->wlr_output);
|
2017-06-26 15:34:22 +00:00
|
|
|
}
|
|
|
|
|
2019-11-16 20:05:46 +00:00
|
|
|
static const struct wl_callback_listener frame_listener = {
|
2017-06-26 15:34:22 +00:00
|
|
|
.done = surface_frame_callback
|
|
|
|
};
|
|
|
|
|
2019-11-16 20:05:46 +00:00
|
|
|
static void presentation_feedback_destroy(
|
|
|
|
struct wlr_wl_presentation_feedback *feedback) {
|
|
|
|
wl_list_remove(&feedback->link);
|
|
|
|
wp_presentation_feedback_destroy(feedback->feedback);
|
|
|
|
free(feedback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void presentation_feedback_handle_sync_output(void *data,
|
|
|
|
struct wp_presentation_feedback *feedback, struct wl_output *output) {
|
|
|
|
// This space is intentionally left blank
|
|
|
|
}
|
|
|
|
|
|
|
|
static void presentation_feedback_handle_presented(void *data,
|
|
|
|
struct wp_presentation_feedback *wp_feedback, uint32_t tv_sec_hi,
|
|
|
|
uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh_ns,
|
|
|
|
uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) {
|
|
|
|
struct wlr_wl_presentation_feedback *feedback = data;
|
|
|
|
|
|
|
|
struct timespec t = {
|
|
|
|
.tv_sec = ((uint64_t)tv_sec_hi << 32) | tv_sec_lo,
|
|
|
|
.tv_nsec = tv_nsec,
|
|
|
|
};
|
|
|
|
struct wlr_output_event_present event = {
|
|
|
|
.commit_seq = feedback->commit_seq,
|
2021-10-14 19:40:12 +00:00
|
|
|
.presented = true,
|
2019-11-16 20:05:46 +00:00
|
|
|
.when = &t,
|
|
|
|
.seq = ((uint64_t)seq_hi << 32) | seq_lo,
|
|
|
|
.refresh = refresh_ns,
|
|
|
|
.flags = flags,
|
|
|
|
};
|
|
|
|
wlr_output_send_present(&feedback->output->wlr_output, &event);
|
|
|
|
|
|
|
|
presentation_feedback_destroy(feedback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void presentation_feedback_handle_discarded(void *data,
|
|
|
|
struct wp_presentation_feedback *wp_feedback) {
|
|
|
|
struct wlr_wl_presentation_feedback *feedback = data;
|
|
|
|
|
2021-10-14 19:32:40 +00:00
|
|
|
struct wlr_output_event_present event = {
|
|
|
|
.commit_seq = feedback->commit_seq,
|
2021-10-14 19:40:12 +00:00
|
|
|
.presented = false,
|
2021-10-14 19:32:40 +00:00
|
|
|
};
|
|
|
|
wlr_output_send_present(&feedback->output->wlr_output, &event);
|
2019-11-16 20:05:46 +00:00
|
|
|
|
|
|
|
presentation_feedback_destroy(feedback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wp_presentation_feedback_listener
|
|
|
|
presentation_feedback_listener = {
|
|
|
|
.sync_output = presentation_feedback_handle_sync_output,
|
|
|
|
.presented = presentation_feedback_handle_presented,
|
|
|
|
.discarded = presentation_feedback_handle_discarded,
|
|
|
|
};
|
|
|
|
|
2020-12-11 17:14:58 +00:00
|
|
|
void destroy_wl_buffer(struct wlr_wl_buffer *buffer) {
|
2020-01-09 14:34:34 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-11 17:14:58 +00:00
|
|
|
wl_list_remove(&buffer->buffer_destroy.link);
|
|
|
|
wl_list_remove(&buffer->link);
|
2020-01-09 14:34:34 +00:00
|
|
|
wl_buffer_destroy(buffer->wl_buffer);
|
2022-12-06 19:14:44 +00:00
|
|
|
if (!buffer->released) {
|
|
|
|
wlr_buffer_unlock(buffer->buffer);
|
|
|
|
}
|
2020-01-09 14:34:34 +00:00
|
|
|
free(buffer);
|
|
|
|
}
|
2019-09-24 12:33:15 +00:00
|
|
|
|
2020-01-09 14:34:34 +00:00
|
|
|
static void buffer_handle_release(void *data, struct wl_buffer *wl_buffer) {
|
|
|
|
struct wlr_wl_buffer *buffer = data;
|
2020-12-11 17:14:58 +00:00
|
|
|
buffer->released = true;
|
|
|
|
wlr_buffer_unlock(buffer->buffer); // might free buffer
|
2020-01-09 14:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_buffer_listener buffer_listener = {
|
|
|
|
.release = buffer_handle_release,
|
|
|
|
};
|
|
|
|
|
2020-12-11 17:14:58 +00:00
|
|
|
static void buffer_handle_buffer_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_wl_buffer *buffer =
|
|
|
|
wl_container_of(listener, buffer, buffer_destroy);
|
|
|
|
destroy_wl_buffer(buffer);
|
|
|
|
}
|
|
|
|
|
2020-04-02 12:12:26 +00:00
|
|
|
static bool test_buffer(struct wlr_wl_backend *wl,
|
2020-04-10 12:54:33 +00:00
|
|
|
struct wlr_buffer *wlr_buffer) {
|
2021-02-09 22:29:44 +00:00
|
|
|
struct wlr_dmabuf_attributes dmabuf;
|
|
|
|
struct wlr_shm_attributes shm;
|
|
|
|
if (wlr_buffer_get_dmabuf(wlr_buffer, &dmabuf)) {
|
|
|
|
return wlr_drm_format_set_has(&wl->linux_dmabuf_v1_formats,
|
|
|
|
dmabuf.format, dmabuf.modifier);
|
|
|
|
} else if (wlr_buffer_get_shm(wlr_buffer, &shm)) {
|
|
|
|
return wlr_drm_format_set_has(&wl->shm_formats, shm.format,
|
|
|
|
DRM_FORMAT_MOD_INVALID);
|
|
|
|
} else {
|
2020-04-02 12:12:26 +00:00
|
|
|
return false;
|
2019-09-24 12:33:15 +00:00
|
|
|
}
|
2020-04-02 12:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 22:29:44 +00:00
|
|
|
static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl,
|
|
|
|
struct wlr_dmabuf_attributes *dmabuf) {
|
|
|
|
uint32_t modifier_hi = dmabuf->modifier >> 32;
|
|
|
|
uint32_t modifier_lo = (uint32_t)dmabuf->modifier;
|
2019-09-24 12:33:15 +00:00
|
|
|
struct zwp_linux_buffer_params_v1 *params =
|
|
|
|
zwp_linux_dmabuf_v1_create_params(wl->zwp_linux_dmabuf_v1);
|
2021-02-09 22:29:44 +00:00
|
|
|
for (int i = 0; i < dmabuf->n_planes; i++) {
|
|
|
|
zwp_linux_buffer_params_v1_add(params, dmabuf->fd[i], i,
|
|
|
|
dmabuf->offset[i], dmabuf->stride[i], modifier_hi, modifier_lo);
|
2019-09-24 12:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_buffer *wl_buffer = zwp_linux_buffer_params_v1_create_immed(
|
2021-11-16 21:51:06 +00:00
|
|
|
params, dmabuf->width, dmabuf->height, dmabuf->format, 0);
|
2023-02-28 19:05:46 +00:00
|
|
|
zwp_linux_buffer_params_v1_destroy(params);
|
2019-09-24 12:33:15 +00:00
|
|
|
// TODO: handle create() errors
|
2021-02-09 22:29:44 +00:00
|
|
|
return wl_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wl_buffer *import_shm(struct wlr_wl_backend *wl,
|
|
|
|
struct wlr_shm_attributes *shm) {
|
|
|
|
enum wl_shm_format wl_shm_format = convert_drm_format_to_wl_shm(shm->format);
|
|
|
|
uint32_t size = shm->stride * shm->height;
|
|
|
|
struct wl_shm_pool *pool = wl_shm_create_pool(wl->shm, shm->fd, size);
|
|
|
|
if (pool == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
struct wl_buffer *wl_buffer = wl_shm_pool_create_buffer(pool, shm->offset,
|
|
|
|
shm->width, shm->height, shm->stride, wl_shm_format);
|
|
|
|
wl_shm_pool_destroy(pool);
|
|
|
|
return wl_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wlr_wl_buffer *create_wl_buffer(struct wlr_wl_backend *wl,
|
|
|
|
struct wlr_buffer *wlr_buffer) {
|
|
|
|
if (!test_buffer(wl, wlr_buffer)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_dmabuf_attributes dmabuf;
|
|
|
|
struct wlr_shm_attributes shm;
|
|
|
|
struct wl_buffer *wl_buffer;
|
|
|
|
if (wlr_buffer_get_dmabuf(wlr_buffer, &dmabuf)) {
|
|
|
|
wl_buffer = import_dmabuf(wl, &dmabuf);
|
|
|
|
} else if (wlr_buffer_get_shm(wlr_buffer, &shm)) {
|
|
|
|
wl_buffer = import_shm(wl, &shm);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (wl_buffer == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-09-24 12:33:15 +00:00
|
|
|
|
2020-01-09 14:34:34 +00:00
|
|
|
struct wlr_wl_buffer *buffer = calloc(1, sizeof(struct wlr_wl_buffer));
|
|
|
|
if (buffer == NULL) {
|
|
|
|
wl_buffer_destroy(wl_buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
buffer->wl_buffer = wl_buffer;
|
2020-02-28 12:25:05 +00:00
|
|
|
buffer->buffer = wlr_buffer_lock(wlr_buffer);
|
2020-12-11 17:14:58 +00:00
|
|
|
wl_list_insert(&wl->buffers, &buffer->link);
|
2019-09-24 12:33:15 +00:00
|
|
|
|
2020-01-09 14:34:34 +00:00
|
|
|
wl_buffer_add_listener(wl_buffer, &buffer_listener, buffer);
|
|
|
|
|
2020-12-11 17:14:58 +00:00
|
|
|
buffer->buffer_destroy.notify = buffer_handle_buffer_destroy;
|
|
|
|
wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy);
|
|
|
|
|
2020-01-09 14:34:34 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-12-11 17:14:58 +00:00
|
|
|
static struct wlr_wl_buffer *get_or_create_wl_buffer(struct wlr_wl_backend *wl,
|
|
|
|
struct wlr_buffer *wlr_buffer) {
|
|
|
|
struct wlr_wl_buffer *buffer;
|
|
|
|
wl_list_for_each(buffer, &wl->buffers, link) {
|
|
|
|
// We can only re-use a wlr_wl_buffer if the parent compositor has
|
|
|
|
// released it, because wl_buffer.release is per-wl_buffer, not per
|
|
|
|
// wl_surface.commit.
|
|
|
|
if (buffer->buffer == wlr_buffer && buffer->released) {
|
|
|
|
buffer->released = false;
|
|
|
|
wlr_buffer_lock(buffer->buffer);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return create_wl_buffer(wl, wlr_buffer);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
static bool output_test(struct wlr_output *wlr_output,
|
|
|
|
const struct wlr_output_state *state) {
|
2020-04-10 13:00:00 +00:00
|
|
|
struct wlr_wl_output *output =
|
|
|
|
get_wl_output_from_output(wlr_output);
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
uint32_t unsupported = state->committed & ~SUPPORTED_OUTPUT_STATE;
|
2021-06-18 10:15:08 +00:00
|
|
|
if (unsupported != 0) {
|
|
|
|
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
|
|
|
|
unsupported);
|
2020-04-02 10:41:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-28 17:55:48 +00:00
|
|
|
// Adaptive sync is effectively always enabled when using the Wayland
|
|
|
|
// backend. This is not something we have control over, so we set the state
|
|
|
|
// to enabled on creating the output and never allow changing it.
|
|
|
|
assert(wlr_output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED);
|
|
|
|
if (state->committed & WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED) {
|
|
|
|
if (!state->adaptive_sync_enabled) {
|
2023-07-18 22:12:08 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Disabling adaptive sync is not supported");
|
2022-06-28 17:55:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_MODE) {
|
|
|
|
assert(state->mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM);
|
2023-06-27 15:45:09 +00:00
|
|
|
|
|
|
|
if (state->custom_mode.refresh != 0) {
|
2023-07-18 22:12:08 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Refresh rates are not supported");
|
2023-06-27 15:45:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-04-02 10:41:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
if ((state->committed & WLR_OUTPUT_STATE_BUFFER) &&
|
|
|
|
!test_buffer(output->backend, state->buffer)) {
|
2023-07-18 22:12:08 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Unsupported buffer format");
|
2020-04-10 13:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-18 10:04:39 +00:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_LAYERS) {
|
|
|
|
// If we can't use a sub-surface for a layer, then we can't use a
|
|
|
|
// sub-surface for any layer underneath
|
|
|
|
bool supported = output->backend->subcompositor != NULL;
|
|
|
|
for (ssize_t i = state->layers_len - 1; i >= 0; i--) {
|
|
|
|
struct wlr_output_layer_state *layer_state = &state->layers[i];
|
|
|
|
if (layer_state->buffer != NULL) {
|
2023-04-04 17:38:48 +00:00
|
|
|
int x = layer_state->dst_box.x;
|
|
|
|
int y = layer_state->dst_box.y;
|
|
|
|
int width = layer_state->dst_box.width;
|
|
|
|
int height = layer_state->dst_box.height;
|
2023-04-20 08:31:22 +00:00
|
|
|
bool needs_viewport = width != layer_state->buffer->width ||
|
|
|
|
height != layer_state->buffer->height;
|
2023-04-20 10:04:01 +00:00
|
|
|
if (!wlr_fbox_empty(&layer_state->src_box)) {
|
|
|
|
needs_viewport = needs_viewport ||
|
|
|
|
layer_state->src_box.x != 0 ||
|
|
|
|
layer_state->src_box.y != 0 ||
|
|
|
|
layer_state->src_box.width != width ||
|
|
|
|
layer_state->src_box.height != height;
|
|
|
|
}
|
2023-04-04 17:38:48 +00:00
|
|
|
if (x < 0 || y < 0 ||
|
|
|
|
x + width > wlr_output->width ||
|
|
|
|
y + height > wlr_output->height ||
|
2023-04-20 08:31:22 +00:00
|
|
|
(output->backend->viewporter == NULL && needs_viewport)) {
|
2022-08-18 10:04:39 +00:00
|
|
|
supported = false;
|
|
|
|
}
|
|
|
|
supported = supported &&
|
|
|
|
test_buffer(output->backend, layer_state->buffer);
|
|
|
|
}
|
|
|
|
layer_state->accepted = supported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_layer_handle_addon_destroy(struct wlr_addon *addon) {
|
|
|
|
struct wlr_wl_output_layer *layer = wl_container_of(addon, layer, addon);
|
|
|
|
|
|
|
|
wlr_addon_finish(&layer->addon);
|
2023-04-20 08:31:22 +00:00
|
|
|
if (layer->viewport != NULL) {
|
|
|
|
wp_viewport_destroy(layer->viewport);
|
|
|
|
}
|
2022-08-18 10:04:39 +00:00
|
|
|
wl_subsurface_destroy(layer->subsurface);
|
|
|
|
wl_surface_destroy(layer->surface);
|
|
|
|
free(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_addon_interface output_layer_addon_impl = {
|
|
|
|
.name = "wlr_wl_output_layer",
|
|
|
|
.destroy = output_layer_handle_addon_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct wlr_wl_output_layer *get_or_create_output_layer(
|
|
|
|
struct wlr_wl_output *output, struct wlr_output_layer *wlr_layer) {
|
|
|
|
assert(output->backend->subcompositor != NULL);
|
|
|
|
|
|
|
|
struct wlr_wl_output_layer *layer;
|
|
|
|
struct wlr_addon *addon = wlr_addon_find(&wlr_layer->addons, output,
|
|
|
|
&output_layer_addon_impl);
|
|
|
|
if (addon != NULL) {
|
|
|
|
layer = wl_container_of(addon, layer, addon);
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer = calloc(1, sizeof(*layer));
|
|
|
|
if (layer == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_addon_init(&layer->addon, &wlr_layer->addons, output,
|
|
|
|
&output_layer_addon_impl);
|
|
|
|
|
|
|
|
layer->surface = wl_compositor_create_surface(output->backend->compositor);
|
|
|
|
layer->subsurface = wl_subcompositor_get_subsurface(
|
|
|
|
output->backend->subcompositor, layer->surface, output->surface);
|
|
|
|
|
|
|
|
// Set an empty input region so that input events are handled by the main
|
|
|
|
// surface
|
|
|
|
struct wl_region *region = wl_compositor_create_region(output->backend->compositor);
|
|
|
|
wl_surface_set_input_region(layer->surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
2023-04-20 08:31:22 +00:00
|
|
|
if (output->backend->viewporter != NULL) {
|
|
|
|
layer->viewport = wp_viewporter_get_viewport(output->backend->viewporter, layer->surface);
|
|
|
|
}
|
|
|
|
|
2022-08-18 10:04:39 +00:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2023-02-21 08:38:41 +00:00
|
|
|
static bool has_layers_order_changed(struct wlr_wl_output *output,
|
|
|
|
struct wlr_output_layer_state *layers, size_t layers_len) {
|
2023-02-21 08:45:05 +00:00
|
|
|
// output_basic_check() ensures that layers_len equals the number of
|
|
|
|
// registered output layers
|
2023-02-21 08:38:41 +00:00
|
|
|
size_t i = 0;
|
|
|
|
struct wlr_output_layer *layer;
|
|
|
|
wl_list_for_each(layer, &output->wlr_output.layers, link) {
|
2023-02-21 08:45:05 +00:00
|
|
|
assert(i < layers_len);
|
2023-02-21 08:38:41 +00:00
|
|
|
const struct wlr_output_layer_state *layer_state = &layers[i];
|
|
|
|
if (layer_state->layer != layer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2023-02-21 08:45:05 +00:00
|
|
|
assert(i == layers_len);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_layer_unmap(struct wlr_wl_output_layer *layer) {
|
|
|
|
if (!layer->mapped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_surface_attach(layer->surface, NULL, 0, 0);
|
|
|
|
wl_surface_commit(layer->surface);
|
|
|
|
layer->mapped = false;
|
2023-02-21 08:38:41 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 09:21:16 +00:00
|
|
|
static void damage_surface(struct wl_surface *surface,
|
|
|
|
const pixman_region32_t *damage) {
|
|
|
|
if (damage == NULL) {
|
|
|
|
wl_surface_damage_buffer(surface,
|
|
|
|
0, 0, INT32_MAX, INT32_MAX);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rects_len;
|
|
|
|
const pixman_box32_t *rects = pixman_region32_rectangles(damage, &rects_len);
|
|
|
|
for (int i = 0; i < rects_len; i++) {
|
|
|
|
const pixman_box32_t *r = &rects[i];
|
|
|
|
wl_surface_damage_buffer(surface, r->x1, r->y1,
|
|
|
|
r->x2 - r->x1, r->y2 - r->y1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 10:04:39 +00:00
|
|
|
static bool output_layer_commit(struct wlr_wl_output *output,
|
|
|
|
struct wlr_wl_output_layer *layer,
|
|
|
|
const struct wlr_output_layer_state *state) {
|
2023-04-04 17:38:48 +00:00
|
|
|
if (state->layer->dst_box.x != state->dst_box.x ||
|
|
|
|
state->layer->dst_box.y != state->dst_box.y) {
|
|
|
|
wl_subsurface_set_position(layer->subsurface, state->dst_box.x, state->dst_box.y);
|
2023-02-21 08:40:28 +00:00
|
|
|
}
|
2022-08-18 10:04:39 +00:00
|
|
|
|
2023-02-21 08:45:05 +00:00
|
|
|
if (state->buffer == NULL) {
|
|
|
|
output_layer_unmap(layer);
|
|
|
|
return true;
|
2022-08-18 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 08:45:05 +00:00
|
|
|
struct wlr_wl_buffer *buffer =
|
|
|
|
get_or_create_wl_buffer(output->backend, state->buffer);
|
|
|
|
if (buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-08-18 10:04:39 +00:00
|
|
|
|
2023-04-20 08:31:22 +00:00
|
|
|
if (layer->viewport != NULL &&
|
|
|
|
(state->layer->dst_box.width != state->dst_box.width ||
|
|
|
|
state->layer->dst_box.height != state->dst_box.height)) {
|
|
|
|
wp_viewport_set_destination(layer->viewport, state->dst_box.width, state->dst_box.height);
|
|
|
|
}
|
2023-04-20 10:04:01 +00:00
|
|
|
if (layer->viewport != NULL && !wlr_fbox_equal(&state->layer->src_box, &state->src_box)) {
|
|
|
|
struct wlr_fbox src_box = state->src_box;
|
|
|
|
if (wlr_fbox_empty(&src_box)) {
|
|
|
|
// -1 resets the box
|
|
|
|
src_box = (struct wlr_fbox){
|
|
|
|
.x = -1,
|
|
|
|
.y = -1,
|
|
|
|
.width = -1,
|
|
|
|
.height = -1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
wp_viewport_set_source(layer->viewport,
|
|
|
|
wl_fixed_from_double(src_box.x),
|
|
|
|
wl_fixed_from_double(src_box.y),
|
|
|
|
wl_fixed_from_double(src_box.width),
|
|
|
|
wl_fixed_from_double(src_box.height));
|
|
|
|
}
|
2023-04-20 08:31:22 +00:00
|
|
|
|
2023-02-21 08:45:05 +00:00
|
|
|
wl_surface_attach(layer->surface, buffer->wl_buffer, 0, 0);
|
2023-02-21 09:21:16 +00:00
|
|
|
damage_surface(layer->surface, state->damage);
|
2022-08-18 10:04:39 +00:00
|
|
|
wl_surface_commit(layer->surface);
|
2023-02-21 08:45:05 +00:00
|
|
|
layer->mapped = true;
|
2022-08-18 10:04:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool commit_layers(struct wlr_wl_output *output,
|
|
|
|
struct wlr_output_layer_state *layers, size_t layers_len) {
|
|
|
|
if (output->backend->subcompositor == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-21 08:38:41 +00:00
|
|
|
bool reordered = has_layers_order_changed(output, layers, layers_len);
|
|
|
|
|
2022-08-18 10:04:39 +00:00
|
|
|
struct wlr_wl_output_layer *prev_layer = NULL;
|
|
|
|
for (size_t i = 0; i < layers_len; i++) {
|
|
|
|
struct wlr_wl_output_layer *layer =
|
|
|
|
get_or_create_output_layer(output, layers[i].layer);
|
|
|
|
if (layer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!layers[i].accepted) {
|
2023-02-21 08:45:05 +00:00
|
|
|
output_layer_unmap(layer);
|
2022-08-18 10:04:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-21 08:38:41 +00:00
|
|
|
if (prev_layer != NULL && reordered) {
|
2022-08-18 10:04:39 +00:00
|
|
|
wl_subsurface_place_above(layer->subsurface,
|
|
|
|
prev_layer->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output_layer_commit(output, layer, &layers[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:41:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
static bool output_commit(struct wlr_output *wlr_output,
|
|
|
|
const struct wlr_output_state *state) {
|
2018-04-29 11:16:31 +00:00
|
|
|
struct wlr_wl_output *output =
|
2018-09-17 20:10:34 +00:00
|
|
|
get_wl_output_from_output(wlr_output);
|
2018-01-20 23:06:35 +00:00
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
if (!output_test(wlr_output, state)) {
|
2018-01-30 13:45:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-26 13:48:01 +00:00
|
|
|
if ((state->committed & WLR_OUTPUT_STATE_ENABLED) && !state->enabled) {
|
|
|
|
wl_surface_attach(output->surface, NULL, 0, 0);
|
|
|
|
wl_surface_commit(output->surface);
|
|
|
|
}
|
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
|
2022-10-24 10:47:59 +00:00
|
|
|
const pixman_region32_t *damage = NULL;
|
2022-05-24 17:16:50 +00:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
|
2022-10-24 10:47:59 +00:00
|
|
|
damage = &state->damage;
|
2019-09-24 12:33:15 +00:00
|
|
|
}
|
2019-08-16 16:41:56 +00:00
|
|
|
|
2022-05-24 17:16:50 +00:00
|
|
|
struct wlr_buffer *wlr_buffer = state->buffer;
|
2020-11-26 10:40:23 +00:00
|
|
|
struct wlr_wl_buffer *buffer =
|
2020-12-11 17:14:58 +00:00
|
|
|
get_or_create_wl_buffer(output->backend, wlr_buffer);
|
2020-11-26 10:40:23 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_surface_attach(output->surface, buffer->wl_buffer, 0, 0);
|
2023-02-21 09:21:16 +00:00
|
|
|
damage_surface(output->surface, damage);
|
2022-08-18 10:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((state->committed & WLR_OUTPUT_STATE_LAYERS) &&
|
|
|
|
!commit_layers(output, state->layers, state->layers_len)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->committed & (WLR_OUTPUT_STATE_BUFFER | WLR_OUTPUT_STATE_LAYERS)) {
|
|
|
|
if (output->frame_callback != NULL) {
|
|
|
|
wl_callback_destroy(output->frame_callback);
|
|
|
|
}
|
|
|
|
output->frame_callback = wl_surface_frame(output->surface);
|
|
|
|
wl_callback_add_listener(output->frame_callback, &frame_listener, output);
|
|
|
|
|
|
|
|
struct wp_presentation_feedback *wp_feedback = NULL;
|
|
|
|
if (output->backend->presentation != NULL) {
|
|
|
|
wp_feedback = wp_presentation_feedback(output->backend->presentation,
|
|
|
|
output->surface);
|
|
|
|
}
|
2019-09-24 12:33:15 +00:00
|
|
|
|
2020-11-26 10:40:23 +00:00
|
|
|
wl_surface_commit(output->surface);
|
|
|
|
|
2019-08-16 16:41:56 +00:00
|
|
|
if (wp_feedback != NULL) {
|
|
|
|
struct wlr_wl_presentation_feedback *feedback =
|
|
|
|
calloc(1, sizeof(*feedback));
|
|
|
|
if (feedback == NULL) {
|
|
|
|
wp_presentation_feedback_destroy(wp_feedback);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
feedback->output = output;
|
|
|
|
feedback->feedback = wp_feedback;
|
|
|
|
feedback->commit_seq = output->wlr_output.commit_seq + 1;
|
|
|
|
wl_list_insert(&output->presentation_feedbacks, &feedback->link);
|
2018-10-01 09:07:58 +00:00
|
|
|
|
2019-08-16 16:41:56 +00:00
|
|
|
wp_presentation_feedback_add_listener(wp_feedback,
|
|
|
|
&presentation_feedback_listener, feedback);
|
|
|
|
} else {
|
2021-10-14 19:32:40 +00:00
|
|
|
struct wlr_output_event_present present_event = {
|
|
|
|
.commit_seq = wlr_output->commit_seq + 1,
|
2021-10-14 19:40:12 +00:00
|
|
|
.presented = true,
|
2021-10-14 19:32:40 +00:00
|
|
|
};
|
|
|
|
wlr_output_send_present(wlr_output, &present_event);
|
2019-11-16 20:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-24 12:33:15 +00:00
|
|
|
|
2021-01-29 09:06:16 +00:00
|
|
|
wl_display_flush(output->backend->remote_display);
|
|
|
|
|
2018-10-01 09:07:58 +00:00
|
|
|
return true;
|
2017-06-20 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 18:58:18 +00:00
|
|
|
static bool output_set_cursor(struct wlr_output *wlr_output,
|
2020-12-04 15:41:16 +00:00
|
|
|
struct wlr_buffer *wlr_buffer, int hotspot_x, int hotspot_y) {
|
2018-09-17 20:10:34 +00:00
|
|
|
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
|
2017-08-14 16:19:42 +00:00
|
|
|
struct wlr_wl_backend *backend = output->backend;
|
2020-12-04 15:41:16 +00:00
|
|
|
|
|
|
|
output->cursor.hotspot_x = hotspot_x;
|
|
|
|
output->cursor.hotspot_y = hotspot_y;
|
2017-10-08 19:21:06 +00:00
|
|
|
|
2018-05-01 20:38:04 +00:00
|
|
|
if (output->cursor.surface == NULL) {
|
2017-10-29 16:43:26 +00:00
|
|
|
output->cursor.surface =
|
2018-05-01 20:38:04 +00:00
|
|
|
wl_compositor_create_surface(backend->compositor);
|
2017-08-14 16:19:42 +00:00
|
|
|
}
|
2018-05-01 20:38:04 +00:00
|
|
|
struct wl_surface *surface = output->cursor.surface;
|
2017-08-14 16:19:42 +00:00
|
|
|
|
2020-12-04 15:41:16 +00:00
|
|
|
if (wlr_buffer != NULL) {
|
2020-11-26 12:18:44 +00:00
|
|
|
struct wlr_wl_buffer *buffer =
|
2021-01-04 11:55:40 +00:00
|
|
|
get_or_create_wl_buffer(output->backend, wlr_buffer);
|
2020-11-26 12:18:44 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_surface_attach(surface, buffer->wl_buffer, 0, 0);
|
|
|
|
wl_surface_damage_buffer(surface, 0, 0, INT32_MAX, INT32_MAX);
|
|
|
|
wl_surface_commit(surface);
|
2018-05-01 20:38:04 +00:00
|
|
|
} else {
|
|
|
|
wl_surface_attach(surface, NULL, 0, 0);
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
}
|
2017-08-14 16:19:42 +00:00
|
|
|
|
2018-04-25 22:24:58 +00:00
|
|
|
update_wl_output_cursor(output);
|
2021-01-29 09:06:16 +00:00
|
|
|
wl_display_flush(backend->remote_display);
|
2017-08-14 16:19:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-19 15:16:07 +00:00
|
|
|
static const struct wlr_drm_format_set *output_get_formats(
|
2020-12-02 09:36:23 +00:00
|
|
|
struct wlr_output *wlr_output, uint32_t buffer_caps) {
|
|
|
|
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
|
|
|
|
if (buffer_caps & WLR_BUFFER_CAP_DMABUF) {
|
|
|
|
return &output->backend->linux_dmabuf_v1_formats;
|
|
|
|
} else if (buffer_caps & WLR_BUFFER_CAP_SHM) {
|
|
|
|
return &output->backend->shm_formats;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-25 22:51:00 +00:00
|
|
|
static void output_destroy(struct wlr_output *wlr_output) {
|
2018-09-17 20:10:34 +00:00
|
|
|
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
|
2018-01-30 18:45:57 +00:00
|
|
|
if (output == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-29 16:43:26 +00:00
|
|
|
|
2017-12-13 20:48:59 +00:00
|
|
|
wl_list_remove(&output->link);
|
|
|
|
|
2017-10-29 16:43:26 +00:00
|
|
|
if (output->cursor.surface) {
|
|
|
|
wl_surface_destroy(output->cursor.surface);
|
2017-08-14 16:19:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 15:43:36 +00:00
|
|
|
if (output->frame_callback) {
|
|
|
|
wl_callback_destroy(output->frame_callback);
|
|
|
|
}
|
2017-12-13 20:48:59 +00:00
|
|
|
|
2019-11-16 20:05:46 +00:00
|
|
|
struct wlr_wl_presentation_feedback *feedback, *feedback_tmp;
|
|
|
|
wl_list_for_each_safe(feedback, feedback_tmp,
|
|
|
|
&output->presentation_feedbacks, link) {
|
|
|
|
presentation_feedback_destroy(feedback);
|
|
|
|
}
|
|
|
|
|
2019-05-06 16:06:31 +00:00
|
|
|
if (output->zxdg_toplevel_decoration_v1) {
|
|
|
|
zxdg_toplevel_decoration_v1_destroy(output->zxdg_toplevel_decoration_v1);
|
|
|
|
}
|
2023-06-07 12:35:26 +00:00
|
|
|
if (output->xdg_toplevel) {
|
|
|
|
xdg_toplevel_destroy(output->xdg_toplevel);
|
|
|
|
}
|
|
|
|
if (output->xdg_surface) {
|
|
|
|
xdg_surface_destroy(output->xdg_surface);
|
|
|
|
}
|
|
|
|
if (output->own_surface) {
|
|
|
|
wl_surface_destroy(output->surface);
|
|
|
|
}
|
2021-01-29 09:06:16 +00:00
|
|
|
wl_display_flush(output->backend->remote_display);
|
2017-06-19 20:36:40 +00:00
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
2018-04-29 11:16:31 +00:00
|
|
|
void update_wl_output_cursor(struct wlr_wl_output *output) {
|
2020-10-09 20:17:17 +00:00
|
|
|
struct wlr_wl_pointer *pointer = output->cursor.pointer;
|
|
|
|
if (pointer) {
|
|
|
|
assert(pointer->output == output);
|
|
|
|
assert(output->enter_serial);
|
2022-03-05 02:59:59 +00:00
|
|
|
|
|
|
|
struct wlr_wl_seat *seat = pointer->seat;
|
|
|
|
wl_pointer_set_cursor(seat->wl_pointer, output->enter_serial,
|
2017-10-29 16:43:26 +00:00
|
|
|
output->cursor.surface, output->cursor.hotspot_x,
|
|
|
|
output->cursor.hotspot_y);
|
2017-08-14 16:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 14:14:22 +00:00
|
|
|
static bool output_move_cursor(struct wlr_output *_output, int x, int y) {
|
2017-08-14 16:19:42 +00:00
|
|
|
// TODO: only return true if x == current x and y == current y
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-25 22:51:00 +00:00
|
|
|
static const struct wlr_output_impl output_impl = {
|
|
|
|
.destroy = output_destroy,
|
2020-04-02 10:41:19 +00:00
|
|
|
.test = output_test,
|
2019-04-23 16:26:21 +00:00
|
|
|
.commit = output_commit,
|
2018-04-25 22:51:00 +00:00
|
|
|
.set_cursor = output_set_cursor,
|
|
|
|
.move_cursor = output_move_cursor,
|
2020-12-19 15:16:07 +00:00
|
|
|
.get_cursor_formats = output_get_formats,
|
|
|
|
.get_primary_formats = output_get_formats,
|
2017-06-19 20:36:40 +00:00
|
|
|
};
|
|
|
|
|
2017-12-19 18:55:18 +00:00
|
|
|
bool wlr_output_is_wl(struct wlr_output *wlr_output) {
|
|
|
|
return wlr_output->impl == &output_impl;
|
|
|
|
}
|
|
|
|
|
2019-01-10 14:17:14 +00:00
|
|
|
static void xdg_surface_handle_configure(void *data,
|
|
|
|
struct xdg_surface *xdg_surface, uint32_t serial) {
|
2018-04-29 11:16:31 +00:00
|
|
|
struct wlr_wl_output *output = data;
|
2017-08-16 17:19:31 +00:00
|
|
|
assert(output && output->xdg_surface == xdg_surface);
|
|
|
|
|
2023-08-16 20:09:01 +00:00
|
|
|
output->configured = true;
|
2019-01-10 14:17:14 +00:00
|
|
|
xdg_surface_ack_configure(xdg_surface, serial);
|
2017-08-16 17:19:31 +00:00
|
|
|
|
|
|
|
// nothing else?
|
2017-06-20 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:57:18 +00:00
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
2017-08-16 17:19:31 +00:00
|
|
|
.configure = xdg_surface_handle_configure,
|
|
|
|
};
|
|
|
|
|
2018-09-17 20:10:34 +00:00
|
|
|
static void xdg_toplevel_handle_configure(void *data,
|
2019-01-10 14:17:14 +00:00
|
|
|
struct xdg_toplevel *xdg_toplevel,
|
2017-08-16 17:19:31 +00:00
|
|
|
int32_t width, int32_t height, struct wl_array *states) {
|
2018-04-29 11:16:31 +00:00
|
|
|
struct wlr_wl_output *output = data;
|
2017-08-16 17:19:31 +00:00
|
|
|
assert(output && output->xdg_toplevel == xdg_toplevel);
|
|
|
|
|
2018-06-30 02:08:49 +00:00
|
|
|
if (width == 0 || height == 0) {
|
2017-08-17 08:22:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-18 08:56:18 +00:00
|
|
|
|
2023-06-22 13:48:35 +00:00
|
|
|
struct wlr_output_state state;
|
|
|
|
wlr_output_state_init(&state);
|
|
|
|
wlr_output_state_set_custom_mode(&state, width, height, 0);
|
2021-01-28 15:04:47 +00:00
|
|
|
wlr_output_send_request_state(&output->wlr_output, &state);
|
2023-06-22 13:48:35 +00:00
|
|
|
wlr_output_state_finish(&state);
|
2017-06-20 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 20:10:34 +00:00
|
|
|
static void xdg_toplevel_handle_close(void *data,
|
2019-01-10 14:17:14 +00:00
|
|
|
struct xdg_toplevel *xdg_toplevel) {
|
2018-04-29 11:16:31 +00:00
|
|
|
struct wlr_wl_output *output = data;
|
2017-11-01 19:14:52 +00:00
|
|
|
assert(output && output->xdg_toplevel == xdg_toplevel);
|
2017-08-16 17:19:31 +00:00
|
|
|
|
2021-01-29 11:12:30 +00:00
|
|
|
wlr_output_destroy(&output->wlr_output);
|
2017-06-20 16:27:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:57:18 +00:00
|
|
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
2017-08-16 17:19:31 +00:00
|
|
|
.configure = xdg_toplevel_handle_configure,
|
|
|
|
.close = xdg_toplevel_handle_close,
|
2017-06-20 16:27:05 +00:00
|
|
|
};
|
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
static struct wlr_wl_output *output_create(struct wlr_wl_backend *backend,
|
|
|
|
struct wl_surface *surface) {
|
|
|
|
struct wlr_wl_output *output = calloc(1, sizeof(*output));
|
|
|
|
if (output == NULL) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_wl_output");
|
2017-06-19 20:36:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-13 14:51:50 +00:00
|
|
|
struct wlr_output *wlr_output = &output->wlr_output;
|
2017-06-19 20:36:40 +00:00
|
|
|
|
2023-06-27 16:29:52 +00:00
|
|
|
struct wlr_output_state state;
|
|
|
|
wlr_output_state_init(&state);
|
|
|
|
wlr_output_state_set_custom_mode(&state, 1280, 720, 0);
|
|
|
|
|
|
|
|
wlr_output_init(wlr_output, &backend->backend, &output_impl,
|
|
|
|
backend->local_display, &state);
|
|
|
|
wlr_output_state_finish(&state);
|
2021-12-09 14:43:19 +00:00
|
|
|
|
2022-06-28 17:55:48 +00:00
|
|
|
wlr_output->adaptive_sync_status = WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
|
|
|
|
|
2022-10-13 11:12:43 +00:00
|
|
|
size_t output_num = ++last_output_num;
|
|
|
|
|
2021-12-09 14:43:19 +00:00
|
|
|
char name[64];
|
2022-10-13 11:12:43 +00:00
|
|
|
snprintf(name, sizeof(name), "WL-%zu", output_num);
|
2021-12-09 14:43:19 +00:00
|
|
|
wlr_output_set_name(wlr_output, name);
|
2017-06-19 20:36:40 +00:00
|
|
|
|
2019-12-26 15:09:05 +00:00
|
|
|
char description[128];
|
2022-10-13 11:12:43 +00:00
|
|
|
snprintf(description, sizeof(description), "Wayland output %zu", output_num);
|
2019-12-26 15:09:05 +00:00
|
|
|
wlr_output_set_description(wlr_output, description);
|
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
output->surface = surface;
|
2017-08-13 14:51:50 +00:00
|
|
|
output->backend = backend;
|
2019-11-16 20:05:46 +00:00
|
|
|
wl_list_init(&output->presentation_feedbacks);
|
2017-06-20 16:27:05 +00:00
|
|
|
|
2023-06-14 16:16:44 +00:00
|
|
|
wl_proxy_set_tag((struct wl_proxy *)output->surface, &surface_tag);
|
2018-04-29 12:37:29 +00:00
|
|
|
wl_surface_set_user_data(output->surface, output);
|
2023-06-07 12:35:26 +00:00
|
|
|
|
|
|
|
wl_list_insert(&backend->outputs, &output->link);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_start(struct wlr_wl_output *output) {
|
|
|
|
struct wlr_output *wlr_output = &output->wlr_output;
|
|
|
|
struct wlr_wl_backend *backend = output->backend;
|
|
|
|
|
|
|
|
wl_signal_emit_mutable(&backend->backend.events.new_output, wlr_output);
|
|
|
|
|
|
|
|
struct wlr_wl_seat *seat;
|
|
|
|
wl_list_for_each(seat, &backend->seats, link) {
|
|
|
|
if (seat->wl_pointer) {
|
|
|
|
create_pointer(seat, output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
|
|
|
|
struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
|
|
|
|
if (!backend->started) {
|
|
|
|
++backend->requested_outputs;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_surface *surface = wl_compositor_create_surface(backend->compositor);
|
|
|
|
if (surface == NULL) {
|
|
|
|
wlr_log(WLR_ERROR, "Could not create output surface");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_wl_output *output = output_create(backend, surface);
|
|
|
|
if (output == NULL) {
|
|
|
|
wl_surface_destroy(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->own_surface = true;
|
|
|
|
|
2017-08-16 17:19:31 +00:00
|
|
|
output->xdg_surface =
|
2019-01-10 14:17:14 +00:00
|
|
|
xdg_wm_base_get_xdg_surface(backend->xdg_wm_base, output->surface);
|
2017-08-16 17:33:16 +00:00
|
|
|
if (!output->xdg_surface) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log_errno(WLR_ERROR, "Could not get xdg surface");
|
2017-08-16 17:33:16 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2023-06-07 12:35:26 +00:00
|
|
|
|
2017-08-16 17:19:31 +00:00
|
|
|
output->xdg_toplevel =
|
2019-01-10 14:17:14 +00:00
|
|
|
xdg_surface_get_toplevel(output->xdg_surface);
|
2017-08-16 17:33:16 +00:00
|
|
|
if (!output->xdg_toplevel) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log_errno(WLR_ERROR, "Could not get xdg toplevel");
|
2017-08-16 17:33:16 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2017-08-16 17:19:31 +00:00
|
|
|
|
2019-05-06 16:06:31 +00:00
|
|
|
if (backend->zxdg_decoration_manager_v1) {
|
|
|
|
output->zxdg_toplevel_decoration_v1 =
|
|
|
|
zxdg_decoration_manager_v1_get_toplevel_decoration(
|
|
|
|
backend->zxdg_decoration_manager_v1, output->xdg_toplevel);
|
2019-08-09 14:23:10 +00:00
|
|
|
if (!output->zxdg_toplevel_decoration_v1) {
|
2019-05-06 16:06:31 +00:00
|
|
|
wlr_log_errno(WLR_ERROR, "Could not get xdg toplevel decoration");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
zxdg_toplevel_decoration_v1_set_mode(output->zxdg_toplevel_decoration_v1,
|
|
|
|
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
|
|
|
|
}
|
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
wlr_wl_output_set_title(&output->wlr_output, NULL);
|
2018-05-14 23:16:18 +00:00
|
|
|
|
2019-01-10 14:17:14 +00:00
|
|
|
xdg_toplevel_set_app_id(output->xdg_toplevel, "wlroots");
|
|
|
|
xdg_surface_add_listener(output->xdg_surface,
|
2017-08-16 17:19:31 +00:00
|
|
|
&xdg_surface_listener, output);
|
2019-01-10 14:17:14 +00:00
|
|
|
xdg_toplevel_add_listener(output->xdg_toplevel,
|
2017-08-16 17:19:31 +00:00
|
|
|
&xdg_toplevel_listener, output);
|
2017-08-16 22:52:01 +00:00
|
|
|
wl_surface_commit(output->surface);
|
2017-06-20 16:27:05 +00:00
|
|
|
|
2023-08-16 20:09:01 +00:00
|
|
|
struct wl_event_loop *event_loop = wl_display_get_event_loop(backend->local_display);
|
|
|
|
while (!output->configured) {
|
|
|
|
int ret = wl_event_loop_dispatch(event_loop, -1);
|
|
|
|
if (ret < 0) {
|
|
|
|
wlr_log(WLR_ERROR, "wl_event_loop_dispatch() failed");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 08:22:54 +00:00
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
output_start(output);
|
2018-04-29 11:16:31 +00:00
|
|
|
|
2021-10-26 06:31:48 +00:00
|
|
|
// TODO: let the compositor do this bit
|
|
|
|
if (backend->activation_v1 && backend->activation_token) {
|
|
|
|
xdg_activation_v1_activate(backend->activation_v1,
|
|
|
|
backend->activation_token, output->surface);
|
|
|
|
}
|
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
return &output->wlr_output;
|
2017-08-16 17:33:16 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
wlr_output_destroy(&output->wlr_output);
|
|
|
|
return NULL;
|
2017-06-19 20:36:40 +00:00
|
|
|
}
|
2019-01-11 02:53:32 +00:00
|
|
|
|
2023-06-07 12:35:26 +00:00
|
|
|
struct wlr_output *wlr_wl_output_create_from_surface(struct wlr_backend *wlr_backend,
|
|
|
|
struct wl_surface *surface) {
|
|
|
|
struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend);
|
|
|
|
assert(backend->started);
|
|
|
|
|
|
|
|
struct wlr_wl_output *output = output_create(backend, surface);
|
|
|
|
if (output == NULL) {
|
|
|
|
wl_surface_destroy(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_start(output);
|
|
|
|
|
|
|
|
return &output->wlr_output;
|
|
|
|
}
|
|
|
|
|
2019-01-11 02:53:32 +00:00
|
|
|
void wlr_wl_output_set_title(struct wlr_output *output, const char *title) {
|
|
|
|
struct wlr_wl_output *wl_output = get_wl_output_from_output(output);
|
2023-06-07 12:35:26 +00:00
|
|
|
assert(wl_output->xdg_toplevel != NULL);
|
2019-01-24 12:48:26 +00:00
|
|
|
|
|
|
|
char wl_title[32];
|
|
|
|
if (title == NULL) {
|
|
|
|
if (snprintf(wl_title, sizeof(wl_title), "wlroots - %s", output->name) <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
title = wl_title;
|
|
|
|
}
|
|
|
|
|
2019-01-11 02:53:32 +00:00
|
|
|
xdg_toplevel_set_title(wl_output->xdg_toplevel, title);
|
2021-01-29 09:06:16 +00:00
|
|
|
wl_display_flush(wl_output->backend->remote_display);
|
2019-01-11 02:53:32 +00:00
|
|
|
}
|
2019-11-12 16:56:57 +00:00
|
|
|
|
|
|
|
struct wl_surface *wlr_wl_output_get_surface(struct wlr_output *output) {
|
|
|
|
struct wlr_wl_output *wl_output = get_wl_output_from_output(output);
|
|
|
|
return wl_output->surface;
|
|
|
|
}
|