summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2019-11-30 10:00:49 +0800
committerPhilip Langdale <github.philipl@overt.org>2019-12-01 09:39:51 +0800
commit61b8e1d436976b0d13805728c4b7f3ccd8061c90 (patch)
tree9671489932c7a4a9df5b0315fe30b6732fb3e150
parent78f1629a539cc14a598831a73c59c3763c074094 (diff)
downloadmpv-61b8e1d436976b0d13805728c4b7f3ccd8061c90.tar.bz2
mpv-61b8e1d436976b0d13805728c4b7f3ccd8061c90.tar.xz
wayland: update Maximize and Minimize handling to use new options
I wanted to get this done quickly as I introduced the new VOCTRL behaviour for minimize and maximize and it was immediately made legacy, so best to purge it before anyone gets confused. I did not sort out fullscreen as that's more involved and not something I've educated myself about yet. But I did replace the VOCTRL_FULLSCREEN usage with the new option change mechanism as that seemed simple enough.
-rw-r--r--player/command.c4
-rw-r--r--video/out/vo.h3
-rw-r--r--video/out/wayland_common.c62
-rw-r--r--video/out/wayland_common.h4
4 files changed, 43 insertions, 30 deletions
diff --git a/player/command.c b/player/command.c
index cf85858f47..505c092c27 100644
--- a/player/command.c
+++ b/player/command.c
@@ -6151,10 +6151,6 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
vo_control(mpctx->video_out, VOCTRL_BORDER, 0);
if (opt_ptr == &opts->vo->all_workspaces)
vo_control(mpctx->video_out, VOCTRL_ALL_WORKSPACES, 0);
- if (opt_ptr == &opts->vo->window_minimized)
- vo_control(mpctx->video_out, VOCTRL_MINIMIZE, 0);
- if (opt_ptr == &opts->vo->window_maximized)
- vo_control(mpctx->video_out, VOCTRL_MAXIMIZE, 0);
}
if (opt_ptr == &opts->vo->taskbar_progress)
diff --git a/video/out/vo.h b/video/out/vo.h
index 8ff99db07d..94582cd8e5 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -92,8 +92,6 @@ enum mp_voctrl {
VOCTRL_ALL_WORKSPACES,
VOCTRL_GET_FULLSCREEN,
VOCTRL_GET_WIN_STATE, // int* (VO_WIN_STATE_* flags)
- VOCTRL_MAXIMIZE,
- VOCTRL_MINIMIZE,
VOCTRL_UPDATE_WINDOW_TITLE, // char*
VOCTRL_UPDATE_PLAYBACK_STATE, // struct voctrl_playback_state*
@@ -136,7 +134,6 @@ enum mp_voctrl {
// VOCTRL_GET_WIN_STATE (legacy, ignored)
#define VO_WIN_STATE_MINIMIZED (1 << 0)
-#define VO_WIN_STATE_MAXIMIZED (1 << 1)
#define VO_TRUE true
#define VO_FALSE false
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index f66016dcbb..3d5d7fd5d4 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -174,7 +174,7 @@ static void window_move(struct vo_wayland_state *wl, uint32_t serial)
static int check_for_resize(struct vo_wayland_state *wl, wl_fixed_t x_w, wl_fixed_t y_w,
int edge_pixels, enum xdg_toplevel_resize_edge *edge)
{
- if (wl->touch_entries || wl->fullscreen || wl->maximized)
+ if (wl->touch_entries || wl->fullscreen || wl->vo_opts->window_maximized)
return 0;
int pos[2] = { wl_fixed_to_double(x_w), wl_fixed_to_double(y_w) };
@@ -547,7 +547,7 @@ static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keybo
int32_t rate, int32_t delay)
{
struct vo_wayland_state *wl = data;
- if (wl->vo->opts->native_keyrepeat)
+ if (wl->vo_opts->native_keyrepeat)
mp_input_set_repeat_info(wl->vo->input_ctx, rate, delay);
}
@@ -947,10 +947,11 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
int32_t width, int32_t height, struct wl_array *states)
{
struct vo_wayland_state *wl = data;
+ struct mp_vo_opts *vo_opts = wl->vo_opts;
struct mp_rect old_geometry = wl->geometry;
int prev_fs_state = wl->fullscreen;
- wl->maximized = false;
+ bool is_maximized = false;
wl->fullscreen = false;
enum xdg_toplevel_state *state;
wl_array_for_each(state, states) {
@@ -962,25 +963,36 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
wl->pending_vo_events |= VO_EVENT_LIVE_RESIZING;
break;
case XDG_TOPLEVEL_STATE_ACTIVATED:
+ /*
+ * If we get an ACTIVATED state, we know it cannot be
+ * minimised, but it may not have been minimized
+ * previously, so we can't detect the exact state.
+ */
+ vo_opts->window_minimized = false;
+ m_config_cache_write_opt(wl->vo_opts_cache,
+ &vo_opts->window_minimized);
break;
case XDG_TOPLEVEL_STATE_TILED_TOP:
case XDG_TOPLEVEL_STATE_TILED_LEFT:
case XDG_TOPLEVEL_STATE_TILED_RIGHT:
case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
case XDG_TOPLEVEL_STATE_MAXIMIZED:
- wl->maximized = true;
+ is_maximized = true;
break;
}
}
+ vo_opts->window_maximized = is_maximized;
+ m_config_cache_write_opt(wl->vo_opts_cache, &vo_opts->window_maximized);
+
if (prev_fs_state != wl->fullscreen)
wl->pending_vo_events |= VO_EVENT_FULLSCREEN_STATE;
if (!(wl->pending_vo_events & VO_EVENT_LIVE_RESIZING))
vo_query_and_reset_events(wl->vo, VO_EVENT_LIVE_RESIZING);
if (width > 0 && height > 0) {
- if (!wl->fullscreen && !wl->maximized) {
- if (wl->vo->opts->keepaspect && wl->vo->opts->keepaspect_window) {
+ if (!wl->fullscreen && !is_maximized) {
+ if (wl->vo_opts->keepaspect && wl->vo_opts->keepaspect_window) {
if (width > height)
width = height * wl->aspect_ratio;
else
@@ -1065,7 +1077,9 @@ int vo_wayland_init(struct vo *vo)
.dnd_fd = -1,
.cursor_visible = true,
.prev_fullscreen = vo->opts->fullscreen,
+ .vo_opts_cache = m_config_cache_alloc(wl, vo->global, &vo_sub_opts),
};
+ wl->vo_opts = wl->vo_opts_cache->opts;
wl_list_init(&wl->output_list);
@@ -1274,7 +1288,7 @@ int vo_wayland_reconfig(struct vo *vo)
vo_calc_window_geometry(vo, &screenrc, &geo);
vo_apply_window_geometry(vo, &geo);
- if (!wl->configured || !wl->maximized) {
+ if (!wl->configured || !wl->vo_opts->window_maximized) {
wl->geometry.x0 = 0;
wl->geometry.y0 = 0;
wl->geometry.x1 = vo->dwidth / wl->scaling;
@@ -1346,10 +1360,10 @@ static int toggle_maximized(struct vo_wayland_state *wl)
{
if (!wl->xdg_toplevel)
return VO_NOTAVAIL;
- if (wl->maximized)
- xdg_toplevel_unset_maximized(wl->xdg_toplevel);
- else
+ if (wl->vo_opts->window_maximized)
xdg_toplevel_set_maximized(wl->xdg_toplevel);
+ else
+ xdg_toplevel_unset_maximized(wl->xdg_toplevel);
return VO_TRUE;
}
@@ -1357,7 +1371,8 @@ static int do_minimize(struct vo_wayland_state *wl)
{
if (!wl->xdg_toplevel)
return VO_NOTAVAIL;
- xdg_toplevel_set_minimized(wl->xdg_toplevel);
+ if (wl->vo_opts->window_minimized)
+ xdg_toplevel_set_minimized(wl->xdg_toplevel);
return VO_TRUE;
}
@@ -1430,6 +1445,7 @@ static char **get_displays_spanned(struct vo_wayland_state *wl)
int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
{
struct vo_wayland_state *wl = vo->wl;
+ struct mp_vo_opts *opts = wl->vo_opts;
wl_display_dispatch_pending(wl->display);
switch (request) {
@@ -1439,6 +1455,18 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
wl->pending_vo_events = 0;
return VO_TRUE;
}
+ case VOCTRL_VO_OPTS_CHANGED: {
+ void *opt;
+ while (m_config_cache_get_next_changed(wl->vo_opts_cache, &opt)) {
+ if (opt == &opts->fullscreen)
+ return toggle_fullscreen(wl);
+ if (opt == &opts->window_minimized)
+ return do_minimize(wl);
+ if (opt == &opts->window_maximized)
+ return toggle_maximized(wl);
+ }
+ return VO_TRUE;
+ }
case VOCTRL_GET_FULLSCREEN: {
*(int *)arg = wl->fullscreen;
return VO_TRUE;
@@ -1447,10 +1475,6 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
*(char ***)arg = get_displays_spanned(wl);
return VO_TRUE;
}
- case VOCTRL_GET_WIN_STATE: {
- *(int *)arg = wl->maximized ? VO_WIN_STATE_MAXIMIZED : 0;
- return VO_TRUE;
- }
case VOCTRL_GET_UNFS_WINDOW_SIZE: {
int *s = arg;
s[0] = mp_rect_w(wl->geometry)*wl->scaling;
@@ -1459,7 +1483,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
}
case VOCTRL_SET_UNFS_WINDOW_SIZE: {
int *s = arg;
- if (!wl->fullscreen && !wl->maximized) {
+ if (!wl->fullscreen && !wl->vo_opts->window_maximized) {
wl->geometry.x0 = 0;
wl->geometry.y0 = 0;
wl->geometry.x1 = s[0]/wl->scaling;
@@ -1476,12 +1500,6 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
}
case VOCTRL_UPDATE_WINDOW_TITLE:
return update_window_title(wl, (char *)arg);
- case VOCTRL_FULLSCREEN:
- return toggle_fullscreen(wl);
- case VOCTRL_MAXIMIZE:
- return toggle_maximized(wl);
- case VOCTRL_MINIMIZE:
- return do_minimize(wl);
case VOCTRL_SET_CURSOR_VISIBILITY:
return set_cursor_visibility(wl, *(bool *)arg);
case VOCTRL_BORDER:
diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
index 567a38fd41..65e0867e23 100644
--- a/video/out/wayland_common.h
+++ b/video/out/wayland_common.h
@@ -65,12 +65,14 @@ struct vo_wayland_state {
struct wl_registry *registry;
struct wayland_opts *opts;
+ struct m_config_cache *vo_opts_cache;
+ struct mp_vo_opts *vo_opts;
+
/* State */
struct mp_rect geometry;
struct mp_rect window_size;
float aspect_ratio;
bool fullscreen;
- bool maximized;
bool configured;
bool frame_wait;
bool hidden;