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

GTK Focus issue when used with SDL #31

Closed
btzy opened this issue Apr 2, 2021 · 1 comment · Fixed by #32
Closed

GTK Focus issue when used with SDL #31

btzy opened this issue Apr 2, 2021 · 1 comment · Fixed by #32

Comments

@btzy
Copy link
Owner

btzy commented Apr 2, 2021

This is the same as mlabbe/nativefiledialog#79, where the file dialog goes under an existing SDL window. It does not happen in the tests where we are launching the dialog directly from the terminal.

Tested on Ubuntu 20.04.

@btzy
Copy link
Owner Author

btzy commented Apr 2, 2021

Test case (modified from mlabbe/nativefiledialog#79):

main.c:

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

#include <SDL.h>

#include <nfd.h>

int main()
{
    SDL_Init(SDL_INIT_VIDEO);
    
    NFD_Init();

    SDL_Window *window = SDL_CreateWindow("nativefiledialog issue 79", SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED, 800, 480, SDL_WINDOW_SHOWN);

    int w, h;
    SDL_GetWindowSize(window, &w, &h);

    bool running = true;
    while (running) {
        SDL_Event e;
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) {
                running = false;
                break;
            }
            if (e.type == SDL_MOUSEBUTTONDOWN) {
                nfdchar_t *filename;
                nfdresult_t res = NFD_OpenDialog(&filename, NULL, 0, NULL);
                if (res == NFD_OKAY) {
                    printf("Got filename: %s\n", filename);
                    free(filename);
                }
            }
        }
    }

    SDL_DestroyWindow(window);
    
    NFD_Quit();
    
    SDL_Quit();

    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
project(MyProgram)


set (CMAKE_CXX_STANDARD 17)


add_executable(MyProgram main.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(MyProgram PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(MyProgram PRIVATE ${SDL2_LIBRARIES})

add_subdirectory(${PROJECT_SOURCE_DIR}/../nativefiledialog-extended ${PROJECT_SOURCE_DIR}/../nativefiledialog-extended/build)
target_link_libraries(MyProgram PRIVATE nfd)

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

Successfully merging a pull request may close this issue.

1 participant