From 06733491fd7fc4cb309c40101cb0977fa8a65ed9 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Mon, 4 Dec 2023 23:17:44 +0800 Subject: [PATCH] Revert "fix window maximized/minimized event" This reverts commit 6980d566dc3c5e28c2f91e1714e169b5d69623d5. --- include/player.h | 5 ----- include/window.h | 1 - source/player.cpp | 29 +++++------------------------ source/window.cpp | 28 ++++++++++------------------ 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/include/player.h b/include/player.h index 2784a67..e9b43a9 100644 --- a/include/player.h +++ b/include/player.h @@ -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); @@ -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; @@ -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; diff --git a/include/window.h b/include/window.h index cdccb57..cc0920b 100644 --- a/include/window.h +++ b/include/window.h @@ -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; diff --git a/source/player.cpp b/source/player.cpp index 2caf90d..f8437c6 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -109,6 +109,9 @@ void Player::drawVideo() { } void Player::render() { + auto g = ImGui::GetCurrentContext(); + if (g != nullptr && g->WithinFrameScope) return; + { ContextGuard guard(this); @@ -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); @@ -392,14 +379,8 @@ void Player::initObservers() { mpv->observeProperty("media-title", [this](char *data) { SetWindowTitle(data); }); mpv->observeProperty("border", [this](int flag) { SetWindowDecorated(flag); }); mpv->observeProperty("ontop", [this](int flag) { SetWindowFloating(flag); }); - mpv->observeProperty("window-maximized", [this](int flag) { - maximized = flag; - SetWindowMaximized(flag); - }); - mpv->observeProperty("window-minimized", [this](int flag) { - minimized = flag; - SetWindowMinimized(flag); - }); + mpv->observeProperty("window-maximized", [this](int flag) { SetWindowMaximized(flag); }); + mpv->observeProperty("window-minimized", [this](int flag) { SetWindowMinimized(flag); }); mpv->observeProperty("window-scale", [this](double scale) { int w = (int)mpv->property("dwidth"); int h = (int)mpv->property("dheight"); diff --git a/source/window.cpp b/source/window.cpp index 089af1d..e38db4d 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -179,17 +179,13 @@ void Window::installCallbacks(GLFWwindow* target) { auto win = static_cast(glfwGetWindowUserPointer(window)); win->shutdown(); }); - glfwSetWindowIconifyCallback(target, [](GLFWwindow* window, int iconified) { - auto win = static_cast(glfwGetWindowUserPointer(window)); - win->onIconifyEvent(iconified); - }); glfwSetWindowSizeCallback(target, [](GLFWwindow* window, int w, int h) { auto win = static_cast(glfwGetWindowUserPointer(window)); - win->onSizeEvent(w, h); + win->render(); }); glfwSetWindowPosCallback(target, [](GLFWwindow* window, int x, int y) { auto win = static_cast(glfwGetWindowUserPointer(window)); - win->onPosEvent(x, y); + win->render(); }); glfwSetCursorEnterCallback(target, [](GLFWwindow* window, int entered) { auto win = static_cast(glfwGetWindowUserPointer(window)); @@ -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); }