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

options/m_option: restore m_geometry_apply centering ability #15399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions options/m_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ static char *print_geometry(const m_option_t *opt, const void *val)
// scrw,scrh: width and height of the current screen
// The input parameters should be set to a centered window (default fallbacks).
void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh,
int scrw, int scrh, struct m_geometry *gm)
int scrw, int scrh, bool center, struct m_geometry *gm)
{
if (gm->wh_valid) {
int prew = *widw, preh = *widh;
Expand All @@ -2232,6 +2232,10 @@ void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh,
} else if (!(gm->w > 0) && gm->h > 0) {
*widw = *widh * asp;
}
if (center) {
*xpos += prew / 2 - *widw / 2;
*ypos += preh / 2 - *widh / 2;
}
}

if (gm->xy_valid) {
Expand Down Expand Up @@ -2341,7 +2345,7 @@ void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm)
*rc = (struct mp_rect){0, 0, w, h};
if (!w || !h)
return;
m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, w, h, gm);
m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, w, h, true, gm);
if (!gm->xy_valid && gm->wh_valid && rc->x1 == 0 && rc->y1 == 0)
return;
if (!gm->wh_valid || rc->x1 == 0 || rc->x1 == INT_MIN)
Expand Down
2 changes: 1 addition & 1 deletion options/m_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct m_geometry {
};

void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh,
int scrw, int scrh, struct m_geometry *gm);
int scrw, int scrh, bool center, struct m_geometry *gm);
void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm);

struct m_channels {
Expand Down
13 changes: 3 additions & 10 deletions video/out/win_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void apply_autofit(int *w, int *h, int scr_w, int scr_h,

int dummy = 0;
int n_w = *w, n_h = *h;
m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, true, geo);

if (!allow_up && *w <= n_w && *h <= n_h)
return;
Expand Down Expand Up @@ -125,16 +125,9 @@ void vo_calc_window_geometry(struct vo *vo, const struct mp_rect *screen,
out_geo->win.x0 = (int)(scr_w - d_w) / 2;
out_geo->win.y0 = (int)(scr_h - d_h) / 2;

int old_w = d_w;
int old_h = d_h;

bool center = (opts->force_window_position || force_center) && !opts->geometry.xy_valid;
m_geometry_apply(&out_geo->win.x0, &out_geo->win.y0, &d_w, &d_h,
scr_w, scr_h, &opts->geometry);

if ((opts->force_window_position || force_center) && !opts->geometry.xy_valid) {
out_geo->win.x0 += old_w / 2 - d_w / 2;
out_geo->win.y0 += old_h / 2 - d_h / 2;
}
scr_w, scr_h, center, &opts->geometry);

out_geo->win.x0 += screen->x0;
out_geo->win.y0 += screen->y0;
Expand Down