• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Cross-Platform OpenGL Windowing Library


Commit MetaInfo

Revisione828b335cb2a4bfce84b5dfc8ac7acbf72fafe4f (tree)
Time2020-02-23 02:45:28
AuthorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Fix issue with sometimes clicking the X on a window not closing it

Change Summary

Incremental Difference

--- a/glow_win32.c
+++ b/glow_win32.c
@@ -184,83 +184,92 @@ static LRESULT WINAPI glow_window_proc(HWND wnd,
184184 WPARAM parm,
185185 LPARAM lparam){
186186
187- if(msg == WM_CREATE){
188- struct Glow_Window *const window =
189- (struct Glow_Window *)(((CREATESTRUCT*)lparam)->lpCreateParams);
190- const int let =
191- ChoosePixelFormat((window->dc = GetDC(wnd)), &glow_pixel_format);
192-
193- /* This will get set to -1 if adaptive vsync works. */
194- int interval = 1;
195- const char *const ext = glGetString(GL_EXTENSIONS);
196-
197- SetPixelFormat(window->dc, let, &glow_pixel_format);
198- window->ctx.ctx = wglCreateContext(window->dc);
199- window->ctx.dc = window->dc;
200- wglMakeCurrent(window->dc, window->ctx.ctx);
201-
202- /* Try to get VSync or, if requested, adaptive VSync. */
203- if((window->adaptive_vsync || window->vsync) &&
204- strstr(ext, "WGL_EXT_swap_control") != NULL){
205-
206- typedef BOOL(*wgl_swap_interval_func)(int);
207-
208- const wgl_swap_interval_func wglSwapIntervalEXT =
209- (wgl_swap_interval_func)wglGetProcAddress(
210- "wglSwapIntervalEXT");
211-
212- assert(wglSwapIntervalEXT);
213-
214- /* Try to use control_tear if requested. */
215- if(window->adaptive_vsync &&
216- strstr(ext, "WGL_EXT_extensions_string") != NULL){
217-
218- typedef const char*(*wgl_extension_strings_func)(void);
187+ switch(msg){
188+ case WM_CREATE:
189+ {
190+ struct Glow_Window *const window =
191+ (void*)(((CREATESTRUCT*)lparam)->lpCreateParams);
192+ const int pix_format = ChoosePixelFormat(
193+ (window->dc = GetDC(wnd)),
194+ &glow_pixel_format);
219195
220- const wgl_extension_strings_func wglGetExtensionsStringEXT =
221- (wgl_extension_strings_func)wglGetProcAddress(
222- "wglGetExtensionsStringEXT");
196+ /* This will get set to -1 if adaptive vsync works. */
197+ int interval = 1;
198+ const char *const ext = glGetString(GL_EXTENSIONS);
223199
224- assert(wglGetExtensionsStringEXT);
200+ SetPixelFormat(window->dc, pix_format, &glow_pixel_format);
201+ window->ctx.ctx = wglCreateContext(window->dc);
202+ window->ctx.dc = window->dc;
203+ wglMakeCurrent(window->dc, window->ctx.ctx);
225204
226- if(wglGetExtensionsStringEXT){
227- const char *const wgl_ext = wglGetExtensionsStringEXT();
228- if(strstr(wgl_ext, "WGL_EXT_swap_control_tear") != NULL){
229- interval = -1;
205+ /* Try to get VSync or, if requested, adaptive VSync. */
206+ if((window->adaptive_vsync || window->vsync) &&
207+ strstr(ext, "WGL_EXT_swap_control") != NULL){
208+
209+ typedef BOOL(*wgl_swap_interval_func)(int);
210+
211+ const wgl_swap_interval_func wglSwapIntervalEXT =
212+ (wgl_swap_interval_func)wglGetProcAddress(
213+ "wglSwapIntervalEXT");
214+
215+ assert(wglSwapIntervalEXT);
216+
217+ /* Try to use control_tear if requested. */
218+ if(window->adaptive_vsync &&
219+ strstr(ext, "WGL_EXT_extensions_string") != NULL){
220+
221+ typedef const char*(*wgl_extension_strings_func)(void);
222+
223+ const wgl_extension_strings_func
224+ wglGetExtensionsStringEXT =
225+ (wgl_extension_strings_func)wglGetProcAddress(
226+ "wglGetExtensionsStringEXT");
227+
228+ assert(wglGetExtensionsStringEXT);
229+
230+ const char *const wgl_ext =
231+ wglGetExtensionsStringEXT();
232+
233+ if(strstr(wgl_ext, "WGL_EXT_swap_control_tear") !=
234+ NULL){
235+
236+ interval = -1;
237+ }
238+ }
239+
240+ /* Set the interval if either adaptive VSync or regular
241+ * VSync was requested.
242+ */
243+ if(((window->adaptive_vsync && interval == -1) ||
244+ window->vsync) &&
245+ wglSwapIntervalEXT != NULL){
246+
247+ wglSwapIntervalEXT(interval);
230248 }
231249 }
232- }
233-
234- /* Set the interval if either adaptive VSync or regular VSync was
235- * requested.
236- */
237- if(((window->adaptive_vsync && interval == -1) || window->vsync) &&
238- wglSwapIntervalEXT != NULL){
239250
240- wglSwapIntervalEXT(interval);
251+ glClearColor(0.75f, 0.333f, 0.0f, 1.0f);
252+ SetFocus(wnd);
253+ return 0;
241254 }
242- }
243-
244- glClearColor(0.75f, 0.333f, 0.0f, 1.0f);
245- SetFocus(wnd);
246- return 0;
247- }
248- else if(msg == WM_SHOWWINDOW){
249- if(parm == FALSE){
255+ case WM_SHOWWINDOW:
256+ if(parm == FALSE){
257+ DestroyWindow(wnd);
258+ return 0;
259+ }
260+ else{
261+ ShowWindow(wnd, SW_SHOWNORMAL);
262+ SetFocus(wnd);
263+ }
264+ return 0;
265+ case WM_CLOSE:
266+ return DefWindowProc(wnd, msg, parm, lparam);
267+ case WM_NCDESTROY: /* FALLTHROUGH */
268+ case WM_DESTROY:
250269 PostQuitMessage(EXIT_SUCCESS);
251- }
252- else{
253- ShowWindow(wnd, SW_SHOWNORMAL);
254- SetFocus(wnd);
255- }
256- return 0;
257- }
258- else if(msg == WM_CLOSE || msg == WM_DESTROY){
259- PostQuitMessage(EXIT_SUCCESS);
260- return 0;
261- }
262- else{
263- return DefWindowProc(wnd, msg, parm, lparam);
270+ return 0;
271+ default:
272+ return DefWindowProc(wnd, msg, parm, lparam);
264273 }
265274 }
266275
@@ -461,6 +470,9 @@ static BOOL glow_translate_event(const MSG *msg, struct Glow_Window *window,
461470 case WM_KEYUP:
462471 out_event->type = pressed ?
463472 eGlowKeyboardPressed : eGlowKeyboardReleased;
473+
474+ TranslateMessage(msg);
475+
464476 {
465477 const char c = glow_get_key_char(msg->wParam),
466478 *c_str;
@@ -501,9 +513,10 @@ static BOOL glow_translate_event(const MSG *msg, struct Glow_Window *window,
501513 window, out_event->value.mouse.xy);
502514 out_event->type = eGlowMouseMoved;
503515 return TRUE;
504- case WM_DESTROY:
505- case WM_CLOSE:
506- case WM_QUIT:
516+
517+ case WM_DESTROY: /* FALLTHROUGH */
518+ case WM_CLOSE: /* FALLTHROUGH */
519+ case WM_QUIT: /* Note that quit actually never happens right now... */
507520 out_event->type = eGlowQuit;
508521 return TRUE;
509522 default:
@@ -516,9 +529,12 @@ static BOOL glow_translate_event(const MSG *msg, struct Glow_Window *window,
516529 unsigned Glow_GetEvent(struct Glow_Window *window,
517530 struct Glow_Event *out_event){
518531 MSG msg;
532+
519533 do{
520- if(!PeekMessage(&msg, window->win, 0, 0, PM_REMOVE))
534+ if(!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
521535 return 0;
536+ }
537+
522538 DispatchMessage(&msg);
523539 }while(!glow_translate_event(&msg, window, out_event));
524540
@@ -530,8 +546,17 @@ unsigned Glow_GetEvent(struct Glow_Window *window,
530546 void Glow_WaitEvent(struct Glow_Window *window,
531547 struct Glow_Event *out_event){
532548 MSG msg;
549+
533550 do{
534- GetMessage(&msg, window->win, 0, 0);
551+ if(GetMessage(&msg, NULL, 0, 0)){
552+ DispatchMessage(&msg);
553+ }
554+ else{
555+ /* Got a WM_QUIT */
556+ out_event->type = eGlowQuit;
557+ PostQuitMessage(msg.wParam);
558+ return;
559+ }
535560 }while(!glow_translate_event(&msg, window, out_event));
536561 }
537562