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

Revert "Restore window before closing (#453)" #773

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/graphic/Fast3D/gfx_dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,6 @@ void GetMonitorHzPeriod(std::tuple<HMONITOR, RECT, BOOL> Monitor, double& Freque
}
}

static void gfx_dxgi_close() {
ShowWindow(dxgi.h_wnd, SW_NORMAL); // Restore window before closing, so normal window pos and size is saved
dxgi.is_running = false;
}

static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_param, LPARAM l_param) {
char fileName[256];
Ship::WindowEvent event_impl;
Expand Down Expand Up @@ -334,7 +329,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
}
break;
case WM_CLOSE:
gfx_dxgi_close();
dxgi.is_running = false;
break;
case WM_DPICHANGED: {
RECT* const prcNewWindow = (RECT*)l_param;
Expand All @@ -349,7 +344,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par
case WM_ENDSESSION:
// This hopefully gives the game a chance to shut down, before windows kills it.
if (w_param == TRUE) {
gfx_dxgi_close();
dxgi.is_running = false;
}
break;
case WM_ACTIVATEAPP:
Expand Down Expand Up @@ -486,6 +481,10 @@ void gfx_dxgi_init(const char* game_name, const char* gfx_api_name, bool start_i
DragAcceptFiles(dxgi.h_wnd, TRUE);
}

static void gfx_dxgi_close() {
dxgi.is_running = false;
}

static void gfx_dxgi_set_fullscreen_changed_callback(void (*on_fullscreen_changed)(bool is_now_fullscreen)) {
dxgi.on_fullscreen_changed = on_fullscreen_changed;
}
Expand Down
34 changes: 11 additions & 23 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,13 @@ static int target_fps = 60;
#define FRAME_INTERVAL_US_NUMERATOR 1000000
#define FRAME_INTERVAL_US_DENOMINATOR (target_fps)

static void gfx_sdl_close(void) {
SDL_RestoreWindow(wnd); // Restore window before closing, so normal window pos and size is saved
is_running = false;
}

#ifdef _WIN32
static LRESULT CALLBACK gfx_sdl_wnd_proc(HWND h_wnd, UINT message, WPARAM w_param, LPARAM l_param) {
switch (message) {
case WM_GETDPISCALEDSIZE:
// Something is wrong with SDLs original implementation of WM_GETDPISCALEDSIZE, so pass it to the default
// system window procedure instead.
return DefWindowProc(h_wnd, message, w_param, l_param);
case WM_ENDSESSION:
// Apparently SDL2 does not handle this
if (w_param == TRUE) {
gfx_sdl_close();
}
break;
default:
// Pass anything else to SDLs original window procedure.
return CallWindowProc((WNDPROC)SDL_WndProc, h_wnd, message, w_param, l_param);
Expand Down Expand Up @@ -431,6 +420,10 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s
}
}

static void gfx_sdl_close() {
is_running = false;
}

static void gfx_sdl_set_fullscreen_changed_callback(void (*on_fullscreen_changed)(bool is_now_fullscreen)) {
on_fullscreen_changed_callback = on_fullscreen_changed;
}
Expand Down Expand Up @@ -540,17 +533,12 @@ static void gfx_sdl_handle_single_event(SDL_Event& event) {
break;
#endif
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
SDL_GL_GetDrawableSize(wnd, &window_width, &window_height);
break;
case SDL_WINDOWEVENT_CLOSE:
if (event.window.windowID == SDL_GetWindowID(wnd)) {
// We listen specifically for main window close because closing main window
// on macOS does not trigger SDL_Quit.
gfx_sdl_close();
}
break;
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
SDL_GL_GetDrawableSize(wnd, &window_width, &window_height);
} else if (event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(wnd)) {
// We listen specifically for main window close because closing main window
// on macOS does not trigger SDL_Quit.
is_running = false;
}
break;
case SDL_DROPFILE:
Expand All @@ -559,7 +547,7 @@ static void gfx_sdl_handle_single_event(SDL_Event& event) {
Ship::Context::GetInstance()->GetConsoleVariables()->Save();
break;
case SDL_QUIT:
gfx_sdl_close();
is_running = false;
break;
}
}
Expand Down
Loading