Skip to content

Commit

Permalink
Revert "fix window maximized/minimized event"
Browse files Browse the repository at this point in the history
This reverts commit 6980d56.
  • Loading branch information
tsl0922 committed Dec 4, 2023
1 parent 913e59b commit 0673349
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
5 changes: 0 additions & 5 deletions include/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class Player {
void render();
void renderVideo();

void onIconifyEvent(bool iconified);
void onSizeEvent(int w, int h);
void onPosEvent(int x, int y);
void onCursorEvent(double x, double y);
void onScrollEvent(double x, double y);
void onKeyEvent(std::string name);
Expand Down Expand Up @@ -104,7 +101,6 @@ class Player {
virtual void SetWindowSize(int w, int h) = 0;
virtual void SetWindowTitle(std::string) = 0;
virtual void SetWindowAspectRatio(int num, int den) = 0;
virtual bool GetWindowMaximized() = 0;
virtual void SetWindowMaximized(bool m) = 0;
virtual void SetWindowMinimized(bool m) = 0;
virtual void SetWindowDecorated(bool d) = 0;
Expand All @@ -113,7 +109,6 @@ class Player {
virtual void SetWindowShouldClose(bool c) = 0;

bool idle = true;
bool maximized, minimized;
GLuint fbo = 0, tex = 0;
ImTextureID logoTexture = nullptr;
std::mutex contextLock;
Expand Down
1 change: 0 additions & 1 deletion include/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Window : Player {
void SetWindowSize(int w, int h) override;
void SetWindowTitle(std::string title) override;
void SetWindowAspectRatio(int num, int den) override;
bool GetWindowMaximized() override;
void SetWindowMaximized(bool m) override;
void SetWindowMinimized(bool m) override;
void SetWindowDecorated(bool d) override;
Expand Down
29 changes: 5 additions & 24 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ void Player::drawVideo() {
}

void Player::render() {
auto g = ImGui::GetCurrentContext();
if (g != nullptr && g->WithinFrameScope) return;

{
ContextGuard guard(this);

Expand Down Expand Up @@ -307,22 +310,6 @@ void Player::loadFonts() {

void Player::shutdown() { mpv->command(config->Data.Mpv.WatchLater ? "quit-watch-later" : "quit"); }

void Player::onIconifyEvent(bool iconified) {
if (minimized != iconified) mpv->property("window-minimized", iconified ? "yes" : "no");
}

void Player::onSizeEvent(int w, int h) {
bool m = GetWindowMaximized();
if (maximized != m) mpv->property("window-maximized", m ? "yes" : "no");
auto g = ImGui::GetCurrentContext();
if (g != nullptr && !g->WithinFrameScope) render();
}

void Player::onPosEvent(int x, int y) {
auto g = ImGui::GetCurrentContext();
if (g != nullptr && !g->WithinFrameScope) render();
}

void Player::onCursorEvent(double x, double y) {
std::string xs = std::to_string((int)x);
std::string ys = std::to_string((int)y);
Expand Down Expand Up @@ -392,14 +379,8 @@ void Player::initObservers() {
mpv->observeProperty<char *, MPV_FORMAT_STRING>("media-title", [this](char *data) { SetWindowTitle(data); });
mpv->observeProperty<int, MPV_FORMAT_FLAG>("border", [this](int flag) { SetWindowDecorated(flag); });
mpv->observeProperty<int, MPV_FORMAT_FLAG>("ontop", [this](int flag) { SetWindowFloating(flag); });
mpv->observeProperty<int, MPV_FORMAT_FLAG>("window-maximized", [this](int flag) {
maximized = flag;
SetWindowMaximized(flag);
});
mpv->observeProperty<int, MPV_FORMAT_FLAG>("window-minimized", [this](int flag) {
minimized = flag;
SetWindowMinimized(flag);
});
mpv->observeProperty<int, MPV_FORMAT_FLAG>("window-maximized", [this](int flag) { SetWindowMaximized(flag); });
mpv->observeProperty<int, MPV_FORMAT_FLAG>("window-minimized", [this](int flag) { SetWindowMinimized(flag); });
mpv->observeProperty<double, MPV_FORMAT_DOUBLE>("window-scale", [this](double scale) {
int w = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dwidth");
int h = (int)mpv->property<int64_t, MPV_FORMAT_INT64>("dheight");
Expand Down
28 changes: 10 additions & 18 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,13 @@ void Window::installCallbacks(GLFWwindow* target) {
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->shutdown();
});
glfwSetWindowIconifyCallback(target, [](GLFWwindow* window, int iconified) {
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->onIconifyEvent(iconified);
});
glfwSetWindowSizeCallback(target, [](GLFWwindow* window, int w, int h) {
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->onSizeEvent(w, h);
win->render();
});
glfwSetWindowPosCallback(target, [](GLFWwindow* window, int x, int y) {
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->onPosEvent(x, y);
win->render();
});
glfwSetCursorEnterCallback(target, [](GLFWwindow* window, int entered) {
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
Expand Down Expand Up @@ -324,22 +320,18 @@ void Window::SetWindowTitle(std::string title) { glfwSetWindowTitle(window, titl

void Window::SetWindowAspectRatio(int num, int den) { glfwSetWindowAspectRatio(window, num, den); }

bool Window::GetWindowMaximized() { return (bool)glfwGetWindowAttrib(window, GLFW_MAXIMIZED); }

void Window::SetWindowMaximized(bool m) {
if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) {
if (!m) glfwRestoreWindow(window);
} else {
if (m) glfwMaximizeWindow(window);
}
if (m)
glfwMaximizeWindow(window);
else
glfwRestoreWindow(window);
}

void Window::SetWindowMinimized(bool m) {
if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) {
if (!m) glfwRestoreWindow(window);
} else {
if (m) glfwIconifyWindow(window);
}
if (m)
glfwIconifyWindow(window);
else
glfwRestoreWindow(window);
}

void Window::SetWindowDecorated(bool d) { glfwSetWindowAttrib(window, GLFW_DECORATED, d); }
Expand Down

0 comments on commit 0673349

Please sign in to comment.