From c4e38ed1ac4ef4e4dde8192a0141b4aecc08ab81 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Fri, 23 Feb 2024 22:24:00 +0800 Subject: [PATCH] improve popup on wid mode --- include/mpv.h | 2 +- source/mpv.cpp | 1 + source/player.cpp | 22 +++++++++++++++++----- source/views/context_menu.cpp | 16 +--------------- source/views/quickview.cpp | 8 -------- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/mpv.h b/include/mpv.h index aec33cd..61b99ba 100644 --- a/include/mpv.h +++ b/include/mpv.h @@ -117,7 +117,7 @@ class Mpv { int64_t chapter, volume, playlistPos, playlistPlayingPos, timePos; int64_t brightness, contrast, saturation, gamma, hue; double audioDelay, subDelay, subScale; - bool pause, mute, fullscreen, sidv, sidv2, forceWindow; + bool pause, mute, fullscreen, sidv, sidv2, forceWindow, ontop; bool keepaspect, keepaspectWindow, windowDragging, autoResize; private: diff --git a/source/mpv.cpp b/source/mpv.cpp index 1afa9f8..61dfe12 100644 --- a/source/mpv.cpp +++ b/source/mpv.cpp @@ -154,6 +154,7 @@ void Mpv::observeProperties() { observeProperty("secondary-sub-visibility", [this](int flag) { sidv2 = flag; }); observeProperty("window-dragging", [this](int flag) { windowDragging = flag; }); observeProperty("keepaspect", [this](int flag) { keepaspect = flag; }); + observeProperty("ontop", [this](int flag) { ontop = flag; }); observeProperty("keepaspect-window", [this](int flag) { keepaspectWindow = flag; }); observeProperty("auto-window-resize", [this](int flag) { autoResize = flag; }); diff --git a/source/player.cpp b/source/player.cpp index 76f9a72..0a20f67 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -142,6 +142,19 @@ void Player::render() { #endif draw(); + +#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT) + if (config->Data.Mpv.UseWid && mpv->ontop) { + ImGuiContext *ctx = ImGui::GetCurrentContext(); + for (int i = 1; i < ctx->Windows.Size; i++) { + ImGuiWindow *w = ctx->Windows[i]; + if (w->Flags & ImGuiWindowFlags_Popup) { // HACK: make all popup topmost + w->WindowClass.ViewportFlagsOverrideSet = ImGuiViewportFlags_TopMost; + } + } + } +#endif + ImGui::Render(); { @@ -610,9 +623,8 @@ void Player::drawOpenURL() { ImVec2 wSize = ImGui::GetMainViewport()->WorkSize; ImGui::SetNextWindowSize(ImVec2(std::min(wSize.x * 0.8f, scaled(50)), 0), ImGuiCond_Always); - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetWorkCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - if (ImGui::BeginPopupModal("views.dialog.open_url.title"_i18n, &m_openURL, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetWorkCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + if (ImGui::BeginPopupModal("views.dialog.open_url.title"_i18n, &m_openURL)) { if (ImGui::IsKeyDown(ImGuiKey_Escape)) m_openURL = false; static char url[256] = {0}; bool loadfile = false; @@ -645,8 +657,8 @@ void Player::drawDialog() { ImGui::OpenPopup(m_dialog_title.c_str()); ImGui::SetNextWindowSize(ImVec2(scaled(30), 0), ImGuiCond_Always); - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetWorkCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - if (ImGui::BeginPopupModal(m_dialog_title.c_str(), &m_dialog, ImGuiWindowFlags_NoMove)) { + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetWorkCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + if (ImGui::BeginPopupModal(m_dialog_title.c_str(), &m_dialog)) { ImGui::TextWrapped("%s", m_dialog_msg.c_str()); ImGui::Spacing(); ImGui::Separator(); diff --git a/source/views/context_menu.cpp b/source/views/context_menu.cpp index 47aec63..aefd3a8 100644 --- a/source/views/context_menu.cpp +++ b/source/views/context_menu.cpp @@ -13,23 +13,9 @@ void ContextMenu::draw() { m_open = false; } - ImGuiIO &io = ImGui::GetIO(); -#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT) - if (config->Data.Mpv.UseWid && io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGuiWindowClass windowClass; - windowClass.ViewportFlagsOverrideSet = ImGuiViewportFlags_TopMost; - ImGui::SetNextWindowClass(&windowClass); - } -#endif - if (ImGui::BeginPopup("##context_menu", ImGuiWindowFlags_NoMove)) { - if (io.AppFocusLost) ImGui::CloseCurrentPopup(); -#ifdef IMGUI_HAS_VIEWPORT - if (ImGui::GetWindowViewport()->Flags & ImGuiViewportFlags_IsMinimized) ImGui::CloseCurrentPopup(); -#endif - + if (ImGui::GetIO().AppFocusLost) ImGui::CloseCurrentPopup(); draw(build()); - ImGui::EndPopup(); } } diff --git a/source/views/quickview.cpp b/source/views/quickview.cpp index f17a7bf..9dc3584 100644 --- a/source/views/quickview.cpp +++ b/source/views/quickview.cpp @@ -64,14 +64,6 @@ void Quickview::drawPopup() { ImGui::SetNextWindowSize(ImVec2(width, wSize.y), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(wPos.x + wSize.x - width, wPos.y), ImGuiCond_Always); -#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT) - if (config->Data.Mpv.UseWid && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGuiWindowClass windowClass; - windowClass.ViewportFlagsOverrideSet = ImGuiViewportFlags_TopMost; - ImGui::SetNextWindowClass(&windowClass); - } -#endif - if (ImGui::BeginPopup("##quickview")) { drawTabBar(); ImGui::EndPopup();