4 Commits

Author SHA1 Message Date
Ray
dd19b8d2c2 REVIEWED: Requested window flags application after window initialization 2025-08-12 11:44:20 +02:00
Ray
195b968b86 Merge pull request #4837 from Andersama/support_all_window_flags_at_initialization
[rcore] Support window flags with initialization issues
2025-08-12 11:38:22 +02:00
Ray
95e4494cfe ADDED: cursorLocked variable and review required code #4940 #4955 2025-08-12 11:33:58 +02:00
99a9ecfaac [rcore] Support window flags with initialization issues
This may not be the correct approach, however this appears to work. The idea is that before modifying `CORE.Window.flags` when first creating the window we keep a copy of the flags in order to call `SetWindowState` after initialization has completed, which should behave as if `MaximizeWindow` or `MinimizeWindow`, or conceptually any other flag modifying function were called after `InitWindow`.

This pull request only performs this for the windows platform, modify as needed in the switch statement at the end for others.
2025-03-12 14:56:02 -07:00
6 changed files with 31 additions and 25 deletions

View File

@ -560,7 +560,7 @@ void EnableCursor(void)
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorLocked = false;
} }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
@ -569,7 +569,7 @@ void DisableCursor(void)
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorLocked = true;
} }
// Swap back buffer with front buffer (screen drawing) // Swap back buffer with front buffer (screen drawing)

View File

@ -1029,7 +1029,7 @@ void EnableCursor(void)
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE);
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorLocked = false;
} }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
@ -1045,7 +1045,7 @@ void DisableCursor(void)
if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorLocked = true;
} }
// Swap back buffer with front buffer (screen drawing) // Swap back buffer with front buffer (screen drawing)
@ -1363,6 +1363,9 @@ int InitPlatform(void)
// additionally auto iconify restores the hardware resolution of the monitor if the window that loses focus is a fullscreen window // additionally auto iconify restores the hardware resolution of the monitor if the window that loses focus is a fullscreen window
glfwWindowHint(GLFW_AUTO_ICONIFY, 0); glfwWindowHint(GLFW_AUTO_ICONIFY, 0);
// Window flags requested before initialization to be applied after initialization
unsigned int requetedWindowFlags = CORE.Window.flags;
// Check window creation flags // Check window creation flags
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) CORE.Window.fullscreen = true; if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) CORE.Window.fullscreen = true;
@ -1673,6 +1676,9 @@ int InitPlatform(void)
CORE.Window.position.y = posY; CORE.Window.position.y = posY;
} }
// Apply window flags requested previous to initialization
SetWindowState(requetedWindowFlags);
// Load OpenGL extensions // Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions // NOTE: GL procedures address loader is required to load extensions
rlLoadExtensions(glfwGetProcAddress); rlLoadExtensions(glfwGetProcAddress);
@ -1725,7 +1731,7 @@ int InitPlatform(void)
#if defined(__NetBSD__) #if defined(__NetBSD__)
// Workaround for NetBSD // Workaround for NetBSD
char *glfwPlatform = "X11"; char *glfwPlatform = "X11 (NetBSD)";
#else #else
char *glfwPlatform = ""; char *glfwPlatform = "";
switch (glfwGetPlatform()) switch (glfwGetPlatform())

View File

@ -1214,7 +1214,7 @@ void EnableCursor(void)
#endif #endif
platform.cursorRelative = false; platform.cursorRelative = false;
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorLocked = false;
} }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
@ -1223,7 +1223,7 @@ void DisableCursor(void)
SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE);
platform.cursorRelative = true; platform.cursorRelative = true;
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorLocked = true;
} }
// Swap back buffer with front buffer (screen drawing) // Swap back buffer with front buffer (screen drawing)

View File

