Skip to content

Commit

Permalink
fix fullscreen state
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Nov 13, 2023
1 parent 420bba4 commit 05b7a36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Player {
int width = 1280, height = 720;

private:
void updateWindowState();
void initObservers();
void writeMpvConf();

Expand Down
30 changes: 17 additions & 13 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void Player::loadFonts() {
io.Fonts->AddFontFromFileTTF(config->Data.Font.Path.c_str(), 0, &cfg, font_range);
else
io.Fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 0, &cfg, font_range);

cfg.MergeMode = true;

static ImWchar fa_range[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
Expand Down Expand Up @@ -344,22 +344,26 @@ void Player::onDropEvent(int count, const char **paths) {
load(files);
}

void Player::updateWindowState() {
int width = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dwidth");
int height = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dheight");
if (width > 0 && height > 0) {
int x, y, w, h;
GetWindowPos(&x, &y);
GetWindowSize(&w, &h);
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);
}
}

void Player::initObservers() {
mpv->observeEvent(MPV_EVENT_SHUTDOWN, [this](void *data) { SetWindowShouldClose(true); });

mpv->observeEvent(MPV_EVENT_VIDEO_RECONFIG, [this](void *data) {
int width = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dwidth");
int height = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dheight");
if (width > 0 && height > 0) {
int x, y, w, h;
GetWindowPos(&x, &y);
GetWindowSize(&w, &h);
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);
}
if (!mpv->fullscreen) updateWindowState();
});

mpv->observeEvent(MPV_EVENT_FILE_LOADED, [this](void *data) {
Expand Down

0 comments on commit 05b7a36

Please sign in to comment.