diff --git a/Makefile b/Makefile index e0aa55949..6eae5503d 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ # RGFW_WAYLAND=1 -> use wayland # NO_VULKAN=1 -> do not compile the vulkan example # NO_GLES=1 -> do not compile the gles example (on by default for non-linux OSes) +# NO_OSMESA=1 -> do not compile the osmesa example (on by default for non-linux OSes) CC = gcc AR = ar @@ -23,6 +24,7 @@ WARNINGS = -Wall -Wstrict-prototypes -Wextra -Wstrict-prototypes -Wold-style-de OS_DIR = \\ NO_GLES = 1 +NO_OSMESA = 1 detected_OS = windows OBJ_FILE = .o @@ -46,6 +48,11 @@ ifeq (,$(filter $(CC),x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc x86_64-w64-min LIB_EXT = .so OS_DIR = / NO_GLES = 0 + NO_OSMESA = 0 + endif + + ifeq (,$(filter $(detected_OS),Linux Darwin)) + detected_OS := windows endif else OS_DIR = / @@ -93,10 +100,12 @@ EXAMPLE_OUTPUTS_CUSTOM = \ examples/gl33/gl33 \ examples/portableGL/pgl \ examples/gles2/gles2 \ + examples/osmesa/osmesa \ examples/vk10/vk10 \ examples/dx11/dx11 \ examples/metal/metal \ - examples/webgpu/webgpu + examples/webgpu/webgpu \ + examples/minimal_links/minimal_links all: xdg-shell.c $(EXAMPLE_OUTPUTS) $(EXAMPLE_OUTPUTS_CUSTOM) libRGFW$(LIB_EXT) libRGFW.a @@ -116,6 +125,13 @@ else @echo gles has been disabled endif +examples/osmesa/osmesa: examples/osmesa/osmesa.c RGFW.h +ifneq ($(NO_GLES), 1) + $(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL2) -lOSMesa -o $@$(EXT) +else + @echo osmesa has been disabled +endif + examples/vk10/vk10: examples/vk10/vk10.c RGFW.h ifneq ($(NO_VULKAN), 1) glslangValidator -V examples/vk10/shaders/vert.vert -o examples/vk10/shaders/vert.h --vn vert_code @@ -150,6 +166,20 @@ else @echo webgpu is not supported on $(detected_OS) endif +examples/minimal_links/minimal_links: examples/minimal_links/minimal_links.c RGFW.h +ifeq ($(detected_OS),Linux) + $(CC) $(CFLAGS) $(WARNINGS) -I. $< -lm -o $@$(EXT) +else ifeq ($(detected_OS),windows) + $(CC) $(CFLAGS) $(WARNINGS) -I. $< -lgdi32 -o $@$(EXT) +else ifeq ($(detected_OS),Darwin) + $(CC) $(CFLAGS) $(WARNINGS) -I. $< -framework Foundation -framework AppKit -o $@$(EXT) +else ifeq ($(CC),emcc) + $(CC) $(CFLAGS) $(WARNINGS) -I. $< $(LIBS) $(LINK_GL3) -o $@$(EXT) +else + @echo not sure what this platform is +endif + + examples/microui_demo/microui_demo: examples/microui_demo/microui_demo.c RGFW.h ifneq ($(CC), emcc) $(CC) $(CFLAGS) -I. $< examples/microui_demo/microui.c $(LIBS) -o $@$(EXT) @@ -174,6 +204,9 @@ debug: all ifneq ($(NO_GLES), 1) ./examples/gles2/gles2$(EXT) endif +ifneq ($(NO_OSMESA), 1) + ./examples/gles2/gles2$(EXT) +endif ifneq ($(NO_VULKAN), 1) ./examples/vk10/vk10$(EXT) endif diff --git a/README.md b/README.md index b9fbf5fea..d8b58e8be 100755 --- a/README.md +++ b/README.md @@ -41,14 +41,14 @@ This library does not #define RGFW_IMPLEMENTATION #include "RGFW.h" -void keyfunc(RGFW_window* win, u32 key , u32 keyChar , char keyName[16], u8 lockState, u8 pressed) { - if (keycode == RGFW_Escape && pressed) { +void keyfunc(RGFW_window* win, u32 key, u32 keyChar, u8 lockState, u8 pressed) { + if (key == RGFW_Escape && pressed) { RGFW_window_setShouldClose(win); } } int main() { - RGFW_window* win = RGFW_createWindow("a window", RGFW_RECT(0, 0, 800, 600), (u16)(RGFW_CENTER | RGFW_NO_RESIZE)); + RGFW_window* win = RGFW_createWindow("a window", RGFW_RECT(0, 0, 800, 600), (u16)(RGFW_center | RGFW_noResize)); RGFW_setKeyCallback(keyfunc); // you can use callbacks like this if you want @@ -85,7 +85,7 @@ int main() { ```sh linux : gcc main.c -lX11 -lGL -lXrandr -lm -windows : gcc main.c -lopengl32 -lshell32 -lgdi32 -lwinmm -lm +windows : gcc main.c -lopengl32 -lshell32 -lgdi32 -lm macos : gcc main.c -framework Foundation -framework AppKit -framework OpenGL -framework IOKit -lm ``` diff --git a/RGFW.h b/RGFW.h index 608f1fc3b..c7675cca6 100644 --- a/RGFW.h +++ b/RGFW.h @@ -32,8 +32,7 @@ /* #define RGFW_IMPLEMENTATION - (required) makes it so the source code is included - #define RGFW_PRINT_ERRORS - (optional) makes it so RGFW prints errors when they're found - #define RGFW_DEBUG - (optional) makes it so RGFW prints debug messages + #define RGFW_DEBUG - (optional) makes it so RGFW prints debug messages anderrors when they're found #define RGFW_OSMESA - (optional) use OSmesa as backend (instead of system's opengl api + regular opengl) #define RGFW_BUFFER - (optional) just draw directly to (RGFW) window pixel buffer that is drawn to screen (the buffer is in the RGBA format) #define RGFW_EGL - (optional) use EGL for loading an OpenGL context (instead of the system's opengl api) @@ -52,13 +51,16 @@ #define RGFW_WGL_LOAD (optional) (windows only) if WGL should be loaded dynamically during runtime #define RGFW_NO_X11_CURSOR (optional) (unix only) don't use XCursor #define RGFW_NO_X11_CURSOR_PRELOAD (optional) (unix only) Use XCursor, but don't link it in code, (you'll have to link it with -lXcursor) + #define RGFW_NO_LOAD_WINMM (optional) (windows only) Use winmm (timeBeginPeriod), but don't link it in code, (you'll have to link it with -lwinmm) + #define RGFW_NO_WINMM (optional) (windows only) don't use winmm + #define RGFW_NO_IOKIT (optional) (macOS) don't use IOKit #define RGFW_NO_DPI - Do not include calculate DPI (no XRM nor libShcore included) #define RGFW_ALLOC_DROPFILES (optional) if room should be allocating for drop files (by default it's global data) - #define RGFW_MALLOC x - choose what function to use to allocate, by default the standard malloc is used - #define RGFW_CALLOC x - choose what function to use to allocate (calloc), by default the standard calloc is used - #define RGFW_FREE x - choose what function to use to allocated memory, by default the standard free is used + #define RGFW_alloc(userptr, size) x - choose what default function to use to allocate, by default the standard malloc is used + #define RGFW_free(userptr, ptr) x - choose what default function to use to allocated memory, by default the standard free is used + #define RGFW_USERPTR x - choose the default userptr sent to the malloc call, (NULL by default) #define RGFW_EXPORT - Use when building RGFW #define RGFW_IMPORT - Use when linking with RGFW (not as a single-header) @@ -166,7 +168,15 @@ int main() { #pragma comment(lib, "user32") #endif -#ifndef RGFW_MALLOC +#ifndef RGFW_UNUSED + #define RGFW_UNUSED(x) (void)(x) +#endif + +#ifndef RGFW_USERPTR + #define RGFW_USERPTR NULL +#endif + +#ifndef RGFW_ALLOC #include #ifndef __USE_POSIX199309 @@ -174,9 +184,8 @@ int main() { #endif #include - #define RGFW_MALLOC malloc - #define RGFW_CALLOC calloc - #define RGFW_FREE free + #define RGFW_ALLOC(userptr, size) (RGFW_UNUSED(userptr),malloc(size)) + #define RGFW_FREE(userptr, ptr) (RGFW_UNUSED(userptr),free(ptr)) #endif #if !_MSC_VER @@ -218,9 +227,6 @@ int main() { #define RGFW_ENUM(type, name) type name; enum #endif -#ifndef RGFW_UNUSED - #define RGFW_UNUSED(x) (void)(x); -#endif #if defined(__cplusplus) && !defined(__EMSCRIPTEN__) #ifdef __clang__ @@ -319,6 +325,7 @@ int main() { #endif #if defined(RGFW_DIRECTX) + #define OEMRESOURCE #include #include #include @@ -371,27 +378,31 @@ int main() { #endif #ifndef RGFW_ALPHA - #define RGFW_ALPHA 128 /* alpha value for RGFW_TRANSPARENT_WINDOW (WINAPI ONLY, macOS + linux don't need this) */ + #define RGFW_ALPHA 128 /* alpha value for RGFW_transparent (WINAPI ONLY, macOS + linux don't need this) */ #endif -/*! Optional arguments for making a windows */ -#define RGFW_TRANSPARENT_WINDOW (1L<<9) /*!< the window is transparent (only properly works on X11 and MacOS, although it's although for windows) */ -#define RGFW_NO_BORDER (1L<<3) /*!< the window doesn't have border */ -#define RGFW_NO_RESIZE (1L<<4) /*!< the window cannot be resized by the user */ -#define RGFW_ALLOW_DND (1L<<5) /*!< the window supports drag and drop*/ -#define RGFW_HIDE_MOUSE (1L<<6) /*! the window should hide the mouse or not (can be toggled later on) using `RGFW_window_mouseShow*/ -#define RGFW_FULLSCREEN (1L<<8) /* the window is fullscreen by default or not */ -#define RGFW_CENTER (1L<<10) /*! center the window on the screen */ -#define RGFW_OPENGL_SOFTWARE (1L<<11) /*! use OpenGL software rendering */ -#define RGFW_COCOA_MOVE_TO_RESOURCE_DIR (1L << 12) /* (cocoa only), move to resource folder */ -#define RGFW_SCALE_TO_MONITOR (1L << 13) /* scale the window to the screen */ -#define RGFW_NO_INIT_API (1L << 2) /* DO not init an API (mostly for bindings, you should use `#define RGFW_NO_API` in C */ - -#define RGFW_NO_GPU_RENDER (1L<<14) /* don't render (using the GPU based API)*/ -#define RGFW_NO_CPU_RENDER (1L<<15) /* don't render (using the CPU based buffer rendering)*/ -#define RGFW_WINDOW_HIDE (1L << 16)/* the window is hidden */ - -typedef RGFW_ENUM(u8, RGFW_event_types) { +/* + RGFW_allocator (optional) + you can ignore this if you use standard malloc/free +*/ +typedef void* (* RGFW_allocatorMallocfunc)(void* userdata, size_t size); +typedef void (* RGFW_allocatorFreefunc)(void* userdata, void* ptr); + +typedef struct RGFW_allocator { + void* userdata; + RGFW_allocatorMallocfunc alloc; + RGFW_allocatorFreefunc free; +} RGFW_allocator; + +RGFWDEF RGFW_allocator RGFW_loadAllocator(RGFW_allocator allocator); +RGFWDEF void* RGFW_alloc(size_t len); +RGFWDEF void RGFW_free(void* ptr); + +/* + regular RGFW stuff +*/ + +typedef RGFW_ENUM(u8, RGFW_eventTypes) { /*! event codes */ RGFW_noEvent = 0, /*!< no event has been sent */ RGFW_keyPressed, /* a key has been pressed */ @@ -475,7 +486,7 @@ enum RGFW_mouse_codes { #define RGFW_NUMLOCK (1L << 2) /*! gamepad button codes (based on xbox/playstation), you may need to change these values per controller */ -typedef RGFW_ENUM(u8, RGFW_gamepadcodes) { +typedef RGFW_ENUM(u8, RGFW_gamepadCodes) { RGFW_gamepadNone = 0, /*!< or PS X button */ RGFW_gamepadA, /*!< or PS X button */ RGFW_gamepadB, /*!< or PS circle button */ @@ -522,7 +533,7 @@ typedef RGFW_ENUM(u8, RGFW_gamepadcodes) { char name[128]; /*!< monitor name */ RGFW_rect rect; /*!< monitor Workarea */ float scaleX, scaleY; /*!< monitor content scale*/ - float pixelRatio; /*!< pixel ratio for monitor (1.0 for regular, 2.0 for) */ + float pixelRatio; /*!< pixel ratio for monitor (1.0 for regular, 2.0 for hiDPI) */ float physW, physH; /*!< monitor physical size in inches*/ } RGFW_monitor; @@ -539,8 +550,6 @@ typedef RGFW_ENUM(u8, RGFW_gamepadcodes) { /* NOTE: some parts of the data can represent different things based on the event (read comments in RGFW_Event struct) */ /*! Event structure for checking/getting events */ typedef struct RGFW_Event { - char keyName[16]; /*!< key name of event*/ - /*! drag and drop data */ /* 260 max paths with a max length of 260 */ #ifdef RGFW_ALLOC_DROPFILES @@ -665,7 +674,23 @@ typedef struct RGFW_window_src { #endif } RGFW_window_src; - +/*! Optional arguments for making a windows */ +typedef RGFW_ENUM(u16, RGFW_windowArgs) { + RGFW_transparent = (1L<<9), /*!< the window is transparent (only properly works on X11 and MacOS, although it's although for windows) */ + RGFW_noBorder = (1L<<3), /*!< the window doesn't have border */ + RGFW_noResize = (1L<<4), /*!< the window cannot be resized by the user */ + RGFW_allowDND = (1L<<5), /*!< the window supports drag and drop*/ + RGFW_hideMouse = (1L<<6), /*! the window should hide the mouse or not (can be toggled later on) using `RGFW_window_mouseShow*/ + RGFW_fullscreen = (1L<<8), /* the window is fullscreen by default or not */ + RGFW_center = (1L<<10), /*! center the window on the screen */ + RGFW_openglSoftware = (1L<<11), /*! use OpenGL software rendering */ + RGFW_cocoaMoveToResourceDir = (1L << 12), /* (cocoa only), move to resource folder */ + RGFW_scaleToMonitor = (1L << 13), /* scale the window to the screen */ + RGFW_noInitAPI = (1L << 2), /* DO not init an API (mostly for bindings, you should use `#define RGFW_NO_API` in C */ + RGFW_noGPURender = (1L<<14), /* don't render (using the GPU based API)*/ + RGFW_noCPURender = (1L<<15), /* don't render (using the CPU based buffer rendering)*/ + RGFW_windowHide = (1L << 16)/* the window is hidden */ +}; typedef struct RGFW_window { RGFW_window_src src; /*!< src window data */ @@ -709,7 +734,7 @@ RGFWDEF void RGFW_setBufferSize(RGFW_area size); /*!< the buffer cannot be resiz RGFWDEF RGFW_window* RGFW_createWindow( const char* name, /* name of the window */ RGFW_rect rect, /* rect of window */ - u16 args /* extra arguments (NULL / (u16)0 means no args used)*/ + RGFW_windowArgs args /* extra arguments (NULL / (u16)0 means no args used)*/ ); /*!< function to create a window struct */ /*! get the size of the screen to an area struct */ @@ -785,7 +810,7 @@ RGFWDEF void RGFW_window_restore(RGFW_window* win); /*!< restore the window from /*! if the window should have a border or not (borderless) based on bool value of `border` */ RGFWDEF void RGFW_window_setBorder(RGFW_window* win, b8 border); -/*! turn on / off dnd (RGFW_ALLOW_DND stil must be passed to the window)*/ +/*! turn on / off dnd (RGFW_allowDND stil must be passed to the window)*/ RGFWDEF void RGFW_window_setDND(RGFW_window* win, b8 allow); #ifndef RGFW_NO_PASSTHROUGH @@ -862,7 +887,7 @@ RGFWDEF b8 RGFW_window_isMaximized(RGFW_window* win); #ifndef RGFW_NO_MONITOR /* scale the window to the monitor, -this is run by default if the user uses the arg `RGFW_SCALE_TO_MONITOR` during window creation +this is run by default if the user uses the arg `RGFW_scaleToMonitor` during window creation */ RGFWDEF void RGFW_window_scaleToMonitor(RGFW_window* win); /*! get the struct of the window's monitor */ @@ -931,7 +956,7 @@ typedef void (* RGFW_dndInitfunc)(RGFW_window* win, RGFW_point point); /*! RGFW_windowRefresh, the window that needs to be refreshed */ typedef void (* RGFW_windowrefreshfunc)(RGFW_window* win); /*! RGFW_keyPressed / RGFW_keyReleased, the window that got the event, the mapped key, the physical key, the string version, the state of mod keys, if it was a press (else it's a release) */ -typedef void (* RGFW_keyfunc)(RGFW_window* win, u32 key, u32 mappedKey, char keyName[16], u8 lockState, b8 pressed); +typedef void (* RGFW_keyfunc)(RGFW_window* win, u32 key, u32 mappedKey, u8 lockState, b8 pressed); /*! RGFW_mouseButtonPressed / RGFW_mouseButtonReleased, the window that got the event, the button that was pressed, the scroll value, if it was a press (else it's a release) */ typedef void (* RGFW_mousebuttonfunc)(RGFW_window* win, u8 button, double scroll, b8 pressed); /*!gamepad /gamepad, the window that got the event, the button that was pressed, the scroll value, if it was a press (else it's a release) */ @@ -982,25 +1007,25 @@ RGFWDEF RGFW_gamepadfunc RGFW_setGamepadCallback(RGFW_gamepadfunc func); * @{ */ #ifndef RGFW_NO_THREADS - /*! threading functions*/ +/*! threading functions*/ - /*! NOTE! (for X11/linux) : if you define a window in a thread, it must be run after the original thread's window is created or else there will be a memory error */ - /* - I'd suggest you use sili's threading functions instead - if you're going to use sili - which is a good idea generally - */ +/*! NOTE! (for X11/linux) : if you define a window in a thread, it must be run after the original thread's window is created or else there will be a memory error */ +/* + I'd suggest you use sili's threading functions instead + if you're going to use sili + which is a good idea generally +*/ - #if defined(__unix__) || defined(__APPLE__) || defined(RGFW_WEBASM) - typedef void* (* RGFW_threadFunc_ptr)(void*); - #else - typedef DWORD (__stdcall *RGFW_threadFunc_ptr) (LPVOID lpThreadParameter); - #endif +#if defined(__unix__) || defined(__APPLE__) || defined(RGFW_WEBASM) + typedef void* (* RGFW_threadFunc_ptr)(void*); +#else + typedef DWORD (__stdcall *RGFW_threadFunc_ptr) (LPVOID lpThreadParameter); +#endif - RGFWDEF RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args); /*!< create a thread*/ - RGFWDEF void RGFW_cancelThread(RGFW_thread thread); /*!< cancels a thread*/ - RGFWDEF void RGFW_joinThread(RGFW_thread thread); /*!< join thread to current thread */ - RGFWDEF void RGFW_setThreadPriority(RGFW_thread thread, u8 priority); /*!< sets the priority priority */ +RGFWDEF RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args); /*!< create a thread*/ +RGFWDEF void RGFW_cancelThread(RGFW_thread thread); /*!< cancels a thread*/ +RGFWDEF void RGFW_joinThread(RGFW_thread thread); /*!< join thread to current thread */ +RGFWDEF void RGFW_setThreadPriority(RGFW_thread thread, u8 priority); /*!< sets the priority priority */ #endif /** @} */ @@ -1045,32 +1070,33 @@ RGFWDEF void RGFW_window_setCPURender(RGFW_window* win, i8 set); /*! native API functions */ #if defined(RGFW_OPENGL) || defined(RGFW_EGL) - /*! OpenGL init hints */ - RGFWDEF void RGFW_setGLStencil(i32 stencil); /*!< set stencil buffer bit size (8 by default) */ - RGFWDEF void RGFW_setGLSamples(i32 samples); /*!< set number of sampiling buffers (4 by default) */ - RGFWDEF void RGFW_setGLStereo(i32 stereo); /*!< use GL_STEREO (GL_FALSE by default) */ - RGFWDEF void RGFW_setGLAuxBuffers(i32 auxBuffers); /*!< number of aux buffers (0 by default) */ - - /*! which profile to use for the opengl verion */ - typedef RGFW_ENUM(u8, RGFW_GL_profile) { RGFW_glCore = 0, RGFW_glCompatibility }; - /*! Set OpenGL version hint (core or compatibility profile)*/ - RGFWDEF void RGFW_setGLVersion(RGFW_GL_profile profile, i32 major, i32 minor); - RGFWDEF void RGFW_setDoubleBuffer(b8 useDoubleBuffer); - RGFWDEF void* RGFW_getProcAddress(const char* procname); /*!< get native opengl proc address */ - RGFWDEF void RGFW_window_makeCurrent_OpenGL(RGFW_window* win); /*!< to be called by RGFW_window_makeCurrent */ +/*! OpenGL init hints */ +RGFWDEF void RGFW_setGLStencil(i32 stencil); /*!< set stencil buffer bit size (8 by default) */ +RGFWDEF void RGFW_setGLSamples(i32 samples); /*!< set number of sampiling buffers (4 by default) */ +RGFWDEF void RGFW_setGLStereo(i32 stereo); /*!< use GL_STEREO (GL_FALSE by default) */ +RGFWDEF void RGFW_setGLAuxBuffers(i32 auxBuffers); /*!< number of aux buffers (0 by default) */ + +/*! which profile to use for the opengl verion */ +typedef RGFW_ENUM(u8, RGFW_glProfile) { RGFW_glCore = 0, RGFW_glCompatibility }; +/*! Set OpenGL version hint (core or compatibility profile)*/ +RGFWDEF void RGFW_setGLVersion(RGFW_glProfile profile, i32 major, i32 minor); +RGFWDEF void RGFW_setDoubleBuffer(b8 useDoubleBuffer); +RGFWDEF void* RGFW_getProcAddress(const char* procname); /*!< get native opengl proc address */ +RGFWDEF void RGFW_window_makeCurrent_OpenGL(RGFW_window* win); /*!< to be called by RGFW_window_makeCurrent */ + #elif defined(RGFW_DIRECTX) - typedef struct { - IDXGIFactory* pFactory; - IDXGIAdapter* pAdapter; - ID3D11Device* pDevice; - ID3D11DeviceContext* pDeviceContext; - } RGFW_directXinfo; +typedef struct { + IDXGIFactory* pFactory; + IDXGIAdapter* pAdapter; + ID3D11Device* pDevice; + ID3D11DeviceContext* pDeviceContext; +} RGFW_directXinfo; - /* - RGFW stores a global instance of RGFW_directXinfo, - you can use this function to get a pointer the instance - */ - RGFWDEF RGFW_directXinfo* RGFW_getDirectXInfo(void); +/* + RGFW stores a global instance of RGFW_directXinfo, + you can use this function to get a pointer the instance +*/ +RGFWDEF RGFW_directXinfo* RGFW_getDirectXInfo(void); #endif /** @} */ @@ -1231,11 +1257,31 @@ typedef RGFW_ENUM(u8, RGFW_mouseIcons) { #ifdef RGFW_IMPLEMENTATION +#ifdef RGFW_DEBUG #include -#include +#endif + #include #include +/* + RGFW_allocator, (optional) + you can ignore this if you use standard malloc/free +*/ + +void* RGFW_allocatorMalloc(void* userdata, size_t size) { return RGFW_ALLOC(userdata, size); } +void RGFW_allocatorFree(void* userdata, void* ptr) { RGFW_FREE(userdata, ptr); } +RGFW_allocator RGFW_current_allocator = {RGFW_USERPTR, RGFW_allocatorMalloc, RGFW_allocatorFree}; + +RGFW_allocator RGFW_loadAllocator(RGFW_allocator allocator) { + RGFW_allocator old = RGFW_current_allocator; + RGFW_current_allocator = allocator; + return old; +} + +void* RGFW_alloc(size_t len) { return RGFW_current_allocator.alloc(RGFW_current_allocator.userdata, len); } +void RGFW_free(void* ptr) { RGFW_current_allocator.free(RGFW_current_allocator.userdata, ptr); } + /* RGFW_IMPLEMENTATION starts with generic RGFW defines @@ -1452,7 +1498,7 @@ void RGFW_mouseNotifyfuncEMPTY(RGFW_window* win, RGFW_point point, b8 status) {R void RGFW_mouseposfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);} void RGFW_dndInitfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);} void RGFW_windowrefreshfuncEMPTY(RGFW_window* win) {RGFW_UNUSED(win); } -void RGFW_keyfuncEMPTY(RGFW_window* win, u32 key, u32 mappedKey, char keyName[16], u8 lockState, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(key); RGFW_UNUSED(mappedKey); RGFW_UNUSED(keyName); RGFW_UNUSED(lockState); RGFW_UNUSED(pressed);} +void RGFW_keyfuncEMPTY(RGFW_window* win, u32 key, u32 mappedKey, u8 lockState, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(key); RGFW_UNUSED(mappedKey); RGFW_UNUSED(lockState); RGFW_UNUSED(pressed);} void RGFW_mousebuttonfuncEMPTY(RGFW_window* win, u8 button, double scroll, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(button); RGFW_UNUSED(scroll); RGFW_UNUSED(pressed);} void RGFW_gamepadButtonfuncEMPTY(RGFW_window* win, u16 gamepad, u8 button, b8 pressed){RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(button); RGFW_UNUSED(pressed); } void RGFW_gamepadAxisfuncEMPTY(RGFW_window* win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis){RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(axis); RGFW_UNUSED(axisesCount); RGFW_UNUSED(whichAxis); } @@ -1567,13 +1613,6 @@ RGFW_gamepadfunc RGFW_setGamepadCallback(RGFW_gamepadfunc func) { no more event call back defines */ -#define RGFW_ASSERT(check, str) {\ - if (!(check)) { \ - printf(str); \ - assert(check); \ - } \ -} - #define SET_ATTRIB(a, v) { \ assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \ attribs[index++] = a; \ @@ -1586,18 +1625,20 @@ void RGFW_setBufferSize(RGFW_area size) { } -RGFWDEF RGFW_window* RGFW_window_basic_init(RGFW_rect rect, u16 args); +RGFWDEF RGFW_window* RGFW_window_basic_init(RGFW_rect rect, RGFW_windowArgs args); /* do a basic initialization for RGFW_window, this is to standard it for each OS */ -RGFW_window* RGFW_window_basic_init(RGFW_rect rect, u16 args) { - RGFW_window* win = (RGFW_window*) RGFW_MALLOC(sizeof(RGFW_window)); /*!< make a new RGFW struct */ +RGFW_window* RGFW_window_basic_init(RGFW_rect rect, RGFW_windowArgs args) { + RGFW_window* win = (RGFW_window*) RGFW_alloc(sizeof(RGFW_window)); /*!< make a new RGFW struct */ /* clear out dnd info */ #ifdef RGFW_ALLOC_DROPFILES - win->event.droppedFiles = (char**) RGFW_MALLOC(sizeof(char*) * RGFW_MAX_DROPS); + win->event.droppedFiles = (char**) RGFW_alloc(sizeof(char*) * RGFW_MAX_DROPS); u32 i; - for (i = 0; i < RGFW_MAX_DROPS; i++) - win->event.droppedFiles[i] = (char*) RGFW_CALLOC(RGFW_MAX_PATH, sizeof(char)); + for (i = 0; i < RGFW_MAX_DROPS; i++) { + win->event.droppedFiles[i] = (char*) RGFW_alloc(RGFW_MAX_PATH); + memset(win->event.droppedFiles[i], 0, RGFW_MAX_PATH); + } #endif /* X11 requires us to have a display to get the screen size */ @@ -1612,7 +1653,7 @@ RGFW_window* RGFW_window_basic_init(RGFW_rect rect, u16 args) { #endif /* rect based the requested args */ - if (args & RGFW_FULLSCREEN) + if (args & RGFW_fullscreen) rect = RGFW_RECT(0, 0, screenR.w, screenR.h); /* set and init the new window's data */ @@ -1649,7 +1690,7 @@ void RGFW_setClassName(const char* name) { RGFW_className = (char*)name; } -void RGFW_clipboardFree(char* str) { RGFW_FREE(str); } +void RGFW_clipboardFree(char* str) { RGFW_free(str); } RGFW_keyState RGFW_mouseButtons[5] = { {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} }; @@ -1702,24 +1743,24 @@ void RGFW_window_makeCurrent(RGFW_window* win) { #elif defined(RGFW_OPENGL) RGFW_window_makeCurrent_OpenGL(win); #else - RGFW_UNUSED(win) + RGFW_UNUSED(win); #endif } void RGFW_window_setGPURender(RGFW_window* win, i8 set) { - if (!set && !(win->_winArgs & RGFW_NO_GPU_RENDER)) - win->_winArgs |= RGFW_NO_GPU_RENDER; + if (!set && !(win->_winArgs & RGFW_noGPURender)) + win->_winArgs |= RGFW_noGPURender; - else if (set && win->_winArgs & RGFW_NO_GPU_RENDER) - win->_winArgs ^= RGFW_NO_GPU_RENDER; + else if (set && win->_winArgs & RGFW_noGPURender) + win->_winArgs ^= RGFW_noGPURender; } void RGFW_window_setCPURender(RGFW_window* win, i8 set) { - if (!set && !(win->_winArgs & RGFW_NO_CPU_RENDER)) - win->_winArgs |= RGFW_NO_CPU_RENDER; + if (!set && !(win->_winArgs & RGFW_noCPURender)) + win->_winArgs |= RGFW_noCPURender; - else if (set && win->_winArgs & RGFW_NO_CPU_RENDER) - win->_winArgs ^= RGFW_NO_CPU_RENDER; + else if (set && win->_winArgs & RGFW_noCPURender) + win->_winArgs ^= RGFW_noCPURender; } void RGFW_window_maximize(RGFW_window* win) { @@ -1852,11 +1893,11 @@ int clock_gettime(clockid_t clk_id, struct timespec* tp); int setenv(const char *name, const char *value, int overwrite); void RGFW_window_setDND(RGFW_window* win, b8 allow) { - if (allow && !(win->_winArgs & RGFW_ALLOW_DND)) - win->_winArgs |= RGFW_ALLOW_DND; + if (allow && !(win->_winArgs & RGFW_allowDND)) + win->_winArgs |= RGFW_allowDND; - else if (!allow && (win->_winArgs & RGFW_ALLOW_DND)) - win->_winArgs ^= RGFW_ALLOW_DND; + else if (!allow && (win->_winArgs & RGFW_allowDND)) + win->_winArgs ^= RGFW_allowDND; } #endif @@ -2187,9 +2228,11 @@ void RGFW_createOpenGLContext(RGFW_window* win) { win->src.EGL_context = eglCreateContext(win->src.EGL_display, config, EGL_NO_CONTEXT, attribs); - if (win->src.EGL_context == NULL) + if (win->src.EGL_context == NULL) { + #ifdef RGFW_DEBUG fprintf(stderr, "failed to create an EGL opengl context\n"); - + #endif + } eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context); eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); } @@ -2238,25 +2281,25 @@ void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { /* OPENGL Normal / EGL defines only (no OS MESA) Ends here */ #elif defined(RGFW_OSMESA) /* OSmesa only */ -RGFWDEF void RGFW_OSMesa_reorganize(void); +RGFWDEF void RGFW_OSMesa_reorganize(RGFW_window* win); /* reorganize buffer for osmesa */ -void RGFW_OSMesa_reorganize(void) { - u8* row = (u8*) RGFW_MALLOC(win->r.w * 3); +void RGFW_OSMesa_reorganize(RGFW_window* win) { + u8* row = (u8*) RGFW_alloc(RGFW_bufferSize.w * 3); - i32 half_height = win->r.h / 2; - i32 stride = win->r.w * 3; + i32 half_height = RGFW_bufferSize.h / 2; + i32 stride = RGFW_bufferSize.w * 3; i32 y; for (y = 0; y < half_height; ++y) { i32 top_offset = y * stride; - i32 bottom_offset = (win->r.h - y - 1) * stride; + i32 bottom_offset = (RGFW_bufferSize.h - y - 1) * stride; memcpy(row, win->buffer + top_offset, stride); memcpy(win->buffer + top_offset, win->buffer + bottom_offset, stride); memcpy(win->buffer + bottom_offset, row, stride); } - RGFW_FREE(row); + RGFW_free(row); } #endif /* RGFW_OSMesa */ @@ -2478,15 +2521,15 @@ void RGFW_init_buffer(RGFW_window* win, XVisualInfo* vi) { if (RGFW_bufferSize.w == 0 && RGFW_bufferSize.h == 0) RGFW_bufferSize = RGFW_getScreenSize(); - win->buffer = (u8*)RGFW_MALLOC(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); + win->buffer = (u8*)RGFW_alloc(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); #ifdef RGFW_DEBUG printf("RGFW INFO: createing a 4 channel %i by %i buffer\n", RGFW_bufferSize.w, RGFW_bufferSize.h); #endif #ifdef RGFW_OSMESA - win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL); - OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h); + win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL); + OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, RGFW_bufferSize.w, RGFW_bufferSize.h); #endif win->src.bitmap = XCreateImage( @@ -2500,7 +2543,7 @@ void RGFW_init_buffer(RGFW_window* win, XVisualInfo* vi) { #else RGFW_UNUSED(win); /*!< if buffer rendering is not being used */ - RGFW_UNUSED(vi) + RGFW_UNUSED(vi); #endif } @@ -2553,7 +2596,7 @@ void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) { RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (i32)(r.w / 2), win->r.y + (i32)(r.h / 2))); } -RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { +RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs args) { #if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD) if (X11Cursorhandle == NULL) { #if defined(__CYGWIN__) @@ -2586,7 +2629,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { XInitThreads(); /*!< init X11 threading*/ - if (args & RGFW_OPENGL_SOFTWARE) + if (args & RGFW_openglSoftware) setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); RGFW_window* win = RGFW_window_basic_init(rect, args); @@ -2594,14 +2637,16 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { u64 event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | FocusChangeMask | LeaveWindowMask | EnterWindowMask | ExposureMask; /*!< X11 events accepted*/ #ifdef RGFW_OPENGL - u32* visual_attribs = RGFW_initFormatAttribs(args & RGFW_OPENGL_SOFTWARE); + u32* visual_attribs = RGFW_initFormatAttribs(args & RGFW_openglSoftware); i32 fbcount; GLXFBConfig* fbc = glXChooseFBConfig((Display*) win->src.display, DefaultScreen(win->src.display), (i32*) visual_attribs, &fbcount); i32 best_fbc = -1; if (fbcount == 0) { - printf("Failed to find any valid GLX visual configs\n"); + #ifdef RGFW_DEBUG + fprintf(stderr, "Failed to find any valid GLX visual configs\n"); + #endif return NULL; } @@ -2617,14 +2662,16 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf); glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLES, &samples); - if ((!(args & RGFW_TRANSPARENT_WINDOW) || vi->depth == 32) && + if ((!(args & RGFW_transparent) || vi->depth == 32) && (best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) { best_fbc = i; } } if (best_fbc == -1) { - printf("Failed to get a valid GLX visual\n"); + #ifdef RGFW_DEBUG + fprintf(stderr, "Failed to get a valid GLX visual\n"); + #endif return NULL; } @@ -2683,7 +2730,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { XSetClassHint((Display*) win->src.display, win->src.window, hint); XFree(hint); - if ((args & RGFW_NO_INIT_API) == 0) { + if ((args & RGFW_noInitAPI) == 0) { #ifdef RGFW_OPENGL /* This is the second part of setting up opengl. This is where we ask OpenGL for a specific version. */ i32 context_attribs[7] = { 0, 0, 0, 0, 0, 0, 0 }; context_attribs[0] = GLX_CONTEXT_PROFILE_MASK_ARB; @@ -2717,16 +2764,16 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { } #ifndef RGFW_NO_MONITOR - if (args & RGFW_SCALE_TO_MONITOR) + if (args & RGFW_scaleToMonitor) RGFW_window_scaleToMonitor(win); #endif - if (args & RGFW_CENTER) { + if (args & RGFW_center) { RGFW_area screenR = RGFW_getScreenSize(); RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2)); } - if (args & RGFW_NO_RESIZE) { /* make it so the user can't resize the window*/ + if (args & RGFW_noResize) { /* make it so the user can't resize the window*/ XSizeHints sh = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; sh.flags = (1L << 4) | (1L << 5); sh.min_width = sh.max_width = win->r.w; @@ -2734,10 +2781,10 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { XSetWMSizeHints((Display*) win->src.display, (Drawable) win->src.window, &sh, XA_WM_NORMAL_HINTS); - win->_winArgs |= RGFW_NO_RESIZE; + win->_winArgs |= RGFW_noResize; } - if (args & RGFW_NO_BORDER) { + if (args & RGFW_noBorder) { RGFW_window_setBorder(win, 0); } @@ -2751,7 +2798,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { /* connect the context to the window*/ #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) + if ((args & RGFW_noInitAPI) == 0) glXMakeCurrent((Display*) win->src.display, (Drawable) win->src.window, (GLXContext) win->src.ctx); #endif @@ -2761,8 +2808,8 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { XMapWindow((Display*) win->src.display, (Drawable) win->src.window); /* draw the window*/ XMoveWindow((Display*) win->src.display, (Drawable) win->src.window, win->r.x, win->r.y); /*!< move the window to it's proper cords*/ - if (args & RGFW_ALLOW_DND) { /* init drag and drop atoms and turn on drag and drop for this window */ - win->_winArgs |= RGFW_ALLOW_DND; + if (args & RGFW_allowDND) { /* init drag and drop atoms and turn on drag and drop for this window */ + win->_winArgs |= RGFW_allowDND; XdndTypeList = XInternAtom((Display*) win->src.display, "XdndTypeList", False); XdndSelection = XInternAtom((Display*) win->src.display, "XdndSelection", False); @@ -2790,7 +2837,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { } #ifdef RGFW_EGL - if ((args & RGFW_NO_INIT_API) == 0) + if ((args & RGFW_noInitAPI) == 0) RGFW_createOpenGLContext(win); #endif @@ -2903,12 +2950,6 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { win->event.keyChar = (u8)sym; - char* str = (char*)XKeysymToString(sym); - if (str != NULL) - strncpy(win->event.keyName, str, 16); - - win->event.keyName[15] = '\0'; - RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key); /* get keystate data */ @@ -2919,7 +2960,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { RGFW_updateLockState(win, (keystate.led_mask & 1), (keystate.led_mask & 2)); RGFW_keyboard[win->event.key].current = (E.type == KeyPress); - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, (E.type == KeyPress)); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, (E.type == KeyPress)); break; } case ButtonPress: @@ -3020,7 +3061,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { win->event.droppedFilesCount = 0; - if ((win->_winArgs & RGFW_ALLOW_DND) == 0) + if ((win->_winArgs & RGFW_allowDND) == 0) break; reply.xclient.window = xdnd.source; @@ -3153,7 +3194,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { break; case SelectionNotify: { /* this is only for checking for xdnd drops */ - if (E.xselection.property != XdndSelection || !(win->_winArgs | RGFW_ALLOW_DND)) + if (E.xselection.property != XdndSelection || !(win->_winArgs | RGFW_allowDND)) break; char* data; @@ -3220,7 +3261,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { line++; } path[index] = '\0'; - strncpy(win->event.droppedFiles[win->event.droppedFilesCount - 1], path, index + 1); + memcpy(win->event.droppedFiles[win->event.droppedFilesCount - 1], path, index + 1); } if (data) @@ -3316,7 +3357,7 @@ void RGFW_window_resize(RGFW_window* win, RGFW_area a) { XResizeWindow((Display*) win->src.display, (Window) win->src.window, a.w, a.h); - if (!(win->_winArgs & RGFW_NO_RESIZE)) + if (!(win->_winArgs & RGFW_noResize)) return; XSizeHints sh = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -3435,7 +3476,7 @@ void RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) i32 longCount = 2 + a.w * a.h; - u64* X11Icon = (u64*) RGFW_MALLOC(longCount * sizeof(u64)); + u64* X11Icon = (u64*) RGFW_alloc(longCount * sizeof(u64)); u64* target = X11Icon; *target++ = a.w; @@ -3468,7 +3509,7 @@ void RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) (u8*) X11Icon, longCount); - RGFW_FREE(X11Icon); + RGFW_free(X11Icon); XFlush((Display*) win->src.display); } @@ -3499,7 +3540,7 @@ void RGFW_window_setMouse(RGFW_window* win, u8* image, RGFW_area a, i32 channels XFreeCursor((Display*) win->src.display, (Cursor) cursor); XcursorImageDestroy(native); #else - RGFW_UNUSED(image) RGFW_UNUSED(a.w) RGFW_UNUSED(channels) + RGFW_UNUSED(image); RGFW_UNUSED(a.w); RGFW_UNUSED(channels); #endif } @@ -3582,8 +3623,8 @@ char* RGFW_readClipboard(size_t* size) { &format, &sizeN, &N, (unsigned char**) &data); if (target == UTF8 || target == XA_STRING) { - s = (char*)RGFW_MALLOC(sizeof(char) * sizeN); - strncpy(s, data, sizeN); + s = (char*)RGFW_alloc(sizeof(char) * sizeN); + memcpy(s, data, sizeN); s[sizeN] = '\0'; XFree(data); } @@ -3943,7 +3984,7 @@ RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) { return (RGFW_monitor){}; } - for (size_t i = 0; i < screenRes->ncrtc; i++) { + for (int i = 0; i < screenRes->ncrtc; i++) { XRRCrtcInfo* crtcInfo = XRRGetCrtcInfo(win->src.display, screenRes, screenRes->crtcs[i]); if (!crtcInfo) continue; @@ -3983,15 +4024,15 @@ void RGFW_window_swapBuffers(RGFW_window* win) { assert(win != NULL); /* clear the window*/ - if (!(win->_winArgs & RGFW_NO_CPU_RENDER)) { + if (!(win->_winArgs & RGFW_noCPURender)) { #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) + RGFW_area area = RGFW_bufferSize; #ifdef RGFW_OSMESA - RGFW_OSMesa_reorganize(); + RGFW_OSMesa_reorganize(win); #endif - RGFW_area area = RGFW_bufferSize; - #ifndef RGFW_X11_DONT_CONVERT_BGR - win->src.bitmap->data = (char*) win->buffer; + win->src.bitmap->data = (char*) win->buffer; + #if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA) u32 x, y; for (y = 0; y < (u32)win->r.h; y++) { for (x = 0; x < (u32)win->r.w; x++) { @@ -4008,7 +4049,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { #endif } - if (!(win->_winArgs & RGFW_NO_GPU_RENDER)) { + if (!(win->_winArgs & RGFW_noGPURender)) { #ifdef RGFW_EGL eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); #elif defined(RGFW_OPENGL) @@ -4066,10 +4107,10 @@ void RGFW_window_close(RGFW_window* win) { { u32 i; for (i = 0; i < RGFW_MAX_DROPS; i++) - RGFW_FREE(win->event.droppedFiles[i]); + RGFW_free(win->event.droppedFiles[i]); - RGFW_FREE(win->event.droppedFiles); + RGFW_free(win->event.droppedFiles); } #endif @@ -4111,7 +4152,7 @@ void RGFW_window_close(RGFW_window* win) { win->src.display = (Display*) 0; win->src.window = (Window) 0; - RGFW_FREE(win); /*!< free collected window data */ + RGFW_free(win); /*!< free collected window data */ } @@ -4240,9 +4281,9 @@ Wayland TODO: RGFW_dnd_init - window args: - #define RGFW_NO_RESIZE the window cannot be resized by the user - #define RGFW_ALLOW_DND the window supports drag and drop - #define RGFW_SCALE_TO_MONITOR scale the window to the screen + #define RGFW_noResize the window cannot be resized by the user + #define RGFW_allowDND the window supports drag and drop + #define RGFW_scaleToMonitor scale the window to the screen - other missing functions functions ("TODO wayland") (~30 functions) - fix buffer rendering weird behavior @@ -4336,8 +4377,10 @@ static void xdg_toplevel_configure_handler(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height, struct wl_array *states) { - RGFW_UNUSED(data); RGFW_UNUSED(toplevel); RGFW_UNUSED(states) + RGFW_UNUSED(data); RGFW_UNUSED(toplevel); RGFW_UNUSED(states); + #ifdef RGFW_DEBUG fprintf(stderr, "XDG toplevel configure: %dx%d\n", width, height); + #endif } static void xdg_toplevel_close_handler(void *data, @@ -4360,7 +4403,9 @@ static void shm_format_handler(void *data, struct wl_shm *shm, uint32_t format) { RGFW_UNUSED(data); RGFW_UNUSED(shm); + #ifdef RGFW_DEBUG fprintf(stderr, "Format %d\n", format); + #endif } static const struct wl_shm_listener shm_listener = { @@ -4506,8 +4551,7 @@ static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t ser ev.type = RGFW_keyPressed + state; ev.key = RGFW_key; ev.keyChar = (u8)keysym; - - strcpy(ev.keyName, name); + ev.repeat = RGFW_isHeld(RGFW_key_win, RGFW_key); RGFW_eventPipe_push(RGFW_key_win, ev); @@ -4591,7 +4635,9 @@ static void decoration_handle_configure(void *data, struct zxdg_toplevel_decoration_v1 *decoration, enum zxdg_toplevel_decoration_v1_mode mode) { RGFW_UNUSED(data); RGFW_UNUSED(decoration); + #ifdef RGFW_DEBUG printf("Using %s\n", get_mode_name(mode)); + #endif RGFW_current_mode = mode; } @@ -4609,12 +4655,18 @@ static void randname(char *buf) { } } +size_t wl_stringlen(char* name) { + size_t i = 0; + for (i; name[i]; i++); + return i; +} + static int anonymous_shm_open(void) { char name[] = "/RGFW-wayland-XXXXXX"; int retries = 100; do { - randname(name + strlen(name) - 6); + randname(name + wl_stringlen(name) - 6); --retries; // shm_open guarantees that O_CLOEXEC is set @@ -4647,7 +4699,7 @@ static void wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t t #ifdef RGFW_BUFFER RGFW_window* win = (RGFW_window*)data; - if ((win->_winArgs & RGFW_NO_CPU_RENDER)) + if ((win->_winArgs & RGFW_noCPURender)) return; #ifndef RGFW_X11_DONT_CONVERT_BGR @@ -4743,7 +4795,7 @@ void RGFW_init_buffer(RGFW_window* win) { #endif } -RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { +RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs args) { RGFW_window* win = RGFW_window_basic_init(rect, args); fprintf(stderr, "Warning: RGFW Wayland support is experimental\n"); @@ -4802,17 +4854,17 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { xdg_surface_set_window_geometry(win->src.xdg_surface, 0, 0, win->r.w, win->r.h); - if (!(args & RGFW_NO_BORDER)) { + if (!(args & RGFW_noBorder)) { win->src.decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( decoration_manager, win->src.xdg_toplevel); } - if (args & RGFW_CENTER) { + if (args & RGFW_center) { RGFW_area screenR = RGFW_getScreenSize(); RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2)); } - if (args & RGFW_OPENGL_SOFTWARE) + if (args & RGFW_openglSoftware) setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); wl_display_roundtrip(win->src.display); @@ -4824,7 +4876,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) { + if ((args & RGFW_noInitAPI) == 0) { win->src.window = wl_egl_window_create(win->src.surface, win->r.w, win->r.h); RGFW_createOpenGLContext(win); } @@ -4836,7 +4888,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { wl_callback_add_listener(callback, &wl_surface_frame_listener, win); wl_surface_commit(win->src.surface); - if (args & RGFW_HIDE_MOUSE) { + if (args & RGFW_hideMouse) { RGFW_window_showMouse(win, 0); } @@ -4855,7 +4907,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { } RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { - if (win->_winArgs & RGFW_WINDOW_HIDE) + if (win->_winArgs & RGFW_windowHide) return NULL; if (win->src.eventIndex == 0) { @@ -4977,14 +5029,14 @@ void RGFW_window_show(RGFW_window* win) { //wl_surface_attach(win->src.surface, win->rc., 0, 0); wl_surface_commit(win->src.surface); - if (win->_winArgs & RGFW_WINDOW_HIDE) - win->_winArgs ^= RGFW_WINDOW_HIDE; + if (win->_winArgs & RGFW_windowHide) + win->_winArgs ^= RGFW_windowHide; } void RGFW_window_hide(RGFW_window* win) { wl_surface_attach(win->src.surface, NULL, 0, 0); wl_surface_commit(win->src.surface); - win->_winArgs |= RGFW_WINDOW_HIDE; + win->_winArgs |= RGFW_windowHide; } void RGFW_window_setMouseDefault(RGFW_window* win) { @@ -5075,7 +5127,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { /* clear the window*/ #ifdef RGFW_BUFFER wl_surface_frame_done(win, NULL, 0); - if (!(win->_winArgs & RGFW_NO_GPU_RENDER)) + if (!(win->_winArgs & RGFW_noGPURender)) #endif { #ifdef RGFW_OPENGL @@ -5104,7 +5156,7 @@ void RGFW_window_close(RGFW_window* win) { #endif wl_display_disconnect(win->src.display); - RGFW_FREE(win); + RGFW_free(win); } RGFW_monitor RGFW_getPrimaryMonitor(void) { @@ -5218,8 +5270,9 @@ PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; typedef BOOL(WINAPI* PFN_wglDeleteContext)(HGLRC); typedef PROC(WINAPI* PFN_wglGetProcAddress)(LPCSTR); typedef BOOL(WINAPI* PFN_wglMakeCurrent)(HDC, HGLRC); - typedef HDC(WINAPI* PFN_wglGetCurrentDC)(); - typedef HGLRC(WINAPI* PFN_wglGetCurrentContext)(); + typedef HDC(WINAPI* PFN_wglGetCurrentDC)(void); + typedef HGLRC(WINAPI* PFN_wglGetCurrentContext)(void); + typedef BOOL(WINAPI* PFN_wglShareLists)(HGLRC, HGLRC); PFN_wglCreateContext wglCreateContextSRC; PFN_wglDeleteContext wglDeleteContextSRC; @@ -5227,14 +5280,15 @@ PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; PFN_wglMakeCurrent wglMakeCurrentSRC; PFN_wglGetCurrentDC wglGetCurrentDCSRC; PFN_wglGetCurrentContext wglGetCurrentContextSRC; + PFN_wglShareLists wglShareListsSRC; #define wglCreateContext wglCreateContextSRC #define wglDeleteContext wglDeleteContextSRC #define wglGetProcAddress wglGetProcAddressSRC #define wglMakeCurrent wglMakeCurrentSRC - #define wglGetCurrentDC wglGetCurrentDCSRC #define wglGetCurrentContext wglGetCurrentContextSRC + #define wglShareLists wglShareListsSRC #endif #ifdef RGFW_OPENGL @@ -5275,8 +5329,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) PFN_GetDpiForMonitor GetDpiForMonitorSRC = NULL; #define GetDpiForMonitor GetDpiForMonitorSRC #endif - - __declspec(dllimport) u32 __stdcall timeBeginPeriod(u32 uPeriod); + + #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM) + static HMODULE RGFW_winmm_dll = NULL; + typedef u32 (WINAPI * PFN_timeBeginPeriod)(u32); + PFN_timeBeginPeriod timeBeginPeriodSRC = NULL; + #define timeBeginPeriod timeBeginPeriodSRC + #elif !defined(RGFW_NO_WINMM) + __declspec(dllimport) u32 __stdcall timeBeginPeriod(u32 uPeriod); + #endif #ifndef RGFW_NO_XINPUT void RGFW_loadXInput(void) { @@ -5301,10 +5362,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) XInputGetKeystrokeSRC = (PFN_XInputGetKeystroke)(void*)GetProcAddress(RGFW_XInput_dll, "XInputGetKeystroke"); } - if (XInputGetStateSRC == NULL) + #ifdef RGFW_DEBUG + if (XInputGetStateSRC == NULL) { printf("RGFW ERR: Failed to load XInputGetState\n"); if (XInputGetKeystrokeSRC == NULL) printf("RGFW ERR: Failed to load XInputGetKeystroke\n"); + #endif } #endif @@ -5370,7 +5433,7 @@ void RGFW_captureCursor(RGFW_window* win, RGFW_rect rect) { RegisterRawInputDevices(&id, 1, sizeof(id)); } -RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { +RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs args) { #ifndef RGFW_NO_XINPUT if (RGFW_XInput_dll == NULL) RGFW_loadXInput(); @@ -5386,15 +5449,23 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { } #endif + #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM) + if (RGFW_winmm_dll == NULL) { + RGFW_winmm_dll = LoadLibraryA("winmm.dll"); + timeBeginPeriodSRC = (PFN_timeBeginPeriod)(void*)GetProcAddress(RGFW_winmm_dll, "timeBeginPeriod"); + } + #endif + if (wglinstance == NULL) { wglinstance = LoadLibraryA("opengl32.dll"); #ifdef RGFW_WGL_LOAD - wglCreateContextSRC = (PFN_wglCreateContext) GetProcAddress(wglinstance, "wglCreateContext"); - wglDeleteContextSRC = (PFN_wglDeleteContext) GetProcAddress(wglinstance, "wglDeleteContext"); - wglGetProcAddressSRC = (PFN_wglGetProcAddress) GetProcAddress(wglinstance, "wglGetProcAddress"); - wglMakeCurrentSRC = (PFN_wglMakeCurrent) GetProcAddress(wglinstance, "wglMakeCurrent"); - wglGetCurrentDCSRC = (PFN_wglGetCurrentDC) GetProcAddress(wglinstance, "wglGetCurrentDC"); - wglGetCurrentContextSRC = (PFN_wglGetCurrentContext) GetProcAddress(wglinstance, "wglGetCurrentContext"); + wglCreateContextSRC = (PFN_wglCreateContext) (void*)GetProcAddress(wglinstance, "wglCreateContext"); + wglDeleteContextSRC = (PFN_wglDeleteContext) (void*)GetProcAddress(wglinstance, "wglDeleteContext"); + wglGetProcAddressSRC = (PFN_wglGetProcAddress) (void*)GetProcAddress(wglinstance, "wglGetProcAddress"); + wglMakeCurrentSRC = (PFN_wglMakeCurrent) (void*)GetProcAddress(wglinstance, "wglMakeCurrent"); + wglGetCurrentDCSRC = (PFN_wglGetCurrentDC) (void*)GetProcAddress(wglinstance, "wglGetCurrentDC"); + wglGetCurrentContextSRC = (PFN_wglGetCurrentContext) (void*)GetProcAddress(wglinstance, "wglGetCurrentContext"); + wglShareListsSRC = (PFN_wglShareLists) (void*)GetProcAddress(wglinstance, "wglShareLists"); #endif } @@ -5436,10 +5507,10 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { RECT windowRect, clientRect; - if (!(args & RGFW_NO_BORDER)) { + if (!(args & RGFW_noBorder)) { window_style |= WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX; - if (!(args & RGFW_NO_RESIZE)) + if (!(args & RGFW_noResize)) window_style |= WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME; } else window_style |= WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX; @@ -5453,13 +5524,13 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { win->src.hOffset = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top); win->src.window = CreateWindowA(Class.lpszClassName, name, window_style, win->r.x, win->r.y, win->r.w, win->r.h + win->src.hOffset, 0, 0, inh, 0); - if (args & RGFW_ALLOW_DND) { - win->_winArgs |= RGFW_ALLOW_DND; + if (args & RGFW_allowDND) { + win->_winArgs |= RGFW_allowDND; RGFW_window_setDND(win, 1); } win->src.hdc = GetDC(win->src.window); - if ((args & RGFW_NO_INIT_API) == 0) { + if ((args & RGFW_noInitAPI) == 0) { #ifdef RGFW_DIRECTX assert(FAILED(CreateDXGIFactory(&__uuidof(IDXGIFactory), (void**) &RGFW_dxInfo.pFactory)) == 0); @@ -5564,22 +5635,26 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { if (wglCreateContextAttribsARB != NULL) { PIXELFORMATDESCRIPTOR pfd = {sizeof(pfd), 1, pfd_flags, PFD_TYPE_RGBA, 32, 8, PFD_MAIN_PLANE, 24, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - if (args & RGFW_OPENGL_SOFTWARE) + if (args & RGFW_openglSoftware) pfd.dwFlags |= PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED; if (wglChoosePixelFormatARB != NULL) { - i32* pixel_format_attribs = (i32*)RGFW_initFormatAttribs(args & RGFW_OPENGL_SOFTWARE); + i32* pixel_format_attribs = (i32*)RGFW_initFormatAttribs(args & RGFW_openglSoftware); int pixel_format; UINT num_formats; wglChoosePixelFormatARB(win->src.hdc, pixel_format_attribs, 0, 1, &pixel_format, &num_formats); if (!num_formats) { - printf("Failed to create a pixel format for WGL.\n"); + #ifdef RGFW_DEBUG + printf("Failed to create a pixel format for WGL.\n"); + #endif } DescribePixelFormat(win->src.hdc, pixel_format, sizeof(pfd), &pfd); if (!SetPixelFormat(win->src.hdc, pixel_format, &pfd)) { + #ifdef RGFW_DEBUG printf("Failed to set the WGL pixel format.\n"); + #endif } } @@ -5603,7 +5678,9 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { win->src.ctx = (HGLRC)wglCreateContextAttribsARB(win->src.hdc, NULL, attribs); } else { /* fall back to a default context (probably opengl 2 or something) */ + #ifdef RGFW_DEBUG fprintf(stderr, "Failed to create an accelerated OpenGL Context\n"); + #endif int pixel_format = ChoosePixelFormat(win->src.hdc, &pfd); SetPixelFormat(win->src.hdc, pixel_format, &pfd); @@ -5624,7 +5701,7 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { #endif #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) { + if ((args & RGFW_noInitAPI) == 0) { ReleaseDC(win->src.window, win->src.hdc); win->src.hdc = GetDC(win->src.window); wglMakeCurrent(win->src.hdc, win->src.ctx); @@ -5636,24 +5713,24 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { #ifndef RGFW_NO_MONITOR - if (args & RGFW_SCALE_TO_MONITOR) + if (args & RGFW_scaleToMonitor) RGFW_window_scaleToMonitor(win); #endif - if (args & RGFW_CENTER) { + if (args & RGFW_center) { RGFW_area screenR = RGFW_getScreenSize(); RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2)); } #ifdef RGFW_EGL - if ((args & RGFW_NO_INIT_API) == 0) + if ((args & RGFW_noInitAPI) == 0) RGFW_createOpenGLContext(win); #endif - if (args & RGFW_HIDE_MOUSE) + if (args & RGFW_hideMouse) RGFW_window_showMouse(win, 0); - if (args & RGFW_TRANSPARENT_WINDOW) { + if (args & RGFW_transparent) { SetWindowLong(win->src.window, GWL_EXSTYLE, GetWindowLong(win->src.window, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(win->src.window, RGB(255, 255, 255), RGFW_ALPHA, LWA_ALPHA); } @@ -5696,7 +5773,10 @@ void RGFW_window_setBorder(RGFW_window* win, u8 border) { RGFW_area RGFW_getScreenSize(void) { - return RGFW_AREA(GetDeviceCaps(GetDC(NULL), HORZRES), GetDeviceCaps(GetDC(NULL), VERTRES)); + HDC dc = GetDC(NULL); + RGFW_area area = RGFW_AREA(GetDeviceCaps(dc, HORZRES), GetDeviceCaps(dc, VERTRES)); + ReleaseDC(NULL, dc); + return area; } RGFW_point RGFW_getGlobalMousePoint(void) { @@ -5758,7 +5838,7 @@ u8 RGFW_xinput2RGFW[] = { }; static i32 RGFW_checkXInput(RGFW_window* win, RGFW_Event* e) { - RGFW_UNUSED(win) + RGFW_UNUSED(win); size_t i; for (i = 0; i < 4; i++) { XINPUT_KEYSTROKE keystroke; @@ -5916,17 +5996,17 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { win->event.droppedFilesCount = 0; win->event.droppedFilesCount = DragQueryFileW(drop, 0xffffffff, NULL, 0); - //win->event.droppedFiles = (char**)RGFW_CALLOC(win->event.droppedFilesCount, sizeof(char*)); u32 i; for (i = 0; i < win->event.droppedFilesCount; i++) { const UINT length = DragQueryFileW(drop, i, NULL, 0); - WCHAR* buffer = (WCHAR*) RGFW_CALLOC((size_t) length + 1, sizeof(WCHAR)); + WCHAR* buffer = (WCHAR*) RGFW_alloc((size_t) length + 1); + memset(buffer, 0, length + 1); DragQueryFileW(drop, i, buffer, length + 1); - strncpy(win->event.droppedFiles[i], createUTF8FromWideStringWin32(buffer), RGFW_MAX_PATH); + memcpy(win->event.droppedFiles[i], createUTF8FromWideStringWin32(buffer), RGFW_MAX_PATH); win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0'; - RGFW_FREE(buffer); + RGFW_free(buffer); } DragFinish(drop); @@ -6012,29 +6092,11 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { win->event.keyChar = (u8)charBuffer; RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key); - - static char keyName[16]; - - { - GetKeyNameTextA((LONG) msg.lParam, keyName, 16); - if ((!(GetKeyState(VK_CAPITAL) & 0x0001) && !(GetKeyState(VK_SHIFT) & 0x8000)) || - ((GetKeyState(VK_CAPITAL) & 0x0001) && (GetKeyState(VK_SHIFT) & 0x8000))) { - CharLowerBuffA(keyName, 16); - } - } - RGFW_updateLockState(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001)); - strncpy(win->event.keyName, keyName, 16); - - if (RGFW_isPressed(win, RGFW_ShiftL)) { - ToAscii((UINT) msg.wParam, MapVirtualKey((UINT) msg.wParam, MAPVK_VK_TO_CHAR), - keyboardState, (LPWORD) win->event.keyName, 0); - } - win->event.type = RGFW_keyReleased; RGFW_keyboard[win->event.key].current = 0; - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, 0); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, 0); break; } case WM_KEYDOWN: { @@ -6063,30 +6125,12 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key); - static char keyName[16]; - - { - GetKeyNameTextA((LONG) msg.lParam, keyName, 16); - - if ((!(GetKeyState(VK_CAPITAL) & 0x0001) && !(GetKeyState(VK_SHIFT) & 0x8000)) || - ((GetKeyState(VK_CAPITAL) & 0x0001) && (GetKeyState(VK_SHIFT) & 0x8000))) { - CharLowerBuffA(keyName, 16); - } - } - RGFW_updateLockState(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001)); - strncpy(win->event.keyName, keyName, 16); - - if (RGFW_isPressed(win, RGFW_ShiftL) & 0x8000) { - ToAscii((UINT) msg.wParam, MapVirtualKey((UINT) msg.wParam, MAPVK_VK_TO_CHAR), - keyboardState, (LPWORD) win->event.keyName, 0); - } - win->event.type = RGFW_keyPressed; win->event.repeat = RGFW_isPressed(win, win->event.key); RGFW_keyboard[win->event.key].current = 1; - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, 1); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, 1); break; } @@ -6320,8 +6364,8 @@ u8 RGFW_window_isMaximized(RGFW_window* win) { typedef struct { int iIndex; HMONITOR hMonitor; } RGFW_mInfo; BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - RGFW_UNUSED(hdcMonitor) - RGFW_UNUSED(lprcMonitor) + RGFW_UNUSED(hdcMonitor); + RGFW_UNUSED(lprcMonitor); RGFW_mInfo* info = (RGFW_mInfo*) dwData; if (info->hMonitor == hMonitor) @@ -6337,8 +6381,8 @@ RGFW_monitor win32CreateMonitor(HMONITOR src) { RGFW_monitor monitor; MONITORINFOEX monitorInfo; - monitorInfo.cbSize = sizeof(MONITORINFOEX ); - GetMonitorInfo(src, &monitorInfo); + monitorInfo.cbSize = sizeof(MONITORINFOEX); + GetMonitorInfoA(src, (LPMONITORINFO)&monitorInfo); RGFW_mInfo info; info.iIndex = 0; @@ -6354,7 +6398,7 @@ RGFW_monitor win32CreateMonitor(HMONITOR src) { for (deviceIndex = 0; EnumDisplayDevicesA(0, (DWORD) deviceIndex, &dd, 0); deviceIndex++) { char* deviceName = dd.DeviceName; if (EnumDisplayDevicesA(deviceName, info.iIndex, &dd, 0)) { - strncpy(monitor.name, dd.DeviceString, 128); /*!< copy the monitor's name */ + memcpy(monitor.name, dd.DeviceString, 128); /*!< copy the monitor's name */ break; } } @@ -6399,8 +6443,8 @@ RGFW_monitor win32CreateMonitor(HMONITOR src) { RGFW_monitor RGFW_monitors[6]; BOOL CALLBACK GetMonitorHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { - RGFW_UNUSED(hdcMonitor) - RGFW_UNUSED(lprcMonitor) + RGFW_UNUSED(hdcMonitor); + RGFW_UNUSED(lprcMonitor); RGFW_mInfo* info = (RGFW_mInfo*) dwData; @@ -6497,7 +6541,7 @@ HICON RGFW_loadHandleImage(RGFW_window* win, u8* src, RGFW_area a, BOOL icon) { void RGFW_window_setMouse(RGFW_window* win, u8* image, RGFW_area a, i32 channels) { assert(win != NULL); - RGFW_UNUSED(channels) + RGFW_UNUSED(channels); HCURSOR cursor = (HCURSOR) RGFW_loadHandleImage(win, image, a, FALSE); SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) cursor); @@ -6556,6 +6600,13 @@ void RGFW_window_close(RGFW_window* win) { } #endif + #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM) + if (RGFW_winmm_dll != NULL) { + FreeLibrary(RGFW_winmm_dll); + RGFW_winmm_dll = NULL; + } + #endif + if (wglinstance != NULL) { FreeLibrary(wglinstance); wglinstance = NULL; @@ -6578,26 +6629,26 @@ void RGFW_window_close(RGFW_window* win) { #ifdef RGFW_OPENGL wglDeleteContext((HGLRC) win->src.ctx); /*!< delete opengl context */ #endif - DeleteDC(win->src.hdc); /*!< delete device context */ + ReleaseDC(win->src.window, win->src.hdc); /*!< delete device context */ DestroyWindow(win->src.window); /*!< delete window */ #if defined(RGFW_OSMESA) if (win->buffer != NULL) - RGFW_FREE(win->buffer); + RGFW_free(win->buffer); #endif #ifdef RGFW_ALLOC_DROPFILES { u32 i; for (i = 0; i < RGFW_MAX_DROPS; i++) - RGFW_FREE(win->event.droppedFiles[i]); + RGFW_free(win->event.droppedFiles[i]); - RGFW_FREE(win->event.droppedFiles); + RGFW_free(win->event.droppedFiles); } #endif - RGFW_FREE(win); + RGFW_free(win); } void RGFW_window_move(RGFW_window* win, RGFW_point v) { @@ -6663,7 +6714,7 @@ void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) { void RGFW_window_setIcon(RGFW_window* win, u8* src, RGFW_area a, i32 channels) { assert(win != NULL); #ifndef RGFW_WIN95 - RGFW_UNUSED(channels) + RGFW_UNUSED(channels); HICON handle = RGFW_loadHandleImage(win, src, a, TRUE); @@ -6671,9 +6722,9 @@ void RGFW_window_setIcon(RGFW_window* win, u8* src, RGFW_area a, i32 channels) { DestroyIcon(handle); #else - RGFW_UNUSED(src) - RGFW_UNUSED(a) - RGFW_UNUSED(channels) + RGFW_UNUSED(src); + RGFW_UNUSED(a); + RGFW_UNUSED(channels); #endif } @@ -6700,7 +6751,7 @@ char* RGFW_readClipboard(size_t* size) { if (textLen == 0) return (char*) ""; - text = (char*) RGFW_MALLOC((textLen * sizeof(char)) + 1); + text = (char*) RGFW_alloc((textLen * sizeof(char)) + 1); wcstombs(text, wstr, (textLen) +1); @@ -6770,7 +6821,9 @@ void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { static void* loadSwapFunc = (void*) 1; if (loadSwapFunc == NULL) { + #ifdef RGFW_DEBUG fprintf(stderr, "wglSwapIntervalEXT not supported\n"); + #endif return; } @@ -6779,8 +6832,11 @@ void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) loadSwapFunc; } - if (wglSwapIntervalEXT(swapInterval) == FALSE) + if (wglSwapIntervalEXT(swapInterval) == FALSE) { + #ifdef RGFW_DEBUG fprintf(stderr, "Failed to set swap interval\n"); + #endif + } #else RGFW_UNUSED(swapInterval); #endif @@ -6792,7 +6848,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { //assert(win != NULL); /* clear the window*/ - if (!(win->_winArgs & RGFW_NO_CPU_RENDER)) { + if (!(win->_winArgs & RGFW_noCPURender)) { #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) #ifdef RGFW_OSMESA RGFW_OSMesa_reorganize(); @@ -6803,7 +6859,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { #endif } - if (!(win->_winArgs & RGFW_NO_GPU_RENDER)) { + if (!(win->_winArgs & RGFW_noGPURender)) { #ifdef RGFW_EGL eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); #elif defined(RGFW_OPENGL) @@ -6825,10 +6881,11 @@ char* createUTF8FromWideStringWin32(const WCHAR* source) { return NULL; } - target = (char*) RGFW_CALLOC(size, 1); + target = (char*) RGFW_alloc(size); + memset(target, 0, size); if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL)) { - RGFW_FREE(target); + RGFW_free(target); return NULL; } @@ -6838,7 +6895,9 @@ char* createUTF8FromWideStringWin32(const WCHAR* source) { static inline LARGE_INTEGER RGFW_win32_initTimer(void) { static LARGE_INTEGER frequency = {{0, 0}}; if (frequency.QuadPart == 0) { + #if !defined(RGFW_NO_WINMM) timeBeginPeriod(1); + #endif QueryPerformanceFrequency(&frequency); } @@ -6901,9 +6960,6 @@ void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { SetThreadPriority #include #include -#include -#include - typedef CGRect NSRect; typedef CGPoint NSPoint; typedef CGSize NSSize; @@ -6977,7 +7033,7 @@ typedef struct siArrayHeader { #define SI_ARRAY_HEADER(s) ((siArrayHeader*)s - 1) void* si_array_init_reserve(size_t sizeof_element, size_t count) { - siArrayHeader* ptr = (siArrayHeader*)RGFW_MALLOC(sizeof(siArrayHeader) + (sizeof_element * count)); + siArrayHeader* ptr = (siArrayHeader*)RGFW_alloc(sizeof(siArrayHeader) + (sizeof_element * count)); void* array = ptr + sizeof(siArrayHeader); siArrayHeader* header = SI_ARRAY_HEADER(array); @@ -7097,10 +7153,14 @@ id* cstrToNSStringArray(char** strs, size_t len) { return nstrs; } -const char* NSPasteboard_stringForType(id pasteboard, NSPasteboardType dataType) { +const char* NSPasteboard_stringForType(id pasteboard, NSPasteboardType dataType, size_t* len) { SEL func = sel_registerName("stringForType:"); id nsstr = NSString_stringWithUTF8String(dataType); - return NSString_to_char(((id(*)(id, SEL, id))objc_msgSend)(pasteboard, func, nsstr)); + id nsString = ((id(*)(id, SEL, id))objc_msgSend)(pasteboard, func, nsstr); + const char* str = NSString_to_char(nsString); + if (len != NULL) + *len = (size_t)((NSUInteger(*)(id, SEL))objc_msgSend)(nsString, sel_registerName("length")); + return str; } id c_array_to_NSArray(void* array, size_t len) { @@ -7272,7 +7332,7 @@ NSDragOperation draggingUpdated(id self, SEL sel, id sender) { if (win == NULL) return 0; - if (!(win->_winArgs & RGFW_ALLOW_DND)) { + if (!(win->_winArgs & RGFW_allowDND)) { return 0; } @@ -7292,7 +7352,7 @@ bool prepareForDragOperation(id self) { if (win == NULL) return true; - if (!(win->_winArgs & RGFW_ALLOW_DND)) { + if (!(win->_winArgs & RGFW_allowDND)) { return false; } @@ -7340,7 +7400,7 @@ bool performDragOperation(id self, SEL sel, id sender) { for (int i = 0; i < count; i++) { id fileURL = objc_msgSend_arr(fileURLs, sel_registerName("objectAtIndex:"), i); const char *filePath = ((const char* (*)(id, SEL))objc_msgSend)(fileURL, sel_registerName("UTF8String")); - strncpy(win->event.droppedFiles[i], filePath, RGFW_MAX_PATH); + memcpy(win->event.droppedFiles[i], filePath, RGFW_MAX_PATH); win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0'; } win->event.droppedFilesCount = count; @@ -7356,6 +7416,10 @@ bool performDragOperation(id self, SEL sel, id sender) { return false; } +#ifndef RGFW_NO_IOKIT +#include +#include + IOHIDDeviceRef RGFW_osxControllers[4] = {NULL}; int findControllerIndex(IOHIDDeviceRef device) { @@ -7513,6 +7577,45 @@ void RGFW__osxDeviceRemovedCallback(void *context, IOReturn result, void *sender RGFW_gamepadCount--; } +RGFWDEF void RGFW_osxInitIOKit(void); +void RGFW_osxInitIOKit(void) { + IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); + if (!hidManager) { + fprintf(stderr, "Failed to create IOHIDManager.\n"); + return; + } + + CFMutableDictionaryRef matchingDictionary = CFDictionaryCreateMutable( + kCFAllocatorDefault, + 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks + ); + if (!matchingDictionary) { + fprintf(stderr, "Failed to create matching dictionary.\n"); + CFRelease(hidManager); + return; + } + + CFDictionarySetValue( + matchingDictionary, + CFSTR(kIOHIDDeviceUsagePageKey), + CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, (int[]){kHIDPage_GenericDesktop}) + ); + + IOHIDManagerSetDeviceMatching(hidManager, matchingDictionary); + + IOHIDManagerRegisterDeviceMatchingCallback(hidManager, RGFW__osxDeviceAddedCallback, NULL); + IOHIDManagerRegisterDeviceRemovalCallback(hidManager, RGFW__osxDeviceRemovedCallback, NULL); + + IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + + IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); + + // Execute the run loop once in order to register any initially-attached joysticks + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); +} +#endif void NSMoveToResourceDir(void) { /* sourced from glfw */ @@ -7590,7 +7693,7 @@ void RGFW_init_buffer(RGFW_window* win) { if (RGFW_bufferSize.w == 0 && RGFW_bufferSize.h == 0) RGFW_bufferSize = RGFW_getScreenSize(); - win->buffer = RGFW_MALLOC(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); + win->buffer = RGFW_alloc(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); #ifdef RGFW_OSMESA win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL); OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h); @@ -7608,50 +7711,11 @@ void* RGFW_cocoaGetLayer(void) { return objc_msgSend_class((id)objc_getClass("CAMetalLayer"), (SEL)sel_registerName("layer")); } -RGFWDEF void RGFW_osxInitIOKit(void); -void RGFW_osxInitIOKit(void) { - IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - if (!hidManager) { - fprintf(stderr, "Failed to create IOHIDManager.\n"); - return; - } - - CFMutableDictionaryRef matchingDictionary = CFDictionaryCreateMutable( - kCFAllocatorDefault, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks - ); - if (!matchingDictionary) { - fprintf(stderr, "Failed to create matching dictionary.\n"); - CFRelease(hidManager); - return; - } - - CFDictionarySetValue( - matchingDictionary, - CFSTR(kIOHIDDeviceUsagePageKey), - CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, (int[]){kHIDPage_GenericDesktop}) - ); - - IOHIDManagerSetDeviceMatching(hidManager, matchingDictionary); - - IOHIDManagerRegisterDeviceMatchingCallback(hidManager, RGFW__osxDeviceAddedCallback, NULL); - IOHIDManagerRegisterDeviceRemovalCallback(hidManager, RGFW__osxDeviceRemovedCallback, NULL); - - IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - - IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); - - // Execute the run loop once in order to register any initially-attached joysticks - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); -} - NSPasteboardType const NSPasteboardTypeURL = "public.url"; NSPasteboardType const NSPasteboardTypeFileURL = "public.file-url"; -RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { +RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs args) { static u8 RGFW_loaded = 0; /* NOTE(EimaMei): Why does Apple hate good code? Like wtf, who thought of methods being a great idea??? @@ -7673,7 +7737,9 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { ((void (*)(id, SEL, NSUInteger))objc_msgSend) (NSApp, sel_registerName("setActivationPolicy:"), NSApplicationActivationPolicyRegular); - RGFW_osxInitIOKit(); + #ifndef RGFW_NO_IOKIT + RGFW_osxInitIOKit(); + #endif } RGFW_window* win = RGFW_window_basic_init(rect, args); @@ -7688,9 +7754,9 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { NSBackingStoreType macArgs = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSBackingStoreBuffered | NSWindowStyleMaskTitled; - if (!(args & RGFW_NO_RESIZE)) + if (!(args & RGFW_noResize)) macArgs |= NSWindowStyleMaskResizable; - if (!(args & RGFW_NO_BORDER)) + if (!(args & RGFW_noBorder)) macArgs |= NSWindowStyleMaskTitled; else macArgs = NSWindowStyleMaskBorderless; @@ -7706,14 +7772,14 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { objc_msgSend_void_id((id)win->src.window, sel_registerName("setTitle:"), str); #ifdef RGFW_EGL - if ((args & RGFW_NO_INIT_API) == 0) + if ((args & RGFW_noInitAPI) == 0) RGFW_createOpenGLContext(win); #endif #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) { - void* attrs = RGFW_initFormatAttribs(args & RGFW_OPENGL_SOFTWARE); + if ((args & RGFW_noInitAPI) == 0) { + void* attrs = RGFW_initFormatAttribs(args & RGFW_openglSoftware); void* format = NSOpenGLPixelFormat_initWithAttributes((uint32_t*)attrs); if (format == NULL) { @@ -7747,13 +7813,13 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { objc_msgSend_void_id((id)win->src.window, sel_registerName("setContentView:"), win->src.view); #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) + if ((args & RGFW_noInitAPI) == 0) objc_msgSend_void(win->src.ctx, sel_registerName("makeCurrentContext")); #endif - if (args & RGFW_TRANSPARENT_WINDOW) { + if (args & RGFW_transparent) { #ifdef RGFW_OPENGL - if ((args & RGFW_NO_INIT_API) == 0) { + if ((args & RGFW_noInitAPI) == 0) { i32 opacity = 0; #define NSOpenGLCPSurfaceOpacity 236 NSOpenGLContext_setValues((id)win->src.ctx, &opacity, NSOpenGLCPSurfaceOpacity); @@ -7769,19 +7835,19 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { RGFW_init_buffer(win); #ifndef RGFW_NO_MONITOR - if (args & RGFW_SCALE_TO_MONITOR) + if (args & RGFW_scaleToMonitor) RGFW_window_scaleToMonitor(win); #endif - if (args & RGFW_CENTER) { + if (args & RGFW_center) { RGFW_area screenR = RGFW_getScreenSize(); RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2)); } - if (args & RGFW_HIDE_MOUSE) + if (args & RGFW_hideMouse) RGFW_window_showMouse(win, 0); - if (args & RGFW_COCOA_MOVE_TO_RESOURCE_DIR) + if (args & RGFW_cocoaMoveToResourceDir) NSMoveToResourceDir(); Class delegateClass = objc_allocateClassPair(objc_getClass("NSObject"), "WindowDelegate", 0); @@ -7809,8 +7875,8 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { objc_msgSend_void_id((id)win->src.window, sel_registerName("setDelegate:"), delegate); - if (args & RGFW_ALLOW_DND) { - win->_winArgs |= RGFW_ALLOW_DND; + if (args & RGFW_allowDND) { + win->_winArgs |= RGFW_allowDND; NSPasteboardType types[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString}; NSregisterForDraggedTypes((id)win->src.window, types, 3); @@ -7848,7 +7914,7 @@ void RGFW_window_setBorder(RGFW_window* win, u8 border) { if (!border) { storeType = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable; } - if (!(win->_winArgs & RGFW_NO_RESIZE)) { + if (!(win->_winArgs & RGFW_noResize)) { storeType |= NSWindowStyleMaskResizable; } @@ -8025,6 +8091,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { return &win->event; } + #ifndef RGFW_NO_IOKIT if (RGFW_gamepadEventQueueCount && win == RGFW_root) { static u8 index = 0; @@ -8045,6 +8112,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows")); return &win->event; } + #endif id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc")); eventPool = objc_msgSend_id(eventPool, sel_registerName("init")); @@ -8119,12 +8187,10 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current; win->event.type = RGFW_keyPressed; - char* str = (char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); - strncpy(win->event.keyName, str, 16); win->event.repeat = RGFW_isPressed(win, win->event.key); RGFW_keyboard[win->event.key].current = 1; - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, 1); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, 1); break; } @@ -8142,11 +8208,9 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current; win->event.type = RGFW_keyReleased; - char* str = (char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); - strncpy(win->event.keyName, str, 16); RGFW_keyboard[win->event.key].current = 0; - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, 0); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, 0); break; } @@ -8185,7 +8249,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { } } - RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyName, win->event.lockState, win->event.type == RGFW_keyPressed); + RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.lockState, win->event.type == RGFW_keyPressed); break; } @@ -8436,7 +8500,7 @@ void RGFW_releaseCursor(RGFW_window* win) { } void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) { - RGFW_UNUSED(win) + RGFW_UNUSED(win); CGWarpMouseCursorPosition(CGPointMake(r.x + (r.w / 2), r.y + (r.h / 2))); CGAssociateMouseAndMouseCursorPosition(0); @@ -8510,7 +8574,7 @@ RGFW_monitor RGFW_NSCreateMonitor(CGDirectDisplayID display, id screen) { RGFW_monitor monitor; const char name[] = "MacOS\0"; - strncpy(monitor.name, name, 6); + memcpy(monitor.name, name, 6); CGRect bounds = CGDisplayBounds(display); monitor.rect = RGFW_RECT((int) bounds.origin.x, (int) bounds.origin.y, (int) bounds.size.width, (int) bounds.size.height); @@ -8568,18 +8632,13 @@ RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) { } char* RGFW_readClipboard(size_t* size) { - char* clip = (char*)NSPasteboard_stringForType(NSPasteboard_generalPasteboard(), NSPasteboardTypeString); - - size_t clip_len = 1; + size_t clip_len; + char* clip = (char*)NSPasteboard_stringForType(NSPasteboard_generalPasteboard(), NSPasteboardTypeString, &clip_len); - if (clip != NULL) { - clip_len = strlen(clip) + 1; - } - - char* str = (char*)RGFW_MALLOC(sizeof(char) * clip_len); + char* str = (char*)RGFW_alloc(sizeof(char) * clip_len); if (clip != NULL) { - strncpy(str, clip, clip_len); + memcpy(str, clip, clip_len); } str[clip_len] = '\0'; @@ -8645,7 +8704,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { assert(win != NULL); /* clear the window*/ - if (!(win->_winArgs & RGFW_NO_CPU_RENDER)) { + if (!(win->_winArgs & RGFW_noCPURender)) { #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) #ifdef RGFW_OSMESA RGFW_OSMesa_reorganize(); @@ -8676,7 +8735,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { #endif } - if (!(win->_winArgs & RGFW_NO_GPU_RENDER)) { + if (!(win->_winArgs & RGFW_noGPURender)) { #ifdef RGFW_EGL eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); #elif defined(RGFW_OPENGL) @@ -8693,10 +8752,10 @@ void RGFW_window_close(RGFW_window* win) { { u32 i; for (i = 0; i < RGFW_MAX_DROPS; i++) - RGFW_FREE(win->event.droppedFiles[i]); + RGFW_free(win->event.droppedFiles[i]); - RGFW_FREE(win->event.droppedFiles); + RGFW_free(win->event.droppedFiles); } #endif @@ -8705,7 +8764,7 @@ void RGFW_window_close(RGFW_window* win) { NSRelease(win->src.image); #endif - RGFW_FREE(win); + RGFW_free(win); } u64 RGFW_getTimeNS(void) { @@ -9088,7 +9147,6 @@ void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyEvent(char* key, char* code, b8 press) { } RGFW_events[RGFW_eventLen].type = press ? RGFW_keyPressed : RGFW_keyReleased; - memcpy(RGFW_events[RGFW_eventLen].keyName, key, 16); RGFW_events[RGFW_eventLen].key = physicalKey; RGFW_events[RGFW_eventLen].keyChar = mappedKey; RGFW_events[RGFW_eventLen].lockState = 0; @@ -9099,12 +9157,12 @@ void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyEvent(char* key, char* code, b8 press) { RGFW_keyCallback(RGFW_root, physicalKey, mappedKey, RGFW_events[RGFW_eventLen].keyName, 0, press); - RGFW_FREE(key); - RGFW_FREE(code); + RGFW_free(key); + RGFW_free(code); } void EMSCRIPTEN_KEEPALIVE Emscripten_onDrop(size_t count) { - if (!(RGFW_root->_winArgs & RGFW_ALLOW_DND)) + if (!(RGFW_root->_winArgs & RGFW_allowDND)) return; RGFW_events[RGFW_eventLen].droppedFilesCount = count; @@ -9140,7 +9198,7 @@ void RGFW_init_buffer(RGFW_window* win) { if (RGFW_bufferSize.w == 0 && RGFW_bufferSize.h == 0) RGFW_bufferSize = RGFW_getScreenSize(); - win->buffer = RGFW_MALLOC(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); + win->buffer = RGFW_alloc(RGFW_bufferSize.w * RGFW_bufferSize.h * 4); #ifdef RGFW_OSMESA win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL); OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h); @@ -9152,12 +9210,11 @@ void RGFW_init_buffer(RGFW_window* win) { void EMSCRIPTEN_KEEPALIVE RGFW_makeSetValue(size_t index, char* file) { /* This seems like a terrible idea, don't replicate this unless you hate yourself or the OS */ - /* TODO: find a better way to do this, - strcpy doesn't seem to work, maybe because of asyncio + /* TODO: find a better way to do this */ RGFW_events[RGFW_eventLen].type = RGFW_dnd; - strcpy((char*)RGFW_events[RGFW_eventLen].droppedFiles[index], file); + memcpy((char*)RGFW_events[RGFW_eventLen].droppedFiles[index], file, RGFW_MAX_PATH); } #include @@ -9175,8 +9232,8 @@ void EMSCRIPTEN_KEEPALIVE RGFW_writeFile(const char *path, const char *data, siz fclose(file); } -RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { - RGFW_UNUSED(name) +RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs args) { + RGFW_UNUSED(name); RGFW_UNUSED(RGFW_initFormatAttribs); @@ -9236,8 +9293,8 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { emscripten_set_gamepadconnected_callback(NULL, 1, Emscripten_on_gamepad); emscripten_set_gamepaddisconnected_callback(NULL, 1, Emscripten_on_gamepad); - if (args & RGFW_ALLOW_DND) { - win->_winArgs |= RGFW_ALLOW_DND; + if (args & RGFW_allowDND) { + win->_winArgs |= RGFW_allowDND; } EM_ASM({ @@ -9311,11 +9368,11 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { RGFW_root = win; - if (args & RGFW_HIDE_MOUSE) { + if (args & RGFW_hideMouse) { RGFW_window_showMouse(win, 0); } - if (args & RGFW_FULLSCREEN) { + if (args & RGFW_fullscreen) { RGFW_window_resize(win, RGFW_getScreenSize()); } @@ -9414,14 +9471,14 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { } void RGFW_window_resize(RGFW_window* win, RGFW_area a) { - RGFW_UNUSED(win) + RGFW_UNUSED(win); emscripten_set_canvas_element_size("#canvas", a.w, a.h); } /* NOTE: I don't know if this is possible */ void RGFW_window_moveMouse(RGFW_window* win, RGFW_point v) { RGFW_UNUSED(win); RGFW_UNUSED(v); } /* this one might be possible but it looks iffy */ -void RGFW_window_setMouse(RGFW_window* win, u8* image, RGFW_area a, i32 channels) { RGFW_UNUSED(win); RGFW_UNUSED(channels) RGFW_UNUSED(a) RGFW_UNUSED(image) } +void RGFW_window_setMouse(RGFW_window* win, u8* image, RGFW_area a, i32 channels) { RGFW_UNUSED(win); RGFW_UNUSED(channels); RGFW_UNUSED(a); RGFW_UNUSED(image); } const char RGFW_CURSORS[11][12] = { "default", @@ -9438,7 +9495,7 @@ const char RGFW_CURSORS[11][12] = { }; void RGFW_window_setMouseStandard(RGFW_window* win, u8 mouse) { - RGFW_UNUSED(win) + RGFW_UNUSED(win); EM_ASM( { document.getElementById("canvas").style.cursor = UTF8ToString($0); }, RGFW_CURSORS[mouse]); } @@ -9486,7 +9543,7 @@ void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) { } void RGFW_writeClipboard(const char* text, u32 textLen) { - RGFW_UNUSED(textLen) + RGFW_UNUSED(textLen); EM_ASM({ navigator.clipboard.writeText(UTF8ToString($0)); }, text); } @@ -9497,11 +9554,12 @@ char* RGFW_readClipboard(size_t* size) { I'm not sure if this is possible do the the async stuff */ + size_t len = 0; if (size != NULL) - *size = 0; + *size = len; - char* str = (char*)RGFW_MALLOC(1); - str[0] = '\0'; + char* str = (char*)RGFW_alloc(1); + str[len] = '\0'; return str; } @@ -9510,7 +9568,7 @@ void RGFW_window_swapBuffers(RGFW_window* win) { RGFW_UNUSED(win); #ifdef RGFW_BUFFER - if (!(win->_winArgs & RGFW_NO_CPU_RENDER)) { + if (!(win->_winArgs & RGFW_noCPURender)) { glEnable(GL_TEXTURE_2D); GLuint texture; @@ -9570,7 +9628,7 @@ void RGFW_window_close(RGFW_window* win) { emscripten_webgl_destroy_context(win->src.ctx); #endif - RGFW_FREE(win); + RGFW_free(win); } int RGFW_innerWidth(void) { return EM_ASM_INT({ return window.innerWidth; }); } @@ -9616,19 +9674,19 @@ void RGFW_window_setName(RGFW_window* win, char* name) { /* unsupported functions */ RGFW_monitor* RGFW_getMonitors(void) { return NULL; } RGFW_monitor RGFW_getPrimaryMonitor(void) { return (RGFW_monitor){}; } -void RGFW_window_move(RGFW_window* win, RGFW_point v) { RGFW_UNUSED(win) RGFW_UNUSED(v) } -void RGFW_window_setMinSize(RGFW_window* win, RGFW_area a) { RGFW_UNUSED(win) RGFW_UNUSED(a) } -void RGFW_window_setMaxSize(RGFW_window* win, RGFW_area a) { RGFW_UNUSED(win) RGFW_UNUSED(a) } -void RGFW_window_minimize(RGFW_window* win) { RGFW_UNUSED(win)} -void RGFW_window_restore(RGFW_window* win) { RGFW_UNUSED(win) } -void RGFW_window_setBorder(RGFW_window* win, b8 border) { RGFW_UNUSED(win) RGFW_UNUSED(border) } -void RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) { RGFW_UNUSED(win) RGFW_UNUSED(icon) RGFW_UNUSED(a) RGFW_UNUSED(channels) } -void RGFW_window_hide(RGFW_window* win) { RGFW_UNUSED(win) } -void RGFW_window_show(RGFW_window* win) {RGFW_UNUSED(win) } -b8 RGFW_window_isHidden(RGFW_window* win) { RGFW_UNUSED(win) return 0; } -b8 RGFW_window_isMinimized(RGFW_window* win) { RGFW_UNUSED(win) return 0; } -b8 RGFW_window_isMaximized(RGFW_window* win) { RGFW_UNUSED(win) return 0; } -RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) { RGFW_UNUSED(win) return (RGFW_monitor){}; } +void RGFW_window_move(RGFW_window* win, RGFW_point v) { RGFW_UNUSED(win); RGFW_UNUSED(v); } +void RGFW_window_setMinSize(RGFW_window* win, RGFW_area a) { RGFW_UNUSED(win); RGFW_UNUSED(a); } +void RGFW_window_setMaxSize(RGFW_window* win, RGFW_area a) { RGFW_UNUSED(win); RGFW_UNUSED(a); } +void RGFW_window_minimize(RGFW_window* win) { RGFW_UNUSED(win); } +void RGFW_window_restore(RGFW_window* win) { RGFW_UNUSED(win); } +void RGFW_window_setBorder(RGFW_window* win, b8 border) { RGFW_UNUSED(win); RGFW_UNUSED(border); } +void RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) { RGFW_UNUSED(win); RGFW_UNUSED(icon); RGFW_UNUSED(a); RGFW_UNUSED(channels); } +void RGFW_window_hide(RGFW_window* win) { RGFW_UNUSED(win); } +void RGFW_window_show(RGFW_window* win) {RGFW_UNUSED(win); } +b8 RGFW_window_isHidden(RGFW_window* win) { RGFW_UNUSED(win); return 0; } +b8 RGFW_window_isMinimized(RGFW_window* win) { RGFW_UNUSED(win); return 0; } +b8 RGFW_window_isMaximized(RGFW_window* win) { RGFW_UNUSED(win); return 0; } +RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) { RGFW_UNUSED(win); return (RGFW_monitor){}; } #endif /* end of web asm defines */ diff --git a/examples/basic/basic.c b/examples/basic/basic.c index 920d5b750..9b5bf152c 100644 --- a/examples/basic/basic.c +++ b/examples/basic/basic.c @@ -29,7 +29,7 @@ RGFW_window* win2; int main(void) { RGFW_setClassName("RGFW Basic"); - RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(500, 500, 500, 500), RGFW_ALLOW_DND | RGFW_CENTER); + RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(500, 500, 500, 500), RGFW_allowDND | RGFW_center); RGFW_window_makeCurrent(win); RGFW_window_setIcon(win, icon, RGFW_AREA(3, 3), 4); diff --git a/examples/buffer/buffer.c b/examples/buffer/buffer.c index 9b522c3db..1e86d485b 100644 --- a/examples/buffer/buffer.c +++ b/examples/buffer/buffer.c @@ -65,7 +65,7 @@ void drawRect(RGFW_window* win, RGFW_rect r, u8 color[4]) { } int main(void) { - RGFW_window* win = RGFW_createWindow("Basic buffer example", RGFW_RECT(0, 0, 500, 500), RGFW_CENTER | RGFW_TRANSPARENT_WINDOW); + RGFW_window* win = RGFW_createWindow("Basic buffer example", RGFW_RECT(0, 0, 500, 500), RGFW_center| RGFW_transparent); screenSize = RGFW_getScreenSize(); diff --git a/examples/callbacks/callbacks.c b/examples/callbacks/callbacks.c index 67f5d2caf..9f29df888 100644 --- a/examples/callbacks/callbacks.c +++ b/examples/callbacks/callbacks.c @@ -59,12 +59,12 @@ void windowrefreshfunc(RGFW_window* win) { printf("refresh\n"); } -void keyfunc(RGFW_window* win, u32 physicalKey, u32 mappedKey, char keyName[16], u8 lockState, u8 pressed) { +void keyfunc(RGFW_window* win, u32 physicalKey, u32 mappedKey, u8 lockState, u8 pressed) { if (window != win) return; if (pressed) - printf("key pressed : %i (%c) mapped : %i (%c): %s with lockState : %i\n", physicalKey, physicalKey, mappedKey, mappedKey, keyName, lockState); + printf("key pressed : %i (%c) mapped : %i (%c): %s with lockState : %i\n", physicalKey, physicalKey, mappedKey, mappedKey, lockState); else - printf("key released : %i (%c) mapped: %i (%c): %s with lockState : %i\n", physicalKey, physicalKey, mappedKey, mappedKey, keyName, lockState); + printf("key released : %i (%c) mapped: %i (%c): %s with lockState : %i\n", physicalKey, physicalKey, mappedKey, mappedKey, lockState); } void mousebuttonfunc(RGFW_window* win, u8 button, double scroll, u8 pressed) { @@ -82,7 +82,7 @@ void mousebuttonfunc(RGFW_window* win, u8 button, double scroll, u8 pressed) { int main(void) { - window = RGFW_createWindow("RGFW Callbacks", RGFW_RECT(500, 500, 500, 500), (u64)RGFW_CENTER | RGFW_ALLOW_DND); + window = RGFW_createWindow("RGFW Callbacks", RGFW_RECT(500, 500, 500, 500), RGFW_center | RGFW_allowDND); RGFW_setWindowMoveCallback(windowmovefunc); RGFW_setWindowResizeCallback(windowresizefunc); diff --git a/examples/dx11/dx11.c b/examples/dx11/dx11.c index 4443d25fa..77e47dcad 100644 --- a/examples/dx11/dx11.c +++ b/examples/dx11/dx11.c @@ -28,7 +28,7 @@ const char* shaderString = MULTILINE_STR( ); int main(void) { - RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(0, 0, 500, 500), RGFW_CENTER); + RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(0, 0, 500, 500), RGFW_center); RGFW_window_makeCurrent(win); RGFW_directXinfo* dxInfo = RGFW_getDirectXInfo(); diff --git a/examples/events/events.c b/examples/events/events.c index dc7cfbf79..e118ac418 100644 --- a/examples/events/events.c +++ b/examples/events/events.c @@ -2,7 +2,7 @@ #include "RGFW.h" int main(void) { - RGFW_window* win = RGFW_createWindow("RGFW Events", RGFW_RECT(500, 500, 500, 500), (u64)RGFW_CENTER | RGFW_ALLOW_DND | RGFW_TRANSPARENT_WINDOW); + RGFW_window* win = RGFW_createWindow("RGFW Events", RGFW_RECT(500, 500, 500, 500), RGFW_center | RGFW_allowDND | RGFW_transparent); while (RGFW_window_shouldClose(win) == 0) { glClearColor(0.25, 0, 0.15, 0.25); diff --git a/examples/first-person-camera/camera.c b/examples/first-person-camera/camera.c index cb1629734..449f8c5cd 100644 --- a/examples/first-person-camera/camera.c +++ b/examples/first-person-camera/camera.c @@ -10,7 +10,7 @@ RGFWDEF void update_camera(void); RGFWDEF void glPerspective(double fovY, double aspect, double zNear, double zFar); int main(void) { - RGFW_window* win = RGFW_createWindow("First person camera", RGFW_RECT(0, 0, 800, 450), RGFW_CENTER | RGFW_NO_RESIZE ); + RGFW_window* win = RGFW_createWindow("First person camera", RGFW_RECT(0, 0, 800, 450), RGFW_center | RGFW_noResize ); RGFW_window_showMouse(win, 0); glEnable(GL_DEPTH_TEST); diff --git a/examples/gamepad/gamepad.c b/examples/gamepad/gamepad.c index 019b9a636..770e591f5 100644 --- a/examples/gamepad/gamepad.c +++ b/examples/gamepad/gamepad.c @@ -8,7 +8,7 @@ void drawGamepad(RGFW_window* w, size_t gamepad); int main(void) { - RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(0, 0, 800, 450), RGFW_CENTER); + RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(0, 0, 800, 450), RGFW_center); RGFW_window_makeCurrent(win); size_t gamepad = 0; diff --git a/examples/gl33/gl33.c b/examples/gl33/gl33.c index 7f351b3bc..00a69ee78 100644 --- a/examples/gl33/gl33.c +++ b/examples/gl33/gl33.c @@ -69,7 +69,7 @@ int main(void) { RGFW_setGLVersion(RGFW_glCore, 3, 3); - RGFW_window* window = RGFW_createWindow("LearnOpenGL", RGFW_RECT(SCR_WIDTH, SCR_HEIGHT, SCR_WIDTH, SCR_HEIGHT), RGFW_ALLOW_DND | RGFW_CENTER | RGFW_SCALE_TO_MONITOR); + RGFW_window* window = RGFW_createWindow("LearnOpenGL", RGFW_RECT(SCR_WIDTH, SCR_HEIGHT, SCR_WIDTH, SCR_HEIGHT), RGFW_allowDND | RGFW_center | RGFW_scaleToMonitor); if (window == NULL) { printf("Failed to create RGFW window\n"); diff --git a/examples/gles2/gles2.c b/examples/gles2/gles2.c index 46bf999cc..509238f83 100644 --- a/examples/gles2/gles2.c +++ b/examples/gles2/gles2.c @@ -23,7 +23,7 @@ GLuint load_shader(const char *shaderSource, GLenum type) { } int main(void) { - RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(0, 0, 500, 500), RGFW_CENTER); + RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(0, 0, 500, 500), RGFW_center); /////// the openGL part /////////////////////////////////////////////////////////////// diff --git a/examples/microui_demo/microui_demo.c b/examples/microui_demo/microui_demo.c index 177dcb626..67deafae1 100644 --- a/examples/microui_demo/microui_demo.c +++ b/examples/microui_demo/microui_demo.c @@ -242,7 +242,7 @@ static int text_height(mu_Font font) { int main(int argc, char **argv) { RGFW_UNUSED(argc); RGFW_UNUSED(argv); /* init RGFW window */ - RGFW_window* window = RGFW_createWindow("", RGFW_RECT(0, 0, width, height), RGFW_CENTER | RGFW_SCALE_TO_MONITOR); + RGFW_window* window = RGFW_createWindow("", RGFW_RECT(0, 0, width, height), RGFW_center | RGFW_scaleToMonitor); r_init(); /* init microui */ diff --git a/examples/minimal_links/XDL.h b/examples/minimal_links/XDL.h new file mode 100644 index 000000000..fe2e4ffdf --- /dev/null +++ b/examples/minimal_links/XDL.h @@ -0,0 +1,571 @@ +/* + + + This is free and unencumbered software released into the public domain. + Anyone is free to copy, modify, publish, use, compile, sell, or distribute this + software, either in source code form or as a compiled binary, for any purpose, + commercial or non-commercial, and by any means. + In jurisdictions that recognize copyright laws, the author or authors of this + software dedicate any and all copyright interest in the software to the public + domain. We make this dedication for the benefit of the public at large and to + the detriment of our heirs and successors. We intend this dedication to be an + overt act of relinquishment in perpetuity of all present and future rights to + this software under copyright law. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Credit is not required but would be greatly appreciated. :) +*/ + +/* + #define XDL_IMPLEMENTATION - (semi-option) makes it so function definitions are included + #define XDL_NO_GLX - (optional) Makes it so the GLX module is not included + #define XDL_NO_DEALLOCATE - (optional) Disables automatic deallocation for c++, returns back to C's void** system +*/ + +/* +Credits : + GLFW - Much of this implementation is based on GLFW's internal x11 dynamic loader + A great portion of the declarations for the X11 module are sourced from GLFW + + stb - This project is heavily inspired by the stb single header files +*/ + +#include +#include +#include +#include + +#ifndef XDL_NO_GLX +#include +#endif + +#if !defined(__cplusplus) || defined(XDL_NO_DEALLOCATE) +typedef void** XDLModule; /* in C (or c++ deallocate disabled), it's just a regular void** c array */ +#else +struct XDLModule { /* (by default) in c++, the array is embeded in an object so it can be deallocated automatically */ + void** module; + + ~XDLModule(); +}; +#endif + +XDLModule XDL_init(); /* inits the X11 (and GLX) modules */ +void XDL_close(XDLModule module); /* closes and frees the X11 (and GLX modules) */ + +/* function types */ +typedef XClassHint* (* PFN_XAllocClassHint)(void); +typedef XSizeHints* (* PFN_XAllocSizeHints)(void); +typedef XWMHints* (* PFN_XAllocWMHints)(void); +typedef int (* PFN_XChangeProperty)(Display*,Window,Atom,Atom,int,int,const unsigned char*,int); +typedef int (* PFN_XChangeWindowAttributes)(Display*,Window,unsigned long,XSetWindowAttributes*); +typedef Bool (* PFN_XCheckIfEvent)(Display*,XEvent*,Bool(*)(Display*,XEvent*,XPointer),XPointer); +typedef Bool (* PFN_XCheckTypedWindowEvent)(Display*,Window,int,XEvent*); +typedef int (* PFN_XCloseDisplay)(Display*); +typedef Status (* PFN_XCloseIM)(XIM); +typedef int (* PFN_XConvertSelection)(Display*,Atom,Atom,Atom,Window,Time); +typedef Colormap (* PFN_XCreateColormap)(Display*,Window,Visual*,int); +typedef Cursor (* PFN_XCreateFontCursor)(Display*,unsigned int); +typedef XIC (* PFN_XCreateIC)(XIM,...); +typedef Region (* PFN_XCreateRegion)(void); +typedef Window (* PFN_XCreateWindow)(Display*,Window,int,int,unsigned int,unsigned int,unsigned int,int,unsigned int,Visual*,unsigned long,XSetWindowAttributes*); +typedef int (* PFN_XDefineCursor)(Display*,Window,Cursor); +typedef int (* PFN_XDeleteContext)(Display*,XID,XContext); +typedef int (* PFN_XDeleteProperty)(Display*,Window,Atom); +typedef void (* PFN_XDestroyIC)(XIC); +typedef int (* PFN_XDestroyRegion)(Region); +typedef int (* PFN_XDestroyWindow)(Display*,Window); +typedef int (* PFN_XDisplayKeycodes)(Display*,int*,int*); +typedef int (* PFN_XEventsQueued)(Display*,int); +typedef Bool (* PFN_XFilterEvent)(XEvent*,Window); +typedef int (* PFN_XFindContext)(Display*,XID,XContext,XPointer*); +typedef int (* PFN_XFlush)(Display*); +typedef int (* PFN_XFree)(void*); +typedef int (* PFN_XFreeColormap)(Display*,Colormap); +typedef int (* PFN_XFreeCursor)(Display*,Cursor); +typedef void (* PFN_XFreeEventData)(Display*,XGenericEventCookie*); +typedef int (* PFN_XGetErrorText)(Display*,int,char*,int); +typedef Bool (* PFN_XGetEventData)(Display*,XGenericEventCookie*); +typedef char* (* PFN_XGetICValues)(XIC,...); +typedef char* (* PFN_XGetIMValues)(XIM,...); +typedef int (* PFN_XGetInputFocus)(Display*,Window*,int*); +typedef KeySym* (* PFN_XGetKeyboardMapping)(Display*,KeyCode,int,int*); +typedef int (* PFN_XGetScreenSaver)(Display*,int*,int*,int*,int*); +typedef Window (* PFN_XGetSelectionOwner)(Display*,Atom); +typedef XVisualInfo* (* PFN_XGetVisualInfo)(Display*,long,XVisualInfo*,int*); +typedef Status (* PFN_XGetWMNormalHints)(Display*,Window,XSizeHints*,long*); +typedef Status (* PFN_XGetWindowAttributes)(Display*,Window,XWindowAttributes*); +typedef int (* PFN_XGetWindowProperty)(Display*,Window,Atom,long,long,Bool,Atom,Atom*,int*,unsigned long*,unsigned long*,unsigned char**); +typedef int (* PFN_XGrabPointer)(Display*,Window,Bool,unsigned int,int,int,Window,Cursor,Time); +typedef Status (* PFN_XIconifyWindow)(Display*,Window,int); +typedef Status (* PFN_XInitThreads)(void); +typedef Atom (* PFN_XInternAtom)(Display*,const char*,Bool); +typedef int (* PFN_XLookupString)(XKeyEvent*,char*,int,KeySym*,XComposeStatus*); +typedef int (* PFN_XMapRaised)(Display*,Window); +typedef int (* PFN_XMapWindow)(Display*,Window); +typedef int (* PFN_XMoveResizeWindow)(Display*,Window,int,int,unsigned int,unsigned int); +typedef int (* PFN_XMoveWindow)(Display*,Window,int,int); +typedef int (* PFN_XNextEvent)(Display*,XEvent*); +typedef Display* (* PFN_XOpenDisplay)(const char*); +typedef int (* PFN_XPeekEvent)(Display*,XEvent*); +typedef int (* PFN_XPending)(Display*); +typedef Bool (* PFN_XQueryExtension)(Display*,const char*,int*,int*,int*); +typedef Bool (* PFN_XQueryPointer)(Display*,Window,Window*,Window*,int*,int*,int*,int*,unsigned int*); +typedef int (* PFN_XRaiseWindow)(Display*,Window); +typedef Bool (* PFN_XRegisterIMInstantiateCallback)(Display*,void*,char*,char*,XIDProc,XPointer); +typedef int (* PFN_XResizeWindow)(Display*,Window,unsigned int,unsigned int); +typedef char* (* PFN_XResourceManagerString)(Display*); +typedef int (* PFN_XSaveContext)(Display*,XID,XContext,const char*); +typedef int (* PFN_XSelectInput)(Display*,Window,long); +typedef Status (* PFN_XSendEvent)(Display*,Window,Bool,long,XEvent*); +typedef int (* PFN_XSetClassHint)(Display*,Window,XClassHint*); +typedef XErrorHandler (* PFN_XSetErrorHandler)(XErrorHandler); +typedef void (* PFN_XSetICFocus)(XIC); +typedef char* (* PFN_XSetIMValues)(XIM,...); +typedef int (* PFN_XSetInputFocus)(Display*,Window,int,Time); +typedef char* (* PFN_XSetLocaleModifiers)(const char*); +typedef int (* PFN_XSetScreenSaver)(Display*,int,int,int,int); +typedef int (* PFN_XSetSelectionOwner)(Display*,Atom,Window,Time); +typedef int (* PFN_XSetWMHints)(Display*,Window,XWMHints*); +typedef void (* PFN_XSetWMNormalHints)(Display*,Window,XSizeHints*); +typedef Status (* PFN_XSetWMProtocols)(Display*,Window,Atom*,int); +typedef Bool (* PFN_XSupportsLocale)(void); +typedef int (* PFN_XSync)(Display*,Bool); +typedef Bool (* PFN_XTranslateCoordinates)(Display*,Window,Window,int,int,int*,int*,Window*); +typedef int (* PFN_XUndefineCursor)(Display*,Window); +typedef int (* PFN_XUngrabPointer)(Display*,Time); +typedef int (* PFN_XUnmapWindow)(Display*,Window); +typedef void (* PFN_XUnsetICFocus)(XIC); +typedef VisualID (* PFN_XVisualIDFromVisual)(Visual*); +typedef int (* PFN_XWarpPointer)(Display*,Window,Window,int,int,unsigned int,unsigned int,int,int); +typedef void (* PFN_XkbFreeKeyboard)(XkbDescPtr,unsigned int,Bool); +typedef void (* PFN_XkbFreeNames)(XkbDescPtr,unsigned int,Bool); +typedef XkbDescPtr (* PFN_XkbGetMap)(Display*,unsigned int,unsigned int); +typedef Status (* PFN_XkbGetNames)(Display*,unsigned int,XkbDescPtr); +typedef Status (* PFN_XkbGetState)(Display*,unsigned int,XkbStatePtr); +typedef KeySym (* PFN_XkbKeycodeToKeysym)(Display*,KeyCode,int,int); +typedef Bool (* PFN_XkbQueryExtension)(Display*,int*,int*,int*,int*,int*); +typedef Bool (* PFN_XkbSelectEventDetails)(Display*,unsigned int,unsigned int,unsigned long,unsigned long); +typedef Bool (* PFN_XkbSetDetectableAutoRepeat)(Display*,Bool,Bool*); +typedef KeySym (*PFN_XStringToKeysym)(char*); +typedef int (*PFN_XConnectionNumber)(Display*); +typedef int (*PFN_XStoreName)(Display*, Window, char*); +typedef Status (*PFN_XMatchVisualInfo)(Display*, int, int, int, XVisualInfo*); +typedef void (*PFN_XSetWMSizeHints)(Display*, Window, XSizeHints*, Atom); +typedef char* (*PFN_XKeysymToString)(KeySym); +typedef int (*PFN_XGetKeyboardControl)(Display*, XKeyboardState*); +typedef char* (*PFN_XGetAtomName)(Display*, Atom); +typedef Window (*PFN_XDefaultRootWindow)(Display*); +typedef int (*PFN_XQueryKeymap)(Display*, char[32]); +typedef KeyCode (*PFN_XKeysymToKeycode)(Display*, KeySym); + + + + +#ifndef XDL_NO_GLX +typedef XVisualInfo* (*PFN_glXChooseVisual)(Display*, int, int*); +typedef GLXContext (*PFN_glXCreateContext)(Display*, XVisualInfo*, GLXContext, Bool); +typedef Bool (*PFN_glXMakeCurrent)(Display*, GLXDrawable, GLXContext); +typedef void (*PFN_glXSwapBuffers)(Display*, GLXDrawable); +typedef PFNGLXSWAPINTERVALEXTPROC PFN_glXSwapIntervalEXT; +typedef void* (*PFN_glXGetProcAddress)(const GLubyte *procname); +typedef PFNGLXGETVISUALFROMFBCONFIGPROC PFN_glXGetVisualFromFBConfig; +typedef PFNGLXGETFBCONFIGATTRIBPROC PFN_glXGetFBConfigAttrib; +typedef __GLXextFuncPtr (*PFN_glXGetProcAddressARB)(const GLubyte *); +typedef PFNGLXCHOOSEFBCONFIGPROC PFN_glXChooseFBConfig; +#endif + +/* Src vars for reciving the functions */ +PFN_XAllocClassHint XAllocClassHintSrc; +PFN_XAllocSizeHints XAllocSizeHintsSrc; +PFN_XAllocWMHints XAllocWMHintsSrc; +PFN_XChangeProperty XChangePropertySrc; +PFN_XChangeWindowAttributes XChangeWindowAttributesSrc; +PFN_XCheckIfEvent XCheckIfEventSrc; +PFN_XCheckTypedWindowEvent XCheckTypedWindowEventSrc; +PFN_XCloseDisplay XCloseDisplaySrc; +PFN_XCloseIM XCloseIMSrc; +PFN_XConvertSelection XConvertSelectionSrc; +PFN_XCreateColormap XCreateColormapSrc; +PFN_XCreateFontCursor XCreateFontCursorSrc; +PFN_XCreateIC XCreateICSrc; +PFN_XCreateRegion XCreateRegionSrc; +PFN_XCreateWindow XCreateWindowSrc; +PFN_XDefineCursor XDefineCursorSrc; +PFN_XDeleteContext XDeleteContextSrc; +PFN_XDeleteProperty XDeletePropertySrc; +PFN_XDestroyIC XDestroyICSrc; +PFN_XDestroyRegion XDestroyRegionSrc; +PFN_XDestroyWindow XDestroyWindowSrc; +PFN_XDisplayKeycodes XDisplayKeycodesSrc; +PFN_XEventsQueued XEventsQueuedSrc; +PFN_XFilterEvent XFilterEventSrc; +PFN_XFindContext XFindContextSrc; +PFN_XFlush XFlushSrc; +PFN_XFree XFreeSrc; +PFN_XFreeColormap XFreeColormapSrc; +PFN_XFreeCursor XFreeCursorSrc; +PFN_XFreeEventData XFreeEventDataSrc; +PFN_XGetErrorText XGetErrorTextSrc; +PFN_XGetEventData XGetEventDataSrc; +PFN_XGetICValues XGetICValuesSrc; +PFN_XGetIMValues XGetIMValuesSrc; +PFN_XGetInputFocus XGetInputFocusSrc; +PFN_XGetKeyboardMapping XGetKeyboardMappingSrc; +PFN_XGetScreenSaver XGetScreenSaverSrc; +PFN_XGetSelectionOwner XGetSelectionOwnerSrc; +PFN_XGetVisualInfo XGetVisualInfoSrc; +PFN_XGetWMNormalHints XGetWMNormalHintsSrc; +PFN_XGetWindowAttributes XGetWindowAttributesSrc; +PFN_XGetWindowProperty XGetWindowPropertySrc; +PFN_XGrabPointer XGrabPointerSrc; +PFN_XIconifyWindow XIconifyWindowSrc; +PFN_XInternAtom XInternAtomSrc; +PFN_XLookupString XLookupStringSrc; +PFN_XMapRaised XMapRaisedSrc; +PFN_XMapWindow XMapWindowSrc; +PFN_XMoveResizeWindow XMoveResizeWindowSrc; +PFN_XMoveWindow XMoveWindowSrc; +PFN_XNextEvent XNextEventSrc; +PFN_XPeekEvent XPeekEventSrc; +PFN_XPending XPendingSrc; +PFN_XQueryExtension XQueryExtensionSrc; +PFN_XQueryPointer XQueryPointerSrc; +PFN_XRaiseWindow XRaiseWindowSrc; +PFN_XRegisterIMInstantiateCallback XRegisterIMInstantiateCallbackSrc; +PFN_XResizeWindow XResizeWindowSrc; +PFN_XResourceManagerString XResourceManagerStringSrc; +PFN_XSaveContext XSaveContextSrc; +PFN_XSelectInput XSelectInputSrc; +PFN_XSendEvent XSendEventSrc; +PFN_XSetClassHint XSetClassHintSrc; +PFN_XSetErrorHandler XSetErrorHandlerSrc; +PFN_XSetICFocus XSetICFocusSrc; +PFN_XSetIMValues XSetIMValuesSrc; +PFN_XSetInputFocus XSetInputFocusSrc; +PFN_XSetLocaleModifiers XSetLocaleModifiersSrc; +PFN_XSetScreenSaver XSetScreenSaverSrc; +PFN_XSetSelectionOwner XSetSelectionOwnerSrc; +PFN_XSetWMHints XSetWMHintsSrc; +PFN_XSetWMNormalHints XSetWMNormalHintsSrc; +PFN_XSetWMProtocols XSetWMProtocolsSrc; +PFN_XSupportsLocale XSupportsLocaleSrc; +PFN_XSync XSyncSrc; +PFN_XTranslateCoordinates XTranslateCoordinatesSrc; +PFN_XUndefineCursor XUndefineCursorSrc; +PFN_XUngrabPointer XUngrabPointerSrc; +PFN_XUnmapWindow XUnmapWindowSrc; +PFN_XUnsetICFocus XUnsetICFocusSrc; +PFN_XVisualIDFromVisual XVisualIDFromVisualSrc; +PFN_XWarpPointer XWarpPointerSrc; +PFN_XOpenDisplay XOpenDisplaySrc; +PFN_XInitThreads XInitThreadsSrc; +PFN_XkbKeycodeToKeysym XkbKeycodeToKeysymSrc; +PFN_XStringToKeysym XStringToKeysymSrc; +PFN_XConnectionNumber XConnectionNumberSrc; +PFN_XMatchVisualInfo XMatchVisualInfoSrc; +PFN_XSetWMSizeHints XSetWMSizeHintsSrc; +PFN_XStoreName XStoreNameSrc; +PFN_XKeysymToString XKeysymToStringSrc; +PFN_XGetKeyboardControl XGetKeyboardControlSrc; +PFN_XGetAtomName XGetAtomNameSrc; +PFN_XDefaultRootWindow XDefaultRootWindowSrc; +PFN_XQueryKeymap XQueryKeymapSrc; +PFN_XKeysymToKeycode XKeysymToKeycodeSrc; + +#ifndef XDL_NO_GLX +PFN_glXChooseVisual glXChooseVisualSrc; +PFN_glXCreateContext glXCreateContextSrc; +PFN_glXMakeCurrent glXMakeCurrentSrc; +PFN_glXSwapBuffers glXSwapBuffersSrc; +PFN_glXSwapIntervalEXT glXSwapIntervalEXTSrc; +PFN_glXGetProcAddress glXGetProcAddressSrc; +PFN_glXGetVisualFromFBConfig glXGetVisualFromFBConfigSrc; +PFN_glXGetFBConfigAttrib glXGetFBConfigAttribSrc; +PFN_glXGetProcAddressARB glXGetProcAddressARBSrc; +PFN_glXChooseFBConfig glXChooseFBConfigSrc; +#endif + +/* Function to source defines */ +#define XAllocClassHint XAllocClassHintSrc +#define XAllocSizeHints XAllocSizeHintsSrc +#define XAllocWMHints XAllocWMHintsSrc +#define XChangeProperty XChangePropertySrc +#define XChangeWindowAttributes XChangeWindowAttributesSrc +#define XCheckIfEvent XCheckIfEventSrc +#define XCheckTypedWindowEvent XCheckTypedWindowEventSrc +#define XCloseDisplay XCloseDisplaySrc +#define XCloseIM XCloseIMSrc +#define XConvertSelection XConvertSelectionSrc +#define XCreateColormap XCreateColormapSrc +#define XCreateFontCursor XCreateFontCursorSrc +#define XCreateIC XCreateICSrc +#define XCreateRegion XCreateRegionSrc +#define XCreateWindow XCreateWindowSrc +#define XDefineCursor XDefineCursorSrc +#define XDeleteContext XDeleteContextSrc +#define XDeleteProperty XDeletePropertySrc +#define XDestroyIC XDestroyICSrc +#define XDestroyRegion XDestroyRegionSrc +#define XDestroyWindow XDestroyWindowSrc +#define XDisplayKeycodes XDisplayKeycodesSrc +#define XEventsQueued XEventsQueuedSrc +#define XFilterEvent XFilterEventSrc +#define XFindContext XFindContextSrc +#define XFlush XFlushSrc +#define XFree XFreeSrc +#define XFreeColormap XFreeColormapSrc +#define XFreeCursor XFreeCursorSrc +#define XFreeEventData XFreeEventDataSrc +#define XGetErrorText XGetErrorTextSrc +#define XGetEventData XGetEventDataSrc +#define XGetICValues XGetICValuesSrc +#define XGetIMValues XGetIMValuesSrc +#define XGetInputFocus XGetInputFocusSrc +#define XGetKeyboardMapping XGetKeyboardMappingSrc +#define XGetScreenSaver XGetScreenSaverSrc +#define XGetSelectionOwner XGetSelectionOwnerSrc +#define XGetVisualInfo XGetVisualInfoSrc +#define XGetWMNormalHints XGetWMNormalHintsSrc +#define XGetWindowAttributes XGetWindowAttributesSrc +#define XGetWindowProperty XGetWindowPropertySrc +#define XGrabPointer XGrabPointerSrc +#define XIconifyWindow XIconifyWindowSrc +#define XInternAtom XInternAtomSrc +#define XLookupString XLookupStringSrc +#define XMapRaised XMapRaisedSrc +#define XMapWindow XMapWindowSrc +#define XMoveResizeWindow XMoveResizeWindowSrc +#define XMoveWindow XMoveWindowSrc +#define XNextEvent XNextEventSrc +#define XPeekEvent XPeekEventSrc +#define XPending XPendingSrc +#define XQueryExtension XQueryExtensionSrc +#define XQueryPointer XQueryPointerSrc +#define XRaiseWindow XRaiseWindowSrc +#define XRegisterIMInstantiateCallback XRegisterIMInstantiateCallbackSrc +#define XResizeWindow XResizeWindowSrc +#define XResourceManagerString XResourceManagerStringSrc +#define XSaveContext XSaveContextSrc +#define XSelectInput XSelectInputSrc +#define XSendEvent XSendEventSrc +#define XSetClassHint XSetClassHintSrc +#define XSetErrorHandler XSetErrorHandlerSrc +#define XSetICFocus XSetICFocusSrc +#define XSetIMValues XSetIMValuesSrc +#define XSetInputFocus XSetInputFocusSrc +#define XSetLocaleModifiers XSetLocaleModifiersSrc +#define XSetScreenSaver XSetScreenSaverSrc +#define XSetSelectionOwner XSetSelectionOwnerSrc +#define XSetWMHints XSetWMHintsSrc +#define XSetWMNormalHints XSetWMNormalHintsSrc +#define XSetWMProtocols XSetWMProtocolsSrc +#define XSupportsLocale XSupportsLocaleSrc +#define XSync XSyncSrc +#define XTranslateCoordinates XTranslateCoordinatesSrc +#define XUndefineCursor XUndefineCursorSrc +#define XUngrabPointer XUngrabPointerSrc +#define XUnmapWindow XUnmapWindowSrc +#define XUnsetICFocus XUnsetICFocusSrc +#define XVisualIDFromVisual XVisualIDFromVisualSrc +#define XWarpPointer XWarpPointerSrc +#define XStoreName XStoreNameSrc +#define XSetWMSizeHints XSetWMSizeHintsSrc +#define XOpenDisplay XOpenDisplaySrc +#define XStringToKeysym XStringToKeysymSrc +#define XQueryKeymap XQueryKeymapSrc +#define XKeysymToString XKeysymToStringSrc +#define XInitThreads XInitThreadsSrc +#define XkbKeycodeToKeysym XkbKeycodeToKeysymSrc +#define XGetAtomName XGetAtomNameSrc +#define XDefaultRootWindow XDefaultRootWindowSrc +#define XMatchVisualInfo XMatchVisualInfoSrc +#define XGetKeyboardControl XGetKeyboardControlSrc +#define XKeysymToKeycode XKeysymToKeycodeSrc +#define XConnectionNumber XConnectionNumberSrc + +#ifndef XDL_NO_GLX +#define glXChooseVisual glXChooseVisualSrc +#define glXCreateContext glXCreateContextSrc +#define glXMakeCurrent glXMakeCurrentSrc +#define glXSwapBuffers glXSwapBuffersSrc +#define glXGetProcAddress glXGetProcAddressSrc +#define glXGetVisualFromFBConfig glXGetVisualFromFBConfigSrc +#define glXGetFBConfigAttrib glXGetFBConfigAttribSrc +#define glXGetProcAddressARB glXGetProcAddressARBSrc +#define glXChooseFBConfig glXChooseFBConfigSrc +#endif + +#ifdef XDL_IMPLEMENTATION +#include + +XDLModule XDL_init() { + /* allocating memory for module data */ + #ifndef XDL_NO_GLX + void** module = (void**)malloc(2 * sizeof(void*)); + #else + void** module = (void**)malloc(sizeof(void*)); + #endif + + /* loading the modules */ + #if defined(__CYGWIN__) + module[0] = dlopen("libX11-6.so", RTLD_LAZY | RTLD_LOCAL); + #elif defined(__OpenBSD__) || defined(__NetBSD__) + module[0] = dlopen("libX11.so", RTLD_LAZY | RTLD_LOCAL); + #else + module[0] = dlopen("libX11.so.6", RTLD_LAZY | RTLD_LOCAL); + #endif + + #ifndef XDL_NO_GLX + module[1] = dlopen("libGLX.so", RTLD_LAZY | RTLD_LOCAL); + #endif + + /* loading the functions into the source vars */ + XAllocClassHintSrc = (PFN_XAllocClassHint)dlsym(module[0], "XAllocClassHint"); + XAllocSizeHintsSrc = (PFN_XAllocSizeHints)dlsym(module[0], "XAllocSizeHints"); + XAllocWMHintsSrc = (PFN_XAllocWMHints)dlsym(module[0], "XAllocWMHints"); + XChangePropertySrc = (PFN_XChangeProperty)dlsym(module[0], "XChangeProperty"); + XChangeWindowAttributesSrc = (PFN_XChangeWindowAttributes)dlsym(module[0], "XChangeWindowAttributes"); + XCheckIfEventSrc = (PFN_XCheckIfEvent)dlsym(module[0], "XCheckIfEvent"); + XCheckTypedWindowEventSrc = (PFN_XCheckTypedWindowEvent)dlsym(module[0], "XCheckTypedWindowEvent"); + XCloseDisplaySrc = (PFN_XCloseDisplay)dlsym(module[0], "XCloseDisplay"); + XCloseIMSrc = (PFN_XCloseIM)dlsym(module[0], "XCloseIM"); + XConvertSelectionSrc = (PFN_XConvertSelection)dlsym(module[0], "XConvertSelection"); + XCreateColormapSrc = (PFN_XCreateColormap)dlsym(module[0], "XCreateColormap"); + XCreateFontCursorSrc = (PFN_XCreateFontCursor)dlsym(module[0], "XCreateFontCursor"); + XCreateICSrc = (PFN_XCreateIC)dlsym(module[0], "XCreateIC"); + XCreateRegionSrc = (PFN_XCreateRegion)dlsym(module[0], "XCreateRegion"); + XCreateWindowSrc = (PFN_XCreateWindow)dlsym(module[0], "XCreateWindow"); + XDefineCursorSrc = (PFN_XDefineCursor)dlsym(module[0], "XDefineCursor"); + XDeleteContextSrc = (PFN_XDeleteContext)dlsym(module[0], "XDeleteContext"); + XDeletePropertySrc = (PFN_XDeleteProperty)dlsym(module[0], "XDeleteProperty"); + XDestroyICSrc = (PFN_XDestroyIC)dlsym(module[0], "XDestroyIC"); + XDestroyRegionSrc = (PFN_XDestroyRegion)dlsym(module[0], "XDestroyRegion"); + XDestroyWindowSrc = (PFN_XDestroyWindow)dlsym(module[0], "XDestroyWindow"); + XDisplayKeycodesSrc = (PFN_XDisplayKeycodes)dlsym(module[0], "XDisplayKeycodes"); + XEventsQueuedSrc = (PFN_XEventsQueued)dlsym(module[0], "XEventsQueued"); + XFilterEventSrc = (PFN_XFilterEvent)dlsym(module[0], "XFilterEvent"); + XFindContextSrc = (PFN_XFindContext)dlsym(module[0], "XFindContext"); + XFlushSrc = (PFN_XFlush)dlsym(module[0], "XFlush"); + XFreeSrc = (PFN_XFree)dlsym(module[0], "XFree"); + XFreeColormapSrc = (PFN_XFreeColormap)dlsym(module[0], "XFreeColormap"); + XFreeCursorSrc = (PFN_XFreeCursor)dlsym(module[0], "XFreeCursor"); + XFreeEventDataSrc = (PFN_XFreeEventData)dlsym(module[0], "XFreeEventData"); + XGetErrorTextSrc = (PFN_XGetErrorText)dlsym(module[0], "XGetErrorText"); + XGetEventDataSrc = (PFN_XGetEventData)dlsym(module[0], "XGetEventData"); + XGetICValuesSrc = (PFN_XGetICValues)dlsym(module[0], "XGetICValues"); + XGetIMValuesSrc = (PFN_XGetIMValues)dlsym(module[0], "XGetIMValues"); + XGetInputFocusSrc = (PFN_XGetInputFocus)dlsym(module[0], "XGetInputFocus"); + XGetKeyboardMappingSrc = (PFN_XGetKeyboardMapping)dlsym(module[0], "XGetKeyboardMapping"); + XGetScreenSaverSrc = (PFN_XGetScreenSaver)dlsym(module[0], "XGetScreenSaver"); + XGetSelectionOwnerSrc = (PFN_XGetSelectionOwner)dlsym(module[0], "XGetSelectionOwner"); + XGetVisualInfoSrc = (PFN_XGetVisualInfo)dlsym(module[0], "XGetVisualInfo"); + XGetWMNormalHintsSrc = (PFN_XGetWMNormalHints)dlsym(module[0], "XGetWMNormalHints"); + XGetWindowAttributesSrc = (PFN_XGetWindowAttributes)dlsym(module[0], "XGetWindowAttributes"); + XGetWindowPropertySrc = (PFN_XGetWindowProperty)dlsym(module[0], "XGetWindowProperty"); + XGrabPointerSrc = (PFN_XGrabPointer)dlsym(module[0], "XGrabPointer"); + XIconifyWindowSrc = (PFN_XIconifyWindow)dlsym(module[0], "XIconifyWindow"); + XInternAtomSrc = (PFN_XInternAtom)dlsym(module[0], "XInternAtom"); + XLookupStringSrc = (PFN_XLookupString)dlsym(module[0], "XLookupString"); + XMapRaisedSrc = (PFN_XMapRaised)dlsym(module[0], "XMapRaised"); + XMapWindowSrc = (PFN_XMapWindow)dlsym(module[0], "XMapWindow"); + XMoveResizeWindowSrc = (PFN_XMoveResizeWindow)dlsym(module[0], "XMoveResizeWindow"); + XMoveWindowSrc = (PFN_XMoveWindow)dlsym(module[0], "XMoveWindow"); + XNextEventSrc = (PFN_XNextEvent)dlsym(module[0], "XNextEvent"); + XPeekEventSrc = (PFN_XPeekEvent)dlsym(module[0], "XPeekEvent"); + XPendingSrc = (PFN_XPending)dlsym(module[0], "XPending"); + XQueryExtensionSrc = (PFN_XQueryExtension)dlsym(module[0], "XQueryExtension"); + XQueryPointerSrc = (PFN_XQueryPointer)dlsym(module[0], "XQueryPointer"); + XRaiseWindowSrc = (PFN_XRaiseWindow)dlsym(module[0], "XRaiseWindow"); + XRegisterIMInstantiateCallbackSrc = (PFN_XRegisterIMInstantiateCallback)dlsym(module[0], "XRegisterIMInstantiateCallback"); + XResizeWindowSrc = (PFN_XResizeWindow)dlsym(module[0], "XResizeWindow"); + XResourceManagerStringSrc = (PFN_XResourceManagerString)dlsym(module[0], "XResourceManagerString"); + XSaveContextSrc = (PFN_XSaveContext)dlsym(module[0], "XSaveContext"); + XSelectInputSrc = (PFN_XSelectInput)dlsym(module[0], "XSelectInput"); + XSendEventSrc = (PFN_XSendEvent)dlsym(module[0], "XSendEvent"); + XSetClassHintSrc = (PFN_XSetClassHint)dlsym(module[0], "XSetClassHint"); + XSetErrorHandlerSrc = (PFN_XSetErrorHandler)dlsym(module[0], "XSetErrorHandler"); + XSetICFocusSrc = (PFN_XSetICFocus)dlsym(module[0], "XSetICFocus"); + XSetIMValuesSrc = (PFN_XSetIMValues)dlsym(module[0], "XSetIMValues"); + XSetInputFocusSrc = (PFN_XSetInputFocus)dlsym(module[0], "XSetInputFocus"); + XSetLocaleModifiersSrc = (PFN_XSetLocaleModifiers)dlsym(module[0], "XSetLocaleModifiers"); + XSetScreenSaverSrc = (PFN_XSetScreenSaver)dlsym(module[0], "XSetScreenSaver"); + XSetSelectionOwnerSrc = (PFN_XSetSelectionOwner)dlsym(module[0], "XSetSelectionOwner"); + XSetWMHintsSrc = (PFN_XSetWMHints)dlsym(module[0], "XSetWMHints"); + XSetWMNormalHintsSrc = (PFN_XSetWMNormalHints)dlsym(module[0], "XSetWMNormalHints"); + XSetWMProtocolsSrc = (PFN_XSetWMProtocols)dlsym(module[0], "XSetWMProtocols"); + XSupportsLocaleSrc = (PFN_XSupportsLocale)dlsym(module[0], "XSupportsLocale"); + XSyncSrc = (PFN_XSync)dlsym(module[0], "XSync"); + XTranslateCoordinatesSrc = (PFN_XTranslateCoordinates)dlsym(module[0], "XTranslateCoordinates"); + XUndefineCursorSrc = (PFN_XUndefineCursor)dlsym(module[0], "XUndefineCursor"); + XUngrabPointerSrc = (PFN_XUngrabPointer)dlsym(module[0], "XUngrabPointer"); + XUnmapWindowSrc = (PFN_XUnmapWindow)dlsym(module[0], "XUnmapWindow"); + XUnsetICFocusSrc = (PFN_XUnsetICFocus)dlsym(module[0], "XUnsetICFocus"); + XVisualIDFromVisualSrc = (PFN_XVisualIDFromVisual)dlsym(module[0], "XVisualIDFromVisual"); + XWarpPointerSrc = (PFN_XWarpPointer)dlsym(module[0], "XWarpPointer"); + XStoreNameSrc = (PFN_XStoreName)dlsym(module[0], "XStoreName"); + XSetWMSizeHintsSrc = (PFN_XSetWMSizeHints)dlsym(module[0], "XSetWMSizeHints"); + XOpenDisplaySrc = (PFN_XOpenDisplay)dlsym(module[0], "XOpenDisplay"); + XStringToKeysymSrc = (PFN_XStringToKeysym)dlsym(module[0], "XStringToKeysym"); + XQueryKeymapSrc = (PFN_XQueryKeymap)dlsym(module[0], "XQueryKeymap"); + XKeysymToStringSrc = (PFN_XKeysymToString)dlsym(module[0], "XKeysymToString"); + XInitThreadsSrc = (PFN_XInitThreads)dlsym(module[0], "XInitThreads"); + XkbKeycodeToKeysymSrc = (PFN_XkbKeycodeToKeysym)dlsym(module[0], "XkbKeycodeToKeysym"); + XGetAtomNameSrc = (PFN_XGetAtomName)dlsym(module[0], "XGetAtomName"); + XDefaultRootWindowSrc = (PFN_XDefaultRootWindow)dlsym(module[0], "XDefaultRootWindow"); + XMatchVisualInfoSrc = (PFN_XMatchVisualInfo)dlsym(module[0], "XMatchVisualInfo"); + XGetKeyboardControlSrc = (PFN_XGetKeyboardControl)dlsym(module[0], "XGetKeyboardControl"); + XKeysymToKeycodeSrc = (PFN_XKeysymToKeycode)dlsym(module[0], "XKeysymToKeycode"); + XConnectionNumberSrc = (PFN_XConnectionNumber)dlsym(module[0], "XConnectionNumber"); + + #ifndef XDL_NO_GLX + glXChooseVisualSrc = (PFN_glXChooseVisual)dlsym(module[1], "glXChooseVisual"); + glXCreateContextSrc = (PFN_glXCreateContext)dlsym(module[1], "glXCreateContext"); + glXMakeCurrentSrc = (PFN_glXMakeCurrent)dlsym(module[1], "glXMakeCurrent"); + glXSwapBuffersSrc = (PFN_glXSwapBuffers)dlsym(module[1], "glXSwapBuffers"); + glXSwapIntervalEXTSrc = (PFN_glXSwapIntervalEXT)dlsym(module[1], "glXSwapIntervalEXT"); + glXGetProcAddressSrc = (PFN_glXGetProcAddress)dlsym(module[1], "glXGetProcAddress"); + glXGetVisualFromFBConfigSrc = (PFN_glXGetVisualFromFBConfig)dlsym(module[1],"glXGetVisualFromFBConfig"); + glXGetFBConfigAttribSrc == (PFN_glXGetFBConfigAttrib)dlsym(module[1],"glXGetFBConfigAttrib"); + glXGetProcAddressARBSrc = (PFN_glXGetProcAddressARB)dlsym(module[1],"glXGetProcAddressARB"); + glXChooseFBConfigSrc = (PFN_glXChooseFBConfig)dlsym(module[1],"glXChooseFBConfig"); + #endif + + /* send the module to the user */ + #if !defined(__cplusplus) || defined(XDL_NO_DEALLOCATE) + return module; + #else + return {module}; + #endif +} + +void XDL_close(XDLModule m) { + #if defined(__cplusplus) && !defined(XDL_NO_DEALLOCATE) + void** module = m.module; + #else + void** module = m; + #endif + if (module != NULL) { + /* close the modules and free their data */ + dlclose(module[0]); + + #ifndef XDL_NO_GLX + dlclose(module[1]); + #endif + + free(module); + } + + module = NULL; +} +#if defined(__cplusplus) && !defined(XDL_NO_DEALLOCATE) +XDLModule::~XDLModule() { + XDL_close(*this); +} +#endif + +#endif \ No newline at end of file diff --git a/examples/minimal_links/minimal_links.c b/examples/minimal_links/minimal_links.c new file mode 100644 index 000000000..b2d7bdda1 --- /dev/null +++ b/examples/minimal_links/minimal_links.c @@ -0,0 +1,30 @@ +#define RGFW_IMPLEMENTATION +#define RGFW_NO_API +#define RGFW_WGL_LOAD + +#ifdef __linux__ +#define XDL_IMPLEMENTATION +#include "XDL.h" +#endif + +#include "RGFW.h" + +int main() { + #ifdef __linux__ + XDLModule m = XDL_init(); + #endif + + RGFW_window* win = RGFW_createWindow("a window", RGFW_RECT(0, 0, 800, 600), (u16)(RGFW_center | RGFW_noResize)); + + while (RGFW_window_shouldClose(win) == RGFW_FALSE) { + while (RGFW_window_checkEvent(win)) + + RGFW_window_swapBuffers(win); + } + + RGFW_window_close(win); + + #ifdef __linux__ + XDL_close(m); + #endif +} \ No newline at end of file diff --git a/examples/osmesa/osmesa.c b/examples/osmesa/osmesa.c new file mode 100644 index 000000000..cec12ec41 --- /dev/null +++ b/examples/osmesa/osmesa.c @@ -0,0 +1,34 @@ +#define RGFW_IMPLEMENTATION +#define RGFW_PRINT_ERRORS +#define RGFW_DEBUG +#define RGFW_OSMESA +#include "RGFW.h" +#include + +int main(void) { + RGFW_setClassName("RGFW Basic"); + RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(500, 500, 500, 500), RGFW_allowDND | RGFW_center); + RGFW_window_makeCurrent(win); + + while (RGFW_window_shouldClose(win) == RGFW_FALSE) { + RGFW_window_eventWait(win, RGFW_waitNext); + while (RGFW_window_checkEvent(win) != NULL); + + RGFW_window_makeCurrent(win); + + glClearColor(255, 255, 255, 255); + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor3f(1, 0, 0); glVertex2f(-0.6, -0.75); + glColor3f(0, 1, 0); glVertex2f(0.6, -0.75); + glColor3f(0, 0, 1); glVertex2f(0, 0.75); + glEnd(); + + glFlush(); + RGFW_window_swapBuffers(win); + } + + RGFW_window_close(win); +} \ No newline at end of file diff --git a/examples/portableGL/pgl.c b/examples/portableGL/pgl.c index 38bc821a2..fbd8fc0b2 100644 --- a/examples/portableGL/pgl.c +++ b/examples/portableGL/pgl.c @@ -29,7 +29,7 @@ int main() { RGFW_area area = RGFW_AREA(500, 500); RGFW_setBufferSize(area); - RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(500, 500, 500, 500), (u64)RGFW_CENTER | RGFW_NO_RESIZE); + RGFW_window* win = RGFW_createWindow("name", RGFW_RECT(500, 500, 500, 500), (u64)RGFW_center | RGFW_noResize); glContext context; init_glContext(&context, (u32**)&win->buffer, area.w, 500, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); diff --git a/examples/silk/silk.c b/examples/silk/silk.c index bcc8c0c3e..431bbd73e 100644 --- a/examples/silk/silk.c +++ b/examples/silk/silk.c @@ -21,7 +21,7 @@ typedef int64_t i64; int main(void) { RGFW_setBufferSize(RGFW_AREA(500, 500)); - RGFW_window* win = RGFW_createWindow("Basic buffer example", RGFW_RECT(0, 0, 500, 500), RGFW_CENTER | RGFW_TRANSPARENT_WINDOW | RGFW_NO_RESIZE); + RGFW_window* win = RGFW_createWindow("Basic buffer example", RGFW_RECT(0, 0, 500, 500), RGFW_center | RGFW_transparent | RGFW_noResize); u32 angle = 0; diff --git a/examples/vk10/RGFW_vulkan.h b/examples/vk10/RGFW_vulkan.h index 016b79029..d91d2c02a 100644 --- a/examples/vk10/RGFW_vulkan.h +++ b/examples/vk10/RGFW_vulkan.h @@ -183,14 +183,14 @@ int RGFW_deviceInitialization(RGFW_window* win, RGFW_window_vulkanInfo* vulkWin) u32 deviceCount = 0; vkEnumeratePhysicalDevices(RGFW_vulkan_info.instance, &deviceCount, NULL); - VkPhysicalDevice* devices = (VkPhysicalDevice*) RGFW_MALLOC(sizeof(VkPhysicalDevice) * deviceCount); + VkPhysicalDevice* devices = (VkPhysicalDevice*) RGFW_alloc(sizeof(VkPhysicalDevice) * deviceCount); vkEnumeratePhysicalDevices(RGFW_vulkan_info.instance, &deviceCount, devices); RGFW_vulkan_info.physical_device = devices[0]; u32 queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(RGFW_vulkan_info.physical_device, &queue_family_count, NULL); - VkQueueFamilyProperties* queueFamilies = (VkQueueFamilyProperties*) RGFW_MALLOC(sizeof(VkQueueFamilyProperties) * queue_family_count); + VkQueueFamilyProperties* queueFamilies = (VkQueueFamilyProperties*) RGFW_alloc(sizeof(VkQueueFamilyProperties) * queue_family_count); vkGetPhysicalDeviceQueueFamilyProperties(RGFW_vulkan_info.physical_device, &queue_family_count, queueFamilies); float queuePriority = 1.0f; @@ -267,10 +267,10 @@ int RGFW_createSwapchain(RGFW_window* win, RGFW_window_vulkanInfo* vulkWin) { u32 imageCount; vkGetSwapchainImagesKHR(RGFW_vulkan_info.device, vulkWin->swapchain, &imageCount, NULL); - vulkWin->swapchain_images = (VkImage*) RGFW_MALLOC(sizeof(VkImage) * imageCount); + vulkWin->swapchain_images = (VkImage*) RGFW_alloc(sizeof(VkImage) * imageCount); vkGetSwapchainImagesKHR(RGFW_vulkan_info.device, vulkWin->swapchain, &imageCount, vulkWin->swapchain_images); - vulkWin->swapchain_image_views = (VkImageView*) RGFW_MALLOC(sizeof(VkImageView) * imageCount); + vulkWin->swapchain_image_views = (VkImageView*) RGFW_alloc(sizeof(VkImageView) * imageCount); for (u32 i = 0; i < imageCount; i++) { VkImageViewCreateInfo image_view_cre_infos = { 0 }; image_view_cre_infos.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; @@ -354,7 +354,7 @@ int RGFW_createCommandPool(void) { int RGFW_createCommandBuffers(RGFW_window_vulkanInfo* vulkWin) { assert(vulkWin != NULL); - RGFW_vulkan_info.command_buffers = (VkCommandBuffer*) RGFW_MALLOC(sizeof(VkCommandBuffer) * vulkWin->image_count); + RGFW_vulkan_info.command_buffers = (VkCommandBuffer*) RGFW_alloc(sizeof(VkCommandBuffer) * vulkWin->image_count); VkCommandBufferAllocateInfo allocInfo = { 0 }; allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; @@ -372,10 +372,10 @@ int RGFW_createCommandBuffers(RGFW_window_vulkanInfo* vulkWin) { int RGFW_createSyncObjects(RGFW_window_vulkanInfo* vulkWin) { assert(vulkWin != NULL); - RGFW_vulkan_info.available_semaphores = (VkSemaphore*) RGFW_MALLOC(sizeof(VkSemaphore) * RGFW_MAX_FRAMES_IN_FLIGHT); - RGFW_vulkan_info.finished_semaphore = (VkSemaphore*) RGFW_MALLOC(sizeof(VkSemaphore) * RGFW_MAX_FRAMES_IN_FLIGHT); - RGFW_vulkan_info.in_flight_fences = (VkFence*) RGFW_MALLOC(sizeof(VkFence) * RGFW_MAX_FRAMES_IN_FLIGHT); - RGFW_vulkan_info.image_in_flight = (VkFence*) RGFW_MALLOC(sizeof(VkFence) * vulkWin->image_count); + RGFW_vulkan_info.available_semaphores = (VkSemaphore*) RGFW_alloc(sizeof(VkSemaphore) * RGFW_MAX_FRAMES_IN_FLIGHT); + RGFW_vulkan_info.finished_semaphore = (VkSemaphore*) RGFW_alloc(sizeof(VkSemaphore) * RGFW_MAX_FRAMES_IN_FLIGHT); + RGFW_vulkan_info.in_flight_fences = (VkFence*) RGFW_alloc(sizeof(VkFence) * RGFW_MAX_FRAMES_IN_FLIGHT); + RGFW_vulkan_info.image_in_flight = (VkFence*) RGFW_alloc(sizeof(VkFence) * vulkWin->image_count); VkSemaphoreCreateInfo semaphore_info = { 0 }; semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; @@ -403,7 +403,7 @@ int RGFW_createSyncObjects(RGFW_window_vulkanInfo* vulkWin) { int RGFW_createFramebuffers(RGFW_window* win, RGFW_window_vulkanInfo* vulkWin) { assert(vulkWin != NULL); - RGFW_vulkan_info.framebuffers = (VkFramebuffer*) RGFW_MALLOC(sizeof(VkFramebuffer) * vulkWin->image_count); + RGFW_vulkan_info.framebuffers = (VkFramebuffer*) RGFW_alloc(sizeof(VkFramebuffer) * vulkWin->image_count); for (size_t i = 0; i < vulkWin->image_count; i++) { VkImageView attachments[] = { vulkWin->swapchain_image_views[i] }; @@ -435,8 +435,8 @@ void RGFW_freeVulkan(RGFW_window_vulkanInfo* vulkWin) { vkDestroySwapchainKHR(RGFW_vulkan_info.device, vulkWin->swapchain, NULL); vkDestroySurfaceKHR(RGFW_vulkan_info.instance, vulkWin->rSurf, NULL); - RGFW_FREE(vulkWin->swapchain_image_views); - RGFW_FREE(vulkWin->swapchain_images); + RGFW_free(vulkWin->swapchain_image_views); + RGFW_free(vulkWin->swapchain_images); vkDeviceWaitIdle(RGFW_vulkan_info.device); @@ -462,12 +462,12 @@ void RGFW_freeVulkan(RGFW_window_vulkanInfo* vulkWin) { vkDestroyDevice(RGFW_vulkan_info.device, NULL); vkDestroyInstance(RGFW_vulkan_info.instance, NULL); - RGFW_FREE(RGFW_vulkan_info.framebuffers); - RGFW_FREE(RGFW_vulkan_info.command_buffers); - RGFW_FREE(RGFW_vulkan_info.available_semaphores); - RGFW_FREE(RGFW_vulkan_info.finished_semaphore); - RGFW_FREE(RGFW_vulkan_info.in_flight_fences); - RGFW_FREE(RGFW_vulkan_info.image_in_flight); + RGFW_free(RGFW_vulkan_info.framebuffers); + RGFW_free(RGFW_vulkan_info.command_buffers); + RGFW_free(RGFW_vulkan_info.available_semaphores); + RGFW_free(RGFW_vulkan_info.finished_semaphore); + RGFW_free(RGFW_vulkan_info.in_flight_fences); + RGFW_free(RGFW_vulkan_info.image_in_flight); } VkShaderModule RGFW_createShaderModule(const u32* code, size_t code_size) { diff --git a/examples/vk10/vk10.c b/examples/vk10/vk10.c index a8e6d37a3..ac8fdef40 100644 --- a/examples/vk10/vk10.c +++ b/examples/vk10/vk10.c @@ -31,7 +31,7 @@ int draw_frame(RGFW_window_vulkanInfo* vulkWin); int main(void) { - RGFW_window* win = RGFW_createWindow("Vulkan Example", RGFW_RECT(0, 0, 500, 500), RGFW_ALLOW_DND | RGFW_CENTER);; + RGFW_window* win = RGFW_createWindow("Vulkan Example", RGFW_RECT(0, 0, 500, 500), RGFW_allowDND | RGFW_center);; RGFW_window_vulkanInfo vulkWin; vulkan_info = RGFW_initVulkan(win, &vulkWin);