@ -556,7 +556,7 @@ void EnableCursor(void)
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
platform.cursorRelative = false; platform.cursorRelative = false;
CORE.Input.Mouse.cursorHidden = false; CORE.Input.Mouse.cursorLocked = false;
} }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
@ -566,7 +566,7 @@ void DisableCursor(void)
SetMousePosition(0, 0); SetMousePosition(0, 0);
platform.cursorRelative = true; platform.cursorRelative = true;
CORE.Input.Mouse.cursorHidden = true; CORE.Input.Mouse.cursorLocked = true;
} }
#if defined(SUPPORT_DRM_CACHE) #if defined(SUPPORT_DRM_CACHE)
@ -2060,7 +2060,7 @@ static void PollMouseEvents(void)
} }
// Screen confinement // Screen confinement
if (!CORE.Input.Mouse.cursorHidden) if (!CORE.Input.Mouse.cursorLocked)
{ {
if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0; if (CORE.Input.Mouse.currentPosition.x < 0) CORE.Input.Mouse.currentPosition.x = 0;
if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x; if (CORE.Input.Mouse.currentPosition.x > CORE.Window.screen.width/CORE.Input.Mouse.scale.x) CORE.Input.Mouse.currentPosition.x = CORE.Window.screen.width/CORE.Input.Mouse.scale.x;

View File

@ -102,8 +102,6 @@ static const char cursorLUT[11][12] = {
"not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED "not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED
}; };
Vector2 lockedMousePos = { 0 };
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Internal Functions Declaration // Module Internal Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -862,7 +860,7 @@ void EnableCursor(void)
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
} }
// Disables cursor (lock cursor) // Disables cursor (lock cursor)
@ -874,7 +872,7 @@ void DisableCursor(void)
// Set cursor position in the middle // Set cursor position in the middle
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
// NOTE: CORE.Input.Mouse.cursorHidden handled by EmscriptenPointerlockCallback() // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
} }
// Swap back buffer with front buffer (screen drawing) // Swap back buffer with front buffer (screen drawing)
@ -955,7 +953,7 @@ void SetMousePosition(int x, int y)
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
if (CORE.Input.Mouse.cursorHidden) lockedMousePos = CORE.Input.Mouse.currentPosition; if (CORE.Input.Mouse.cursorLocked) CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
// NOTE: emscripten not implemented // NOTE: emscripten not implemented
glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y);
@ -966,7 +964,7 @@ void SetMouseCursor(int cursor)
{ {
if (CORE.Input.Mouse.cursor != cursor) if (CORE.Input.Mouse.cursor != cursor)
{ {
if (!CORE.Input.Mouse.cursorHidden) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]); if (!CORE.Input.Mouse.cursorLocked) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]);
CORE.Input.Mouse.cursor = cursor; CORE.Input.Mouse.cursor = cursor;
} }
@ -1573,7 +1571,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
static void MouseMoveCallback(GLFWwindow *window, double x, double y) static void MouseMoveCallback(GLFWwindow *window, double x, double y)
{ {
// If the pointer is not locked, follow the position // If the pointer is not locked, follow the position
if (!CORE.Input.Mouse.cursorHidden) if (!CORE.Input.Mouse.cursorLocked)
{ {
CORE.Input.Mouse.currentPosition.x = (float)x; CORE.Input.Mouse.currentPosition.x = (float)x;
CORE.Input.Mouse.currentPosition.y = (float)y; CORE.Input.Mouse.currentPosition.y = (float)y;
@ -1641,11 +1639,11 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
// Emscripten: Called on mouse move events // Emscripten: Called on mouse move events
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
{ {
// To emulate the GLFW_RAW_MOUSE_MOTION property. // To emulate the GLFW_RAW_MOUSE_MOTION property
if (CORE.Input.Mouse.cursorHidden) if (CORE.Input.Mouse.cursorLocked)
{ {
CORE.Input.Mouse.previousPosition.x = lockedMousePos.x - mouseEvent->movementX; CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.lockedPosition.x - mouseEvent->movementX;
CORE.Input.Mouse.previousPosition.y = lockedMousePos.y - mouseEvent->movementY; CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.lockedPosition.y - mouseEvent->movementY;
} }
return 1; // The event was consumed by the callback handler return 1; // The event was consumed by the callback handler
@ -1654,12 +1652,12 @@ static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseE
// Emscripten: Called on pointer lock events // Emscripten: Called on pointer lock events
static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData) static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData)
{ {
CORE.Input.Mouse.cursorHidden = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0); CORE.Input.Mouse.cursorLocked = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
if (CORE.Input.Mouse.cursorHidden) if (CORE.Input.Mouse.cursorLocked)
{ {
lockedMousePos = CORE.Input.Mouse.currentPosition; CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
CORE.Input.Mouse.previousPosition = lockedMousePos; CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.lockedPosition;
} }
return 1; // The event was consumed by the callback handler return 1; // The event was consumed by the callback handler

View File

@ -333,9 +333,11 @@ typedef struct CoreData {
Vector2 scale; // Mouse scaling Vector2 scale; // Mouse scaling
Vector2 currentPosition; // Mouse position on screen Vector2 currentPosition; // Mouse position on screen
Vector2 previousPosition; // Previous mouse position Vector2 previousPosition; // Previous mouse position
Vector2 lockedPosition; // Mouse position when locked
int cursor; // Tracks current mouse cursor int cursor; // Tracks current mouse cursor
bool cursorHidden; // Track if cursor is hidden bool cursorHidden; // Track if cursor is hidden
bool cursorLocked; // Track if cursor is locked (disabled)
bool cursorOnScreen; // Tracks if cursor is inside client area bool cursorOnScreen; // Tracks if cursor is inside client area
char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state char currentButtonState[MAX_MOUSE_BUTTONS]; // Registers current mouse button state