@@ -137,6 +137,7 @@ static struct {
137137 fn_mousewheel_move * onMouseWheelMove ;
138138 uint32_t width ;
139139 uint32_t height ;
140+ bool fullscreen ;
140141} glfwState ;
141142
142143static void onError (int code , const char * description ) {
@@ -163,8 +164,6 @@ static void onWindowFocus(GLFWwindow* window, int focused) {
163164
164165static void onWindowResize (GLFWwindow * window , int width , int height ) {
165166 if (glfwState .onWindowResize && width > 0 && height > 0 ) {
166- glfwState .width = width ;
167- glfwState .height = height ;
168167 glfwState .onWindowResize (width , height );
169168 }
170169}
@@ -377,29 +376,22 @@ bool os_window_open(const os_window_config* config) {
377376 glfwWindowHint (GLFW_CLIENT_API , GLFW_NO_API );
378377 glfwWindowHint (GLFW_RESIZABLE , config -> resizable );
379378
380- if (config -> width == 0 && config -> height == 0 ) {
381- glfwWindowHint (GLFW_DECORATED , GLFW_FALSE );
382- }
383-
384- bool center = config -> centered && !config -> fullscreen && config -> width > 0 && config -> height > 0 ;
379+ bool center = config -> centered && !config -> fullscreen ;
385380
386381 if (center ) {
387382 glfwWindowHint (GLFW_VISIBLE , GLFW_FALSE );
388383 }
389384
390385 GLFWmonitor * monitor = glfwGetPrimaryMonitor ();
391386 const GLFWvidmode * mode = glfwGetVideoMode (monitor );
392- uint32_t width = config -> width ? config -> width : ( uint32_t ) mode -> width ;
393- uint32_t height = config -> height ? config -> height : ( uint32_t ) mode -> height ;
387+ uint32_t width = config -> fullscreen ? ( uint32_t ) mode -> width : config -> width ;
388+ uint32_t height = config -> fullscreen ? ( uint32_t ) mode -> height : config -> height ;
394389
395390 if (config -> fullscreen ) {
396- glfwWindowHint (GLFW_RED_BITS , mode -> redBits );
397- glfwWindowHint (GLFW_GREEN_BITS , mode -> greenBits );
398- glfwWindowHint (GLFW_BLUE_BITS , mode -> blueBits );
399- glfwWindowHint (GLFW_REFRESH_RATE , mode -> refreshRate );
391+ glfwWindowHint (GLFW_DECORATED , GLFW_FALSE );
400392 }
401393
402- glfwState .window = glfwCreateWindow (width , height , config -> title , config -> fullscreen ? monitor : NULL , NULL );
394+ glfwState .window = glfwCreateWindow (width , height , config -> title , NULL , NULL );
403395
404396 if (!glfwState .window ) {
405397 return false;
@@ -429,8 +421,9 @@ bool os_window_open(const os_window_config* config) {
429421 glfwSetMouseButtonCallback (glfwState .window , onMouseButton );
430422 glfwSetCursorPosCallback (glfwState .window , onMouseMove );
431423 glfwSetScrollCallback (glfwState .window , onMouseWheelMove );
432- glfwState .width = width ;
433- glfwState .height = height ;
424+ glfwState .width = config -> width ;
425+ glfwState .height = config -> height ;
426+ glfwState .fullscreen = config -> fullscreen ;
434427 return true;
435428}
436429
@@ -446,9 +439,38 @@ bool os_window_is_focused(void) {
446439 return glfwState .window && glfwGetWindowAttrib (glfwState .window , GLFW_FOCUSED );
447440}
448441
442+ bool os_window_is_fullscreen (void ) {
443+ return glfwState .fullscreen ;
444+ }
445+
446+ void os_window_set_fullscreen (bool fullscreen ) {
447+ if (!glfwState .window ) {
448+ return ;
449+ }
450+
451+ glfwState .fullscreen = fullscreen ;
452+
453+ if (fullscreen ) {
454+ os_window_get_size (& glfwState .width , & glfwState .height );
455+ GLFWmonitor * monitor = glfwGetPrimaryMonitor ();
456+ const GLFWvidmode * mode = glfwGetVideoMode (monitor );
457+ glfwSetWindowSize (glfwState .window , mode -> width , mode -> height );
458+ glfwSetWindowAttrib (glfwState .window , GLFW_DECORATED , false);
459+ glfwSetWindowPos (glfwState .window , 0 , 0 );
460+ } else {
461+ int x , y , w , h ;
462+ int width = (int ) glfwState .width ;
463+ int height = (int ) glfwState .height ;
464+ GLFWmonitor * monitor = glfwGetPrimaryMonitor ();
465+ glfwGetMonitorWorkarea (monitor , & x , & y , & w , & h );
466+ glfwSetWindowSize (glfwState .window , width , height );
467+ glfwSetWindowAttrib (glfwState .window , GLFW_DECORATED , true);
468+ glfwSetWindowPos (glfwState .window , x + (w - width ) / 2 , y + (h - height ) / 2 );
469+ }
470+ }
471+
449472void os_window_get_size (uint32_t * width , uint32_t * height ) {
450- * width = glfwState .width ;
451- * height = glfwState .height ;
473+ glfwGetWindowSize (glfwState .window , width , height );
452474}
453475
454476float os_window_get_pixel_density (void ) {
0 commit comments