Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3: Add support for parent viewports #7973

Closed
wants to merge 1 commit into from
Closed

SDL3: Add support for parent viewports #7973

wants to merge 1 commit into from

Conversation

RT2Code
Copy link
Contributor

@RT2Code RT2Code commented Sep 11, 2024

As SDL3 added support for non-modal parent windows, we can now add support for windows parenting in the SDL3 backend.

I'm unsure about the Win32 specific hack in the ImGui_ImplSDL3_ShowWindow function:

static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport)
{
    ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData;
#if defined(_WIN32)
    HWND hwnd = (HWND)viewport->PlatformHandleRaw;

    // SDL hack: Hide icon from task bar
    // Note: SDL 3.0.0+ has a SDL_WINDOW_UTILITY flag which is supported under Windows but the way it create the window breaks our seamless transition.
    if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)
    {
        LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
        ex_style &= ~WS_EX_APPWINDOW;
        ex_style |= WS_EX_TOOLWINDOW;
        ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
    }
#endif

    SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "0" : "1");
    SDL_ShowWindow(vd->Window);
}

SDL3 child windows aren't shown in the taskbar by default, so should this hack be removed? Or are there cases where viewports have no parents and this hack is still necessary?

@ocornut
Copy link
Owner

ocornut commented Sep 11, 2024

Thank you Rémy! I will review this later but it looks good.

About ImGuiViewportFlags_NoTaskBarIcon: this is pretty much orthogonal to the child<>parent relationship from our point of view. User can technically control which window will use this flag and which wouldn't. So ideally we'd have control over this either way, and I presume the hack is necessary for now (ideally it would be a multi-platform feature of course).

I don't remember the exact problem with SDL_WINDOW_UTILITY. If SDL_WINDOW_UTILITY honors "not showing in the task bar and window list" regardless of parenting setup we would use it.

ocornut pushed a commit that referenced this pull request Sep 12, 2024
@ocornut
Copy link
Owner

ocornut commented Sep 12, 2024

Merged as 4847648. Thank you Remy for this!
I really appreciate the support with SDL3 and the careful/quality PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants