Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion video/out/opengl/context_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ static void wayland_egl_update_render_opts(struct ra_ctx *ctx)
{
struct vo_wayland_state *wl = ctx->vo->wl;
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_commit(wl->surface);
}

static bool wayland_egl_init(struct ra_ctx *ctx)
Expand Down
1 change: 0 additions & 1 deletion video/out/vulkan/context_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ static void wayland_vk_update_render_opts(struct ra_ctx *ctx)
{
struct vo_wayland_state *wl = ctx->vo->wl;
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_commit(wl->surface);
}

const struct ra_ctx_fns ra_ctx_vulkan_wayland = {
Expand Down
136 changes: 58 additions & 78 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ struct vo_wayland_output {
uint32_t flags;
int phys_width;
int phys_height;
int mode_width;
int mode_height;
int transform;
int scale;
double refresh_rate;
Expand Down Expand Up @@ -1223,15 +1225,19 @@ static void seat_handle_caps(void *data, struct wl_seat *seat,
get_shape_device(s->wl, s);
wl_pointer_add_listener(s->pointer, &pointer_listener, s);
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && s->pointer) {
wl_pointer_destroy(s->pointer);
if (s->cursor_shape_device) {
wp_cursor_shape_device_v1_destroy(s->cursor_shape_device);
s->cursor_shape_device = NULL;
}
MP_WL_RELEASE_OR_DESTROY(wl_pointer, s->pointer, WL_POINTER_RELEASE_SINCE_VERSION);
s->pointer = NULL;
}

if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !s->keyboard) {
s->keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_add_listener(s->keyboard, &keyboard_listener, s);
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && s->keyboard) {
wl_keyboard_destroy(s->keyboard);
MP_WL_RELEASE_OR_DESTROY(wl_keyboard, s->keyboard, WL_KEYBOARD_RELEASE_SINCE_VERSION);
s->keyboard = NULL;
}

Expand All @@ -1240,7 +1246,7 @@ static void seat_handle_caps(void *data, struct wl_seat *seat,
wl_touch_set_user_data(s->touch, s);
wl_touch_add_listener(s->touch, &touch_listener, s);
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && s->touch) {
wl_touch_destroy(s->touch);
MP_WL_RELEASE_OR_DESTROY(wl_touch, s->touch, WL_TOUCH_RELEASE_SINCE_VERSION);
s->touch = NULL;
}
}
Expand Down Expand Up @@ -1583,8 +1589,8 @@ static void output_handle_geometry(void *data, struct wl_output *wl_output,
int32_t transform)
{
struct vo_wayland_output *output = data;
output->make = talloc_strdup(output->wl, make);
output->model = talloc_strdup(output->wl, model);
ta_replace(output, output->make, make);
ta_replace(output, output->model, model);
output->geometry.x0 = x;
output->geometry.y0 = y;
output->phys_width = phys_width;
Expand All @@ -1602,8 +1608,8 @@ static void output_handle_mode(void *data, struct wl_output *wl_output,
if (!(flags & WL_OUTPUT_MODE_CURRENT))
return;

output->geometry.x1 = width;
output->geometry.y1 = height;
output->mode_width = width;
output->mode_height = height;
output->flags = flags;
output->refresh_rate = (double)refresh * 0.001;
}
Expand All @@ -1613,6 +1619,8 @@ static void output_handle_done(void *data, struct wl_output *wl_output)
struct vo_wayland_output *o = data;
struct vo_wayland_state *wl = o->wl;

o->geometry.x1 = o->mode_width;
o->geometry.y1 = o->mode_height;
if (o->transform % 2)
MPSWAP(int, o->geometry.x1, o->geometry.y1);

Expand Down Expand Up @@ -1656,7 +1664,7 @@ static void output_handle_name(void *data, struct wl_output *wl_output,
const char *name)
{
struct vo_wayland_output *output = data;
output->name = talloc_strdup(output->wl, name);
ta_replace(output, output->name, name);
}

static void output_handle_description(void *data, struct wl_output *wl_output,
Expand All @@ -1673,30 +1681,38 @@ static const struct wl_output_listener output_listener = {
.description = output_handle_description,
};

static void surface_handle_enter(void *data, struct wl_surface *wl_surface,
struct wl_output *output)
static void update_surface_outputs(struct vo_wayland_state *wl,
struct wl_output *output, bool entered)
{
struct vo_wayland_state *wl = data;

if (wl->current_output) {
wl->old_output_geometry = wl->current_output->geometry;
wl->old_geometry = wl->geometry;
}

wl->current_output = NULL;
int outputs = 0;
struct vo_wayland_output *o;
struct vo_wayland_output *o, *event_output = NULL, *last_output = NULL;
wl_list_for_each(o, &wl->output_list, link) {
if (o->output == output) {
wl->current_output = o;
wl->current_output->has_surface = true;
o->has_surface = entered;
event_output = o;
}
if (o->has_surface)
if (o->has_surface) {
++outputs;
last_output = o;
}
}

wl->current_output = entered ? event_output : last_output;
if (outputs == 1)
update_output_geometry(wl);
wl->pending_vo_events |= VO_EVENT_WIN_STATE;
}

static void surface_handle_enter(void *data, struct wl_surface *wl_surface,
struct wl_output *output)
{
struct vo_wayland_state *wl = data;
update_surface_outputs(wl, output, true);

if (wl->current_output) {
MP_VERBOSE(wl, "Surface entered output %s %s (%s) (0x%x), scale = %f, refresh rate = %f Hz\n",
Expand All @@ -1705,38 +1721,12 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface,
} else {
MP_VERBOSE(wl, "Surface entered unknown output\n");
}

wl->pending_vo_events |= VO_EVENT_WIN_STATE;
}

static void surface_handle_leave(void *data, struct wl_surface *wl_surface,
struct wl_output *output)
{
struct vo_wayland_state *wl = data;

if (wl->current_output) {
wl->old_output_geometry = wl->current_output->geometry;
wl->old_geometry = wl->geometry;
}

int outputs = 0;
struct vo_wayland_output *o;
wl_list_for_each(o, &wl->output_list, link) {
if (o->output == output)
o->has_surface = false;
if (o->has_surface)
++outputs;
if (o->output != output && o->has_surface)
wl->current_output = o;
}

if (!outputs)
wl->current_output = NULL;

if (outputs == 1)
update_output_geometry(wl);

wl->pending_vo_events |= VO_EVENT_WIN_STATE;
update_surface_outputs(data, output, false);
}

static void surface_handle_preferred_buffer_scale(void *data,
Expand Down Expand Up @@ -1812,11 +1802,6 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
struct vo_wayland_toplevel_pending_state *pending = &wl->pending_state;
struct vo_wayland_toplevel_pending_flags *flags = &pending->flags;

if (width < 0 || height < 0) {
MP_WARN(wl, "Compositor sent negative width/height values. Treating them as zero.\n");
width = height = 0;
}

pending->width = width;
pending->height = height;
*flags = (struct vo_wayland_toplevel_pending_flags){ 0 };
Expand Down Expand Up @@ -1994,8 +1979,8 @@ static void handle_configure_bounds(void *data, struct xdg_toplevel *xdg_topleve
int32_t width, int32_t height)
{
struct vo_wayland_state *wl = data;
wl->pending_state.bounded_width = handle_round(wl->scaling, width);
wl->pending_state.bounded_height = handle_round(wl->scaling, height);
wl->pending_state.bounded_width = width;
wl->pending_state.bounded_height = height;
}

static void handle_wm_capabilities(void *data, struct xdg_toplevel *xdg_toplevel,
Expand Down Expand Up @@ -2872,7 +2857,9 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id
output->wl = wl;
output->id = id;
output->scale = 1;
output->name = "";
output->name = talloc_strdup(output, "");
output->make = talloc_strdup(output, "");
output->model = talloc_strdup(output, "");

ver = MPMIN(ver, 4); /* Cap at 4 in case new events are added later. */
output->output = wl_registry_bind(reg, id, &wl_output_interface, ver);
Expand Down Expand Up @@ -3029,18 +3016,18 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id
static void registry_handle_remove(void *data, struct wl_registry *reg, uint32_t id)
{
struct vo_wayland_state *wl = data;
struct vo_wayland_output *output, *output_tmp;
wl_list_for_each_safe(output, output_tmp, &wl->output_list, link) {
struct vo_wayland_output *output;
wl_list_for_each(output, &wl->output_list, link) {
if (output->id == id) {
if (output->has_surface || wl->current_output == output)
update_surface_outputs(wl, output->output, false);
remove_output(output);
if (wl_list_length(&wl->output_list) == 0)
wl->current_output = NULL;
goto ack_global_remove;
}
}

struct vo_wayland_seat *seat, *seat_tmp;
wl_list_for_each_safe(seat, seat_tmp, &wl->seat_list, link) {
struct vo_wayland_seat *seat;
wl_list_for_each(seat, &wl->seat_list, link) {
if (seat->id == id) {
remove_seat(seat);
goto ack_global_remove;
Expand Down Expand Up @@ -3215,14 +3202,16 @@ static bool check_for_resize(struct vo_wayland_state *wl, int edge_pixels,
*edges = 0;

edge_pixels = handle_round(wl->scaling, edge_pixels);
if (pos[0] < edge_pixels)
if (pos[0] < edge_pixels) {
*edges |= XDG_TOPLEVEL_RESIZE_EDGE_LEFT;
if (pos[0] >= (mp_rect_w(wl->geometry) - edge_pixels))
} else if (pos[0] >= (mp_rect_w(wl->geometry) - edge_pixels)) {
*edges |= XDG_TOPLEVEL_RESIZE_EDGE_RIGHT;
if (pos[1] < edge_pixels)
}
if (pos[1] < edge_pixels) {
*edges |= XDG_TOPLEVEL_RESIZE_EDGE_TOP;
if (pos[1] >= (mp_rect_h(wl->geometry) - edge_pixels))
} else if (pos[1] >= (mp_rect_h(wl->geometry) - edge_pixels)) {
*edges |= XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM;
}

return *edges != 0;
}
Expand Down Expand Up @@ -3564,9 +3553,7 @@ static void remove_output(struct vo_wayland_output *out)
MP_VERBOSE(out->wl, "Deregistering output %s %s (%s) (0x%x)\n", out->make,
out->model, out->name, out->id);
wl_list_remove(&out->link);
wl_output_destroy(out->output);
talloc_free(out->make);
talloc_free(out->model);
MP_WL_RELEASE_OR_DESTROY(wl_output, out->output, WL_OUTPUT_RELEASE_SINCE_VERSION);
talloc_free(out);
}

Expand Down Expand Up @@ -3631,18 +3618,11 @@ static void remove_seat(struct vo_wayland_seat *seat)
wl_list_remove(&seat->link);
if (seat == seat->wl->last_button_seat)
seat->wl->last_button_seat = NULL;
if (seat->keyboard)
wl_keyboard_destroy(seat->keyboard);
if (seat->pointer)
wl_pointer_destroy(seat->pointer);
if (seat->touch)
wl_touch_destroy(seat->touch);
seat_handle_caps(seat, seat->seat, 0);
if (seat->data_device)
wl_data_device_destroy(seat->data_device);
wl_data_device_release(seat->data_device);
if (seat->text_input)
zwp_text_input_v3_destroy(seat->text_input->text_input);
if (seat->cursor_shape_device)
wp_cursor_shape_device_v1_destroy(seat->cursor_shape_device);
if (seat->xkb_keymap)
xkb_keymap_unref(seat->xkb_keymap);
if (seat->xkb_state)
Expand Down Expand Up @@ -3670,7 +3650,7 @@ static void remove_seat(struct vo_wayland_seat *seat)
if (seat->data_source)
wl_data_source_destroy(seat->data_source);

wl_seat_destroy(seat->seat);
MP_WL_RELEASE_OR_DESTROY(wl_seat, seat->seat, WL_SEAT_RELEASE_SINCE_VERSION);
talloc_free(seat);
}

Expand Down Expand Up @@ -3991,8 +3971,8 @@ static void set_geometry(struct vo_wayland_state *wl, bool resize)
struct vo_win_geometry geo;
struct mp_rect screenrc = wl->current_output->geometry;
struct m_geometry bounds = {
.w = wl->bounded_width,
.h = wl->bounded_height,
.w = handle_round(wl->scaling, wl->bounded_width),
.h = handle_round(wl->scaling, wl->bounded_height),
.wh_valid = opts->wl_configure_bounds == 1 ||
(opts->wl_configure_bounds == -1 && !autofit_or_geometry),
};
Expand Down Expand Up @@ -4974,7 +4954,7 @@ void vo_wayland_uninit(struct vo *vo)
if (wl->shm)
wl_shm_destroy(wl->shm);

#ifdef WL_FIXES_DESTROY
#ifdef WL_FIXES_ACK_GLOBAL_REMOVE
if (wl->fixes)
wl_fixes_destroy(wl->fixes);
#endif
Expand Down
3 changes: 3 additions & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "vo.h"
#include "xdg-activation-v1.h"

#define MP_WL_RELEASE_OR_DESTROY(type, object, since) \
(type##_get_version(object) >= (since) ? type##_release : type##_destroy)(object)

struct compositor_format;
struct vo_wayland_seat;
struct vo_wayland_tranche;
Expand Down
Loading