Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wayland: fix vertical resize #11420

Closed
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
46 changes: 42 additions & 4 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <wayland-cursor.h>
#include <xkbcommon/xkbcommon.h>

#include "common/common.h"
#include "common/msg.h"
#include "input/input.h"
#include "input/keycodes.h"
Expand Down Expand Up @@ -902,13 +903,15 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
bool is_activated = false;
bool is_suspended = false;
bool is_tiled = false;
bool is_resizing = false;
enum xdg_toplevel_state *state;
wl_array_for_each(state, states) {
switch (*state) {
case XDG_TOPLEVEL_STATE_FULLSCREEN:
is_fullscreen = true;
break;
case XDG_TOPLEVEL_STATE_RESIZING:
is_resizing = true;
break;
case XDG_TOPLEVEL_STATE_ACTIVATED:
is_activated = true;
Expand Down Expand Up @@ -936,6 +939,9 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
}
}

if (!is_resizing)
wl->resizing = 0;

if (wl->hidden != is_suspended)
wl->hidden = is_suspended;

Expand Down Expand Up @@ -990,10 +996,42 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,

if (!wl->locked_size) {
if (vo_opts->keepaspect) {
double scale_factor = (double)width / wl->reduced_width;
width = ceil(wl->reduced_width * scale_factor);
if (vo_opts->keepaspect_window)
height = ceil(wl->reduced_height * scale_factor);
int real_width = round(width * wl->scaling);
int real_height = round(height * wl->scaling);
if (real_width - mp_rect_w(wl->window_size) || real_height - mp_rect_h(wl->window_size)) {
wl->resizing |= wl->toplevel_width - old_toplevel_width ? 1 : 0;
wl->resizing |= wl->toplevel_height - old_toplevel_height ? 2 : 0;
}
switch (wl->resizing) {
case 1: { // horizontal
double scale_factor = (double)width / wl->reduced_width;
width = ceil(wl->reduced_width * scale_factor);
if (vo_opts->keepaspect_window)
height = ceil(wl->reduced_height * scale_factor);
break;
}
case 2: { // vertical
double scale_factor = (double)height / wl->reduced_height;
height = ceil(wl->reduced_height * scale_factor);
if (vo_opts->keepaspect_window)
width = ceil(wl->reduced_width * scale_factor);
break;
}
case 3: { // both
if (vo_opts->keepaspect_window) {
double sf_w = (double)width / wl->reduced_width;
double sf_h = (double)height / wl->reduced_height;
if (sf_w > sf_h) {
width = ceil(wl->reduced_width * sf_w);
height = ceil(wl->reduced_height * sf_w);
} else {
width = ceil(wl->reduced_width * sf_h);
height = ceil(wl->reduced_height * sf_h);
}
}
break;
}
}
}
wl->window_size.x0 = 0;
wl->window_size.y0 = 0;
Expand Down
1 change: 1 addition & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct vo_wayland_state {
double scaling;
int timeout_count;
int wakeup_pipe[2];
int resizing;

/* content-type */
/* TODO: unvoid these if required wayland protocols is bumped to 1.27+ */
Expand Down