Skip to content

Commit

Permalink
add auto-window-resize support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Nov 12, 2023
1 parent 9d6d1f5 commit 130d278
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/mpv.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class Mpv {
std::vector<std::string> profiles;
std::string aid, vid, sid, sid2, audioDevice, cursorAutohide;
int64_t chapter = 0, volume = 100, playlistPos = -1, playlistPlayingPos = -1, timePos = 0;
bool pause, mute, fullscreen, sidv, sidv2, windowDragging, forceWindow, keepaspect;
bool pause, mute, fullscreen, sidv, sidv2, forceWindow;
bool keepaspect, keepaspectWindow, windowDragging, autoResize;

private:
void eventLoop();
Expand Down
4 changes: 3 additions & 1 deletion source/mpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ void Mpv::observeProperties() {
observeProperty<int, MPV_FORMAT_FLAG>("sub-visibility", [this](int flag) { sidv = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("secondary-sub-visibility", [this](int flag) { sidv2 = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("window-dragging", [this](int flag) { windowDragging = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("keepaspect-window", [this](int flag) { keepaspect = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("keepaspect", [this](int flag) { keepaspect = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("keepaspect-window", [this](int flag) { keepaspectWindow = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("auto-window-resize", [this](int flag) { autoResize = flag; });

observeProperty<int64_t, MPV_FORMAT_INT64>("volume", [this](int64_t val) { volume = val; });
observeProperty<int64_t, MPV_FORMAT_INT64>("chapter", [this](int64_t val) { chapter = val; });
Expand Down
9 changes: 5 additions & 4 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ void Player::initObservers() {
int x, y, w, h;
GetWindowPos(&x, &y);
GetWindowSize(&w, &h);

SetWindowSize(width, height);
SetWindowPos(x + (w - width) / 2, y + (h - height) / 2);
if (mpv->keepaspect) SetWindowAspectRatio(width, height);
if ((w != width || h != height) && mpv->autoResize) {
SetWindowSize(width, height);
SetWindowPos(x + (w - width) / 2, y + (h - height) / 2);
}
if (mpv->keepaspect && mpv->keepaspectWindow) SetWindowAspectRatio(width, height);
}
});

Expand Down

0 comments on commit 130d278

Please sign in to comment.