Skip to content

Commit

Permalink
improve popup on wid mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Feb 24, 2024
1 parent b78a9b4 commit c4e38ed
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion include/mpv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions source/mpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void Mpv::observeProperties() {
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", [this](int flag) { keepaspect = flag; });
observeProperty<int, MPV_FORMAT_FLAG>("ontop", [this](int flag) { ontop = 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; });

Expand Down
22 changes: 17 additions & 5 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 1 addition & 15 deletions source/views/context_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
8 changes: 0 additions & 8 deletions source/views/quickview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c4e38ed

Please sign in to comment.