mirror of
https://github.com/raysan5/raylib.git
synced 2026-07-11 08:11:55 -04:00
Compare commits
3 Commits
7b96144716
...
2ee6a76464
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ee6a76464 | |||
| f0d3e9a5c8 | |||
| 7c284cc5bc |
@ -473,8 +473,7 @@ void SetWindowFocused(void)
|
|||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetWindowHandle() not implemented on target platform");
|
return (void *)platform.app->window; // Type: ANativeWindow*
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get number of monitors
|
// Get number of monitors
|
||||||
|
|||||||
@ -115,7 +115,7 @@ typedef struct {
|
|||||||
// Local storage for the window handle returned by glfwGetX11Window
|
// Local storage for the window handle returned by glfwGetX11Window
|
||||||
// This is needed as X11 handles are integers and may not fit inside a pointer depending on platform
|
// This is needed as X11 handles are integers and may not fit inside a pointer depending on platform
|
||||||
// Storing the handle locally and returning a pointer in GetWindowHandle allows the code to work regardless of pointer width
|
// Storing the handle locally and returning a pointer in GetWindowHandle allows the code to work regardless of pointer width
|
||||||
XID windowHandleX11;
|
Window windowHandleX11; // Underlying type: unsigned long (XID, Window)
|
||||||
#endif
|
#endif
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
||||||
@ -764,9 +764,10 @@ void SetWindowFocused(void)
|
|||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
|
void *handle = NULL;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// NOTE: Returned handle is: void *HWND (windows.h)
|
handle = glfwGetWin32Window(platform.handle); // Type: HWND
|
||||||
return glfwGetWin32Window(platform.handle);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#if defined(_GLFW_WAYLAND)
|
#if defined(_GLFW_WAYLAND)
|
||||||
@ -774,28 +775,27 @@ void *GetWindowHandle(void)
|
|||||||
int platformID = glfwGetPlatform();
|
int platformID = glfwGetPlatform();
|
||||||
if (platformID == GLFW_PLATFORM_WAYLAND)
|
if (platformID == GLFW_PLATFORM_WAYLAND)
|
||||||
{
|
{
|
||||||
return glfwGetWaylandWindow(platform.handle);
|
handle = (void *)glfwGetWaylandWindow(platform.handle); // Type: struct wl_surface*
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
platform.windowHandleX11 = glfwGetX11Window(platform.handle);
|
platform.windowHandleX11 = glfwGetX11Window(platform.handle); // Type: Window (unsigned long)
|
||||||
return &platform.windowHandleX11;
|
handle = &platform.windowHandleX11;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return glfwGetWaylandWindow(platform.handle);
|
handle = (void *)glfwGetWaylandWindow(platform.handle);
|
||||||
#endif
|
#endif
|
||||||
#elif defined(_GLFW_X11)
|
#elif defined(_GLFW_X11)
|
||||||
// Store the window handle localy and return a pointer to the variable instead
|
// Store the window handle locally and return a pointer to the variable instead
|
||||||
platform.windowHandleX11 = glfwGetX11Window(platform.handle);
|
platform.windowHandleX11 = glfwGetX11Window(platform.handle);
|
||||||
return &platform.windowHandleX11;
|
handle = &platform.windowHandleX11;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
// NOTE: Returned handle is: (objc_object *)
|
handle = (void *)glfwGetCocoaWindow(platform.handle); // Type: NSWindow*
|
||||||
return (void *)glfwGetCocoaWindow(platform.handle);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get number of monitors
|
// Get number of monitors
|
||||||
|
|||||||
@ -184,6 +184,9 @@ typedef struct {
|
|||||||
i32 surfaceWidth;
|
i32 surfaceWidth;
|
||||||
i32 surfaceHeight;
|
i32 surfaceHeight;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__linux__) && defined(RGFW_X11)
|
||||||
|
Window windowHandleX11; // Underlying type: unsigned long
|
||||||
|
#endif
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -851,15 +854,25 @@ void SetWindowFocused(void)
|
|||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
if (platform.window == NULL) return NULL;
|
void *handle = NULL;
|
||||||
|
|
||||||
#if defined(RGFW_WASM)
|
if (platform.window != NULL)
|
||||||
return (void *)&platform.window->src.ctx;
|
{
|
||||||
#elif defined(RGFW_WAYLAND)
|
#if defined(_WIN32)
|
||||||
return (void *)platform.window->src.surface;
|
handle = (void *)platform.window->src.window; // Type: HWND
|
||||||
#else
|
#elif defined(__linux__)
|
||||||
return (void *)platform.window->src.window;
|
#if defined(RGFW_X11)
|
||||||
|
platform.windowHandleX11 = platform.window->src.window; // Type: Window (unsigned long)
|
||||||
|
handle = &platform.window->src.window;
|
||||||
|
#elif defined(RGFW_WAYLAND)
|
||||||
|
handle = (void *)platform.window->src.surface; // Type: struct wl_surface*
|
||||||
|
#endif
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
handle = (void *)platform.window->src.window; // Type: id, NSWindow*
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get number of monitors
|
// Get number of monitors
|
||||||
|
|||||||
@ -56,6 +56,7 @@
|
|||||||
#include "SDL3/SDL.h"
|
#include "SDL3/SDL.h"
|
||||||
#elif defined(USING_SDL2_PROJECT)
|
#elif defined(USING_SDL2_PROJECT)
|
||||||
#include "SDL2/SDL.h"
|
#include "SDL2/SDL.h"
|
||||||
|
#include "SDL2/SDL_syswm.h" // Required to get window handlers
|
||||||
#else
|
#else
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#endif
|
#endif
|
||||||
@ -101,6 +102,13 @@ typedef struct {
|
|||||||
SDL_GameController *gamepad[MAX_GAMEPADS];
|
SDL_GameController *gamepad[MAX_GAMEPADS];
|
||||||
SDL_JoystickID gamepadId[MAX_GAMEPADS]; // Joystick instance ids, they do not start from 0
|
SDL_JoystickID gamepadId[MAX_GAMEPADS]; // Joystick instance ids, they do not start from 0
|
||||||
SDL_Cursor *cursor;
|
SDL_Cursor *cursor;
|
||||||
|
|
||||||
|
#if defined(__linux__)
|
||||||
|
// Local storage for the window handle (X11)
|
||||||
|
// NOTE: On SDL is not possible to know windowing backend at compile time, so,
|
||||||
|
// just in case, avoiding X11 specific types here
|
||||||
|
unsigned long windowHandleX11; // Underlying type for: XID, Window
|
||||||
|
#endif
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -920,9 +928,60 @@ void SetWindowFocused(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get native window handle
|
// Get native window handle
|
||||||
|
// NOTE: Handle type depends on OS and windowing system
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
return (void *)platform.window;
|
void *handle = NULL;
|
||||||
|
|
||||||
|
#if defined(USING_SDL3_PROJECT)
|
||||||
|
// REF: https://github.com/libsdl-org/SDL/blob/main/include/SDL3/SDL_video.h#L1590
|
||||||
|
SDL_PropertiesID props = SDL_GetWindowProperties(platform.window);
|
||||||
|
#if defined(_WIN32)
|
||||||
|
handle = (void *)SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL); // Type: HWND
|
||||||
|
#elif defined(__linux__)
|
||||||
|
unsigned long windowId = (unsigned long)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); // Type: unsigned long (XID, Window)
|
||||||
|
if (windowId != 0)
|
||||||
|
{
|
||||||
|
// X11 window ID
|
||||||
|
platform.windowHandleX11 = windowId;
|
||||||
|
handle = &platform.windowHandleX11;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Wayland, get display surface pointer
|
||||||
|
// NOTE: Alternative SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER
|
||||||
|
handle = (void *)SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL); // Type: struct wl_surface*
|
||||||
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
handle = (void *)SDL_GetPointerProperty(props, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL); // Type: NSWindow*
|
||||||
|
#endif
|
||||||
|
#elif defined(USING_SDL2_PROJECT)
|
||||||
|
SDL_SysWMinfo wmInfo = { 0 };
|
||||||
|
SDL_VERSION(&wmInfo.version);
|
||||||
|
if (SDL_GetWindowWMInfo(platform.window, &wmInfo))
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
handle = (void *)wmInfo.info.win.window; // Type: HWND
|
||||||
|
#elif defined(__linux__)
|
||||||
|
if (wmInfo.subsystem == SDL_SYSWM_X11)
|
||||||
|
{
|
||||||
|
// X11, get window ID (unsigned long)
|
||||||
|
platform.windowHandleX11 = (unsigned long)wmInfo.info.x11.window;
|
||||||
|
handle = &platform.windowHandleX11;
|
||||||
|
}
|
||||||
|
else if (wmInfo.subsystem == SDL_SYSWM_WAYLAND)
|
||||||
|
{
|
||||||
|
// Wayland, get display surface pointer
|
||||||
|
// NOTE: Alternative: wmInfo.info.wl.display
|
||||||
|
handle = (void *)wmInfo.info.wl.surface; // Type: struct wl_surface*
|
||||||
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
handle = (void *)wmInfo.info.cocoa.window; // Type: NSWindow*
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get number of monitors
|
// Get number of monitors
|
||||||
|
|||||||
@ -1023,7 +1023,7 @@ void SetWindowFocused(void)
|
|||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
return platform.hwnd;
|
return (void *)platform.hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetMonitorCount(void)
|
int GetMonitorCount(void)
|
||||||
@ -1257,8 +1257,9 @@ void OpenURL(const char *url)
|
|||||||
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
|
if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *cmd = (char *)RL_CALLOC(strlen(url) + 32, sizeof(char));
|
int len = strlen(url) + 32;
|
||||||
sprintf(cmd, "explorer \"%s\"", url);
|
char *cmd = (char *)RL_CALLOC(len, sizeof(char));
|
||||||
|
snprintf(cmd, len, "explorer \"%s\"", url);
|
||||||
int result = system(cmd);
|
int result = system(cmd);
|
||||||
if (result == -1) TRACELOG(LOG_WARNING, "OpenURL() child process could not be created");
|
if (result == -1) TRACELOG(LOG_WARNING, "OpenURL() child process could not be created");
|
||||||
RL_FREE(cmd);
|
RL_FREE(cmd);
|
||||||
@ -2052,8 +2053,11 @@ static void HandleMouseButton(int button, char state)
|
|||||||
static void HandleRawInput(LPARAM lparam)
|
static void HandleRawInput(LPARAM lparam)
|
||||||
{
|
{
|
||||||
RAWINPUT input = { 0 };
|
RAWINPUT input = { 0 };
|
||||||
|
UINT inputSize = 0;
|
||||||
|
|
||||||
|
if (GetRawInputData((HRAWINPUT)lparam, RID_INPUT, NULL, &inputSize, sizeof(RAWINPUTHEADER)) != 0) return;
|
||||||
|
if (inputSize > sizeof(input)) return;
|
||||||
|
|
||||||
UINT inputSize = sizeof(input);
|
|
||||||
UINT size = GetRawInputData((HRAWINPUT)lparam, RID_INPUT, &input, &inputSize, sizeof(RAWINPUTHEADER));
|
UINT size = GetRawInputData((HRAWINPUT)lparam, RID_INPUT, &input, &inputSize, sizeof(RAWINPUTHEADER));
|
||||||
|
|
||||||
if (size == (UINT)-1) TRACELOG(LOG_ERROR, "WIN32: Failed to get raw input data [ERROR: %lu]", GetLastError());
|
if (size == (UINT)-1) TRACELOG(LOG_ERROR, "WIN32: Failed to get raw input data [ERROR: %lu]", GetLastError());
|
||||||
|
|||||||
@ -2277,10 +2277,11 @@ int FileMove(const char *srcPath, const char *dstPath)
|
|||||||
int FileTextReplace(const char *fileName, const char *search, const char *replacement)
|
int FileTextReplace(const char *fileName, const char *search, const char *replacement)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
#if SUPPORT_MODULE_RTEXT
|
||||||
char *fileText = NULL;
|
char *fileText = NULL;
|
||||||
char *fileTextUpdated = { 0 };
|
char *fileTextUpdated = { 0 };
|
||||||
|
|
||||||
#if SUPPORT_MODULE_RTEXT
|
|
||||||
if (FileExists(fileName))
|
if (FileExists(fileName))
|
||||||
{
|
{
|
||||||
fileText = LoadFileText(fileName);
|
fileText = LoadFileText(fileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user