options: move all wayland specific options to vo_opts

Unlike most other platforming backends, wayland has its own specific
sub_options struct. 027ca4fb85 originally
introduced this and some more options were added later, but in
retrospect it's an unneccesary complication. There are already x11,
and windows-specific options within vo_opts. In fact, there actually is
a wayland one in there already as well (wayland-content-type) so it's
split btween two places. The wayland code already has to handle vo_opts
and it is already handles callbacks if needed. There is no advantage to
having a separate wayland-specific sub_options struct which is stuck
with whatever you set at init time.

So solve everything by deleting the old sub_options struct, moving it to
vo_opts and make some minor option naming changes for clarity (i.e.
adding a 'wl_' in front of the name). This simplifies the wayland common
code and also makes it have more functionality since you get runtime
updates for free.
This commit is contained in:
Dudemanguy 2024-07-23 18:22:50 -05:00
parent bde7cac447
commit 3c7b6db205
8 changed files with 96 additions and 116 deletions

View File

@ -194,8 +194,16 @@ static const m_option_t mp_vo_opt_list[] = {
{"x11-wid-title", OPT_BOOL(x11_wid_title)}, {"x11-wid-title", OPT_BOOL(x11_wid_title)},
#endif #endif
#if HAVE_WAYLAND #if HAVE_WAYLAND
{"wayland-content-type", OPT_CHOICE(content_type, {"auto", -1}, {"none", 0}, {"wayland-configure-bounds", OPT_CHOICE(wl_configure_bounds,
{"auto", -1}, {"no", 0}, {"yes", 1})},
{"wayland-content-type", OPT_CHOICE(wl_content_type, {"auto", -1}, {"none", 0},
{"photo", 1}, {"video", 2}, {"game", 3})}, {"photo", 1}, {"video", 2}, {"game", 3})},
{"wayland-disable-vsync", OPT_BOOL(wl_disable_vsync)},
{"wayland-edge-pixels-pointer", OPT_INT(wl_edge_pixels_pointer),
M_RANGE(0, INT_MAX)},
{"wayland-edge-pixels-touch", OPT_INT(wl_edge_pixels_touch),
M_RANGE(0, INT_MAX)},
{"wayland-present", OPT_BOOL(wl_present)},
#endif #endif
#if HAVE_WIN32_DESKTOP #if HAVE_WIN32_DESKTOP
// For old MinGW-w64 compatibility // For old MinGW-w64 compatibility
@ -250,11 +258,15 @@ const struct m_sub_options vo_sub_opts = {
.border = true, .border = true,
.title_bar = true, .title_bar = true,
.appid = "mpv", .appid = "mpv",
.content_type = -1,
.WinID = -1, .WinID = -1,
.window_scale = 1.0, .window_scale = 1.0,
.x11_bypass_compositor = 2, .x11_bypass_compositor = 2,
.x11_present = 1, .x11_present = 1,
.wl_configure_bounds = -1,
.wl_content_type = -1,
.wl_edge_pixels_pointer = 16,
.wl_edge_pixels_touch = 32,
.wl_present = true,
.mmcss_profile = "Playback", .mmcss_profile = "Playback",
.ontop_level = -1, .ontop_level = -1,
.timing_offset = 0.050, .timing_offset = 0.050,
@ -928,10 +940,6 @@ static const m_option_t mp_opts[] = {
{"", OPT_SUBSTRUCT(drm_opts, drm_conf)}, {"", OPT_SUBSTRUCT(drm_opts, drm_conf)},
#endif #endif
#if HAVE_WAYLAND
{"", OPT_SUBSTRUCT(wayland_opts, wayland_conf)},
#endif
#if HAVE_GL_WIN32 #if HAVE_GL_WIN32
{"", OPT_SUBSTRUCT(wingl_opts, wingl_conf)}, {"", OPT_SUBSTRUCT(wingl_opts, wingl_conf)},
#endif #endif

View File

@ -28,7 +28,6 @@ typedef struct mp_vo_opts {
char *fsscreen_name; char *fsscreen_name;
char *winname; char *winname;
char *appid; char *appid;
int content_type;
int x11_netwm; int x11_netwm;
int x11_bypass_compositor; int x11_bypass_compositor;
int x11_present; int x11_present;
@ -36,6 +35,13 @@ typedef struct mp_vo_opts {
bool cursor_passthrough; bool cursor_passthrough;
bool native_keyrepeat; bool native_keyrepeat;
int wl_configure_bounds;
int wl_content_type;
bool wl_disable_vsync;
int wl_edge_pixels_pointer;
int wl_edge_pixels_touch;
bool wl_present;
float panscan; float panscan;
float zoom; float zoom;
float pan_x, pan_y; float pan_x, pan_y;
@ -381,7 +387,6 @@ typedef struct MPOpts {
struct d3d11va_opts *d3d11va_opts; struct d3d11va_opts *d3d11va_opts;
struct macos_opts *macos_opts; struct macos_opts *macos_opts;
struct drm_opts *drm_opts; struct drm_opts *drm_opts;
struct wayland_opts *wayland_opts;
struct wingl_opts *wingl_opts; struct wingl_opts *wingl_opts;
struct cuda_opts *cuda_opts; struct cuda_opts *cuda_opts;
struct dvd_opts *dvd_opts; struct dvd_opts *dvd_opts;

View File

@ -69,7 +69,7 @@ static void wayland_egl_swap_buffers(struct ra_ctx *ctx)
eglSwapBuffers(p->egl_display, p->egl_surface); eglSwapBuffers(p->egl_display, p->egl_surface);
if (!wl->opts->disable_vsync) if (!wl->opts->wl_disable_vsync)
vo_wayland_wait_frame(wl); vo_wayland_wait_frame(wl);
if (wl->use_present) if (wl->use_present)

View File

@ -505,7 +505,7 @@ static void resize(struct vo *vo)
struct mp_rect src; struct mp_rect src;
struct mp_rect dst; struct mp_rect dst;
struct mp_vo_opts *vo_opts = wl->vo_opts; struct mp_vo_opts *opts = wl->opts;
const int width = mp_rect_w(wl->geometry); const int width = mp_rect_w(wl->geometry);
const int height = mp_rect_h(wl->geometry); const int height = mp_rect_h(wl->geometry);
@ -529,8 +529,8 @@ static void resize(struct vo *vo)
lround(window_h / wl->scaling_factor)); lround(window_h / wl->scaling_factor));
//now we restore pan for video viewport calculation //now we restore pan for video viewport calculation
vo->opts->pan_x = vo_opts->pan_x; vo->opts->pan_x = opts->pan_x;
vo->opts->pan_y = vo_opts->pan_y; vo->opts->pan_y = opts->pan_y;
vo_get_src_dst_rects(vo, &src, &dst, &p->screen_osd_res); vo_get_src_dst_rects(vo, &src, &dst, &p->screen_osd_res);
wp_viewport_set_destination(wl->video_viewport, lround(mp_rect_w(dst) / wl->scaling_factor), wp_viewport_set_destination(wl->video_viewport, lround(mp_rect_w(dst) / wl->scaling_factor),
lround(mp_rect_h(dst) / wl->scaling_factor)); lround(mp_rect_h(dst) / wl->scaling_factor));
@ -643,7 +643,7 @@ static void flip_page(struct vo *vo)
wl_surface_commit(wl->osd_surface); wl_surface_commit(wl->osd_surface);
wl_surface_commit(wl->surface); wl_surface_commit(wl->surface);
if (!wl->opts->disable_vsync) if (!wl->opts->wl_disable_vsync)
vo_wayland_wait_frame(wl); vo_wayland_wait_frame(wl);
if (wl->use_present) if (wl->use_present)

View File

@ -299,7 +299,7 @@ static void flip_page(struct vo *vo)
vo->dheight); vo->dheight);
wl_surface_commit(wl->surface); wl_surface_commit(wl->surface);
if (!wl->opts->disable_vsync) if (!wl->opts->wl_disable_vsync)
vo_wayland_wait_frame(wl); vo_wayland_wait_frame(wl);
if (wl->use_present) if (wl->use_present)

View File

@ -36,7 +36,7 @@ static void wayland_vk_swap_buffers(struct ra_ctx *ctx)
{ {
struct vo_wayland_state *wl = ctx->vo->wl; struct vo_wayland_state *wl = ctx->vo->wl;
if (!wl->opts->disable_vsync) if (!wl->opts->wl_disable_vsync)
vo_wayland_wait_frame(wl); vo_wayland_wait_frame(wl);
if (wl->use_present) if (wl->use_present)

View File

@ -137,28 +137,6 @@ static const struct mp_keymap keymap[] = {
{0, 0} {0, 0}
}; };
#define OPT_BASE_STRUCT struct wayland_opts
const struct m_sub_options wayland_conf = {
.opts = (const struct m_option[]) {
{"wayland-configure-bounds", OPT_CHOICE(configure_bounds,
{"auto", -1}, {"no", 0}, {"yes", 1})},
{"wayland-disable-vsync", OPT_BOOL(disable_vsync)},
{"wayland-edge-pixels-pointer", OPT_INT(edge_pixels_pointer),
M_RANGE(0, INT_MAX)},
{"wayland-edge-pixels-touch", OPT_INT(edge_pixels_touch),
M_RANGE(0, INT_MAX)},
{"wayland-present", OPT_BOOL(present)},
{0},
},
.size = sizeof(struct wayland_opts),
.defaults = &(struct wayland_opts) {
.configure_bounds = -1,
.edge_pixels_pointer = 16,
.edge_pixels_touch = 32,
.present = true,
},
};
struct vo_wayland_feedback_pool { struct vo_wayland_feedback_pool {
struct wp_presentation_feedback **fback; struct wp_presentation_feedback **fback;
struct vo_wayland_state *wl; struct vo_wayland_state *wl;
@ -322,7 +300,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
enum xdg_toplevel_resize_edge edges; enum xdg_toplevel_resize_edge edges;
if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) && if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) &&
!wl->locked_size && (button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN) && !wl->locked_size && (button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN) &&
!wl->vo_opts->border && check_for_resize(wl, wl->opts->edge_pixels_pointer, &edges)) !wl->opts->border && check_for_resize(wl, wl->opts->wl_edge_pixels_pointer, &edges))
{ {
// Implement an edge resize zone if there are no decorations // Implement an edge resize zone if there are no decorations
xdg_toplevel_resize(wl->xdg_toplevel, s->seat, serial, edges); xdg_toplevel_resize(wl->xdg_toplevel, s->seat, serial, edges);
@ -443,7 +421,7 @@ static void touch_handle_down(void *data, struct wl_touch *wl_touch,
enum xdg_toplevel_resize_edge edge; enum xdg_toplevel_resize_edge edge;
if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) && if (!mp_input_test_dragging(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y) &&
!wl->locked_size && check_for_resize(wl, wl->opts->edge_pixels_touch, &edge)) !wl->locked_size && check_for_resize(wl, wl->opts->wl_edge_pixels_touch, &edge))
{ {
xdg_toplevel_resize(wl->xdg_toplevel, s->seat, serial, edge); xdg_toplevel_resize(wl->xdg_toplevel, s->seat, serial, edge);
} else { } else {
@ -611,7 +589,7 @@ static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keybo
{ {
struct vo_wayland_seat *s = data; struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl; struct vo_wayland_state *wl = s->wl;
if (wl->vo_opts->native_keyrepeat) if (wl->opts->native_keyrepeat)
mp_input_set_repeat_info(wl->vo->input_ctx, rate, delay); mp_input_set_repeat_info(wl->vo->input_ctx, rate, delay);
} }
@ -672,7 +650,7 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer,
struct vo_wayland_seat *s = data; struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl; struct vo_wayland_state *wl = s->wl;
int score = mp_event_get_mime_type_score(wl->vo->input_ctx, mime_type); int score = mp_event_get_mime_type_score(wl->vo->input_ctx, mime_type);
if (score > wl->dnd_mime_score && wl->vo_opts->drag_and_drop != -2) { if (score > wl->dnd_mime_score && wl->opts->drag_and_drop != -2) {
wl->dnd_mime_score = score; wl->dnd_mime_score = score;
if (wl->dnd_mime_type) if (wl->dnd_mime_type)
talloc_free(wl->dnd_mime_type); talloc_free(wl->dnd_mime_type);
@ -689,9 +667,9 @@ static void data_offer_action(void *data, struct wl_data_offer *wl_data_offer, u
{ {
struct vo_wayland_seat *s = data; struct vo_wayland_seat *s = data;
struct vo_wayland_state *wl = s->wl; struct vo_wayland_state *wl = s->wl;
if (dnd_action && wl->vo_opts->drag_and_drop != -2) { if (dnd_action && wl->opts->drag_and_drop != -2) {
if (wl->vo_opts->drag_and_drop >= 0) { if (wl->opts->drag_and_drop >= 0) {
wl->dnd_action = wl->vo_opts->drag_and_drop; wl->dnd_action = wl->opts->drag_and_drop;
} else { } else {
wl->dnd_action = dnd_action & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY ? wl->dnd_action = dnd_action & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY ?
DND_REPLACE : DND_APPEND; DND_REPLACE : DND_APPEND;
@ -737,7 +715,7 @@ static void data_device_handle_enter(void *data, struct wl_data_device *wl_ddev,
return; return;
} }
if (wl->vo_opts->drag_and_drop != -2) { if (wl->opts->drag_and_drop != -2) {
wl_data_offer_set_actions(id, WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | wl_data_offer_set_actions(id, WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY |
WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE, WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE,
WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY); WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
@ -759,7 +737,7 @@ static void data_device_handle_leave(void *data, struct wl_data_device *wl_ddev)
wl->dnd_offer = NULL; wl->dnd_offer = NULL;
} }
if (wl->vo_opts->drag_and_drop != -2) { if (wl->opts->drag_and_drop != -2) {
MP_VERBOSE(wl, "Releasing DND offer with mime type %s\n", wl->dnd_mime_type); MP_VERBOSE(wl, "Releasing DND offer with mime type %s\n", wl->dnd_mime_type);
if (wl->dnd_mime_type) if (wl->dnd_mime_type)
TA_FREEP(&wl->dnd_mime_type); TA_FREEP(&wl->dnd_mime_type);
@ -787,7 +765,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_ddev)
return; return;
} }
if (wl->vo_opts->drag_and_drop != -2) { if (wl->opts->drag_and_drop != -2) {
MP_VERBOSE(wl, "Receiving DND offer with mime %s\n", wl->dnd_mime_type); MP_VERBOSE(wl, "Receiving DND offer with mime %s\n", wl->dnd_mime_type);
wl_data_offer_receive(wl->dnd_offer, wl->dnd_mime_type, pipefd[1]); wl_data_offer_receive(wl->dnd_offer, wl->dnd_mime_type, pipefd[1]);
} }
@ -1036,7 +1014,7 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
int32_t width, int32_t height, struct wl_array *states) int32_t width, int32_t height, struct wl_array *states)
{ {
struct vo_wayland_state *wl = data; struct vo_wayland_state *wl = data;
struct mp_vo_opts *vo_opts = wl->vo_opts; struct mp_vo_opts *opts = wl->opts;
struct mp_rect old_geometry = wl->geometry; struct mp_rect old_geometry = wl->geometry;
if (width < 0 || height < 0) { if (width < 0 || height < 0) {
@ -1046,8 +1024,8 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
if (!wl->geometry_configured) { if (!wl->geometry_configured) {
/* Save initial window size if the compositor gives us a hint here. */ /* Save initial window size if the compositor gives us a hint here. */
bool autofit_or_geometry = vo_opts->geometry.wh_valid || vo_opts->autofit.wh_valid || bool autofit_or_geometry = opts->geometry.wh_valid || opts->autofit.wh_valid ||
vo_opts->autofit_larger.wh_valid || vo_opts->autofit_smaller.wh_valid; opts->autofit_larger.wh_valid || opts->autofit_smaller.wh_valid;
if (width && height && !autofit_or_geometry) { if (width && height && !autofit_or_geometry) {
wl->initial_size_hint = true; wl->initial_size_hint = true;
wl->window_size = (struct mp_rect){0, 0, width, height}; wl->window_size = (struct mp_rect){0, 0, width, height};
@ -1076,9 +1054,9 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
* minimized, but it may not have been minimized * minimized, but it may not have been minimized
* previously, so we can't detect the exact state. * previously, so we can't detect the exact state.
*/ */
vo_opts->window_minimized = false; opts->window_minimized = false;
m_config_cache_write_opt(wl->vo_opts_cache, m_config_cache_write_opt(wl->opts_cache,
&vo_opts->window_minimized); &opts->window_minimized);
break; break;
case XDG_TOPLEVEL_STATE_TILED_TOP: case XDG_TOPLEVEL_STATE_TILED_TOP:
case XDG_TOPLEVEL_STATE_TILED_LEFT: case XDG_TOPLEVEL_STATE_TILED_LEFT:
@ -1098,16 +1076,16 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
if (wl->hidden != is_suspended) if (wl->hidden != is_suspended)
wl->hidden = is_suspended; wl->hidden = is_suspended;
if (vo_opts->fullscreen != is_fullscreen) { if (opts->fullscreen != is_fullscreen) {
wl->state_change = wl->reconfigured; wl->state_change = wl->reconfigured;
vo_opts->fullscreen = is_fullscreen; opts->fullscreen = is_fullscreen;
m_config_cache_write_opt(wl->vo_opts_cache, &vo_opts->fullscreen); m_config_cache_write_opt(wl->opts_cache, &opts->fullscreen);
} }
if (vo_opts->window_maximized != is_maximized) { if (opts->window_maximized != is_maximized) {
wl->state_change = wl->reconfigured; wl->state_change = wl->reconfigured;
vo_opts->window_maximized = is_maximized; opts->window_maximized = is_maximized;
m_config_cache_write_opt(wl->vo_opts_cache, &vo_opts->window_maximized); m_config_cache_write_opt(wl->opts_cache, &opts->window_maximized);
} }
if (!is_tiled && wl->tiled) if (!is_tiled && wl->tiled)
@ -1242,7 +1220,7 @@ static void configure_decorations(void *data,
uint32_t mode) uint32_t mode)
{ {
struct vo_wayland_state *wl = data; struct vo_wayland_state *wl = data;
struct mp_vo_opts *opts = wl->vo_opts; struct mp_vo_opts *opts = wl->opts;
if (wl->requested_decoration && mode != wl->requested_decoration) { if (wl->requested_decoration && mode != wl->requested_decoration) {
MP_DBG(wl, MP_DBG(wl,
@ -1260,7 +1238,7 @@ static void configure_decorations(void *data,
MP_VERBOSE(wl, "Disabling server decorations\n"); MP_VERBOSE(wl, "Disabling server decorations\n");
} }
opts->border = mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; opts->border = mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
m_config_cache_write_opt(wl->vo_opts_cache, &opts->border); m_config_cache_write_opt(wl->opts_cache, &opts->border);
} }
static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = { static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
@ -1339,7 +1317,7 @@ static void frame_callback(void *data, struct wl_callback *callback, uint32_t ti
wl->frame_callback = wl_surface_frame(wl->callback_surface); wl->frame_callback = wl_surface_frame(wl->callback_surface);
wl_callback_add_listener(wl->frame_callback, &frame_listener, wl); wl_callback_add_listener(wl->frame_callback, &frame_listener, wl);
wl->use_present = wl->present_clock && wl->opts->present; wl->use_present = wl->present_clock && wl->opts->wl_present;
if (wl->use_present) { if (wl->use_present) {
struct wp_presentation_feedback *fback = wp_presentation_feedback(wl->presentation, wl->callback_surface); struct wp_presentation_feedback *fback = wp_presentation_feedback(wl->presentation, wl->callback_surface);
add_feedback(wl->fback_pool, fback); add_feedback(wl->fback_pool, fback);
@ -1571,12 +1549,12 @@ static const struct wl_registry_listener registry_listener = {
/* Static functions */ /* Static functions */
static void apply_keepaspect(struct vo_wayland_state *wl, int *width, int *height) static void apply_keepaspect(struct vo_wayland_state *wl, int *width, int *height)
{ {
if (!wl->vo_opts->keepaspect) if (!wl->opts->keepaspect)
return; return;
double scale_factor = (double)*width / wl->reduced_width; double scale_factor = (double)*width / wl->reduced_width;
*width = ceil(wl->reduced_width * scale_factor); *width = ceil(wl->reduced_width * scale_factor);
if (wl->vo_opts->keepaspect_window) if (wl->opts->keepaspect_window)
*height = ceil(wl->reduced_height * scale_factor); *height = ceil(wl->reduced_height * scale_factor);
} }
@ -1645,7 +1623,7 @@ static void check_dnd_fd(struct vo_wayland_state *wl)
static int check_for_resize(struct vo_wayland_state *wl, int edge_pixels, static int check_for_resize(struct vo_wayland_state *wl, int edge_pixels,
enum xdg_toplevel_resize_edge *edge) enum xdg_toplevel_resize_edge *edge)
{ {
if (wl->vo_opts->fullscreen || wl->vo_opts->window_maximized) if (wl->opts->fullscreen || wl->opts->window_maximized)
return 0; return 0;
int pos[2] = { wl->mouse_x, wl->mouse_y }; int pos[2] = { wl->mouse_x, wl->mouse_y };
@ -1736,7 +1714,7 @@ static void add_feedback(struct vo_wayland_feedback_pool *fback_pool,
static void do_minimize(struct vo_wayland_state *wl) static void do_minimize(struct vo_wayland_state *wl)
{ {
if (wl->vo_opts->window_minimized) if (wl->opts->window_minimized)
xdg_toplevel_set_minimized(wl->xdg_toplevel); xdg_toplevel_set_minimized(wl->xdg_toplevel);
} }
@ -1827,7 +1805,7 @@ static void guess_focus(struct vo_wayland_state *wl)
static struct vo_wayland_output *find_output(struct vo_wayland_state *wl) static struct vo_wayland_output *find_output(struct vo_wayland_state *wl)
{ {
int index = 0; int index = 0;
struct mp_vo_opts *opts = wl->vo_opts; struct mp_vo_opts *opts = wl->opts;
int screen_id = opts->fullscreen ? opts->fsscreen_id : opts->screen_id; int screen_id = opts->fullscreen ? opts->fsscreen_id : opts->screen_id;
char *screen_name = opts->fullscreen ? opts->fsscreen_name : opts->screen_name; char *screen_name = opts->fullscreen ? opts->fsscreen_name : opts->screen_name;
struct vo_wayland_output *output = NULL; struct vo_wayland_output *output = NULL;
@ -1936,7 +1914,7 @@ static void request_decoration_mode(struct vo_wayland_state *wl, uint32_t mode)
static void rescale_geometry(struct vo_wayland_state *wl, double old_scale) static void rescale_geometry(struct vo_wayland_state *wl, double old_scale)
{ {
if (!wl->vo_opts->hidpi_window_scale && !wl->locked_size) if (!wl->opts->hidpi_window_scale && !wl->locked_size)
return; return;
double factor = old_scale / wl->scaling; double factor = old_scale / wl->scaling;
@ -2019,10 +1997,10 @@ static void set_content_type(struct vo_wayland_state *wl)
if (!wl->content_type_manager) if (!wl->content_type_manager)
return; return;
// handle auto; // handle auto;
if (wl->vo_opts->content_type == -1) { if (wl->opts->wl_content_type == -1) {
wp_content_type_v1_set_content_type(wl->content_type, wl->current_content_type); wp_content_type_v1_set_content_type(wl->content_type, wl->current_content_type);
} else { } else {
wp_content_type_v1_set_content_type(wl->content_type, wl->vo_opts->content_type); wp_content_type_v1_set_content_type(wl->content_type, wl->opts->wl_content_type);
} }
} }
@ -2160,9 +2138,9 @@ static void set_window_bounds(struct vo_wayland_state *wl)
{ {
// If the user has set geometry/autofit and the option is auto, // If the user has set geometry/autofit and the option is auto,
// don't use these. // don't use these.
if (wl->opts->configure_bounds == -1 && (wl->vo_opts->geometry.wh_valid || if (wl->opts->wl_configure_bounds == -1 && (wl->opts->geometry.wh_valid ||
wl->vo_opts->autofit.wh_valid || wl->vo_opts->autofit_larger.wh_valid || wl->opts->autofit.wh_valid || wl->opts->autofit_larger.wh_valid ||
wl->vo_opts->autofit_smaller.wh_valid)) wl->opts->autofit_smaller.wh_valid))
{ {
return; return;
} }
@ -2230,10 +2208,10 @@ static int spawn_cursor(struct vo_wayland_state *wl)
static void toggle_fullscreen(struct vo_wayland_state *wl) static void toggle_fullscreen(struct vo_wayland_state *wl)
{ {
bool specific_screen = wl->vo_opts->fsscreen_id >= 0 || wl->vo_opts->fsscreen_name; bool specific_screen = wl->opts->fsscreen_id >= 0 || wl->opts->fsscreen_name;
if (wl->vo_opts->fullscreen && !specific_screen) { if (wl->opts->fullscreen && !specific_screen) {
xdg_toplevel_set_fullscreen(wl->xdg_toplevel, NULL); xdg_toplevel_set_fullscreen(wl->xdg_toplevel, NULL);
} else if (wl->vo_opts->fullscreen && specific_screen) { } else if (wl->opts->fullscreen && specific_screen) {
struct vo_wayland_output *output = find_output(wl); struct vo_wayland_output *output = find_output(wl);
xdg_toplevel_set_fullscreen(wl->xdg_toplevel, output->output); xdg_toplevel_set_fullscreen(wl->xdg_toplevel, output->output);
} else { } else {
@ -2244,7 +2222,7 @@ static void toggle_fullscreen(struct vo_wayland_state *wl)
static void toggle_maximized(struct vo_wayland_state *wl) static void toggle_maximized(struct vo_wayland_state *wl)
{ {
if (wl->vo_opts->window_maximized) { if (wl->opts->window_maximized) {
xdg_toplevel_set_maximized(wl->xdg_toplevel); xdg_toplevel_set_maximized(wl->xdg_toplevel);
} else { } else {
wl->state_change = wl->reconfigured; wl->state_change = wl->reconfigured;
@ -2254,7 +2232,7 @@ static void toggle_maximized(struct vo_wayland_state *wl)
static void update_app_id(struct vo_wayland_state *wl) static void update_app_id(struct vo_wayland_state *wl)
{ {
xdg_toplevel_set_app_id(wl->xdg_toplevel, wl->vo_opts->appid); xdg_toplevel_set_app_id(wl->xdg_toplevel, wl->opts->appid);
} }
static void update_output_scaling(struct vo_wayland_state *wl) static void update_output_scaling(struct vo_wayland_state *wl)
@ -2379,7 +2357,7 @@ int vo_wayland_allocate_memfd(struct vo *vo, size_t size)
bool vo_wayland_check_visible(struct vo *vo) bool vo_wayland_check_visible(struct vo *vo)
{ {
struct vo_wayland_state *wl = vo->wl; struct vo_wayland_state *wl = vo->wl;
bool render = !wl->hidden || wl->vo_opts->force_render; bool render = !wl->hidden || wl->opts->force_render;
wl->frame_wait = true; wl->frame_wait = true;
return render; return render;
} }
@ -2387,7 +2365,7 @@ bool vo_wayland_check_visible(struct vo *vo)
int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
{ {
struct vo_wayland_state *wl = vo->wl; struct vo_wayland_state *wl = vo->wl;
struct mp_vo_opts *opts = wl->vo_opts; struct mp_vo_opts *opts = wl->opts;
wl_display_dispatch_pending(wl->display); wl_display_dispatch_pending(wl->display);
switch (request) { switch (request) {
@ -2405,7 +2383,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
} }
case VOCTRL_VO_OPTS_CHANGED: { case VOCTRL_VO_OPTS_CHANGED: {
void *opt; void *opt;
while (m_config_cache_get_next_changed(wl->vo_opts_cache, &opt)) { while (m_config_cache_get_next_changed(wl->opts_cache, &opt)) {
if (opt == &opts->appid) if (opt == &opts->appid)
update_app_id(wl); update_app_id(wl);
if (opt == &opts->border) if (opt == &opts->border)
@ -2416,7 +2394,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
if (wl->xdg_toplevel_decoration) { if (wl->xdg_toplevel_decoration) {
int requested_border_mode = opts->border; int requested_border_mode = opts->border;
opts->border = !opts->border; opts->border = !opts->border;
m_config_cache_write_opt(wl->vo_opts_cache, m_config_cache_write_opt(wl->opts_cache,
&opts->border); &opts->border);
request_decoration_mode( request_decoration_mode(
wl, requested_border_mode ? wl, requested_border_mode ?
@ -2424,11 +2402,11 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
} else { } else {
opts->border = false; opts->border = false;
m_config_cache_write_opt(wl->vo_opts_cache, m_config_cache_write_opt(wl->opts_cache,
&wl->vo_opts->border); &wl->opts->border);
} }
} }
if (opt == &opts->content_type) if (opt == &opts->wl_content_type)
set_content_type(wl); set_content_type(wl);
if (opt == &opts->cursor_passthrough) if (opt == &opts->cursor_passthrough)
set_input_region(wl, opts->cursor_passthrough); set_input_region(wl, opts->cursor_passthrough);
@ -2462,7 +2440,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
} }
case VOCTRL_GET_UNFS_WINDOW_SIZE: { case VOCTRL_GET_UNFS_WINDOW_SIZE: {
int *s = arg; int *s = arg;
if (wl->vo_opts->window_maximized || wl->tiled) { if (wl->opts->window_maximized || wl->tiled) {
s[0] = mp_rect_w(wl->geometry); s[0] = mp_rect_w(wl->geometry);
s[1] = mp_rect_h(wl->geometry); s[1] = mp_rect_h(wl->geometry);
} else { } else {
@ -2477,13 +2455,13 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
wl->window_size.y0 = 0; wl->window_size.y0 = 0;
wl->window_size.x1 = s[0]; wl->window_size.x1 = s[0];
wl->window_size.y1 = s[1]; wl->window_size.y1 = s[1];
if (!wl->vo_opts->fullscreen && !wl->tiled) { if (!wl->opts->fullscreen && !wl->tiled) {
wl->state_change = true; wl->state_change = true;
if (wl->vo_opts->window_maximized) { if (wl->opts->window_maximized) {
xdg_toplevel_unset_maximized(wl->xdg_toplevel); xdg_toplevel_unset_maximized(wl->xdg_toplevel);
wl_display_dispatch_pending(wl->display); wl_display_dispatch_pending(wl->display);
/* Make sure the compositor let us unmaximize */ /* Make sure the compositor let us unmaximize */
if (wl->vo_opts->window_maximized) if (wl->opts->window_maximized)
return VO_TRUE; return VO_TRUE;
} }
wl->geometry = wl->window_size; wl->geometry = wl->window_size;
@ -2564,9 +2542,9 @@ bool vo_wayland_init(struct vo *vo)
.display_fd = -1, .display_fd = -1,
.dnd_fd = -1, .dnd_fd = -1,
.cursor_visible = true, .cursor_visible = true,
.vo_opts_cache = m_config_cache_alloc(wl, vo->global, &vo_sub_opts), .opts_cache = m_config_cache_alloc(wl, vo->global, &vo_sub_opts),
}; };
wl->vo_opts = wl->vo_opts_cache->opts; wl->opts = wl->opts_cache->opts;
bool using_dmabuf_wayland = !strcmp(wl->vo->driver->name, "dmabuf-wayland"); bool using_dmabuf_wayland = !strcmp(wl->vo->driver->name, "dmabuf-wayland");
wl_list_init(&wl->output_list); wl_list_init(&wl->output_list);
@ -2664,7 +2642,7 @@ bool vo_wayland_init(struct vo *vo)
wl->fback_pool->len = VO_MAX_SWAPCHAIN_DEPTH; wl->fback_pool->len = VO_MAX_SWAPCHAIN_DEPTH;
wl->fback_pool->fback = talloc_zero_array(wl->fback_pool, struct wp_presentation_feedback *, wl->fback_pool->fback = talloc_zero_array(wl->fback_pool, struct wp_presentation_feedback *,
wl->fback_pool->len); wl->fback_pool->len);
wl->present = mp_present_initialize(wl, wl->vo_opts, VO_MAX_SWAPCHAIN_DEPTH); wl->present = mp_present_initialize(wl, wl->opts, VO_MAX_SWAPCHAIN_DEPTH);
} else { } else {
MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n", MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n",
wp_presentation_interface.name); wp_presentation_interface.name);
@ -2674,13 +2652,13 @@ bool vo_wayland_init(struct vo *vo)
wl->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(wl->xdg_decoration_manager, wl->xdg_toplevel); wl->xdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(wl->xdg_decoration_manager, wl->xdg_toplevel);
zxdg_toplevel_decoration_v1_add_listener(wl->xdg_toplevel_decoration, &decoration_listener, wl); zxdg_toplevel_decoration_v1_add_listener(wl->xdg_toplevel_decoration, &decoration_listener, wl);
request_decoration_mode( request_decoration_mode(
wl, wl->vo_opts->border ? wl, wl->opts->border ?
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE :
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
} else { } else {
wl->vo_opts->border = false; wl->opts->border = false;
m_config_cache_write_opt(wl->vo_opts_cache, m_config_cache_write_opt(wl->opts_cache,
&wl->vo_opts->border); &wl->opts->border);
MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n", MP_VERBOSE(wl, "Compositor doesn't support the %s protocol!\n",
zxdg_decoration_manager_v1_interface.name); zxdg_decoration_manager_v1_interface.name);
} }
@ -2690,7 +2668,6 @@ bool vo_wayland_init(struct vo *vo)
zwp_idle_inhibit_manager_v1_interface.name); zwp_idle_inhibit_manager_v1_interface.name);
} }
wl->opts = mp_get_config_group(wl, wl->vo->global, &wayland_conf);
wl->display_fd = wl_display_get_fd(wl->display); wl->display_fd = wl_display_get_fd(wl->display);
update_app_id(wl); update_app_id(wl);
@ -2727,29 +2704,29 @@ bool vo_wayland_reconfig(struct vo *vo)
wl->pending_vo_events |= VO_EVENT_DPI; wl->pending_vo_events |= VO_EVENT_DPI;
} }
if (wl->vo_opts->auto_window_resize || !wl->geometry_configured) if (wl->opts->auto_window_resize || !wl->geometry_configured)
set_geometry(wl, false); set_geometry(wl, false);
if (wl->geometry_configured && wl->vo_opts->auto_window_resize) if (wl->geometry_configured && wl->opts->auto_window_resize)
wl->reconfigured = true; wl->reconfigured = true;
if (wl->opts->configure_bounds) if (wl->opts->wl_configure_bounds)
set_window_bounds(wl); set_window_bounds(wl);
if (wl->vo_opts->cursor_passthrough) if (wl->opts->cursor_passthrough)
set_input_region(wl, true); set_input_region(wl, true);
if (!wl->geometry_configured || !wl->locked_size) if (!wl->geometry_configured || !wl->locked_size)
wl->geometry = wl->window_size; wl->geometry = wl->window_size;
if (!wl->geometry_configured) { if (!wl->geometry_configured) {
if (wl->vo_opts->fullscreen) if (wl->opts->fullscreen)
toggle_fullscreen(wl); toggle_fullscreen(wl);
if (wl->vo_opts->window_maximized) if (wl->opts->window_maximized)
toggle_maximized(wl); toggle_maximized(wl);
if (wl->vo_opts->window_minimized) if (wl->opts->window_minimized)
do_minimize(wl); do_minimize(wl);
wl->geometry_configured = true; wl->geometry_configured = true;
} }

View File

@ -30,21 +30,11 @@ typedef struct {
uint64_t modifier; uint64_t modifier;
} wayland_format; } wayland_format;
struct wayland_opts {
int configure_bounds;
int content_type;
bool disable_vsync;
int edge_pixels_pointer;
int edge_pixels_touch;
bool present;
};
struct vo_wayland_state { struct vo_wayland_state {
struct m_config_cache *vo_opts_cache; struct m_config_cache *opts_cache;
struct mp_log *log; struct mp_log *log;
struct mp_vo_opts *vo_opts; struct mp_vo_opts *opts;
struct vo *vo; struct vo *vo;
struct wayland_opts *opts;
struct wl_callback *frame_callback; struct wl_callback *frame_callback;
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct wl_subcompositor *subcompositor; struct wl_subcompositor *subcompositor;