From 53eaf8f12fb4859c6966d98d591744e0a0477318 Mon Sep 17 00:00:00 2001 From: ColleagueRiley Date: Thu, 16 Jan 2025 21:12:23 +0000 Subject: [PATCH] deploy: cace5319471d66fc23b29701bc8dc33c98e0453b --- RGFW.h | 13 +- RGFW.o | Bin 1413686 -> 1413686 bytes docs/RGFW_8h_source.html | 17035 +++++++++++---------- docs/md_README.html | 4 +- examples/callbacks/callbacks.wasm | Bin 123501 -> 123501 bytes examples/events/events.wasm | Bin 111827 -> 111827 bytes examples/first-person-camera/camera.wasm | Bin 101829 -> 101829 bytes examples/gamepad/gamepad.wasm | Bin 132388 -> 132388 bytes examples/gles2/gles2.wasm | Bin 80672 -> 80672 bytes examples/microui_demo/microui_demo.wasm | Bin 353259 -> 353259 bytes examples/webgpu/webgpu.wasm | Bin 46804 -> 46804 bytes libRGFW.a | Bin 1413754 -> 1413754 bytes libRGFW.so | Bin 1420847 -> 1420847 bytes 13 files changed, 8537 insertions(+), 8515 deletions(-) diff --git a/RGFW.h b/RGFW.h index 9f23b76..e660966 100644 --- a/RGFW.h +++ b/RGFW.h @@ -625,6 +625,7 @@ typedef struct RGFW_window_src { #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) HDC hdcMem; HBITMAP bitmap; + u8* bitmapBits; #endif RGFW_area maxSize, minSize; /*!< for setting max/min resize (RGFW_WINDOWS) */ } RGFW_window_src; @@ -1731,7 +1732,11 @@ void RGFW_window_initBuffer(RGFW_window* win) { void RGFW_window_initBufferSize(RGFW_window* win, RGFW_area area) { if (!(win->_flags & RGFW_BUFFER_ALLOC)) win->_flags |= RGFW_BUFFER_ALLOC; + #ifndef RGFW_WINDOWS return RGFW_window_initBufferPtr(win, RGFW_ALLOC(area.w * area.h * 4), area); + #else /* windows's bitmap allocs memory for us */ + return RGFW_window_initBufferPtr(win, NULL, area); + #endif } #ifdef RGFW_MACOS @@ -5429,9 +5434,12 @@ void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area){ win->src.bitmap = CreateDIBSection(win->src.hdc, (BITMAPINFO*) &bi, DIB_RGB_COLORS, - (void**) &win->buffer, + (void**) &win->src.bitmapBits, NULL, (DWORD) 0); + + if (win->buffer == NULL) + win->buffer = win->src.bitmapBits; win->src.hdcMem = CreateCompatibleDC(win->src.hdc); @@ -6883,6 +6891,9 @@ void RGFW_window_swapBuffers(RGFW_window* win) { if (!(win->_flags & RGFW_NO_CPU_RENDER)) { #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) + if (win->buffer != win->src.bitmapBits) + memcpy(win->src.bitmapBits, win->buffer, win->bufferSize.w * win->bufferSize.h * 4); + HGDIOBJ oldbmp = SelectObject(win->src.hdcMem, win->src.bitmap); BitBlt(win->src.hdc, 0, 0, win->r.w, win->r.h, win->src.hdcMem, 0, 0, SRCCOPY); SelectObject(win->src.hdcMem, oldbmp); diff --git a/RGFW.o b/RGFW.o index db512f76cf5c220276417a06b60d094867bd4105..befaa67ca902c1769e67d3ed2ac356b3c1ac945d 100644 GIT binary patch delta 107 zcmWN=xeb6I06@{;ec|l{RxpP%FoX?5Sh$7-jh%@JRyv#iCC@wKow;5u&im8rB92Yj gU0K0^AtT02m@;F|f+Z_T)@<0aW6y!(qwFN-AN8>!c>n+a delta 107 zcmWN=xeb6I06@{;eW7?wU 625 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
626 HDC hdcMem;
627 HBITMAP bitmap;
-
628 #endif
-
629 RGFW_area maxSize, minSize;
-
630} RGFW_window_src;
-
631#elif defined(RGFW_UNIX)
-
632typedef struct RGFW_window_src {
-
633#if defined(RGFW_X11)
-
634 Display* display;
-
635 Window window;
-
636 #if (defined(RGFW_OPENGL)) && !defined(RGFW_OSMESA) && !defined(RGFW_EGL)
-
637 GLXContext ctx;
-
638 #elif defined(RGFW_OSMESA)
-
639 OSMesaContext ctx;
-
640 #elif defined(RGFW_EGL)
-
641 EGLSurface EGL_surface;
-
642 EGLDisplay EGL_display;
-
643 EGLContext EGL_context;
-
644 #endif
-
645
-
646 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
647 XImage* bitmap;
-
648 GC gc;
-
649 #endif
-
650#endif /* RGFW_X11 */
-
651#if defined(RGFW_WAYLAND)
-
652 struct wl_display* wl_display;
-
653 struct wl_surface* surface;
-
654 struct wl_buffer* wl_buffer;
-
655 struct wl_keyboard* keyboard;
-
656
-
657 struct wl_compositor* compositor;
-
658 struct xdg_surface* xdg_surface;
-
659 struct xdg_toplevel* xdg_toplevel;
-
660 struct zxdg_toplevel_decoration_v1* decoration;
-
661 struct xdg_wm_base* xdg_wm_base;
-
662 struct wl_shm* shm;
-
663 struct wl_seat *seat;
-
664 u8* buffer;
-
665
-
666 RGFW_event events[20];
-
667 i32 eventLen;
-
668 size_t eventIndex;
-
669 #if defined(RGFW_EGL)
-
670 struct wl_egl_window* eglWindow;
-
671 #endif
-
672 #if defined(RGFW_EGL) && !defined(RGFW_X11)
-
673 EGLSurface EGL_surface;
-
674 EGLDisplay EGL_display;
-
675 EGLContext EGL_context;
-
676 #elif defined(RGFW_OSMESA) && !defined(RGFW_X11)
-
677 OSMesaContext ctx;
-
678 #endif
-
679#endif /* RGFW_WAYLAND */
-
680} RGFW_window_src;
-
681#endif /* RGFW_UNIX */
-
682#if defined(RGFW_MACOS)
-
683typedef struct RGFW_window_src {
-
684 void* window;
-
685 b8 dndPassed;
-
686#if (defined(RGFW_OPENGL)) && !defined(RGFW_OSMESA) && !defined(RGFW_EGL)
-
687 void* ctx;
-
688#elif defined(RGFW_OSMESA)
-
689 OSMesaContext ctx;
-
690#elif defined(RGFW_EGL)
-
691 EGLSurface EGL_surface;
-
692 EGLDisplay EGL_display;
-
693 EGLContext EGL_context;
-
694#endif
-
695
-
696 void* view; /*apple viewpoint thingy*/
-
697
-
698#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
699 void* bitmap;
-
700 void* image;
-
701#endif
-
702} RGFW_window_src;
-
703#elif defined(RGFW_WEBASM)
-
704typedef struct RGFW_window_src {
-
705 #ifdef RGFW_WEBGPU
-
706 WGPUInstance ctx;
-
707 WGPUDevice device;
-
708 WGPUQueue queue;
-
709 #else
-
710 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;
-
711 #endif
-
712} RGFW_window_src;
-
713#endif
-
714
-
716typedef RGFW_ENUM(u32, RGFW_windowFlags) {
-
717 RGFW_windowNoInitAPI = RGFW_BIT(0), /* DO not init an API (mostly for bindings, you should use `#define RGFW_NO_API` in C */
-
718 RGFW_windowNoBorder = RGFW_BIT(1),
-
719 RGFW_windowNoResize = RGFW_BIT(2),
-
720 RGFW_windowAllowDND = RGFW_BIT(3),
-
721 RGFW_windowHideMouse = RGFW_BIT(4),
-
722 RGFW_windowFullscreen = RGFW_BIT(5), /* the window is fullscreen by default or not */
-
723 RGFW_windowTransparent = RGFW_BIT(6),
-
724 RGFW_windowCenter = RGFW_BIT(7),
-
725 RGFW_windowOpenglSoftware = RGFW_BIT(8),
-
726 RGFW_windowCocoaCHDirToRes = RGFW_BIT(9), /* (cocoa only), change directory to resource folder */
-
727 RGFW_windowScaleToMonitor = RGFW_BIT(10), /* scale the window to the screen */
-
728 RGFW_windowHide = RGFW_BIT(11)/* the window is hidden */
-
729};
-
730
-
731typedef struct RGFW_window {
-
732 RGFW_window_src src;
-
734#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
735 u8* buffer;
-
736 /* when rendering using RGFW_BUFFER, the buffer is in the RGBA format */
-
737 RGFW_area bufferSize;
-
738#endif
-
739 void* userPtr; /* ptr for usr data */
-
740
- - - - - -
750#if defined(RGFW_X11) || defined(RGFW_MACOS)
-
751 typedef u64 RGFW_thread;
-
752#else
-
753 typedef void* RGFW_thread;
-
754#endif
-
755
-
764RGFWDEF void RGFW_setClassName(const char* name);
-
765
-
766/* NOTE: (windows)If the executable has an icon resource named RGFW_ICON, it will be set as the initial icon for the window.*/
-
767
- -
769 const char* name, /* name of the window */
-
770 RGFW_rect rect, /* rect of window */
-
771 RGFW_windowFlags flags /* extra arguments ((u32)0 means no flags used)*/
-
772);
- -
775 const char* name, /* name of the window */
-
776 RGFW_rect rect, /* rect of window */
-
777 RGFW_windowFlags flags, /* extra arguments (NULL / (u32)0 means no flags used)*/
-
778 RGFW_window* win /* ptr to the window struct you want to use */
-
779);
- - - -
784
- -
787
+
628 u8* bitmapBits;
+
629 #endif
+
630 RGFW_area maxSize, minSize;
+
631} RGFW_window_src;
+
632#elif defined(RGFW_UNIX)
+
633typedef struct RGFW_window_src {
+
634#if defined(RGFW_X11)
+
635 Display* display;
+
636 Window window;
+
637 #if (defined(RGFW_OPENGL)) && !defined(RGFW_OSMESA) && !defined(RGFW_EGL)
+
638 GLXContext ctx;
+
639 #elif defined(RGFW_OSMESA)
+
640 OSMesaContext ctx;
+
641 #elif defined(RGFW_EGL)
+
642 EGLSurface EGL_surface;
+
643 EGLDisplay EGL_display;
+
644 EGLContext EGL_context;
+
645 #endif
+
646
+
647 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
648 XImage* bitmap;
+
649 GC gc;
+
650 #endif
+
651#endif /* RGFW_X11 */
+
652#if defined(RGFW_WAYLAND)
+
653 struct wl_display* wl_display;
+
654 struct wl_surface* surface;
+
655 struct wl_buffer* wl_buffer;
+
656 struct wl_keyboard* keyboard;
+
657
+
658 struct wl_compositor* compositor;
+
659 struct xdg_surface* xdg_surface;
+
660 struct xdg_toplevel* xdg_toplevel;
+
661 struct zxdg_toplevel_decoration_v1* decoration;
+
662 struct xdg_wm_base* xdg_wm_base;
+
663 struct wl_shm* shm;
+
664 struct wl_seat *seat;
+
665 u8* buffer;
+
666
+
667 RGFW_event events[20];
+
668 i32 eventLen;
+
669 size_t eventIndex;
+
670 #if defined(RGFW_EGL)
+
671 struct wl_egl_window* eglWindow;
+
672 #endif
+
673 #if defined(RGFW_EGL) && !defined(RGFW_X11)
+
674 EGLSurface EGL_surface;
+
675 EGLDisplay EGL_display;
+
676 EGLContext EGL_context;
+
677 #elif defined(RGFW_OSMESA) && !defined(RGFW_X11)
+
678 OSMesaContext ctx;
+
679 #endif
+
680#endif /* RGFW_WAYLAND */
+
681} RGFW_window_src;
+
682#endif /* RGFW_UNIX */
+
683#if defined(RGFW_MACOS)
+
684typedef struct RGFW_window_src {
+
685 void* window;
+
686 b8 dndPassed;
+
687#if (defined(RGFW_OPENGL)) && !defined(RGFW_OSMESA) && !defined(RGFW_EGL)
+
688 void* ctx;
+
689#elif defined(RGFW_OSMESA)
+
690 OSMesaContext ctx;
+
691#elif defined(RGFW_EGL)
+
692 EGLSurface EGL_surface;
+
693 EGLDisplay EGL_display;
+
694 EGLContext EGL_context;
+
695#endif
+
696
+
697 void* view; /*apple viewpoint thingy*/
+
698
+
699#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
700 void* bitmap;
+
701 void* image;
+
702#endif
+
703} RGFW_window_src;
+
704#elif defined(RGFW_WEBASM)
+
705typedef struct RGFW_window_src {
+
706 #ifdef RGFW_WEBGPU
+
707 WGPUInstance ctx;
+
708 WGPUDevice device;
+
709 WGPUQueue queue;
+
710 #else
+
711 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;
+
712 #endif
+
713} RGFW_window_src;
+
714#endif
+
715
+
717typedef RGFW_ENUM(u32, RGFW_windowFlags) {
+
718 RGFW_windowNoInitAPI = RGFW_BIT(0), /* DO not init an API (mostly for bindings, you should use `#define RGFW_NO_API` in C */
+
719 RGFW_windowNoBorder = RGFW_BIT(1),
+
720 RGFW_windowNoResize = RGFW_BIT(2),
+
721 RGFW_windowAllowDND = RGFW_BIT(3),
+
722 RGFW_windowHideMouse = RGFW_BIT(4),
+
723 RGFW_windowFullscreen = RGFW_BIT(5), /* the window is fullscreen by default or not */
+
724 RGFW_windowTransparent = RGFW_BIT(6),
+
725 RGFW_windowCenter = RGFW_BIT(7),
+
726 RGFW_windowOpenglSoftware = RGFW_BIT(8),
+
727 RGFW_windowCocoaCHDirToRes = RGFW_BIT(9), /* (cocoa only), change directory to resource folder */
+
728 RGFW_windowScaleToMonitor = RGFW_BIT(10), /* scale the window to the screen */
+
729 RGFW_windowHide = RGFW_BIT(11)/* the window is hidden */
+
730};
+
731
+
732typedef struct RGFW_window {
+
733 RGFW_window_src src;
+
735#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
736 u8* buffer;
+
737 /* when rendering using RGFW_BUFFER, the buffer is in the RGBA format */
+
738 RGFW_area bufferSize;
+
739#endif
+
740 void* userPtr; /* ptr for usr data */
+
741
+ + + + + +
751#if defined(RGFW_X11) || defined(RGFW_MACOS)
+
752 typedef u64 RGFW_thread;
+
753#else
+
754 typedef void* RGFW_thread;
+
755#endif
+
756
+
765RGFWDEF void RGFW_setClassName(const char* name);
+
766
+
767/* NOTE: (windows)If the executable has an icon resource named RGFW_ICON, it will be set as the initial icon for the window.*/
+
768
+ +
770 const char* name, /* name of the window */
+
771 RGFW_rect rect, /* rect of window */
+
772 RGFW_windowFlags flags /* extra arguments ((u32)0 means no flags used)*/
+
773);
+ +
776 const char* name, /* name of the window */
+
777 RGFW_rect rect, /* rect of window */
+
778 RGFW_windowFlags flags, /* extra arguments (NULL / (u32)0 means no flags used)*/
+
779 RGFW_window* win /* ptr to the window struct you want to use */
+
780);
+ + + +
785
+
788
- -
810typedef RGFW_ENUM(i32, RGFW_eventWait) {
-
811 RGFW_eventWaitNext = -1,
-
812 RGFW_eventNoWait = 0
-
813};
-
814
- -
817
- -
823
- -
828
- - -
834 RGFW_point v
-
835);
-
836
-
837#ifndef RGFW_NO_MONITOR
- -
840#endif
-
841
- -
844 RGFW_area a
-
845);
-
846
- - -
851
- - - - -
858
- -
861
-
862#ifndef RGFW_NO_PASSTHROUGH
- -
865#endif
-
866
- -
869 const char* name
-
870);
-
871
- -
873 u8* icon ,
-
874 RGFW_area a ,
-
875 i32 channels
-
876);
- -
880
- -
883
- -
885/*
-
886 Locks cursor at the center of the window
-
887 win->event.point become raw mouse movement data
-
888
-
889 this is useful for a 3D camera
-
890*/
- - -
894
- - -
899
-
900/*
-
901 makes it so `RGFW_window_shouldClose` returns true
-
902 by setting the window event.type to RGFW_quit
-
903*/
- -
905
- -
908
- -
911
- - -
916
- - - - - -
927
-
933#ifndef RGFW_NO_MONITOR
-
934/*
-
935scale the window to the monitor,
-
936this is run by default if the user uses the arg `RGFW_scaleToMonitor` during window creation
-
937*/
- - -
941#endif
-
942
- - - - -
956/* if a key is pressed and then released, pretty much the same as RGFW_isReleased */
- -
958
-
960RGFWDEF b8 RGFW_isMousePressed(RGFW_window* win, RGFW_mouseButton button );
-
962RGFWDEF b8 RGFW_isMouseHeld(RGFW_window* win, RGFW_mouseButton button );
-
964RGFWDEF b8 RGFW_isMouseReleased(RGFW_window* win, RGFW_mouseButton button );
-
966RGFWDEF b8 RGFW_wasMousePressed(RGFW_window* win, RGFW_mouseButton button );
-
971typedef ptrdiff_t RGFW_ssize_t;
-
972
-
973RGFWDEF const char* RGFW_readClipboard(size_t* size);
-
975RGFWDEF RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity);
-
976RGFWDEF void RGFW_writeClipboard(const char* text, u32 textLen);
-
991typedef void (* RGFW_windowmovefunc)(RGFW_window* win, RGFW_rect r);
- -
995typedef void (* RGFW_windowquitfunc)(RGFW_window* win);
-
997typedef void (* RGFW_focusfunc)(RGFW_window* win, b8 inFocus);
-
999typedef void (* RGFW_mouseNotifyfunc)(RGFW_window* win, RGFW_point point, b8 status);
-
1001typedef void (* RGFW_mouseposfunc)(RGFW_window* win, RGFW_point point);
-
1003typedef void (* RGFW_dndInitfunc)(RGFW_window* win, RGFW_point point);
- -
1007typedef void (* RGFW_keyfunc)(RGFW_window* win, u8 key, char keyChar, RGFW_keymod keyMod, b8 pressed);
-
1009typedef void (* RGFW_mousebuttonfunc)(RGFW_window* win, RGFW_mouseButton button, double scroll, b8 pressed);
-
1011typedef void (* RGFW_gamepadButtonfunc)(RGFW_window* win, u16 gamepad, u8 button, b8 pressed);
-
1013typedef void (* RGFW_gamepadAxisfunc)(RGFW_window* win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis);
-
1015typedef void (* RGFW_gamepadfunc)(RGFW_window* win, u16 gamepad, b8 connected);
-
1016
-
1018typedef void (* RGFW_dndfunc)(RGFW_window* win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount);
-
1019
- - - - - - - - - - - - - - -
1048
-
1054#ifndef RGFW_NO_THREADS
-
1058/*
-
1059 I'd suggest you use sili's threading functions instead
-
1060 if you're going to use sili
-
1061 which is a good idea generally
-
1062*/
-
1063
-
1064#if defined(__unix__) || defined(__APPLE__) || defined(RGFW_WEBASM) || defined(RGFW_CUSTOM_BACKEND)
-
1065 typedef void* (* RGFW_threadFunc_ptr)(void*);
-
1066#else
-
1067 typedef DWORD (__stdcall *RGFW_threadFunc_ptr) (LPVOID lpThreadParameter);
-
1068#endif
-
1069
- - - - -
1074#endif
-
1075
-
1081typedef RGFW_ENUM(u8, RGFW_gamepadType) {
-
1082 RGFW_gamepadMicrosoft = 0, RGFW_gamepadSony, RGFW_gamepadNintendo, RGFW_gamepadLogitech, RGFW_gamepadUnknown
-
1083};
-
1084
-
1086RGFWDEF u32 RGFW_isPressedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
-
1087RGFWDEF u32 RGFW_isReleasedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
-
1088RGFWDEF u32 RGFW_isHeldGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
-
1089RGFWDEF u32 RGFW_wasPressedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
- -
1091RGFWDEF const char* RGFW_getGamepadName(RGFW_window* win, u16 controller);
- -
1093RGFWDEF RGFW_gamepadType RGFW_getGamepadType(RGFW_window* win, u16 controller);
-
1094
- -
1108
-
1109/*< updates fps / sets fps to cap (must by ran manually by the user at the end of a frame), returns current fps */
- -
1111
-
1112/* supports openGL, directX, OSMesa, EGL and software rendering */
- - -
1115
- - -
1118
-
1120#if defined(RGFW_OPENGL) || defined(RGFW_EGL)
- - - - -
1128typedef RGFW_ENUM(u8, RGFW_glProfile) { RGFW_glCore = 0, RGFW_glCompatibility };
-
1130RGFWDEF void RGFW_setGLVersion(RGFW_glProfile profile, i32 major, i32 minor);
-
1131RGFWDEF void RGFW_setDoubleBuffer(b8 useDoubleBuffer);
-
1132RGFWDEF void* RGFW_getProcAddress(const char* procname);
- -
1135#elif defined(RGFW_DIRECTX)
-
1136typedef struct {
-
1137 IDXGIFactory* pFactory;
-
1138 IDXGIAdapter* pAdapter;
-
1139 ID3D11Device* pDevice;
-
1140 ID3D11DeviceContext* pDeviceContext;
-
1141} RGFW_directXinfo;
-
1142
-
1143/*
-
1144 RGFW stores a global instance of RGFW_directXinfo,
-
1145 you can use this function to get a pointer the instance
-
1146*/
-
1147RGFWDEF RGFW_directXinfo* RGFW_getDirectXInfo(void);
-
1148#endif
-
1149
- - -
1156RGFWDEF void RGFW_sleep(u64 milisecond);
- -
1163 RGFW_keyNULL = 0,
-
1164 RGFW_escape = '\033',
-
1165 RGFW_backtick = '`',
-
1166 RGFW_0 = '0',
-
1167 RGFW_1 = '1',
-
1168 RGFW_2 = '2',
-
1169 RGFW_3 = '3',
-
1170 RGFW_4 = '4',
-
1171 RGFW_5 = '5',
-
1172 RGFW_6 = '6',
-
1173 RGFW_7 = '7',
-
1174 RGFW_8 = '8',
-
1175 RGFW_9 = '9',
-
1176
-
1177 RGFW_minus = '-',
-
1178 RGFW_equals = '=',
-
1179 RGFW_backSpace = '\b',
-
1180 RGFW_tab = '\t',
-
1181 RGFW_space = ' ',
-
1182
-
1183 RGFW_a = 'a',
-
1184 RGFW_b = 'b',
-
1185 RGFW_c = 'c',
-
1186 RGFW_d = 'd',
-
1187 RGFW_e = 'e',
-
1188 RGFW_f = 'f',
-
1189 RGFW_g = 'g',
-
1190 RGFW_h = 'h',
-
1191 RGFW_i = 'i',
-
1192 RGFW_j = 'j',
-
1193 RGFW_k = 'k',
-
1194 RGFW_l = 'l',
-
1195 RGFW_m = 'm',
-
1196 RGFW_n = 'n',
-
1197 RGFW_o = 'o',
-
1198 RGFW_p = 'p',
-
1199 RGFW_q = 'q',
-
1200 RGFW_r = 'r',
-
1201 RGFW_s = 's',
-
1202 RGFW_t = 't',
-
1203 RGFW_u = 'u',
-
1204 RGFW_v = 'v',
-
1205 RGFW_w = 'w',
-
1206 RGFW_x = 'x',
-
1207 RGFW_y = 'y',
-
1208 RGFW_z = 'z',
-
1209
-
1210 RGFW_period = '.',
-
1211 RGFW_comma = ',',
-
1212 RGFW_slash = '/',
-
1213 RGFW_bracket = '{',
-
1214 RGFW_closeBracket = '}',
-
1215 RGFW_semicolon = ';',
-
1216 RGFW_apostrophe = '\'',
-
1217 RGFW_backSlash = '\\',
-
1218 RGFW_return = '\n',
-
1219
-
1220 RGFW_delete = '\177', /* 127 */
-
1221
-
1222 RGFW_F1,
-
1223 RGFW_F2,
-
1224 RGFW_F3,
-
1225 RGFW_F4,
-
1226 RGFW_F5,
-
1227 RGFW_F6,
-
1228 RGFW_F7,
-
1229 RGFW_F8,
-
1230 RGFW_F9,
-
1231 RGFW_F10,
-
1232 RGFW_F11,
-
1233 RGFW_F12,
-
1234
-
1235 RGFW_capsLock,
-
1236 RGFW_shiftL,
-
1237 RGFW_controlL,
-
1238 RGFW_altL,
-
1239 RGFW_superL,
-
1240 RGFW_shiftR,
-
1241 RGFW_controlR,
-
1242 RGFW_altR,
-
1243 RGFW_superR,
-
1244 RGFW_up,
-
1245 RGFW_down,
-
1246 RGFW_left,
-
1247 RGFW_right,
-
1248
-
1249 RGFW_insert,
-
1250 RGFW_end,
-
1251 RGFW_home,
-
1252 RGFW_pageUp,
-
1253 RGFW_pageDown,
-
1254
-
1255 RGFW_numLock,
-
1256 RGFW_KP_Slash,
-
1257 RGFW_multiply,
-
1258 RGFW_KP_Minus,
-
1259 RGFW_KP_1,
-
1260 RGFW_KP_2,
-
1261 RGFW_KP_3,
-
1262 RGFW_KP_4,
-
1263 RGFW_KP_5,
-
1264 RGFW_KP_6,
-
1265 RGFW_KP_7,
-
1266 RGFW_KP_8,
-
1267 RGFW_KP_9,
-
1268 RGFW_KP_0,
-
1269 RGFW_KP_Period,
-
1270 RGFW_KP_Return,
-
1271 RGFW_keyLast
-
1272};
-
1273
- -
1275
-
1276typedef RGFW_ENUM(u8, RGFW_mouseIcons) {
-
1277 RGFW_mouseNormal = 0,
-
1278 RGFW_mouseArrow,
-
1279 RGFW_mouseIbeam,
-
1280 RGFW_mouseCrosshair,
-
1281 RGFW_mousePointingHand,
-
1282 RGFW_mouseResizeEW,
-
1283 RGFW_mouseResizeNS,
-
1284 RGFW_mouseResizeNWSE,
-
1285 RGFW_mouseResizeNESW,
-
1286 RGFW_mouseResizeAll,
-
1287 RGFW_mouseNotAllowed,
-
1288};
-
1289
-
1292#endif /* RGFW_HEADER */
-
1293#if defined(RGFW_X11) || defined(RGFW_WAYLAND)
-
1294 #define RGFW_OS_BASED_VALUE(l, w, m, h) l
-
1295#elif defined(RGFW_WINDOWS)
-
1296 #define RGFW_OS_BASED_VALUE(l, w, m, h) w
-
1297#elif defined(RGFW_MACOS)
-
1298 #define RGFW_OS_BASED_VALUE(l, w, m, h) m
-
1299#elif defined(RGFW_WEBASM)
-
1300 #define RGFW_OS_BASED_VALUE(l, w, m, h) h
-
1301#endif
-
1302
+
789
+ +
811typedef RGFW_ENUM(i32, RGFW_eventWait) {
+
812 RGFW_eventWaitNext = -1,
+
813 RGFW_eventNoWait = 0
+
814};
+
815
+ +
818
+ +
824
+ +
829
+ + +
835 RGFW_point v
+
836);
+
837
+
838#ifndef RGFW_NO_MONITOR
+ +
841#endif
+
842
+ +
845 RGFW_area a
+
846);
+
847
+ + +
852
+ + + + +
859
+ +
862
+
863#ifndef RGFW_NO_PASSTHROUGH
+ +
866#endif
+
867
+ +
870 const char* name
+
871);
+
872
+ +
874 u8* icon ,
+
875 RGFW_area a ,
+
876 i32 channels
+
877);
+ +
881
+ +
884
+ +
886/*
+
887 Locks cursor at the center of the window
+
888 win->event.point become raw mouse movement data
+
889
+
890 this is useful for a 3D camera
+
891*/
+ + +
895
+ + +
900
+
901/*
+
902 makes it so `RGFW_window_shouldClose` returns true
+
903 by setting the window event.type to RGFW_quit
+
904*/
+ +
906
+ +
909
+ +
912
+ + +
917
+ + + + + +
928
+
934#ifndef RGFW_NO_MONITOR
+
935/*
+
936scale the window to the monitor,
+
937this is run by default if the user uses the arg `RGFW_scaleToMonitor` during window creation
+
938*/
+ + +
942#endif
+
943
+ + + + +
957/* if a key is pressed and then released, pretty much the same as RGFW_isReleased */
+ +
959
+
961RGFWDEF b8 RGFW_isMousePressed(RGFW_window* win, RGFW_mouseButton button );
+
963RGFWDEF b8 RGFW_isMouseHeld(RGFW_window* win, RGFW_mouseButton button );
+
965RGFWDEF b8 RGFW_isMouseReleased(RGFW_window* win, RGFW_mouseButton button );
+
967RGFWDEF b8 RGFW_wasMousePressed(RGFW_window* win, RGFW_mouseButton button );
+
972typedef ptrdiff_t RGFW_ssize_t;
+
973
+
974RGFWDEF const char* RGFW_readClipboard(size_t* size);
+
976RGFWDEF RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity);
+
977RGFWDEF void RGFW_writeClipboard(const char* text, u32 textLen);
+
992typedef void (* RGFW_windowmovefunc)(RGFW_window* win, RGFW_rect r);
+ +
996typedef void (* RGFW_windowquitfunc)(RGFW_window* win);
+
998typedef void (* RGFW_focusfunc)(RGFW_window* win, b8 inFocus);
+
1000typedef void (* RGFW_mouseNotifyfunc)(RGFW_window* win, RGFW_point point, b8 status);
+
1002typedef void (* RGFW_mouseposfunc)(RGFW_window* win, RGFW_point point);
+
1004typedef void (* RGFW_dndInitfunc)(RGFW_window* win, RGFW_point point);
+ +
1008typedef void (* RGFW_keyfunc)(RGFW_window* win, u8 key, char keyChar, RGFW_keymod keyMod, b8 pressed);
+
1010typedef void (* RGFW_mousebuttonfunc)(RGFW_window* win, RGFW_mouseButton button, double scroll, b8 pressed);
+
1012typedef void (* RGFW_gamepadButtonfunc)(RGFW_window* win, u16 gamepad, u8 button, b8 pressed);
+
1014typedef void (* RGFW_gamepadAxisfunc)(RGFW_window* win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis);
+
1016typedef void (* RGFW_gamepadfunc)(RGFW_window* win, u16 gamepad, b8 connected);
+
1017
+
1019typedef void (* RGFW_dndfunc)(RGFW_window* win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount);
+
1020
+ + + + + + + + + + + + + + +
1049
+
1055#ifndef RGFW_NO_THREADS
+
1059/*
+
1060 I'd suggest you use sili's threading functions instead
+
1061 if you're going to use sili
+
1062 which is a good idea generally
+
1063*/
+
1064
+
1065#if defined(__unix__) || defined(__APPLE__) || defined(RGFW_WEBASM) || defined(RGFW_CUSTOM_BACKEND)
+
1066 typedef void* (* RGFW_threadFunc_ptr)(void*);
+
1067#else
+
1068 typedef DWORD (__stdcall *RGFW_threadFunc_ptr) (LPVOID lpThreadParameter);
+
1069#endif
+
1070
+ + + + +
1075#endif
+
1076
+
1082typedef RGFW_ENUM(u8, RGFW_gamepadType) {
+
1083 RGFW_gamepadMicrosoft = 0, RGFW_gamepadSony, RGFW_gamepadNintendo, RGFW_gamepadLogitech, RGFW_gamepadUnknown
+
1084};
+
1085
+
1087RGFWDEF u32 RGFW_isPressedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
+
1088RGFWDEF u32 RGFW_isReleasedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
+
1089RGFWDEF u32 RGFW_isHeldGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
+
1090RGFWDEF u32 RGFW_wasPressedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button);
+ +
1092RGFWDEF const char* RGFW_getGamepadName(RGFW_window* win, u16 controller);
+ +
1094RGFWDEF RGFW_gamepadType RGFW_getGamepadType(RGFW_window* win, u16 controller);
+
1095
+ +
1109
+
1110/*< updates fps / sets fps to cap (must by ran manually by the user at the end of a frame), returns current fps */
+ +
1112
+
1113/* supports openGL, directX, OSMesa, EGL and software rendering */
+ + +
1116
+ + +
1119
+
1121#if defined(RGFW_OPENGL) || defined(RGFW_EGL)
+ + + + +
1129typedef RGFW_ENUM(u8, RGFW_glProfile) { RGFW_glCore = 0, RGFW_glCompatibility };
+
1131RGFWDEF void RGFW_setGLVersion(RGFW_glProfile profile, i32 major, i32 minor);
+
1132RGFWDEF void RGFW_setDoubleBuffer(b8 useDoubleBuffer);
+
1133RGFWDEF void* RGFW_getProcAddress(const char* procname);
+ +
1136#elif defined(RGFW_DIRECTX)
+
1137typedef struct {
+
1138 IDXGIFactory* pFactory;
+
1139 IDXGIAdapter* pAdapter;
+
1140 ID3D11Device* pDevice;
+
1141 ID3D11DeviceContext* pDeviceContext;
+
1142} RGFW_directXinfo;
+
1143
+
1144/*
+
1145 RGFW stores a global instance of RGFW_directXinfo,
+
1146 you can use this function to get a pointer the instance
+
1147*/
+
1148RGFWDEF RGFW_directXinfo* RGFW_getDirectXInfo(void);
+
1149#endif
+
1150
+ + +
1157RGFWDEF void RGFW_sleep(u64 milisecond);
+ +
1164 RGFW_keyNULL = 0,
+
1165 RGFW_escape = '\033',
+
1166 RGFW_backtick = '`',
+
1167 RGFW_0 = '0',
+
1168 RGFW_1 = '1',
+
1169 RGFW_2 = '2',
+
1170 RGFW_3 = '3',
+
1171 RGFW_4 = '4',
+
1172 RGFW_5 = '5',
+
1173 RGFW_6 = '6',
+
1174 RGFW_7 = '7',
+
1175 RGFW_8 = '8',
+
1176 RGFW_9 = '9',
+
1177
+
1178 RGFW_minus = '-',
+
1179 RGFW_equals = '=',
+
1180 RGFW_backSpace = '\b',
+
1181 RGFW_tab = '\t',
+
1182 RGFW_space = ' ',
+
1183
+
1184 RGFW_a = 'a',
+
1185 RGFW_b = 'b',
+
1186 RGFW_c = 'c',
+
1187 RGFW_d = 'd',
+
1188 RGFW_e = 'e',
+
1189 RGFW_f = 'f',
+
1190 RGFW_g = 'g',
+
1191 RGFW_h = 'h',
+
1192 RGFW_i = 'i',
+
1193 RGFW_j = 'j',
+
1194 RGFW_k = 'k',
+
1195 RGFW_l = 'l',
+
1196 RGFW_m = 'm',
+
1197 RGFW_n = 'n',
+
1198 RGFW_o = 'o',
+
1199 RGFW_p = 'p',
+
1200 RGFW_q = 'q',
+
1201 RGFW_r = 'r',
+
1202 RGFW_s = 's',
+
1203 RGFW_t = 't',
+
1204 RGFW_u = 'u',
+
1205 RGFW_v = 'v',
+
1206 RGFW_w = 'w',
+
1207 RGFW_x = 'x',
+
1208 RGFW_y = 'y',
+
1209 RGFW_z = 'z',
+
1210
+
1211 RGFW_period = '.',
+
1212 RGFW_comma = ',',
+
1213 RGFW_slash = '/',
+
1214 RGFW_bracket = '{',
+
1215 RGFW_closeBracket = '}',
+
1216 RGFW_semicolon = ';',
+
1217 RGFW_apostrophe = '\'',
+
1218 RGFW_backSlash = '\\',
+
1219 RGFW_return = '\n',
+
1220
+
1221 RGFW_delete = '\177', /* 127 */
+
1222
+
1223 RGFW_F1,
+
1224 RGFW_F2,
+
1225 RGFW_F3,
+
1226 RGFW_F4,
+
1227 RGFW_F5,
+
1228 RGFW_F6,
+
1229 RGFW_F7,
+
1230 RGFW_F8,
+
1231 RGFW_F9,
+
1232 RGFW_F10,
+
1233 RGFW_F11,
+
1234 RGFW_F12,
+
1235
+
1236 RGFW_capsLock,
+
1237 RGFW_shiftL,
+
1238 RGFW_controlL,
+
1239 RGFW_altL,
+
1240 RGFW_superL,
+
1241 RGFW_shiftR,
+
1242 RGFW_controlR,
+
1243 RGFW_altR,
+
1244 RGFW_superR,
+
1245 RGFW_up,
+
1246 RGFW_down,
+
1247 RGFW_left,
+
1248 RGFW_right,
+
1249
+
1250 RGFW_insert,
+
1251 RGFW_end,
+
1252 RGFW_home,
+
1253 RGFW_pageUp,
+
1254 RGFW_pageDown,
+
1255
+
1256 RGFW_numLock,
+
1257 RGFW_KP_Slash,
+
1258 RGFW_multiply,
+
1259 RGFW_KP_Minus,
+
1260 RGFW_KP_1,
+
1261 RGFW_KP_2,
+
1262 RGFW_KP_3,
+
1263 RGFW_KP_4,
+
1264 RGFW_KP_5,
+
1265 RGFW_KP_6,
+
1266 RGFW_KP_7,
+
1267 RGFW_KP_8,
+
1268 RGFW_KP_9,
+
1269 RGFW_KP_0,
+
1270 RGFW_KP_Period,
+
1271 RGFW_KP_Return,
+
1272 RGFW_keyLast
+
1273};
+
1274
+ +
1276
+
1277typedef RGFW_ENUM(u8, RGFW_mouseIcons) {
+
1278 RGFW_mouseNormal = 0,
+
1279 RGFW_mouseArrow,
+
1280 RGFW_mouseIbeam,
+
1281 RGFW_mouseCrosshair,
+
1282 RGFW_mousePointingHand,
+
1283 RGFW_mouseResizeEW,
+
1284 RGFW_mouseResizeNS,
+
1285 RGFW_mouseResizeNWSE,
+
1286 RGFW_mouseResizeNESW,
+
1287 RGFW_mouseResizeAll,
+
1288 RGFW_mouseNotAllowed,
+
1289};
+
1290
+
1293#endif /* RGFW_HEADER */
+
1294#if defined(RGFW_X11) || defined(RGFW_WAYLAND)
+
1295 #define RGFW_OS_BASED_VALUE(l, w, m, h) l
+
1296#elif defined(RGFW_WINDOWS)
+
1297 #define RGFW_OS_BASED_VALUE(l, w, m, h) w
+
1298#elif defined(RGFW_MACOS)
+
1299 #define RGFW_OS_BASED_VALUE(l, w, m, h) m
+
1300#elif defined(RGFW_WEBASM)
+
1301 #define RGFW_OS_BASED_VALUE(l, w, m, h) h
+
1302#endif
1303
-
1304#ifdef RGFW_IMPLEMENTATION
-
1305b8 RGFW_useWaylandBool = 1;
-
1306
-
1307#ifdef RGFW_DEBUG
-
1308#include <stdio.h>
-
1309#endif
-
1310
-
1311#ifndef RGFW_ASSERT
-
1312 #include <assert.h>
-
1313 #define RGFW_ASSERT assert
-
1314#endif
-
1315
-
1316char* RGFW_clipboard_data;
-
1317void RGFW_clipboard_switch(char* newstr) {
-
1318 if (RGFW_clipboard_data != NULL)
-
1319 RGFW_FREE(RGFW_clipboard_data);
-
1320 RGFW_clipboard_data = newstr;
-
1321}
-
1322
-
1323#define RGFW_CHECK_CLIPBOARD() \
-
1324 if (size <= 0 && RGFW_clipboard_data != NULL) \
-
1325 return (const char*)RGFW_clipboard_data; \
-
1326 else if (size <= 0) \
-
1327 return "\0";
-
1328
-
1329const char* RGFW_readClipboard(size_t* len) {
-
1330 RGFW_ssize_t size = RGFW_readClipboardPtr(NULL, 0);
-
1331 RGFW_CHECK_CLIPBOARD();
-
1332 char* str = (char*)RGFW_ALLOC(size);
-
1333 size = RGFW_readClipboardPtr(str, size);
-
1334 RGFW_CHECK_CLIPBOARD();
-
1335
-
1336 if (len != NULL) *len = size;
-
1337
-
1338 RGFW_clipboard_switch(str);
-
1339 return (const char*)str;
-
1340}
-
1341
-
1342/*
-
1343RGFW_IMPLEMENTATION starts with generic RGFW defines
-
1344
-
1345This is the start of keycode data
-
1346
-
1347 Why not use macros instead of the numbers itself?
-
1348 Windows -> Not all scancodes keys are macros
-
1349 Linux -> Only symcodes are values, (XK_0 - XK_1, XK_a - XK_z) are larger than 0xFF00, I can't find any way to work with them without making the array an unreasonable size
-
1350 MacOS -> windows and linux already don't have keycodes as macros, so there's no point
-
1351*/
-
1352
+
1304
+
1305#ifdef RGFW_IMPLEMENTATION
+
1306b8 RGFW_useWaylandBool = 1;
+
1307
+
1308#ifdef RGFW_DEBUG
+
1309#include <stdio.h>
+
1310#endif
+
1311
+
1312#ifndef RGFW_ASSERT
+
1313 #include <assert.h>
+
1314 #define RGFW_ASSERT assert
+
1315#endif
+
1316
+
1317char* RGFW_clipboard_data;
+
1318void RGFW_clipboard_switch(char* newstr) {
+
1319 if (RGFW_clipboard_data != NULL)
+
1320 RGFW_FREE(RGFW_clipboard_data);
+
1321 RGFW_clipboard_data = newstr;
+
1322}
+
1323
+
1324#define RGFW_CHECK_CLIPBOARD() \
+
1325 if (size <= 0 && RGFW_clipboard_data != NULL) \
+
1326 return (const char*)RGFW_clipboard_data; \
+
1327 else if (size <= 0) \
+
1328 return "\0";
+
1329
+
1330const char* RGFW_readClipboard(size_t* len) {
+
1331 RGFW_ssize_t size = RGFW_readClipboardPtr(NULL, 0);
+
1332 RGFW_CHECK_CLIPBOARD();
+
1333 char* str = (char*)RGFW_ALLOC(size);
+
1334 size = RGFW_readClipboardPtr(str, size);
+
1335 RGFW_CHECK_CLIPBOARD();
+
1336
+
1337 if (len != NULL) *len = size;
+
1338
+
1339 RGFW_clipboard_switch(str);
+
1340 return (const char*)str;
+
1341}
+
1342
+
1343/*
+
1344RGFW_IMPLEMENTATION starts with generic RGFW defines
+
1345
+
1346This is the start of keycode data
+
1347
+
1348 Why not use macros instead of the numbers itself?
+
1349 Windows -> Not all scancodes keys are macros
+
1350 Linux -> Only symcodes are values, (XK_0 - XK_1, XK_a - XK_z) are larger than 0xFF00, I can't find any way to work with them without making the array an unreasonable size
+
1351 MacOS -> windows and linux already don't have keycodes as macros, so there's no point
+
1352*/
1353
1354
-
1355/*
-
1356 the c++ compiler doesn't support setting up an array like,
-
1357 we'll have to do it during runtime using a function & this messy setup
-
1358*/
-
1359
-
1360#ifndef RGFW_CUSTOM_BACKEND
-
1361
-
1362#ifndef __cplusplus
-
1363#define RGFW_NEXT ,
-
1364#define RGFW_MAP
-
1365#else
-
1366#define RGFW_NEXT ;
-
1367#define RGFW_MAP RGFW_keycodes
-
1368#endif
-
1369
-
1370u8 RGFW_keycodes [RGFW_OS_BASED_VALUE(136, 0x15C + 1, 128, DOM_VK_WIN_OEM_CLEAR + 1)] = {
-
1371#ifdef __cplusplus
-
1372 0
-
1373};
-
1374void RGFW_init_keys(void) {
-
1375#endif
-
1376 RGFW_MAP [RGFW_OS_BASED_VALUE(49, 0x029, 50, DOM_VK_BACK_QUOTE)] = RGFW_backtick RGFW_NEXT
-
1377
-
1378 RGFW_MAP [RGFW_OS_BASED_VALUE(19, 0x00B, 29, DOM_VK_0)] = RGFW_0 RGFW_NEXT
-
1379 RGFW_MAP [RGFW_OS_BASED_VALUE(10, 0x002, 18, DOM_VK_1)] = RGFW_1 RGFW_NEXT
-
1380 RGFW_MAP [RGFW_OS_BASED_VALUE(11, 0x003, 19, DOM_VK_2)] = RGFW_2 RGFW_NEXT
-
1381 RGFW_MAP [RGFW_OS_BASED_VALUE(12, 0x004, 20, DOM_VK_3)] = RGFW_3 RGFW_NEXT
-
1382 RGFW_MAP [RGFW_OS_BASED_VALUE(13, 0x005, 21, DOM_VK_4)] = RGFW_4 RGFW_NEXT
-
1383 RGFW_MAP [RGFW_OS_BASED_VALUE(14, 0x006, 23, DOM_VK_5)] = RGFW_5 RGFW_NEXT
-
1384 RGFW_MAP [RGFW_OS_BASED_VALUE(15, 0x007, 22, DOM_VK_6)] = RGFW_6 RGFW_NEXT
-
1385 RGFW_MAP [RGFW_OS_BASED_VALUE(16, 0x008, 26, DOM_VK_7)] = RGFW_7 RGFW_NEXT
-
1386 RGFW_MAP [RGFW_OS_BASED_VALUE(17, 0x009, 28, DOM_VK_8)] = RGFW_8 RGFW_NEXT
-
1387 RGFW_MAP [RGFW_OS_BASED_VALUE(18, 0x00A, 25, DOM_VK_9)] = RGFW_9,
-
1388 RGFW_MAP [RGFW_OS_BASED_VALUE(65, 0x039, 49, DOM_VK_SPACE)] = RGFW_space,
-
1389 RGFW_MAP [RGFW_OS_BASED_VALUE(38, 0x01E, 0, DOM_VK_A)] = RGFW_a RGFW_NEXT
-
1390 RGFW_MAP [RGFW_OS_BASED_VALUE(56, 0x030, 11, DOM_VK_B)] = RGFW_b RGFW_NEXT
-
1391 RGFW_MAP [RGFW_OS_BASED_VALUE(54, 0x02E, 8, DOM_VK_C)] = RGFW_c RGFW_NEXT
-
1392 RGFW_MAP [RGFW_OS_BASED_VALUE(40, 0x020, 2, DOM_VK_D)] = RGFW_d RGFW_NEXT
-
1393 RGFW_MAP [RGFW_OS_BASED_VALUE(26, 0x012, 14, DOM_VK_E)] = RGFW_e RGFW_NEXT
-
1394 RGFW_MAP [RGFW_OS_BASED_VALUE(41, 0x021, 3, DOM_VK_F)] = RGFW_f RGFW_NEXT
-
1395 RGFW_MAP [RGFW_OS_BASED_VALUE(42, 0x022, 5, DOM_VK_G)] = RGFW_g RGFW_NEXT
-
1396 RGFW_MAP [RGFW_OS_BASED_VALUE(43, 0x023, 4, DOM_VK_H)] = RGFW_h RGFW_NEXT
-
1397 RGFW_MAP [RGFW_OS_BASED_VALUE(31, 0x017, 34, DOM_VK_I)] = RGFW_i RGFW_NEXT
-
1398 RGFW_MAP [RGFW_OS_BASED_VALUE(44, 0x024, 38, DOM_VK_J)] = RGFW_j RGFW_NEXT
-
1399 RGFW_MAP [RGFW_OS_BASED_VALUE(45, 0x025, 40, DOM_VK_K)] = RGFW_k RGFW_NEXT
-
1400 RGFW_MAP [RGFW_OS_BASED_VALUE(46, 0x026, 37, DOM_VK_L)] = RGFW_l RGFW_NEXT
-
1401 RGFW_MAP [RGFW_OS_BASED_VALUE(58, 0x032, 46, DOM_VK_M)] = RGFW_m RGFW_NEXT
-
1402 RGFW_MAP [RGFW_OS_BASED_VALUE(57, 0x031, 45, DOM_VK_N)] = RGFW_n RGFW_NEXT
-
1403 RGFW_MAP [RGFW_OS_BASED_VALUE(32, 0x018, 31, DOM_VK_O)] = RGFW_o RGFW_NEXT
-
1404 RGFW_MAP [RGFW_OS_BASED_VALUE(33, 0x019, 35, DOM_VK_P)] = RGFW_p RGFW_NEXT
-
1405 RGFW_MAP [RGFW_OS_BASED_VALUE(24, 0x010, 12, DOM_VK_Q)] = RGFW_q RGFW_NEXT
-
1406 RGFW_MAP [RGFW_OS_BASED_VALUE(27, 0x013, 15, DOM_VK_R)] = RGFW_r RGFW_NEXT
-
1407 RGFW_MAP [RGFW_OS_BASED_VALUE(39, 0x01F, 1, DOM_VK_S)] = RGFW_s RGFW_NEXT
-
1408 RGFW_MAP [RGFW_OS_BASED_VALUE(28, 0x014, 17, DOM_VK_T)] = RGFW_t RGFW_NEXT
-
1409 RGFW_MAP [RGFW_OS_BASED_VALUE(30, 0x016, 32, DOM_VK_U)] = RGFW_u RGFW_NEXT
-
1410 RGFW_MAP [RGFW_OS_BASED_VALUE(55, 0x02F, 9, DOM_VK_V)] = RGFW_v RGFW_NEXT
-
1411 RGFW_MAP [RGFW_OS_BASED_VALUE(25, 0x011, 13, DOM_VK_W)] = RGFW_w RGFW_NEXT
-
1412 RGFW_MAP [RGFW_OS_BASED_VALUE(53, 0x02D, 7, DOM_VK_X)] = RGFW_x RGFW_NEXT
-
1413 RGFW_MAP [RGFW_OS_BASED_VALUE(29, 0x015, 16, DOM_VK_Y)] = RGFW_y RGFW_NEXT
-
1414 RGFW_MAP [RGFW_OS_BASED_VALUE(52, 0x02C, 6, DOM_VK_Z)] = RGFW_z,
-
1415 RGFW_MAP [RGFW_OS_BASED_VALUE(60, 0x034, 47, DOM_VK_PERIOD)] = RGFW_period RGFW_NEXT
-
1416 RGFW_MAP [RGFW_OS_BASED_VALUE(59, 0x033, 43, DOM_VK_COMMA)] = RGFW_comma RGFW_NEXT
-
1417 RGFW_MAP [RGFW_OS_BASED_VALUE(61, 0x035, 44, DOM_VK_SLASH)] = RGFW_slash RGFW_NEXT
-
1418 RGFW_MAP [RGFW_OS_BASED_VALUE(34, 0x01A, 33, DOM_VK_OPEN_BRACKET)] = RGFW_bracket RGFW_NEXT
-
1419 RGFW_MAP [RGFW_OS_BASED_VALUE(35, 0x01B, 30, DOM_VK_CLOSE_BRACKET)] = RGFW_closeBracket RGFW_NEXT
-
1420 RGFW_MAP [RGFW_OS_BASED_VALUE(47, 0x027, 41, DOM_VK_SEMICOLON)] = RGFW_semicolon RGFW_NEXT
-
1421 RGFW_MAP [RGFW_OS_BASED_VALUE(48, 0x028, 39, DOM_VK_QUOTE)] = RGFW_apostrophe RGFW_NEXT
-
1422 RGFW_MAP [RGFW_OS_BASED_VALUE(51, 0x02B, 42, DOM_VK_BACK_SLASH)] = RGFW_backSlash,
-
1423 RGFW_MAP [RGFW_OS_BASED_VALUE(36, 0x01C, 36, DOM_VK_RETURN)] = RGFW_return RGFW_NEXT
-
1424 RGFW_MAP [RGFW_OS_BASED_VALUE(119, 0x153, 118, DOM_VK_DELETE)] = RGFW_delete RGFW_NEXT
-
1425 RGFW_MAP [RGFW_OS_BASED_VALUE(77, 0x145, 72, DOM_VK_NUM_LOCK)] = RGFW_numLock RGFW_NEXT
-
1426 RGFW_MAP [RGFW_OS_BASED_VALUE(106, 0x135, 82, DOM_VK_DIVIDE)] = RGFW_KP_Slash RGFW_NEXT
-
1427 RGFW_MAP [RGFW_OS_BASED_VALUE(63, 0x037, 76, DOM_VK_MULTIPLY)] = RGFW_multiply RGFW_NEXT
-
1428 RGFW_MAP [RGFW_OS_BASED_VALUE(82, 0x04A, 67, DOM_VK_SUBTRACT)] = RGFW_KP_Minus RGFW_NEXT
-
1429 RGFW_MAP [RGFW_OS_BASED_VALUE(87, 0x04F, 84, DOM_VK_NUMPAD1)] = RGFW_KP_1 RGFW_NEXT
-
1430 RGFW_MAP [RGFW_OS_BASED_VALUE(88, 0x050, 85, DOM_VK_NUMPAD2)] = RGFW_KP_2 RGFW_NEXT
-
1431 RGFW_MAP [RGFW_OS_BASED_VALUE(89, 0x051, 86, DOM_VK_NUMPAD3)] = RGFW_KP_3 RGFW_NEXT
-
1432 RGFW_MAP [RGFW_OS_BASED_VALUE(83, 0x04B, 87, DOM_VK_NUMPAD4)] = RGFW_KP_4 RGFW_NEXT
-
1433 RGFW_MAP [RGFW_OS_BASED_VALUE(84, 0x04C, 88, DOM_VK_NUMPAD5)] = RGFW_KP_5 RGFW_NEXT
-
1434 RGFW_MAP [RGFW_OS_BASED_VALUE(85, 0x04D, 89, DOM_VK_NUMPAD6)] = RGFW_KP_6 RGFW_NEXT
-
1435 RGFW_MAP [RGFW_OS_BASED_VALUE(79, 0x047, 90, DOM_VK_NUMPAD7)] = RGFW_KP_7 RGFW_NEXT
-
1436 RGFW_MAP [RGFW_OS_BASED_VALUE(80, 0x048, 92, DOM_VK_NUMPAD8)] = RGFW_KP_8 RGFW_NEXT
-
1437 RGFW_MAP [RGFW_OS_BASED_VALUE(81, 0x049, 93, DOM_VK_NUMPAD9)] = RGFW_KP_9 RGFW_NEXT
-
1438 RGFW_MAP [RGFW_OS_BASED_VALUE(90, 0x052, 83, DOM_VK_NUMPAD0)] = RGFW_KP_0 RGFW_NEXT
-
1439 RGFW_MAP [RGFW_OS_BASED_VALUE(91, 0x053, 65, DOM_VK_DECIMAL)] = RGFW_KP_Period RGFW_NEXT
-
1440 RGFW_MAP [RGFW_OS_BASED_VALUE(104, 0x11C, 77, 0)] = RGFW_KP_Return,
-
1441 RGFW_MAP [RGFW_OS_BASED_VALUE(20, 0x00C, 27, DOM_VK_HYPHEN_MINUS)] = RGFW_minus RGFW_NEXT
-
1442 RGFW_MAP [RGFW_OS_BASED_VALUE(21, 0x00D, 24, DOM_VK_EQUALS)] = RGFW_equals RGFW_NEXT
-
1443 RGFW_MAP [RGFW_OS_BASED_VALUE(22, 0x00E, 51, DOM_VK_BACK_SPACE)] = RGFW_backSpace RGFW_NEXT
-
1444 RGFW_MAP [RGFW_OS_BASED_VALUE(23, 0x00F, 48, DOM_VK_TAB)] = RGFW_tab RGFW_NEXT
-
1445 RGFW_MAP [RGFW_OS_BASED_VALUE(66, 0x03A, 57, DOM_VK_CAPS_LOCK)] = RGFW_capsLock RGFW_NEXT
-
1446 RGFW_MAP [RGFW_OS_BASED_VALUE(50, 0x02A, 56, DOM_VK_SHIFT)] = RGFW_shiftL RGFW_NEXT
-
1447 RGFW_MAP [RGFW_OS_BASED_VALUE(37, 0x01D, 59, DOM_VK_CONTROL)] = RGFW_controlL RGFW_NEXT
-
1448 RGFW_MAP [RGFW_OS_BASED_VALUE(64, 0x038, 58, DOM_VK_ALT)] = RGFW_altL RGFW_NEXT
-
1449 RGFW_MAP [RGFW_OS_BASED_VALUE(133, 0x15B, 55, DOM_VK_WIN)] = RGFW_superL,
-
1450 #if !defined(RGFW_MACOS) && !defined(RGFW_WEBASM)
-
1451 RGFW_MAP [RGFW_OS_BASED_VALUE(105, 0x11D, 59, 0)] = RGFW_controlR RGFW_NEXT
-
1452 RGFW_MAP [RGFW_OS_BASED_VALUE(135, 0x15C, 55, 0)] = RGFW_superR,
-
1453 RGFW_MAP [RGFW_OS_BASED_VALUE(62, 0x036, 56, 0)] = RGFW_shiftR RGFW_NEXT
-
1454 RGFW_MAP [RGFW_OS_BASED_VALUE(108, 0x138, 58, 0)] = RGFW_altR,
-
1455 #endif
-
1456 RGFW_MAP [RGFW_OS_BASED_VALUE(67, 0x03B, 127, DOM_VK_F1)] = RGFW_F1 RGFW_NEXT
-
1457 RGFW_MAP [RGFW_OS_BASED_VALUE(68, 0x03C, 121, DOM_VK_F2)] = RGFW_F2 RGFW_NEXT
-
1458 RGFW_MAP [RGFW_OS_BASED_VALUE(69, 0x03D, 100, DOM_VK_F3)] = RGFW_F3 RGFW_NEXT
-
1459 RGFW_MAP [RGFW_OS_BASED_VALUE(70, 0x03E, 119, DOM_VK_F4)] = RGFW_F4 RGFW_NEXT
-
1460 RGFW_MAP [RGFW_OS_BASED_VALUE(71, 0x03F, 97, DOM_VK_F5)] = RGFW_F5 RGFW_NEXT
-
1461 RGFW_MAP [RGFW_OS_BASED_VALUE(72, 0x040, 98, DOM_VK_F6)] = RGFW_F6 RGFW_NEXT
-
1462 RGFW_MAP [RGFW_OS_BASED_VALUE(73, 0x041, 99, DOM_VK_F7)] = RGFW_F7 RGFW_NEXT
-
1463 RGFW_MAP [RGFW_OS_BASED_VALUE(74, 0x042, 101, DOM_VK_F8)] = RGFW_F8 RGFW_NEXT
-
1464 RGFW_MAP [RGFW_OS_BASED_VALUE(75, 0x043, 102, DOM_VK_F9)] = RGFW_F9 RGFW_NEXT
-
1465 RGFW_MAP [RGFW_OS_BASED_VALUE(76, 0x044, 110, DOM_VK_F10)] = RGFW_F10 RGFW_NEXT
-
1466 RGFW_MAP [RGFW_OS_BASED_VALUE(95, 0x057, 104, DOM_VK_F11)] = RGFW_F11 RGFW_NEXT
-
1467 RGFW_MAP [RGFW_OS_BASED_VALUE(96, 0x058, 112, DOM_VK_F12)] = RGFW_F12 RGFW_NEXT
-
1468 RGFW_MAP [RGFW_OS_BASED_VALUE(111, 0x148, 126, DOM_VK_UP)] = RGFW_up RGFW_NEXT
-
1469 RGFW_MAP [RGFW_OS_BASED_VALUE(116, 0x150, 125, DOM_VK_DOWN)] = RGFW_down RGFW_NEXT
-
1470 RGFW_MAP [RGFW_OS_BASED_VALUE(113, 0x14B, 123, DOM_VK_LEFT)] = RGFW_left RGFW_NEXT
-
1471 RGFW_MAP [RGFW_OS_BASED_VALUE(114, 0x14D, 124, DOM_VK_RIGHT)] = RGFW_right RGFW_NEXT
-
1472 RGFW_MAP [RGFW_OS_BASED_VALUE(118, 0x152, 115, DOM_VK_INSERT)] = RGFW_insert RGFW_NEXT
-
1473 RGFW_MAP [RGFW_OS_BASED_VALUE(115, 0x14F, 120, DOM_VK_END)] = RGFW_end RGFW_NEXT
-
1474 RGFW_MAP [RGFW_OS_BASED_VALUE(112, 0x149, 117, DOM_VK_PAGE_UP)] = RGFW_pageUp RGFW_NEXT
-
1475 RGFW_MAP [RGFW_OS_BASED_VALUE(117, 0x151, 122, DOM_VK_PAGE_DOWN)] = RGFW_pageDown RGFW_NEXT
-
1476 RGFW_MAP [RGFW_OS_BASED_VALUE(9, 0x001, 53, DOM_VK_ESCAPE)] = RGFW_escape RGFW_NEXT
-
1477 RGFW_MAP [RGFW_OS_BASED_VALUE(110, 0x147, 116, DOM_VK_HOME)] = RGFW_home RGFW_NEXT
-
1478#ifndef __cplusplus
-
1479};
-
1480#else
-
1481}
-
1482#endif
-
1483
-
1484#undef RGFW_NEXT
-
1485#undef RGFW_MAP
-
1486
-
1487u32 RGFW_apiKeyToRGFW(u32 keycode) {
-
1488 #ifdef __cplusplus
-
1489 if (RGFW_OS_BASED_VALUE(49, 192, 50, DOM_VK_BACK_QUOTE, KEY_GRAVE) != RGFW_backtick) {
-
1490 RGFW_init_keys();
-
1491 }
-
1492 #endif
-
1493
-
1494 /* make sure the key isn't out of bounds */
-
1495 if (keycode > sizeof(RGFW_keycodes) / sizeof(u8))
-
1496 return 0;
-
1497
-
1498 return RGFW_keycodes[keycode];
-
1499}
-
1500#endif
-
1501
-
1502typedef struct {
-
1503 b8 current : 1;
-
1504 b8 prev : 1;
-
1505} RGFW_keyState;
-
1506
-
1507RGFW_keyState RGFW_keyboard[RGFW_keyLast] = { {0, 0} };
-
1508
-
1509RGFWDEF void RGFW_resetKey(void);
-
1510void RGFW_resetKey(void) {
-
1511 size_t len = RGFW_keyLast;
-
1513 size_t i;
-
1514 for (i = 0; i < len; i++)
-
1515 RGFW_keyboard[i].prev = 0;
-
1516}
-
1517
-
1518/*
-
1519 this is the end of keycode data
-
1520*/
-
1521
-
1522/* gamepad data */
-
1523RGFW_keyState RGFW_gamepadPressed[4][18];
-
1524RGFW_point RGFW_gamepadAxes[4][4];
-
1526RGFW_gamepadType RGFW_gamepads_type[4];
-
1527i32 RGFW_gamepads[4] = {0, 0, 0, 0};
-
1528char RGFW_gamepads_name[4][128];
-
1529u16 RGFW_gamepadCount = 0;
-
1531/*
-
1532 event callback defines start here
-
1533*/
-
1534
+
1355
+
1356/*
+
1357 the c++ compiler doesn't support setting up an array like,
+
1358 we'll have to do it during runtime using a function & this messy setup
+
1359*/
+
1360
+
1361#ifndef RGFW_CUSTOM_BACKEND
+
1362
+
1363#ifndef __cplusplus
+
1364#define RGFW_NEXT ,
+
1365#define RGFW_MAP
+
1366#else
+
1367#define RGFW_NEXT ;
+
1368#define RGFW_MAP RGFW_keycodes
+
1369#endif
+
1370
+
1371u8 RGFW_keycodes [RGFW_OS_BASED_VALUE(136, 0x15C + 1, 128, DOM_VK_WIN_OEM_CLEAR + 1)] = {
+
1372#ifdef __cplusplus
+
1373 0
+
1374};
+
1375void RGFW_init_keys(void) {
+
1376#endif
+
1377 RGFW_MAP [RGFW_OS_BASED_VALUE(49, 0x029, 50, DOM_VK_BACK_QUOTE)] = RGFW_backtick RGFW_NEXT
+
1378
+
1379 RGFW_MAP [RGFW_OS_BASED_VALUE(19, 0x00B, 29, DOM_VK_0)] = RGFW_0 RGFW_NEXT
+
1380 RGFW_MAP [RGFW_OS_BASED_VALUE(10, 0x002, 18, DOM_VK_1)] = RGFW_1 RGFW_NEXT
+
1381 RGFW_MAP [RGFW_OS_BASED_VALUE(11, 0x003, 19, DOM_VK_2)] = RGFW_2 RGFW_NEXT
+
1382 RGFW_MAP [RGFW_OS_BASED_VALUE(12, 0x004, 20, DOM_VK_3)] = RGFW_3 RGFW_NEXT
+
1383 RGFW_MAP [RGFW_OS_BASED_VALUE(13, 0x005, 21, DOM_VK_4)] = RGFW_4 RGFW_NEXT
+
1384 RGFW_MAP [RGFW_OS_BASED_VALUE(14, 0x006, 23, DOM_VK_5)] = RGFW_5 RGFW_NEXT
+
1385 RGFW_MAP [RGFW_OS_BASED_VALUE(15, 0x007, 22, DOM_VK_6)] = RGFW_6 RGFW_NEXT
+
1386 RGFW_MAP [RGFW_OS_BASED_VALUE(16, 0x008, 26, DOM_VK_7)] = RGFW_7 RGFW_NEXT
+
1387 RGFW_MAP [RGFW_OS_BASED_VALUE(17, 0x009, 28, DOM_VK_8)] = RGFW_8 RGFW_NEXT
+
1388 RGFW_MAP [RGFW_OS_BASED_VALUE(18, 0x00A, 25, DOM_VK_9)] = RGFW_9,
+
1389 RGFW_MAP [RGFW_OS_BASED_VALUE(65, 0x039, 49, DOM_VK_SPACE)] = RGFW_space,
+
1390 RGFW_MAP [RGFW_OS_BASED_VALUE(38, 0x01E, 0, DOM_VK_A)] = RGFW_a RGFW_NEXT
+
1391 RGFW_MAP [RGFW_OS_BASED_VALUE(56, 0x030, 11, DOM_VK_B)] = RGFW_b RGFW_NEXT
+
1392 RGFW_MAP [RGFW_OS_BASED_VALUE(54, 0x02E, 8, DOM_VK_C)] = RGFW_c RGFW_NEXT
+
1393 RGFW_MAP [RGFW_OS_BASED_VALUE(40, 0x020, 2, DOM_VK_D)] = RGFW_d RGFW_NEXT
+
1394 RGFW_MAP [RGFW_OS_BASED_VALUE(26, 0x012, 14, DOM_VK_E)] = RGFW_e RGFW_NEXT
+
1395 RGFW_MAP [RGFW_OS_BASED_VALUE(41, 0x021, 3, DOM_VK_F)] = RGFW_f RGFW_NEXT
+
1396 RGFW_MAP [RGFW_OS_BASED_VALUE(42, 0x022, 5, DOM_VK_G)] = RGFW_g RGFW_NEXT
+
1397 RGFW_MAP [RGFW_OS_BASED_VALUE(43, 0x023, 4, DOM_VK_H)] = RGFW_h RGFW_NEXT
+
1398 RGFW_MAP [RGFW_OS_BASED_VALUE(31, 0x017, 34, DOM_VK_I)] = RGFW_i RGFW_NEXT
+
1399 RGFW_MAP [RGFW_OS_BASED_VALUE(44, 0x024, 38, DOM_VK_J)] = RGFW_j RGFW_NEXT
+
1400 RGFW_MAP [RGFW_OS_BASED_VALUE(45, 0x025, 40, DOM_VK_K)] = RGFW_k RGFW_NEXT
+
1401 RGFW_MAP [RGFW_OS_BASED_VALUE(46, 0x026, 37, DOM_VK_L)] = RGFW_l RGFW_NEXT
+
1402 RGFW_MAP [RGFW_OS_BASED_VALUE(58, 0x032, 46, DOM_VK_M)] = RGFW_m RGFW_NEXT
+
1403 RGFW_MAP [RGFW_OS_BASED_VALUE(57, 0x031, 45, DOM_VK_N)] = RGFW_n RGFW_NEXT
+
1404 RGFW_MAP [RGFW_OS_BASED_VALUE(32, 0x018, 31, DOM_VK_O)] = RGFW_o RGFW_NEXT
+
1405 RGFW_MAP [RGFW_OS_BASED_VALUE(33, 0x019, 35, DOM_VK_P)] = RGFW_p RGFW_NEXT
+
1406 RGFW_MAP [RGFW_OS_BASED_VALUE(24, 0x010, 12, DOM_VK_Q)] = RGFW_q RGFW_NEXT
+
1407 RGFW_MAP [RGFW_OS_BASED_VALUE(27, 0x013, 15, DOM_VK_R)] = RGFW_r RGFW_NEXT
+
1408 RGFW_MAP [RGFW_OS_BASED_VALUE(39, 0x01F, 1, DOM_VK_S)] = RGFW_s RGFW_NEXT
+
1409 RGFW_MAP [RGFW_OS_BASED_VALUE(28, 0x014, 17, DOM_VK_T)] = RGFW_t RGFW_NEXT
+
1410 RGFW_MAP [RGFW_OS_BASED_VALUE(30, 0x016, 32, DOM_VK_U)] = RGFW_u RGFW_NEXT
+
1411 RGFW_MAP [RGFW_OS_BASED_VALUE(55, 0x02F, 9, DOM_VK_V)] = RGFW_v RGFW_NEXT
+
1412 RGFW_MAP [RGFW_OS_BASED_VALUE(25, 0x011, 13, DOM_VK_W)] = RGFW_w RGFW_NEXT
+
1413 RGFW_MAP [RGFW_OS_BASED_VALUE(53, 0x02D, 7, DOM_VK_X)] = RGFW_x RGFW_NEXT
+
1414 RGFW_MAP [RGFW_OS_BASED_VALUE(29, 0x015, 16, DOM_VK_Y)] = RGFW_y RGFW_NEXT
+
1415 RGFW_MAP [RGFW_OS_BASED_VALUE(52, 0x02C, 6, DOM_VK_Z)] = RGFW_z,
+
1416 RGFW_MAP [RGFW_OS_BASED_VALUE(60, 0x034, 47, DOM_VK_PERIOD)] = RGFW_period RGFW_NEXT
+
1417 RGFW_MAP [RGFW_OS_BASED_VALUE(59, 0x033, 43, DOM_VK_COMMA)] = RGFW_comma RGFW_NEXT
+
1418 RGFW_MAP [RGFW_OS_BASED_VALUE(61, 0x035, 44, DOM_VK_SLASH)] = RGFW_slash RGFW_NEXT
+
1419 RGFW_MAP [RGFW_OS_BASED_VALUE(34, 0x01A, 33, DOM_VK_OPEN_BRACKET)] = RGFW_bracket RGFW_NEXT
+
1420 RGFW_MAP [RGFW_OS_BASED_VALUE(35, 0x01B, 30, DOM_VK_CLOSE_BRACKET)] = RGFW_closeBracket RGFW_NEXT
+
1421 RGFW_MAP [RGFW_OS_BASED_VALUE(47, 0x027, 41, DOM_VK_SEMICOLON)] = RGFW_semicolon RGFW_NEXT
+
1422 RGFW_MAP [RGFW_OS_BASED_VALUE(48, 0x028, 39, DOM_VK_QUOTE)] = RGFW_apostrophe RGFW_NEXT
+
1423 RGFW_MAP [RGFW_OS_BASED_VALUE(51, 0x02B, 42, DOM_VK_BACK_SLASH)] = RGFW_backSlash,
+
1424 RGFW_MAP [RGFW_OS_BASED_VALUE(36, 0x01C, 36, DOM_VK_RETURN)] = RGFW_return RGFW_NEXT
+
1425 RGFW_MAP [RGFW_OS_BASED_VALUE(119, 0x153, 118, DOM_VK_DELETE)] = RGFW_delete RGFW_NEXT
+
1426 RGFW_MAP [RGFW_OS_BASED_VALUE(77, 0x145, 72, DOM_VK_NUM_LOCK)] = RGFW_numLock RGFW_NEXT
+
1427 RGFW_MAP [RGFW_OS_BASED_VALUE(106, 0x135, 82, DOM_VK_DIVIDE)] = RGFW_KP_Slash RGFW_NEXT
+
1428 RGFW_MAP [RGFW_OS_BASED_VALUE(63, 0x037, 76, DOM_VK_MULTIPLY)] = RGFW_multiply RGFW_NEXT
+
1429 RGFW_MAP [RGFW_OS_BASED_VALUE(82, 0x04A, 67, DOM_VK_SUBTRACT)] = RGFW_KP_Minus RGFW_NEXT
+
1430 RGFW_MAP [RGFW_OS_BASED_VALUE(87, 0x04F, 84, DOM_VK_NUMPAD1)] = RGFW_KP_1 RGFW_NEXT
+
1431 RGFW_MAP [RGFW_OS_BASED_VALUE(88, 0x050, 85, DOM_VK_NUMPAD2)] = RGFW_KP_2 RGFW_NEXT
+
1432 RGFW_MAP [RGFW_OS_BASED_VALUE(89, 0x051, 86, DOM_VK_NUMPAD3)] = RGFW_KP_3 RGFW_NEXT
+
1433 RGFW_MAP [RGFW_OS_BASED_VALUE(83, 0x04B, 87, DOM_VK_NUMPAD4)] = RGFW_KP_4 RGFW_NEXT
+
1434 RGFW_MAP [RGFW_OS_BASED_VALUE(84, 0x04C, 88, DOM_VK_NUMPAD5)] = RGFW_KP_5 RGFW_NEXT
+
1435 RGFW_MAP [RGFW_OS_BASED_VALUE(85, 0x04D, 89, DOM_VK_NUMPAD6)] = RGFW_KP_6 RGFW_NEXT
+
1436 RGFW_MAP [RGFW_OS_BASED_VALUE(79, 0x047, 90, DOM_VK_NUMPAD7)] = RGFW_KP_7 RGFW_NEXT
+
1437 RGFW_MAP [RGFW_OS_BASED_VALUE(80, 0x048, 92, DOM_VK_NUMPAD8)] = RGFW_KP_8 RGFW_NEXT
+
1438 RGFW_MAP [RGFW_OS_BASED_VALUE(81, 0x049, 93, DOM_VK_NUMPAD9)] = RGFW_KP_9 RGFW_NEXT
+
1439 RGFW_MAP [RGFW_OS_BASED_VALUE(90, 0x052, 83, DOM_VK_NUMPAD0)] = RGFW_KP_0 RGFW_NEXT
+
1440 RGFW_MAP [RGFW_OS_BASED_VALUE(91, 0x053, 65, DOM_VK_DECIMAL)] = RGFW_KP_Period RGFW_NEXT
+
1441 RGFW_MAP [RGFW_OS_BASED_VALUE(104, 0x11C, 77, 0)] = RGFW_KP_Return,
+
1442 RGFW_MAP [RGFW_OS_BASED_VALUE(20, 0x00C, 27, DOM_VK_HYPHEN_MINUS)] = RGFW_minus RGFW_NEXT
+
1443 RGFW_MAP [RGFW_OS_BASED_VALUE(21, 0x00D, 24, DOM_VK_EQUALS)] = RGFW_equals RGFW_NEXT
+
1444 RGFW_MAP [RGFW_OS_BASED_VALUE(22, 0x00E, 51, DOM_VK_BACK_SPACE)] = RGFW_backSpace RGFW_NEXT
+
1445 RGFW_MAP [RGFW_OS_BASED_VALUE(23, 0x00F, 48, DOM_VK_TAB)] = RGFW_tab RGFW_NEXT
+
1446 RGFW_MAP [RGFW_OS_BASED_VALUE(66, 0x03A, 57, DOM_VK_CAPS_LOCK)] = RGFW_capsLock RGFW_NEXT
+
1447 RGFW_MAP [RGFW_OS_BASED_VALUE(50, 0x02A, 56, DOM_VK_SHIFT)] = RGFW_shiftL RGFW_NEXT
+
1448 RGFW_MAP [RGFW_OS_BASED_VALUE(37, 0x01D, 59, DOM_VK_CONTROL)] = RGFW_controlL RGFW_NEXT
+
1449 RGFW_MAP [RGFW_OS_BASED_VALUE(64, 0x038, 58, DOM_VK_ALT)] = RGFW_altL RGFW_NEXT
+
1450 RGFW_MAP [RGFW_OS_BASED_VALUE(133, 0x15B, 55, DOM_VK_WIN)] = RGFW_superL,
+
1451 #if !defined(RGFW_MACOS) && !defined(RGFW_WEBASM)
+
1452 RGFW_MAP [RGFW_OS_BASED_VALUE(105, 0x11D, 59, 0)] = RGFW_controlR RGFW_NEXT
+
1453 RGFW_MAP [RGFW_OS_BASED_VALUE(135, 0x15C, 55, 0)] = RGFW_superR,
+
1454 RGFW_MAP [RGFW_OS_BASED_VALUE(62, 0x036, 56, 0)] = RGFW_shiftR RGFW_NEXT
+
1455 RGFW_MAP [RGFW_OS_BASED_VALUE(108, 0x138, 58, 0)] = RGFW_altR,
+
1456 #endif
+
1457 RGFW_MAP [RGFW_OS_BASED_VALUE(67, 0x03B, 127, DOM_VK_F1)] = RGFW_F1 RGFW_NEXT
+
1458 RGFW_MAP [RGFW_OS_BASED_VALUE(68, 0x03C, 121, DOM_VK_F2)] = RGFW_F2 RGFW_NEXT
+
1459 RGFW_MAP [RGFW_OS_BASED_VALUE(69, 0x03D, 100, DOM_VK_F3)] = RGFW_F3 RGFW_NEXT
+
1460 RGFW_MAP [RGFW_OS_BASED_VALUE(70, 0x03E, 119, DOM_VK_F4)] = RGFW_F4 RGFW_NEXT
+
1461 RGFW_MAP [RGFW_OS_BASED_VALUE(71, 0x03F, 97, DOM_VK_F5)] = RGFW_F5 RGFW_NEXT
+
1462 RGFW_MAP [RGFW_OS_BASED_VALUE(72, 0x040, 98, DOM_VK_F6)] = RGFW_F6 RGFW_NEXT
+
1463 RGFW_MAP [RGFW_OS_BASED_VALUE(73, 0x041, 99, DOM_VK_F7)] = RGFW_F7 RGFW_NEXT
+
1464 RGFW_MAP [RGFW_OS_BASED_VALUE(74, 0x042, 101, DOM_VK_F8)] = RGFW_F8 RGFW_NEXT
+
1465 RGFW_MAP [RGFW_OS_BASED_VALUE(75, 0x043, 102, DOM_VK_F9)] = RGFW_F9 RGFW_NEXT
+
1466 RGFW_MAP [RGFW_OS_BASED_VALUE(76, 0x044, 110, DOM_VK_F10)] = RGFW_F10 RGFW_NEXT
+
1467 RGFW_MAP [RGFW_OS_BASED_VALUE(95, 0x057, 104, DOM_VK_F11)] = RGFW_F11 RGFW_NEXT
+
1468 RGFW_MAP [RGFW_OS_BASED_VALUE(96, 0x058, 112, DOM_VK_F12)] = RGFW_F12 RGFW_NEXT
+
1469 RGFW_MAP [RGFW_OS_BASED_VALUE(111, 0x148, 126, DOM_VK_UP)] = RGFW_up RGFW_NEXT
+
1470 RGFW_MAP [RGFW_OS_BASED_VALUE(116, 0x150, 125, DOM_VK_DOWN)] = RGFW_down RGFW_NEXT
+
1471 RGFW_MAP [RGFW_OS_BASED_VALUE(113, 0x14B, 123, DOM_VK_LEFT)] = RGFW_left RGFW_NEXT
+
1472 RGFW_MAP [RGFW_OS_BASED_VALUE(114, 0x14D, 124, DOM_VK_RIGHT)] = RGFW_right RGFW_NEXT
+
1473 RGFW_MAP [RGFW_OS_BASED_VALUE(118, 0x152, 115, DOM_VK_INSERT)] = RGFW_insert RGFW_NEXT
+
1474 RGFW_MAP [RGFW_OS_BASED_VALUE(115, 0x14F, 120, DOM_VK_END)] = RGFW_end RGFW_NEXT
+
1475 RGFW_MAP [RGFW_OS_BASED_VALUE(112, 0x149, 117, DOM_VK_PAGE_UP)] = RGFW_pageUp RGFW_NEXT
+
1476 RGFW_MAP [RGFW_OS_BASED_VALUE(117, 0x151, 122, DOM_VK_PAGE_DOWN)] = RGFW_pageDown RGFW_NEXT
+
1477 RGFW_MAP [RGFW_OS_BASED_VALUE(9, 0x001, 53, DOM_VK_ESCAPE)] = RGFW_escape RGFW_NEXT
+
1478 RGFW_MAP [RGFW_OS_BASED_VALUE(110, 0x147, 116, DOM_VK_HOME)] = RGFW_home RGFW_NEXT
+
1479#ifndef __cplusplus
+
1480};
+
1481#else
+
1482}
+
1483#endif
+
1484
+
1485#undef RGFW_NEXT
+
1486#undef RGFW_MAP
+
1487
+
1488u32 RGFW_apiKeyToRGFW(u32 keycode) {
+
1489 #ifdef __cplusplus
+
1490 if (RGFW_OS_BASED_VALUE(49, 192, 50, DOM_VK_BACK_QUOTE, KEY_GRAVE) != RGFW_backtick) {
+
1491 RGFW_init_keys();
+
1492 }
+
1493 #endif
+
1494
+
1495 /* make sure the key isn't out of bounds */
+
1496 if (keycode > sizeof(RGFW_keycodes) / sizeof(u8))
+
1497 return 0;
+
1498
+
1499 return RGFW_keycodes[keycode];
+
1500}
+
1501#endif
+
1502
+
1503typedef struct {
+
1504 b8 current : 1;
+
1505 b8 prev : 1;
+
1506} RGFW_keyState;
+
1507
+
1508RGFW_keyState RGFW_keyboard[RGFW_keyLast] = { {0, 0} };
+
1509
+
1510RGFWDEF void RGFW_resetKey(void);
+
1511void RGFW_resetKey(void) {
+
1512 size_t len = RGFW_keyLast;
+
1514 size_t i;
+
1515 for (i = 0; i < len; i++)
+
1516 RGFW_keyboard[i].prev = 0;
+
1517}
+
1518
+
1519/*
+
1520 this is the end of keycode data
+
1521*/
+
1522
+
1523/* gamepad data */
+
1524RGFW_keyState RGFW_gamepadPressed[4][18];
+
1525RGFW_point RGFW_gamepadAxes[4][4];
+
1527RGFW_gamepadType RGFW_gamepads_type[4];
+
1528i32 RGFW_gamepads[4] = {0, 0, 0, 0};
+
1529char RGFW_gamepads_name[4][128];
+
1530u16 RGFW_gamepadCount = 0;
+
1532/*
+
1533 event callback defines start here
+
1534*/
1535
-
1536/*
-
1537 These exist to avoid the
-
1538 if (func == NULL) check
-
1539 for (allegedly) better performance
-
1540*/
-
1541void RGFW_windowmovefuncEMPTY(RGFW_window* win, RGFW_rect r) { RGFW_UNUSED(win); RGFW_UNUSED(r); }
-
1542void RGFW_windowresizefuncEMPTY(RGFW_window* win, RGFW_rect r) { RGFW_UNUSED(win); RGFW_UNUSED(r); }
-
1543void RGFW_windowquitfuncEMPTY(RGFW_window* win) { RGFW_UNUSED(win); }
-
1544void RGFW_focusfuncEMPTY(RGFW_window* win, b8 inFocus) {RGFW_UNUSED(win); RGFW_UNUSED(inFocus);}
-
1545void RGFW_mouseNotifyfuncEMPTY(RGFW_window* win, RGFW_point point, b8 status) {RGFW_UNUSED(win); RGFW_UNUSED(point); RGFW_UNUSED(status);}
-
1546void RGFW_mouseposfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);}
-
1547void RGFW_dndInitfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);}
-
1548void RGFW_windowrefreshfuncEMPTY(RGFW_window* win) {RGFW_UNUSED(win); }
-
1549void RGFW_keyfuncEMPTY(RGFW_window* win, RGFW_key key, char keyChar, RGFW_keymod keyMod, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(key); RGFW_UNUSED(keyChar); RGFW_UNUSED(keyMod); RGFW_UNUSED(pressed);}
-
1550void RGFW_mousebuttonfuncEMPTY(RGFW_window* win, RGFW_mouseButton button, double scroll, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(button); RGFW_UNUSED(scroll); RGFW_UNUSED(pressed);}
-
1551void RGFW_gamepadButtonfuncEMPTY(RGFW_window* win, u16 gamepad, u8 button, b8 pressed){RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(button); RGFW_UNUSED(pressed); }
-
1552void 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); }
-
1553void RGFW_gamepadfuncEMPTY(RGFW_window* win, u16 gamepad, b8 connected) {RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(connected);}
-
1554void RGFW_dndfuncEMPTY(RGFW_window* win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount) {RGFW_UNUSED(win); RGFW_UNUSED(droppedFiles); RGFW_UNUSED(droppedFilesCount);}
-
1555
-
1556RGFW_windowmovefunc RGFW_windowMoveCallback = RGFW_windowmovefuncEMPTY;
-
1557RGFW_windowresizefunc RGFW_windowResizeCallback = RGFW_windowresizefuncEMPTY;
-
1558RGFW_windowquitfunc RGFW_windowQuitCallback = RGFW_windowquitfuncEMPTY;
-
1559RGFW_mouseposfunc RGFW_mousePosCallback = RGFW_mouseposfuncEMPTY;
-
1560RGFW_windowrefreshfunc RGFW_windowRefreshCallback = RGFW_windowrefreshfuncEMPTY;
-
1561RGFW_focusfunc RGFW_focusCallback = RGFW_focusfuncEMPTY;
-
1562RGFW_mouseNotifyfunc RGFW_mouseNotifyCallBack = RGFW_mouseNotifyfuncEMPTY;
-
1563RGFW_dndfunc RGFW_dndCallback = RGFW_dndfuncEMPTY;
-
1564RGFW_dndInitfunc RGFW_dndInitCallback = RGFW_dndInitfuncEMPTY;
-
1565RGFW_keyfunc RGFW_keyCallback = RGFW_keyfuncEMPTY;
-
1566RGFW_mousebuttonfunc RGFW_mouseButtonCallback = RGFW_mousebuttonfuncEMPTY;
-
1567RGFW_gamepadButtonfunc RGFW_gamepadButtonCallback = RGFW_gamepadButtonfuncEMPTY;
-
1568RGFW_gamepadAxisfunc RGFW_gamepadAxisCallback = RGFW_gamepadAxisfuncEMPTY;
-
1569RGFW_gamepadfunc RGFW_gamepadCallback = RGFW_gamepadfuncEMPTY;
-
1570
-
1571void RGFW_window_checkEvents(RGFW_window* win, i32 waitMS) {
-
1572 RGFW_window_eventWait(win, waitMS);
-
1573
-
1574 while (RGFW_window_checkEvent(win) != NULL && RGFW_window_shouldClose(win) == 0) {
-
1575 if (win->event.type == RGFW_quit) return;
-
1576 }
-
1577
-
1578 #ifdef RGFW_WEBASM /* webasm needs to run the sleep function for asyncify */
-
1579 RGFW_sleep(0);
-
1580 #endif
-
1581}
-
1582
- -
1584 RGFW_windowmovefunc prev = (RGFW_windowMoveCallback == RGFW_windowmovefuncEMPTY) ? NULL : RGFW_windowMoveCallback;
-
1585 RGFW_windowMoveCallback = func;
-
1586 return prev;
-
1587}
- -
1589 RGFW_windowresizefunc prev = (RGFW_windowResizeCallback == RGFW_windowresizefuncEMPTY) ? NULL : RGFW_windowResizeCallback;
-
1590 RGFW_windowResizeCallback = func;
-
1591 return prev;
-
1592}
- -
1594 RGFW_windowquitfunc prev = (RGFW_windowQuitCallback == RGFW_windowquitfuncEMPTY) ? NULL : RGFW_windowQuitCallback;
-
1595 RGFW_windowQuitCallback = func;
-
1596 return prev;
-
1597}
-
1598
- -
1600 RGFW_mouseposfunc prev = (RGFW_mousePosCallback == RGFW_mouseposfuncEMPTY) ? NULL : RGFW_mousePosCallback;
-
1601 RGFW_mousePosCallback = func;
-
1602 return prev;
-
1603}
- -
1605 RGFW_windowrefreshfunc prev = (RGFW_windowRefreshCallback == RGFW_windowrefreshfuncEMPTY) ? NULL : RGFW_windowRefreshCallback;
-
1606 RGFW_windowRefreshCallback = func;
-
1607 return prev;
-
1608}
- -
1610 RGFW_focusfunc prev = (RGFW_focusCallback == RGFW_focusfuncEMPTY) ? NULL : RGFW_focusCallback;
-
1611 RGFW_focusCallback = func;
-
1612 return prev;
-
1613}
-
1614
- -
1616 RGFW_mouseNotifyfunc prev = (RGFW_mouseNotifyCallBack == RGFW_mouseNotifyfuncEMPTY) ? NULL : RGFW_mouseNotifyCallBack;
-
1617 RGFW_mouseNotifyCallBack = func;
-
1618 return prev;
-
1619}
- -
1621 RGFW_dndfunc prev = (RGFW_dndCallback == RGFW_dndfuncEMPTY) ? NULL : RGFW_dndCallback;
-
1622 RGFW_dndCallback = func;
-
1623 return prev;
-
1624}
- -
1626 RGFW_dndInitfunc prev = (RGFW_dndInitCallback == RGFW_dndInitfuncEMPTY) ? NULL : RGFW_dndInitCallback;
-
1627 RGFW_dndInitCallback = func;
-
1628 return prev;
-
1629}
- -
1631 RGFW_keyfunc prev = (RGFW_keyCallback == RGFW_keyfuncEMPTY) ? NULL : RGFW_keyCallback;
-
1632 RGFW_keyCallback = func;
-
1633 return prev;
-
1634}
- -
1636 RGFW_mousebuttonfunc prev = (RGFW_mouseButtonCallback == RGFW_mousebuttonfuncEMPTY) ? NULL : RGFW_mouseButtonCallback;
-
1637 RGFW_mouseButtonCallback = func;
-
1638 return prev;
-
1639}
- -
1641 RGFW_gamepadButtonfunc prev = (RGFW_gamepadButtonCallback == RGFW_gamepadButtonfuncEMPTY) ? NULL : RGFW_gamepadButtonCallback;
-
1642 RGFW_gamepadButtonCallback = func;
-
1643 return prev;
-
1644}
- -
1646 RGFW_gamepadAxisfunc prev = (RGFW_gamepadAxisCallback == RGFW_gamepadAxisfuncEMPTY) ? NULL : RGFW_gamepadAxisCallback;
-
1647 RGFW_gamepadAxisCallback = func;
-
1648 return prev;
-
1649}
- -
1651 RGFW_gamepadfunc prev = (RGFW_gamepadCallback == RGFW_gamepadfuncEMPTY) ? NULL : RGFW_gamepadCallback;
-
1652 RGFW_gamepadCallback = func;
-
1653 return prev;
-
1654}
-
1655/*
-
1656no more event call back defines
-
1657*/
-
1658
-
1659#define SET_ATTRIB(a, v) { \
-
1660 RGFW_ASSERT(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
-
1661 attribs[index++] = a; \
-
1662 attribs[index++] = v; \
-
1663}
-
1664
-
1665#define RGFW_NO_GPU_RENDER RGFW_BIT(20) /* don't render (using the GPU based API)*/
-
1666#define RGFW_NO_CPU_RENDER RGFW_BIT(21) /* don't render (using the CPU based buffer rendering)*/
-
1667#define RGFW_HOLD_MOUSE RGFW_BIT(22)
-
1668#define RGFW_MOUSE_LEFT RGFW_BIT(23) /* if mouse left the window */
-
1669#define RGFW_WINDOW_ALLOC RGFW_BIT(24) /* if window was allocated by RGFW */
-
1670#define RGFW_BUFFER_ALLOC RGFW_BIT(25) /* if window.buffer was allocated by RGFW */
-
1671
-
1672RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowFlags flags) {
- -
1674 win->_flags = 0;
-
1675 win->_flags |= RGFW_WINDOW_ALLOC;
-
1676 return RGFW_createWindowPtr(name, rect, flags, win);
-
1677}
-
1678
-
1679#if defined(RGFW_USE_XDL) && defined(RGFW_X11)
-
1680 #define XDL_IMPLEMENTATION
-
1681 #include "XDL.h"
-
1682#endif
-
1683
-
1684RGFWDEF void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags flags);
-
1685
-
1686#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
1687RGFW_mouse* RGFW_hiddenMouse = NULL;
-
1688#endif
-
1689
-
1690RGFW_window* RGFW_root = NULL;
-
1691
-
1692/* do a basic initialization for RGFW_window, this is to standard it for each OS */
-
1693void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags flags) {
-
1694 /* X11 requires us to have a display to get the screen size */
-
1695 #ifndef RGFW_X11
-
1696 RGFW_area screenR = RGFW_getScreenSize();
-
1697 #else
-
1698 win->src.display = XOpenDisplay(NULL);
-
1699 RGFW_ASSERT(win->src.display != NULL);
-
1700
-
1701 Screen* scrn = DefaultScreenOfDisplay(win->src.display);
-
1702 RGFW_area screenR = RGFW_AREA((u32)scrn->width, (u32)scrn->height);
-
1703 #endif
-
1704
-
1705 /* rect based the requested flags */
-
1706 if (flags & RGFW_windowFullscreen)
-
1707 rect = RGFW_RECT(0, 0, screenR.w, screenR.h);
-
1708
-
1709 if (RGFW_root == NULL) {
-
1710 RGFW_root = win;
-
1711 }
-
1712
-
1713 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
1714 if (RGFW_hiddenMouse == NULL) {
-
1715 u8 RGFW_blk[] = { 0, 0, 0, 0 };
-
1716 RGFW_hiddenMouse = RGFW_loadMouse(RGFW_blk, RGFW_AREA(1, 1), 4);
-
1717 }
-
1718 #endif
-
1719
-
1720 /* set and init the new window's data */
-
1721 win->r = rect;
-
1722 win->event.inFocus = 1;
-
1723 win->event.droppedFilesCount = 0;
-
1724 win->_flags = 0;
-
1725 win->event.keyMod = 0;
-
1726}
-
1727
- - -
1730}
-
1731
- -
1733 if (!(win->_flags & RGFW_BUFFER_ALLOC)) win->_flags |= RGFW_BUFFER_ALLOC;
-
1734 return RGFW_window_initBufferPtr(win, RGFW_ALLOC(area.w * area.h * 4), area);
-
1735}
-
1736
-
1737#ifdef RGFW_MACOS
-
1738RGFWDEF void RGFW_window_cocoaSetLayer(RGFW_window* win, void* layer);
-
1739RGFWDEF void* RGFW_cocoaGetLayer(void);
-
1740#endif
+
1536
+
1537/*
+
1538 These exist to avoid the
+
1539 if (func == NULL) check
+
1540 for (allegedly) better performance
+
1541*/
+
1542void RGFW_windowmovefuncEMPTY(RGFW_window* win, RGFW_rect r) { RGFW_UNUSED(win); RGFW_UNUSED(r); }
+
1543void RGFW_windowresizefuncEMPTY(RGFW_window* win, RGFW_rect r) { RGFW_UNUSED(win); RGFW_UNUSED(r); }
+
1544void RGFW_windowquitfuncEMPTY(RGFW_window* win) { RGFW_UNUSED(win); }
+
1545void RGFW_focusfuncEMPTY(RGFW_window* win, b8 inFocus) {RGFW_UNUSED(win); RGFW_UNUSED(inFocus);}
+
1546void RGFW_mouseNotifyfuncEMPTY(RGFW_window* win, RGFW_point point, b8 status) {RGFW_UNUSED(win); RGFW_UNUSED(point); RGFW_UNUSED(status);}
+
1547void RGFW_mouseposfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);}
+
1548void RGFW_dndInitfuncEMPTY(RGFW_window* win, RGFW_point point) {RGFW_UNUSED(win); RGFW_UNUSED(point);}
+
1549void RGFW_windowrefreshfuncEMPTY(RGFW_window* win) {RGFW_UNUSED(win); }
+
1550void RGFW_keyfuncEMPTY(RGFW_window* win, RGFW_key key, char keyChar, RGFW_keymod keyMod, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(key); RGFW_UNUSED(keyChar); RGFW_UNUSED(keyMod); RGFW_UNUSED(pressed);}
+
1551void RGFW_mousebuttonfuncEMPTY(RGFW_window* win, RGFW_mouseButton button, double scroll, b8 pressed) {RGFW_UNUSED(win); RGFW_UNUSED(button); RGFW_UNUSED(scroll); RGFW_UNUSED(pressed);}
+
1552void RGFW_gamepadButtonfuncEMPTY(RGFW_window* win, u16 gamepad, u8 button, b8 pressed){RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(button); RGFW_UNUSED(pressed); }
+
1553void 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); }
+
1554void RGFW_gamepadfuncEMPTY(RGFW_window* win, u16 gamepad, b8 connected) {RGFW_UNUSED(win); RGFW_UNUSED(gamepad); RGFW_UNUSED(connected);}
+
1555void RGFW_dndfuncEMPTY(RGFW_window* win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount) {RGFW_UNUSED(win); RGFW_UNUSED(droppedFiles); RGFW_UNUSED(droppedFilesCount);}
+
1556
+
1557RGFW_windowmovefunc RGFW_windowMoveCallback = RGFW_windowmovefuncEMPTY;
+
1558RGFW_windowresizefunc RGFW_windowResizeCallback = RGFW_windowresizefuncEMPTY;
+
1559RGFW_windowquitfunc RGFW_windowQuitCallback = RGFW_windowquitfuncEMPTY;
+
1560RGFW_mouseposfunc RGFW_mousePosCallback = RGFW_mouseposfuncEMPTY;
+
1561RGFW_windowrefreshfunc RGFW_windowRefreshCallback = RGFW_windowrefreshfuncEMPTY;
+
1562RGFW_focusfunc RGFW_focusCallback = RGFW_focusfuncEMPTY;
+
1563RGFW_mouseNotifyfunc RGFW_mouseNotifyCallBack = RGFW_mouseNotifyfuncEMPTY;
+
1564RGFW_dndfunc RGFW_dndCallback = RGFW_dndfuncEMPTY;
+
1565RGFW_dndInitfunc RGFW_dndInitCallback = RGFW_dndInitfuncEMPTY;
+
1566RGFW_keyfunc RGFW_keyCallback = RGFW_keyfuncEMPTY;
+
1567RGFW_mousebuttonfunc RGFW_mouseButtonCallback = RGFW_mousebuttonfuncEMPTY;
+
1568RGFW_gamepadButtonfunc RGFW_gamepadButtonCallback = RGFW_gamepadButtonfuncEMPTY;
+
1569RGFW_gamepadAxisfunc RGFW_gamepadAxisCallback = RGFW_gamepadAxisfuncEMPTY;
+
1570RGFW_gamepadfunc RGFW_gamepadCallback = RGFW_gamepadfuncEMPTY;
+
1571
+
1572void RGFW_window_checkEvents(RGFW_window* win, i32 waitMS) {
+
1573 RGFW_window_eventWait(win, waitMS);
+
1574
+
1575 while (RGFW_window_checkEvent(win) != NULL && RGFW_window_shouldClose(win) == 0) {
+
1576 if (win->event.type == RGFW_quit) return;
+
1577 }
+
1578
+
1579 #ifdef RGFW_WEBASM /* webasm needs to run the sleep function for asyncify */
+
1580 RGFW_sleep(0);
+
1581 #endif
+
1582}
+
1583
+ +
1585 RGFW_windowmovefunc prev = (RGFW_windowMoveCallback == RGFW_windowmovefuncEMPTY) ? NULL : RGFW_windowMoveCallback;
+
1586 RGFW_windowMoveCallback = func;
+
1587 return prev;
+
1588}
+ +
1590 RGFW_windowresizefunc prev = (RGFW_windowResizeCallback == RGFW_windowresizefuncEMPTY) ? NULL : RGFW_windowResizeCallback;
+
1591 RGFW_windowResizeCallback = func;
+
1592 return prev;
+
1593}
+ +
1595 RGFW_windowquitfunc prev = (RGFW_windowQuitCallback == RGFW_windowquitfuncEMPTY) ? NULL : RGFW_windowQuitCallback;
+
1596 RGFW_windowQuitCallback = func;
+
1597 return prev;
+
1598}
+
1599
+ +
1601 RGFW_mouseposfunc prev = (RGFW_mousePosCallback == RGFW_mouseposfuncEMPTY) ? NULL : RGFW_mousePosCallback;
+
1602 RGFW_mousePosCallback = func;
+
1603 return prev;
+
1604}
+ +
1606 RGFW_windowrefreshfunc prev = (RGFW_windowRefreshCallback == RGFW_windowrefreshfuncEMPTY) ? NULL : RGFW_windowRefreshCallback;
+
1607 RGFW_windowRefreshCallback = func;
+
1608 return prev;
+
1609}
+ +
1611 RGFW_focusfunc prev = (RGFW_focusCallback == RGFW_focusfuncEMPTY) ? NULL : RGFW_focusCallback;
+
1612 RGFW_focusCallback = func;
+
1613 return prev;
+
1614}
+
1615
+ +
1617 RGFW_mouseNotifyfunc prev = (RGFW_mouseNotifyCallBack == RGFW_mouseNotifyfuncEMPTY) ? NULL : RGFW_mouseNotifyCallBack;
+
1618 RGFW_mouseNotifyCallBack = func;
+
1619 return prev;
+
1620}
+ +
1622 RGFW_dndfunc prev = (RGFW_dndCallback == RGFW_dndfuncEMPTY) ? NULL : RGFW_dndCallback;
+
1623 RGFW_dndCallback = func;
+
1624 return prev;
+
1625}
+ +
1627 RGFW_dndInitfunc prev = (RGFW_dndInitCallback == RGFW_dndInitfuncEMPTY) ? NULL : RGFW_dndInitCallback;
+
1628 RGFW_dndInitCallback = func;
+
1629 return prev;
+
1630}
+ +
1632 RGFW_keyfunc prev = (RGFW_keyCallback == RGFW_keyfuncEMPTY) ? NULL : RGFW_keyCallback;
+
1633 RGFW_keyCallback = func;
+
1634 return prev;
+
1635}
+ +
1637 RGFW_mousebuttonfunc prev = (RGFW_mouseButtonCallback == RGFW_mousebuttonfuncEMPTY) ? NULL : RGFW_mouseButtonCallback;
+
1638 RGFW_mouseButtonCallback = func;
+
1639 return prev;
+
1640}
+ +
1642 RGFW_gamepadButtonfunc prev = (RGFW_gamepadButtonCallback == RGFW_gamepadButtonfuncEMPTY) ? NULL : RGFW_gamepadButtonCallback;
+
1643 RGFW_gamepadButtonCallback = func;
+
1644 return prev;
+
1645}
+ +
1647 RGFW_gamepadAxisfunc prev = (RGFW_gamepadAxisCallback == RGFW_gamepadAxisfuncEMPTY) ? NULL : RGFW_gamepadAxisCallback;
+
1648 RGFW_gamepadAxisCallback = func;
+
1649 return prev;
+
1650}
+ +
1652 RGFW_gamepadfunc prev = (RGFW_gamepadCallback == RGFW_gamepadfuncEMPTY) ? NULL : RGFW_gamepadCallback;
+
1653 RGFW_gamepadCallback = func;
+
1654 return prev;
+
1655}
+
1656/*
+
1657no more event call back defines
+
1658*/
+
1659
+
1660#define SET_ATTRIB(a, v) { \
+
1661 RGFW_ASSERT(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
+
1662 attribs[index++] = a; \
+
1663 attribs[index++] = v; \
+
1664}
+
1665
+
1666#define RGFW_NO_GPU_RENDER RGFW_BIT(20) /* don't render (using the GPU based API)*/
+
1667#define RGFW_NO_CPU_RENDER RGFW_BIT(21) /* don't render (using the CPU based buffer rendering)*/
+
1668#define RGFW_HOLD_MOUSE RGFW_BIT(22)
+
1669#define RGFW_MOUSE_LEFT RGFW_BIT(23) /* if mouse left the window */
+
1670#define RGFW_WINDOW_ALLOC RGFW_BIT(24) /* if window was allocated by RGFW */
+
1671#define RGFW_BUFFER_ALLOC RGFW_BIT(25) /* if window.buffer was allocated by RGFW */
+
1672
+
1673RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowFlags flags) {
+ +
1675 win->_flags = 0;
+
1676 win->_flags |= RGFW_WINDOW_ALLOC;
+
1677 return RGFW_createWindowPtr(name, rect, flags, win);
+
1678}
+
1679
+
1680#if defined(RGFW_USE_XDL) && defined(RGFW_X11)
+
1681 #define XDL_IMPLEMENTATION
+
1682 #include "XDL.h"
+
1683#endif
+
1684
+
1685RGFWDEF void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags flags);
+
1686
+
1687#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
1688RGFW_mouse* RGFW_hiddenMouse = NULL;
+
1689#endif
+
1690
+
1691RGFW_window* RGFW_root = NULL;
+
1692
+
1693/* do a basic initialization for RGFW_window, this is to standard it for each OS */
+
1694void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags flags) {
+
1695 /* X11 requires us to have a display to get the screen size */
+
1696 #ifndef RGFW_X11
+
1697 RGFW_area screenR = RGFW_getScreenSize();
+
1698 #else
+
1699 win->src.display = XOpenDisplay(NULL);
+
1700 RGFW_ASSERT(win->src.display != NULL);
+
1701
+
1702 Screen* scrn = DefaultScreenOfDisplay(win->src.display);
+
1703 RGFW_area screenR = RGFW_AREA((u32)scrn->width, (u32)scrn->height);
+
1704 #endif
+
1705
+
1706 /* rect based the requested flags */
+
1707 if (flags & RGFW_windowFullscreen)
+
1708 rect = RGFW_RECT(0, 0, screenR.w, screenR.h);
+
1709
+
1710 if (RGFW_root == NULL) {
+
1711 RGFW_root = win;
+
1712 }
+
1713
+
1714 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
1715 if (RGFW_hiddenMouse == NULL) {
+
1716 u8 RGFW_blk[] = { 0, 0, 0, 0 };
+
1717 RGFW_hiddenMouse = RGFW_loadMouse(RGFW_blk, RGFW_AREA(1, 1), 4);
+
1718 }
+
1719 #endif
+
1720
+
1721 /* set and init the new window's data */
+
1722 win->r = rect;
+
1723 win->event.inFocus = 1;
+
1724 win->event.droppedFilesCount = 0;
+
1725 win->_flags = 0;
+
1726 win->event.keyMod = 0;
+
1727}
+
1728
+ + +
1731}
+
1732
+ +
1734 if (!(win->_flags & RGFW_BUFFER_ALLOC)) win->_flags |= RGFW_BUFFER_ALLOC;
+
1735 #ifndef RGFW_WINDOWS
+
1736 return RGFW_window_initBufferPtr(win, RGFW_ALLOC(area.w * area.h * 4), area);
+
1737 #else /* windows's bitmap allocs memory for us */
+
1738 return RGFW_window_initBufferPtr(win, NULL, area);
+
1739 #endif
+
1740}
1741
-
1742const char* RGFW_className = NULL;
-
1743void RGFW_setClassName(const char* name) {
-
1744 RGFW_className = name;
-
1745}
+
1742#ifdef RGFW_MACOS
+
1743RGFWDEF void RGFW_window_cocoaSetLayer(RGFW_window* win, void* layer);
+
1744RGFWDEF void* RGFW_cocoaGetLayer(void);
+
1745#endif
1746
-
1747RGFW_keyState RGFW_mouseButtons[5] = { {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} };
-
1748
-
1749b8 RGFW_isMousePressed(RGFW_window* win, RGFW_mouseButton button) {
-
1750 return RGFW_mouseButtons[button].current && (win == NULL || win->event.inFocus);
-
1751}
-
1752b8 RGFW_wasMousePressed(RGFW_window* win, RGFW_mouseButton button) {
-
1753 return RGFW_mouseButtons[button].prev && (win != NULL || win->event.inFocus);
-
1754}
-
1755b8 RGFW_isMouseHeld(RGFW_window* win, RGFW_mouseButton button) {
-
1756 return (RGFW_isMousePressed(win, button) && RGFW_wasMousePressed(win, button));
-
1757}
-
1758b8 RGFW_isMouseReleased(RGFW_window* win, RGFW_mouseButton button) {
-
1759 return (!RGFW_isMousePressed(win, button) && RGFW_wasMousePressed(win, button));
-
1760}
-
1761
- -
1763 return RGFW_keyboard[key].current && (win == NULL || win->event.inFocus);
-
1764}
-
1765
- -
1767 return RGFW_keyboard[key].prev && (win == NULL || win->event.inFocus);
-
1768}
-
1769
- -
1771 return (RGFW_isPressed(win, key) && RGFW_wasPressed(win, key));
-
1772}
-
1773
- -
1775 return (RGFW_wasPressed(win, key) && !RGFW_isPressed(win, key));
-
1776}
-
1777
- -
1779 return (!RGFW_isPressed(win, key) && RGFW_wasPressed(win, key));
-
1780}
-
1781
-
1782#if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX) /* defines for directX context*/
-
1783 RGFW_directXinfo RGFW_dxInfo;
-
1784 RGFW_directXinfo* RGFW_getDirectXInfo(void) { return &RGFW_dxInfo; }
-
1785#endif
+
1747const char* RGFW_className = NULL;
+
1748void RGFW_setClassName(const char* name) {
+
1749 RGFW_className = name;
+
1750}
+
1751
+
1752RGFW_keyState RGFW_mouseButtons[5] = { {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+
1753
+
1754b8 RGFW_isMousePressed(RGFW_window* win, RGFW_mouseButton button) {
+
1755 return RGFW_mouseButtons[button].current && (win == NULL || win->event.inFocus);
+
1756}
+
1757b8 RGFW_wasMousePressed(RGFW_window* win, RGFW_mouseButton button) {
+
1758 return RGFW_mouseButtons[button].prev && (win != NULL || win->event.inFocus);
+
1759}
+
1760b8 RGFW_isMouseHeld(RGFW_window* win, RGFW_mouseButton button) {
+
1761 return (RGFW_isMousePressed(win, button) && RGFW_wasMousePressed(win, button));
+
1762}
+
1763b8 RGFW_isMouseReleased(RGFW_window* win, RGFW_mouseButton button) {
+
1764 return (!RGFW_isMousePressed(win, button) && RGFW_wasMousePressed(win, button));
+
1765}
+
1766
+ +
1768 return RGFW_keyboard[key].current && (win == NULL || win->event.inFocus);
+
1769}
+
1770
+ +
1772 return RGFW_keyboard[key].prev && (win == NULL || win->event.inFocus);
+
1773}
+
1774
+ +
1776 return (RGFW_isPressed(win, key) && RGFW_wasPressed(win, key));
+
1777}
+
1778
+ +
1780 return (RGFW_wasPressed(win, key) && !RGFW_isPressed(win, key));
+
1781}
+
1782
+ +
1784 return (!RGFW_isPressed(win, key) && RGFW_wasPressed(win, key));
+
1785}
1786
-
1787#ifndef RGFW_CUSTOM_BACKEND
- -
1789#if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX)
-
1790 if (win == NULL)
-
1791 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, NULL, NULL);
-
1792 else
-
1793 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, &win->src.renderTargetView, NULL);
-
1794#elif defined(RGFW_OPENGL)
- -
1796#else
-
1797 RGFW_UNUSED(win);
-
1798#endif
-
1799}
-
1800#endif
-
1801
-
1802void RGFW_window_setGPURender(RGFW_window* win, i8 set) {
-
1803 if (!set && !(win->_flags & RGFW_NO_GPU_RENDER))
-
1804 win->_flags |= RGFW_NO_GPU_RENDER;
-
1805
-
1806 else if (set && win->_flags & RGFW_NO_GPU_RENDER)
-
1807 win->_flags ^= RGFW_NO_GPU_RENDER;
-
1808}
-
1809
-
1810void RGFW_window_setCPURender(RGFW_window* win, i8 set) {
-
1811 if (!set && !(win->_flags & RGFW_NO_CPU_RENDER))
-
1812 win->_flags |= RGFW_NO_CPU_RENDER;
-
1813
-
1814 else if (set && win->_flags & RGFW_NO_CPU_RENDER)
-
1815 win->_flags ^= RGFW_NO_CPU_RENDER;
-
1816}
-
1817
- -
1819 RGFW_ASSERT(win != NULL);
-
1820
-
1821 RGFW_area screen = RGFW_getScreenSize();
+
1787#if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX) /* defines for directX context*/
+
1788 RGFW_directXinfo RGFW_dxInfo;
+
1789 RGFW_directXinfo* RGFW_getDirectXInfo(void) { return &RGFW_dxInfo; }
+
1790#endif
+
1791
+
1792#ifndef RGFW_CUSTOM_BACKEND
+ +
1794#if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX)
+
1795 if (win == NULL)
+
1796 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, NULL, NULL);
+
1797 else
+
1798 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, &win->src.renderTargetView, NULL);
+
1799#elif defined(RGFW_OPENGL)
+ +
1801#else
+
1802 RGFW_UNUSED(win);
+
1803#endif
+
1804}
+
1805#endif
+
1806
+
1807void RGFW_window_setGPURender(RGFW_window* win, i8 set) {
+
1808 if (!set && !(win->_flags & RGFW_NO_GPU_RENDER))
+
1809 win->_flags |= RGFW_NO_GPU_RENDER;
+
1810
+
1811 else if (set && win->_flags & RGFW_NO_GPU_RENDER)
+
1812 win->_flags ^= RGFW_NO_GPU_RENDER;
+
1813}
+
1814
+
1815void RGFW_window_setCPURender(RGFW_window* win, i8 set) {
+
1816 if (!set && !(win->_flags & RGFW_NO_CPU_RENDER))
+
1817 win->_flags |= RGFW_NO_CPU_RENDER;
+
1818
+
1819 else if (set && win->_flags & RGFW_NO_CPU_RENDER)
+
1820 win->_flags ^= RGFW_NO_CPU_RENDER;
+
1821}
1822
-
1823 RGFW_window_move(win, RGFW_POINT(0, 0));
-
1824 RGFW_window_resize(win, screen);
-
1825}
-
1826
- -
1828 RGFW_ASSERT(win != NULL);
-
1829 return (win->event.type == RGFW_quit || RGFW_isPressed(win, RGFW_escape));
+ +
1824 RGFW_ASSERT(win != NULL);
+
1825
+
1826 RGFW_area screen = RGFW_getScreenSize();
+
1827
+
1828 RGFW_window_move(win, RGFW_POINT(0, 0));
+
1829 RGFW_window_resize(win, screen);
1830}
1831
-
1832void RGFW_window_setShouldClose(RGFW_window* win) { win->event.type = RGFW_quit; RGFW_windowQuitCallback(win); }
-
1833
-
1834#ifndef RGFW_NO_MONITOR
- -
1836 RGFW_monitor monitor = RGFW_window_getMonitor(win);
-
1837
-
1838 RGFW_window_resize(win, RGFW_AREA((u32)(monitor.scaleX * (float)win->r.w), (u32)(monitor.scaleY * (float)win->r.h)));
-
1839}
-
1840
- -
1842 RGFW_window_move(win, RGFW_POINT(m.rect.x + win->r.x, m.rect.y + win->r.y));
-
1843}
-
1844#endif
+ +
1833 RGFW_ASSERT(win != NULL);
+
1834 return (win->event.type == RGFW_quit || RGFW_isPressed(win, RGFW_escape));
+
1835}
+
1836
+
1837void RGFW_window_setShouldClose(RGFW_window* win) { win->event.type = RGFW_quit; RGFW_windowQuitCallback(win); }
+
1838
+
1839#ifndef RGFW_NO_MONITOR
+ +
1841 RGFW_monitor monitor = RGFW_window_getMonitor(win);
+
1842
+
1843 RGFW_window_resize(win, RGFW_AREA((u32)(monitor.scaleX * (float)win->r.w), (u32)(monitor.scaleY * (float)win->r.h)));
+
1844}
1845
-
1846RGFWDEF void RGFW_captureCursor(RGFW_window* win, RGFW_rect);
-
1847RGFWDEF void RGFW_releaseCursor(RGFW_window* win);
-
1848
- -
1850 if ((win->_flags & RGFW_HOLD_MOUSE))
-
1851 return;
-
1852
+ +
1847 RGFW_window_move(win, RGFW_POINT(m.rect.x + win->r.x, m.rect.y + win->r.y));
+
1848}
+
1849#endif
+
1850
+
1851RGFWDEF void RGFW_captureCursor(RGFW_window* win, RGFW_rect);
+
1852RGFWDEF void RGFW_releaseCursor(RGFW_window* win);
1853
-
1854 if (!area.w && !area.h)
-
1855 area = RGFW_AREA(win->r.w / 2, win->r.h / 2);
-
1856
-
1857 win->_flags |= RGFW_HOLD_MOUSE;
-
1858 RGFW_captureCursor(win, win->r);
-
1859 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2)));
-
1860}
+ +
1855 if ((win->_flags & RGFW_HOLD_MOUSE))
+
1856 return;
+
1857
+
1858
+
1859 if (!area.w && !area.h)
+
1860 area = RGFW_AREA(win->r.w / 2, win->r.h / 2);
1861
- -
1863 if ((win->_flags & RGFW_HOLD_MOUSE)) {
-
1864 win->_flags ^= RGFW_HOLD_MOUSE;
-
1865
-
1866 RGFW_releaseCursor(win);
-
1867 }
-
1868}
-
1869
- -
1871 u64 deltaTime = RGFW_getTimeNS() - win->event.frameTime;
-
1872
-
1873 u32 output_fps = 0;
-
1874 u64 fps = RGFW_ROUND(1e+9 / deltaTime);
-
1875 output_fps= fps;
-
1876
-
1877 if (fpsCap && fps > fpsCap) {
-
1878 u64 frameTimeNS = 1e+9 / fpsCap;
-
1879 u64 sleepTimeMS = (frameTimeNS - deltaTime) / 1e6;
-
1880
-
1881 if (sleepTimeMS > 0) {
-
1882 RGFW_sleep(sleepTimeMS);
-
1883 win->event.frameTime = 0;
-
1884 }
-
1885 }
-
1886
- -
1888
-
1889 if (fpsCap == 0)
-
1890 return (u32) output_fps;
+
1862 win->_flags |= RGFW_HOLD_MOUSE;
+
1863 RGFW_captureCursor(win, win->r);
+
1864 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2)));
+
1865}
+
1866
+ +
1868 if ((win->_flags & RGFW_HOLD_MOUSE)) {
+
1869 win->_flags ^= RGFW_HOLD_MOUSE;
+
1870
+
1871 RGFW_releaseCursor(win);
+
1872 }
+
1873}
+
1874
+ +
1876 u64 deltaTime = RGFW_getTimeNS() - win->event.frameTime;
+
1877
+
1878 u32 output_fps = 0;
+
1879 u64 fps = RGFW_ROUND(1e+9 / deltaTime);
+
1880 output_fps= fps;
+
1881
+
1882 if (fpsCap && fps > fpsCap) {
+
1883 u64 frameTimeNS = 1e+9 / fpsCap;
+
1884 u64 sleepTimeMS = (frameTimeNS - deltaTime) / 1e6;
+
1885
+
1886 if (sleepTimeMS > 0) {
+
1887 RGFW_sleep(sleepTimeMS);
+
1888 win->event.frameTime = 0;
+
1889 }
+
1890 }
1891
-
1892 deltaTime = RGFW_getTimeNS() - win->event.frameTime2;
-
1893 output_fps = RGFW_ROUND(1e+9 / deltaTime);
- -
1895
-
1896 return output_fps;
-
1897}
-
1898
-
1899u32 RGFW_isPressedGamepad(RGFW_window* win, u8 c, RGFW_gamepadCodes button) {
-
1900 RGFW_UNUSED(win);
-
1901 return RGFW_gamepadPressed[c][button].current;
+ +
1893
+
1894 if (fpsCap == 0)
+
1895 return (u32) output_fps;
+
1896
+
1897 deltaTime = RGFW_getTimeNS() - win->event.frameTime2;
+
1898 output_fps = RGFW_ROUND(1e+9 / deltaTime);
+ +
1900
+
1901 return output_fps;
1902}
-
1903u32 RGFW_wasPressedGamepad(RGFW_window* win, u8 c, RGFW_gamepadCodes button) {
-
1904 RGFW_UNUSED(win);
-
1905 return RGFW_gamepadPressed[c][button].prev;
-
1906}
-
1907u32 RGFW_isReleasedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button) {
-
1908 RGFW_UNUSED(win);
-
1909 return !RGFW_isPressedGamepad(win, controller, button) && RGFW_wasPressedGamepad(win, controller, button);
-
1910}
-
1911u32 RGFW_isHeldGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button) {
-
1912 RGFW_UNUSED(win);
-
1913 return RGFW_isPressedGamepad(win, controller, button) && RGFW_wasPressedGamepad(win, controller, button);
-
1914}
-
1915
-
1916RGFW_point RGFW_getGamepadAxis(RGFW_window* win, u16 controller, u16 whichAxis) {
+
1903
+
1904u32 RGFW_isPressedGamepad(RGFW_window* win, u8 c, RGFW_gamepadCodes button) {
+
1905 RGFW_UNUSED(win);
+
1906 return RGFW_gamepadPressed[c][button].current;
+
1907}
+
1908u32 RGFW_wasPressedGamepad(RGFW_window* win, u8 c, RGFW_gamepadCodes button) {
+
1909 RGFW_UNUSED(win);
+
1910 return RGFW_gamepadPressed[c][button].prev;
+
1911}
+
1912u32 RGFW_isReleasedGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button) {
+
1913 RGFW_UNUSED(win);
+
1914 return !RGFW_isPressedGamepad(win, controller, button) && RGFW_wasPressedGamepad(win, controller, button);
+
1915}
+
1916u32 RGFW_isHeldGamepad(RGFW_window* win, u8 controller, RGFW_gamepadCodes button) {
1917 RGFW_UNUSED(win);
-
1918 return RGFW_gamepadAxes[controller][whichAxis];
+
1918 return RGFW_isPressedGamepad(win, controller, button) && RGFW_wasPressedGamepad(win, controller, button);
1919}
-
1920const char* RGFW_getGamepadName(RGFW_window* win, u16 controller) {
-
1921 RGFW_UNUSED(win);
-
1922 return (const char*)RGFW_gamepads_name[controller];
-
1923}
-
1924
-
1925size_t RGFW_getGamepadCount(RGFW_window* win) {
+
1920
+
1921RGFW_point RGFW_getGamepadAxis(RGFW_window* win, u16 controller, u16 whichAxis) {
+
1922 RGFW_UNUSED(win);
+
1923 return RGFW_gamepadAxes[controller][whichAxis];
+
1924}
+
1925const char* RGFW_getGamepadName(RGFW_window* win, u16 controller) {
1926 RGFW_UNUSED(win);
-
1927 return RGFW_gamepadCount;
+
1927 return (const char*)RGFW_gamepads_name[controller];
1928}
1929
-
1930RGFW_gamepadType RGFW_getGamepadType(RGFW_window* win, u16 controller) {
+
1930size_t RGFW_getGamepadCount(RGFW_window* win) {
1931 RGFW_UNUSED(win);
-
1932 return RGFW_gamepads_type[controller];
+
1932 return RGFW_gamepadCount;
1933}
1934
-
1935#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
1936void RGFW_window_showMouse(RGFW_window* win, i8 show) {
-
1937 if (show == 0)
-
1938 RGFW_window_setMouse(win, RGFW_hiddenMouse);
-
1939 else
- -
1941}
-
1942#endif
-
1943
-
1944RGFWDEF void RGFW_updateKeyMod(RGFW_window* win, RGFW_keymod mod, b8 value);
-
1945void RGFW_updateKeyMod(RGFW_window* win, RGFW_keymod mod, b8 value) {
-
1946 if (value && !(win->event.keyMod & mod))
-
1947 win->event.keyMod |= mod;
-
1948 else if (!value && ((win->event.keyMod & mod)))
-
1949 win->event.keyMod ^= mod;
-
1950}
-
1951
-
1952RGFWDEF void RGFW_updateKeyModsPro(RGFW_window* win, b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super);
-
1953void RGFW_updateKeyModsPro(RGFW_window* win, b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super) {
-
1954 RGFW_updateKeyMod(win, RGFW_modCapsLock, capital);
-
1955 RGFW_updateKeyMod(win, RGFW_modNumLock, numlock);
-
1956 RGFW_updateKeyMod(win, RGFW_modControl, control);
-
1957 RGFW_updateKeyMod(win, RGFW_modAlt, alt);
-
1958 RGFW_updateKeyMod(win, RGFW_modShift, shift);
-
1959 RGFW_updateKeyMod(win, RGFW_modSuper, super);
-
1960}
-
1961
-
1962RGFWDEF void RGFW_updateKeyMods(RGFW_window* win, b8 capital, b8 numlock);
-
1963void RGFW_updateKeyMods(RGFW_window* win, b8 capital, b8 numlock) {
-
1964 RGFW_updateKeyModsPro(win, capital, numlock,
-
1965 RGFW_isPressed(win, RGFW_controlL) || RGFW_isPressed(win, RGFW_controlR),
-
1966 RGFW_isPressed(win, RGFW_altL) || RGFW_isPressed(win, RGFW_altR),
-
1967 RGFW_isPressed(win, RGFW_shiftL) || RGFW_isPressed(win, RGFW_shiftR),
-
1968 RGFW_isPressed(win, RGFW_superL) || RGFW_isPressed(win, RGFW_superR));
-
1969}
-
1970
-
1971#if defined(RGFW_X11) || defined(RGFW_MACOS) || defined(RGFW_WEBASM) || defined(RGFW_WAYLAND)
-
1972#include <time.h>
-
1973struct timespec;
-
1974
-
1975#ifndef RGFW_NO_UNIX_CLOCK
-
1976int nanosleep(const struct timespec* duration, struct timespec* rem);
-
1977int clock_gettime(clockid_t clk_id, struct timespec* tp);
-
1978#endif
+
1935RGFW_gamepadType RGFW_getGamepadType(RGFW_window* win, u16 controller) {
+
1936 RGFW_UNUSED(win);
+
1937 return RGFW_gamepads_type[controller];
+
1938}
+
1939
+
1940#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
1941void RGFW_window_showMouse(RGFW_window* win, i8 show) {
+
1942 if (show == 0)
+
1943 RGFW_window_setMouse(win, RGFW_hiddenMouse);
+
1944 else
+ +
1946}
+
1947#endif
+
1948
+
1949RGFWDEF void RGFW_updateKeyMod(RGFW_window* win, RGFW_keymod mod, b8 value);
+
1950void RGFW_updateKeyMod(RGFW_window* win, RGFW_keymod mod, b8 value) {
+
1951 if (value && !(win->event.keyMod & mod))
+
1952 win->event.keyMod |= mod;
+
1953 else if (!value && ((win->event.keyMod & mod)))
+
1954 win->event.keyMod ^= mod;
+
1955}
+
1956
+
1957RGFWDEF void RGFW_updateKeyModsPro(RGFW_window* win, b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super);
+
1958void RGFW_updateKeyModsPro(RGFW_window* win, b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super) {
+
1959 RGFW_updateKeyMod(win, RGFW_modCapsLock, capital);
+
1960 RGFW_updateKeyMod(win, RGFW_modNumLock, numlock);
+
1961 RGFW_updateKeyMod(win, RGFW_modControl, control);
+
1962 RGFW_updateKeyMod(win, RGFW_modAlt, alt);
+
1963 RGFW_updateKeyMod(win, RGFW_modShift, shift);
+
1964 RGFW_updateKeyMod(win, RGFW_modSuper, super);
+
1965}
+
1966
+
1967RGFWDEF void RGFW_updateKeyMods(RGFW_window* win, b8 capital, b8 numlock);
+
1968void RGFW_updateKeyMods(RGFW_window* win, b8 capital, b8 numlock) {
+
1969 RGFW_updateKeyModsPro(win, capital, numlock,
+
1970 RGFW_isPressed(win, RGFW_controlL) || RGFW_isPressed(win, RGFW_controlR),
+
1971 RGFW_isPressed(win, RGFW_altL) || RGFW_isPressed(win, RGFW_altR),
+
1972 RGFW_isPressed(win, RGFW_shiftL) || RGFW_isPressed(win, RGFW_shiftR),
+
1973 RGFW_isPressed(win, RGFW_superL) || RGFW_isPressed(win, RGFW_superR));
+
1974}
+
1975
+
1976#if defined(RGFW_X11) || defined(RGFW_MACOS) || defined(RGFW_WEBASM) || defined(RGFW_WAYLAND)
+
1977#include <time.h>
+
1978struct timespec;
1979
-
1980int setenv(const char *name, const char *value, int overwrite);
-
1981
-
1982void RGFW_window_setDND(RGFW_window* win, b8 allow) {
-
1983 if (allow && !(win->_flags & RGFW_windowAllowDND))
-
1984 win->_flags |= RGFW_windowAllowDND;
-
1985
-
1986 else if (!allow && (win->_flags & RGFW_windowAllowDND))
-
1987 win->_flags ^= RGFW_windowAllowDND;
-
1988}
-
1989#endif
+
1980#ifndef RGFW_NO_UNIX_CLOCK
+
1981int nanosleep(const struct timespec* duration, struct timespec* rem);
+
1982int clock_gettime(clockid_t clk_id, struct timespec* tp);
+
1983#endif
+
1984
+
1985int setenv(const char *name, const char *value, int overwrite);
+
1986
+
1987void RGFW_window_setDND(RGFW_window* win, b8 allow) {
+
1988 if (allow && !(win->_flags & RGFW_windowAllowDND))
+
1989 win->_flags |= RGFW_windowAllowDND;
1990
-
1991/*
-
1992 graphics API specific code (end of generic code)
-
1993 starts here
-
1994*/
+
1991 else if (!allow && (win->_flags & RGFW_windowAllowDND))
+
1992 win->_flags ^= RGFW_windowAllowDND;
+
1993}
+
1994#endif
1995
-
1996
-
1997/*
-
1998 OpenGL defines start here (Normal, EGL, OSMesa)
+
1996/*
+
1997 graphics API specific code (end of generic code)
+
1998 starts here
1999*/
2000
-
2001#if defined(RGFW_OPENGL) || defined(RGFW_EGL)
-
2002
-
2003#ifdef RGFW_WINDOWS
-
2004 #define WIN32_LEAN_AND_MEAN
-
2005 #define OEMRESOURCE
-
2006 #include <windows.h>
-
2007#endif
-
2008
-
2009#if !defined(__APPLE__) && !defined(RGFW_NO_GL_HEADER)
-
2010 #include <GL/gl.h>
-
2011#elif defined(__APPLE__)
-
2012 #ifndef GL_SILENCE_DEPRECATION
-
2013 #define GL_SILENCE_DEPRECATION
-
2014 #endif
-
2015 #include <OpenGL/gl.h>
-
2016 #include <OpenGL/OpenGL.h>
-
2017#endif
-
2018
-
2019/* EGL, normal OpenGL only */
-
2020i32 RGFW_majorVersion = 0, RGFW_minorVersion = 0;
-
2021b8 RGFW_profile = RGFW_glCore;
-
2022
-
2023#ifndef RGFW_EGL
-
2024i32 RGFW_STENCIL = 8, RGFW_SAMPLES = 4, RGFW_STEREO = 0, RGFW_AUX_BUFFERS = 0, RGFW_DOUBLE_BUFFER = 1;
-
2025#else
-
2026i32 RGFW_STENCIL = 0, RGFW_SAMPLES = 0, RGFW_STEREO = 0, RGFW_AUX_BUFFERS = 0, RGFW_DOUBLE_BUFFER = 1;
-
2027#endif
-
2028
-
2029void RGFW_setGLStencil(i32 stencil) { RGFW_STENCIL = stencil; }
-
2030void RGFW_setGLSamples(i32 samples) { RGFW_SAMPLES = samples; }
-
2031void RGFW_setGLStereo(i32 stereo) { RGFW_STEREO = stereo; }
-
2032void RGFW_setGLAuxBuffers(i32 auxBuffers) { RGFW_AUX_BUFFERS = auxBuffers; }
-
2033void RGFW_setDoubleBuffer(b8 useDoubleBuffer) { RGFW_DOUBLE_BUFFER = useDoubleBuffer; }
-
2034
-
2035void RGFW_setGLVersion(b8 profile, i32 major, i32 minor) {
-
2036 RGFW_profile = profile;
-
2037 RGFW_majorVersion = major;
-
2038 RGFW_minorVersion = minor;
-
2039}
-
2040
-
2041/* OPENGL normal only (no EGL / OSMesa) */
-
2042#if !defined(RGFW_EGL) && !defined(RGFW_CUSTOM_BACKEND)
-
2043
-
2044#define RGFW_GL_RENDER_TYPE RGFW_OS_BASED_VALUE(GLX_X_VISUAL_TYPE, 0x2003, 73, 0)
-
2045 #define RGFW_GL_ALPHA_SIZE RGFW_OS_BASED_VALUE(GLX_ALPHA_SIZE, 0x201b, 11, 0)
-
2046 #define RGFW_GL_DEPTH_SIZE RGFW_OS_BASED_VALUE(GLX_DEPTH_SIZE, 0x2022, 12, 0)
-
2047 #define RGFW_GL_DOUBLEBUFFER RGFW_OS_BASED_VALUE(GLX_DOUBLEBUFFER, 0x2011, 5, 0)
-
2048 #define RGFW_GL_STENCIL_SIZE RGFW_OS_BASED_VALUE(GLX_STENCIL_SIZE, 0x2023, 13, 0)
-
2049 #define RGFW_GL_SAMPLES RGFW_OS_BASED_VALUE(GLX_SAMPLES, 0x2042, 55, 0)
-
2050 #define RGFW_GL_STEREO RGFW_OS_BASED_VALUE(GLX_STEREO, 0x2012, 6, 0)
-
2051 #define RGFW_GL_AUX_BUFFERS RGFW_OS_BASED_VALUE(GLX_AUX_BUFFERS, 0x2024, 7, 0)
-
2052
-
2053#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
2054 #define RGFW_GL_DRAW RGFW_OS_BASED_VALUE(GLX_X_RENDERABLE, 0x2001, 0, 0)
-
2055 #define RGFW_GL_DRAW_TYPE RGFW_OS_BASED_VALUE(GLX_RENDER_TYPE, 0x2013, 0, 0)
-
2056 #define RGFW_GL_FULL_FORMAT RGFW_OS_BASED_VALUE(GLX_TRUE_COLOR, 0x2027, 0, 0)
-
2057 #define RGFW_GL_RED_SIZE RGFW_OS_BASED_VALUE(GLX_RED_SIZE, 0x2015, 0, 0)
-
2058 #define RGFW_GL_GREEN_SIZE RGFW_OS_BASED_VALUE(GLX_GREEN_SIZE, 0x2017, 0, 0)
-
2059 #define RGFW_GL_BLUE_SIZE RGFW_OS_BASED_VALUE(GLX_BLUE_SIZE, 0x2019, 0, 0)
-
2060 #define RGFW_GL_USE_RGBA RGFW_OS_BASED_VALUE(GLX_RGBA_BIT, 0x202B, 0, 0)
-
2061#endif
-
2062
-
2063#ifdef RGFW_WINDOWS
-
2064 #define WGL_SUPPORT_OPENGL_ARB 0x2010
-
2065 #define WGL_COLOR_BITS_ARB 0x2014
-
2066 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
-
2067 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
-
2068 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
-
2069 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
-
2070 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
-
2071 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
-
2072 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
-
2073 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9
-
2074 #define WGL_PIXEL_TYPE_ARB 0x2013
-
2075 #define WGL_TYPE_RGBA_ARB 0x202B
-
2076
-
2077 #define WGL_TRANSPARENT_ARB 0x200A
-
2078#endif
-
2079
-
2080/* The window'ing api needs to know how to render the data we (or opengl) give it
-
2081 MacOS and Windows do this using a structure called a "pixel format"
-
2082 X11 calls it a "Visual"
-
2083 This function returns the attributes for the format we want */
-
2084u32* RGFW_initFormatAttribs(u32 useSoftware) {
-
2085 RGFW_UNUSED(useSoftware);
-
2086 static u32 attribs[] = {
-
2087 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
2088 RGFW_GL_RENDER_TYPE,
-
2089 RGFW_GL_FULL_FORMAT,
-
2090 #endif
-
2091 RGFW_GL_ALPHA_SIZE , 8,
-
2092 RGFW_GL_DEPTH_SIZE , 24,
-
2093 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
-
2094 RGFW_GL_DRAW, 1,
-
2095 RGFW_GL_RED_SIZE , 8,
-
2096 RGFW_GL_GREEN_SIZE , 8,
-
2097 RGFW_GL_BLUE_SIZE , 8,
-
2098 RGFW_GL_DRAW_TYPE , RGFW_GL_USE_RGBA,
-
2099 #endif
-
2100
-
2101 #ifdef RGFW_X11
-
2102 GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
-
2103 #endif
-
2104
-
2105 #ifdef RGFW_MACOS
-
2106 72,
-
2107 8, 24,
+
2001
+
2002/*
+
2003 OpenGL defines start here (Normal, EGL, OSMesa)
+
2004*/
+
2005
+
2006#if defined(RGFW_OPENGL) || defined(RGFW_EGL)
+
2007
+
2008#ifdef RGFW_WINDOWS
+
2009 #define WIN32_LEAN_AND_MEAN
+
2010 #define OEMRESOURCE
+
2011 #include <windows.h>
+
2012#endif
+
2013
+
2014#if !defined(__APPLE__) && !defined(RGFW_NO_GL_HEADER)
+
2015 #include <GL/gl.h>
+
2016#elif defined(__APPLE__)
+
2017 #ifndef GL_SILENCE_DEPRECATION
+
2018 #define GL_SILENCE_DEPRECATION
+
2019 #endif
+
2020 #include <OpenGL/gl.h>
+
2021 #include <OpenGL/OpenGL.h>
+
2022#endif
+
2023
+
2024/* EGL, normal OpenGL only */
+
2025i32 RGFW_majorVersion = 0, RGFW_minorVersion = 0;
+
2026b8 RGFW_profile = RGFW_glCore;
+
2027
+
2028#ifndef RGFW_EGL
+
2029i32 RGFW_STENCIL = 8, RGFW_SAMPLES = 4, RGFW_STEREO = 0, RGFW_AUX_BUFFERS = 0, RGFW_DOUBLE_BUFFER = 1;
+
2030#else
+
2031i32 RGFW_STENCIL = 0, RGFW_SAMPLES = 0, RGFW_STEREO = 0, RGFW_AUX_BUFFERS = 0, RGFW_DOUBLE_BUFFER = 1;
+
2032#endif
+
2033
+
2034void RGFW_setGLStencil(i32 stencil) { RGFW_STENCIL = stencil; }
+
2035void RGFW_setGLSamples(i32 samples) { RGFW_SAMPLES = samples; }
+
2036void RGFW_setGLStereo(i32 stereo) { RGFW_STEREO = stereo; }
+
2037void RGFW_setGLAuxBuffers(i32 auxBuffers) { RGFW_AUX_BUFFERS = auxBuffers; }
+
2038void RGFW_setDoubleBuffer(b8 useDoubleBuffer) { RGFW_DOUBLE_BUFFER = useDoubleBuffer; }
+
2039
+
2040void RGFW_setGLVersion(b8 profile, i32 major, i32 minor) {
+
2041 RGFW_profile = profile;
+
2042 RGFW_majorVersion = major;
+
2043 RGFW_minorVersion = minor;
+
2044}
+
2045
+
2046/* OPENGL normal only (no EGL / OSMesa) */
+
2047#if !defined(RGFW_EGL) && !defined(RGFW_CUSTOM_BACKEND)
+
2048
+
2049#define RGFW_GL_RENDER_TYPE RGFW_OS_BASED_VALUE(GLX_X_VISUAL_TYPE, 0x2003, 73, 0)
+
2050 #define RGFW_GL_ALPHA_SIZE RGFW_OS_BASED_VALUE(GLX_ALPHA_SIZE, 0x201b, 11, 0)
+
2051 #define RGFW_GL_DEPTH_SIZE RGFW_OS_BASED_VALUE(GLX_DEPTH_SIZE, 0x2022, 12, 0)
+
2052 #define RGFW_GL_DOUBLEBUFFER RGFW_OS_BASED_VALUE(GLX_DOUBLEBUFFER, 0x2011, 5, 0)
+
2053 #define RGFW_GL_STENCIL_SIZE RGFW_OS_BASED_VALUE(GLX_STENCIL_SIZE, 0x2023, 13, 0)
+
2054 #define RGFW_GL_SAMPLES RGFW_OS_BASED_VALUE(GLX_SAMPLES, 0x2042, 55, 0)
+
2055 #define RGFW_GL_STEREO RGFW_OS_BASED_VALUE(GLX_STEREO, 0x2012, 6, 0)
+
2056 #define RGFW_GL_AUX_BUFFERS RGFW_OS_BASED_VALUE(GLX_AUX_BUFFERS, 0x2024, 7, 0)
+
2057
+
2058#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
2059 #define RGFW_GL_DRAW RGFW_OS_BASED_VALUE(GLX_X_RENDERABLE, 0x2001, 0, 0)
+
2060 #define RGFW_GL_DRAW_TYPE RGFW_OS_BASED_VALUE(GLX_RENDER_TYPE, 0x2013, 0, 0)
+
2061 #define RGFW_GL_FULL_FORMAT RGFW_OS_BASED_VALUE(GLX_TRUE_COLOR, 0x2027, 0, 0)
+
2062 #define RGFW_GL_RED_SIZE RGFW_OS_BASED_VALUE(GLX_RED_SIZE, 0x2015, 0, 0)
+
2063 #define RGFW_GL_GREEN_SIZE RGFW_OS_BASED_VALUE(GLX_GREEN_SIZE, 0x2017, 0, 0)
+
2064 #define RGFW_GL_BLUE_SIZE RGFW_OS_BASED_VALUE(GLX_BLUE_SIZE, 0x2019, 0, 0)
+
2065 #define RGFW_GL_USE_RGBA RGFW_OS_BASED_VALUE(GLX_RGBA_BIT, 0x202B, 0, 0)
+
2066#endif
+
2067
+
2068#ifdef RGFW_WINDOWS
+
2069 #define WGL_SUPPORT_OPENGL_ARB 0x2010
+
2070 #define WGL_COLOR_BITS_ARB 0x2014
+
2071 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
+
2072 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
+
2073 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
+
2074 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
+
2075 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
+
2076 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+
2077 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
+
2078 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9
+
2079 #define WGL_PIXEL_TYPE_ARB 0x2013
+
2080 #define WGL_TYPE_RGBA_ARB 0x202B
+
2081
+
2082 #define WGL_TRANSPARENT_ARB 0x200A
+
2083#endif
+
2084
+
2085/* The window'ing api needs to know how to render the data we (or opengl) give it
+
2086 MacOS and Windows do this using a structure called a "pixel format"
+
2087 X11 calls it a "Visual"
+
2088 This function returns the attributes for the format we want */
+
2089u32* RGFW_initFormatAttribs(u32 useSoftware) {
+
2090 RGFW_UNUSED(useSoftware);
+
2091 static u32 attribs[] = {
+
2092 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
2093 RGFW_GL_RENDER_TYPE,
+
2094 RGFW_GL_FULL_FORMAT,
+
2095 #endif
+
2096 RGFW_GL_ALPHA_SIZE , 8,
+
2097 RGFW_GL_DEPTH_SIZE , 24,
+
2098 #if defined(RGFW_X11) || defined(RGFW_WINDOWS)
+
2099 RGFW_GL_DRAW, 1,
+
2100 RGFW_GL_RED_SIZE , 8,
+
2101 RGFW_GL_GREEN_SIZE , 8,
+
2102 RGFW_GL_BLUE_SIZE , 8,
+
2103 RGFW_GL_DRAW_TYPE , RGFW_GL_USE_RGBA,
+
2104 #endif
+
2105
+
2106 #ifdef RGFW_X11
+
2107 GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
2108 #endif
2109
-
2110 #ifdef RGFW_WINDOWS
-
2111 WGL_SUPPORT_OPENGL_ARB, 1,
-
2112 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
-
2113 WGL_COLOR_BITS_ARB, 32,
-
2114 #endif
-
2115
-
2116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-
2117 };
-
2118
-
2119 size_t index = (sizeof(attribs) / sizeof(attribs[0])) - 13;
+
2110 #ifdef RGFW_MACOS
+
2111 72,
+
2112 8, 24,
+
2113 #endif
+
2114
+
2115 #ifdef RGFW_WINDOWS
+
2116 WGL_SUPPORT_OPENGL_ARB, 1,
+
2117 WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
+
2118 WGL_COLOR_BITS_ARB, 32,
+
2119 #endif
2120
-
2121 #define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
-
2122 if (attVal) { \
-
2123 attribs[index] = attrib;\
-
2124 attribs[index + 1] = attVal;\
-
2125 index += 2;\
-
2126 }
-
2127
-
2128 RGFW_GL_ADD_ATTRIB(RGFW_GL_DOUBLEBUFFER, 1);
-
2129
-
2130 RGFW_GL_ADD_ATTRIB(RGFW_GL_STENCIL_SIZE, RGFW_STENCIL);
-
2131 RGFW_GL_ADD_ATTRIB(RGFW_GL_STEREO, RGFW_STEREO);
-
2132 RGFW_GL_ADD_ATTRIB(RGFW_GL_AUX_BUFFERS, RGFW_AUX_BUFFERS);
-
2133
-
2134 #ifndef RGFW_X11
-
2135 RGFW_GL_ADD_ATTRIB(RGFW_GL_SAMPLES, RGFW_SAMPLES);
-
2136 #endif
-
2137
-
2138 #ifdef RGFW_MACOS
-
2139 if (useSoftware) {
-
2140 RGFW_GL_ADD_ATTRIB(70, kCGLRendererGenericFloatID);
-
2141 } else {
-
2142 attribs[index] = RGFW_GL_RENDER_TYPE;
-
2143 index += 1;
-
2144 }
-
2145 #endif
-
2146
-
2147 #ifdef RGFW_MACOS
-
2148 /* macOS has the surface attribs and the opengl attribs connected for some reason
-
2149 maybe this is to give macOS more control to limit openGL/the opengl version? */
-
2150
-
2151 attribs[index] = 99;
-
2152 attribs[index + 1] = 0x1000;
-
2153
-
2154 if (RGFW_majorVersion >= 4 || RGFW_majorVersion >= 3) {
-
2155 attribs[index + 1] = (u32) ((RGFW_majorVersion >= 4) ? 0x4100 : 0x3200);
-
2156 }
-
2157 #endif
+
2121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+
2122 };
+
2123
+
2124 size_t index = (sizeof(attribs) / sizeof(attribs[0])) - 13;
+
2125
+
2126 #define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
+
2127 if (attVal) { \
+
2128 attribs[index] = attrib;\
+
2129 attribs[index + 1] = attVal;\
+
2130 index += 2;\
+
2131 }
+
2132
+
2133 RGFW_GL_ADD_ATTRIB(RGFW_GL_DOUBLEBUFFER, 1);
+
2134
+
2135 RGFW_GL_ADD_ATTRIB(RGFW_GL_STENCIL_SIZE, RGFW_STENCIL);
+
2136 RGFW_GL_ADD_ATTRIB(RGFW_GL_STEREO, RGFW_STEREO);
+
2137 RGFW_GL_ADD_ATTRIB(RGFW_GL_AUX_BUFFERS, RGFW_AUX_BUFFERS);
+
2138
+
2139 #ifndef RGFW_X11
+
2140 RGFW_GL_ADD_ATTRIB(RGFW_GL_SAMPLES, RGFW_SAMPLES);
+
2141 #endif
+
2142
+
2143 #ifdef RGFW_MACOS
+
2144 if (useSoftware) {
+
2145 RGFW_GL_ADD_ATTRIB(70, kCGLRendererGenericFloatID);
+
2146 } else {
+
2147 attribs[index] = RGFW_GL_RENDER_TYPE;
+
2148 index += 1;
+
2149 }
+
2150 #endif
+
2151
+
2152 #ifdef RGFW_MACOS
+
2153 /* macOS has the surface attribs and the opengl attribs connected for some reason
+
2154 maybe this is to give macOS more control to limit openGL/the opengl version? */
+
2155
+
2156 attribs[index] = 99;
+
2157 attribs[index + 1] = 0x1000;
2158
-
2159 RGFW_GL_ADD_ATTRIB(0, 0);
-
2160
-
2161 return attribs;
-
2162}
+
2159 if (RGFW_majorVersion >= 4 || RGFW_majorVersion >= 3) {
+
2160 attribs[index + 1] = (u32) ((RGFW_majorVersion >= 4) ? 0x4100 : 0x3200);
+
2161 }
+
2162 #endif
2163
-
2164/* EGL only (no OSMesa nor normal OPENGL) */
-
2165#elif defined(RGFW_EGL)
-
2166
-
2167#include <EGL/egl.h>
+
2164 RGFW_GL_ADD_ATTRIB(0, 0);
+
2165
+
2166 return attribs;
+
2167}
2168
-
2169#if defined(RGFW_LINK_EGL)
-
2170 typedef EGLBoolean(EGLAPIENTRY* PFN_eglInitialize)(EGLDisplay, EGLint*, EGLint*);
+
2169/* EGL only (no OSMesa nor normal OPENGL) */
+
2170#elif defined(RGFW_EGL)
2171
-
2172 PFNEGLINITIALIZEPROC eglInitializeSource;
-
2173 PFNEGLGETCONFIGSPROC eglGetConfigsSource;
-
2174 PFNEGLCHOOSECONFIgamepadROC eglChooseConfigSource;
-
2175 PFNEGLCREATEWINDOWSURFACEPROC eglCreateWindowSurfaceSource;
-
2176 PFNEGLCREATECONTEXTPROC eglCreateContextSource;
-
2177 PFNEGLMAKECURRENTPROC eglMakeCurrentSource;
-
2178 PFNEGLGETDISPLAYPROC eglGetDisplaySource;
-
2179 PFNEGLSWAPBUFFERSPROC eglSwapBuffersSource;
-
2180 PFNEGLSWAPINTERVALPROC eglSwapIntervalSource;
-
2181 PFNEGLBINDAPIPROC eglBindAPISource;
-
2182 PFNEGLDESTROYCONTEXTPROC eglDestroyContextSource;
-
2183 PFNEGLTERMINATEPROC eglTerminateSource;
-
2184 PFNEGLDESTROYSURFACEPROC eglDestroySurfaceSource;
-
2185
-
2186 #define eglInitialize eglInitializeSource
-
2187 #define eglGetConfigs eglGetConfigsSource
-
2188 #define eglChooseConfig eglChooseConfigSource
-
2189 #define eglCreateWindowSurface eglCreateWindowSurfaceSource
-
2190 #define eglCreateContext eglCreateContextSource
-
2191 #define eglMakeCurrent eglMakeCurrentSource
-
2192 #define eglGetDisplay eglGetDisplaySource
-
2193 #define eglSwapBuffers eglSwapBuffersSource
-
2194 #define eglSwapInterval eglSwapIntervalSource
-
2195 #define eglBindAPI eglBindAPISource
-
2196 #define eglDestroyContext eglDestroyContextSource
-
2197 #define eglTerminate eglTerminateSource
-
2198 #define eglDestroySurface eglDestroySurfaceSource;
-
2199#endif
-
2200
-
2201
-
2202#define EGL_SURFACE_MAJOR_VERSION_KHR 0x3098
-
2203#define EGL_SURFACE_MINOR_VERSION_KHR 0x30fb
-
2204
-
2205#ifndef RGFW_GL_ADD_ATTRIB
-
2206#define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
-
2207 if (attVal) { \
-
2208 attribs[index] = attrib;\
-
2209 attribs[index + 1] = attVal;\
-
2210 index += 2;\
-
2211 }
-
2212#endif
-
2213
-
2214
-
2215void RGFW_createOpenGLContext(RGFW_window* win) {
-
2216#if defined(RGFW_LINK_EGL)
-
2217 eglInitializeSource = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize");
-
2218 eglGetConfigsSource = (PFNEGLGETCONFIGSPROC) eglGetProcAddress("eglGetConfigs");
-
2219 eglChooseConfigSource = (PFNEGLCHOOSECONFIgamepadROC) eglGetProcAddress("eglChooseConfig");
-
2220 eglCreateWindowSurfaceSource = (PFNEGLCREATEWINDOWSURFACEPROC) eglGetProcAddress("eglCreateWindowSurface");
-
2221 eglCreateContextSource = (PFNEGLCREATECONTEXTPROC) eglGetProcAddress("eglCreateContext");
-
2222 eglMakeCurrentSource = (PFNEGLMAKECURRENTPROC) eglGetProcAddress("eglMakeCurrent");
-
2223 eglGetDisplaySource = (PFNEGLGETDISPLAYPROC) eglGetProcAddress("eglGetDisplay");
-
2224 eglSwapBuffersSource = (PFNEGLSWAPBUFFERSPROC) eglGetProcAddress("eglSwapBuffers");
-
2225 eglSwapIntervalSource = (PFNEGLSWAPINTERVALPROC) eglGetProcAddress("eglSwapInterval");
-
2226 eglBindAPISource = (PFNEGLBINDAPIPROC) eglGetProcAddress("eglBindAPI");
-
2227 eglDestroyContextSource = (PFNEGLDESTROYCONTEXTPROC) eglGetProcAddress("eglDestroyContext");
-
2228 eglTerminateSource = (PFNEGLTERMINATEPROC) eglGetProcAddress("eglTerminate");
-
2229 eglDestroySurfaceSource = (PFNEGLDESTROYSURFACEPROC) eglGetProcAddress("eglDestroySurface");
-
2230#endif /* RGFW_LINK_EGL */
-
2231
-
2232 #ifdef RGFW_WINDOWS
-
2233 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.hdc);
-
2234 #elif defined(RGFW_MACOS)
-
2235 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType)0);
-
2236 #elif defined(RGFW_WAYLAND)
-
2237 if (RGFW_useWaylandBool)
-
2238 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.wl_display);
-
2239 else
-
2240 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.display);
-
2241 #else
-
2242 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.display);
-
2243 #endif
-
2244
-
2245 EGLint major, minor;
-
2246
-
2247 eglInitialize(win->src.EGL_display, &major, &minor);
-
2248
-
2249 #ifndef EGL_OPENGL_ES1_BIT
-
2250 #define EGL_OPENGL_ES1_BIT 0x1
-
2251 #endif
-
2252
-
2253 EGLint egl_config[] = {
-
2254 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
-
2255 EGL_RENDERABLE_TYPE,
-
2256 #ifdef RGFW_OPENGL_ES1
-
2257 EGL_OPENGL_ES1_BIT,
-
2258 #elif defined(RGFW_OPENGL_ES3)
-
2259 EGL_OPENGL_ES3_BIT,
-
2260 #elif defined(RGFW_OPENGL_ES2)
-
2261 EGL_OPENGL_ES2_BIT,
-
2262 #else
-
2263 EGL_OPENGL_BIT,
-
2264 #endif
-
2265 EGL_NONE, EGL_NONE
-
2266 };
-
2267
-
2268 EGLConfig config;
-
2269 EGLint numConfigs;
-
2270 eglChooseConfig(win->src.EGL_display, egl_config, &config, 1, &numConfigs);
-
2271
-
2272 #if defined(RGFW_MACOS)
-
2273 void* layer = RGFW_cocoaGetLayer();
-
2274
-
2275 RGFW_window_cocoaSetLayer(win, layer);
+
2172#include <EGL/egl.h>
+
2173
+
2174#if defined(RGFW_LINK_EGL)
+
2175 typedef EGLBoolean(EGLAPIENTRY* PFN_eglInitialize)(EGLDisplay, EGLint*, EGLint*);
+
2176
+
2177 PFNEGLINITIALIZEPROC eglInitializeSource;
+
2178 PFNEGLGETCONFIGSPROC eglGetConfigsSource;
+
2179 PFNEGLCHOOSECONFIgamepadROC eglChooseConfigSource;
+
2180 PFNEGLCREATEWINDOWSURFACEPROC eglCreateWindowSurfaceSource;
+
2181 PFNEGLCREATECONTEXTPROC eglCreateContextSource;
+
2182 PFNEGLMAKECURRENTPROC eglMakeCurrentSource;
+
2183 PFNEGLGETDISPLAYPROC eglGetDisplaySource;
+
2184 PFNEGLSWAPBUFFERSPROC eglSwapBuffersSource;
+
2185 PFNEGLSWAPINTERVALPROC eglSwapIntervalSource;
+
2186 PFNEGLBINDAPIPROC eglBindAPISource;
+
2187 PFNEGLDESTROYCONTEXTPROC eglDestroyContextSource;
+
2188 PFNEGLTERMINATEPROC eglTerminateSource;
+
2189 PFNEGLDESTROYSURFACEPROC eglDestroySurfaceSource;
+
2190
+
2191 #define eglInitialize eglInitializeSource
+
2192 #define eglGetConfigs eglGetConfigsSource
+
2193 #define eglChooseConfig eglChooseConfigSource
+
2194 #define eglCreateWindowSurface eglCreateWindowSurfaceSource
+
2195 #define eglCreateContext eglCreateContextSource
+
2196 #define eglMakeCurrent eglMakeCurrentSource
+
2197 #define eglGetDisplay eglGetDisplaySource
+
2198 #define eglSwapBuffers eglSwapBuffersSource
+
2199 #define eglSwapInterval eglSwapIntervalSource
+
2200 #define eglBindAPI eglBindAPISource
+
2201 #define eglDestroyContext eglDestroyContextSource
+
2202 #define eglTerminate eglTerminateSource
+
2203 #define eglDestroySurface eglDestroySurfaceSource;
+
2204#endif
+
2205
+
2206
+
2207#define EGL_SURFACE_MAJOR_VERSION_KHR 0x3098
+
2208#define EGL_SURFACE_MINOR_VERSION_KHR 0x30fb
+
2209
+
2210#ifndef RGFW_GL_ADD_ATTRIB
+
2211#define RGFW_GL_ADD_ATTRIB(attrib, attVal) \
+
2212 if (attVal) { \
+
2213 attribs[index] = attrib;\
+
2214 attribs[index + 1] = attVal;\
+
2215 index += 2;\
+
2216 }
+
2217#endif
+
2218
+
2219
+
2220void RGFW_createOpenGLContext(RGFW_window* win) {
+
2221#if defined(RGFW_LINK_EGL)
+
2222 eglInitializeSource = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize");
+
2223 eglGetConfigsSource = (PFNEGLGETCONFIGSPROC) eglGetProcAddress("eglGetConfigs");
+
2224 eglChooseConfigSource = (PFNEGLCHOOSECONFIgamepadROC) eglGetProcAddress("eglChooseConfig");
+
2225 eglCreateWindowSurfaceSource = (PFNEGLCREATEWINDOWSURFACEPROC) eglGetProcAddress("eglCreateWindowSurface");
+
2226 eglCreateContextSource = (PFNEGLCREATECONTEXTPROC) eglGetProcAddress("eglCreateContext");
+
2227 eglMakeCurrentSource = (PFNEGLMAKECURRENTPROC) eglGetProcAddress("eglMakeCurrent");
+
2228 eglGetDisplaySource = (PFNEGLGETDISPLAYPROC) eglGetProcAddress("eglGetDisplay");
+
2229 eglSwapBuffersSource = (PFNEGLSWAPBUFFERSPROC) eglGetProcAddress("eglSwapBuffers");
+
2230 eglSwapIntervalSource = (PFNEGLSWAPINTERVALPROC) eglGetProcAddress("eglSwapInterval");
+
2231 eglBindAPISource = (PFNEGLBINDAPIPROC) eglGetProcAddress("eglBindAPI");
+
2232 eglDestroyContextSource = (PFNEGLDESTROYCONTEXTPROC) eglGetProcAddress("eglDestroyContext");
+
2233 eglTerminateSource = (PFNEGLTERMINATEPROC) eglGetProcAddress("eglTerminate");
+
2234 eglDestroySurfaceSource = (PFNEGLDESTROYSURFACEPROC) eglGetProcAddress("eglDestroySurface");
+
2235#endif /* RGFW_LINK_EGL */
+
2236
+
2237 #ifdef RGFW_WINDOWS
+
2238 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.hdc);
+
2239 #elif defined(RGFW_MACOS)
+
2240 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType)0);
+
2241 #elif defined(RGFW_WAYLAND)
+
2242 if (RGFW_useWaylandBool)
+
2243 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.wl_display);
+
2244 else
+
2245 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.display);
+
2246 #else
+
2247 win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.display);
+
2248 #endif
+
2249
+
2250 EGLint major, minor;
+
2251
+
2252 eglInitialize(win->src.EGL_display, &major, &minor);
+
2253
+
2254 #ifndef EGL_OPENGL_ES1_BIT
+
2255 #define EGL_OPENGL_ES1_BIT 0x1
+
2256 #endif
+
2257
+
2258 EGLint egl_config[] = {
+
2259 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+
2260 EGL_RENDERABLE_TYPE,
+
2261 #ifdef RGFW_OPENGL_ES1
+
2262 EGL_OPENGL_ES1_BIT,
+
2263 #elif defined(RGFW_OPENGL_ES3)
+
2264 EGL_OPENGL_ES3_BIT,
+
2265 #elif defined(RGFW_OPENGL_ES2)
+
2266 EGL_OPENGL_ES2_BIT,
+
2267 #else
+
2268 EGL_OPENGL_BIT,
+
2269 #endif
+
2270 EGL_NONE, EGL_NONE
+
2271 };
+
2272
+
2273 EGLConfig config;
+
2274 EGLint numConfigs;
+
2275 eglChooseConfig(win->src.EGL_display, egl_config, &config, 1, &numConfigs);
2276
-
2277 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) layer, NULL);
-
2278 #elif defined(RGFW_WINDOWS)
-
2279 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.hwnd, NULL);
-
2280 #elif defined(RGFW_WAYLAND)
-
2281 if (RGFW_useWaylandBool)
-
2282 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.eglWindow, NULL);
-
2283 else
-
2284 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL);
-
2285 #else
-
2286 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL);
-
2287 #endif
-
2288
-
2289 EGLint attribs[] = {
-
2290 EGL_CONTEXT_CLIENT_VERSION,
-
2291 #ifdef RGFW_OPENGL_ES1
-
2292 1,
-
2293 #else
-
2294 2,
-
2295 #endif
-
2296 EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE
-
2297 };
-
2298
-
2299 size_t index = 4;
-
2300 RGFW_GL_ADD_ATTRIB(EGL_STENCIL_SIZE, RGFW_STENCIL);
-
2301 RGFW_GL_ADD_ATTRIB(EGL_SAMPLES, RGFW_SAMPLES);
-
2302
-
2303 if (RGFW_DOUBLE_BUFFER)
-
2304 RGFW_GL_ADD_ATTRIB(EGL_RENDER_BUFFER, EGL_BACK_BUFFER);
-
2305
-
2306 if (RGFW_majorVersion) {
-
2307 attribs[1] = RGFW_majorVersion;
-
2308
-
2309 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MAJOR_VERSION, RGFW_majorVersion);
-
2310 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MINOR_VERSION, RGFW_minorVersion);
-
2311
-
2312 if (RGFW_profile == RGFW_glCore) {
-
2313 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT);
-
2314 }
-
2315 else {
-
2316 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT);
-
2317 }
-
2318
-
2319 }
-
2320
-
2321 #if defined(RGFW_OPENGL_ES1) || defined(RGFW_OPENGL_ES2) || defined(RGFW_OPENGL_ES3)
-
2322 eglBindAPI(EGL_OPENGL_ES_API);
-
2323 #else
-
2324 eglBindAPI(EGL_OPENGL_API);
-
2325 #endif
-
2326
-
2327 win->src.EGL_context = eglCreateContext(win->src.EGL_display, config, EGL_NO_CONTEXT, attribs);
-
2328
-
2329 if (win->src.EGL_context == NULL) {
-
2330 #ifdef RGFW_DEBUG
-
2331 fprintf(stderr, "failed to create an EGL opengl context\n");
-
2332 #endif
-
2333 }
-
2334 eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context);
-
2335 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
-
2336}
-
2337
- +
2277 #if defined(RGFW_MACOS)
+
2278 void* layer = RGFW_cocoaGetLayer();
+
2279
+
2280 RGFW_window_cocoaSetLayer(win, layer);
+
2281
+
2282 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) layer, NULL);
+
2283 #elif defined(RGFW_WINDOWS)
+
2284 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.hwnd, NULL);
+
2285 #elif defined(RGFW_WAYLAND)
+
2286 if (RGFW_useWaylandBool)
+
2287 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.eglWindow, NULL);
+
2288 else
+
2289 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL);
+
2290 #else
+
2291 win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL);
+
2292 #endif
+
2293
+
2294 EGLint attribs[] = {
+
2295 EGL_CONTEXT_CLIENT_VERSION,
+
2296 #ifdef RGFW_OPENGL_ES1
+
2297 1,
+
2298 #else
+
2299 2,
+
2300 #endif
+
2301 EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE
+
2302 };
+
2303
+
2304 size_t index = 4;
+
2305 RGFW_GL_ADD_ATTRIB(EGL_STENCIL_SIZE, RGFW_STENCIL);
+
2306 RGFW_GL_ADD_ATTRIB(EGL_SAMPLES, RGFW_SAMPLES);
+
2307
+
2308 if (RGFW_DOUBLE_BUFFER)
+
2309 RGFW_GL_ADD_ATTRIB(EGL_RENDER_BUFFER, EGL_BACK_BUFFER);
+
2310
+
2311 if (RGFW_majorVersion) {
+
2312 attribs[1] = RGFW_majorVersion;
+
2313
+
2314 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MAJOR_VERSION, RGFW_majorVersion);
+
2315 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MINOR_VERSION, RGFW_minorVersion);
+
2316
+
2317 if (RGFW_profile == RGFW_glCore) {
+
2318 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT);
+
2319 }
+
2320 else {
+
2321 RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT);
+
2322 }
+
2323
+
2324 }
+
2325
+
2326 #if defined(RGFW_OPENGL_ES1) || defined(RGFW_OPENGL_ES2) || defined(RGFW_OPENGL_ES3)
+
2327 eglBindAPI(EGL_OPENGL_ES_API);
+
2328 #else
+
2329 eglBindAPI(EGL_OPENGL_API);
+
2330 #endif
+
2331
+
2332 win->src.EGL_context = eglCreateContext(win->src.EGL_display, config, EGL_NO_CONTEXT, attribs);
+
2333
+
2334 if (win->src.EGL_context == NULL) {
+
2335 #ifdef RGFW_DEBUG
+
2336 fprintf(stderr, "failed to create an EGL opengl context\n");
+
2337 #endif
+
2338 }
2339 eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context);
-
2340}
-
2341
-
2342#ifdef RGFW_APPLE
-
2343void* RGFWnsglFramework = NULL;
-
2344#elif defined(RGFW_WINDOWS)
-
2345static HMODULE RGFW_wgl_dll = NULL;
-
2346#endif
-
2347
-
2348void* RGFW_getProcAddress(const char* procname) {
-
2349 #if defined(RGFW_WINDOWS)
-
2350 void* proc = (void*) GetProcAddress(RGFW_wgl_dll, procname);
-
2351
-
2352 if (proc)
-
2353 return proc;
-
2354 #endif
-
2355
-
2356 return (void*) eglGetProcAddress(procname);
-
2357}
-
2358
-
2359void RGFW_closeEGL(RGFW_window* win) {
-
2360 eglDestroySurface(win->src.EGL_display, win->src.EGL_surface);
-
2361 eglDestroyContext(win->src.EGL_display, win->src.EGL_context);
-
2362
-
2363 eglTerminate(win->src.EGL_display);
-
2364}
-
2365
-
2366void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
-
2367 RGFW_ASSERT(win != NULL);
-
2368
-
2369 eglSwapInterval(win->src.EGL_display, swapInterval);
+
2340 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
+
2341}
+
2342
+ +
2344 eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context);
+
2345}
+
2346
+
2347#ifdef RGFW_APPLE
+
2348void* RGFWnsglFramework = NULL;
+
2349#elif defined(RGFW_WINDOWS)
+
2350static HMODULE RGFW_wgl_dll = NULL;
+
2351#endif
+
2352
+
2353void* RGFW_getProcAddress(const char* procname) {
+
2354 #if defined(RGFW_WINDOWS)
+
2355 void* proc = (void*) GetProcAddress(RGFW_wgl_dll, procname);
+
2356
+
2357 if (proc)
+
2358 return proc;
+
2359 #endif
+
2360
+
2361 return (void*) eglGetProcAddress(procname);
+
2362}
+
2363
+
2364void RGFW_closeEGL(RGFW_window* win) {
+
2365 eglDestroySurface(win->src.EGL_display, win->src.EGL_surface);
+
2366 eglDestroyContext(win->src.EGL_display, win->src.EGL_context);
+
2367
+
2368 eglTerminate(win->src.EGL_display);
+
2369}
2370
-
2371}
-
2372
-
2373#endif /* RGFW_EGL */
-
2374
-
2375/*
-
2376 end of RGFW_EGL defines
-
2377*/
-
2378#endif /* RGFW_GL (OpenGL, EGL, OSMesa )*/
+
2371void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
+
2372 RGFW_ASSERT(win != NULL);
+
2373
+
2374 eglSwapInterval(win->src.EGL_display, swapInterval);
+
2375
+
2376}
+
2377
+
2378#endif /* RGFW_EGL */
2379
2380/*
-
2381This is where OS specific stuff starts
+
2381 end of RGFW_EGL defines
2382*/
-
2383
+
2383#endif /* RGFW_GL (OpenGL, EGL, OSMesa )*/
2384
-
2385#if (defined(RGFW_WAYLAND) || defined(RGFW_X11)) && !defined(RGFW_NO_LINUX)
-
2386 int RGFW_eventWait_forceStop[] = {0, 0, 0}; /* for wait events */
-
2387
-
2388 #if defined(__linux__)
-
2389 #include <linux/joystick.h>
-
2390 #include <fcntl.h>
-
2391 #include <unistd.h>
-
2392 #include <errno.h>
-
2393
-
2394 u32 RGFW_linux_updateGamepad(RGFW_window* win) {
-
2395 /* check for new gamepads */
-
2396 static const char* str[] = {"/dev/input/js0", "/dev/input/js1", "/dev/input/js2", "/dev/input/js3", "/dev/input/js4", "/dev/input/js5"};
-
2397 static u8 RGFW_rawGamepads[6];
+
2385/*
+
2386This is where OS specific stuff starts
+
2387*/
+
2388
+
2389
+
2390#if (defined(RGFW_WAYLAND) || defined(RGFW_X11)) && !defined(RGFW_NO_LINUX)
+
2391 int RGFW_eventWait_forceStop[] = {0, 0, 0}; /* for wait events */
+
2392
+
2393 #if defined(__linux__)
+
2394 #include <linux/joystick.h>
+
2395 #include <fcntl.h>
+
2396 #include <unistd.h>
+
2397 #include <errno.h>
2398
-
2399 for (size_t i = 0; i < 6; i++) {
-
2400 size_t index = RGFW_gamepadCount;
-
2401 if (RGFW_rawGamepads[i]) {
-
2402 struct input_id device_info;
-
2403 if (ioctl(RGFW_rawGamepads[i], EVIOCGID, &device_info) == -1) {
-
2404 if (errno == ENODEV) {
-
2405 RGFW_rawGamepads[i] = 0;
-
2406 }
-
2407 }
-
2408 continue;
-
2409 }
-
2410
-
2411 i32 js = open(str[i], O_RDONLY);
-
2412
-
2413 if (js <= 0)
-
2414 break;
+
2399 u32 RGFW_linux_updateGamepad(RGFW_window* win) {
+
2400 /* check for new gamepads */
+
2401 static const char* str[] = {"/dev/input/js0", "/dev/input/js1", "/dev/input/js2", "/dev/input/js3", "/dev/input/js4", "/dev/input/js5"};
+
2402 static u8 RGFW_rawGamepads[6];
+
2403
+
2404 for (size_t i = 0; i < 6; i++) {
+
2405 size_t index = RGFW_gamepadCount;
+
2406 if (RGFW_rawGamepads[i]) {
+
2407 struct input_id device_info;
+
2408 if (ioctl(RGFW_rawGamepads[i], EVIOCGID, &device_info) == -1) {
+
2409 if (errno == ENODEV) {
+
2410 RGFW_rawGamepads[i] = 0;
+
2411 }
+
2412 }
+
2413 continue;
+
2414 }
2415
-
2416 if (RGFW_gamepadCount >= 4) {
-
2417 close(js);
-
2418 break;
-
2419 }
+
2416 i32 js = open(str[i], O_RDONLY);
+
2417
+
2418 if (js <= 0)
+
2419 break;
2420
-
2421 RGFW_rawGamepads[i] = 1;
-
2422
-
2423 int axes, buttons;
-
2424 if (ioctl(js, JSIOCGAXES, &axes) < 0 || ioctl(js, JSIOCGBUTTONS, &buttons) < 0) {
-
2425 close(js);
-
2426 continue;
-
2427 }
-
2428
-
2429 if (buttons <= 5 || buttons >= 30) {
+
2421 if (RGFW_gamepadCount >= 4) {
+
2422 close(js);
+
2423 break;
+
2424 }
+
2425
+
2426 RGFW_rawGamepads[i] = 1;
+
2427
+
2428 int axes, buttons;
+
2429 if (ioctl(js, JSIOCGAXES, &axes) < 0 || ioctl(js, JSIOCGBUTTONS, &buttons) < 0) {
2430 close(js);
2431 continue;
2432 }
2433
-
2434 RGFW_gamepadCount++;
-
2435
-
2436 RGFW_gamepads[index] = js;
-
2437
-
2438 ioctl(js, JSIOCGNAME(sizeof(RGFW_gamepads_name[index])), RGFW_gamepads_name[index]);
-
2439 RGFW_gamepads_name[index][sizeof(RGFW_gamepads_name[index]) - 1] = 0;
+
2434 if (buttons <= 5 || buttons >= 30) {
+
2435 close(js);
+
2436 continue;
+
2437 }
+
2438
+
2439 RGFW_gamepadCount++;
2440
-
2441 u8 j;
-
2442 for (j = 0; j < 16; j++)
-
2443 RGFW_gamepadPressed[index][j] = (RGFW_keyState){0, 0};
-
2444
-
2445 win->event.type = RGFW_gamepadConnected;
-
2446
-
2447 RGFW_gamepads_type[index] = RGFW_gamepadUnknown;
-
2448 if (strstr(RGFW_gamepads_name[index], "Microsoft") || strstr(RGFW_gamepads_name[index], "X-Box"))
-
2449 RGFW_gamepads_type[index] = RGFW_gamepadMicrosoft;
-
2450 else if (strstr(RGFW_gamepads_name[index], "PlayStation") || strstr(RGFW_gamepads_name[index], "PS3") || strstr(RGFW_gamepads_name[index], "PS4") || strstr(RGFW_gamepads_name[index], "PS5"))
-
2451 RGFW_gamepads_type[index] = RGFW_gamepadSony;
-
2452 else if (strstr(RGFW_gamepads_name[index], "Nintendo"))
-
2453 RGFW_gamepads_type[index] = RGFW_gamepadNintendo;
-
2454 else if (strstr(RGFW_gamepads_name[index], "Logitech"))
-
2455 RGFW_gamepads_type[index] = RGFW_gamepadLogitech;
-
2456
-
2457 win->event.gamepad = index;
-
2458 RGFW_gamepadCallback(win, index, 1);
-
2459 return 1;
-
2460 }
+
2441 RGFW_gamepads[index] = js;
+
2442
+
2443 ioctl(js, JSIOCGNAME(sizeof(RGFW_gamepads_name[index])), RGFW_gamepads_name[index]);
+
2444 RGFW_gamepads_name[index][sizeof(RGFW_gamepads_name[index]) - 1] = 0;
+
2445
+
2446 u8 j;
+
2447 for (j = 0; j < 16; j++)
+
2448 RGFW_gamepadPressed[index][j] = (RGFW_keyState){0, 0};
+
2449
+
2450 win->event.type = RGFW_gamepadConnected;
+
2451
+
2452 RGFW_gamepads_type[index] = RGFW_gamepadUnknown;
+
2453 if (strstr(RGFW_gamepads_name[index], "Microsoft") || strstr(RGFW_gamepads_name[index], "X-Box"))
+
2454 RGFW_gamepads_type[index] = RGFW_gamepadMicrosoft;
+
2455 else if (strstr(RGFW_gamepads_name[index], "PlayStation") || strstr(RGFW_gamepads_name[index], "PS3") || strstr(RGFW_gamepads_name[index], "PS4") || strstr(RGFW_gamepads_name[index], "PS5"))
+
2456 RGFW_gamepads_type[index] = RGFW_gamepadSony;
+
2457 else if (strstr(RGFW_gamepads_name[index], "Nintendo"))
+
2458 RGFW_gamepads_type[index] = RGFW_gamepadNintendo;
+
2459 else if (strstr(RGFW_gamepads_name[index], "Logitech"))
+
2460 RGFW_gamepads_type[index] = RGFW_gamepadLogitech;
2461
-
2462 /* check gamepad events */
-
2463 u8 i;
-
2464
-
2465 for (i = 0; i < RGFW_gamepadCount; i++) {
-
2466 struct js_event e;
-
2467 if (RGFW_gamepads[i] == 0)
-
2468 continue;
+
2462 win->event.gamepad = index;
+
2463 RGFW_gamepadCallback(win, index, 1);
+
2464 return 1;
+
2465 }
+
2466
+
2467 /* check gamepad events */
+
2468 u8 i;
2469
-
2470 i32 flags = fcntl(RGFW_gamepads[i], F_GETFL, 0);
-
2471 fcntl(RGFW_gamepads[i], F_SETFL, flags | O_NONBLOCK);
-
2472
-
2473 ssize_t bytes;
-
2474 while ((bytes = read(RGFW_gamepads[i], &e, sizeof(e))) > 0) {
-
2475 switch (e.type) {
-
2476 case JS_EVENT_BUTTON: {
-
2477 size_t typeIndex = 0;
-
2478 if (RGFW_gamepads_type[i] == RGFW_gamepadMicrosoft) typeIndex = 1;
-
2479 else if (RGFW_gamepads_type[i] == RGFW_gamepadLogitech) typeIndex = 2;
-
2480
-
2481 win->event.type = e.value ? RGFW_gamepadButtonPressed : RGFW_gamepadButtonReleased;
-
2482 u8 RGFW_linux2RGFW[3][RGFW_gamepadR3 + 8] = {{ /* ps */
-
2483 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadY, RGFW_gamepadX, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
-
2484 RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight,
-
2485 },{ /* xbox */
-
2486 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadSelect, RGFW_gamepadStart,
-
2487 RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, 255, 255, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight
-
2488 },{ /* Logitech */
-
2489 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
-
2490 RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight
-
2491 }
-
2492 };
-
2493
-
2494 win->event.button = RGFW_linux2RGFW[typeIndex][e.number];
-
2495 win->event.gamepad = i;
-
2496 if (win->event.button == 255) break;
-
2497
-
2498 RGFW_gamepadPressed[i][win->event.button].prev = RGFW_gamepadPressed[i][win->event.button].current;
-
2499 RGFW_gamepadPressed[i][win->event.button].current = e.value;
-
2500 RGFW_gamepadButtonCallback(win, i, win->event.button, e.value);
-
2501
-
2502 return 1;
-
2503 }
-
2504 case JS_EVENT_AXIS: {
-
2505 size_t axis = e.number / 2;
-
2506 if (axis == 2) axis = 1;
-
2507
-
2508 ioctl(RGFW_gamepads[i], JSIOCGAXES, &win->event.axisesCount);
-
2509 win->event.axisesCount = 2;
-
2510
-
2511 if (axis < 3) {
-
2512 if (e.number == 0 || e.number == 3)
-
2513 RGFW_gamepadAxes[i][axis].x = (e.value / 32767.0f) * 100;
-
2514 else if (e.number == 1 || e.number == 4) {
-
2515 RGFW_gamepadAxes[i][axis].y = (e.value / 32767.0f) * 100;
-
2516 }
-
2517 }
-
2518
-
2519 win->event.axis[axis] = RGFW_gamepadAxes[i][axis];
-
2520 win->event.type = RGFW_gamepadAxisMove;
-
2521 win->event.gamepad = i;
-
2522 win->event.whichAxis = axis;
-
2523 RGFW_gamepadAxisCallback(win, i, win->event.axis, win->event.axisesCount, win->event.whichAxis);
-
2524 return 1;
-
2525 }
-
2526 default: break;
-
2527 }
-
2528 }
-
2529 if (bytes == -1 && errno == ENODEV) {
-
2530 RGFW_gamepadCount--;
-
2531 close(RGFW_gamepads[i]);
-
2532 RGFW_gamepads[i] = 0;
-
2533
-
2534 win->event.type = RGFW_gamepadDisconnected;
-
2535 win->event.gamepad = i;
-
2536 RGFW_gamepadCallback(win, i, 0);
-
2537 return 1;
-
2538 }
-
2539 }
-
2540 return 0;
-
2541 }
-
2542
-
2543 #endif
-
2544#endif
-
2545
-
2546
+
2470 for (i = 0; i < RGFW_gamepadCount; i++) {
+
2471 struct js_event e;
+
2472 if (RGFW_gamepads[i] == 0)
+
2473 continue;
+
2474
+
2475 i32 flags = fcntl(RGFW_gamepads[i], F_GETFL, 0);
+
2476 fcntl(RGFW_gamepads[i], F_SETFL, flags | O_NONBLOCK);
+
2477
+
2478 ssize_t bytes;
+
2479 while ((bytes = read(RGFW_gamepads[i], &e, sizeof(e))) > 0) {
+
2480 switch (e.type) {
+
2481 case JS_EVENT_BUTTON: {
+
2482 size_t typeIndex = 0;
+
2483 if (RGFW_gamepads_type[i] == RGFW_gamepadMicrosoft) typeIndex = 1;
+
2484 else if (RGFW_gamepads_type[i] == RGFW_gamepadLogitech) typeIndex = 2;
+
2485
+
2486 win->event.type = e.value ? RGFW_gamepadButtonPressed : RGFW_gamepadButtonReleased;
+
2487 u8 RGFW_linux2RGFW[3][RGFW_gamepadR3 + 8] = {{ /* ps */
+
2488 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadY, RGFW_gamepadX, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
+
2489 RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight,
+
2490 },{ /* xbox */
+
2491 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadSelect, RGFW_gamepadStart,
+
2492 RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, 255, 255, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight
+
2493 },{ /* Logitech */
+
2494 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY, RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
+
2495 RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight
+
2496 }
+
2497 };
+
2498
+
2499 win->event.button = RGFW_linux2RGFW[typeIndex][e.number];
+
2500 win->event.gamepad = i;
+
2501 if (win->event.button == 255) break;
+
2502
+
2503 RGFW_gamepadPressed[i][win->event.button].prev = RGFW_gamepadPressed[i][win->event.button].current;
+
2504 RGFW_gamepadPressed[i][win->event.button].current = e.value;
+
2505 RGFW_gamepadButtonCallback(win, i, win->event.button, e.value);
+
2506
+
2507 return 1;
+
2508 }
+
2509 case JS_EVENT_AXIS: {
+
2510 size_t axis = e.number / 2;
+
2511 if (axis == 2) axis = 1;
+
2512
+
2513 ioctl(RGFW_gamepads[i], JSIOCGAXES, &win->event.axisesCount);
+
2514 win->event.axisesCount = 2;
+
2515
+
2516 if (axis < 3) {
+
2517 if (e.number == 0 || e.number == 3)
+
2518 RGFW_gamepadAxes[i][axis].x = (e.value / 32767.0f) * 100;
+
2519 else if (e.number == 1 || e.number == 4) {
+
2520 RGFW_gamepadAxes[i][axis].y = (e.value / 32767.0f) * 100;
+
2521 }
+
2522 }
+
2523
+
2524 win->event.axis[axis] = RGFW_gamepadAxes[i][axis];
+
2525 win->event.type = RGFW_gamepadAxisMove;
+
2526 win->event.gamepad = i;
+
2527 win->event.whichAxis = axis;
+
2528 RGFW_gamepadAxisCallback(win, i, win->event.axis, win->event.axisesCount, win->event.whichAxis);
+
2529 return 1;
+
2530 }
+
2531 default: break;
+
2532 }
+
2533 }
+
2534 if (bytes == -1 && errno == ENODEV) {
+
2535 RGFW_gamepadCount--;
+
2536 close(RGFW_gamepads[i]);
+
2537 RGFW_gamepads[i] = 0;
+
2538
+
2539 win->event.type = RGFW_gamepadDisconnected;
+
2540 win->event.gamepad = i;
+
2541 RGFW_gamepadCallback(win, i, 0);
+
2542 return 1;
+
2543 }
+
2544 }
+
2545 return 0;
+
2546 }
2547
-
2548/*
-
2549
-
2550 Start of Wayland defines
-
2551
-
2552
-
2553*/
-
2554
-
2555#ifdef RGFW_WAYLAND
-
2556/*
-
2557Wayland TODO:
-
2558- fix RGFW_keyPressed lock state
-
2559
-
2560 RGFW_windowMoved, the window was moved (by the user)
-
2561 RGFW_windowResized the window was resized (by the user), [on webASM this means the browser was resized]
-
2562 RGFW_windowRefresh The window content needs to be refreshed
-
2563
-
2564 RGFW_DND a file has been dropped into the window
-
2565 RGFW_DNDInit
-
2566
-
2567- window args:
-
2568 #define RGFW_windowNoResize the window cannot be resized by the user
-
2569 #define RGFW_windowAllowDND the window supports drag and drop
-
2570 #define RGFW_scaleToMonitor scale the window to the screen
+
2548 #endif
+
2549#endif
+
2550
+
2551
+
2552
+
2553/*
+
2554
+
2555 Start of Wayland defines
+
2556
+
2557
+
2558*/
+
2559
+
2560#ifdef RGFW_WAYLAND
+
2561/*
+
2562Wayland TODO:
+
2563- fix RGFW_keyPressed lock state
+
2564
+
2565 RGFW_windowMoved, the window was moved (by the user)
+
2566 RGFW_windowResized the window was resized (by the user), [on webASM this means the browser was resized]
+
2567 RGFW_windowRefresh The window content needs to be refreshed
+
2568
+
2569 RGFW_DND a file has been dropped into the window
+
2570 RGFW_DNDInit
2571
-
2572- other missing functions functions ("TODO wayland") (~30 functions)
-
2573- fix buffer rendering weird behavior
-
2574*/
-
2575#include <errno.h>
-
2576#include <unistd.h>
-
2577#include <sys/mman.h>
-
2578#include <xkbcommon/xkbcommon.h>
-
2579#include <xkbcommon/xkbcommon-keysyms.h>
-
2580#include <dirent.h>
-
2581#include <linux/kd.h>
-
2582#include <wayland-cursor.h>
-
2583
-
2584RGFW_window* RGFW_key_win = NULL;
-
2585
-
2586void RGFW_eventPipe_push(RGFW_window* win, RGFW_event event) {
-
2587 if (win == NULL) {
-
2588 win = RGFW_key_win;
-
2589
-
2590 if (win == NULL) return;
-
2591 }
-
2592
-
2593 if (win->src.eventLen >= (i32)(sizeof(win->src.events) / sizeof(win->src.events[0])))
-
2594 return;
-
2595
-
2596 win->src.events[win->src.eventLen] = event;
-
2597 win->src.eventLen += 1;
-
2598}
-
2599
-
2600RGFW_event RGFW_eventPipe_pop(RGFW_window* win) {
-
2601 RGFW_event ev;
-
2602 ev.type = 0;
-
2603
-
2604 if (win->src.eventLen > -1)
-
2605 win->src.eventLen -= 1;
-
2606
-
2607 if (win->src.eventLen >= 0)
-
2608 ev = win->src.events[win->src.eventLen];
-
2609
-
2610 return ev;
-
2611}
-
2612
-
2613/* wayland global garbage (wayland bad, X11 is fine (ish) (not really)) */
-
2614#include "xdg-shell.h"
-
2615#include "xdg-decoration-unstable-v1.h"
-
2616
-
2617static struct xkb_context *xkb_context;
-
2618static struct xkb_keymap *keymap = NULL;
-
2619static struct xkb_state *xkb_state = NULL;
-
2620enum zxdg_toplevel_decoration_v1_mode client_preferred_mode, RGFW_current_mode;
-
2621static struct zxdg_decoration_manager_v1 *decoration_manager = NULL;
-
2622
-
2623struct wl_cursor_theme* RGFW_wl_cursor_theme = NULL;
-
2624struct wl_surface* RGFW_cursor_surface = NULL;
-
2625struct wl_cursor_image* RGFW_cursor_image = NULL;
-
2626
-
2627static void xdg_wm_base_ping_handler(void *data,
-
2628 struct xdg_wm_base *wm_base, uint32_t serial)
-
2629{
-
2630 RGFW_UNUSED(data);
-
2631 xdg_wm_base_pong(wm_base, serial);
-
2632}
-
2633
-
2634static const struct xdg_wm_base_listener xdg_wm_base_listener = {
-
2635 .ping = xdg_wm_base_ping_handler,
-
2636};
-
2637
-
2638b8 RGFW_wl_configured = 0;
-
2639
-
2640static void xdg_surface_configure_handler(void *data,
-
2641 struct xdg_surface *xdg_surface, uint32_t serial)
-
2642{
-
2643 RGFW_UNUSED(data);
-
2644 xdg_surface_ack_configure(xdg_surface, serial);
-
2645 #ifdef RGFW_DEBUG
-
2646 printf("Surface configured\n");
-
2647 #endif
-
2648 RGFW_wl_configured = 1;
-
2649}
-
2650
-
2651static const struct xdg_surface_listener xdg_surface_listener = {
-
2652 .configure = xdg_surface_configure_handler,
-
2653};
-
2654
-
2655static void xdg_toplevel_configure_handler(void *data,
-
2656 struct xdg_toplevel *toplevel, int32_t width, int32_t height,
-
2657 struct wl_array *states)
-
2658{
-
2659 RGFW_UNUSED(data); RGFW_UNUSED(toplevel); RGFW_UNUSED(states);
-
2660 #ifdef RGFW_DEBUG
-
2661 fprintf(stderr, "XDG toplevel configure: %dx%d\n", width, height);
-
2662 #endif
-
2663}
-
2664
-
2665static void xdg_toplevel_close_handler(void *data,
-
2666 struct xdg_toplevel *toplevel)
-
2667{
-
2668 RGFW_UNUSED(data);
-
2669 RGFW_window* win = (RGFW_window*)xdg_toplevel_get_user_data(toplevel);
-
2670 if (win == NULL)
-
2671 win = RGFW_key_win;
-
2672
-
2673 RGFW_event ev;
-
2674 ev.type = RGFW_quit;
-
2675
-
2676 RGFW_eventPipe_push(win, ev);
+
2572- window args:
+
2573 #define RGFW_windowNoResize the window cannot be resized by the user
+
2574 #define RGFW_windowAllowDND the window supports drag and drop
+
2575 #define RGFW_scaleToMonitor scale the window to the screen
+
2576
+
2577- other missing functions functions ("TODO wayland") (~30 functions)
+
2578- fix buffer rendering weird behavior
+
2579*/
+
2580#include <errno.h>
+
2581#include <unistd.h>
+
2582#include <sys/mman.h>
+
2583#include <xkbcommon/xkbcommon.h>
+
2584#include <xkbcommon/xkbcommon-keysyms.h>
+
2585#include <dirent.h>
+
2586#include <linux/kd.h>
+
2587#include <wayland-cursor.h>
+
2588
+
2589RGFW_window* RGFW_key_win = NULL;
+
2590
+
2591void RGFW_eventPipe_push(RGFW_window* win, RGFW_event event) {
+
2592 if (win == NULL) {
+
2593 win = RGFW_key_win;
+
2594
+
2595 if (win == NULL) return;
+
2596 }
+
2597
+
2598 if (win->src.eventLen >= (i32)(sizeof(win->src.events) / sizeof(win->src.events[0])))
+
2599 return;
+
2600
+
2601 win->src.events[win->src.eventLen] = event;
+
2602 win->src.eventLen += 1;
+
2603}
+
2604
+
2605RGFW_event RGFW_eventPipe_pop(RGFW_window* win) {
+
2606 RGFW_event ev;
+
2607 ev.type = 0;
+
2608
+
2609 if (win->src.eventLen > -1)
+
2610 win->src.eventLen -= 1;
+
2611
+
2612 if (win->src.eventLen >= 0)
+
2613 ev = win->src.events[win->src.eventLen];
+
2614
+
2615 return ev;
+
2616}
+
2617
+
2618/* wayland global garbage (wayland bad, X11 is fine (ish) (not really)) */
+
2619#include "xdg-shell.h"
+
2620#include "xdg-decoration-unstable-v1.h"
+
2621
+
2622static struct xkb_context *xkb_context;
+
2623static struct xkb_keymap *keymap = NULL;
+
2624static struct xkb_state *xkb_state = NULL;
+
2625enum zxdg_toplevel_decoration_v1_mode client_preferred_mode, RGFW_current_mode;
+
2626static struct zxdg_decoration_manager_v1 *decoration_manager = NULL;
+
2627
+
2628struct wl_cursor_theme* RGFW_wl_cursor_theme = NULL;
+
2629struct wl_surface* RGFW_cursor_surface = NULL;
+
2630struct wl_cursor_image* RGFW_cursor_image = NULL;
+
2631
+
2632static void xdg_wm_base_ping_handler(void *data,
+
2633 struct xdg_wm_base *wm_base, uint32_t serial)
+
2634{
+
2635 RGFW_UNUSED(data);
+
2636 xdg_wm_base_pong(wm_base, serial);
+
2637}
+
2638
+
2639static const struct xdg_wm_base_listener xdg_wm_base_listener = {
+
2640 .ping = xdg_wm_base_ping_handler,
+
2641};
+
2642
+
2643b8 RGFW_wl_configured = 0;
+
2644
+
2645static void xdg_surface_configure_handler(void *data,
+
2646 struct xdg_surface *xdg_surface, uint32_t serial)
+
2647{
+
2648 RGFW_UNUSED(data);
+
2649 xdg_surface_ack_configure(xdg_surface, serial);
+
2650 #ifdef RGFW_DEBUG
+
2651 printf("Surface configured\n");
+
2652 #endif
+
2653 RGFW_wl_configured = 1;
+
2654}
+
2655
+
2656static const struct xdg_surface_listener xdg_surface_listener = {
+
2657 .configure = xdg_surface_configure_handler,
+
2658};
+
2659
+
2660static void xdg_toplevel_configure_handler(void *data,
+
2661 struct xdg_toplevel *toplevel, int32_t width, int32_t height,
+
2662 struct wl_array *states)
+
2663{
+
2664 RGFW_UNUSED(data); RGFW_UNUSED(toplevel); RGFW_UNUSED(states);
+
2665 #ifdef RGFW_DEBUG
+
2666 fprintf(stderr, "XDG toplevel configure: %dx%d\n", width, height);
+
2667 #endif
+
2668}
+
2669
+
2670static void xdg_toplevel_close_handler(void *data,
+
2671 struct xdg_toplevel *toplevel)
+
2672{
+
2673 RGFW_UNUSED(data);
+
2674 RGFW_window* win = (RGFW_window*)xdg_toplevel_get_user_data(toplevel);
+
2675 if (win == NULL)
+
2676 win = RGFW_key_win;
2677
-
2678 RGFW_windowQuitCallback(win);
-
2679}
+
2678 RGFW_event ev;
+
2679 ev.type = RGFW_quit;
2680
-
2681static void shm_format_handler(void *data,
-
2682 struct wl_shm *shm, uint32_t format)
-
2683{
-
2684 RGFW_UNUSED(data); RGFW_UNUSED(shm);
-
2685 #ifdef RGFW_DEBUG
-
2686 fprintf(stderr, "Format %d\n", format);
-
2687 #endif
-
2688}
-
2689
-
2690static const struct wl_shm_listener shm_listener = {
-
2691 .format = shm_format_handler,
-
2692};
-
2693
-
2694static const struct xdg_toplevel_listener xdg_toplevel_listener = {
-
2695 .configure = xdg_toplevel_configure_handler,
-
2696 .close = xdg_toplevel_close_handler,
+
2681 RGFW_eventPipe_push(win, ev);
+
2682
+
2683 RGFW_windowQuitCallback(win);
+
2684}
+
2685
+
2686static void shm_format_handler(void *data,
+
2687 struct wl_shm *shm, uint32_t format)
+
2688{
+
2689 RGFW_UNUSED(data); RGFW_UNUSED(shm);
+
2690 #ifdef RGFW_DEBUG
+
2691 fprintf(stderr, "Format %d\n", format);
+
2692 #endif
+
2693}
+
2694
+
2695static const struct wl_shm_listener shm_listener = {
+
2696 .format = shm_format_handler,
2697};
2698
-
2699RGFW_window* RGFW_mouse_win = NULL;
-
2700
-
2701static void pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
-
2702 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(serial); RGFW_UNUSED(surface_x); RGFW_UNUSED(surface_y);
-
2703 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
-
2704 RGFW_mouse_win = win;
+
2699static const struct xdg_toplevel_listener xdg_toplevel_listener = {
+
2700 .configure = xdg_toplevel_configure_handler,
+
2701 .close = xdg_toplevel_close_handler,
+
2702};
+
2703
+
2704RGFW_window* RGFW_mouse_win = NULL;
2705
-
2706 RGFW_event ev;
-
2707 ev.type = RGFW_mouseEnter;
-
2708 ev.point = win->event.point;
-
2709
-
2710 RGFW_eventPipe_push(win, ev);
-
2711
-
2712 RGFW_mouseNotifyCallBack(win, win->event.point, RGFW_TRUE);
-
2713}
-
2714static void pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) {
-
2715 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(serial); RGFW_UNUSED(surface);
-
2716 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
-
2717 if (RGFW_mouse_win == win)
-
2718 RGFW_mouse_win = NULL;
-
2719
-
2720 RGFW_event ev;
-
2721 ev.type = RGFW_mouseLeave;
-
2722 ev.point = win->event.point;
-
2723 RGFW_eventPipe_push(win, ev);
+
2706static void pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
+
2707 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(serial); RGFW_UNUSED(surface_x); RGFW_UNUSED(surface_y);
+
2708 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
+
2709 RGFW_mouse_win = win;
+
2710
+
2711 RGFW_event ev;
+
2712 ev.type = RGFW_mouseEnter;
+
2713 ev.point = win->event.point;
+
2714
+
2715 RGFW_eventPipe_push(win, ev);
+
2716
+
2717 RGFW_mouseNotifyCallBack(win, win->event.point, RGFW_TRUE);
+
2718}
+
2719static void pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) {
+
2720 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(serial); RGFW_UNUSED(surface);
+
2721 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
+
2722 if (RGFW_mouse_win == win)
+
2723 RGFW_mouse_win = NULL;
2724
-
2725 RGFW_mouseNotifyCallBack(win, win->event.point, RGFW_FALSE);
-
2726}
-
2727static void pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y) {
-
2728 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(x); RGFW_UNUSED(y);
+
2725 RGFW_event ev;
+
2726 ev.type = RGFW_mouseLeave;
+
2727 ev.point = win->event.point;
+
2728 RGFW_eventPipe_push(win, ev);
2729
-
2730 RGFW_ASSERT(RGFW_mouse_win != NULL);
-
2731
-
2732 RGFW_event ev;
-
2733 ev.type = RGFW_mousePosChanged;
-
2734 ev.point = RGFW_POINT(wl_fixed_to_double(x), wl_fixed_to_double(y));
-
2735 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2730 RGFW_mouseNotifyCallBack(win, win->event.point, RGFW_FALSE);
+
2731}
+
2732static void pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y) {
+
2733 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(x); RGFW_UNUSED(y);
+
2734
+
2735 RGFW_ASSERT(RGFW_mouse_win != NULL);
2736
-
2737 RGFW_mousePosCallback(RGFW_mouse_win, RGFW_POINT(wl_fixed_to_double(x), wl_fixed_to_double(y)));
-
2738}
-
2739static void pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
-
2740 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(serial);
-
2741 RGFW_ASSERT(RGFW_mouse_win != NULL);
-
2742
-
2743 u32 b = (button - 0x110) + 1;
-
2744
-
2745 /* flip right and middle button codes */
-
2746 if (b == 2) b = 3;
-
2747 else if (b == 3) b = 2;
-
2748
-
2749 RGFW_mouseButtons[b].prev = RGFW_mouseButtons[b].current;
-
2750 RGFW_mouseButtons[b].current = state;
-
2751
-
2752 RGFW_event ev;
-
2753 ev.type = RGFW_mouseButtonPressed + state;
-
2754 ev.button = b;
-
2755 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2737 RGFW_event ev;
+
2738 ev.type = RGFW_mousePosChanged;
+
2739 ev.point = RGFW_POINT(wl_fixed_to_double(x), wl_fixed_to_double(y));
+
2740 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2741
+
2742 RGFW_mousePosCallback(RGFW_mouse_win, RGFW_POINT(wl_fixed_to_double(x), wl_fixed_to_double(y)));
+
2743}
+
2744static void pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
+
2745 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(serial);
+
2746 RGFW_ASSERT(RGFW_mouse_win != NULL);
+
2747
+
2748 u32 b = (button - 0x110) + 1;
+
2749
+
2750 /* flip right and middle button codes */
+
2751 if (b == 2) b = 3;
+
2752 else if (b == 3) b = 2;
+
2753
+
2754 RGFW_mouseButtons[b].prev = RGFW_mouseButtons[b].current;
+
2755 RGFW_mouseButtons[b].current = state;
2756
-
2757 RGFW_mouseButtonCallback(RGFW_mouse_win, b, 0, state);
-
2758}
-
2759static void pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
-
2760 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(axis);
-
2761 RGFW_ASSERT(RGFW_mouse_win != NULL);
-
2762
-
2763 double scroll = wl_fixed_to_double(value);
-
2764
-
2765 RGFW_event ev;
-
2766 ev.type = RGFW_mouseButtonPressed;
-
2767 ev.button = RGFW_mouseScrollUp + (scroll < 0);
-
2768 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2757 RGFW_event ev;
+
2758 ev.type = RGFW_mouseButtonPressed + state;
+
2759 ev.button = b;
+
2760 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2761
+
2762 RGFW_mouseButtonCallback(RGFW_mouse_win, b, 0, state);
+
2763}
+
2764static void pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
+
2765 RGFW_UNUSED(data); RGFW_UNUSED(pointer); RGFW_UNUSED(time); RGFW_UNUSED(axis);
+
2766 RGFW_ASSERT(RGFW_mouse_win != NULL);
+
2767
+
2768 double scroll = wl_fixed_to_double(value);
2769
-
2770 RGFW_mouseButtonCallback(RGFW_mouse_win, RGFW_mouseScrollUp + (scroll < 0), scroll, 1);
-
2771}
-
2772
-
2773void RGFW_doNothing(void) { }
-
2774static struct wl_pointer_listener pointer_listener = (struct wl_pointer_listener){&pointer_enter, &pointer_leave, &pointer_motion, &pointer_button, &pointer_axis, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing};
-
2775
-
2776static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) {
-
2777 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(format);
-
2778
-
2779 char *keymap_string = mmap (NULL, size, PROT_READ, MAP_SHARED, fd, 0);
-
2780 xkb_keymap_unref (keymap);
-
2781 keymap = xkb_keymap_new_from_string (xkb_context, keymap_string, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
-
2782
-
2783 munmap (keymap_string, size);
-
2784 close (fd);
-
2785 xkb_state_unref (xkb_state);
-
2786 xkb_state = xkb_state_new (keymap);
-
2787}
-
2788static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
-
2789 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(keys);
-
2790
-
2791 RGFW_key_win = (RGFW_window*)wl_surface_get_user_data(surface);
-
2792
-
2793 RGFW_event ev;
-
2794 ev.type = RGFW_focusIn;
-
2795 ev.inFocus = RGFW_TRUE;
-
2796 RGFW_key_win->event.inFocus = RGFW_TRUE;
+
2770 RGFW_event ev;
+
2771 ev.type = RGFW_mouseButtonPressed;
+
2772 ev.button = RGFW_mouseScrollUp + (scroll < 0);
+
2773 RGFW_eventPipe_push(RGFW_mouse_win, ev);
+
2774
+
2775 RGFW_mouseButtonCallback(RGFW_mouse_win, RGFW_mouseScrollUp + (scroll < 0), scroll, 1);
+
2776}
+
2777
+
2778void RGFW_doNothing(void) { }
+
2779static struct wl_pointer_listener pointer_listener = (struct wl_pointer_listener){&pointer_enter, &pointer_leave, &pointer_motion, &pointer_button, &pointer_axis, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing, (void*)&RGFW_doNothing};
+
2780
+
2781static void keyboard_keymap (void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd, uint32_t size) {
+
2782 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(format);
+
2783
+
2784 char *keymap_string = mmap (NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+
2785 xkb_keymap_unref (keymap);
+
2786 keymap = xkb_keymap_new_from_string (xkb_context, keymap_string, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
+
2787
+
2788 munmap (keymap_string, size);
+
2789 close (fd);
+
2790 xkb_state_unref (xkb_state);
+
2791 xkb_state = xkb_state_new (keymap);
+
2792}
+
2793static void keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
+
2794 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(keys);
+
2795
+
2796 RGFW_key_win = (RGFW_window*)wl_surface_get_user_data(surface);
2797
-
2798 RGFW_eventPipe_push((RGFW_window*)RGFW_mouse_win, ev);
-
2799
-
2800 RGFW_focusCallback(RGFW_key_win, RGFW_TRUE);
-
2801}
-
2802static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
-
2803 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial);
+
2798 RGFW_event ev;
+
2799 ev.type = RGFW_focusIn;
+
2800 ev.inFocus = RGFW_TRUE;
+
2801 RGFW_key_win->event.inFocus = RGFW_TRUE;
+
2802
+
2803 RGFW_eventPipe_push((RGFW_window*)RGFW_mouse_win, ev);
2804
-
2805 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
-
2806 if (RGFW_key_win == win)
-
2807 RGFW_key_win = NULL;
-
2808
-
2809 RGFW_event ev;
-
2810 ev.type = RGFW_focusOut;
-
2811 ev.inFocus = RGFW_FALSE;
-
2812 win->event.inFocus = RGFW_FALSE;
-
2813 RGFW_eventPipe_push(win, ev);
-
2814
-
2815 RGFW_focusCallback(win, RGFW_FALSE);
-
2816}
-
2817static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
-
2818 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(time);
+
2805 RGFW_focusCallback(RGFW_key_win, RGFW_TRUE);
+
2806}
+
2807static void keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
+
2808 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial);
+
2809
+
2810 RGFW_window* win = (RGFW_window*)wl_surface_get_user_data(surface);
+
2811 if (RGFW_key_win == win)
+
2812 RGFW_key_win = NULL;
+
2813
+
2814 RGFW_event ev;
+
2815 ev.type = RGFW_focusOut;
+
2816 ev.inFocus = RGFW_FALSE;
+
2817 win->event.inFocus = RGFW_FALSE;
+
2818 RGFW_eventPipe_push(win, ev);
2819
-
2820 RGFW_ASSERT(RGFW_key_win != NULL);
-
2821
-
2822 xkb_keysym_t keysym = xkb_state_key_get_one_sym(xkb_state, key + 8);
-
2823
-
2824 u32 RGFW_key = RGFW_apiKeyToRGFW(key + 8);
-
2825 RGFW_keyboard[RGFW_key].prev = RGFW_keyboard[RGFW_key].current;
-
2826 RGFW_keyboard[RGFW_key].current = state;
-
2827 RGFW_event ev;
-
2828 ev.type = RGFW_keyPressed + state;
-
2829 ev.key = RGFW_key;
-
2830 ev.keyChar = (u8)keysym;
-
2831
-
2832 ev.repeat = RGFW_isHeld(RGFW_key_win, RGFW_key);
-
2833 RGFW_eventPipe_push(RGFW_key_win, ev);
-
2834
-
2835 RGFW_updateKeyMods(RGFW_key_win, xkb_keymap_mod_get_index(keymap, "Lock"), xkb_keymap_mod_get_index(keymap, "Mod2"));
+
2820 RGFW_focusCallback(win, RGFW_FALSE);
+
2821}
+
2822static void keyboard_key (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
+
2823 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(time);
+
2824
+
2825 RGFW_ASSERT(RGFW_key_win != NULL);
+
2826
+
2827 xkb_keysym_t keysym = xkb_state_key_get_one_sym(xkb_state, key + 8);
+
2828
+
2829 u32 RGFW_key = RGFW_apiKeyToRGFW(key + 8);
+
2830 RGFW_keyboard[RGFW_key].prev = RGFW_keyboard[RGFW_key].current;
+
2831 RGFW_keyboard[RGFW_key].current = state;
+
2832 RGFW_event ev;
+
2833 ev.type = RGFW_keyPressed + state;
+
2834 ev.key = RGFW_key;
+
2835 ev.keyChar = (u8)keysym;
2836
-
2837 RGFW_keyCallback(RGFW_key_win, RGFW_key, (u8)keysym, RGFW_key_win->event.keyMod, state);
-
2838}
-
2839static void keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
-
2840 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(time);
-
2841 xkb_state_update_mask (xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group);
-
2842}
-
2843static struct wl_keyboard_listener keyboard_listener = {&keyboard_keymap, &keyboard_enter, &keyboard_leave, &keyboard_key, &keyboard_modifiers, (void*)&RGFW_doNothing};
-
2844
-
2845static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) {
-
2846 RGFW_UNUSED(data);
-
2847
-
2848 if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
-
2849 struct wl_pointer *pointer = wl_seat_get_pointer (seat);
-
2850 wl_pointer_add_listener (pointer, &pointer_listener, NULL);
-
2851 }
-
2852 if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
-
2853 struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
-
2854 wl_keyboard_add_listener (keyboard, &keyboard_listener, NULL);
-
2855 }
-
2856}
-
2857static struct wl_seat_listener seat_listener = {&seat_capabilities, (void*)&RGFW_doNothing};
-
2858
-
2859static void wl_global_registry_handler(void *data,
-
2860 struct wl_registry *registry, uint32_t id, const char *interface,
-
2861 uint32_t version)
-
2862{
-
2863 RGFW_window* win = (RGFW_window*)data;
-
2864 RGFW_UNUSED(version);
-
2865 if (RGFW_STRNCMP(interface, "wl_compositor", 16) == 0) {
-
2866 win->src.compositor = wl_registry_bind(registry,
-
2867 id, &wl_compositor_interface, 4);
-
2868 } else if (RGFW_STRNCMP(interface, "xdg_wm_base", 12) == 0) {
-
2869 win->src.xdg_wm_base = wl_registry_bind(registry,
-
2870 id, &xdg_wm_base_interface, 1);
-
2871 } else if (RGFW_STRNCMP(interface, zxdg_decoration_manager_v1_interface.name, 255) == 0) {
-
2872 decoration_manager = wl_registry_bind(registry, id, &zxdg_decoration_manager_v1_interface, 1);
-
2873 } else if (RGFW_STRNCMP(interface, "wl_shm", 7) == 0) {
-
2874 win->src.shm = wl_registry_bind(registry,
-
2875 id, &wl_shm_interface, 1);
-
2876 wl_shm_add_listener(win->src.shm, &shm_listener, NULL);
-
2877 } else if (RGFW_STRNCMP(interface,"wl_seat", 8) == 0) {
-
2878 win->src.seat = wl_registry_bind(registry, id, &wl_seat_interface, 1);
-
2879 wl_seat_add_listener(win->src.seat, &seat_listener, NULL);
-
2880 }
-
2881
-
2882 else {
-
2883 #ifdef RGFW_DEBUG
-
2884 printf("did not register %s\n", interface);
-
2885 return;
-
2886 #endif
-
2887 }
-
2888
-
2889 #ifdef RGFW_DEBUG
-
2890 printf("registered %s\n", interface);
-
2891 #endif
-
2892}
+
2837 ev.repeat = RGFW_isHeld(RGFW_key_win, RGFW_key);
+
2838 RGFW_eventPipe_push(RGFW_key_win, ev);
+
2839
+
2840 RGFW_updateKeyMods(RGFW_key_win, xkb_keymap_mod_get_index(keymap, "Lock"), xkb_keymap_mod_get_index(keymap, "Mod2"));
+
2841
+
2842 RGFW_keyCallback(RGFW_key_win, RGFW_key, (u8)keysym, RGFW_key_win->event.keyMod, state);
+
2843}
+
2844static void keyboard_modifiers (void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
+
2845 RGFW_UNUSED(data); RGFW_UNUSED(keyboard); RGFW_UNUSED(serial); RGFW_UNUSED(time);
+
2846 xkb_state_update_mask (xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group);
+
2847}
+
2848static struct wl_keyboard_listener keyboard_listener = {&keyboard_keymap, &keyboard_enter, &keyboard_leave, &keyboard_key, &keyboard_modifiers, (void*)&RGFW_doNothing};
+
2849
+
2850static void seat_capabilities (void *data, struct wl_seat *seat, uint32_t capabilities) {
+
2851 RGFW_UNUSED(data);
+
2852
+
2853 if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
+
2854 struct wl_pointer *pointer = wl_seat_get_pointer (seat);
+
2855 wl_pointer_add_listener (pointer, &pointer_listener, NULL);
+
2856 }
+
2857 if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
+
2858 struct wl_keyboard *keyboard = wl_seat_get_keyboard (seat);
+
2859 wl_keyboard_add_listener (keyboard, &keyboard_listener, NULL);
+
2860 }
+
2861}
+
2862static struct wl_seat_listener seat_listener = {&seat_capabilities, (void*)&RGFW_doNothing};
+
2863
+
2864static void wl_global_registry_handler(void *data,
+
2865 struct wl_registry *registry, uint32_t id, const char *interface,
+
2866 uint32_t version)
+
2867{
+
2868 RGFW_window* win = (RGFW_window*)data;
+
2869 RGFW_UNUSED(version);
+
2870 if (RGFW_STRNCMP(interface, "wl_compositor", 16) == 0) {
+
2871 win->src.compositor = wl_registry_bind(registry,
+
2872 id, &wl_compositor_interface, 4);
+
2873 } else if (RGFW_STRNCMP(interface, "xdg_wm_base", 12) == 0) {
+
2874 win->src.xdg_wm_base = wl_registry_bind(registry,
+
2875 id, &xdg_wm_base_interface, 1);
+
2876 } else if (RGFW_STRNCMP(interface, zxdg_decoration_manager_v1_interface.name, 255) == 0) {
+
2877 decoration_manager = wl_registry_bind(registry, id, &zxdg_decoration_manager_v1_interface, 1);
+
2878 } else if (RGFW_STRNCMP(interface, "wl_shm", 7) == 0) {
+
2879 win->src.shm = wl_registry_bind(registry,
+
2880 id, &wl_shm_interface, 1);
+
2881 wl_shm_add_listener(win->src.shm, &shm_listener, NULL);
+
2882 } else if (RGFW_STRNCMP(interface,"wl_seat", 8) == 0) {
+
2883 win->src.seat = wl_registry_bind(registry, id, &wl_seat_interface, 1);
+
2884 wl_seat_add_listener(win->src.seat, &seat_listener, NULL);
+
2885 }
+
2886
+
2887 else {
+
2888 #ifdef RGFW_DEBUG
+
2889 printf("did not register %s\n", interface);
+
2890 return;
+
2891 #endif
+
2892 }
2893
-
2894static void wl_global_registry_remove(void *data, struct wl_registry *registry, uint32_t name) { RGFW_UNUSED(data); RGFW_UNUSED(registry); RGFW_UNUSED(name); }
-
2895static const struct wl_registry_listener registry_listener = {
-
2896 .global = wl_global_registry_handler,
-
2897 .global_remove = wl_global_registry_remove,
-
2898};
-
2899
-
2900static const char *get_mode_name(enum zxdg_toplevel_decoration_v1_mode mode) {
-
2901 switch (mode) {
-
2902 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
-
2903 return "client-side decorations";
-
2904 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE:
-
2905 return "server-side decorations";
-
2906 }
-
2907 abort();
-
2908}
-
2909
-
2910
-
2911static void decoration_handle_configure(void *data,
-
2912 struct zxdg_toplevel_decoration_v1 *decoration,
-
2913 enum zxdg_toplevel_decoration_v1_mode mode) {
-
2914 RGFW_UNUSED(data); RGFW_UNUSED(decoration);
-
2915 #ifdef RGFW_DEBUG
-
2916 printf("Using %s\n", get_mode_name(mode));
-
2917 #endif
-
2918 RGFW_current_mode = mode;
-
2919}
-
2920
-
2921static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
-
2922 .configure = decoration_handle_configure,
-
2923};
-
2924
-
2925static void randname(char *buf) {
-
2926 struct timespec ts;
-
2927 clock_gettime(CLOCK_REALTIME, &ts);
-
2928 long r = ts.tv_nsec;
-
2929 for (int i = 0; i < 6; ++i) {
-
2930 buf[i] = 'A'+(r&15)+(r&16)*2;
-
2931 r >>= 5;
-
2932 }
-
2933}
-
2934
-
2935size_t wl_stringlen(char* name) {
-
2936 size_t i = 0;
-
2937 for (i; name[i]; i++);
-
2938 return i;
-
2939}
-
2940
-
2941static int anonymous_shm_open(void) {
-
2942 char name[] = "/RGFW-wayland-XXXXXX";
-
2943 int retries = 100;
-
2944
-
2945 do {
-
2946 randname(name + wl_stringlen(name) - 6);
-
2947
-
2948 --retries;
-
2949 // shm_open guarantees that O_CLOEXEC is set
-
2950 int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
-
2951 if (fd >= 0) {
-
2952 shm_unlink(name);
-
2953 return fd;
-
2954 }
-
2955 } while (retries > 0 && errno == EEXIST);
-
2956
-
2957 return -1;
-
2958}
-
2959
-
2960int create_shm_file(off_t size) {
-
2961 int fd = anonymous_shm_open();
-
2962 if (fd < 0) {
-
2963 return fd;
-
2964 }
-
2965
-
2966 if (ftruncate(fd, size) < 0) {
-
2967 close(fd);
-
2968 return -1;
+
2894 #ifdef RGFW_DEBUG
+
2895 printf("registered %s\n", interface);
+
2896 #endif
+
2897}
+
2898
+
2899static void wl_global_registry_remove(void *data, struct wl_registry *registry, uint32_t name) { RGFW_UNUSED(data); RGFW_UNUSED(registry); RGFW_UNUSED(name); }
+
2900static const struct wl_registry_listener registry_listener = {
+
2901 .global = wl_global_registry_handler,
+
2902 .global_remove = wl_global_registry_remove,
+
2903};
+
2904
+
2905static const char *get_mode_name(enum zxdg_toplevel_decoration_v1_mode mode) {
+
2906 switch (mode) {
+
2907 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
+
2908 return "client-side decorations";
+
2909 case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE:
+
2910 return "server-side decorations";
+
2911 }
+
2912 abort();
+
2913}
+
2914
+
2915
+
2916static void decoration_handle_configure(void *data,
+
2917 struct zxdg_toplevel_decoration_v1 *decoration,
+
2918 enum zxdg_toplevel_decoration_v1_mode mode) {
+
2919 RGFW_UNUSED(data); RGFW_UNUSED(decoration);
+
2920 #ifdef RGFW_DEBUG
+
2921 printf("Using %s\n", get_mode_name(mode));
+
2922 #endif
+
2923 RGFW_current_mode = mode;
+
2924}
+
2925
+
2926static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = {
+
2927 .configure = decoration_handle_configure,
+
2928};
+
2929
+
2930static void randname(char *buf) {
+
2931 struct timespec ts;
+
2932 clock_gettime(CLOCK_REALTIME, &ts);
+
2933 long r = ts.tv_nsec;
+
2934 for (int i = 0; i < 6; ++i) {
+
2935 buf[i] = 'A'+(r&15)+(r&16)*2;
+
2936 r >>= 5;
+
2937 }
+
2938}
+
2939
+
2940size_t wl_stringlen(char* name) {
+
2941 size_t i = 0;
+
2942 for (i; name[i]; i++);
+
2943 return i;
+
2944}
+
2945
+
2946static int anonymous_shm_open(void) {
+
2947 char name[] = "/RGFW-wayland-XXXXXX";
+
2948 int retries = 100;
+
2949
+
2950 do {
+
2951 randname(name + wl_stringlen(name) - 6);
+
2952
+
2953 --retries;
+
2954 // shm_open guarantees that O_CLOEXEC is set
+
2955 int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
+
2956 if (fd >= 0) {
+
2957 shm_unlink(name);
+
2958 return fd;
+
2959 }
+
2960 } while (retries > 0 && errno == EEXIST);
+
2961
+
2962 return -1;
+
2963}
+
2964
+
2965int create_shm_file(off_t size) {
+
2966 int fd = anonymous_shm_open();
+
2967 if (fd < 0) {
+
2968 return fd;
2969 }
2970
-
2971 return fd;
-
2972}
-
2973
-
2974static void wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time) {
-
2975 RGFW_UNUSED(data); RGFW_UNUSED(cb); RGFW_UNUSED(time);
-
2976
-
2977 #ifdef RGFW_BUFFER
-
2978 RGFW_window* win = (RGFW_window*)data;
-
2979 if ((win->_flags & RGFW_NO_CPU_RENDER))
-
2980 return;
-
2981
-
2982 wl_surface_attach(win->src.surface, win->src.wl_buffer, 0, 0);
-
2983 wl_surface_damage_buffer(win->src.surface, 0, 0, win->r.w, win->r.h);
-
2984 wl_surface_commit(win->src.surface);
-
2985 #endif
-
2986}
-
2987
-
2988static const struct wl_callback_listener wl_surface_frame_listener = {
-
2989 .done = wl_surface_frame_done,
-
2990};
-
2991#endif /* RGFW_WAYLAND */
-
2992#if !defined(RGFW_NO_X11) && defined(RGFW_WAYLAND)
-
2993void RGFW_useWayland(b8 wayland) { RGFW_useWaylandBool = wayland; }
-
2994#define RGFW_GOTO_WAYLAND(fallback) if (RGFW_useWaylandBool && fallback == 0) goto wayland
-
2995#else
-
2996#define RGFW_GOTO_WAYLAND(fallback)
-
2997void RGFW_useWayland(b8 wayland) { RGFW_UNUSED(wayland); }
-
2998#endif
-
2999
-
3000/*
-
3001 End of Wayland defines
-
3002*/
-
3003
-
3004/*
-
3005
-
3006
-
3007Start of Linux / Unix defines
-
3008
-
3009
-
3010*/
-
3011
-
3012#ifdef RGFW_UNIX
-
3013#if !defined(RGFW_NO_X11_CURSOR) && defined(RGFW_X11)
-
3014#include <X11/Xcursor/Xcursor.h>
-
3015#endif
+
2971 if (ftruncate(fd, size) < 0) {
+
2972 close(fd);
+
2973 return -1;
+
2974 }
+
2975
+
2976 return fd;
+
2977}
+
2978
+
2979static void wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time) {
+
2980 RGFW_UNUSED(data); RGFW_UNUSED(cb); RGFW_UNUSED(time);
+
2981
+
2982 #ifdef RGFW_BUFFER
+
2983 RGFW_window* win = (RGFW_window*)data;
+
2984 if ((win->_flags & RGFW_NO_CPU_RENDER))
+
2985 return;
+
2986
+
2987 wl_surface_attach(win->src.surface, win->src.wl_buffer, 0, 0);
+
2988 wl_surface_damage_buffer(win->src.surface, 0, 0, win->r.w, win->r.h);
+
2989 wl_surface_commit(win->src.surface);
+
2990 #endif
+
2991}
+
2992
+
2993static const struct wl_callback_listener wl_surface_frame_listener = {
+
2994 .done = wl_surface_frame_done,
+
2995};
+
2996#endif /* RGFW_WAYLAND */
+
2997#if !defined(RGFW_NO_X11) && defined(RGFW_WAYLAND)
+
2998void RGFW_useWayland(b8 wayland) { RGFW_useWaylandBool = wayland; }
+
2999#define RGFW_GOTO_WAYLAND(fallback) if (RGFW_useWaylandBool && fallback == 0) goto wayland
+
3000#else
+
3001#define RGFW_GOTO_WAYLAND(fallback)
+
3002void RGFW_useWayland(b8 wayland) { RGFW_UNUSED(wayland); }
+
3003#endif
+
3004
+
3005/*
+
3006 End of Wayland defines
+
3007*/
+
3008
+
3009/*
+
3010
+
3011
+
3012Start of Linux / Unix defines
+
3013
+
3014
+
3015*/
3016
-
3017#include <dlfcn.h>
-
3018
-
3019#ifndef RGFW_NO_DPI
-
3020#include <X11/extensions/Xrandr.h>
-
3021#include <X11/Xresource.h>
-
3022#endif
+
3017#ifdef RGFW_UNIX
+
3018#if !defined(RGFW_NO_X11_CURSOR) && defined(RGFW_X11)
+
3019#include <X11/Xcursor/Xcursor.h>
+
3020#endif
+
3021
+
3022#include <dlfcn.h>
3023
-
3024#include <X11/Xutil.h>
-
3025#include <X11/Xatom.h>
-
3026#include <X11/keysymdef.h>
-
3027#include <unistd.h>
+
3024#ifndef RGFW_NO_DPI
+
3025#include <X11/extensions/Xrandr.h>
+
3026#include <X11/Xresource.h>
+
3027#endif
3028
-
3029#include <X11/XKBlib.h> /* for converting keycode to string */
-
3030#include <X11/cursorfont.h> /* for hiding */
-
3031#include <X11/extensions/shapeconst.h>
-
3032#include <X11/extensions/shape.h>
-
3033#include <X11/extensions/XInput2.h>
-
3034
-
3035#include <limits.h> /* for data limits (mainly used in drag and drop functions) */
-
3036#include <poll.h>
-
3037
-
3038
-
3039#if defined(__linux__) && !defined(RGFW_NO_LINUX)
-
3040#include <linux/joystick.h>
-
3041#endif
+
3029#include <X11/Xutil.h>
+
3030#include <X11/Xatom.h>
+
3031#include <X11/keysymdef.h>
+
3032#include <unistd.h>
+
3033
+
3034#include <X11/XKBlib.h> /* for converting keycode to string */
+
3035#include <X11/cursorfont.h> /* for hiding */
+
3036#include <X11/extensions/shapeconst.h>
+
3037#include <X11/extensions/shape.h>
+
3038#include <X11/extensions/XInput2.h>
+
3039
+
3040#include <limits.h> /* for data limits (mainly used in drag and drop functions) */
+
3041#include <poll.h>
3042
-
3043u8 RGFW_mouseIconSrc[] = { XC_arrow, XC_left_ptr, XC_xterm, XC_crosshair, XC_hand2, XC_sb_h_double_arrow, XC_sb_v_double_arrow, XC_bottom_left_corner, XC_bottom_right_corner, XC_fleur, XC_X_cursor};
-
3044/*atoms needed for drag and drop*/
-
3045Atom XdndAware, XdndTypeList, XdndSelection, XdndEnter, XdndPosition, XdndStatus, XdndLeave, XdndDrop, XdndFinished, XdndActionCopy, XtextPlain, XtextUriList;
-
3046Atom RGFW_XUTF8_STRING = 0;
+
3043
+
3044#if defined(__linux__) && !defined(RGFW_NO_LINUX)
+
3045#include <linux/joystick.h>
+
3046#endif
3047
-
3048Atom wm_delete_window = 0, RGFW_XCLIPBOARD = 0;
-
3049
-
3050#if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
-
3051 typedef XcursorImage* (*PFN_XcursorImageCreate)(int, int);
-
3052 typedef void (*PFN_XcursorImageDestroy)(XcursorImage*);
-
3053 typedef Cursor(*PFN_XcursorImageLoadCursor)(Display*, const XcursorImage*);
-
3054#endif
-
3055#ifdef RGFW_OPENGL
-
3056 typedef GLXContext(*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
-
3057#endif
-
3058
-
3059#if !defined(RGFW_NO_X11_XI_PRELOAD)
-
3060 typedef int (* PFN_XISelectEvents)(Display*,Window,XIEventMask*,int);
-
3061 PFN_XISelectEvents XISelectEventsSRC = NULL;
-
3062 #define XISelectEvents XISelectEventsSRC
+
3048u8 RGFW_mouseIconSrc[] = { XC_arrow, XC_left_ptr, XC_xterm, XC_crosshair, XC_hand2, XC_sb_h_double_arrow, XC_sb_v_double_arrow, XC_bottom_left_corner, XC_bottom_right_corner, XC_fleur, XC_X_cursor};
+
3049/*atoms needed for drag and drop*/
+
3050Atom XdndAware, XdndTypeList, XdndSelection, XdndEnter, XdndPosition, XdndStatus, XdndLeave, XdndDrop, XdndFinished, XdndActionCopy, XtextPlain, XtextUriList;
+
3051Atom RGFW_XUTF8_STRING = 0;
+
3052
+
3053Atom wm_delete_window = 0, RGFW_XCLIPBOARD = 0;
+
3054
+
3055#if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
+
3056 typedef XcursorImage* (*PFN_XcursorImageCreate)(int, int);
+
3057 typedef void (*PFN_XcursorImageDestroy)(XcursorImage*);
+
3058 typedef Cursor(*PFN_XcursorImageLoadCursor)(Display*, const XcursorImage*);
+
3059#endif
+
3060#ifdef RGFW_OPENGL
+
3061 typedef GLXContext(*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+
3062#endif
3063
-
3064 void* X11Xihandle = NULL;
-
3065#endif
-
3066
-
3067#if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
-
3068 PFN_XcursorImageLoadCursor XcursorImageLoadCursorSRC = NULL;
-
3069 PFN_XcursorImageCreate XcursorImageCreateSRC = NULL;
-
3070 PFN_XcursorImageDestroy XcursorImageDestroySRC = NULL;
+
3064#if !defined(RGFW_NO_X11_XI_PRELOAD)
+
3065 typedef int (* PFN_XISelectEvents)(Display*,Window,XIEventMask*,int);
+
3066 PFN_XISelectEvents XISelectEventsSRC = NULL;
+
3067 #define XISelectEvents XISelectEventsSRC
+
3068
+
3069 void* X11Xihandle = NULL;
+
3070#endif
3071
-
3072 #define XcursorImageLoadCursor XcursorImageLoadCursorSRC
-
3073 #define XcursorImageCreate XcursorImageCreateSRC
-
3074 #define XcursorImageDestroy XcursorImageDestroySRC
-
3075
-
3076 void* X11Cursorhandle = NULL;
-
3077#endif
-
3078
-
3079u32 RGFW_windowsOpen = 0;
+
3072#if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
+
3073 PFN_XcursorImageLoadCursor XcursorImageLoadCursorSRC = NULL;
+
3074 PFN_XcursorImageCreate XcursorImageCreateSRC = NULL;
+
3075 PFN_XcursorImageDestroy XcursorImageDestroySRC = NULL;
+
3076
+
3077 #define XcursorImageLoadCursor XcursorImageLoadCursorSRC
+
3078 #define XcursorImageCreate XcursorImageCreateSRC
+
3079 #define XcursorImageDestroy XcursorImageDestroySRC
3080
-
3081#if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
3082 void* RGFW_getProcAddress(const char* procname) { return (void*) glXGetProcAddress((GLubyte*) procname); }
-
3083#endif
-
3084
-
3085void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area) {
-
3086 RGFW_GOTO_WAYLAND(0);
-
3087
-
3088 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
3089 win->buffer = (u8*)buffer;
-
3090 win->bufferSize = area;
-
3091
-
3092 #ifdef RGFW_DEBUG
-
3093 printf("RGFW INFO: createing a 4 channel %i by %i buffer\n", area.w, area.h);
-
3094 #endif
-
3095 #ifdef RGFW_X11
-
3096 #ifdef RGFW_OSMESA
-
3097 win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
-
3098 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, area.w, area.h);
-
3099 #endif
-
3100
-
3101 win->src.bitmap = XCreateImage(
-
3102 win->src.display, XDefaultVisual(win->src.display, XDefaultScreen(win->src.display)),
-
3103 32, ZPixmap, 0, NULL, area.w, area.h,
-
3104 32, 0
-
3105 );
-
3106
-
3107 win->src.gc = XCreateGC(win->src.display, win->src.window, 0, NULL);
-
3108 #endif
-
3109 #ifdef RGFW_WAYLAND
-
3110 wayland:
-
3111 size_t size = win->r.w * win->r.h * 4;
-
3112 int fd = create_shm_file(size);
-
3113 if (fd < 0) {
-
3114 fprintf(stderr, "Failed to create a buffer. size: %ld\n", size);
-
3115 exit(1);
-
3116
-
3117 win->src.buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-
3118 if (win->src.buffer == MAP_FAILED) {
-
3119 fprintf(stderr, "mmap failed!\n");
-
3120 close(fd);
-
3121 exit(1);
-
3122 }
-
3123
-
3124 win->_flags |= RGFW_BUFFER_ALLOC;
-
3125
-
3126 struct wl_shm_pool* pool = wl_shm_create_pool(win->src.shm, fd, size);
-
3127 win->src.wl_buffer = wl_shm_pool_create_buffer(pool, 0, win->r.w, win->r.h, win->r.w * 4,
-
3128 WL_SHM_FORMAT_ARGB8888);
-
3129 wl_shm_pool_destroy(pool);
+
3081 void* X11Cursorhandle = NULL;
+
3082#endif
+
3083
+
3084u32 RGFW_windowsOpen = 0;
+
3085
+
3086#if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
3087 void* RGFW_getProcAddress(const char* procname) { return (void*) glXGetProcAddress((GLubyte*) procname); }
+
3088#endif
+
3089
+
3090void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area) {
+
3091 RGFW_GOTO_WAYLAND(0);
+
3092
+
3093 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
3094 win->buffer = (u8*)buffer;
+
3095 win->bufferSize = area;
+
3096
+
3097 #ifdef RGFW_DEBUG
+
3098 printf("RGFW INFO: createing a 4 channel %i by %i buffer\n", area.w, area.h);
+
3099 #endif
+
3100 #ifdef RGFW_X11
+
3101 #ifdef RGFW_OSMESA
+
3102 win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
+
3103 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, area.w, area.h);
+
3104 #endif
+
3105
+
3106 win->src.bitmap = XCreateImage(
+
3107 win->src.display, XDefaultVisual(win->src.display, XDefaultScreen(win->src.display)),
+
3108 32, ZPixmap, 0, NULL, area.w, area.h,
+
3109 32, 0
+
3110 );
+
3111
+
3112 win->src.gc = XCreateGC(win->src.display, win->src.window, 0, NULL);
+
3113 #endif
+
3114 #ifdef RGFW_WAYLAND
+
3115 wayland:
+
3116 size_t size = win->r.w * win->r.h * 4;
+
3117 int fd = create_shm_file(size);
+
3118 if (fd < 0) {
+
3119 fprintf(stderr, "Failed to create a buffer. size: %ld\n", size);
+
3120 exit(1);
+
3121
+
3122 win->src.buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
3123 if (win->src.buffer == MAP_FAILED) {
+
3124 fprintf(stderr, "mmap failed!\n");
+
3125 close(fd);
+
3126 exit(1);
+
3127 }
+
3128
+
3129 win->_flags |= RGFW_BUFFER_ALLOC;
3130
-
3131 close(fd);
-
3132
-
3133 wl_surface_attach(win->src.surface, win->src.wl_buffer, 0, 0);
-
3134 wl_surface_commit(win->src.surface);
+
3131 struct wl_shm_pool* pool = wl_shm_create_pool(win->src.shm, fd, size);
+
3132 win->src.wl_buffer = wl_shm_pool_create_buffer(pool, 0, win->r.w, win->r.h, win->r.w * 4,
+
3133 WL_SHM_FORMAT_ARGB8888);
+
3134 wl_shm_pool_destroy(pool);
3135
-
3136 u8 color[] = {0x00, 0x00, 0x00, 0xFF};
+
3136 close(fd);
3137
-
3138 size_t i;
-
3139 for (i = 0; i < area.w * area.h * 4; i += 4) {
-
3140 RGFW_MEMCPY(&win->buffer[i], color, 4);
-
3141 }
-
3142
-
3143 RGFW_MEMCPY(win->src.buffer, win->buffer, win->r.w * win->r.h * 4);
-
3144
-
3145 #if defined(RGFW_OSMESA)
-
3146 win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
-
3147 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, area.w, area.h);
-
3148 #endif
-
3149 #endif
-
3150 #else
-
3151 wayland:
-
3152 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
-
3153 #endif
-
3154}
-
3155
-
3156#define RGFW_LOAD_ATOM(name) \
-
3157 static Atom name = 0; \
-
3158 if (name == 0) name = XInternAtom(RGFW_root->src.display, #name, False);
-
3159
-
3160void RGFW_window_setBorder(RGFW_window* win, u8 border) {
-
3161 RGFW_GOTO_WAYLAND(0);
-
3162 #ifdef RGFW_X11
-
3163 RGFW_LOAD_ATOM(_MOTIF_WM_HINTS);
+
3138 wl_surface_attach(win->src.surface, win->src.wl_buffer, 0, 0);
+
3139 wl_surface_commit(win->src.surface);
+
3140
+
3141 u8 color[] = {0x00, 0x00, 0x00, 0xFF};
+
3142
+
3143 size_t i;
+
3144 for (i = 0; i < area.w * area.h * 4; i += 4) {
+
3145 RGFW_MEMCPY(&win->buffer[i], color, 4);
+
3146 }
+
3147
+
3148 RGFW_MEMCPY(win->src.buffer, win->buffer, win->r.w * win->r.h * 4);
+
3149
+
3150 #if defined(RGFW_OSMESA)
+
3151 win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
+
3152 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, area.w, area.h);
+
3153 #endif
+
3154 #endif
+
3155 #else
+
3156 wayland:
+
3157 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
+
3158 #endif
+
3159}
+
3160
+
3161#define RGFW_LOAD_ATOM(name) \
+
3162 static Atom name = 0; \
+
3163 if (name == 0) name = XInternAtom(RGFW_root->src.display, #name, False);
3164
-
3165 struct __x11WindowHints {
-
3166 unsigned long flags, functions, decorations, status;
-
3167 long input_mode;
-
3168 } hints;
-
3169 hints.flags = (1L << 1);
-
3170 hints.decorations = border;
-
3171
- -
3173 win->src.display, win->src.window,
-
3174 _MOTIF_WM_HINTS, _MOTIF_WM_HINTS,
-
3175 32, PropModeReplace, (u8*)&hints, 5
-
3176 );
-
3177 #endif
-
3178 #ifdef RGFW_WAYLAND
-
3179 wayland:
-
3180 #endif
-
3181}
-
3182
-
3183void RGFW_releaseCursor(RGFW_window* win) {
-
3184RGFW_GOTO_WAYLAND(0);
-
3185#ifdef RGFW_X11
-
3186 XUngrabPointer(win->src.display, CurrentTime);
+
3165void RGFW_window_setBorder(RGFW_window* win, u8 border) {
+
3166 RGFW_GOTO_WAYLAND(0);
+
3167 #ifdef RGFW_X11
+
3168 RGFW_LOAD_ATOM(_MOTIF_WM_HINTS);
+
3169
+
3170 struct __x11WindowHints {
+
3171 unsigned long flags, functions, decorations, status;
+
3172 long input_mode;
+
3173 } hints;
+
3174 hints.flags = (1L << 1);
+
3175 hints.decorations = border;
+
3176
+ +
3178 win->src.display, win->src.window,
+
3179 _MOTIF_WM_HINTS, _MOTIF_WM_HINTS,
+
3180 32, PropModeReplace, (u8*)&hints, 5
+
3181 );
+
3182 #endif
+
3183 #ifdef RGFW_WAYLAND
+
3184 wayland:
+
3185 #endif
+
3186}
3187
-
3188 /* disable raw input */
-
3189 unsigned char mask[] = { 0 };
-
3190 XIEventMask em;
-
3191 em.deviceid = XIAllMasterDevices;
-
3192 em.mask_len = sizeof(mask);
-
3193 em.mask = mask;
-
3194
-
3195 XISelectEvents(win->src.display, XDefaultRootWindow(win->src.display), &em, 1);
-
3196#endif
-
3197#ifdef RGFW_WAYLAND
-
3198 wayland:
-
3199#endif
-
3200}
-
3201
-
3202void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
-
3203RGFW_GOTO_WAYLAND(0);
-
3204#ifdef RGFW_X11
-
3205 /* enable raw input */
-
3206 unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
-
3207 XISetMask(mask, XI_RawMotion);
-
3208
-
3209 XIEventMask em;
-
3210 em.deviceid = XIAllMasterDevices;
-
3211 em.mask_len = sizeof(mask);
-
3212 em.mask = mask;
+
3188void RGFW_releaseCursor(RGFW_window* win) {
+
3189RGFW_GOTO_WAYLAND(0);
+
3190#ifdef RGFW_X11
+
3191 XUngrabPointer(win->src.display, CurrentTime);
+
3192
+
3193 /* disable raw input */
+
3194 unsigned char mask[] = { 0 };
+
3195 XIEventMask em;
+
3196 em.deviceid = XIAllMasterDevices;
+
3197 em.mask_len = sizeof(mask);
+
3198 em.mask = mask;
+
3199
+
3200 XISelectEvents(win->src.display, XDefaultRootWindow(win->src.display), &em, 1);
+
3201#endif
+
3202#ifdef RGFW_WAYLAND
+
3203 wayland:
+
3204#endif
+
3205}
+
3206
+
3207void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
+
3208RGFW_GOTO_WAYLAND(0);
+
3209#ifdef RGFW_X11
+
3210 /* enable raw input */
+
3211 unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
+
3212 XISetMask(mask, XI_RawMotion);
3213
-
3214 XISelectEvents(win->src.display, XDefaultRootWindow(win->src.display), &em, 1);
-
3215
-
3216 XGrabPointer(win->src.display, win->src.window, True, PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
-
3217 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (i32)(r.w / 2), win->r.y + (i32)(r.h / 2)));
-
3218#endif
-
3219#ifdef RGFW_WAYLAND
-
3220 wayland:
-
3221#endif
-
3222}
-
3223
-
3224#define RGFW_LOAD_LIBRARY(x, lib) if (x == NULL) x = dlopen(lib, RTLD_LAZY | RTLD_LOCAL)
-
3225#define RGFW_PROC_DEF(proc, name) if (name##SRC == NULL && proc != NULL) name##SRC = (PFN_##name)(void*)dlsym(proc, #name)
-
3226
-
3227RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
-
3228 #ifdef RGFW_USE_XDL
-
3229 XDL_init();
-
3230 #endif
+
3214 XIEventMask em;
+
3215 em.deviceid = XIAllMasterDevices;
+
3216 em.mask_len = sizeof(mask);
+
3217 em.mask = mask;
+
3218
+
3219 XISelectEvents(win->src.display, XDefaultRootWindow(win->src.display), &em, 1);
+
3220
+
3221 XGrabPointer(win->src.display, win->src.window, True, PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
+
3222 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (i32)(r.w / 2), win->r.y + (i32)(r.h / 2)));
+
3223#endif
+
3224#ifdef RGFW_WAYLAND
+
3225 wayland:
+
3226#endif
+
3227}
+
3228
+
3229#define RGFW_LOAD_LIBRARY(x, lib) if (x == NULL) x = dlopen(lib, RTLD_LAZY | RTLD_LOCAL)
+
3230#define RGFW_PROC_DEF(proc, name) if (name##SRC == NULL && proc != NULL) name##SRC = (PFN_##name)(void*)dlsym(proc, #name)
3231
-
3232 #if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
-
3233 #if defined(__CYGWIN__)
-
3234 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor-1.so");
-
3235 #elif defined(__OpenBSD__) || defined(__NetBSD__)
-
3236 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor.so");
-
3237 #else
-
3238 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor.so.1");
-
3239 #endif
-
3240 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageCreate);
-
3241 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageDestroy);
-
3242 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageLoadCursor);
-
3243 #endif
-
3244
-
3245 #if !defined(RGFW_NO_X11_XI_PRELOAD)
-
3246 #if defined(__CYGWIN__)
-
3247 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi-6.so");
-
3248 #elif defined(__OpenBSD__) || defined(__NetBSD__)
-
3249 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi.so");
-
3250 #else
-
3251 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi.so.6");
-
3252 #endif
-
3253 RGFW_PROC_DEF(X11Xihandle, XISelectEvents);
-
3254 #endif
-
3255
-
3256 XInitThreads();
-
3258 if (flags & RGFW_windowOpenglSoftware)
-
3259 setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
+
3232RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
+
3233 #ifdef RGFW_USE_XDL
+
3234 XDL_init();
+
3235 #endif
+
3236
+
3237 #if !defined(RGFW_NO_X11_CURSOR) && !defined(RGFW_NO_X11_CURSOR_PRELOAD)
+
3238 #if defined(__CYGWIN__)
+
3239 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor-1.so");
+
3240 #elif defined(__OpenBSD__) || defined(__NetBSD__)
+
3241 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor.so");
+
3242 #else
+
3243 RGFW_LOAD_LIBRARY(X11Cursorhandle, "libXcursor.so.1");
+
3244 #endif
+
3245 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageCreate);
+
3246 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageDestroy);
+
3247 RGFW_PROC_DEF(X11Cursorhandle, XcursorImageLoadCursor);
+
3248 #endif
+
3249
+
3250 #if !defined(RGFW_NO_X11_XI_PRELOAD)
+
3251 #if defined(__CYGWIN__)
+
3252 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi-6.so");
+
3253 #elif defined(__OpenBSD__) || defined(__NetBSD__)
+
3254 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi.so");
+
3255 #else
+
3256 RGFW_LOAD_LIBRARY(X11Xihandle, "libXi.so.6");
+
3257 #endif
+
3258 RGFW_PROC_DEF(X11Xihandle, XISelectEvents);
+
3259 #endif
3260
-
3261 RGFW_window_basic_init(win, rect, flags);
-
3262
-
3263#ifdef RGFW_WAYLAND
-
3264 win->src.compositor = NULL;
-
3265#endif
-
3266 RGFW_GOTO_WAYLAND(0);
-
3267#ifdef RGFW_X11
-
3268 u64 event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | FocusChangeMask | LeaveWindowMask | EnterWindowMask | ExposureMask;
-
3270 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
3271 u32* visual_attribs = (u32*)RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
-
3272 i32 fbcount;
-
3273 GLXFBConfig* fbc = glXChooseFBConfig(win->src.display, DefaultScreen(win->src.display), (i32*) visual_attribs, &fbcount);
-
3274
-
3275 i32 best_fbc = -1;
-
3276
-
3277 if (fbcount == 0) {
-
3278 #ifdef RGFW_DEBUG
-
3279 fprintf(stderr, "Failed to find any valid GLX visual configs\n");
-
3280 #endif
-
3281 return NULL;
-
3282 }
-
3283
-
3284 u32 i;
-
3285 for (i = 0; i < (u32)fbcount; i++) {
-
3286 XVisualInfo* vi = glXGetVisualFromFBConfig(win->src.display, fbc[i]);
-
3287 if (vi == NULL)
-
3288 continue;
-
3289
-
3290 XFree(vi);
-
3291
-
3292 i32 samp_buf, samples;
-
3293 glXGetFBConfigAttrib(win->src.display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
-
3294 glXGetFBConfigAttrib(win->src.display, fbc[i], GLX_SAMPLES, &samples);
-
3295
-
3296 if ((!(flags & RGFW_windowTransparent) || vi->depth == 32) &&
-
3297 (best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) {
-
3298 best_fbc = i;
-
3299 }
-
3300 }
-
3301
-
3302 if (best_fbc == -1) {
-
3303 #ifdef RGFW_DEBUG
-
3304 fprintf(stderr, "Failed to get a valid GLX visual\n");
-
3305 #endif
-
3306 return NULL;
-
3307 }
-
3308
-
3309 GLXFBConfig bestFbc = fbc[best_fbc];
-
3310
-
3311 /* Get a visual */
-
3312 XVisualInfo* vi = glXGetVisualFromFBConfig(win->src.display, bestFbc);
+
3261 XInitThreads();
+
3263 if (flags & RGFW_windowOpenglSoftware)
+
3264 setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
+
3265
+
3266 RGFW_window_basic_init(win, rect, flags);
+
3267
+
3268#ifdef RGFW_WAYLAND
+
3269 win->src.compositor = NULL;
+
3270#endif
+
3271 RGFW_GOTO_WAYLAND(0);
+
3272#ifdef RGFW_X11
+
3273 u64 event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | FocusChangeMask | LeaveWindowMask | EnterWindowMask | ExposureMask;
+
3275 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
3276 u32* visual_attribs = (u32*)RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
+
3277 i32 fbcount;
+
3278 GLXFBConfig* fbc = glXChooseFBConfig(win->src.display, DefaultScreen(win->src.display), (i32*) visual_attribs, &fbcount);
+
3279
+
3280 i32 best_fbc = -1;
+
3281
+
3282 if (fbcount == 0) {
+
3283 #ifdef RGFW_DEBUG
+
3284 fprintf(stderr, "Failed to find any valid GLX visual configs\n");
+
3285 #endif
+
3286 return NULL;
+
3287 }
+
3288
+
3289 u32 i;
+
3290 for (i = 0; i < (u32)fbcount; i++) {
+
3291 XVisualInfo* vi = glXGetVisualFromFBConfig(win->src.display, fbc[i]);
+
3292 if (vi == NULL)
+
3293 continue;
+
3294
+
3295 XFree(vi);
+
3296
+
3297 i32 samp_buf, samples;
+
3298 glXGetFBConfigAttrib(win->src.display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
+
3299 glXGetFBConfigAttrib(win->src.display, fbc[i], GLX_SAMPLES, &samples);
+
3300
+
3301 if ((!(flags & RGFW_windowTransparent) || vi->depth == 32) &&
+
3302 (best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) {
+
3303 best_fbc = i;
+
3304 }
+
3305 }
+
3306
+
3307 if (best_fbc == -1) {
+
3308 #ifdef RGFW_DEBUG
+
3309 fprintf(stderr, "Failed to get a valid GLX visual\n");
+
3310 #endif
+
3311 return NULL;
+
3312 }
3313
-
3314 XFree(fbc);
-
3315 #else
-
3316 XVisualInfo viNorm;
-
3317
-
3318 viNorm.visual = DefaultVisual(win->src.display, DefaultScreen(win->src.display));
-
3319
-
3320 viNorm.depth = 0;
-
3321 XVisualInfo* vi = &viNorm;
+
3314 GLXFBConfig bestFbc = fbc[best_fbc];
+
3315
+
3316 /* Get a visual */
+
3317 XVisualInfo* vi = glXGetVisualFromFBConfig(win->src.display, bestFbc);
+
3318
+
3319 XFree(fbc);
+
3320 #else
+
3321 XVisualInfo viNorm;
3322
-
3323 XMatchVisualInfo(win->src.display, DefaultScreen(win->src.display), 32, TrueColor, vi);
-
3324 #endif
-
3325 /* make X window attrubutes*/
-
3326 XSetWindowAttributes swa;
-
3327 Colormap cmap;
-
3328
-
3329 swa.colormap = cmap = XCreateColormap(win->src.display,
-
3330 DefaultRootWindow(win->src.display),
-
3331 vi->visual, AllocNone);
-
3332
-
3333 swa.background_pixmap = None;
-
3334 swa.border_pixel = 0;
-
3335 swa.event_mask = event_mask;
-
3336
-
3337 swa.background_pixel = 0;
-
3338
-
3339 /* create the window*/
-
3340 win->src.window = XCreateWindow(win->src.display, DefaultRootWindow(win->src.display), win->r.x, win->r.y, win->r.w, win->r.h,
-
3341 0, vi->depth, InputOutput, vi->visual,
-
3342 CWColormap | CWBorderPixel | CWBackPixel | CWEventMask, &swa);
+
3323 viNorm.visual = DefaultVisual(win->src.display, DefaultScreen(win->src.display));
+
3324
+
3325 viNorm.depth = 0;
+
3326 XVisualInfo* vi = &viNorm;
+
3327
+
3328 XMatchVisualInfo(win->src.display, DefaultScreen(win->src.display), 32, TrueColor, vi);
+
3329 #endif
+
3330 /* make X window attrubutes*/
+
3331 XSetWindowAttributes swa;
+
3332 Colormap cmap;
+
3333
+
3334 swa.colormap = cmap = XCreateColormap(win->src.display,
+
3335 DefaultRootWindow(win->src.display),
+
3336 vi->visual, AllocNone);
+
3337
+
3338 swa.background_pixmap = None;
+
3339 swa.border_pixel = 0;
+
3340 swa.event_mask = event_mask;
+
3341
+
3342 swa.background_pixel = 0;
3343
-
3344 XFreeColors(win->src.display, cmap, NULL, 0, 0);
-
3345
-
3346 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
3347 XFree(vi);
-
3348 #endif
-
3349
-
3350 // In your .desktop app, if you set the property
-
3351 // StartupWMClass=RGFW that will assoicate the launcher icon
-
3352 // with your application - robrohan
-
3353
-
3354 if (RGFW_className == NULL)
-
3355 RGFW_className = (char*)name;
-
3356
-
3357 XClassHint hint;
-
3358 hint.res_class = (char*)RGFW_className;
-
3359 hint.res_name = (char*)name; // just use the window name as the app name
-
3360 XSetClassHint(win->src.display, win->src.window, &hint);
-
3361
-
3362 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
3363 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL) /* This is the second part of setting up opengl. This is where we ask OpenGL for a specific version. */
-
3364 i32 context_attribs[7] = { 0, 0, 0, 0, 0, 0, 0 };
-
3365 context_attribs[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
-
3366 if (RGFW_profile == RGFW_glCore)
-
3367 context_attribs[1] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
-
3368 else
-
3369 context_attribs[1] = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
-
3370
-
3371 if (RGFW_majorVersion || RGFW_minorVersion) {
-
3372 context_attribs[2] = GLX_CONTEXT_MAJOR_VERSION_ARB;
-
3373 context_attribs[3] = RGFW_majorVersion;
-
3374 context_attribs[4] = GLX_CONTEXT_MINOR_VERSION_ARB;
-
3375 context_attribs[5] = RGFW_minorVersion;
-
3376 }
-
3377
-
3378 glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
-
3379 glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
-
3380 glXGetProcAddressARB((GLubyte*) "glXCreateContextAttribsARB");
-
3381
-
3382 GLXContext ctx = NULL;
-
3383
-
3384 if (RGFW_root != NULL)
-
3385 ctx = RGFW_root->src.ctx;
+
3344 /* create the window*/
+
3345 win->src.window = XCreateWindow(win->src.display, DefaultRootWindow(win->src.display), win->r.x, win->r.y, win->r.w, win->r.h,
+
3346 0, vi->depth, InputOutput, vi->visual,
+
3347 CWColormap | CWBorderPixel | CWBackPixel | CWEventMask, &swa);
+
3348
+
3349 XFreeColors(win->src.display, cmap, NULL, 0, 0);
+
3350
+
3351 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
3352 XFree(vi);
+
3353 #endif
+
3354
+
3355 // In your .desktop app, if you set the property
+
3356 // StartupWMClass=RGFW that will assoicate the launcher icon
+
3357 // with your application - robrohan
+
3358
+
3359 if (RGFW_className == NULL)
+
3360 RGFW_className = (char*)name;
+
3361
+
3362 XClassHint hint;
+
3363 hint.res_class = (char*)RGFW_className;
+
3364 hint.res_name = (char*)name; // just use the window name as the app name
+
3365 XSetClassHint(win->src.display, win->src.window, &hint);
+
3366
+
3367 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
3368 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL) /* This is the second part of setting up opengl. This is where we ask OpenGL for a specific version. */
+
3369 i32 context_attribs[7] = { 0, 0, 0, 0, 0, 0, 0 };
+
3370 context_attribs[0] = GLX_CONTEXT_PROFILE_MASK_ARB;
+
3371 if (RGFW_profile == RGFW_glCore)
+
3372 context_attribs[1] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+
3373 else
+
3374 context_attribs[1] = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
+
3375
+
3376 if (RGFW_majorVersion || RGFW_minorVersion) {
+
3377 context_attribs[2] = GLX_CONTEXT_MAJOR_VERSION_ARB;
+
3378 context_attribs[3] = RGFW_majorVersion;
+
3379 context_attribs[4] = GLX_CONTEXT_MINOR_VERSION_ARB;
+
3380 context_attribs[5] = RGFW_minorVersion;
+
3381 }
+
3382
+
3383 glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
+
3384 glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
+
3385 glXGetProcAddressARB((GLubyte*) "glXCreateContextAttribsARB");
3386
-
3387 win->src.ctx = glXCreateContextAttribsARB(win->src.display, bestFbc, ctx, True, context_attribs);
-
3388 #endif
-
3389 }
-
3390
-
3391 #ifndef RGFW_NO_MONITOR
-
3392 if (flags & RGFW_windowScaleToMonitor)
- -
3394 #endif
+
3387 GLXContext ctx = NULL;
+
3388
+
3389 if (RGFW_root != NULL)
+
3390 ctx = RGFW_root->src.ctx;
+
3391
+
3392 win->src.ctx = glXCreateContextAttribsARB(win->src.display, bestFbc, ctx, True, context_attribs);
+
3393 #endif
+
3394 }
3395
-
3396 if (flags & RGFW_windowCenter) {
-
3397 RGFW_area screenR = RGFW_getScreenSize();
-
3398 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
-
3399 }
+
3396 #ifndef RGFW_NO_MONITOR
+
3397 if (flags & RGFW_windowScaleToMonitor)
+ +
3399 #endif
3400
-
3401 if (flags & RGFW_windowNoResize) { /* make it so the user can't resize the window*/
-
3402 XSizeHints sh;
-
3403 sh.flags = (1L << 4) | (1L << 5);
-
3404 sh.min_width = sh.max_width = win->r.w;
-
3405 sh.min_height = sh.max_height = win->r.h;
-
3406
-
3407 XSetWMSizeHints(win->src.display, (Drawable) win->src.window, &sh, XA_WM_NORMAL_HINTS);
-
3408
-
3409 win->_flags |= RGFW_windowNoResize;
-
3410 }
+
3401 if (flags & RGFW_windowCenter) {
+
3402 RGFW_area screenR = RGFW_getScreenSize();
+
3403 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
+
3404 }
+
3405
+
3406 if (flags & RGFW_windowNoResize) { /* make it so the user can't resize the window*/
+
3407 XSizeHints sh;
+
3408 sh.flags = (1L << 4) | (1L << 5);
+
3409 sh.min_width = sh.max_width = win->r.w;
+
3410 sh.min_height = sh.max_height = win->r.h;
3411
-
3412 if (flags & RGFW_windowNoBorder) {
-
3413 RGFW_window_setBorder(win, 0);
-
3414 }
-
3415
-
3416 XSelectInput(win->src.display, (Drawable) win->src.window, event_mask);
-
3418 /* make it so the user can't close the window until the program does*/
-
3419 if (wm_delete_window == 0) {
-
3420 wm_delete_window = XInternAtom(win->src.display, "WM_DELETE_WINDOW", False);
-
3421 RGFW_XUTF8_STRING = XInternAtom(win->src.display, "UTF8_STRING", False);
-
3422 RGFW_XCLIPBOARD = XInternAtom(win->src.display, "CLIPBOARD", False);
-
3423 }
-
3424
-
3425 XSetWMProtocols(win->src.display, (Drawable) win->src.window, &wm_delete_window, 1);
-
3426
-
3427 /* connect the context to the window*/
-
3428 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
3429 if ((flags & RGFW_windowNoInitAPI) == 0)
-
3430 glXMakeCurrent(win->src.display, (Drawable) win->src.window, (GLXContext) win->src.ctx);
-
3431 #endif
-
3432
-
3433 /* set the background*/
-
3434 RGFW_window_setName(win, name);
-
3435
-
3436 XMapWindow(win->src.display, (Drawable) win->src.window); /* draw the window*/
-
3437 XMoveWindow(win->src.display, (Drawable) win->src.window, win->r.x, win->r.y);
-
3439 if (flags & RGFW_windowAllowDND) { /* init drag and drop atoms and turn on drag and drop for this window */
-
3440 win->_flags |= RGFW_windowAllowDND;
-
3441
-
3442 XdndTypeList = XInternAtom(win->src.display, "XdndTypeList", False);
-
3443 XdndSelection = XInternAtom(win->src.display, "XdndSelection", False);
-
3444
-
3445 /* client messages */
-
3446 XdndEnter = XInternAtom(win->src.display, "XdndEnter", False);
-
3447 XdndPosition = XInternAtom(win->src.display, "XdndPosition", False);
-
3448 XdndStatus = XInternAtom(win->src.display, "XdndStatus", False);
-
3449 XdndLeave = XInternAtom(win->src.display, "XdndLeave", False);
-
3450 XdndDrop = XInternAtom(win->src.display, "XdndDrop", False);
-
3451 XdndFinished = XInternAtom(win->src.display, "XdndFinished", False);
-
3452
-
3453 /* actions */
-
3454 XdndActionCopy = XInternAtom(win->src.display, "XdndActionCopy", False);
-
3455
-
3456 XtextUriList = XInternAtom(win->src.display, "text/uri-list", False);
-
3457 XtextPlain = XInternAtom(win->src.display, "text/plain", False);
-
3458
-
3459 XdndAware = XInternAtom(win->src.display, "XdndAware", False);
-
3460 const u8 version = 5;
-
3461
-
3462 XChangeProperty(win->src.display, win->src.window,
-
3463 XdndAware, 4, 32,
-
3464 PropModeReplace, &version, 1);
-
3465 }
+
3412 XSetWMSizeHints(win->src.display, (Drawable) win->src.window, &sh, XA_WM_NORMAL_HINTS);
+
3413
+
3414 win->_flags |= RGFW_windowNoResize;
+
3415 }
+
3416
+
3417 if (flags & RGFW_windowNoBorder) {
+
3418 RGFW_window_setBorder(win, 0);
+
3419 }
+
3420
+
3421 XSelectInput(win->src.display, (Drawable) win->src.window, event_mask);
+
3423 /* make it so the user can't close the window until the program does*/
+
3424 if (wm_delete_window == 0) {
+
3425 wm_delete_window = XInternAtom(win->src.display, "WM_DELETE_WINDOW", False);
+
3426 RGFW_XUTF8_STRING = XInternAtom(win->src.display, "UTF8_STRING", False);
+
3427 RGFW_XCLIPBOARD = XInternAtom(win->src.display, "CLIPBOARD", False);
+
3428 }
+
3429
+
3430 XSetWMProtocols(win->src.display, (Drawable) win->src.window, &wm_delete_window, 1);
+
3431
+
3432 /* connect the context to the window*/
+
3433 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
3434 if ((flags & RGFW_windowNoInitAPI) == 0)
+
3435 glXMakeCurrent(win->src.display, (Drawable) win->src.window, (GLXContext) win->src.ctx);
+
3436 #endif
+
3437
+
3438 /* set the background*/
+
3439 RGFW_window_setName(win, name);
+
3440
+
3441 XMapWindow(win->src.display, (Drawable) win->src.window); /* draw the window*/
+
3442 XMoveWindow(win->src.display, (Drawable) win->src.window, win->r.x, win->r.y);
+
3444 if (flags & RGFW_windowAllowDND) { /* init drag and drop atoms and turn on drag and drop for this window */
+
3445 win->_flags |= RGFW_windowAllowDND;
+
3446
+
3447 XdndTypeList = XInternAtom(win->src.display, "XdndTypeList", False);
+
3448 XdndSelection = XInternAtom(win->src.display, "XdndSelection", False);
+
3449
+
3450 /* client messages */
+
3451 XdndEnter = XInternAtom(win->src.display, "XdndEnter", False);
+
3452 XdndPosition = XInternAtom(win->src.display, "XdndPosition", False);
+
3453 XdndStatus = XInternAtom(win->src.display, "XdndStatus", False);
+
3454 XdndLeave = XInternAtom(win->src.display, "XdndLeave", False);
+
3455 XdndDrop = XInternAtom(win->src.display, "XdndDrop", False);
+
3456 XdndFinished = XInternAtom(win->src.display, "XdndFinished", False);
+
3457
+
3458 /* actions */
+
3459 XdndActionCopy = XInternAtom(win->src.display, "XdndActionCopy", False);
+
3460
+
3461 XtextUriList = XInternAtom(win->src.display, "text/uri-list", False);
+
3462 XtextPlain = XInternAtom(win->src.display, "text/plain", False);
+
3463
+
3464 XdndAware = XInternAtom(win->src.display, "XdndAware", False);
+
3465 const u8 version = 5;
3466
-
3467 #ifdef RGFW_EGL
-
3468 if ((flags & RGFW_windowNoInitAPI) == 0)
-
3469 RGFW_createOpenGLContext(win);
-
3470 #endif
-
3471 #ifdef RGFW_DEBUG
-
3472 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
-
3473 #endif
- -
3475 RGFW_windowsOpen++;
-
3476 return win; /*return newly created window*/
-
3477#endif
-
3478#ifdef RGFW_WAYLAND
-
3479 wayland:
-
3480 fprintf(stderr, "Warning: RGFW Wayland support is experimental\n");
-
3481
-
3482 win->src.wl_display = wl_display_connect(NULL);
-
3483 if (win->src.wl_display == NULL) {
-
3484 #ifdef RGFW_DEBUG
-
3485 fprintf(stderr, "Failed to load Wayland display\n");
-
3486 #endif
-
3487 #ifdef RGFW_X11
-
3488 fprintf(stderr, "Falling back to X11\n");
-
3489 RGFW_useWayland(0);
-
3490 return RGFW_createWindowPtr(name, rect, flags, win);
+
3467 XChangeProperty(win->src.display, win->src.window,
+
3468 XdndAware, 4, 32,
+
3469 PropModeReplace, &version, 1);
+
3470 }
+
3471
+
3472 #ifdef RGFW_EGL
+
3473 if ((flags & RGFW_windowNoInitAPI) == 0)
+
3474 RGFW_createOpenGLContext(win);
+
3475 #endif
+
3476 #ifdef RGFW_DEBUG
+
3477 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
+
3478 #endif
+ +
3480 RGFW_windowsOpen++;
+
3481 return win; /*return newly created window*/
+
3482#endif
+
3483#ifdef RGFW_WAYLAND
+
3484 wayland:
+
3485 fprintf(stderr, "Warning: RGFW Wayland support is experimental\n");
+
3486
+
3487 win->src.wl_display = wl_display_connect(NULL);
+
3488 if (win->src.wl_display == NULL) {
+
3489 #ifdef RGFW_DEBUG
+
3490 fprintf(stderr, "Failed to load Wayland display\n");
3491 #endif
-
3492 return NULL;
-
3493 }
-
3494
-
3495
-
3496 #ifdef RGFW_X11
-
3497 XSetWindowAttributes attributes;
-
3498 attributes.background_pixel = 0;
-
3499 attributes.override_redirect = True;
+
3492 #ifdef RGFW_X11
+
3493 fprintf(stderr, "Falling back to X11\n");
+
3494 RGFW_useWayland(0);
+
3495 return RGFW_createWindowPtr(name, rect, flags, win);
+
3496 #endif
+
3497 return NULL;
+
3498 }
+
3499
3500
-
3501 win->src.window = XCreateWindow(win->src.display, DefaultRootWindow(win->src.display), 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent,
-
3502 CWBackPixel | CWOverrideRedirect, &attributes);
-
3503
-
3504 XMapWindow(win->src.display, win->src.window);
-
3505 XFlush(win->src.display);
-
3506 if (wm_delete_window == 0) {
-
3507 wm_delete_window = XInternAtom(win->src.display, "WM_DELETE_WINDOW", False);
-
3508 RGFW_XUTF8_STRING = XInternAtom(win->src.display, "UTF8_STRING", False);
-
3509 RGFW_XCLIPBOARD = XInternAtom(win->src.display, "CLIPBOARD", False);
-
3510 }
-
3511 #endif
-
3512
-
3513 struct wl_registry *registry = wl_display_get_registry(win->src.wl_display);
-
3514 wl_registry_add_listener(registry, &registry_listener, win);
-
3515
-
3516 wl_display_roundtrip(win->src.wl_display);
-
3517 wl_display_dispatch(win->src.wl_display);
-
3518
-
3519 if (win->src.compositor == NULL) {
-
3520 #ifdef RGFW_DEBUG
-
3521 fprintf(stderr, "Can't find compositor.\n");
-
3522 #endif
+
3501 #ifdef RGFW_X11
+
3502 XSetWindowAttributes attributes;
+
3503 attributes.background_pixel = 0;
+
3504 attributes.override_redirect = True;
+
3505
+
3506 win->src.window = XCreateWindow(win->src.display, DefaultRootWindow(win->src.display), 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent,
+
3507 CWBackPixel | CWOverrideRedirect, &attributes);
+
3508
+
3509 XMapWindow(win->src.display, win->src.window);
+
3510 XFlush(win->src.display);
+
3511 if (wm_delete_window == 0) {
+
3512 wm_delete_window = XInternAtom(win->src.display, "WM_DELETE_WINDOW", False);
+
3513 RGFW_XUTF8_STRING = XInternAtom(win->src.display, "UTF8_STRING", False);
+
3514 RGFW_XCLIPBOARD = XInternAtom(win->src.display, "CLIPBOARD", False);
+
3515 }
+
3516 #endif
+
3517
+
3518 struct wl_registry *registry = wl_display_get_registry(win->src.wl_display);
+
3519 wl_registry_add_listener(registry, &registry_listener, win);
+
3520
+
3521 wl_display_roundtrip(win->src.wl_display);
+
3522 wl_display_dispatch(win->src.wl_display);
3523
-
3524 return NULL;
-
3525 }
-
3526
-
3527 if (RGFW_wl_cursor_theme == NULL) {
-
3528 RGFW_wl_cursor_theme = wl_cursor_theme_load(NULL, 24, win->src.shm);
-
3529 RGFW_cursor_surface = wl_compositor_create_surface(win->src.compositor);
-
3530
-
3531 struct wl_cursor* cursor = wl_cursor_theme_get_cursor(RGFW_wl_cursor_theme, "left_ptr");
-
3532 RGFW_cursor_image = cursor->images[0];
-
3533 struct wl_buffer* cursor_buffer = wl_cursor_image_get_buffer(RGFW_cursor_image);
-
3534
-
3535 wl_surface_attach(RGFW_cursor_surface, cursor_buffer, 0, 0);
-
3536 wl_surface_commit(RGFW_cursor_surface);
-
3537 }
-
3538
-
3539 xdg_wm_base_add_listener(win->src.xdg_wm_base, &xdg_wm_base_listener, NULL);
-
3540
-
3541 xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
-
3542
-
3543 win->src.surface = wl_compositor_create_surface(win->src.compositor);
-
3544 wl_surface_set_user_data(win->src.surface, win);
+
3524 if (win->src.compositor == NULL) {
+
3525 #ifdef RGFW_DEBUG
+
3526 fprintf(stderr, "Can't find compositor.\n");
+
3527 #endif
+
3528
+
3529 return NULL;
+
3530 }
+
3531
+
3532 if (RGFW_wl_cursor_theme == NULL) {
+
3533 RGFW_wl_cursor_theme = wl_cursor_theme_load(NULL, 24, win->src.shm);
+
3534 RGFW_cursor_surface = wl_compositor_create_surface(win->src.compositor);
+
3535
+
3536 struct wl_cursor* cursor = wl_cursor_theme_get_cursor(RGFW_wl_cursor_theme, "left_ptr");
+
3537 RGFW_cursor_image = cursor->images[0];
+
3538 struct wl_buffer* cursor_buffer = wl_cursor_image_get_buffer(RGFW_cursor_image);
+
3539
+
3540 wl_surface_attach(RGFW_cursor_surface, cursor_buffer, 0, 0);
+
3541 wl_surface_commit(RGFW_cursor_surface);
+
3542 }
+
3543
+
3544 xdg_wm_base_add_listener(win->src.xdg_wm_base, &xdg_wm_base_listener, NULL);
3545
-
3546 win->src.xdg_surface = xdg_wm_base_get_xdg_surface(win->src.xdg_wm_base, win->src.surface);
-
3547 xdg_surface_add_listener(win->src.xdg_surface, &xdg_surface_listener, NULL);
-
3548
-
3549 xdg_wm_base_set_user_data(win->src.xdg_wm_base, win);
+
3546 xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+
3547
+
3548 win->src.surface = wl_compositor_create_surface(win->src.compositor);
+
3549 wl_surface_set_user_data(win->src.surface, win);
3550
-
3551 win->src.xdg_toplevel = xdg_surface_get_toplevel(win->src.xdg_surface);
-
3552 xdg_toplevel_set_user_data(win->src.xdg_toplevel, win);
-
3553 xdg_toplevel_set_title(win->src.xdg_toplevel, name);
-
3554 xdg_toplevel_add_listener(win->src.xdg_toplevel, &xdg_toplevel_listener, NULL);
+
3551 win->src.xdg_surface = xdg_wm_base_get_xdg_surface(win->src.xdg_wm_base, win->src.surface);
+
3552 xdg_surface_add_listener(win->src.xdg_surface, &xdg_surface_listener, NULL);
+
3553
+
3554 xdg_wm_base_set_user_data(win->src.xdg_wm_base, win);
3555
-
3556 xdg_surface_set_window_geometry(win->src.xdg_surface, 0, 0, win->r.w, win->r.h);
-
3557
-
3558 if (!(flags & RGFW_windowNoBorder)) {
-
3559 win->src.decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(
-
3560 decoration_manager, win->src.xdg_toplevel);
-
3561 }
+
3556 win->src.xdg_toplevel = xdg_surface_get_toplevel(win->src.xdg_surface);
+
3557 xdg_toplevel_set_user_data(win->src.xdg_toplevel, win);
+
3558 xdg_toplevel_set_title(win->src.xdg_toplevel, name);
+
3559 xdg_toplevel_add_listener(win->src.xdg_toplevel, &xdg_toplevel_listener, NULL);
+
3560
+
3561 xdg_surface_set_window_geometry(win->src.xdg_surface, 0, 0, win->r.w, win->r.h);
3562
-
3563 if (flags & RGFW_windowCenter) {
-
3564 RGFW_area screenR = RGFW_getScreenSize();
-
3565 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
+
3563 if (!(flags & RGFW_windowNoBorder)) {
+
3564 win->src.decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(
+
3565 decoration_manager, win->src.xdg_toplevel);
3566 }
3567
-
3568 if (flags & RGFW_windowOpenglSoftware)
-
3569 setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
-
3570
-
3571 wl_display_roundtrip(win->src.wl_display);
+
3568 if (flags & RGFW_windowCenter) {
+
3569 RGFW_area screenR = RGFW_getScreenSize();
+
3570 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
+
3571 }
3572
-
3573 wl_surface_commit(win->src.surface);
-
3574
-
3575 /* wait for the surface to be configured */
-
3576 while (wl_display_dispatch(win->src.wl_display) != -1 && !RGFW_wl_configured) { }
-
3577
-
3578 #ifdef RGFW_OPENGL
-
3579 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
3580 win->src.eglWindow = wl_egl_window_create(win->src.surface, win->r.w, win->r.h);
-
3581 RGFW_createOpenGLContext(win);
-
3582 }
-
3583 #endif
-
3584 struct wl_callback* callback = wl_surface_frame(win->src.surface);
-
3585 wl_callback_add_listener(callback, &wl_surface_frame_listener, win);
-
3586 wl_surface_commit(win->src.surface);
-
3587
-
3588 if (flags & RGFW_windowHideMouse) {
-
3589 RGFW_window_showMouse(win, 0);
-
3590 }
-
3591
-
3592 win->src.eventIndex = 0;
-
3593 win->src.eventLen = 0;
-
3594
-
3595 #ifdef RGFW_DEBUG
-
3596 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
-
3597 #endif
-
3598
-
3599 #ifndef RGFW_NO_MONITOR
-
3600 if (flags & RGFW_windowScaleToMonitor)
- +
3573 if (flags & RGFW_windowOpenglSoftware)
+
3574 setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
+
3575
+
3576 wl_display_roundtrip(win->src.wl_display);
+
3577
+
3578 wl_surface_commit(win->src.surface);
+
3579
+
3580 /* wait for the surface to be configured */
+
3581 while (wl_display_dispatch(win->src.wl_display) != -1 && !RGFW_wl_configured) { }
+
3582
+
3583 #ifdef RGFW_OPENGL
+
3584 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
3585 win->src.eglWindow = wl_egl_window_create(win->src.surface, win->r.w, win->r.h);
+
3586 RGFW_createOpenGLContext(win);
+
3587 }
+
3588 #endif
+
3589 struct wl_callback* callback = wl_surface_frame(win->src.surface);
+
3590 wl_callback_add_listener(callback, &wl_surface_frame_listener, win);
+
3591 wl_surface_commit(win->src.surface);
+
3592
+
3593 if (flags & RGFW_windowHideMouse) {
+
3594 RGFW_window_showMouse(win, 0);
+
3595 }
+
3596
+
3597 win->src.eventIndex = 0;
+
3598 win->src.eventLen = 0;
+
3599
+
3600 #ifdef RGFW_DEBUG
+
3601 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
3602 #endif
3603
- -
3605 RGFW_windowsOpen++;
-
3606 return win; /*return newly created window*/
-
3607#endif
-
3608}
-
3609
- -
3611 RGFW_GOTO_WAYLAND(1);
-
3612 RGFW_ASSERT(RGFW_root != NULL);
-
3613
-
3614 #ifdef RGFW_X11
-
3615 Screen* scrn = DefaultScreenOfDisplay(RGFW_root->src.display);
-
3616 return RGFW_AREA(scrn->width, scrn->height);
-
3617 #endif
-
3618 #ifdef RGFW_WAYLAND
-
3619 wayland: return RGFW_AREA(RGFW_root->r.w, RGFW_root->r.h); // TODO
-
3620 #endif
-
3621}
-
3622
- -
3624 RGFW_ASSERT(RGFW_root != NULL);
-
3625
-
3626 RGFW_point RGFWMouse;
+
3604 #ifndef RGFW_NO_MONITOR
+
3605 if (flags & RGFW_windowScaleToMonitor)
+ +
3607 #endif
+
3608
+ +
3610 RGFW_windowsOpen++;
+
3611 return win; /*return newly created window*/
+
3612#endif
+
3613}
+
3614
+ +
3616 RGFW_GOTO_WAYLAND(1);
+
3617 RGFW_ASSERT(RGFW_root != NULL);
+
3618
+
3619 #ifdef RGFW_X11
+
3620 Screen* scrn = DefaultScreenOfDisplay(RGFW_root->src.display);
+
3621 return RGFW_AREA(scrn->width, scrn->height);
+
3622 #endif
+
3623 #ifdef RGFW_WAYLAND
+
3624 wayland: return RGFW_AREA(RGFW_root->r.w, RGFW_root->r.h); // TODO
+
3625 #endif
+
3626}
3627
-
3628 i32 x, y;
-
3629 u32 z;
-
3630 Window window1, window2;
-
3631 XQueryPointer(RGFW_root->src.display, XDefaultRootWindow(RGFW_root->src.display), &window1, &window2, &RGFWMouse.x, &RGFWMouse.y, &x, &y, &z);
+ +
3629 RGFW_ASSERT(RGFW_root != NULL);
+
3630
+
3631 RGFW_point RGFWMouse;
3632
-
3633 return RGFWMouse;
-
3634}
-
3635
- -
3637 RGFW_ASSERT(win != NULL);
-
3638
-
3639 RGFW_point RGFWMouse;
+
3633 i32 x, y;
+
3634 u32 z;
+
3635 Window window1, window2;
+
3636 XQueryPointer(RGFW_root->src.display, XDefaultRootWindow(RGFW_root->src.display), &window1, &window2, &RGFWMouse.x, &RGFWMouse.y, &x, &y, &z);
+
3637
+
3638 return RGFWMouse;
+
3639}
3640
-
3641 i32 x, y;
-
3642 u32 z;
-
3643 Window window1, window2;
-
3644 XQueryPointer(win->src.display, win->src.window, &window1, &window2, &x, &y, &RGFWMouse.x, &RGFWMouse.y, &z);
+ +
3642 RGFW_ASSERT(win != NULL);
+
3643
+
3644 RGFW_point RGFWMouse;
3645
-
3646 return RGFWMouse;
-
3647}
-
3648
-
3649char* RGFW_strtok(char* str, const char* delimStr) {
-
3650 static char* static_str = NULL;
-
3651
-
3652 if (str != NULL)
-
3653 static_str = str;
-
3654
-
3655 if (static_str == NULL) {
-
3656 return NULL;
-
3657 }
-
3658
-
3659 while (*static_str != '\0') {
-
3660 b8 delim = 0;
-
3661 for (const char* d = delimStr; *d != '\0'; d++) {
-
3662 if (*static_str == *d) {
-
3663 delim = 1;
-
3664 break;
-
3665 }
-
3666 }
-
3667 if (!delim)
-
3668 break;
-
3669 static_str++;
-
3670 }
-
3671
-
3672 if (*static_str == '\0')
-
3673 return NULL;
-
3674
-
3675 char* token_start = static_str;
-
3676 while (*static_str != '\0') {
-
3677 int delim = 0;
-
3678 for (const char* d = delimStr; *d != '\0'; d++) {
-
3679 if (*static_str == *d) {
-
3680 delim = 1;
-
3681 break;
-
3682 }
-
3683 }
-
3684
-
3685 if (delim) {
-
3686 *static_str = '\0';
-
3687 static_str++;
-
3688 break;
-
3689 }
-
3690 static_str++;
-
3691 }
-
3692
-
3693 return token_start;
-
3694}
-
3695int xAxis = 0, yAxis = 0;
-
3696
- -
3698 RGFW_ASSERT(win != NULL);
-
3699
-
3700 if (win->event.type == 0)
-
3701 RGFW_resetKey();
-
3702
-
3703 if (win->event.type == RGFW_quit) {
-
3704 return NULL;
-
3705 }
-
3706
-
3707 win->event.type = 0;
-
3708
-
3709 #if defined(__linux__) && !defined(RGFW_NO_LINUX)
-
3710 if (RGFW_linux_updateGamepad(win)) return &win->event;
-
3711 #endif
-
3712 RGFW_GOTO_WAYLAND(0);
-
3713#ifdef RGFW_X11
-
3714 XPending(win->src.display);
-
3715
-
3716 XEvent E;
-
3718 /* if there is no unread qued events, get a new one */
-
3719 if ((QLength(win->src.display) || XEventsQueued(win->src.display, QueuedAlready) + XEventsQueued(win->src.display, QueuedAfterReading))
-
3720 && win->event.type != RGFW_quit
-
3721 )
-
3722 XNextEvent(win->src.display, &E);
-
3723 else {
-
3724 return NULL;
-
3725 }
-
3726
-
3727 win->event.type = 0;
-
3728
-
3729 /* xdnd data */
-
3730 Window source = 0;
-
3731 long version = 0;
-
3732 i32 format = 0;
-
3733
-
3734 XEvent reply = { ClientMessage };
-
3735
-
3736 switch (E.type) {
-
3737 case KeyPress:
-
3738 case KeyRelease: {
-
3739 win->event.repeat = RGFW_FALSE;
-
3740 /* check if it's a real key release */
-
3741 if (E.type == KeyRelease && XEventsQueued(win->src.display, QueuedAfterReading)) { /* get next event if there is one*/
-
3742 XEvent NE;
-
3743 XPeekEvent(win->src.display, &NE);
-
3744
-
3745 if (E.xkey.time == NE.xkey.time && E.xkey.keycode == NE.xkey.keycode) /* check if the current and next are both the same*/
-
3746 win->event.repeat = RGFW_TRUE;
-
3747 }
-
3748
-
3749 /* set event key data */
-
3750 win->event.key = RGFW_apiKeyToRGFW(E.xkey.keycode);
-
3751
-
3752 KeySym sym = (KeySym)XkbKeycodeToKeysym(win->src.display, E.xkey.keycode, 0, E.xkey.state & ShiftMask ? 1 : 0);
+
3646 i32 x, y;
+
3647 u32 z;
+
3648 Window window1, window2;
+
3649 XQueryPointer(win->src.display, win->src.window, &window1, &window2, &x, &y, &RGFWMouse.x, &RGFWMouse.y, &z);
+
3650
+
3651 return RGFWMouse;
+
3652}
+
3653
+
3654char* RGFW_strtok(char* str, const char* delimStr) {
+
3655 static char* static_str = NULL;
+
3656
+
3657 if (str != NULL)
+
3658 static_str = str;
+
3659
+
3660 if (static_str == NULL) {
+
3661 return NULL;
+
3662 }
+
3663
+
3664 while (*static_str != '\0') {
+
3665 b8 delim = 0;
+
3666 for (const char* d = delimStr; *d != '\0'; d++) {
+
3667 if (*static_str == *d) {
+
3668 delim = 1;
+
3669 break;
+
3670 }
+
3671 }
+
3672 if (!delim)
+
3673 break;
+
3674 static_str++;
+
3675 }
+
3676
+
3677 if (*static_str == '\0')
+
3678 return NULL;
+
3679
+
3680 char* token_start = static_str;
+
3681 while (*static_str != '\0') {
+
3682 int delim = 0;
+
3683 for (const char* d = delimStr; *d != '\0'; d++) {
+
3684 if (*static_str == *d) {
+
3685 delim = 1;
+
3686 break;
+
3687 }
+
3688 }
+
3689
+
3690 if (delim) {
+
3691 *static_str = '\0';
+
3692 static_str++;
+
3693 break;
+
3694 }
+
3695 static_str++;
+
3696 }
+
3697
+
3698 return token_start;
+
3699}
+
3700int xAxis = 0, yAxis = 0;
+
3701
+ +
3703 RGFW_ASSERT(win != NULL);
+
3704
+
3705 if (win->event.type == 0)
+
3706 RGFW_resetKey();
+
3707
+
3708 if (win->event.type == RGFW_quit) {
+
3709 return NULL;
+
3710 }
+
3711
+
3712 win->event.type = 0;
+
3713
+
3714 #if defined(__linux__) && !defined(RGFW_NO_LINUX)
+
3715 if (RGFW_linux_updateGamepad(win)) return &win->event;
+
3716 #endif
+
3717 RGFW_GOTO_WAYLAND(0);
+
3718#ifdef RGFW_X11
+
3719 XPending(win->src.display);
+
3720
+
3721 XEvent E;
+
3723 /* if there is no unread qued events, get a new one */
+
3724 if ((QLength(win->src.display) || XEventsQueued(win->src.display, QueuedAlready) + XEventsQueued(win->src.display, QueuedAfterReading))
+
3725 && win->event.type != RGFW_quit
+
3726 )
+
3727 XNextEvent(win->src.display, &E);
+
3728 else {
+
3729 return NULL;
+
3730 }
+
3731
+
3732 win->event.type = 0;
+
3733
+
3734 /* xdnd data */
+
3735 Window source = 0;
+
3736 long version = 0;
+
3737 i32 format = 0;
+
3738
+
3739 XEvent reply = { ClientMessage };
+
3740
+
3741 switch (E.type) {
+
3742 case KeyPress:
+
3743 case KeyRelease: {
+
3744 win->event.repeat = RGFW_FALSE;
+
3745 /* check if it's a real key release */
+
3746 if (E.type == KeyRelease && XEventsQueued(win->src.display, QueuedAfterReading)) { /* get next event if there is one*/
+
3747 XEvent NE;
+
3748 XPeekEvent(win->src.display, &NE);
+
3749
+
3750 if (E.xkey.time == NE.xkey.time && E.xkey.keycode == NE.xkey.keycode) /* check if the current and next are both the same*/
+
3751 win->event.repeat = RGFW_TRUE;
+
3752 }
3753
-
3754 if ((E.xkey.state & LockMask) && sym >= XK_a && sym <= XK_z)
-
3755 sym = (E.xkey.state & ShiftMask) ? sym + 32 : sym - 32;
-
3756 if ((u8)sym != (u32)sym)
-
3757 sym = 0;
+
3754 /* set event key data */
+
3755 win->event.key = RGFW_apiKeyToRGFW(E.xkey.keycode);
+
3756
+
3757 KeySym sym = (KeySym)XkbKeycodeToKeysym(win->src.display, E.xkey.keycode, 0, E.xkey.state & ShiftMask ? 1 : 0);
3758
-
3759 win->event.keyChar = (u8)sym;
-
3760
-
3761 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
-
3762
-
3763 /* get keystate data */
-
3764 win->event.type = (E.type == KeyPress) ? RGFW_keyPressed : RGFW_keyReleased;
+
3759 if ((E.xkey.state & LockMask) && sym >= XK_a && sym <= XK_z)
+
3760 sym = (E.xkey.state & ShiftMask) ? sym + 32 : sym - 32;
+
3761 if ((u8)sym != (u32)sym)
+
3762 sym = 0;
+
3763
+
3764 win->event.keyChar = (u8)sym;
3765
-
3766 XKeyboardState keystate;
-
3767 XGetKeyboardControl(win->src.display, &keystate);
-
3768
-
3769 RGFW_keyboard[win->event.key].current = (E.type == KeyPress);
-
3770 RGFW_updateKeyMods(win, (keystate.led_mask & 1), (keystate.led_mask & 2));
-
3771 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, (E.type == KeyPress));
-
3772 break;
-
3773 }
-
3774 case ButtonPress:
-
3775 case ButtonRelease:
-
3776 win->event.type = RGFW_mouseButtonPressed + (E.type == ButtonRelease); // the events match
-
3777
-
3778 win->event.button = E.xbutton.button;
-
3779 switch(win->event.button) {
-
3780 case RGFW_mouseScrollUp:
-
3781 win->event.scroll = 1;
-
3782 break;
-
3783 case RGFW_mouseScrollDown:
-
3784 win->event.scroll = -1;
-
3785 break;
-
3786 default: break;
-
3787 }
-
3788
-
3789 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
3790
-
3791 if (win->event.repeat == RGFW_FALSE)
-
3792 win->event.repeat = RGFW_isPressed(win, win->event.key);
+
3766 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
+
3767
+
3768 /* get keystate data */
+
3769 win->event.type = (E.type == KeyPress) ? RGFW_keyPressed : RGFW_keyReleased;
+
3770
+
3771 XKeyboardState keystate;
+
3772 XGetKeyboardControl(win->src.display, &keystate);
+
3773
+
3774 RGFW_keyboard[win->event.key].current = (E.type == KeyPress);
+
3775 RGFW_updateKeyMods(win, (keystate.led_mask & 1), (keystate.led_mask & 2));
+
3776 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, (E.type == KeyPress));
+
3777 break;
+
3778 }
+
3779 case ButtonPress:
+
3780 case ButtonRelease:
+
3781 win->event.type = RGFW_mouseButtonPressed + (E.type == ButtonRelease); // the events match
+
3782
+
3783 win->event.button = E.xbutton.button;
+
3784 switch(win->event.button) {
+
3785 case RGFW_mouseScrollUp:
+
3786 win->event.scroll = 1;
+
3787 break;
+
3788 case RGFW_mouseScrollDown:
+
3789 win->event.scroll = -1;
+
3790 break;
+
3791 default: break;
+
3792 }
3793
-
3794 RGFW_mouseButtons[win->event.button].current = (E.type == ButtonPress);
-
3795 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, (E.type == ButtonPress));
-
3796 break;
-
3797
-
3798 case MotionNotify:
-
3799 win->event.point.x = E.xmotion.x;
-
3800 win->event.point.y = E.xmotion.y;
-
3801
-
3802 if ((win->_flags & RGFW_HOLD_MOUSE)) {
-
3803 win->event.point.y = E.xmotion.y;
-
3804
-
3805 win->event.point.x = win->event.point.x - win->_lastMousePoint.x;
-
3806 win->event.point.y = win->event.point.y - win->_lastMousePoint.y;
-
3807 }
-
3808
-
3809 win->_lastMousePoint = RGFW_POINT(E.xmotion.x, E.xmotion.y);
-
3810
-
3811 win->event.type = RGFW_mousePosChanged;
-
3812 RGFW_mousePosCallback(win, win->event.point);
-
3813 break;
-
3814
-
3815 case GenericEvent: {
-
3816 /* MotionNotify is used for mouse events if the mouse isn't held */
-
3817 if (!(win->_flags & RGFW_HOLD_MOUSE)) {
-
3818 XFreeEventData(win->src.display, &E.xcookie);
-
3819 break;
-
3820 }
-
3821
-
3822 XGetEventData(win->src.display, &E.xcookie);
-
3823 if (E.xcookie.evtype == XI_RawMotion) {
-
3824 XIRawEvent *raw = (XIRawEvent *)E.xcookie.data;
-
3825 if (raw->valuators.mask_len == 0) {
-
3826 XFreeEventData(win->src.display, &E.xcookie);
-
3827 break;
-
3828 }
-
3829
-
3830 double deltaX = 0.0f;
-
3831 double deltaY = 0.0f;
-
3832
-
3833 /* check if relative motion data exists where we think it does */
-
3834 if (XIMaskIsSet(raw->valuators.mask, 0) != 0)
-
3835 deltaX += raw->raw_values[0];
-
3836 if (XIMaskIsSet(raw->valuators.mask, 1) != 0)
-
3837 deltaY += raw->raw_values[1];
-
3838
-
3839 win->event.point = RGFW_POINT((i32)deltaX, (i32)deltaY);
-
3840
-
3841 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2)));
-
3842
-
3843 win->event.type = RGFW_mousePosChanged;
-
3844 RGFW_mousePosCallback(win, win->event.point);
-
3845 }
-
3846
-
3847 XFreeEventData(win->src.display, &E.xcookie);
-
3848 break;
-
3849 }
-
3850
-
3851 case Expose:
-
3852 win->event.type = RGFW_windowRefresh;
-
3853 RGFW_windowRefreshCallback(win);
-
3854 break;
+
3794 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
3795
+
3796 if (win->event.repeat == RGFW_FALSE)
+
3797 win->event.repeat = RGFW_isPressed(win, win->event.key);
+
3798
+
3799 RGFW_mouseButtons[win->event.button].current = (E.type == ButtonPress);
+
3800 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, (E.type == ButtonPress));
+
3801 break;
+
3802
+
3803 case MotionNotify:
+
3804 win->event.point.x = E.xmotion.x;
+
3805 win->event.point.y = E.xmotion.y;
+
3806
+
3807 if ((win->_flags & RGFW_HOLD_MOUSE)) {
+
3808 win->event.point.y = E.xmotion.y;
+
3809
+
3810 win->event.point.x = win->event.point.x - win->_lastMousePoint.x;
+
3811 win->event.point.y = win->event.point.y - win->_lastMousePoint.y;
+
3812 }
+
3813
+
3814 win->_lastMousePoint = RGFW_POINT(E.xmotion.x, E.xmotion.y);
+
3815
+
3816 win->event.type = RGFW_mousePosChanged;
+
3817 RGFW_mousePosCallback(win, win->event.point);
+
3818 break;
+
3819
+
3820 case GenericEvent: {
+
3821 /* MotionNotify is used for mouse events if the mouse isn't held */
+
3822 if (!(win->_flags & RGFW_HOLD_MOUSE)) {
+
3823 XFreeEventData(win->src.display, &E.xcookie);
+
3824 break;
+
3825 }
+
3826
+
3827 XGetEventData(win->src.display, &E.xcookie);
+
3828 if (E.xcookie.evtype == XI_RawMotion) {
+
3829 XIRawEvent *raw = (XIRawEvent *)E.xcookie.data;
+
3830 if (raw->valuators.mask_len == 0) {
+
3831 XFreeEventData(win->src.display, &E.xcookie);
+
3832 break;
+
3833 }
+
3834
+
3835 double deltaX = 0.0f;
+
3836 double deltaY = 0.0f;
+
3837
+
3838 /* check if relative motion data exists where we think it does */
+
3839 if (XIMaskIsSet(raw->valuators.mask, 0) != 0)
+
3840 deltaX += raw->raw_values[0];
+
3841 if (XIMaskIsSet(raw->valuators.mask, 1) != 0)
+
3842 deltaY += raw->raw_values[1];
+
3843
+
3844 win->event.point = RGFW_POINT((i32)deltaX, (i32)deltaY);
+
3845
+
3846 RGFW_window_moveMouse(win, RGFW_POINT(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2)));
+
3847
+
3848 win->event.type = RGFW_mousePosChanged;
+
3849 RGFW_mousePosCallback(win, win->event.point);
+
3850 }
+
3851
+
3852 XFreeEventData(win->src.display, &E.xcookie);
+
3853 break;
+
3854 }
3855
-
3856 case ClientMessage: {
-
3857 /* if the client closed the window*/
-
3858 if (E.xclient.data.l[0] == (long)wm_delete_window) {
-
3859 win->event.type = RGFW_quit;
-
3860 RGFW_windowQuitCallback(win);
-
3861 break;
-
3862 }
-
3863
-
3864 for (size_t i = 0; i < win->event.droppedFilesCount; i++) {
-
3865 win->event.droppedFiles[i][0] = '\0';
-
3866 }
-
3867 win->event.droppedFilesCount = 0;
+
3856 case Expose:
+
3857 win->event.type = RGFW_windowRefresh;
+
3858 RGFW_windowRefreshCallback(win);
+
3859 break;
+
3860
+
3861 case ClientMessage: {
+
3862 /* if the client closed the window*/
+
3863 if (E.xclient.data.l[0] == (long)wm_delete_window) {
+
3864 win->event.type = RGFW_quit;
+
3865 RGFW_windowQuitCallback(win);
+
3866 break;
+
3867 }
3868
-
3869 if ((win->_flags & RGFW_windowAllowDND) == 0)
-
3870 break;
-
3871
-
3872 reply.xclient.window = source;
-
3873 reply.xclient.format = 32;
-
3874 reply.xclient.data.l[0] = (long)win->src.window;
-
3875 reply.xclient.data.l[1] = 0;
-
3876 reply.xclient.data.l[2] = None;
-
3877
-
3878 if (E.xclient.message_type == XdndEnter) {
-
3879 if (version > 5)
-
3880 break;
-
3881
-
3882 unsigned long count;
-
3883 Atom* formats;
-
3884 Atom real_formats[6];
-
3885 Bool list = E.xclient.data.l[1] & 1;
+
3869 for (size_t i = 0; i < win->event.droppedFilesCount; i++) {
+
3870 win->event.droppedFiles[i][0] = '\0';
+
3871 }
+
3872 win->event.droppedFilesCount = 0;
+
3873
+
3874 if ((win->_flags & RGFW_windowAllowDND) == 0)
+
3875 break;
+
3876
+
3877 reply.xclient.window = source;
+
3878 reply.xclient.format = 32;
+
3879 reply.xclient.data.l[0] = (long)win->src.window;
+
3880 reply.xclient.data.l[1] = 0;
+
3881 reply.xclient.data.l[2] = None;
+
3882
+
3883 if (E.xclient.message_type == XdndEnter) {
+
3884 if (version > 5)
+
3885 break;
3886
-
3887 source = E.xclient.data.l[0];
-
3888 version = E.xclient.data.l[1] >> 24;
-
3889 format = None;
-
3890
-
3891 if (list) {
-
3892 Atom actualType;
-
3893 i32 actualFormat;
-
3894 unsigned long bytesAfter;
+
3887 unsigned long count;
+
3888 Atom* formats;
+
3889 Atom real_formats[6];
+
3890 Bool list = E.xclient.data.l[1] & 1;
+
3891
+
3892 source = E.xclient.data.l[0];
+
3893 version = E.xclient.data.l[1] >> 24;
+
3894 format = None;
3895
- -
3897 win->src.display, source, XdndTypeList,
-
3898 0, LONG_MAX, False, 4,
-
3899 &actualType, &actualFormat, &count, &bytesAfter, (u8**)&formats
-
3900 );
-
3901 } else {
-
3902 count = 0;
-
3903
-
3904 for (size_t i = 2; i < 5; i++) {
-
3905 Window format = E.xclient.data.l[i];
-
3906 if (format != None) {
-
3907 real_formats[count] = format;
-
3908 count += 1;
-
3909 }
-
3910 }
-
3911
-
3912 formats = real_formats;
-
3913 }
-
3914
-
3915 for (size_t i = 0; i < count; i++) {
-
3916 if (formats[i] == XtextUriList || formats[i] == XtextPlain) {
-
3917 format = (int)formats[i];
-
3918 break;
-
3919 }
-
3920 }
-
3921
-
3922 if (list) {
-
3923 XFree(formats);
-
3924 }
-
3925
-
3926 break;
-
3927 }
-
3928
-
3929 if (E.xclient.message_type == XdndPosition) {
-
3930 const i32 xabs = (E.xclient.data.l[2] >> 16) & 0xffff;
-
3931 const i32 yabs = (E.xclient.data.l[2]) & 0xffff;
-
3932 Window dummy;
-
3933 i32 xpos, ypos;
-
3934
-
3935 if (version > 5)
-
3936 break;
-
3937
- -
3939 win->src.display, XDefaultRootWindow(win->src.display), win->src.window,
-
3940 xabs, yabs, &xpos, &ypos, &dummy
-
3941 );
+
3896 if (list) {
+
3897 Atom actualType;
+
3898 i32 actualFormat;
+
3899 unsigned long bytesAfter;
+
3900
+ +
3902 win->src.display, source, XdndTypeList,
+
3903 0, LONG_MAX, False, 4,
+
3904 &actualType, &actualFormat, &count, &bytesAfter, (u8**)&formats
+
3905 );
+
3906 } else {
+
3907 count = 0;
+
3908
+
3909 for (size_t i = 2; i < 5; i++) {
+
3910 Window format = E.xclient.data.l[i];
+
3911 if (format != None) {
+
3912 real_formats[count] = format;
+
3913 count += 1;
+
3914 }
+
3915 }
+
3916
+
3917 formats = real_formats;
+
3918 }
+
3919
+
3920 for (size_t i = 0; i < count; i++) {
+
3921 if (formats[i] == XtextUriList || formats[i] == XtextPlain) {
+
3922 format = (int)formats[i];
+
3923 break;
+
3924 }
+
3925 }
+
3926
+
3927 if (list) {
+
3928 XFree(formats);
+
3929 }
+
3930
+
3931 break;
+
3932 }
+
3933
+
3934 if (E.xclient.message_type == XdndPosition) {
+
3935 const i32 xabs = (E.xclient.data.l[2] >> 16) & 0xffff;
+
3936 const i32 yabs = (E.xclient.data.l[2]) & 0xffff;
+
3937 Window dummy;
+
3938 i32 xpos, ypos;
+
3939
+
3940 if (version > 5)
+
3941 break;
3942
-
3943 win->event.point.x = xpos;
-
3944 win->event.point.y = ypos;
-
3945
-
3946 reply.xclient.window = source;
-
3947 reply.xclient.message_type = XdndStatus;
-
3948
-
3949 if (format) {
-
3950 reply.xclient.data.l[1] = 1;
-
3951 if (version >= 2)
-
3952 reply.xclient.data.l[4] = (long)XdndActionCopy;
-
3953 }
-
3954
-
3955 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
-
3956 XFlush(win->src.display);
-
3957 break;
-
3958 }
+ +
3944 win->src.display, XDefaultRootWindow(win->src.display), win->src.window,
+
3945 xabs, yabs, &xpos, &ypos, &dummy
+
3946 );
+
3947
+
3948 win->event.point.x = xpos;
+
3949 win->event.point.y = ypos;
+
3950
+
3951 reply.xclient.window = source;
+
3952 reply.xclient.message_type = XdndStatus;
+
3953
+
3954 if (format) {
+
3955 reply.xclient.data.l[1] = 1;
+
3956 if (version >= 2)
+
3957 reply.xclient.data.l[4] = (long)XdndActionCopy;
+
3958 }
3959
-
3960 if (E.xclient.message_type != XdndDrop)
-
3961 break;
-
3962
-
3963 if (version > 5)
-
3964 break;
-
3965
-
3966 win->event.type = RGFW_DNDInit;
+
3960 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
+
3961 XFlush(win->src.display);
+
3962 break;
+
3963 }
+
3964
+
3965 if (E.xclient.message_type != XdndDrop)
+
3966 break;
3967
-
3968 if (format) {
-
3969 Time time = (version >= 1)
-
3970 ? (Time)E.xclient.data.l[2]
-
3971 : CurrentTime;
+
3968 if (version > 5)
+
3969 break;
+
3970
+
3971 win->event.type = RGFW_DNDInit;
3972
- -
3974 win->src.display, XdndSelection, (Atom)format,
-
3975 XdndSelection, win->src.window, time
-
3976 );
-
3977 } else if (version >= 2) {
-
3978 XEvent reply = { ClientMessage };
-
3979
-
3980 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
-
3981 XFlush(win->src.display);
-
3982 }
-
3983
-
3984 RGFW_dndInitCallback(win, win->event.point);
-
3985 } break;
-
3986 case SelectionNotify: {
-
3987 /* this is only for checking for xdnd drops */
-
3988 if (E.xselection.property != XdndSelection || !(win->_flags & RGFW_windowAllowDND))
-
3989 break;
-
3990
-
3991 char* data;
-
3992 unsigned long result;
-
3993
-
3994 Atom actualType;
-
3995 i32 actualFormat;
-
3996 unsigned long bytesAfter;
-
3997
-
3998 XGetWindowProperty(win->src.display, E.xselection.requestor, E.xselection.property, 0, LONG_MAX, False, E.xselection.target, &actualType, &actualFormat, &result, &bytesAfter, (u8**) &data);
-
3999
-
4000 if (result == 0)
-
4001 break;
-
4002
-
4003 const char* prefix = (const char*)"file://";
+
3973 if (format) {
+
3974 Time time = (version >= 1)
+
3975 ? (Time)E.xclient.data.l[2]
+
3976 : CurrentTime;
+
3977
+ +
3979 win->src.display, XdndSelection, (Atom)format,
+
3980 XdndSelection, win->src.window, time
+
3981 );
+
3982 } else if (version >= 2) {
+
3983 XEvent reply = { ClientMessage };
+
3984
+
3985 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
+
3986 XFlush(win->src.display);
+
3987 }
+
3988
+
3989 RGFW_dndInitCallback(win, win->event.point);
+
3990 } break;
+
3991 case SelectionNotify: {
+
3992 /* this is only for checking for xdnd drops */
+
3993 if (E.xselection.property != XdndSelection || !(win->_flags & RGFW_windowAllowDND))
+
3994 break;
+
3995
+
3996 char* data;
+
3997 unsigned long result;
+
3998
+
3999 Atom actualType;
+
4000 i32 actualFormat;
+
4001 unsigned long bytesAfter;
+
4002
+
4003 XGetWindowProperty(win->src.display, E.xselection.requestor, E.xselection.property, 0, LONG_MAX, False, E.xselection.target, &actualType, &actualFormat, &result, &bytesAfter, (u8**) &data);
4004
-
4005 char* line;
-
4006
-
4007 win->event.droppedFilesCount = 0;
-
4008
-
4009 win->event.type = RGFW_DND;
-
4010
-
4011 while ((line = (char*)RGFW_strtok(data, "\r\n"))) {
-
4012 char path[RGFW_MAX_PATH];
+
4005 if (result == 0)
+
4006 break;
+
4007
+
4008 const char* prefix = (const char*)"file://";
+
4009
+
4010 char* line;
+
4011
+
4012 win->event.droppedFilesCount = 0;
4013
-
4014 data = NULL;
+
4014 win->event.type = RGFW_DND;
4015
-
4016 if (line[0] == '#')
-
4017 continue;
+
4016 while ((line = (char*)RGFW_strtok(data, "\r\n"))) {
+
4017 char path[RGFW_MAX_PATH];
4018
-
4019 char* l;
-
4020 for (l = line; 1; l++) {
-
4021 if ((l - line) > 7)
-
4022 break;
-
4023 else if (*l != prefix[(l - line)])
-
4024 break;
-
4025 else if (*l == '\0' && prefix[(l - line)] == '\0') {
-
4026 line += 7;
-
4027 while (*line != '/')
-
4028 line++;
+
4019 data = NULL;
+
4020
+
4021 if (line[0] == '#')
+
4022 continue;
+
4023
+
4024 char* l;
+
4025 for (l = line; 1; l++) {
+
4026 if ((l - line) > 7)
+
4027 break;
+
4028 else if (*l != prefix[(l - line)])
4029 break;
-
4030 } else if (*l == '\0')
-
4031 break;
-
4032 }
-
4033
-
4034 win->event.droppedFilesCount++;
-
4035
-
4036 size_t index = 0;
-
4037 while (*line) {
-
4038 if (line[0] == '%' && line[1] && line[2]) {
-
4039 const char digits[3] = { line[1], line[2], '\0' };
-
4040 path[index] = (char) RGFW_STRTOL(digits, NULL, 16);
-
4041 line += 2;
-
4042 } else
-
4043 path[index] = *line;
-
4044
-
4045 index++;
-
4046 line++;
-
4047 }
-
4048 path[index] = '\0';
-
4049 RGFW_MEMCPY(win->event.droppedFiles[win->event.droppedFilesCount - 1], path, index + 1);
-
4050 }
-
4051
-
4052 if (data)
-
4053 XFree(data);
-
4054
-
4055 if (version >= 2) {
-
4056 XEvent reply = { ClientMessage };
-
4057 reply.xclient.format = 32;
-
4058 reply.xclient.message_type = XdndFinished;
-
4059 reply.xclient.data.l[1] = result;
-
4060 reply.xclient.data.l[2] = XdndActionCopy;
-
4061
-
4062 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
-
4063 XFlush(win->src.display);
-
4064 }
-
4065
-
4066 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
-
4067 break;
-
4068 }
-
4069 case FocusIn:
-
4070 win->event.inFocus = 1;
-
4071 win->event.type = RGFW_focusIn;
-
4072 RGFW_focusCallback(win, 1);
-
4073 break;
-
4074 case FocusOut:
-
4075 win->event.inFocus = 0;
-
4076 win->event.type = RGFW_focusOut;
-
4077 RGFW_focusCallback(win, 0);
+
4030 else if (*l == '\0' && prefix[(l - line)] == '\0') {
+
4031 line += 7;
+
4032 while (*line != '/')
+
4033 line++;
+
4034 break;
+
4035 } else if (*l == '\0')
+
4036 break;
+
4037 }
+
4038
+
4039 win->event.droppedFilesCount++;
+
4040
+
4041 size_t index = 0;
+
4042 while (*line) {
+
4043 if (line[0] == '%' && line[1] && line[2]) {
+
4044 const char digits[3] = { line[1], line[2], '\0' };
+
4045 path[index] = (char) RGFW_STRTOL(digits, NULL, 16);
+
4046 line += 2;
+
4047 } else
+
4048 path[index] = *line;
+
4049
+
4050 index++;
+
4051 line++;
+
4052 }
+
4053 path[index] = '\0';
+
4054 RGFW_MEMCPY(win->event.droppedFiles[win->event.droppedFilesCount - 1], path, index + 1);
+
4055 }
+
4056
+
4057 if (data)
+
4058 XFree(data);
+
4059
+
4060 if (version >= 2) {
+
4061 XEvent reply = { ClientMessage };
+
4062 reply.xclient.format = 32;
+
4063 reply.xclient.message_type = XdndFinished;
+
4064 reply.xclient.data.l[1] = result;
+
4065 reply.xclient.data.l[2] = XdndActionCopy;
+
4066
+
4067 XSendEvent(win->src.display, source, False, NoEventMask, &reply);
+
4068 XFlush(win->src.display);
+
4069 }
+
4070
+
4071 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
+
4072 break;
+
4073 }
+
4074 case FocusIn:
+
4075 win->event.inFocus = 1;
+
4076 win->event.type = RGFW_focusIn;
+
4077 RGFW_focusCallback(win, 1);
4078 break;
-
4079 case EnterNotify: {
-
4080 win->event.type = RGFW_mouseEnter;
-
4081 win->event.point.x = E.xcrossing.x;
-
4082 win->event.point.y = E.xcrossing.y;
-
4083 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
-
4084 break;
-
4085 }
-
4086
-
4087 case LeaveNotify: {
-
4088 win->event.type = RGFW_mouseLeave;
-
4089 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
-
4090 break;
-
4091 }
-
4092
-
4093 case ConfigureNotify: {
-
4094 /* detect resize */
-
4095 if (E.xconfigure.width != win->r.w || E.xconfigure.height != win->r.h) {
-
4096 win->event.type = RGFW_windowResized;
-
4097 win->r = RGFW_RECT(win->r.x, win->r.y, E.xconfigure.width, E.xconfigure.height);
-
4098 RGFW_windowResizeCallback(win, win->r);
-
4099 break;
-
4100 }
-
4101
-
4102 /* detect move */
-
4103 if (E.xconfigure.x != win->r.x || E.xconfigure.y != win->r.y) {
-
4104 win->event.type = RGFW_windowMoved;
-
4105 win->r = RGFW_RECT(E.xconfigure.x, E.xconfigure.y, win->r.w, win->r.h);
-
4106 RGFW_windowMoveCallback(win, win->r);
-
4107 break;
-
4108 }
-
4109
-
4110 break;
-
4111 }
-
4112 default:
-
4113 XFlush(win->src.display);
-
4114 return RGFW_window_checkEvent(win);
-
4115 }
-
4116
-
4117 XFlush(win->src.display);
-
4118 if (win->event.type) return &win->event;
-
4119 else return NULL;
-
4120#endif
-
4121#ifdef RGFW_WAYLAND
-
4122 wayland:
-
4123 if (win->_flags & RGFW_windowHide)
-
4124 return NULL;
-
4125
-
4126 if (win->src.eventIndex == 0) {
-
4127 if (wl_display_roundtrip(win->src.wl_display) == -1) {
-
4128 return NULL;
-
4129 }
-
4130 }
-
4131
-
4132 if (win->src.eventLen == 0) {
+
4079 case FocusOut:
+
4080 win->event.inFocus = 0;
+
4081 win->event.type = RGFW_focusOut;
+
4082 RGFW_focusCallback(win, 0);
+
4083 break;
+
4084 case EnterNotify: {
+
4085 win->event.type = RGFW_mouseEnter;
+
4086 win->event.point.x = E.xcrossing.x;
+
4087 win->event.point.y = E.xcrossing.y;
+
4088 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
+
4089 break;
+
4090 }
+
4091
+
4092 case LeaveNotify: {
+
4093 win->event.type = RGFW_mouseLeave;
+
4094 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
+
4095 break;
+
4096 }
+
4097
+
4098 case ConfigureNotify: {
+
4099 /* detect resize */
+
4100 if (E.xconfigure.width != win->r.w || E.xconfigure.height != win->r.h) {
+
4101 win->event.type = RGFW_windowResized;
+
4102 win->r = RGFW_RECT(win->r.x, win->r.y, E.xconfigure.width, E.xconfigure.height);
+
4103 RGFW_windowResizeCallback(win, win->r);
+
4104 break;
+
4105 }
+
4106
+
4107 /* detect move */
+
4108 if (E.xconfigure.x != win->r.x || E.xconfigure.y != win->r.y) {
+
4109 win->event.type = RGFW_windowMoved;
+
4110 win->r = RGFW_RECT(E.xconfigure.x, E.xconfigure.y, win->r.w, win->r.h);
+
4111 RGFW_windowMoveCallback(win, win->r);
+
4112 break;
+
4113 }
+
4114
+
4115 break;
+
4116 }
+
4117 default:
+
4118 XFlush(win->src.display);
+
4119 return RGFW_window_checkEvent(win);
+
4120 }
+
4121
+
4122 XFlush(win->src.display);
+
4123 if (win->event.type) return &win->event;
+
4124 else return NULL;
+
4125#endif
+
4126#ifdef RGFW_WAYLAND
+
4127 wayland:
+
4128 if (win->_flags & RGFW_windowHide)
+
4129 return NULL;
+
4130
+
4131 if (win->src.eventIndex == 0) {
+
4132 if (wl_display_roundtrip(win->src.wl_display) == -1) {
4133 return NULL;
-
4134 }
-
4135
-
4136 RGFW_event ev = RGFW_eventPipe_pop(win);
-
4137
-
4138 if (ev.type == 0 || win->event.type == RGFW_quit) {
-
4139 return NULL;
-
4140 }
-
4141
-
4142 ev.frameTime = win->event.frameTime;
-
4143 ev.frameTime2 = win->event.frameTime2;
-
4144 ev.inFocus = win->event.inFocus;
-
4145 win->event = ev;
-
4146 if (win->event.type) return &win->event;
-
4147 else return NULL;
-
4148#endif
-
4149}
-
4150
- -
4152 RGFW_ASSERT(win != NULL);
-
4153 win->r.x = v.x;
-
4154 win->r.y = v.y;
-
4155 RGFW_GOTO_WAYLAND(0);
-
4156#ifdef RGFW_X11
-
4157 XMoveWindow(win->src.display, win->src.window, v.x, v.y);
-
4158#endif
-
4159#ifdef RGFW_WAYLAND
-
4160 wayland:
-
4161 RGFW_ASSERT(win != NULL);
-
4162
-
4163 if (win->src.compositor) {
-
4164 struct wl_pointer *pointer = wl_seat_get_pointer(win->src.seat);
-
4165 if (!pointer) {
-
4166 return;
-
4167 }
-
4168
-
4169 wl_display_flush(win->src.wl_display);
-
4170 }
-
4171#endif
-
4172}
-
4173
-
4174
- -
4176 RGFW_ASSERT(win != NULL);
-
4177 win->r.w = a.w;
-
4178 win->r.h = a.h;
-
4179 RGFW_GOTO_WAYLAND(0);
-
4180#ifdef RGFW_X11
-
4181 XResizeWindow(win->src.display, win->src.window, a.w, a.h);
-
4182
-
4183 if (!(win->_flags & RGFW_windowNoResize))
-
4184 return;
-
4185
-
4186 XSizeHints sh;
-
4187 sh.flags = (1L << 4) | (1L << 5);
-
4188 sh.min_width = sh.max_width = a.w;
-
4189 sh.min_height = sh.max_height = a.h;
-
4190
-
4191 XSetWMSizeHints(win->src.display, (Drawable) win->src.window, &sh, XA_WM_NORMAL_HINTS);
-
4192#endif
-
4193#ifdef RGFW_WAYLAND
-
4194 wayland:
-
4195 if (win->src.compositor) {
-
4196 xdg_surface_set_window_geometry(win->src.xdg_surface, 0, 0, win->r.w, win->r.h);
-
4197 #ifdef RGFW_OPENGL
-
4198 wl_egl_window_resize(win->src.eglWindow, a.w, a.h, 0, 0);
-
4199 #endif
-
4200 }
-
4201#endif
-
4202}
-
4203
- -
4205 RGFW_ASSERT(win != NULL);
-
4206
-
4207 if (a.w == 0 && a.h == 0)
-
4208 return;
-
4209
-
4210 XSizeHints hints;
-
4211 long flags;
-
4212
-
4213 XGetWMNormalHints(win->src.display, win->src.window, &hints, &flags);
+
4134 }
+
4135 }
+
4136
+
4137 if (win->src.eventLen == 0) {
+
4138 return NULL;
+
4139 }
+
4140
+
4141 RGFW_event ev = RGFW_eventPipe_pop(win);
+
4142
+
4143 if (ev.type == 0 || win->event.type == RGFW_quit) {
+
4144 return NULL;
+
4145 }
+
4146
+
4147 ev.frameTime = win->event.frameTime;
+
4148 ev.frameTime2 = win->event.frameTime2;
+
4149 ev.inFocus = win->event.inFocus;
+
4150 win->event = ev;
+
4151 if (win->event.type) return &win->event;
+
4152 else return NULL;
+
4153#endif
+
4154}
+
4155
+ +
4157 RGFW_ASSERT(win != NULL);
+
4158 win->r.x = v.x;
+
4159 win->r.y = v.y;
+
4160 RGFW_GOTO_WAYLAND(0);
+
4161#ifdef RGFW_X11
+
4162 XMoveWindow(win->src.display, win->src.window, v.x, v.y);
+
4163#endif
+
4164#ifdef RGFW_WAYLAND
+
4165 wayland:
+
4166 RGFW_ASSERT(win != NULL);
+
4167
+
4168 if (win->src.compositor) {
+
4169 struct wl_pointer *pointer = wl_seat_get_pointer(win->src.seat);
+
4170 if (!pointer) {
+
4171 return;
+
4172 }
+
4173
+
4174 wl_display_flush(win->src.wl_display);
+
4175 }
+
4176#endif
+
4177}
+
4178
+
4179
+ +
4181 RGFW_ASSERT(win != NULL);
+
4182 win->r.w = a.w;
+
4183 win->r.h = a.h;
+
4184 RGFW_GOTO_WAYLAND(0);
+
4185#ifdef RGFW_X11
+
4186 XResizeWindow(win->src.display, win->src.window, a.w, a.h);
+
4187
+
4188 if (!(win->_flags & RGFW_windowNoResize))
+
4189 return;
+
4190
+
4191 XSizeHints sh;
+
4192 sh.flags = (1L << 4) | (1L << 5);
+
4193 sh.min_width = sh.max_width = a.w;
+
4194 sh.min_height = sh.max_height = a.h;
+
4195
+
4196 XSetWMSizeHints(win->src.display, (Drawable) win->src.window, &sh, XA_WM_NORMAL_HINTS);
+
4197#endif
+
4198#ifdef RGFW_WAYLAND
+
4199 wayland:
+
4200 if (win->src.compositor) {
+
4201 xdg_surface_set_window_geometry(win->src.xdg_surface, 0, 0, win->r.w, win->r.h);
+
4202 #ifdef RGFW_OPENGL
+
4203 wl_egl_window_resize(win->src.eglWindow, a.w, a.h, 0, 0);
+
4204 #endif
+
4205 }
+
4206#endif
+
4207}
+
4208
+ +
4210 RGFW_ASSERT(win != NULL);
+
4211
+
4212 if (a.w == 0 && a.h == 0)
+
4213 return;
4214
-
4215 hints.flags |= PMinSize;
-
4216
-
4217 hints.min_width = a.w;
-
4218 hints.min_height = a.h;
+
4215 XSizeHints hints;
+
4216 long flags;
+
4217
+
4218 XGetWMNormalHints(win->src.display, win->src.window, &hints, &flags);
4219
-
4220 XSetWMNormalHints(win->src.display, win->src.window, &hints);
-
4221}
-
4222
- -
4224 RGFW_ASSERT(win != NULL);
-
4225
-
4226 if (a.w == 0 && a.h == 0)
-
4227 return;
-
4228
-
4229 XSizeHints hints;
-
4230 long flags;
-
4231
-
4232 XGetWMNormalHints(win->src.display, win->src.window, &hints, &flags);
+
4220 hints.flags |= PMinSize;
+
4221
+
4222 hints.min_width = a.w;
+
4223 hints.min_height = a.h;
+
4224
+
4225 XSetWMNormalHints(win->src.display, win->src.window, &hints);
+
4226}
+
4227
+ +
4229 RGFW_ASSERT(win != NULL);
+
4230
+
4231 if (a.w == 0 && a.h == 0)
+
4232 return;
4233
-
4234 hints.flags |= PMaxSize;
-
4235
-
4236 hints.max_width = a.w;
-
4237 hints.max_height = a.h;
+
4234 XSizeHints hints;
+
4235 long flags;
+
4236
+
4237 XGetWMNormalHints(win->src.display, win->src.window, &hints, &flags);
4238
-
4239 XSetWMNormalHints(win->src.display, win->src.window, &hints);
-
4240}
-
4241
-
4242
- -
4244 RGFW_ASSERT(win != NULL);
-
4245
-
4246 XIconifyWindow(win->src.display, win->src.window, DefaultScreen(win->src.display));
-
4247 XFlush(win->src.display);
-
4248}
-
4249
- -
4251 RGFW_ASSERT(win != NULL);
-
4252
-
4253 XMapWindow(win->src.display, win->src.window);
-
4254 XFlush(win->src.display);
-
4255}
-
4256
-
4257void RGFW_window_setName(RGFW_window* win, const char* name) {
-
4258 RGFW_ASSERT(win);
-
4259 RGFW_GOTO_WAYLAND(0);
-
4260 #ifdef RGFW_X11
-
4261 XStoreName(win->src.display, win->src.window, name);
-
4262
-
4263 RGFW_LOAD_ATOM(_NET_WM_NAME);
- -
4265 win->src.display, win->src.window, _NET_WM_NAME, RGFW_XUTF8_STRING,
-
4266 8, PropModeReplace, (u8*)name, 256
-
4267 );
-
4268 #endif
-
4269 #ifdef RGFW_WAYLAND
-
4270 wayland:
-
4271 if (win->src.compositor)
-
4272 xdg_toplevel_set_title(win->src.xdg_toplevel, name);
+
4239 hints.flags |= PMaxSize;
+
4240
+
4241 hints.max_width = a.w;
+
4242 hints.max_height = a.h;
+
4243
+
4244 XSetWMNormalHints(win->src.display, win->src.window, &hints);
+
4245}
+
4246
+
4247
+ +
4249 RGFW_ASSERT(win != NULL);
+
4250
+
4251 XIconifyWindow(win->src.display, win->src.window, DefaultScreen(win->src.display));
+
4252 XFlush(win->src.display);
+
4253}
+
4254
+ +
4256 RGFW_ASSERT(win != NULL);
+
4257
+
4258 XMapWindow(win->src.display, win->src.window);
+
4259 XFlush(win->src.display);
+
4260}
+
4261
+
4262void RGFW_window_setName(RGFW_window* win, const char* name) {
+
4263 RGFW_ASSERT(win);
+
4264 RGFW_GOTO_WAYLAND(0);
+
4265 #ifdef RGFW_X11
+
4266 XStoreName(win->src.display, win->src.window, name);
+
4267
+
4268 RGFW_LOAD_ATOM(_NET_WM_NAME);
+ +
4270 win->src.display, win->src.window, _NET_WM_NAME, RGFW_XUTF8_STRING,
+
4271 8, PropModeReplace, (u8*)name, 256
+
4272 );
4273 #endif
-
4274}
-
4275
-
4276void* RGFW_libxshape = NULL;
-
4277
-
4278#ifndef RGFW_NO_PASSTHROUGH
-
4279
-
4280void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
-
4281 RGFW_ASSERT(win != NULL);
+
4274 #ifdef RGFW_WAYLAND
+
4275 wayland:
+
4276 if (win->src.compositor)
+
4277 xdg_toplevel_set_title(win->src.xdg_toplevel, name);
+
4278 #endif
+
4279}
+
4280
+
4281void* RGFW_libxshape = NULL;
4282
-
4283 #if defined(__CYGWIN__)
-
4284 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext-6.so");
-
4285 #elif defined(__OpenBSD__) || defined(__NetBSD__)
-
4286 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext.so");
-
4287 #else
-
4288 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext.so.6");
-
4289 #endif
-
4290
-
4291 typedef void (* PFN_XShapeCombineMask)(Display*,Window,int,int,int,Pixmap,int);
-
4292 static PFN_XShapeCombineMask XShapeCombineMaskSRC;
-
4293
-
4294 typedef void (* PFN_XShapeCombineRegion)(Display*,Window,int,int,int,Region,int);
-
4295 static PFN_XShapeCombineRegion XShapeCombineRegionSRC;
-
4296
-
4297 RGFW_PROC_DEF(RGFW_libxshape, XShapeCombineRegion);
-
4298 RGFW_PROC_DEF(RGFW_libxshape, XShapeCombineMask);
-
4299
-
4300 if (passthrough) {
-
4301 Region region = XCreateRegion();
-
4302 XShapeCombineRegionSRC(win->src.display, win->src.window, ShapeInput, 0, 0, region, ShapeSet);
-
4303 XDestroyRegion(region);
+
4283#ifndef RGFW_NO_PASSTHROUGH
+
4284
+
4285void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
+
4286 RGFW_ASSERT(win != NULL);
+
4287
+
4288 #if defined(__CYGWIN__)
+
4289 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext-6.so");
+
4290 #elif defined(__OpenBSD__) || defined(__NetBSD__)
+
4291 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext.so");
+
4292 #else
+
4293 RGFW_LOAD_LIBRARY(RGFW_libxshape, "libXext.so.6");
+
4294 #endif
+
4295
+
4296 typedef void (* PFN_XShapeCombineMask)(Display*,Window,int,int,int,Pixmap,int);
+
4297 static PFN_XShapeCombineMask XShapeCombineMaskSRC;
+
4298
+
4299 typedef void (* PFN_XShapeCombineRegion)(Display*,Window,int,int,int,Region,int);
+
4300 static PFN_XShapeCombineRegion XShapeCombineRegionSRC;
+
4301
+
4302 RGFW_PROC_DEF(RGFW_libxshape, XShapeCombineRegion);
+
4303 RGFW_PROC_DEF(RGFW_libxshape, XShapeCombineMask);
4304
-
4305 return;
-
4306 }
-
4307
-
4308 XShapeCombineMaskSRC(win->src.display, win->src.window, ShapeInput, 0, 0, None, ShapeSet);
-
4309}
-
4310
-
4311#endif /* RGFW_NO_PASSTHROUGH */
+
4305 if (passthrough) {
+
4306 Region region = XCreateRegion();
+
4307 XShapeCombineRegionSRC(win->src.display, win->src.window, ShapeInput, 0, 0, region, ShapeSet);
+
4308 XDestroyRegion(region);
+
4309
+
4310 return;
+
4311 }
4312
-
4313b32 RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) {
-
4314 RGFW_ASSERT(win != NULL); RGFW_ASSERT(icon != NULL);
-
4315 RGFW_ASSERT(channels == 3 || channels == 4);
-
4316 RGFW_GOTO_WAYLAND(0);
-
4317#ifdef RGFW_X11
-
4318 RGFW_LOAD_ATOM(_NET_WM_ICON);
-
4319 i32 count = 2 + (a.w * a.h);
-
4320
-
4321 unsigned long* data = (unsigned long*) RGFW_ALLOC(count * sizeof(unsigned long));
-
4322 data[0] = (unsigned long)a.w;
-
4323 data[1] = (unsigned long)a.h;
-
4324
-
4325 unsigned long* target = &data[2];
-
4326 u32 x, y;
-
4327
-
4328 for (x = 0; x < a.w; x++) {
-
4329 for (y = 0; y < a.h; y++) {
-
4330 size_t i = y * a.w + x;
-
4331 u32 alpha = (channels == 4) ? icon[i * 4 + 3] : 0xFF;
+
4313 XShapeCombineMaskSRC(win->src.display, win->src.window, ShapeInput, 0, 0, None, ShapeSet);
+
4314}
+
4315
+
4316#endif /* RGFW_NO_PASSTHROUGH */
+
4317
+
4318b32 RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) {
+
4319 RGFW_ASSERT(win != NULL); RGFW_ASSERT(icon != NULL);
+
4320 RGFW_ASSERT(channels == 3 || channels == 4);
+
4321 RGFW_GOTO_WAYLAND(0);
+
4322#ifdef RGFW_X11
+
4323 RGFW_LOAD_ATOM(_NET_WM_ICON);
+
4324 i32 count = 2 + (a.w * a.h);
+
4325
+
4326 unsigned long* data = (unsigned long*) RGFW_ALLOC(count * sizeof(unsigned long));
+
4327 data[0] = (unsigned long)a.w;
+
4328 data[1] = (unsigned long)a.h;
+
4329
+
4330 unsigned long* target = &data[2];
+
4331 u32 x, y;
4332
-
4333 target[i] = (unsigned long)((icon[i * 4 + 0]) << 16) |
-
4334 (unsigned long)((icon[i * 4 + 1]) << 8) |
-
4335 (unsigned long)((icon[i * 4 + 2]) << 0) |
-
4336 (unsigned long)(alpha << 24);
-
4337 }
-
4338 }
-
4339
-
4340 b32 res = (b32)XChangeProperty(
-
4341 win->src.display, win->src.window, _NET_WM_ICON, XA_CARDINAL, 32,
-
4342 PropModeReplace, (u8*)data, count
-
4343 );
+
4333 for (x = 0; x < a.w; x++) {
+
4334 for (y = 0; y < a.h; y++) {
+
4335 size_t i = y * a.w + x;
+
4336 u32 alpha = (channels == 4) ? icon[i * 4 + 3] : 0xFF;
+
4337
+
4338 target[i] = (unsigned long)((icon[i * 4 + 0]) << 16) |
+
4339 (unsigned long)((icon[i * 4 + 1]) << 8) |
+
4340 (unsigned long)((icon[i * 4 + 2]) << 0) |
+
4341 (unsigned long)(alpha << 24);
+
4342 }
+
4343 }
4344
-
4345 RGFW_FREE(data);
-
4346
-
4347 XFlush(win->src.display);
-
4348 return res;
-
4349#endif
-
4350#ifdef RGFW_WAYLAND
-
4351 wayland:
-
4352 return 0;
-
4353#endif
-
4354}
-
4355
-
4356RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
-
4357 RGFW_ASSERT(icon);
-
4358 RGFW_ASSERT(channels == 3 || channels == 4);
-
4359 RGFW_GOTO_WAYLAND(0);
-
4360
-
4361#ifdef RGFW_X11
-
4362#ifndef RGFW_NO_X11_CURSOR
-
4363 XcursorImage* native = XcursorImageCreate(a.w, a.h);
-
4364 native->xhot = 0;
-
4365 native->yhot = 0;
-
4366
-
4367 XcursorPixel* target = native->pixels;
-
4368 for (size_t x = 0; x < a.w; x++) {
-
4369 for (size_t y = 0; y < a.h; y++) {
-
4370 size_t i = y * a.w + x;
-
4371 u32 alpha = (channels == 4) ? icon[i * 4 + 3] : 0xFF;
-
4372
-
4373 target[i] = (u32)((icon[i * 4 + 0]) << 16)
-
4374 | (u32)((icon[i * 4 + 1]) << 8)
-
4375 | (u32)((icon[i * 4 + 2]) << 0)
-
4376 | (u32)(alpha << 24);
-
4377 }
-
4378 }
-
4379
-
4380 Cursor cursor = XcursorImageLoadCursor(RGFW_root->src.display, native);
-
4381 XcursorImageDestroy(native);
-
4382
-
4383 return (void*)cursor;
-
4384#else
-
4385 RGFW_UNUSED(image); RGFW_UNUSED(a.w); RGFW_UNUSED(channels);
-
4386 return NULL;
-
4387#endif
-
4388#endif
-
4389#ifdef RGFW_WAYLAND
-
4390 wayland:
-
4391 RGFW_UNUSED(icon); RGFW_UNUSED(a); RGFW_UNUSED(channels);
-
4392 return NULL; // TODO
+
4345 b32 res = (b32)XChangeProperty(
+
4346 win->src.display, win->src.window, _NET_WM_ICON, XA_CARDINAL, 32,
+
4347 PropModeReplace, (u8*)data, count
+
4348 );
+
4349
+
4350 RGFW_FREE(data);
+
4351
+
4352 XFlush(win->src.display);
+
4353 return res;
+
4354#endif
+
4355#ifdef RGFW_WAYLAND
+
4356 wayland:
+
4357 return 0;
+
4358#endif
+
4359}
+
4360
+
4361RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
+
4362 RGFW_ASSERT(icon);
+
4363 RGFW_ASSERT(channels == 3 || channels == 4);
+
4364 RGFW_GOTO_WAYLAND(0);
+
4365
+
4366#ifdef RGFW_X11
+
4367#ifndef RGFW_NO_X11_CURSOR
+
4368 XcursorImage* native = XcursorImageCreate(a.w, a.h);
+
4369 native->xhot = 0;
+
4370 native->yhot = 0;
+
4371
+
4372 XcursorPixel* target = native->pixels;
+
4373 for (size_t x = 0; x < a.w; x++) {
+
4374 for (size_t y = 0; y < a.h; y++) {
+
4375 size_t i = y * a.w + x;
+
4376 u32 alpha = (channels == 4) ? icon[i * 4 + 3] : 0xFF;
+
4377
+
4378 target[i] = (u32)((icon[i * 4 + 0]) << 16)
+
4379 | (u32)((icon[i * 4 + 1]) << 8)
+
4380 | (u32)((icon[i * 4 + 2]) << 0)
+
4381 | (u32)(alpha << 24);
+
4382 }
+
4383 }
+
4384
+
4385 Cursor cursor = XcursorImageLoadCursor(RGFW_root->src.display, native);
+
4386 XcursorImageDestroy(native);
+
4387
+
4388 return (void*)cursor;
+
4389#else
+
4390 RGFW_UNUSED(image); RGFW_UNUSED(a.w); RGFW_UNUSED(channels);
+
4391 return NULL;
+
4392#endif
4393#endif
-
4394}
-
4395
-
4396void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
-
4397RGFW_GOTO_WAYLAND(0);
-
4398#ifdef RGFW_X11
-
4399 RGFW_ASSERT(win && mouse);
-
4400 XDefineCursor(win->src.display, win->src.window, (Cursor)mouse);
-
4401#endif
-
4402#ifdef RGFW_WAYLAND
-
4403 wayland:
-
4404#endif
-
4405}
-
4406
-
4407void RGFW_freeMouse(RGFW_mouse* mouse) {
-
4408RGFW_GOTO_WAYLAND(0);
-
4409#ifdef RGFW_X11
-
4410 RGFW_ASSERT(mouse);
-
4411 XFreeCursor(RGFW_root->src.display, (Cursor)mouse);
-
4412#endif
-
4413#ifdef RGFW_WAYLAND
-
4414 wayland:
-
4415#endif
-
4416}
-
4417
- -
4419RGFW_GOTO_WAYLAND(1);
-
4420#ifdef RGFW_X11
-
4421 RGFW_ASSERT(win != NULL);
+
4394#ifdef RGFW_WAYLAND
+
4395 wayland:
+
4396 RGFW_UNUSED(icon); RGFW_UNUSED(a); RGFW_UNUSED(channels);
+
4397 return NULL; // TODO
+
4398#endif
+
4399}
+
4400
+
4401void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
+
4402RGFW_GOTO_WAYLAND(0);
+
4403#ifdef RGFW_X11
+
4404 RGFW_ASSERT(win && mouse);
+
4405 XDefineCursor(win->src.display, win->src.window, (Cursor)mouse);
+
4406#endif
+
4407#ifdef RGFW_WAYLAND
+
4408 wayland:
+
4409#endif
+
4410}
+
4411
+
4412void RGFW_freeMouse(RGFW_mouse* mouse) {
+
4413RGFW_GOTO_WAYLAND(0);
+
4414#ifdef RGFW_X11
+
4415 RGFW_ASSERT(mouse);
+
4416 XFreeCursor(RGFW_root->src.display, (Cursor)mouse);
+
4417#endif
+
4418#ifdef RGFW_WAYLAND
+
4419 wayland:
+
4420#endif
+
4421}
4422
-
4423 XEvent event;
-
4424 XQueryPointer(win->src.display, DefaultRootWindow(win->src.display),
-
4425 &event.xbutton.root, &event.xbutton.window,
-
4426 &event.xbutton.x_root, &event.xbutton.y_root,
-
4427 &event.xbutton.x, &event.xbutton.y,
-
4428 &event.xbutton.state);
-
4429
-
4430 win->_lastMousePoint = RGFW_POINT(p.x - win->r.x, p.y - win->r.y);
-
4431 if (event.xbutton.x == p.x && event.xbutton.y == p.y)
-
4432 return;
-
4433
-
4434 XWarpPointer(win->src.display, None, win->src.window, 0, 0, 0, 0, (int) p.x - win->r.x, (int) p.y - win->r.y);
-
4435#endif
-
4436#ifdef RGFW_WAYLAND
-
4437 wayland:
-
4438#endif
-
4439}
-
4440
- -
4442 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
-
4443}
-
4444
- -
4446 RGFW_ASSERT(win != NULL);
-
4447 RGFW_GOTO_WAYLAND(0);
-
4448#ifdef RGFW_X11
-
4449 if (mouse > (sizeof(RGFW_mouseIconSrc) / sizeof(u8)))
-
4450 return 0;
-
4451
-
4452 mouse = RGFW_mouseIconSrc[mouse];
-
4453
-
4454 Cursor cursor = XCreateFontCursor(win->src.display, mouse);
-
4455 XDefineCursor(win->src.display, win->src.window, (Cursor) cursor);
+ +
4424RGFW_GOTO_WAYLAND(1);
+
4425#ifdef RGFW_X11
+
4426 RGFW_ASSERT(win != NULL);
+
4427
+
4428 XEvent event;
+
4429 XQueryPointer(win->src.display, DefaultRootWindow(win->src.display),
+
4430 &event.xbutton.root, &event.xbutton.window,
+
4431 &event.xbutton.x_root, &event.xbutton.y_root,
+
4432 &event.xbutton.x, &event.xbutton.y,
+
4433 &event.xbutton.state);
+
4434
+
4435 win->_lastMousePoint = RGFW_POINT(p.x - win->r.x, p.y - win->r.y);
+
4436 if (event.xbutton.x == p.x && event.xbutton.y == p.y)
+
4437 return;
+
4438
+
4439 XWarpPointer(win->src.display, None, win->src.window, 0, 0, 0, 0, (int) p.x - win->r.x, (int) p.y - win->r.y);
+
4440#endif
+
4441#ifdef RGFW_WAYLAND
+
4442 wayland:
+
4443#endif
+
4444}
+
4445
+ +
4447 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
+
4448}
+
4449
+ +
4451 RGFW_ASSERT(win != NULL);
+
4452 RGFW_GOTO_WAYLAND(0);
+
4453#ifdef RGFW_X11
+
4454 if (mouse > (sizeof(RGFW_mouseIconSrc) / sizeof(u8)))
+
4455 return 0;
4456
-
4457 XFreeCursor(win->src.display, (Cursor) cursor);
-
4458 return 1;
-
4459#endif
-
4460#ifdef RGFW_WAYLAND
-
4461 wayland:
-
4462 static const char* iconStrings[] = { "left_ptr", "left_ptr", "text", "cross", "pointer", "e-resize", "n-resize", "nw-resize", "ne-resize", "all-resize", "not-allowed" };
-
4463
-
4464 struct wl_cursor* wlcursor = wl_cursor_theme_get_cursor(RGFW_wl_cursor_theme, iconStrings[mouse]);
-
4465 RGFW_cursor_image = wlcursor->images[0];
-
4466 struct wl_buffer* cursor_buffer = wl_cursor_image_get_buffer(RGFW_cursor_image);
-
4467
-
4468 wl_surface_attach(RGFW_cursor_surface, cursor_buffer, 0, 0);
-
4469 wl_surface_commit(RGFW_cursor_surface);
-
4470 return 1;
-
4471#endif
-
4472}
-
4473
-
4474void RGFW_window_hide(RGFW_window* win) {
-
4475 RGFW_GOTO_WAYLAND(0);
-
4476#ifdef RGFW_X11
-
4477 XMapWindow(win->src.display, win->src.window);
-
4478#endif
-
4479#ifdef RGFW_WAYLAND
-
4480 wayland:
-
4481 wl_surface_attach(win->src.surface, NULL, 0, 0);
-
4482 wl_surface_commit(win->src.surface);
-
4483 win->_flags |= RGFW_windowHide;
-
4484#endif
-
4485}
-
4486
-
4487void RGFW_window_show(RGFW_window* win) {
-
4488 if (win->_flags & RGFW_windowHide)
-
4489 win->_flags ^= RGFW_windowHide;
-
4490 RGFW_GOTO_WAYLAND(0);
-
4491#ifdef RGFW_X11
-
4492 XUnmapWindow(win->src.display, win->src.window);
-
4493#endif
-
4494#ifdef RGFW_WAYLAND
-
4495 wayland:
-
4496 //wl_surface_attach(win->src.surface, win->rc., 0, 0);
-
4497 wl_surface_commit(win->src.surface);
+
4457 mouse = RGFW_mouseIconSrc[mouse];
+
4458
+
4459 Cursor cursor = XCreateFontCursor(win->src.display, mouse);
+
4460 XDefineCursor(win->src.display, win->src.window, (Cursor) cursor);
+
4461
+
4462 XFreeCursor(win->src.display, (Cursor) cursor);
+
4463 return 1;
+
4464#endif
+
4465#ifdef RGFW_WAYLAND
+
4466 wayland:
+
4467 static const char* iconStrings[] = { "left_ptr", "left_ptr", "text", "cross", "pointer", "e-resize", "n-resize", "nw-resize", "ne-resize", "all-resize", "not-allowed" };
+
4468
+
4469 struct wl_cursor* wlcursor = wl_cursor_theme_get_cursor(RGFW_wl_cursor_theme, iconStrings[mouse]);
+
4470 RGFW_cursor_image = wlcursor->images[0];
+
4471 struct wl_buffer* cursor_buffer = wl_cursor_image_get_buffer(RGFW_cursor_image);
+
4472
+
4473 wl_surface_attach(RGFW_cursor_surface, cursor_buffer, 0, 0);
+
4474 wl_surface_commit(RGFW_cursor_surface);
+
4475 return 1;
+
4476#endif
+
4477}
+
4478
+
4479void RGFW_window_hide(RGFW_window* win) {
+
4480 RGFW_GOTO_WAYLAND(0);
+
4481#ifdef RGFW_X11
+
4482 XMapWindow(win->src.display, win->src.window);
+
4483#endif
+
4484#ifdef RGFW_WAYLAND
+
4485 wayland:
+
4486 wl_surface_attach(win->src.surface, NULL, 0, 0);
+
4487 wl_surface_commit(win->src.surface);
+
4488 win->_flags |= RGFW_windowHide;
+
4489#endif
+
4490}
+
4491
+
4492void RGFW_window_show(RGFW_window* win) {
+
4493 if (win->_flags & RGFW_windowHide)
+
4494 win->_flags ^= RGFW_windowHide;
+
4495 RGFW_GOTO_WAYLAND(0);
+
4496#ifdef RGFW_X11
+
4497 XUnmapWindow(win->src.display, win->src.window);
4498#endif
-
4499}
-
4500
-
4501RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
-
4502 RGFW_GOTO_WAYLAND(1);
-
4503 #ifdef RGFW_X11
-
4504 XEvent event;
-
4505 int format;
-
4506 unsigned long N, sizeN;
-
4507 char* data;
-
4508 Atom target;
-
4509
-
4510 RGFW_LOAD_ATOM(XSEL_DATA);
-
4511
-
4512 XConvertSelection(RGFW_root->src.display, RGFW_XCLIPBOARD, RGFW_XUTF8_STRING, XSEL_DATA, RGFW_root->src.window, CurrentTime);
-
4513 XSync(RGFW_root->src.display, 0);
-
4514 XNextEvent(RGFW_root->src.display, &event);
-
4515
-
4516 if (event.type != SelectionNotify || event.xselection.selection != RGFW_XCLIPBOARD || event.xselection.property == 0)
-
4517 return -1;
-
4518
-
4519 XGetWindowProperty(event.xselection.display, event.xselection.requestor,
-
4520 event.xselection.property, 0L, (~0L), 0, AnyPropertyType, &target,
-
4521 &format, &sizeN, &N, (unsigned char**) &data);
-
4522
-
4523 RGFW_ssize_t size;
-
4524 if (sizeN > strCapacity && str != NULL)
-
4525 size = -1;
-
4526
-
4527 if ((target == RGFW_XUTF8_STRING || target == XA_STRING) && str != NULL) {
-
4528 RGFW_MEMCPY(str, data, sizeN);
-
4529 str[sizeN] = '\0';
-
4530 XFree(data);
-
4531 } else if (str != NULL) size = -1;
-
4532
-
4533 XDeleteProperty(event.xselection.display, event.xselection.requestor, event.xselection.property);
-
4534 size = sizeN;
-
4535 return size;
-
4536 #endif
-
4537 #if defined(RGFW_WAYLAND)
-
4538 wayland: return 0;
-
4539 #endif
-
4540}
-
4541
-
4542void RGFW_writeClipboard(const char* text, u32 textLen) {
-
4543 RGFW_GOTO_WAYLAND(1);
-
4544 #ifdef RGFW_X11
-
4545 RGFW_LOAD_ATOM(SAVE_TARGETS);
-
4546 RGFW_LOAD_ATOM(TARGETS);
-
4547 RGFW_LOAD_ATOM(MULTIPLE);
-
4548 RGFW_LOAD_ATOM(ATOM_PAIR);
-
4549 RGFW_LOAD_ATOM(CLIPBOARD_MANAGER);
-
4550
-
4551 XSetSelectionOwner(RGFW_root->src.display, RGFW_XCLIPBOARD, RGFW_root->src.window, CurrentTime);
-
4552
-
4553 XConvertSelection(RGFW_root->src.display, CLIPBOARD_MANAGER, SAVE_TARGETS, None, RGFW_root->src.window, CurrentTime);
-
4554 for (;;) {
-
4555 XEvent event;
-
4556
-
4557 XNextEvent(RGFW_root->src.display, &event);
-
4558 if (event.type != SelectionRequest) {
-
4559 break;
-
4560 }
+
4499#ifdef RGFW_WAYLAND
+
4500 wayland:
+
4501 //wl_surface_attach(win->src.surface, win->rc., 0, 0);
+
4502 wl_surface_commit(win->src.surface);
+
4503#endif
+
4504}
+
4505
+
4506RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
+
4507 RGFW_GOTO_WAYLAND(1);
+
4508 #ifdef RGFW_X11
+
4509 XEvent event;
+
4510 int format;
+
4511 unsigned long N, sizeN;
+
4512 char* data;
+
4513 Atom target;
+
4514
+
4515 RGFW_LOAD_ATOM(XSEL_DATA);
+
4516
+
4517 XConvertSelection(RGFW_root->src.display, RGFW_XCLIPBOARD, RGFW_XUTF8_STRING, XSEL_DATA, RGFW_root->src.window, CurrentTime);
+
4518 XSync(RGFW_root->src.display, 0);
+
4519 XNextEvent(RGFW_root->src.display, &event);
+
4520
+
4521 if (event.type != SelectionNotify || event.xselection.selection != RGFW_XCLIPBOARD || event.xselection.property == 0)
+
4522 return -1;
+
4523
+
4524 XGetWindowProperty(event.xselection.display, event.xselection.requestor,
+
4525 event.xselection.property, 0L, (~0L), 0, AnyPropertyType, &target,
+
4526 &format, &sizeN, &N, (unsigned char**) &data);
+
4527
+
4528 RGFW_ssize_t size;
+
4529 if (sizeN > strCapacity && str != NULL)
+
4530 size = -1;
+
4531
+
4532 if ((target == RGFW_XUTF8_STRING || target == XA_STRING) && str != NULL) {
+
4533 RGFW_MEMCPY(str, data, sizeN);
+
4534 str[sizeN] = '\0';
+
4535 XFree(data);
+
4536 } else if (str != NULL) size = -1;
+
4537
+
4538 XDeleteProperty(event.xselection.display, event.xselection.requestor, event.xselection.property);
+
4539 size = sizeN;
+
4540 return size;
+
4541 #endif
+
4542 #if defined(RGFW_WAYLAND)
+
4543 wayland: return 0;
+
4544 #endif
+
4545}
+
4546
+
4547void RGFW_writeClipboard(const char* text, u32 textLen) {
+
4548 RGFW_GOTO_WAYLAND(1);
+
4549 #ifdef RGFW_X11
+
4550 RGFW_LOAD_ATOM(SAVE_TARGETS);
+
4551 RGFW_LOAD_ATOM(TARGETS);
+
4552 RGFW_LOAD_ATOM(MULTIPLE);
+
4553 RGFW_LOAD_ATOM(ATOM_PAIR);
+
4554 RGFW_LOAD_ATOM(CLIPBOARD_MANAGER);
+
4555
+
4556 XSetSelectionOwner(RGFW_root->src.display, RGFW_XCLIPBOARD, RGFW_root->src.window, CurrentTime);
+
4557
+
4558 XConvertSelection(RGFW_root->src.display, CLIPBOARD_MANAGER, SAVE_TARGETS, None, RGFW_root->src.window, CurrentTime);
+
4559 for (;;) {
+
4560 XEvent event;
4561
-
4562 const XSelectionRequestEvent* request = &event.xselectionrequest;
-
4563
-
4564 XEvent reply = { SelectionNotify };
-
4565 reply.xselection.property = 0;
+
4562 XNextEvent(RGFW_root->src.display, &event);
+
4563 if (event.type != SelectionRequest) {
+
4564 break;
+
4565 }
4566
-
4567 if (request->target == TARGETS) {
-
4568 const Atom targets[] = { TARGETS,
-
4569 MULTIPLE,
-
4570 RGFW_XUTF8_STRING,
-
4571 XA_STRING };
-
4572
-
4573 XChangeProperty(RGFW_root->src.display,
-
4574 request->requestor,
-
4575 request->property,
-
4576 4,
-
4577 32,
-
4578 PropModeReplace,
-
4579 (u8*) targets,
-
4580 sizeof(targets) / sizeof(targets[0]));
-
4581
-
4582 reply.xselection.property = request->property;
-
4583 }
-
4584
-
4585 if (request->target == MULTIPLE) {
-
4586 Atom* targets = NULL;
-
4587
-
4588 Atom actualType = 0;
-
4589 int actualFormat = 0;
-
4590 unsigned long count = 0, bytesAfter = 0;
-
4591
-
4592 XGetWindowProperty(RGFW_root->src.display, request->requestor, request->property, 0, LONG_MAX, False, ATOM_PAIR, &actualType, &actualFormat, &count, &bytesAfter, (u8**) &targets);
-
4593
-
4594 unsigned long i;
-
4595 for (i = 0; i < (u32)count; i += 2) {
-
4596 if (targets[i] == RGFW_XUTF8_STRING || targets[i] == XA_STRING) {
-
4597 XChangeProperty(RGFW_root->src.display,
-
4598 request->requestor,
-
4599 targets[i + 1],
-
4600 targets[i],
-
4601 8,
-
4602 PropModeReplace,
-
4603 (u8*) text,
-
4604 textLen);
-
4605 XFlush(RGFW_root->src.display);
-
4606 } else {
-
4607 targets[i + 1] = None;
-
4608 }
-
4609 }
-
4610
-
4611 XChangeProperty(RGFW_root->src.display,
-
4612 request->requestor,
-
4613 request->property,
-
4614 ATOM_PAIR,
-
4615 32,
-
4616 PropModeReplace,
-
4617 (u8*) targets,
-
4618 count);
-
4619
-
4620 XFlush(RGFW_root->src.display);
-
4621 XFree(targets);
-
4622
-
4623 reply.xselection.property = request->property;
-
4624 }
-
4625
-
4626 reply.xselection.display = request->display;
-
4627 reply.xselection.requestor = request->requestor;
-
4628 reply.xselection.selection = request->selection;
-
4629 reply.xselection.target = request->target;
-
4630 reply.xselection.time = request->time;
-
4631
-
4632 XSendEvent(RGFW_root->src.display, request->requestor, False, 0, &reply);
-
4633 XFlush(RGFW_root->src.display);
-
4634 }
-
4635 #endif
-
4636 #if defined(RGFW_WAYLAND)
-
4637 wayland:
-
4638 #endif
-
4639}
-
4640
- -
4642 RGFW_ASSERT(win != NULL);
-
4643
-
4644 XWindowAttributes windowAttributes;
-
4645 XGetWindowAttributes(win->src.display, win->src.window, &windowAttributes);
-
4646
-
4647 /* check if the window is visable */
-
4648 if (windowAttributes.map_state != IsViewable)
-
4649 return 0;
-
4650
-
4651 /* check if the window covers the full screen */
-
4652 return (windowAttributes.x == 0 && windowAttributes.y == 0 &&
-
4653 windowAttributes.width == XDisplayWidth(win->src.display, DefaultScreen(win->src.display)) &&
-
4654 windowAttributes.height == XDisplayHeight(win->src.display, DefaultScreen(win->src.display)));
-
4655}
-
4656
- -
4658 RGFW_ASSERT(win != NULL);
-
4659
-
4660 XWindowAttributes windowAttributes;
-
4661 XGetWindowAttributes(win->src.display, win->src.window, &windowAttributes);
-
4662
-
4663 return (windowAttributes.map_state == IsUnmapped && !RGFW_window_isMinimized(win));
-
4664}
-
4665
- -
4667 RGFW_ASSERT(win != NULL);
-
4668
-
4669 RGFW_LOAD_ATOM(WM_STATE);
+
4567 const XSelectionRequestEvent* request = &event.xselectionrequest;
+
4568
+
4569 XEvent reply = { SelectionNotify };
+
4570 reply.xselection.property = 0;
+
4571
+
4572 if (request->target == TARGETS) {
+
4573 const Atom targets[] = { TARGETS,
+
4574 MULTIPLE,
+
4575 RGFW_XUTF8_STRING,
+
4576 XA_STRING };
+
4577
+
4578 XChangeProperty(RGFW_root->src.display,
+
4579 request->requestor,
+
4580 request->property,
+
4581 4,
+
4582 32,
+
4583 PropModeReplace,
+
4584 (u8*) targets,
+
4585 sizeof(targets) / sizeof(targets[0]));
+
4586
+
4587 reply.xselection.property = request->property;
+
4588 }
+
4589
+
4590 if (request->target == MULTIPLE) {
+
4591 Atom* targets = NULL;
+
4592
+
4593 Atom actualType = 0;
+
4594 int actualFormat = 0;
+
4595 unsigned long count = 0, bytesAfter = 0;
+
4596
+
4597 XGetWindowProperty(RGFW_root->src.display, request->requestor, request->property, 0, LONG_MAX, False, ATOM_PAIR, &actualType, &actualFormat, &count, &bytesAfter, (u8**) &targets);
+
4598
+
4599 unsigned long i;
+
4600 for (i = 0; i < (u32)count; i += 2) {
+
4601 if (targets[i] == RGFW_XUTF8_STRING || targets[i] == XA_STRING) {
+
4602 XChangeProperty(RGFW_root->src.display,
+
4603 request->requestor,
+
4604 targets[i + 1],
+
4605 targets[i],
+
4606 8,
+
4607 PropModeReplace,
+
4608 (u8*) text,
+
4609 textLen);
+
4610 XFlush(RGFW_root->src.display);
+
4611 } else {
+
4612 targets[i + 1] = None;
+
4613 }
+
4614 }
+
4615
+
4616 XChangeProperty(RGFW_root->src.display,
+
4617 request->requestor,
+
4618 request->property,
+
4619 ATOM_PAIR,
+
4620 32,
+
4621 PropModeReplace,
+
4622 (u8*) targets,
+
4623 count);
+
4624
+
4625 XFlush(RGFW_root->src.display);
+
4626 XFree(targets);
+
4627
+
4628 reply.xselection.property = request->property;
+
4629 }
+
4630
+
4631 reply.xselection.display = request->display;
+
4632 reply.xselection.requestor = request->requestor;
+
4633 reply.xselection.selection = request->selection;
+
4634 reply.xselection.target = request->target;
+
4635 reply.xselection.time = request->time;
+
4636
+
4637 XSendEvent(RGFW_root->src.display, request->requestor, False, 0, &reply);
+
4638 XFlush(RGFW_root->src.display);
+
4639 }
+
4640 #endif
+
4641 #if defined(RGFW_WAYLAND)
+
4642 wayland:
+
4643 #endif
+
4644}
+
4645
+ +
4647 RGFW_ASSERT(win != NULL);
+
4648
+
4649 XWindowAttributes windowAttributes;
+
4650 XGetWindowAttributes(win->src.display, win->src.window, &windowAttributes);
+
4651
+
4652 /* check if the window is visable */
+
4653 if (windowAttributes.map_state != IsViewable)
+
4654 return 0;
+
4655
+
4656 /* check if the window covers the full screen */
+
4657 return (windowAttributes.x == 0 && windowAttributes.y == 0 &&
+
4658 windowAttributes.width == XDisplayWidth(win->src.display, DefaultScreen(win->src.display)) &&
+
4659 windowAttributes.height == XDisplayHeight(win->src.display, DefaultScreen(win->src.display)));
+
4660}
+
4661
+ +
4663 RGFW_ASSERT(win != NULL);
+
4664
+
4665 XWindowAttributes windowAttributes;
+
4666 XGetWindowAttributes(win->src.display, win->src.window, &windowAttributes);
+
4667
+
4668 return (windowAttributes.map_state == IsUnmapped && !RGFW_window_isMinimized(win));
+
4669}
4670
-
4671 Atom actual_type;
-
4672 i32 actual_format;
-
4673 unsigned long nitems, bytes_after;
-
4674 unsigned char* prop_data;
+ +
4672 RGFW_ASSERT(win != NULL);
+
4673
+
4674 RGFW_LOAD_ATOM(WM_STATE);
4675
-
4676 i16 status = XGetWindowProperty(win->src.display, win->src.window, WM_STATE, 0, 2, False,
-
4677 AnyPropertyType, &actual_type, &actual_format,
-
4678 &nitems, &bytes_after, &prop_data);
-
4679
-
4680 if (status == Success && nitems >= 1 && *((int*) prop_data) == IconicState) {
-
4681 XFree(prop_data);
-
4682 return 1;
-
4683 }
+
4676 Atom actual_type;
+
4677 i32 actual_format;
+
4678 unsigned long nitems, bytes_after;
+
4679 unsigned char* prop_data;
+
4680
+
4681 i16 status = XGetWindowProperty(win->src.display, win->src.window, WM_STATE, 0, 2, False,
+
4682 AnyPropertyType, &actual_type, &actual_format,
+
4683 &nitems, &bytes_after, &prop_data);
4684
-
4685 if (prop_data != NULL)
+
4685 if (status == Success && nitems >= 1 && *((int*) prop_data) == IconicState) {
4686 XFree(prop_data);
-
4687
-
4688 return 0;
-
4689}
-
4690
- -
4692 RGFW_ASSERT(win != NULL);
-
4693 RGFW_LOAD_ATOM(_NET_WM_STATE);
-
4694 RGFW_LOAD_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
-
4695 RGFW_LOAD_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
-
4696
-
4697 Atom actual_type;
-
4698 i32 actual_format;
-
4699 unsigned long nitems, bytes_after;
-
4700 unsigned char* prop_data;
+
4687 return 1;
+
4688 }
+
4689
+
4690 if (prop_data != NULL)
+
4691 XFree(prop_data);
+
4692
+
4693 return 0;
+
4694}
+
4695
+ +
4697 RGFW_ASSERT(win != NULL);
+
4698 RGFW_LOAD_ATOM(_NET_WM_STATE);
+
4699 RGFW_LOAD_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
+
4700 RGFW_LOAD_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
4701
-
4702 i16 status = XGetWindowProperty(win->src.display, win->src.window, _NET_WM_STATE, 0, 1024, False,
-
4703 XA_ATOM, &actual_type, &actual_format,
-
4704 &nitems, &bytes_after, &prop_data);
-
4705
-
4706 if (status != Success) {
-
4707 if (prop_data != NULL)
-
4708 XFree(prop_data);
-
4709
-
4710 return 0;
-
4711 }
-
4712
-
4713 Atom* atoms = (Atom*) prop_data;
-
4714 u64 i;
-
4715 for (i = 0; i < nitems; ++i) {
-
4716 if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT ||
-
4717 atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
-
4718 XFree(prop_data);
-
4719 return 1;
-
4720 }
-
4721 }
-
4722
-
4723 return 0;
-
4724}
-
4725
-
4726static float XGetSystemContentDPI(Display* display, i32 screen) {
-
4727 float dpi = 96.0f;
-
4728
-
4729 #ifndef RGFW_NO_DPI
-
4730 RGFW_UNUSED(screen);
-
4731 char* rms = XResourceManagerString(display);
-
4732 XrmDatabase db = NULL;
+
4702 Atom actual_type;
+
4703 i32 actual_format;
+
4704 unsigned long nitems, bytes_after;
+
4705 unsigned char* prop_data;
+
4706
+
4707 i16 status = XGetWindowProperty(win->src.display, win->src.window, _NET_WM_STATE, 0, 1024, False,
+
4708 XA_ATOM, &actual_type, &actual_format,
+
4709 &nitems, &bytes_after, &prop_data);
+
4710
+
4711 if (status != Success) {
+
4712 if (prop_data != NULL)
+
4713 XFree(prop_data);
+
4714
+
4715 return 0;
+
4716 }
+
4717
+
4718 Atom* atoms = (Atom*) prop_data;
+
4719 u64 i;
+
4720 for (i = 0; i < nitems; ++i) {
+
4721 if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT ||
+
4722 atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
+
4723 XFree(prop_data);
+
4724 return 1;
+
4725 }
+
4726 }
+
4727
+
4728 return 0;
+
4729}
+
4730
+
4731static float XGetSystemContentDPI(Display* display, i32 screen) {
+
4732 float dpi = 96.0f;
4733
-
4734 if (rms && db) {
-
4735 db = XrmGetStringDatabase(rms);
-
4736 XrmValue value;
-
4737 char* type = NULL;
+
4734 #ifndef RGFW_NO_DPI
+
4735 RGFW_UNUSED(screen);
+
4736 char* rms = XResourceManagerString(display);
+
4737 XrmDatabase db = NULL;
4738
-
4739 if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value) && type && RGFW_STRNCMP(type, "String", 7) == 0) {
-
4740 dpi = (float)atof(value.addr);
-
4741 }
- -
4743 }
-
4744 #else
-
4745 dpi = RGFW_ROUND(DisplayWidth(display, screen) / (DisplayWidthMM(display, screen) / 25.4));
-
4746 #endif
-
4747
-
4748 return dpi;
-
4749}
-
4750
-
4751RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
-
4752 RGFW_monitor monitor;
-
4753
-
4754 Display* display = XOpenDisplay(NULL);
+
4739 if (rms && db) {
+
4740 db = XrmGetStringDatabase(rms);
+
4741 XrmValue value;
+
4742 char* type = NULL;
+
4743
+
4744 if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value) && type && RGFW_STRNCMP(type, "String", 7) == 0) {
+
4745 dpi = (float)atof(value.addr);
+
4746 }
+ +
4748 }
+
4749 #else
+
4750 dpi = RGFW_ROUND(DisplayWidth(display, screen) / (DisplayWidthMM(display, screen) / 25.4));
+
4751 #endif
+
4752
+
4753 return dpi;
+
4754}
4755
- -
4757
-
4758 monitor.rect = RGFW_RECT(0, 0, size.w, size.h);
-
4759 monitor.physW = DisplayWidthMM(display, screen) / 25.4;
-
4760 monitor.physH = DisplayHeightMM(display, screen) / 25.4;
-
4761
-
4762 char* name = XDisplayName((const char*)display);
-
4763 RGFW_MEMCPY(monitor.name, name, 128);
-
4764
-
4765 float dpi = XGetSystemContentDPI(display, screen);
-
4766 monitor.pixelRatio = dpi / 96.0f;
-
4767
-
4768 #ifndef RGFW_NO_DPI
-
4769 XRRScreenResources* sr = XRRGetScreenResourcesCurrent(display, RootWindow(display, screen));
-
4770
-
4771 XRRCrtcInfo* ci = NULL;
-
4772 int crtc = screen;
-
4773
-
4774 if (sr->ncrtc > crtc) {
-
4775 ci = XRRGetCrtcInfo(display, sr, sr->crtcs[crtc]);
-
4776 }
-
4777 #endif
+
4756RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
+
4757 RGFW_monitor monitor;
+
4758
+
4759 Display* display = XOpenDisplay(NULL);
+
4760
+ +
4762
+
4763 monitor.rect = RGFW_RECT(0, 0, size.w, size.h);
+
4764 monitor.physW = DisplayWidthMM(display, screen) / 25.4;
+
4765 monitor.physH = DisplayHeightMM(display, screen) / 25.4;
+
4766
+
4767 char* name = XDisplayName((const char*)display);
+
4768 RGFW_MEMCPY(monitor.name, name, 128);
+
4769
+
4770 float dpi = XGetSystemContentDPI(display, screen);
+
4771 monitor.pixelRatio = dpi / 96.0f;
+
4772
+
4773 #ifndef RGFW_NO_DPI
+
4774 XRRScreenResources* sr = XRRGetScreenResourcesCurrent(display, RootWindow(display, screen));
+
4775
+
4776 XRRCrtcInfo* ci = NULL;
+
4777 int crtc = screen;
4778
-
4779 float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
-
4780 float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);
-
4781
-
4782 monitor.scaleX = (float) (ppi_width) / dpi;
-
4783 monitor.scaleY = (float) (ppi_height) / dpi;
-
4784
-
4785 #ifndef RGFW_NO_DPI
-
4786 XRROutputInfo* info = XRRGetOutputInfo (display, sr, sr->outputs[screen]);
-
4787
-
4788 if (info == NULL || ci == NULL) {
- -
4790 XCloseDisplay(display);
-
4791
-
4792 #ifdef RGFW_DEBUG
-
4793 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
-
4794 #endif
-
4795 return monitor;
-
4796 }
-
4797
-
4798
-
4799 float physW = info->mm_width / 25.4;
-
4800 float physH = info->mm_height / 25.4;
-
4801
-
4802 RGFW_MEMCPY(monitor.name, info->name, 128);
+
4779 if (sr->ncrtc > crtc) {
+
4780 ci = XRRGetCrtcInfo(display, sr, sr->crtcs[crtc]);
+
4781 }
+
4782 #endif
+
4783
+
4784 float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
+
4785 float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);
+
4786
+
4787 monitor.scaleX = (float) (ppi_width) / dpi;
+
4788 monitor.scaleY = (float) (ppi_height) / dpi;
+
4789
+
4790 #ifndef RGFW_NO_DPI
+
4791 XRROutputInfo* info = XRRGetOutputInfo (display, sr, sr->outputs[screen]);
+
4792
+
4793 if (info == NULL || ci == NULL) {
+ +
4795 XCloseDisplay(display);
+
4796
+
4797 #ifdef RGFW_DEBUG
+
4798 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
+
4799 #endif
+
4800 return monitor;
+
4801 }
+
4802
4803
-
4804 if (physW && physH) {
-
4805 monitor.physW = physW;
-
4806 monitor.physH = physH;
-
4807 }
+
4804 float physW = info->mm_width / 25.4;
+
4805 float physH = info->mm_height / 25.4;
+
4806
+
4807 RGFW_MEMCPY(monitor.name, info->name, 128);
4808
-
4809 monitor.rect.x = ci->x;
-
4810 monitor.rect.y = ci->y;
-
4811
-
4812 float w = ci->width;
-
4813 float h = ci->height;
-
4814
-
4815 if (w && h) {
-
4816 monitor.rect.w = w;
-
4817 monitor.rect.h = h;
-
4818 }
-
4819 #endif
-
4820
-
4821 if (monitor.physW == 0 || monitor.physH == 0) {
-
4822 monitor.scaleX = 0;
-
4823 monitor.scaleY = 0;
-
4824 } else {
-
4825 float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
-
4826 float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);
-
4827
-
4828 monitor.scaleX = (float) (ppi_width) / (float) dpi;
-
4829 monitor.scaleY = (float) (ppi_height) / (float) dpi;
-
4830
-
4831 if ((monitor.scaleX > 1 && monitor.scaleX < 1.1))
-
4832 monitor.scaleX = 1;
-
4833
-
4834 if ((monitor.scaleY > 1 && monitor.scaleY < 1.1))
-
4835 monitor.scaleY = 1;
-
4836 }
-
4837
-
4838 #ifndef RGFW_NO_DPI
-
4839 XRRFreeCrtcInfo(ci);
- -
4841 #endif
+
4809 if (physW && physH) {
+
4810 monitor.physW = physW;
+
4811 monitor.physH = physH;
+
4812 }
+
4813
+
4814 monitor.rect.x = ci->x;
+
4815 monitor.rect.y = ci->y;
+
4816
+
4817 float w = ci->width;
+
4818 float h = ci->height;
+
4819
+
4820 if (w && h) {
+
4821 monitor.rect.w = w;
+
4822 monitor.rect.h = h;
+
4823 }
+
4824 #endif
+
4825
+
4826 if (monitor.physW == 0 || monitor.physH == 0) {
+
4827 monitor.scaleX = 0;
+
4828 monitor.scaleY = 0;
+
4829 } else {
+
4830 float ppi_width = RGFW_ROUND((float)monitor.rect.w/(float)monitor.physW);
+
4831 float ppi_height = RGFW_ROUND((float)monitor.rect.h/(float)monitor.physH);
+
4832
+
4833 monitor.scaleX = (float) (ppi_width) / (float) dpi;
+
4834 monitor.scaleY = (float) (ppi_height) / (float) dpi;
+
4835
+
4836 if ((monitor.scaleX > 1 && monitor.scaleX < 1.1))
+
4837 monitor.scaleX = 1;
+
4838
+
4839 if ((monitor.scaleY > 1 && monitor.scaleY < 1.1))
+
4840 monitor.scaleY = 1;
+
4841 }
4842
-
4843 XCloseDisplay(display);
-
4844
-
4845 #ifdef RGFW_DEBUG
-
4846 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
-
4847 #endif
-
4848
-
4849 return monitor;
-
4850}
-
4851
-
4852RGFW_monitor RGFW_monitors[6];
- -
4854 RGFW_GOTO_WAYLAND(1);
-
4855 #ifdef RGFW_X11
-
4856 size_t i;
-
4857 for (i = 0; i < (size_t)ScreenCount(RGFW_root->src.display) && i < 6; i++)
-
4858 RGFW_monitors[i] = RGFW_XCreateMonitor(i);
-
4859
-
4860 return RGFW_monitors;
-
4861 #endif
-
4862 #ifdef RGFW_WAYLAND
-
4863 wayland: return RGFW_monitors; // TODO WAYLAND
-
4864 #endif
-
4865}
-
4866
- -
4868 RGFW_GOTO_WAYLAND(1);
-
4869 #ifdef RGFW_X11
-
4870 RGFW_ASSERT(RGFW_root != NULL);
-
4871 return RGFW_XCreateMonitor(DefaultScreen(RGFW_root->src.display));
-
4872 #endif
-
4873 #ifdef RGFW_WAYLAND
-
4874 wayland: return (RGFW_monitor){ }; // TODO WAYLAND
-
4875 #endif
-
4876}
-
4877
- -
4879 RGFW_ASSERT(win != NULL);
-
4880 RGFW_GOTO_WAYLAND(1);
-
4881#ifdef RGFW_X11
-
4882 XWindowAttributes attrs;
-
4883 if (!XGetWindowAttributes(win->src.display, win->src.window, &attrs)) {
-
4884 return (RGFW_monitor){};
-
4885 }
-
4886
-
4887 #ifndef RGFW_NO_DPI
-
4888 XRRScreenResources* screenRes = XRRGetScreenResources(win->src.display, DefaultRootWindow(win->src.display));
-
4889 if (screenRes == NULL) {
-
4890 return (RGFW_monitor){};
-
4891 }
-
4892
-
4893 for (int i = 0; i < screenRes->ncrtc; i++) {
-
4894 XRRCrtcInfo* crtcInfo = XRRGetCrtcInfo(win->src.display, screenRes, screenRes->crtcs[i]);
-
4895 if (!crtcInfo) continue;
-
4896
-
4897 int monitorX = crtcInfo->x;
-
4898 int monitorY = crtcInfo->y;
-
4899 int monitorWidth = crtcInfo->width;
-
4900 int monitorHeight = crtcInfo->height;
+
4843 #ifndef RGFW_NO_DPI
+
4844 XRRFreeCrtcInfo(ci);
+ +
4846 #endif
+
4847
+
4848 XCloseDisplay(display);
+
4849
+
4850 #ifdef RGFW_DEBUG
+
4851 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
+
4852 #endif
+
4853
+
4854 return monitor;
+
4855}
+
4856
+
4857RGFW_monitor RGFW_monitors[6];
+ +
4859 RGFW_GOTO_WAYLAND(1);
+
4860 #ifdef RGFW_X11
+
4861 size_t i;
+
4862 for (i = 0; i < (size_t)ScreenCount(RGFW_root->src.display) && i < 6; i++)
+
4863 RGFW_monitors[i] = RGFW_XCreateMonitor(i);
+
4864
+
4865 return RGFW_monitors;
+
4866 #endif
+
4867 #ifdef RGFW_WAYLAND
+
4868 wayland: return RGFW_monitors; // TODO WAYLAND
+
4869 #endif
+
4870}
+
4871
+ +
4873 RGFW_GOTO_WAYLAND(1);
+
4874 #ifdef RGFW_X11
+
4875 RGFW_ASSERT(RGFW_root != NULL);
+
4876 return RGFW_XCreateMonitor(DefaultScreen(RGFW_root->src.display));
+
4877 #endif
+
4878 #ifdef RGFW_WAYLAND
+
4879 wayland: return (RGFW_monitor){ }; // TODO WAYLAND
+
4880 #endif
+
4881}
+
4882
+ +
4884 RGFW_ASSERT(win != NULL);
+
4885 RGFW_GOTO_WAYLAND(1);
+
4886#ifdef RGFW_X11
+
4887 XWindowAttributes attrs;
+
4888 if (!XGetWindowAttributes(win->src.display, win->src.window, &attrs)) {
+
4889 return (RGFW_monitor){};
+
4890 }
+
4891
+
4892 #ifndef RGFW_NO_DPI
+
4893 XRRScreenResources* screenRes = XRRGetScreenResources(win->src.display, DefaultRootWindow(win->src.display));
+
4894 if (screenRes == NULL) {
+
4895 return (RGFW_monitor){};
+
4896 }
+
4897
+
4898 for (int i = 0; i < screenRes->ncrtc; i++) {
+
4899 XRRCrtcInfo* crtcInfo = XRRGetCrtcInfo(win->src.display, screenRes, screenRes->crtcs[i]);
+
4900 if (!crtcInfo) continue;
4901
-
4902 if (attrs.x >= monitorX &&
-
4903 attrs.x < monitorX + monitorWidth &&
-
4904 attrs.y >= monitorY &&
-
4905 attrs.y < monitorY + monitorHeight) {
-
4906 XRRFreeCrtcInfo(crtcInfo);
-
4907 XRRFreeScreenResources(screenRes);
-
4908 return RGFW_XCreateMonitor(i);
-
4909 }
-
4910
-
4911 XRRFreeCrtcInfo(crtcInfo);
-
4912 }
-
4913
-
4914 XRRFreeScreenResources(screenRes);
-
4915 #else
-
4916 size_t i;
-
4917 for (i = 0; i < (size_t)ScreenCount(RGFW_root->src.display) && i < 6; i++) {
-
4918 Screen* screen = ScreenOfDisplay(RGFW_root->src.display, i);
-
4919 if (attrs.x >= 0 && attrs.x < 0 + XWidthOfScreen(screen) &&
-
4920 attrs.y >= 0 && attrs.y < 0 + XHeightOfScreen(screen))
-
4921 return RGFW_XCreateMonitor(i);
-
4922 }
-
4923 #endif
-
4924#endif
-
4925wayland:
-
4926 return (RGFW_monitor){};
-
4927
-
4928}
-
4929
-
4930#if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
4931
- -
4933 if (win == NULL)
-
4934 glXMakeCurrent(NULL, (Drawable)NULL, (GLXContext) NULL);
-
4935 else
-
4936 glXMakeCurrent(win->src.display, (Drawable) win->src.window, (GLXContext) win->src.ctx);
-
4937}
-
4938#endif
-
4939
-
4940
- -
4942 RGFW_ASSERT(win != NULL);
-
4943 RGFW_GOTO_WAYLAND(0);
-
4944#ifdef RGFW_X11
-
4945 /* clear the window*/
-
4946 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
-
4947 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
4948 RGFW_area area = win->bufferSize;
-
4949 win->src.bitmap->data = (char*) win->buffer;
-
4950 #if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA)
-
4951 u32 x, y;
-
4952 for (y = 0; y < (u32)win->r.h; y++) {
-
4953 for (x = 0; x < (u32)win->r.w; x++) {
-
4954 u32 index = (y * 4 * area.w) + x * 4;
-
4955
-
4956 u8 red = win->src.bitmap->data[index];
-
4957 win->src.bitmap->data[index] = win->buffer[index + 2];
-
4958 win->src.bitmap->data[index + 2] = red;
-
4959
-
4960 }
-
4961 }
-
4962 #endif
-
4963 XPutImage(win->src.display, win->src.window, win->src.gc, win->src.bitmap, 0, 0, 0, 0, win->bufferSize.w, win->bufferSize.h);
-
4964 win->src.bitmap->data = NULL;
-
4965 #endif
-
4966 }
-
4967
-
4968 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
-
4969 #ifdef RGFW_EGL
-
4970 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
-
4971 #elif defined(RGFW_OPENGL)
-
4972 glXSwapBuffers(win->src.display, win->src.window);
-
4973 #endif
-
4974 }
-
4975 return;
-
4976#endif
-
4977#ifdef RGFW_WAYLAND
-
4978 wayland:
-
4979 #if defined(RGFW_BUFFER) || defined(RGFW_OSMESA)
-
4980 #if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA)
-
4981 for (u32 y = 0; y < (u32)win->r.h; y++) {
-
4982 for (u32 x = 0; x < (u32)win->r.w; x++) {
-
4983 u32 index = (y * 4 * win->r.w) + x * 4;
-
4984 u32 index2 = (y * 4 * win->bufferSize.w) + x * 4;
-
4985
-
4986 u8 red = win->buffer[index2];
-
4987 win->src.buffer[index] = win->buffer[index2 + 2];
-
4988 win->src.buffer[index + 1] = win->buffer[index2 + 1];
-
4989 win->src.buffer[index + 2] = red;
-
4990 }
-
4991 }
-
4992 #else
-
4993 for (size_t y = 0; y < win->r.h; y++) {
-
4994 u32 index = (y * 4 * win->r.w);
-
4995 u32 index2 = (y * 4 * win->bufferSize.w);
-
4996 RGFW_MEMCPY(&win->src.buffer[index], &win->buffer[index2], win->r.w * 4);
-
4997 }
-
4998 #endif
-
4999
-
5000 wl_surface_frame_done(win, NULL, 0);
-
5001 if (!(win->_flags & RGFW_NO_GPU_RENDER))
-
5002 #endif
-
5003 {
-
5004 #ifdef RGFW_OPENGL
-
5005 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
-
5006 #endif
-
5007 }
-
5008
-
5009 wl_surface_commit(win->src.surface);
-
5010#endif
-
5011}
-
5012
-
5013#if !defined(RGFW_EGL)
-
5014
-
5015void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
-
5016 RGFW_ASSERT(win != NULL);
+
4902 int monitorX = crtcInfo->x;
+
4903 int monitorY = crtcInfo->y;
+
4904 int monitorWidth = crtcInfo->width;
+
4905 int monitorHeight = crtcInfo->height;
+
4906
+
4907 if (attrs.x >= monitorX &&
+
4908 attrs.x < monitorX + monitorWidth &&
+
4909 attrs.y >= monitorY &&
+
4910 attrs.y < monitorY + monitorHeight) {
+
4911 XRRFreeCrtcInfo(crtcInfo);
+
4912 XRRFreeScreenResources(screenRes);
+
4913 return RGFW_XCreateMonitor(i);
+
4914 }
+
4915
+
4916 XRRFreeCrtcInfo(crtcInfo);
+
4917 }
+
4918
+
4919 XRRFreeScreenResources(screenRes);
+
4920 #else
+
4921 size_t i;
+
4922 for (i = 0; i < (size_t)ScreenCount(RGFW_root->src.display) && i < 6; i++) {
+
4923 Screen* screen = ScreenOfDisplay(RGFW_root->src.display, i);
+
4924 if (attrs.x >= 0 && attrs.x < 0 + XWidthOfScreen(screen) &&
+
4925 attrs.y >= 0 && attrs.y < 0 + XHeightOfScreen(screen))
+
4926 return RGFW_XCreateMonitor(i);
+
4927 }
+
4928 #endif
+
4929#endif
+
4930wayland:
+
4931 return (RGFW_monitor){};
+
4932
+
4933}
+
4934
+
4935#if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
4936
+ +
4938 if (win == NULL)
+
4939 glXMakeCurrent(NULL, (Drawable)NULL, (GLXContext) NULL);
+
4940 else
+
4941 glXMakeCurrent(win->src.display, (Drawable) win->src.window, (GLXContext) win->src.ctx);
+
4942}
+
4943#endif
+
4944
+
4945
+ +
4947 RGFW_ASSERT(win != NULL);
+
4948 RGFW_GOTO_WAYLAND(0);
+
4949#ifdef RGFW_X11
+
4950 /* clear the window*/
+
4951 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
+
4952 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
4953 RGFW_area area = win->bufferSize;
+
4954 win->src.bitmap->data = (char*) win->buffer;
+
4955 #if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA)
+
4956 u32 x, y;
+
4957 for (y = 0; y < (u32)win->r.h; y++) {
+
4958 for (x = 0; x < (u32)win->r.w; x++) {
+
4959 u32 index = (y * 4 * area.w) + x * 4;
+
4960
+
4961 u8 red = win->src.bitmap->data[index];
+
4962 win->src.bitmap->data[index] = win->buffer[index + 2];
+
4963 win->src.bitmap->data[index + 2] = red;
+
4964
+
4965 }
+
4966 }
+
4967 #endif
+
4968 XPutImage(win->src.display, win->src.window, win->src.gc, win->src.bitmap, 0, 0, 0, 0, win->bufferSize.w, win->bufferSize.h);
+
4969 win->src.bitmap->data = NULL;
+
4970 #endif
+
4971 }
+
4972
+
4973 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
+
4974 #ifdef RGFW_EGL
+
4975 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
+
4976 #elif defined(RGFW_OPENGL)
+
4977 glXSwapBuffers(win->src.display, win->src.window);
+
4978 #endif
+
4979 }
+
4980 return;
+
4981#endif
+
4982#ifdef RGFW_WAYLAND
+
4983 wayland:
+
4984 #if defined(RGFW_BUFFER) || defined(RGFW_OSMESA)
+
4985 #if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA)
+
4986 for (u32 y = 0; y < (u32)win->r.h; y++) {
+
4987 for (u32 x = 0; x < (u32)win->r.w; x++) {
+
4988 u32 index = (y * 4 * win->r.w) + x * 4;
+
4989 u32 index2 = (y * 4 * win->bufferSize.w) + x * 4;
+
4990
+
4991 u8 red = win->buffer[index2];
+
4992 win->src.buffer[index] = win->buffer[index2 + 2];
+
4993 win->src.buffer[index + 1] = win->buffer[index2 + 1];
+
4994 win->src.buffer[index + 2] = red;
+
4995 }
+
4996 }
+
4997 #else
+
4998 for (size_t y = 0; y < win->r.h; y++) {
+
4999 u32 index = (y * 4 * win->r.w);
+
5000 u32 index2 = (y * 4 * win->bufferSize.w);
+
5001 RGFW_MEMCPY(&win->src.buffer[index], &win->buffer[index2], win->r.w * 4);
+
5002 }
+
5003 #endif
+
5004
+
5005 wl_surface_frame_done(win, NULL, 0);
+
5006 if (!(win->_flags & RGFW_NO_GPU_RENDER))
+
5007 #endif
+
5008 {
+
5009 #ifdef RGFW_OPENGL
+
5010 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
+
5011 #endif
+
5012 }
+
5013
+
5014 wl_surface_commit(win->src.surface);
+
5015#endif
+
5016}
5017
-
5018 #if defined(RGFW_OPENGL)
-
5019 ((PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((GLubyte*) "glXSwapIntervalEXT"))(win->src.display, win->src.window, swapInterval);
-
5020 #else
-
5021 RGFW_UNUSED(swapInterval);
-
5022 #endif
-
5023}
-
5024#endif
-
5025
-
5026
-
5027void RGFW_window_close(RGFW_window* win) {
-
5028 RGFW_ASSERT(win != NULL);
-
5029 RGFW_GOTO_WAYLAND(0);
-
5030 #ifdef RGFW_X11
-
5031 /* ungrab pointer if it was grabbed */
-
5032 if (win->_flags & RGFW_HOLD_MOUSE)
-
5033 XUngrabPointer(win->src.display, CurrentTime);
-
5034
-
5035 #ifdef RGFW_EGL
-
5036 RGFW_closeEGL(win);
-
5037 #endif
-
5038
-
5039 if (RGFW_hiddenMouse != NULL && (RGFW_windowsOpen - 1) <= 0) {
-
5040 RGFW_freeMouse(RGFW_hiddenMouse);
-
5041 RGFW_hiddenMouse = 0;
-
5042 }
+
5018#if !defined(RGFW_EGL)
+
5019
+
5020void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
+
5021 RGFW_ASSERT(win != NULL);
+
5022
+
5023 #if defined(RGFW_OPENGL)
+
5024 ((PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((GLubyte*) "glXSwapIntervalEXT"))(win->src.display, win->src.window, swapInterval);
+
5025 #else
+
5026 RGFW_UNUSED(swapInterval);
+
5027 #endif
+
5028}
+
5029#endif
+
5030
+
5031
+
5032void RGFW_window_close(RGFW_window* win) {
+
5033 RGFW_ASSERT(win != NULL);
+
5034 RGFW_GOTO_WAYLAND(0);
+
5035 #ifdef RGFW_X11
+
5036 /* ungrab pointer if it was grabbed */
+
5037 if (win->_flags & RGFW_HOLD_MOUSE)
+
5038 XUngrabPointer(win->src.display, CurrentTime);
+
5039
+
5040 #ifdef RGFW_EGL
+
5041 RGFW_closeEGL(win);
+
5042 #endif
5043
-
5044 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
5045 if (win->buffer != NULL) {
-
5046 if ((win->_flags & RGFW_BUFFER_ALLOC))
-
5047 RGFW_FREE(win->buffer);
-
5048 XDestroyImage((XImage*) win->src.bitmap);
-
5049 XFreeGC(win->src.display, win->src.gc);
-
5050 }
-
5051 #endif
-
5052
-
5053 if (win->src.display) {
-
5054 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
-
5055 glXDestroyContext(win->src.display, win->src.ctx);
+
5044 if (RGFW_hiddenMouse != NULL && (RGFW_windowsOpen - 1) <= 0) {
+
5045 RGFW_freeMouse(RGFW_hiddenMouse);
+
5046 RGFW_hiddenMouse = 0;
+
5047 }
+
5048
+
5049 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
5050 if (win->buffer != NULL) {
+
5051 if ((win->_flags & RGFW_BUFFER_ALLOC))
+
5052 RGFW_FREE(win->buffer);
+
5053 XDestroyImage((XImage*) win->src.bitmap);
+
5054 XFreeGC(win->src.display, win->src.gc);
+
5055 }
5056 #endif
5057
-
5058 if (win == RGFW_root)
-
5059 RGFW_root = NULL;
-
5060
-
5061 if ((Drawable) win->src.window)
-
5062 XDestroyWindow(win->src.display, (Drawable) win->src.window);
-
5064 XCloseDisplay(win->src.display);
-
5065 }
-
5066
-
5067 /* set cleared display / window to NULL for error checking */
-
5068 win->src.display = 0;
-
5069 win->src.window = 0;
-
5070
-
5071 RGFW_windowsOpen--;
-
5072
-
5073 #define RGFW_FREE_LIBRARY(x) if (x != NULL) dlclose(x); x = NULL;
-
5074 if (RGFW_windowsOpen <= 0) {
-
5075 #if !defined(RGFW_NO_X11_CURSOR_PRELOAD) && !defined(RGFW_NO_X11_CURSOR)
-
5076 RGFW_FREE_LIBRARY(X11Cursorhandle);
-
5077 #endif
-
5078 #if !defined(RGFW_NO_X11_XI_PRELOAD)
-
5079 RGFW_FREE_LIBRARY(X11Xihandle);
-
5080 #endif
-
5081
-
5082 #ifdef RGFW_USE_XDL
-
5083 XDL_close();
-
5084 #endif
-
5085
-
5086 #ifndef RGFW_NO_PASSTHROUGH
-
5087 RGFW_FREE_LIBRARY(RGFW_libxshape);
-
5088 #endif
-
5089
-
5090 #ifndef RGFW_NO_LINUX
-
5091 if (RGFW_eventWait_forceStop[0] || RGFW_eventWait_forceStop[1]){
-
5092 close(RGFW_eventWait_forceStop[0]);
-
5093 close(RGFW_eventWait_forceStop[1]);
-
5094 }
-
5095
-
5096 u8 i;
-
5097 for (i = 0; i < RGFW_gamepadCount; i++) {
-
5098 if(RGFW_gamepads[i])
-
5099 close(RGFW_gamepads[i]);
-
5100 }
-
5101 #endif
-
5102 }
-
5103 RGFW_clipboard_switch(NULL);
-
5104 if ((win->_flags & RGFW_WINDOW_ALLOC))
-
5105 RGFW_FREE(win);
-
5106 return;
-
5107 #endif
-
5108
-
5109 #ifdef RGFW_WAYLAND
-
5110 wayland:
-
5111
-
5112 #ifdef RGFW_X11
-
5113 XDestroyWindow(win->src.display, (Drawable) win->src.window);
-
5114 XCloseDisplay(win->src.display);
-
5115 #endif
+
5058 if (win->src.display) {
+
5059 #if defined(RGFW_OPENGL) && !defined(RGFW_EGL)
+
5060 glXDestroyContext(win->src.display, win->src.ctx);
+
5061 #endif
+
5062
+
5063 if (win == RGFW_root)
+
5064 RGFW_root = NULL;
+
5065
+
5066 if ((Drawable) win->src.window)
+
5067 XDestroyWindow(win->src.display, (Drawable) win->src.window);
+
5069 XCloseDisplay(win->src.display);
+
5070 }
+
5071
+
5072 /* set cleared display / window to NULL for error checking */
+
5073 win->src.display = 0;
+
5074 win->src.window = 0;
+
5075
+
5076 RGFW_windowsOpen--;
+
5077
+
5078 #define RGFW_FREE_LIBRARY(x) if (x != NULL) dlclose(x); x = NULL;
+
5079 if (RGFW_windowsOpen <= 0) {
+
5080 #if !defined(RGFW_NO_X11_CURSOR_PRELOAD) && !defined(RGFW_NO_X11_CURSOR)
+
5081 RGFW_FREE_LIBRARY(X11Cursorhandle);
+
5082 #endif
+
5083 #if !defined(RGFW_NO_X11_XI_PRELOAD)
+
5084 RGFW_FREE_LIBRARY(X11Xihandle);
+
5085 #endif
+
5086
+
5087 #ifdef RGFW_USE_XDL
+
5088 XDL_close();
+
5089 #endif
+
5090
+
5091 #ifndef RGFW_NO_PASSTHROUGH
+
5092 RGFW_FREE_LIBRARY(RGFW_libxshape);
+
5093 #endif
+
5094
+
5095 #ifndef RGFW_NO_LINUX
+
5096 if (RGFW_eventWait_forceStop[0] || RGFW_eventWait_forceStop[1]){
+
5097 close(RGFW_eventWait_forceStop[0]);
+
5098 close(RGFW_eventWait_forceStop[1]);
+
5099 }
+
5100
+
5101 u8 i;
+
5102 for (i = 0; i < RGFW_gamepadCount; i++) {
+
5103 if(RGFW_gamepads[i])
+
5104 close(RGFW_gamepads[i]);
+
5105 }
+
5106 #endif
+
5107 }
+
5108 RGFW_clipboard_switch(NULL);
+
5109 if ((win->_flags & RGFW_WINDOW_ALLOC))
+
5110 RGFW_FREE(win);
+
5111 return;
+
5112 #endif
+
5113
+
5114 #ifdef RGFW_WAYLAND
+
5115 wayland:
5116
-
5117 #ifdef RGFW_EGL
-
5118 RGFW_closeEGL(win);
-
5119 #endif
-
5120
-
5121 if (RGFW_root == win) {
-
5122 RGFW_root = NULL;
-
5123 }
-
5124
-
5125 xdg_toplevel_destroy(win->src.xdg_toplevel);
-
5126 xdg_surface_destroy(win->src.xdg_surface);
-
5127 wl_surface_destroy(win->src.surface);
-
5128
-
5129 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
5130 wl_buffer_destroy(win->src.wl_buffer);
-
5131 if ((win->_flags & RGFW_BUFFER_ALLOC))
-
5132 RGFW_FREE(win->buffer);
+
5117 #ifdef RGFW_X11
+
5118 XDestroyWindow(win->src.display, (Drawable) win->src.window);
+
5119 XCloseDisplay(win->src.display);
+
5120 #endif
+
5121
+
5122 #ifdef RGFW_EGL
+
5123 RGFW_closeEGL(win);
+
5124 #endif
+
5125
+
5126 if (RGFW_root == win) {
+
5127 RGFW_root = NULL;
+
5128 }
+
5129
+
5130 xdg_toplevel_destroy(win->src.xdg_toplevel);
+
5131 xdg_surface_destroy(win->src.xdg_surface);
+
5132 wl_surface_destroy(win->src.surface);
5133
-
5134 munmap(win->src.buffer, win->r.w * win->r.h * 4);
-
5135 #endif
-
5136
-
5137 wl_display_disconnect(win->src.wl_display);
-
5138 RGFW_clipboard_switch(NULL);
-
5139 if ((win->_flags & RGFW_WINDOW_ALLOC))
-
5140 RGFW_FREE(win);
-
5141 #endif
-
5142}
-
5143
-
5144
-
5145/*
-
5146 End of X11 linux / wayland / unix defines
-
5147*/
+
5134 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
5135 wl_buffer_destroy(win->src.wl_buffer);
+
5136 if ((win->_flags & RGFW_BUFFER_ALLOC))
+
5137 RGFW_FREE(win->buffer);
+
5138
+
5139 munmap(win->src.buffer, win->r.w * win->r.h * 4);
+
5140 #endif
+
5141
+
5142 wl_display_disconnect(win->src.wl_display);
+
5143 RGFW_clipboard_switch(NULL);
+
5144 if ((win->_flags & RGFW_WINDOW_ALLOC))
+
5145 RGFW_FREE(win);
+
5146 #endif
+
5147}
5148
-
5149#include <fcntl.h>
-
5150#include <poll.h>
-
5151#include <unistd.h>
-
5152
-
5153void RGFW_stopCheckEvents(void) {
-
5154
-
5155 RGFW_eventWait_forceStop[2] = 1;
-
5156 while (1) {
-
5157 const char byte = 0;
-
5158 const ssize_t result = write(RGFW_eventWait_forceStop[1], &byte, 1);
-
5159 if (result == 1 || result == -1)
-
5160 break;
-
5161 }
-
5162}
-
5163
-
5164void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
-
5165 if (waitMS == 0)
-
5166 return;
-
5167
-
5168 u8 i;
-
5169 if (RGFW_eventWait_forceStop[0] == 0 || RGFW_eventWait_forceStop[1] == 0) {
-
5170 if (pipe(RGFW_eventWait_forceStop) != -1) {
-
5171 fcntl(RGFW_eventWait_forceStop[0], F_GETFL, 0);
-
5172 fcntl(RGFW_eventWait_forceStop[0], F_GETFD, 0);
-
5173 fcntl(RGFW_eventWait_forceStop[1], F_GETFL, 0);
-
5174 fcntl(RGFW_eventWait_forceStop[1], F_GETFD, 0);
-
5175 }
-
5176 }
-
5177
-
5178 struct pollfd fds[] = {
-
5179 #ifdef RGFW_WAYLAND
-
5180 { wl_display_get_fd(win->src.wl_display), POLLIN, 0 },
-
5181 #else
-
5182 { ConnectionNumber(win->src.display), POLLIN, 0 },
-
5183 #endif
-
5184 { RGFW_eventWait_forceStop[0], POLLIN, 0 },
-
5185 #if defined(__linux__)
-
5186 { -1, POLLIN, 0 }, {-1, POLLIN, 0 }, {-1, POLLIN, 0 }, {-1, POLLIN, 0}
-
5187 #endif
-
5188 };
-
5189
-
5190 u8 index = 2;
-
5191
-
5192 #if defined(__linux__)
-
5193 for (i = 0; i < RGFW_gamepadCount; i++) {
-
5194 if (RGFW_gamepads[i] == 0)
-
5195 continue;
+
5149
+
5150/*
+
5151 End of X11 linux / wayland / unix defines
+
5152*/
+
5153
+
5154#include <fcntl.h>
+
5155#include <poll.h>
+
5156#include <unistd.h>
+
5157
+
5158void RGFW_stopCheckEvents(void) {
+
5159
+
5160 RGFW_eventWait_forceStop[2] = 1;
+
5161 while (1) {
+
5162 const char byte = 0;
+
5163 const ssize_t result = write(RGFW_eventWait_forceStop[1], &byte, 1);
+
5164 if (result == 1 || result == -1)
+
5165 break;
+
5166 }
+
5167}
+
5168
+
5169void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
+
5170 if (waitMS == 0)
+
5171 return;
+
5172
+
5173 u8 i;
+
5174 if (RGFW_eventWait_forceStop[0] == 0 || RGFW_eventWait_forceStop[1] == 0) {
+
5175 if (pipe(RGFW_eventWait_forceStop) != -1) {
+
5176 fcntl(RGFW_eventWait_forceStop[0], F_GETFL, 0);
+
5177 fcntl(RGFW_eventWait_forceStop[0], F_GETFD, 0);
+
5178 fcntl(RGFW_eventWait_forceStop[1], F_GETFL, 0);
+
5179 fcntl(RGFW_eventWait_forceStop[1], F_GETFD, 0);
+
5180 }
+
5181 }
+
5182
+
5183 struct pollfd fds[] = {
+
5184 #ifdef RGFW_WAYLAND
+
5185 { wl_display_get_fd(win->src.wl_display), POLLIN, 0 },
+
5186 #else
+
5187 { ConnectionNumber(win->src.display), POLLIN, 0 },
+
5188 #endif
+
5189 { RGFW_eventWait_forceStop[0], POLLIN, 0 },
+
5190 #if defined(__linux__)
+
5191 { -1, POLLIN, 0 }, {-1, POLLIN, 0 }, {-1, POLLIN, 0 }, {-1, POLLIN, 0}
+
5192 #endif
+
5193 };
+
5194
+
5195 u8 index = 2;
5196
-
5197 fds[index].fd = RGFW_gamepads[i];
-
5198 index++;
-
5199 }
-
5200 #endif
+
5197 #if defined(__linux__)
+
5198 for (i = 0; i < RGFW_gamepadCount; i++) {
+
5199 if (RGFW_gamepads[i] == 0)
+
5200 continue;
5201
-
5202
-
5203 u64 start = RGFW_getTimeNS();
-
5204
-
5205
-
5206 #ifdef RGFW_WAYLAND
-
5207 while (wl_display_dispatch(win->src.wl_display) <= 0 && waitMS >= -1) {
-
5208 #else
-
5209 while (XPending(win->src.display) == 0 && waitMS >= -1) {
-
5210 #endif
-
5211 if (poll(fds, index, waitMS) <= 0)
-
5212 break;
-
5213
-
5214 if (waitMS > 0) {
-
5215 waitMS -= (RGFW_getTimeNS() - start) / 1e+6;
-
5216 }
-
5217 }
+
5202 fds[index].fd = RGFW_gamepads[i];
+
5203 index++;
+
5204 }
+
5205 #endif
+
5206
+
5207
+
5208 u64 start = RGFW_getTimeNS();
+
5209
+
5210
+
5211 #ifdef RGFW_WAYLAND
+
5212 while (wl_display_dispatch(win->src.wl_display) <= 0 && waitMS >= -1) {
+
5213 #else
+
5214 while (XPending(win->src.display) == 0 && waitMS >= -1) {
+
5215 #endif
+
5216 if (poll(fds, index, waitMS) <= 0)
+
5217 break;
5218
-
5219 /* drain any data in the stop request */
-
5220 if (RGFW_eventWait_forceStop[2]) {
-
5221 char data[64];
-
5222 (void)!read(RGFW_eventWait_forceStop[0], data, sizeof(data));
+
5219 if (waitMS > 0) {
+
5220 waitMS -= (RGFW_getTimeNS() - start) / 1e+6;
+
5221 }
+
5222 }
5223
-
5224 RGFW_eventWait_forceStop[2] = 0;
-
5225 }
-
5226}
-
5227
-
5228u64 RGFW_getTimeNS(void) {
-
5229 struct timespec ts = { 0, 0 };
-
5230 #ifndef RGFW_NO_UNIX_CLOCK
-
5231 clock_gettime(1, &ts);
-
5232 #endif
-
5233 unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
-
5234
-
5235 return nanoSeconds;
-
5236}
-
5237
-
5238u64 RGFW_getTime(void) {
-
5239 struct timespec ts = { 0, 0 };
-
5240 #ifndef RGFW_NO_UNIX_CLOCK
-
5241 clock_gettime(1, &ts);
-
5242 #endif
-
5243 unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
-
5244
-
5245 return (double)(nanoSeconds) * 1e-9;
-
5246}
-
5247#endif /* end of wayland or X11 defines*/
-
5248
+
5224 /* drain any data in the stop request */
+
5225 if (RGFW_eventWait_forceStop[2]) {
+
5226 char data[64];
+
5227 (void)!read(RGFW_eventWait_forceStop[0], data, sizeof(data));
+
5228
+
5229 RGFW_eventWait_forceStop[2] = 0;
+
5230 }
+
5231}
+
5232
+
5233u64 RGFW_getTimeNS(void) {
+
5234 struct timespec ts = { 0, 0 };
+
5235 #ifndef RGFW_NO_UNIX_CLOCK
+
5236 clock_gettime(1, &ts);
+
5237 #endif
+
5238 unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
+
5239
+
5240 return nanoSeconds;
+
5241}
+
5242
+
5243u64 RGFW_getTime(void) {
+
5244 struct timespec ts = { 0, 0 };
+
5245 #ifndef RGFW_NO_UNIX_CLOCK
+
5246 clock_gettime(1, &ts);
+
5247 #endif
+
5248 unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
5249
-
5250/*
-
5251
-
5252 Start of Windows defines
-
5253
-
5254
-
5255*/
-
5256
-
5257#ifdef RGFW_WINDOWS
-
5258#define WIN32_LEAN_AND_MEAN
-
5259#define OEMRESOURCE
-
5260#include <windows.h>
+
5250 return (double)(nanoSeconds) * 1e-9;
+
5251}
+
5252#endif /* end of wayland or X11 defines*/
+
5253
+
5254
+
5255/*
+
5256
+
5257 Start of Windows defines
+
5258
+
5259
+
5260*/
5261
-
5262#include <processthreadsapi.h>
-
5263#include <windowsx.h>
-
5264#include <shellapi.h>
-
5265#include <shellscalingapi.h>
-
5266#include <wchar.h>
-
5267#include <locale.h>
-
5268#include <winuser.h>
-
5269
-
5270__declspec(dllimport) int __stdcall WideCharToMultiByte( UINT CodePage, DWORD dwFlags, const WCHAR* lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
-
5271
-
5272#ifndef RGFW_NO_XINPUT
-
5273 typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*);
-
5274 PFN_XInputGetState XInputGetStateSRC = NULL;
-
5275 #define XInputGetState XInputGetStateSRC
+
5262#ifdef RGFW_WINDOWS
+
5263#define WIN32_LEAN_AND_MEAN
+
5264#define OEMRESOURCE
+
5265#include <windows.h>
+
5266
+
5267#include <processthreadsapi.h>
+
5268#include <windowsx.h>
+
5269#include <shellapi.h>
+
5270#include <shellscalingapi.h>
+
5271#include <wchar.h>
+
5272#include <locale.h>
+
5273#include <winuser.h>
+
5274
+
5275__declspec(dllimport) int __stdcall WideCharToMultiByte( UINT CodePage, DWORD dwFlags, const WCHAR* lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
5276
-
5277 typedef DWORD (WINAPI * PFN_XInputGetKeystroke)(DWORD, DWORD, PXINPUT_KEYSTROKE);
-
5278 PFN_XInputGetKeystroke XInputGetKeystrokeSRC = NULL;
-
5279 #define XInputGetKeystroke XInputGetKeystrokeSRC
-
5280
-
5281 static HMODULE RGFW_XInput_dll = NULL;
-
5282#endif
-
5283
-
5284u32 RGFW_mouseIconSrc[] = {OCR_NORMAL, OCR_NORMAL, OCR_IBEAM, OCR_CROSS, OCR_HAND, OCR_SIZEWE, OCR_SIZENS, OCR_SIZENWSE, OCR_SIZENESW, OCR_SIZEALL, OCR_NO};
+
5277#ifndef RGFW_NO_XINPUT
+
5278 typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*);
+
5279 PFN_XInputGetState XInputGetStateSRC = NULL;
+
5280 #define XInputGetState XInputGetStateSRC
+
5281
+
5282 typedef DWORD (WINAPI * PFN_XInputGetKeystroke)(DWORD, DWORD, PXINPUT_KEYSTROKE);
+
5283 PFN_XInputGetKeystroke XInputGetKeystrokeSRC = NULL;
+
5284 #define XInputGetKeystroke XInputGetKeystrokeSRC
5285
-
5286char* RGFW_createUTF8FromWideStringWin32(const WCHAR* source);
-
5287
-
5288#define GL_FRONT 0x0404
-
5289#define GL_BACK 0x0405
-
5290#define GL_LEFT 0x0406
-
5291#define GL_RIGHT 0x0407
+
5286 static HMODULE RGFW_XInput_dll = NULL;
+
5287#endif
+
5288
+
5289u32 RGFW_mouseIconSrc[] = {OCR_NORMAL, OCR_NORMAL, OCR_IBEAM, OCR_CROSS, OCR_HAND, OCR_SIZEWE, OCR_SIZENS, OCR_SIZENWSE, OCR_SIZENESW, OCR_SIZEALL, OCR_NO};
+
5290
+
5291char* RGFW_createUTF8FromWideStringWin32(const WCHAR* source);
5292
-
5293typedef int (*PFN_wglGetSwapIntervalEXT)(void);
-
5294PFN_wglGetSwapIntervalEXT wglGetSwapIntervalEXTSrc = NULL;
-
5295#define wglGetSwapIntervalEXT wglGetSwapIntervalEXTSrc
-
5296
+
5293#define GL_FRONT 0x0404
+
5294#define GL_BACK 0x0405
+
5295#define GL_LEFT 0x0406
+
5296#define GL_RIGHT 0x0407
5297
-
5298void* RGFWgamepadApi = NULL;
-
5299
-
5300/* these two wgl functions need to be preloaded */
-
5301typedef HGLRC (WINAPI *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hdc, HGLRC hglrc, const int *attribList);
-
5302PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
-
5303
-
5304#ifndef RGFW_EGL
-
5305 static HMODULE RGFW_wgl_dll = NULL;
-
5306#endif
-
5307
-
5308#ifndef RGFW_NO_LOAD_WGL
-
5309 typedef HGLRC(WINAPI* PFN_wglCreateContext)(HDC);
-
5310 typedef BOOL(WINAPI* PFN_wglDeleteContext)(HGLRC);
-
5311 typedef PROC(WINAPI* PFN_wglGetProcAddress)(LPCSTR);
-
5312 typedef BOOL(WINAPI* PFN_wglMakeCurrent)(HDC, HGLRC);
-
5313 typedef HDC(WINAPI* PFN_wglGetCurrentDC)(void);
-
5314 typedef HGLRC(WINAPI* PFN_wglGetCurrentContext)(void);
-
5315 typedef BOOL(WINAPI* PFN_wglShareLists)(HGLRC, HGLRC);
-
5316
-
5317 PFN_wglCreateContext wglCreateContextSRC;
-
5318 PFN_wglDeleteContext wglDeleteContextSRC;
-
5319 PFN_wglGetProcAddress wglGetProcAddressSRC;
-
5320 PFN_wglMakeCurrent wglMakeCurrentSRC;
-
5321 PFN_wglGetCurrentDC wglGetCurrentDCSRC;
-
5322 PFN_wglGetCurrentContext wglGetCurrentContextSRC;
-
5323 PFN_wglShareLists wglShareListsSRC;
-
5324
-
5325 #define wglCreateContext wglCreateContextSRC
-
5326 #define wglDeleteContext wglDeleteContextSRC
-
5327 #define wglGetProcAddress wglGetProcAddressSRC
-
5328 #define wglMakeCurrent wglMakeCurrentSRC
-
5329 #define wglGetCurrentDC wglGetCurrentDCSRC
-
5330 #define wglGetCurrentContext wglGetCurrentContextSRC
-
5331 #define wglShareLists wglShareListsSRC
-
5332#endif
-
5333
-
5334#ifdef RGFW_OPENGL
-
5335 void* RGFW_getProcAddress(const char* procname) {
-
5336 void* proc = (void*) wglGetProcAddress(procname);
-
5337 if (proc)
-
5338 return proc;
-
5339
-
5340 return (void*) GetProcAddress(RGFW_wgl_dll, procname);
-
5341 }
-
5342
-
5343 typedef HRESULT (APIENTRY* PFNWGLCHOOSEPIXELFORMATARBPROC)(HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList, UINT nMaxFormats, int* piFormats, UINT* nNumFormats);
-
5344 static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL;
-
5345#endif
-
5346
-
5347RGFW_window RGFW_eventWindow;
-
5348
-
5349LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
-
5350 switch (message) {
-
5351 case WM_MOVE:
-
5352 RGFW_eventWindow.r.x = LOWORD(lParam);
-
5353 RGFW_eventWindow.r.y = HIWORD(lParam);
-
5354 RGFW_eventWindow.src.window = hWnd;
-
5355 return DefWindowProcA(hWnd, message, wParam, lParam);
-
5356 case WM_SIZE:
-
5357 RGFW_eventWindow.r.w = LOWORD(lParam);
-
5358 RGFW_eventWindow.r.h = HIWORD(lParam);
+
5298typedef int (*PFN_wglGetSwapIntervalEXT)(void);
+
5299PFN_wglGetSwapIntervalEXT wglGetSwapIntervalEXTSrc = NULL;
+
5300#define wglGetSwapIntervalEXT wglGetSwapIntervalEXTSrc
+
5301
+
5302
+
5303void* RGFWgamepadApi = NULL;
+
5304
+
5305/* these two wgl functions need to be preloaded */
+
5306typedef HGLRC (WINAPI *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hdc, HGLRC hglrc, const int *attribList);
+
5307PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
+
5308
+
5309#ifndef RGFW_EGL
+
5310 static HMODULE RGFW_wgl_dll = NULL;
+
5311#endif
+
5312
+
5313#ifndef RGFW_NO_LOAD_WGL
+
5314 typedef HGLRC(WINAPI* PFN_wglCreateContext)(HDC);
+
5315 typedef BOOL(WINAPI* PFN_wglDeleteContext)(HGLRC);
+
5316 typedef PROC(WINAPI* PFN_wglGetProcAddress)(LPCSTR);
+
5317 typedef BOOL(WINAPI* PFN_wglMakeCurrent)(HDC, HGLRC);
+
5318 typedef HDC(WINAPI* PFN_wglGetCurrentDC)(void);
+
5319 typedef HGLRC(WINAPI* PFN_wglGetCurrentContext)(void);
+
5320 typedef BOOL(WINAPI* PFN_wglShareLists)(HGLRC, HGLRC);
+
5321
+
5322 PFN_wglCreateContext wglCreateContextSRC;
+
5323 PFN_wglDeleteContext wglDeleteContextSRC;
+
5324 PFN_wglGetProcAddress wglGetProcAddressSRC;
+
5325 PFN_wglMakeCurrent wglMakeCurrentSRC;
+
5326 PFN_wglGetCurrentDC wglGetCurrentDCSRC;
+
5327 PFN_wglGetCurrentContext wglGetCurrentContextSRC;
+
5328 PFN_wglShareLists wglShareListsSRC;
+
5329
+
5330 #define wglCreateContext wglCreateContextSRC
+
5331 #define wglDeleteContext wglDeleteContextSRC
+
5332 #define wglGetProcAddress wglGetProcAddressSRC
+
5333 #define wglMakeCurrent wglMakeCurrentSRC
+
5334 #define wglGetCurrentDC wglGetCurrentDCSRC
+
5335 #define wglGetCurrentContext wglGetCurrentContextSRC
+
5336 #define wglShareLists wglShareListsSRC
+
5337#endif
+
5338
+
5339#ifdef RGFW_OPENGL
+
5340 void* RGFW_getProcAddress(const char* procname) {
+
5341 void* proc = (void*) wglGetProcAddress(procname);
+
5342 if (proc)
+
5343 return proc;
+
5344
+
5345 return (void*) GetProcAddress(RGFW_wgl_dll, procname);
+
5346 }
+
5347
+
5348 typedef HRESULT (APIENTRY* PFNWGLCHOOSEPIXELFORMATARBPROC)(HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList, UINT nMaxFormats, int* piFormats, UINT* nNumFormats);
+
5349 static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL;
+
5350#endif
+
5351
+
5352RGFW_window RGFW_eventWindow;
+
5353
+
5354LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+
5355 switch (message) {
+
5356 case WM_MOVE:
+
5357 RGFW_eventWindow.r.x = LOWORD(lParam);
+
5358 RGFW_eventWindow.r.y = HIWORD(lParam);
5359 RGFW_eventWindow.src.window = hWnd;
-
5360 return DefWindowProcA(hWnd, message, wParam, lParam); // Call DefWindowProc after handling
-
5361 default:
-
5362 return DefWindowProcA(hWnd, message, wParam, lParam);
-
5363 }
-
5364}
-
5365
-
5366#ifndef RGFW_NO_DPI
-
5367 static HMODULE RGFW_Shcore_dll = NULL;
-
5368 typedef HRESULT (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*);
-
5369 PFN_GetDpiForMonitor GetDpiForMonitorSRC = NULL;
-
5370 #define GetDpiForMonitor GetDpiForMonitorSRC
-
5371#endif
-
5372
-
5373#ifndef RGFW_NO_DWM
-
5374static HMODULE RGFW_dwm_dll = NULL;
-
5375typedef struct { DWORD dwFlags; int fEnable; HRGN hRgnBlur; int fTransitionOnMaximized;} DWM_BLURBEHIND;
-
5376typedef HRESULT (WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND, const DWM_BLURBEHIND*);
-
5377PFN_DwmEnableBlurBehindWindow DwmEnableBlurBehindWindowSRC = NULL;
-
5378#endif
-
5379
-
5380#if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
-
5381 static HMODULE RGFW_winmm_dll = NULL;
-
5382 typedef u32 (WINAPI * PFN_timeBeginPeriod)(u32);
-
5383 PFN_timeBeginPeriod timeBeginPeriodSRC = NULL;
-
5384 #define timeBeginPeriod timeBeginPeriodSRC
-
5385#elif !defined(RGFW_NO_WINMM)
-
5386 __declspec(dllimport) u32 __stdcall timeBeginPeriod(u32 uPeriod);
-
5387#endif
-
5388
-
5389#define RGFW_PROC_DEF(proc, name) if (name##SRC == NULL && proc != NULL) name##SRC = (PFN_##name)(void*)GetProcAddress(proc, #name)
-
5390
-
5391#ifndef RGFW_NO_XINPUT
-
5392void RGFW_loadXInput(void) {
-
5393 u32 i;
-
5394 static const char* names[] = {"xinput1_4.dll", "xinput9_1_0.dll", "xinput1_2.dll", "xinput1_1.dll"};
+
5360 return DefWindowProcA(hWnd, message, wParam, lParam);
+
5361 case WM_SIZE:
+
5362 RGFW_eventWindow.r.w = LOWORD(lParam);
+
5363 RGFW_eventWindow.r.h = HIWORD(lParam);
+
5364 RGFW_eventWindow.src.window = hWnd;
+
5365 return DefWindowProcA(hWnd, message, wParam, lParam); // Call DefWindowProc after handling
+
5366 default:
+
5367 return DefWindowProcA(hWnd, message, wParam, lParam);
+
5368 }
+
5369}
+
5370
+
5371#ifndef RGFW_NO_DPI
+
5372 static HMODULE RGFW_Shcore_dll = NULL;
+
5373 typedef HRESULT (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*);
+
5374 PFN_GetDpiForMonitor GetDpiForMonitorSRC = NULL;
+
5375 #define GetDpiForMonitor GetDpiForMonitorSRC
+
5376#endif
+
5377
+
5378#ifndef RGFW_NO_DWM
+
5379static HMODULE RGFW_dwm_dll = NULL;
+
5380typedef struct { DWORD dwFlags; int fEnable; HRGN hRgnBlur; int fTransitionOnMaximized;} DWM_BLURBEHIND;
+
5381typedef HRESULT (WINAPI * PFN_DwmEnableBlurBehindWindow)(HWND, const DWM_BLURBEHIND*);
+
5382PFN_DwmEnableBlurBehindWindow DwmEnableBlurBehindWindowSRC = NULL;
+
5383#endif
+
5384
+
5385#if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
+
5386 static HMODULE RGFW_winmm_dll = NULL;
+
5387 typedef u32 (WINAPI * PFN_timeBeginPeriod)(u32);
+
5388 PFN_timeBeginPeriod timeBeginPeriodSRC = NULL;
+
5389 #define timeBeginPeriod timeBeginPeriodSRC
+
5390#elif !defined(RGFW_NO_WINMM)
+
5391 __declspec(dllimport) u32 __stdcall timeBeginPeriod(u32 uPeriod);
+
5392#endif
+
5393
+
5394#define RGFW_PROC_DEF(proc, name) if (name##SRC == NULL && proc != NULL) name##SRC = (PFN_##name)(void*)GetProcAddress(proc, #name)
5395
-
5396 for (i = 0; i < sizeof(names) / sizeof(const char*) && (XInputGetStateSRC == NULL || XInputGetStateSRC != NULL); i++) {
-
5397 RGFW_XInput_dll = LoadLibraryA(names[i]);
-
5398 RGFW_PROC_DEF(RGFW_XInput_dll, XInputGetState);
-
5399 RGFW_PROC_DEF(RGFW_XInput_dll, XInputGetKeystroke);
-
5400 }
-
5401
-
5402 #ifdef RGFW_DEBUG
-
5403 if (XInputGetStateSRC == NULL)
-
5404 printf("RGFW ERR: Failed to load XInputGetState\n");
-
5405 if (XInputGetKeystrokeSRC == NULL)
-
5406 printf("RGFW ERR: Failed to load XInputGetKeystroke\n");
-
5407 #endif
-
5408}
-
5409#endif
-
5410
-
5411void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area){
-
5412#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
5413 win->buffer = buffer;
-
5414 win->bufferSize = area;
+
5396#ifndef RGFW_NO_XINPUT
+
5397void RGFW_loadXInput(void) {
+
5398 u32 i;
+
5399 static const char* names[] = {"xinput1_4.dll", "xinput9_1_0.dll", "xinput1_2.dll", "xinput1_1.dll"};
+
5400
+
5401 for (i = 0; i < sizeof(names) / sizeof(const char*) && (XInputGetStateSRC == NULL || XInputGetStateSRC != NULL); i++) {
+
5402 RGFW_XInput_dll = LoadLibraryA(names[i]);
+
5403 RGFW_PROC_DEF(RGFW_XInput_dll, XInputGetState);
+
5404 RGFW_PROC_DEF(RGFW_XInput_dll, XInputGetKeystroke);
+
5405 }
+
5406
+
5407 #ifdef RGFW_DEBUG
+
5408 if (XInputGetStateSRC == NULL)
+
5409 printf("RGFW ERR: Failed to load XInputGetState\n");
+
5410 if (XInputGetKeystrokeSRC == NULL)
+
5411 printf("RGFW ERR: Failed to load XInputGetKeystroke\n");
+
5412 #endif
+
5413}
+
5414#endif
5415
-
5416 BITMAPV5HEADER bi = { 0 };
-
5417 ZeroMemory(&bi, sizeof(bi));
-
5418 bi.bV5Size = sizeof(bi);
-
5419 bi.bV5Width = area.w;
-
5420 bi.bV5Height = -((LONG) area.h);
-
5421 bi.bV5Planes = 1;
-
5422 bi.bV5BitCount = 32;
-
5423 bi.bV5Compression = BI_BITFIELDS;
-
5424 bi.bV5BlueMask = 0x00ff0000;
-
5425 bi.bV5GreenMask = 0x0000ff00;
-
5426 bi.bV5RedMask = 0x000000ff;
-
5427 bi.bV5AlphaMask = 0xff000000;
-
5428
-
5429 win->src.bitmap = CreateDIBSection(win->src.hdc,
-
5430 (BITMAPINFO*) &bi,
-
5431 DIB_RGB_COLORS,
-
5432 (void**) &win->buffer,
-
5433 NULL,
-
5434 (DWORD) 0);
-
5435
-
5436 win->src.hdcMem = CreateCompatibleDC(win->src.hdc);
-
5437
-
5438 #if defined(RGFW_OSMESA)
-
5439 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
-
5440 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
-
5441 #endif
-
5442 #else
-
5443 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
-
5444 #endif
-
5445}
-
5446
-
5447void RGFW_window_setDND(RGFW_window* win, b8 allow) {
-
5448 DragAcceptFiles(win->src.window, allow);
-
5449}
-
5450
-
5451void RGFW_releaseCursor(RGFW_window* win) {
-
5452 RGFW_UNUSED(win);
-
5453 ClipCursor(NULL);
-
5454 const RAWINPUTDEVICE id = { 0x01, 0x02, RIDEV_REMOVE, NULL };
-
5455 RegisterRawInputDevices(&id, 1, sizeof(id));
-
5456}
-
5457
-
5458void RGFW_captureCursor(RGFW_window* win, RGFW_rect rect) {
-
5459 RGFW_UNUSED(win); RGFW_UNUSED(rect);
-
5460
-
5461 RECT clipRect;
-
5462 GetClientRect(win->src.window, &clipRect);
-
5463 ClientToScreen(win->src.window, (POINT*) &clipRect.left);
-
5464 ClientToScreen(win->src.window, (POINT*) &clipRect.right);
-
5465 ClipCursor(&clipRect);
-
5466
-
5467 const RAWINPUTDEVICE id = { 0x01, 0x02, 0, win->src.window };
-
5468 RegisterRawInputDevices(&id, 1, sizeof(id));
-
5469}
-
5470
-
5471#define RGFW_LOAD_LIBRARY(x, lib) if (x == NULL) x = LoadLibraryA(lib)
-
5472
-
5473u32 RGFW_windowsOpen = 0;
+
5416void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area){
+
5417#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
5418 win->buffer = buffer;
+
5419 win->bufferSize = area;
+
5420
+
5421 BITMAPV5HEADER bi = { 0 };
+
5422 ZeroMemory(&bi, sizeof(bi));
+
5423 bi.bV5Size = sizeof(bi);
+
5424 bi.bV5Width = area.w;
+
5425 bi.bV5Height = -((LONG) area.h);
+
5426 bi.bV5Planes = 1;
+
5427 bi.bV5BitCount = 32;
+
5428 bi.bV5Compression = BI_BITFIELDS;
+
5429 bi.bV5BlueMask = 0x00ff0000;
+
5430 bi.bV5GreenMask = 0x0000ff00;
+
5431 bi.bV5RedMask = 0x000000ff;
+
5432 bi.bV5AlphaMask = 0xff000000;
+
5433
+
5434 win->src.bitmap = CreateDIBSection(win->src.hdc,
+
5435 (BITMAPINFO*) &bi,
+
5436 DIB_RGB_COLORS,
+
5437 (void**) &win->src.bitmapBits,
+
5438 NULL,
+
5439 (DWORD) 0);
+
5440
+
5441 if (win->buffer == NULL)
+
5442 win->buffer = win->src.bitmapBits;
+
5443
+
5444 win->src.hdcMem = CreateCompatibleDC(win->src.hdc);
+
5445
+
5446 #if defined(RGFW_OSMESA)
+
5447 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
+
5448 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
+
5449 #endif
+
5450 #else
+
5451 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
+
5452 #endif
+
5453}
+
5454
+
5455void RGFW_window_setDND(RGFW_window* win, b8 allow) {
+
5456 DragAcceptFiles(win->src.window, allow);
+
5457}
+
5458
+
5459void RGFW_releaseCursor(RGFW_window* win) {
+
5460 RGFW_UNUSED(win);
+
5461 ClipCursor(NULL);
+
5462 const RAWINPUTDEVICE id = { 0x01, 0x02, RIDEV_REMOVE, NULL };
+
5463 RegisterRawInputDevices(&id, 1, sizeof(id));
+
5464}
+
5465
+
5466void RGFW_captureCursor(RGFW_window* win, RGFW_rect rect) {
+
5467 RGFW_UNUSED(win); RGFW_UNUSED(rect);
+
5468
+
5469 RECT clipRect;
+
5470 GetClientRect(win->src.window, &clipRect);
+
5471 ClientToScreen(win->src.window, (POINT*) &clipRect.left);
+
5472 ClientToScreen(win->src.window, (POINT*) &clipRect.right);
+
5473 ClipCursor(&clipRect);
5474
-
5475RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
-
5476 #ifndef RGFW_NO_XINPUT
-
5477 if (RGFW_XInput_dll == NULL)
-
5478 RGFW_loadXInput();
-
5479 #endif
+
5475 const RAWINPUTDEVICE id = { 0x01, 0x02, 0, win->src.window };
+
5476 RegisterRawInputDevices(&id, 1, sizeof(id));
+
5477}
+
5478
+
5479#define RGFW_LOAD_LIBRARY(x, lib) if (x == NULL) x = LoadLibraryA(lib)
5480
-
5481 #ifndef RGFW_NO_DPI
-
5482 RGFW_LOAD_LIBRARY(RGFW_Shcore_dll, "shcore.dll");
-
5483 RGFW_PROC_DEF(RGFW_Shcore_dll, GetDpiForMonitor);
-
5484 #if (_WIN32_WINNT >= 0x0600)
-
5485 SetProcessDPIAware();
-
5486 #endif
+
5481u32 RGFW_windowsOpen = 0;
+
5482
+
5483RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
+
5484 #ifndef RGFW_NO_XINPUT
+
5485 if (RGFW_XInput_dll == NULL)
+
5486 RGFW_loadXInput();
5487 #endif
5488
-
5489 #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
-
5490 RGFW_LOAD_LIBRARY(RGFW_winmm_dll, "winmm.dll");
-
5491 RGFW_PROC_DEF(RGFW_winmm_dll, timeBeginPeriod);
-
5492 #endif
-
5493
-
5494 #ifndef RGFW_NO_DWM
-
5495 RGFW_LOAD_LIBRARY(RGFW_dwm_dll, "dwmapi.dll");
-
5496 RGFW_PROC_DEF(RGFW_dwm_dll, DwmEnableBlurBehindWindow);
-
5497 #endif
-
5498
-
5499 RGFW_LOAD_LIBRARY(RGFW_wgl_dll, "opengl32.dll");
-
5500 #ifndef RGFW_NO_LOAD_WGL
-
5501 RGFW_PROC_DEF(RGFW_wgl_dll, wglCreateContext);
-
5502 RGFW_PROC_DEF(RGFW_wgl_dll, wglDeleteContext);
-
5503 RGFW_PROC_DEF(RGFW_wgl_dll, wglDeleteContext);
-
5504 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetProcAddress);
-
5505 RGFW_PROC_DEF(RGFW_wgl_dll, wglMakeCurrent);
-
5506 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetCurrentDC);
-
5507 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetCurrentContext);
-
5508 RGFW_PROC_DEF(RGFW_wgl_dll, wglShareLists);
-
5509 #endif
-
5510
-
5511 if (name[0] == 0) name = (char*) " ";
-
5512
-
5513 RGFW_eventWindow.r = RGFW_RECT(-1, -1, -1, -1);
-
5514 RGFW_eventWindow.src.window = NULL;
-
5515
-
5516 RGFW_window_basic_init(win, rect, flags);
-
5517
-
5518 win->src.maxSize = RGFW_AREA(0, 0);
-
5519 win->src.minSize = RGFW_AREA(0, 0);
+
5489 #ifndef RGFW_NO_DPI
+
5490 RGFW_LOAD_LIBRARY(RGFW_Shcore_dll, "shcore.dll");
+
5491 RGFW_PROC_DEF(RGFW_Shcore_dll, GetDpiForMonitor);
+
5492 #if (_WIN32_WINNT >= 0x0600)
+
5493 SetProcessDPIAware();
+
5494 #endif
+
5495 #endif
+
5496
+
5497 #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
+
5498 RGFW_LOAD_LIBRARY(RGFW_winmm_dll, "winmm.dll");
+
5499 RGFW_PROC_DEF(RGFW_winmm_dll, timeBeginPeriod);
+
5500 #endif
+
5501
+
5502 #ifndef RGFW_NO_DWM
+
5503 RGFW_LOAD_LIBRARY(RGFW_dwm_dll, "dwmapi.dll");
+
5504 RGFW_PROC_DEF(RGFW_dwm_dll, DwmEnableBlurBehindWindow);
+
5505 #endif
+
5506
+
5507 RGFW_LOAD_LIBRARY(RGFW_wgl_dll, "opengl32.dll");
+
5508 #ifndef RGFW_NO_LOAD_WGL
+
5509 RGFW_PROC_DEF(RGFW_wgl_dll, wglCreateContext);
+
5510 RGFW_PROC_DEF(RGFW_wgl_dll, wglDeleteContext);
+
5511 RGFW_PROC_DEF(RGFW_wgl_dll, wglDeleteContext);
+
5512 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetProcAddress);
+
5513 RGFW_PROC_DEF(RGFW_wgl_dll, wglMakeCurrent);
+
5514 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetCurrentDC);
+
5515 RGFW_PROC_DEF(RGFW_wgl_dll, wglGetCurrentContext);
+
5516 RGFW_PROC_DEF(RGFW_wgl_dll, wglShareLists);
+
5517 #endif
+
5518
+
5519 if (name[0] == 0) name = (char*) " ";
5520
-
5521
-
5522 HINSTANCE inh = GetModuleHandleA(NULL);
+
5521 RGFW_eventWindow.r = RGFW_RECT(-1, -1, -1, -1);
+
5522 RGFW_eventWindow.src.window = NULL;
5523
-
5524 #ifndef __cplusplus
-
5525 WNDCLASSA Class = { 0 };
-
5526 #else
-
5527 WNDCLASSA Class = { };
-
5528 #endif
+
5524 RGFW_window_basic_init(win, rect, flags);
+
5525
+
5526 win->src.maxSize = RGFW_AREA(0, 0);
+
5527 win->src.minSize = RGFW_AREA(0, 0);
+
5528
5529
-
5530 if (RGFW_className == NULL)
-
5531 RGFW_className = (char*)name;
-
5532
-
5533 Class.lpszClassName = RGFW_className;
-
5534 Class.hInstance = inh;
-
5535 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
-
5536 Class.lpfnWndProc = WndProc;
+
5530 HINSTANCE inh = GetModuleHandleA(NULL);
+
5531
+
5532 #ifndef __cplusplus
+
5533 WNDCLASSA Class = { 0 };
+
5534 #else
+
5535 WNDCLASSA Class = { };
+
5536 #endif
5537
-
5538 Class.hIcon = (HICON)LoadImageA(GetModuleHandleW(NULL), "RGFW_ICON", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
-
5539 if (Class.hIcon == NULL) {
-
5540 Class.hIcon = (HICON)LoadImageA(NULL, (LPCSTR)IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
-
5541 }
-
5542
-
5543 RegisterClassA(&Class);
-
5544
-
5545 DWORD window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
-
5546
-
5547 RECT windowRect, clientRect;
-
5548
-
5549 if (!(flags & RGFW_windowNoBorder)) {
-
5550 window_style |= WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX;
-
5551
-
5552 if (!(flags & RGFW_windowNoResize))
-
5553 window_style |= WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
-
5554 } else
-
5555 window_style |= WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX;
+
5538 if (RGFW_className == NULL)
+
5539 RGFW_className = (char*)name;
+
5540
+
5541 Class.lpszClassName = RGFW_className;
+
5542 Class.hInstance = inh;
+
5543 Class.hCursor = LoadCursor(NULL, IDC_ARROW);
+
5544 Class.lpfnWndProc = WndProc;
+
5545
+
5546 Class.hIcon = (HICON)LoadImageA(GetModuleHandleW(NULL), "RGFW_ICON", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
+
5547 if (Class.hIcon == NULL) {
+
5548 Class.hIcon = (HICON)LoadImageA(NULL, (LPCSTR)IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
+
5549 }
+
5550
+
5551 RegisterClassA(&Class);
+
5552
+
5553 DWORD window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
+
5554
+
5555 RECT windowRect, clientRect;
5556
-
5557 HWND dummyWin = CreateWindowA(Class.lpszClassName, name, window_style, win->r.x, win->r.y, win->r.w, win->r.h, 0, 0, inh, 0);
-
5558 GetWindowRect(dummyWin, &windowRect);
-
5559 GetClientRect(dummyWin, &clientRect);
-
5560
-
5561 win->src.hOffset = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
-
5562 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);
-
5563
-
5564 if (flags & RGFW_windowAllowDND) {
-
5565 win->_flags |= RGFW_windowAllowDND;
-
5566 RGFW_window_setDND(win, 1);
-
5567 }
-
5568 win->src.hdc = GetDC(win->src.window);
-
5569
-
5570 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
5571 #ifdef RGFW_DIRECTX
-
5572 RGFW_ASSERT(FAILED(CreateDXGIFactory(&__uuidof(IDXGIFactory), (void**) &RGFW_dxInfo.pFactory)) == 0);
-
5573
-
5574 if (FAILED(RGFW_dxInfo.pFactory->lpVtbl->EnumAdapters(RGFW_dxInfo.pFactory, 0, &RGFW_dxInfo.pAdapter))) {
-
5575 #ifdef RGFW_DEBUG
-
5576 fprintf(stderr, "Failed to enumerate DXGI adapters\n");
-
5577 #endif
-
5578 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
-
5579 return NULL;
-
5580 }
+
5557 if (!(flags & RGFW_windowNoBorder)) {
+
5558 window_style |= WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX;
+
5559
+
5560 if (!(flags & RGFW_windowNoResize))
+
5561 window_style |= WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
+
5562 } else
+
5563 window_style |= WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX;
+
5564
+
5565 HWND dummyWin = CreateWindowA(Class.lpszClassName, name, window_style, win->r.x, win->r.y, win->r.w, win->r.h, 0, 0, inh, 0);
+
5566 GetWindowRect(dummyWin, &windowRect);
+
5567 GetClientRect(dummyWin, &clientRect);
+
5568
+
5569 win->src.hOffset = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
+
5570 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);
+
5571
+
5572 if (flags & RGFW_windowAllowDND) {
+
5573 win->_flags |= RGFW_windowAllowDND;
+
5574 RGFW_window_setDND(win, 1);
+
5575 }
+
5576 win->src.hdc = GetDC(win->src.window);
+
5577
+
5578 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
5579 #ifdef RGFW_DIRECTX
+
5580 RGFW_ASSERT(FAILED(CreateDXGIFactory(&__uuidof(IDXGIFactory), (void**) &RGFW_dxInfo.pFactory)) == 0);
5581
-
5582 D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0 };
-
5583
-
5584 if (FAILED(D3D11CreateDevice(RGFW_dxInfo.pAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, featureLevels, 1, D3D11_SDK_VERSION, &RGFW_dxInfo.pDevice, NULL, &RGFW_dxInfo.pDeviceContext))) {
-
5585 #ifdef RGFW_DEBUG
-
5586 fprintf(stderr, "Failed to create Direct3D device\n");
-
5587 #endif
-
5588 RGFW_dxInfo.pAdapter->lpVtbl->Release(RGFW_dxInfo.pAdapter);
-
5589 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
-
5590 return NULL;
-
5591 }
-
5592
-
5593 DXGI_SWAP_CHAIN_DESC swapChainDesc = { 0 };
-
5594 swapChainDesc.BufferCount = 1;
-
5595 swapChainDesc.BufferDesc.Width = win->r.w;
-
5596 swapChainDesc.BufferDesc.Height = win->r.h;
-
5597 swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
-
5598 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-
5599 swapChainDesc.OutputWindow = win->src.window;
-
5600 swapChainDesc.SampleDesc.Count = 1;
-
5601 swapChainDesc.SampleDesc.Quality = 0;
-
5602 swapChainDesc.Windowed = TRUE;
-
5603 RGFW_dxInfo.pFactory->lpVtbl->CreateSwapChain(RGFW_dxInfo.pFactory, (IUnknown*) RGFW_dxInfo.pDevice, &swapChainDesc, &win->src.swapchain);
-
5604
-
5605 ID3D11Texture2D* pBackBuffer;
-
5606 win->src.swapchain->lpVtbl->GetBuffer(win->src.swapchain, 0, &__uuidof(ID3D11Texture2D), (LPVOID*) &pBackBuffer);
-
5607 RGFW_dxInfo.pDevice->lpVtbl->CreateRenderTargetView(RGFW_dxInfo.pDevice, (ID3D11Resource*) pBackBuffer, NULL, &win->src.renderTargetView);
-
5608 pBackBuffer->lpVtbl->Release(pBackBuffer);
-
5609
-
5610 D3D11_TEXTURE2D_DESC depthStencilDesc = { 0 };
-
5611 depthStencilDesc.Width = win->r.w;
-
5612 depthStencilDesc.Height = win->r.h;
-
5613 depthStencilDesc.MipLevels = 1;
-
5614 depthStencilDesc.ArraySize = 1;
-
5615 depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
-
5616 depthStencilDesc.SampleDesc.Count = 1;
-
5617 depthStencilDesc.SampleDesc.Quality = 0;
-
5618 depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
-
5619 depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
-
5620
-
5621 ID3D11Texture2D* pDepthStencilTexture = NULL;
-
5622 RGFW_dxInfo.pDevice->lpVtbl->CreateTexture2D(RGFW_dxInfo.pDevice, &depthStencilDesc, NULL, &pDepthStencilTexture);
-
5623
-
5624 D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc = { 0 };
-
5625 depthStencilViewDesc.Format = depthStencilDesc.Format;
-
5626 depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
-
5627 depthStencilViewDesc.Texture2D.MipSlice = 0;
+
5582 if (FAILED(RGFW_dxInfo.pFactory->lpVtbl->EnumAdapters(RGFW_dxInfo.pFactory, 0, &RGFW_dxInfo.pAdapter))) {
+
5583 #ifdef RGFW_DEBUG
+
5584 fprintf(stderr, "Failed to enumerate DXGI adapters\n");
+
5585 #endif
+
5586 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
+
5587 return NULL;
+
5588 }
+
5589
+
5590 D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0 };
+
5591
+
5592 if (FAILED(D3D11CreateDevice(RGFW_dxInfo.pAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, featureLevels, 1, D3D11_SDK_VERSION, &RGFW_dxInfo.pDevice, NULL, &RGFW_dxInfo.pDeviceContext))) {
+
5593 #ifdef RGFW_DEBUG
+
5594 fprintf(stderr, "Failed to create Direct3D device\n");
+
5595 #endif
+
5596 RGFW_dxInfo.pAdapter->lpVtbl->Release(RGFW_dxInfo.pAdapter);
+
5597 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
+
5598 return NULL;
+
5599 }
+
5600
+
5601 DXGI_SWAP_CHAIN_DESC swapChainDesc = { 0 };
+
5602 swapChainDesc.BufferCount = 1;
+
5603 swapChainDesc.BufferDesc.Width = win->r.w;
+
5604 swapChainDesc.BufferDesc.Height = win->r.h;
+
5605 swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+
5606 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+
5607 swapChainDesc.OutputWindow = win->src.window;
+
5608 swapChainDesc.SampleDesc.Count = 1;
+
5609 swapChainDesc.SampleDesc.Quality = 0;
+
5610 swapChainDesc.Windowed = TRUE;
+
5611 RGFW_dxInfo.pFactory->lpVtbl->CreateSwapChain(RGFW_dxInfo.pFactory, (IUnknown*) RGFW_dxInfo.pDevice, &swapChainDesc, &win->src.swapchain);
+
5612
+
5613 ID3D11Texture2D* pBackBuffer;
+
5614 win->src.swapchain->lpVtbl->GetBuffer(win->src.swapchain, 0, &__uuidof(ID3D11Texture2D), (LPVOID*) &pBackBuffer);
+
5615 RGFW_dxInfo.pDevice->lpVtbl->CreateRenderTargetView(RGFW_dxInfo.pDevice, (ID3D11Resource*) pBackBuffer, NULL, &win->src.renderTargetView);
+
5616 pBackBuffer->lpVtbl->Release(pBackBuffer);
+
5617
+
5618 D3D11_TEXTURE2D_DESC depthStencilDesc = { 0 };
+
5619 depthStencilDesc.Width = win->r.w;
+
5620 depthStencilDesc.Height = win->r.h;
+
5621 depthStencilDesc.MipLevels = 1;
+
5622 depthStencilDesc.ArraySize = 1;
+
5623 depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+
5624 depthStencilDesc.SampleDesc.Count = 1;
+
5625 depthStencilDesc.SampleDesc.Quality = 0;
+
5626 depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
+
5627 depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
5628
-
5629 RGFW_dxInfo.pDevice->lpVtbl->CreateDepthStencilView(RGFW_dxInfo.pDevice, (ID3D11Resource*) pDepthStencilTexture, &depthStencilViewDesc, &win->src.pDepthStencilView);
-
5630
-
5631 pDepthStencilTexture->lpVtbl->Release(pDepthStencilTexture);
-
5632
-
5633 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, &win->src.renderTargetView, win->src.pDepthStencilView);
-
5634 #endif
-
5635
-
5636 #ifdef RGFW_OPENGL
-
5637 HDC dummy_dc = GetDC(dummyWin);
+
5629 ID3D11Texture2D* pDepthStencilTexture = NULL;
+
5630 RGFW_dxInfo.pDevice->lpVtbl->CreateTexture2D(RGFW_dxInfo.pDevice, &depthStencilDesc, NULL, &pDepthStencilTexture);
+
5631
+
5632 D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc = { 0 };
+
5633 depthStencilViewDesc.Format = depthStencilDesc.Format;
+
5634 depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+
5635 depthStencilViewDesc.Texture2D.MipSlice = 0;
+
5636
+
5637 RGFW_dxInfo.pDevice->lpVtbl->CreateDepthStencilView(RGFW_dxInfo.pDevice, (ID3D11Resource*) pDepthStencilTexture, &depthStencilViewDesc, &win->src.pDepthStencilView);
5638
-
5639 u32 pfd_flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+
5639 pDepthStencilTexture->lpVtbl->Release(pDepthStencilTexture);
5640
-
5641 //if (RGFW_DOUBLE_BUFFER)
-
5642 pfd_flags |= PFD_DOUBLEBUFFER;
+
5641 RGFW_dxInfo.pDeviceContext->lpVtbl->OMSetRenderTargets(RGFW_dxInfo.pDeviceContext, 1, &win->src.renderTargetView, win->src.pDepthStencilView);
+
5642 #endif
5643
-
5644 PIXELFORMATDESCRIPTOR pfd = {
-
5645 sizeof(PIXELFORMATDESCRIPTOR), // Size of the descriptor
-
5646 1, // Version
-
5647 pfd_flags, // Flags to specify what the pixel format supports (e.g., PFD_SUPPORT_OPENGL)
-
5648 PFD_TYPE_RGBA, // Pixel type is RGBA
-
5649 32, // Color bits (red, green, blue channels)
-
5650 0, 0, 0, 0, 0, 0, // No color bits for unused channels
-
5651 8, // Alpha bits (important for transparency)
-
5652 0, // No accumulation buffer bits needed
-
5653 0, 0, 0, 0, // No accumulation bits
-
5654 32, // Depth buffer bits
-
5655 8, // Stencil buffer bits
-
5656 0, // Auxiliary buffer bits (unused)
-
5657 PFD_MAIN_PLANE, // Use the main plane for rendering
-
5658 0, 0, 0, 0, 0 // Reserved fields
-
5659 };
-
5660
-
5661
-
5662 int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
-
5663 SetPixelFormat(dummy_dc, pixel_format, &pfd);
-
5664
-
5665 HGLRC dummy_context = wglCreateContext(dummy_dc);
-
5666 wglMakeCurrent(dummy_dc, dummy_context);
-
5667
-
5668 if (wglChoosePixelFormatARB == NULL) {
-
5669 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) (void*) wglGetProcAddress("wglCreateContextAttribsARB");
-
5670 wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) (void*)wglGetProcAddress("wglChoosePixelFormatARB");
-
5671 }
+
5644 #ifdef RGFW_OPENGL
+
5645 HDC dummy_dc = GetDC(dummyWin);
+
5646
+
5647 u32 pfd_flags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+
5648
+
5649 //if (RGFW_DOUBLE_BUFFER)
+
5650 pfd_flags |= PFD_DOUBLEBUFFER;
+
5651
+
5652 PIXELFORMATDESCRIPTOR pfd = {
+
5653 sizeof(PIXELFORMATDESCRIPTOR), // Size of the descriptor
+
5654 1, // Version
+
5655 pfd_flags, // Flags to specify what the pixel format supports (e.g., PFD_SUPPORT_OPENGL)
+
5656 PFD_TYPE_RGBA, // Pixel type is RGBA
+
5657 32, // Color bits (red, green, blue channels)
+
5658 0, 0, 0, 0, 0, 0, // No color bits for unused channels
+
5659 8, // Alpha bits (important for transparency)
+
5660 0, // No accumulation buffer bits needed
+
5661 0, 0, 0, 0, // No accumulation bits
+
5662 32, // Depth buffer bits
+
5663 8, // Stencil buffer bits
+
5664 0, // Auxiliary buffer bits (unused)
+
5665 PFD_MAIN_PLANE, // Use the main plane for rendering
+
5666 0, 0, 0, 0, 0 // Reserved fields
+
5667 };
+
5668
+
5669
+
5670 int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
+
5671 SetPixelFormat(dummy_dc, pixel_format, &pfd);
5672
-
5673 wglMakeCurrent(dummy_dc, 0);
-
5674 wglDeleteContext(dummy_context);
-
5675 ReleaseDC(dummyWin, dummy_dc);
-
5676
-
5677 /* try to create the pixel format we want for opengl and then try to create an opengl context for the specified version */
-
5678 if (wglCreateContextAttribsARB != NULL) {
-
5679 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};
+
5673 HGLRC dummy_context = wglCreateContext(dummy_dc);
+
5674 wglMakeCurrent(dummy_dc, dummy_context);
+
5675
+
5676 if (wglChoosePixelFormatARB == NULL) {
+
5677 wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) (void*) wglGetProcAddress("wglCreateContextAttribsARB");
+
5678 wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) (void*)wglGetProcAddress("wglChoosePixelFormatARB");
+
5679 }
5680
-
5681 if (flags & RGFW_windowOpenglSoftware)
-
5682 pfd.dwFlags |= PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED;
-
5683
-
5684 if (wglChoosePixelFormatARB != NULL) {
-
5685 i32* pixel_format_attribs = (i32*)RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
-
5686
-
5687 int pixel_format;
-
5688 UINT num_formats;
-
5689 wglChoosePixelFormatARB(win->src.hdc, pixel_format_attribs, 0, 1, &pixel_format, &num_formats);
-
5690 if (!num_formats) {
-
5691 #ifdef RGFW_DEBUG
-
5692 printf("Failed to create a pixel format for WGL.\n");
-
5693 #endif
-
5694 }
-
5695
-
5696 DescribePixelFormat(win->src.hdc, pixel_format, sizeof(pfd), &pfd);
-
5697 if (!SetPixelFormat(win->src.hdc, pixel_format, &pfd)) {
-
5698 #ifdef RGFW_DEBUG
-
5699 printf("Failed to set the WGL pixel format.\n");
-
5700 #endif
-
5701 }
-
5702 }
+
5681 wglMakeCurrent(dummy_dc, 0);
+
5682 wglDeleteContext(dummy_context);
+
5683 ReleaseDC(dummyWin, dummy_dc);
+
5684
+
5685 /* try to create the pixel format we want for opengl and then try to create an opengl context for the specified version */
+
5686 if (wglCreateContextAttribsARB != NULL) {
+
5687 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};
+
5688
+
5689 if (flags & RGFW_windowOpenglSoftware)
+
5690 pfd.dwFlags |= PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED;
+
5691
+
5692 if (wglChoosePixelFormatARB != NULL) {
+
5693 i32* pixel_format_attribs = (i32*)RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
+
5694
+
5695 int pixel_format;
+
5696 UINT num_formats;
+
5697 wglChoosePixelFormatARB(win->src.hdc, pixel_format_attribs, 0, 1, &pixel_format, &num_formats);
+
5698 if (!num_formats) {
+
5699 #ifdef RGFW_DEBUG
+
5700 printf("Failed to create a pixel format for WGL.\n");
+
5701 #endif
+
5702 }
5703
-
5704 /* create opengl/WGL context for the specified version */
-
5705 u32 index = 0;
-
5706 i32 attribs[40];
-
5707
-
5708 if (RGFW_profile == RGFW_glCore) {
-
5709 SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB);
+
5704 DescribePixelFormat(win->src.hdc, pixel_format, sizeof(pfd), &pfd);
+
5705 if (!SetPixelFormat(win->src.hdc, pixel_format, &pfd)) {
+
5706 #ifdef RGFW_DEBUG
+
5707 printf("Failed to set the WGL pixel format.\n");
+
5708 #endif
+
5709 }
5710 }
-
5711 else {
-
5712 SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
-
5713 }
-
5714
-
5715 if (RGFW_majorVersion || RGFW_minorVersion) {
-
5716 SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, RGFW_majorVersion);
-
5717 SET_ATTRIB(WGL_CONTEXT_MINOR_VERSION_ARB, RGFW_minorVersion);
+
5711
+
5712 /* create opengl/WGL context for the specified version */
+
5713 u32 index = 0;
+
5714 i32 attribs[40];
+
5715
+
5716 if (RGFW_profile == RGFW_glCore) {
+
5717 SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB);
5718 }
-
5719
-
5720 SET_ATTRIB(0, 0);
-
5721
-
5722 win->src.ctx = (HGLRC)wglCreateContextAttribsARB(win->src.hdc, NULL, attribs);
-
5723 } else { /* fall back to a default context (probably opengl 2 or something) */
-
5724 #ifdef RGFW_DEBUG
-
5725 fprintf(stderr, "Failed to create an accelerated OpenGL Context\n");
-
5726 #endif
+
5719 else {
+
5720 SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
+
5721 }
+
5722
+
5723 if (RGFW_majorVersion || RGFW_minorVersion) {
+
5724 SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, RGFW_majorVersion);
+
5725 SET_ATTRIB(WGL_CONTEXT_MINOR_VERSION_ARB, RGFW_minorVersion);
+
5726 }
5727
-
5728 int pixel_format = ChoosePixelFormat(win->src.hdc, &pfd);
-
5729 SetPixelFormat(win->src.hdc, pixel_format, &pfd);
-
5730
-
5731 win->src.ctx = wglCreateContext(win->src.hdc);
-
5732 }
-
5733
-
5734 wglMakeCurrent(win->src.hdc, win->src.ctx);
-
5735 #endif
-
5736 }
-
5737
-
5738 #ifdef RGFW_OPENGL
-
5739 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
5740 ReleaseDC(win->src.window, win->src.hdc);
-
5741 win->src.hdc = GetDC(win->src.window);
-
5742 wglMakeCurrent(win->src.hdc, win->src.ctx);
-
5743 }
-
5744 #endif
+
5728 SET_ATTRIB(0, 0);
+
5729
+
5730 win->src.ctx = (HGLRC)wglCreateContextAttribsARB(win->src.hdc, NULL, attribs);
+
5731 } else { /* fall back to a default context (probably opengl 2 or something) */
+
5732 #ifdef RGFW_DEBUG
+
5733 fprintf(stderr, "Failed to create an accelerated OpenGL Context\n");
+
5734 #endif
+
5735
+
5736 int pixel_format = ChoosePixelFormat(win->src.hdc, &pfd);
+
5737 SetPixelFormat(win->src.hdc, pixel_format, &pfd);
+
5738
+
5739 win->src.ctx = wglCreateContext(win->src.hdc);
+
5740 }
+
5741
+
5742 wglMakeCurrent(win->src.hdc, win->src.ctx);
+
5743 #endif
+
5744 }
5745
-
5746 DestroyWindow(dummyWin);
-
5747
-
5748
-
5749 #ifndef RGFW_NO_MONITOR
-
5750 if (flags & RGFW_windowScaleToMonitor)
- +
5746 #ifdef RGFW_OPENGL
+
5747 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
5748 ReleaseDC(win->src.window, win->src.hdc);
+
5749 win->src.hdc = GetDC(win->src.window);
+
5750 wglMakeCurrent(win->src.hdc, win->src.ctx);
+
5751 }
5752 #endif
5753
-
5754 if (flags & RGFW_windowCenter) {
-
5755 RGFW_area screenR = RGFW_getScreenSize();
-
5756 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
-
5757 }
-
5758
-
5759 #ifdef RGFW_EGL
-
5760 if ((flags & RGFW_windowNoInitAPI) == 0)
-
5761 RGFW_createOpenGLContext(win);
-
5762 #endif
-
5763
-
5764 if (flags & RGFW_windowHideMouse)
-
5765 RGFW_window_showMouse(win, 0);
+
5754 DestroyWindow(dummyWin);
+
5755
+
5756
+
5757 #ifndef RGFW_NO_MONITOR
+
5758 if (flags & RGFW_windowScaleToMonitor)
+ +
5760 #endif
+
5761
+
5762 if (flags & RGFW_windowCenter) {
+
5763 RGFW_area screenR = RGFW_getScreenSize();
+
5764 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
+
5765 }
5766
-
5767 if (flags & RGFW_windowTransparent) {
-
5768 if (DwmEnableBlurBehindWindowSRC != NULL) {
-
5769 #ifndef RGFW_NO_DWM
-
5770 DWM_BLURBEHIND bb = {0, 0, 0, 0};
-
5771 bb.dwFlags = 0x1;
-
5772 bb.fEnable = TRUE;
-
5773 bb.hRgnBlur = NULL;
-
5774 DwmEnableBlurBehindWindowSRC(win->src.window, &bb);
-
5775 #endif
-
5776 } else {
-
5777 SetWindowLong(win->src.window, GWL_EXSTYLE, WS_EX_LAYERED);
-
5778 SetLayeredWindowAttributes(win->src.window, 0, 128, LWA_ALPHA);
-
5779 }
-
5780 }
-
5781
-
5782 ShowWindow(win->src.window, SW_SHOWNORMAL);
-
5783
-
5784 #ifdef RGFW_OPENGL
-
5785 if (RGFW_root != win)
-
5786 wglShareLists(RGFW_root->src.ctx, win->src.ctx);
-
5787 #endif
-
5788
-
5789 #ifdef RGFW_DEBUG
-
5790 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
-
5791 #endif
-
5792
-
5793 RGFW_windowsOpen++;
-
5794
-
5795 return win;
-
5796}
-
5797
-
5798void RGFW_window_setBorder(RGFW_window* win, u8 border) {
-
5799 DWORD style = GetWindowLong(win->src.window, GWL_STYLE);
+
5767 #ifdef RGFW_EGL
+
5768 if ((flags & RGFW_windowNoInitAPI) == 0)
+
5769 RGFW_createOpenGLContext(win);
+
5770 #endif
+
5771
+
5772 if (flags & RGFW_windowHideMouse)
+
5773 RGFW_window_showMouse(win, 0);
+
5774
+
5775 if (flags & RGFW_windowTransparent) {
+
5776 if (DwmEnableBlurBehindWindowSRC != NULL) {
+
5777 #ifndef RGFW_NO_DWM
+
5778 DWM_BLURBEHIND bb = {0, 0, 0, 0};
+
5779 bb.dwFlags = 0x1;
+
5780 bb.fEnable = TRUE;
+
5781 bb.hRgnBlur = NULL;
+
5782 DwmEnableBlurBehindWindowSRC(win->src.window, &bb);
+
5783 #endif
+
5784 } else {
+
5785 SetWindowLong(win->src.window, GWL_EXSTYLE, WS_EX_LAYERED);
+
5786 SetLayeredWindowAttributes(win->src.window, 0, 128, LWA_ALPHA);
+
5787 }
+
5788 }
+
5789
+
5790 ShowWindow(win->src.window, SW_SHOWNORMAL);
+
5791
+
5792 #ifdef RGFW_OPENGL
+
5793 if (RGFW_root != win)
+
5794 wglShareLists(RGFW_root->src.ctx, win->src.ctx);
+
5795 #endif
+
5796
+
5797 #ifdef RGFW_DEBUG
+
5798 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
+
5799 #endif
5800
-
5801 if (border == 0) {
-
5802 SetWindowLong(win->src.window, GWL_STYLE, style & ~WS_OVERLAPPEDWINDOW);
-
5803 SetWindowPos(
-
5804 win->src.window, HWND_TOP, 0, 0, 0, 0,
-
5805 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE
-
5806 );
-
5807 }
-
5808 else {
-
5809 SetWindowLong(win->src.window, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
-
5810 SetWindowPos(
-
5811 win->src.window, HWND_TOP, 0, 0, 0, 0,
-
5812 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE
-
5813 );
-
5814 }
-
5815}
-
5816
-
5817
- -
5819 HDC dc = GetDC(NULL);
-
5820 RGFW_area area = RGFW_AREA(GetDeviceCaps(dc, HORZRES), GetDeviceCaps(dc, VERTRES));
-
5821 ReleaseDC(NULL, dc);
-
5822 return area;
+
5801 RGFW_windowsOpen++;
+
5802
+
5803 return win;
+
5804}
+
5805
+
5806void RGFW_window_setBorder(RGFW_window* win, u8 border) {
+
5807 DWORD style = GetWindowLong(win->src.window, GWL_STYLE);
+
5808
+
5809 if (border == 0) {
+
5810 SetWindowLong(win->src.window, GWL_STYLE, style & ~WS_OVERLAPPEDWINDOW);
+
5811 SetWindowPos(
+
5812 win->src.window, HWND_TOP, 0, 0, 0, 0,
+
5813 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE
+
5814 );
+
5815 }
+
5816 else {
+
5817 SetWindowLong(win->src.window, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
+
5818 SetWindowPos(
+
5819 win->src.window, HWND_TOP, 0, 0, 0, 0,
+
5820 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE
+
5821 );
+
5822 }
5823}
5824
- -
5826 POINT p;
-
5827 GetCursorPos(&p);
-
5828
-
5829 return RGFW_POINT(p.x, p.y);
-
5830}
-
5831
- -
5833 POINT p;
-
5834 GetCursorPos(&p);
-
5835 ScreenToClient(win->src.window, &p);
+
5825
+ +
5827 HDC dc = GetDC(NULL);
+
5828 RGFW_area area = RGFW_AREA(GetDeviceCaps(dc, HORZRES), GetDeviceCaps(dc, VERTRES));
+
5829 ReleaseDC(NULL, dc);
+
5830 return area;
+
5831}
+
5832
+ +
5834 POINT p;
+
5835 GetCursorPos(&p);
5836
5837 return RGFW_POINT(p.x, p.y);
5838}
5839
- -
5841 RGFW_ASSERT(win != NULL);
-
5842 win->src.minSize = a;
-
5843}
+ +
5841 POINT p;
+
5842 GetCursorPos(&p);
+
5843 ScreenToClient(win->src.window, &p);
5844
- -
5846 RGFW_ASSERT(win != NULL);
-
5847 win->src.maxSize = a;
-
5848}
-
5849
-
5850
- -
5852 RGFW_ASSERT(win != NULL);
-
5853
-
5854 ShowWindow(win->src.window, SW_MINIMIZE);
-
5855}
-
5856
- -
5858 RGFW_ASSERT(win != NULL);
-
5859
-
5860 ShowWindow(win->src.window, SW_RESTORE);
-
5861}
-
5862
-
5863u8 RGFW_xinput2RGFW[] = {
-
5864 RGFW_gamepadA, /* or PS X button */
-
5865 RGFW_gamepadB, /* or PS circle button */
-
5866 RGFW_gamepadX, /* or PS square button */
-
5867 RGFW_gamepadY, /* or PS triangle button */
-
5868 RGFW_gamepadR1, /* right bumper */
-
5869 RGFW_gamepadL1, /* left bump */
-
5870 RGFW_gamepadL2, /* left trigger*/
-
5871 RGFW_gamepadR2, /* right trigger */
-
5872 0, 0, 0, 0, 0, 0, 0, 0,
-
5873 RGFW_gamepadUp, /* dpad up */
-
5874 RGFW_gamepadDown, /* dpad down*/
-
5875 RGFW_gamepadLeft, /* dpad left */
-
5876 RGFW_gamepadRight, /* dpad right */
-
5877 RGFW_gamepadStart, /* start button */
-
5878 RGFW_gamepadSelect,/* select button */
-
5879 RGFW_gamepadL3,
-
5880 RGFW_gamepadR3,
-
5881};
-
5882
-
5883static i32 RGFW_checkXInput(RGFW_window* win, RGFW_event* e) {
-
5884 #ifndef RGFW_NO_XINPUT
-
5885
-
5886 RGFW_UNUSED(win);
-
5887 size_t i;
-
5888 for (i = 0; i < 4; i++) {
-
5889 XINPUT_KEYSTROKE keystroke;
+
5845 return RGFW_POINT(p.x, p.y);
+
5846}
+
5847
+ +
5849 RGFW_ASSERT(win != NULL);
+
5850 win->src.minSize = a;
+
5851}
+
5852
+ +
5854 RGFW_ASSERT(win != NULL);
+
5855 win->src.maxSize = a;
+
5856}
+
5857
+
5858
+ +
5860 RGFW_ASSERT(win != NULL);
+
5861
+
5862 ShowWindow(win->src.window, SW_MINIMIZE);
+
5863}
+
5864
+ +
5866 RGFW_ASSERT(win != NULL);
+
5867
+
5868 ShowWindow(win->src.window, SW_RESTORE);
+
5869}
+
5870
+
5871u8 RGFW_xinput2RGFW[] = {
+
5872 RGFW_gamepadA, /* or PS X button */
+
5873 RGFW_gamepadB, /* or PS circle button */
+
5874 RGFW_gamepadX, /* or PS square button */
+
5875 RGFW_gamepadY, /* or PS triangle button */
+
5876 RGFW_gamepadR1, /* right bumper */
+
5877 RGFW_gamepadL1, /* left bump */
+
5878 RGFW_gamepadL2, /* left trigger*/
+
5879 RGFW_gamepadR2, /* right trigger */
+
5880 0, 0, 0, 0, 0, 0, 0, 0,
+
5881 RGFW_gamepadUp, /* dpad up */
+
5882 RGFW_gamepadDown, /* dpad down*/
+
5883 RGFW_gamepadLeft, /* dpad left */
+
5884 RGFW_gamepadRight, /* dpad right */
+
5885 RGFW_gamepadStart, /* start button */
+
5886 RGFW_gamepadSelect,/* select button */
+
5887 RGFW_gamepadL3,
+
5888 RGFW_gamepadR3,
+
5889};
5890
-
5891 if (XInputGetKeystroke == NULL)
-
5892 return 0;
+
5891static i32 RGFW_checkXInput(RGFW_window* win, RGFW_event* e) {
+
5892 #ifndef RGFW_NO_XINPUT
5893
-
5894 DWORD result = XInputGetKeystroke((DWORD)i, 0, &keystroke);
-
5895
-
5896 if ((keystroke.Flags & XINPUT_KEYSTROKE_REPEAT) == 0 && result != ERROR_EMPTY) {
-
5897 if (result != ERROR_SUCCESS)
-
5898 return 0;
-
5899
-
5900 if (keystroke.VirtualKey > VK_PAD_RTHUMB_PRESS)
-
5901 continue;
-
5902
-
5903 //gamepad + 1 = RGFW_gamepadButtonReleased
-
5904 e->type = RGFW_gamepadButtonPressed + !(keystroke.Flags & XINPUT_KEYSTROKE_KEYDOWN);
-
5905 e->button = RGFW_xinput2RGFW[keystroke.VirtualKey - 0x5800];
-
5906 RGFW_gamepadPressed[i][e->button].prev = RGFW_gamepadPressed[i][e->button].current;
-
5907 RGFW_gamepadPressed[i][e->button].current = (keystroke.Flags & XINPUT_KEYSTROKE_KEYDOWN);
-
5908
-
5909 RGFW_gamepadButtonCallback(win, i, e->button, e->type == RGFW_gamepadButtonPressed);
-
5910 return 1;
-
5911 }
-
5912
-
5913 XINPUT_STATE state;
-
5914 if (XInputGetState == NULL ||
-
5915 XInputGetState((DWORD) i, &state) == ERROR_DEVICE_NOT_CONNECTED
-
5916 ) {
-
5917 if (RGFW_gamepads[i] == 0)
-
5918 continue;
-
5919
-
5920 RGFW_gamepads[i] = 0;
-
5921 RGFW_gamepadCount--;
-
5922
-
5923 win->event.type = RGFW_gamepadDisconnected;
-
5924 win->event.gamepad = i;
-
5925 RGFW_gamepadCallback(win, i, 0);
-
5926 return 1;
-
5927 }
-
5928
-
5929 if (RGFW_gamepads[i] == 0) {
-
5930 RGFW_gamepads[i] = 1;
-
5931 RGFW_gamepadCount++;
-
5932
-
5933 char str[] = "Microsoft X-Box (XInput device)";
-
5934 RGFW_MEMCPY(RGFW_gamepads_name[i], str, sizeof(str));
-
5935 RGFW_gamepads_name[i][sizeof(RGFW_gamepads_name[i]) - 1] = '\0';
-
5936 win->event.type = RGFW_gamepadConnected;
-
5937 win->event.gamepad = i;
-
5938 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
-
5939
-
5940 RGFW_gamepadCallback(win, i, 1);
-
5941 return 1;
-
5942 }
-
5943
-
5944#define INPUT_DEADZONE ( 0.24f * (float)(0x7FFF) ) // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
-
5945
-
5946 if ((state.Gamepad.sThumbLX < INPUT_DEADZONE &&
-
5947 state.Gamepad.sThumbLX > -INPUT_DEADZONE) &&
-
5948 (state.Gamepad.sThumbLY < INPUT_DEADZONE &&
-
5949 state.Gamepad.sThumbLY > -INPUT_DEADZONE))
-
5950 {
-
5951 state.Gamepad.sThumbLX = 0;
-
5952 state.Gamepad.sThumbLY = 0;
-
5953 }
-
5954
-
5955 if ((state.Gamepad.sThumbRX < INPUT_DEADZONE &&
-
5956 state.Gamepad.sThumbRX > -INPUT_DEADZONE) &&
-
5957 (state.Gamepad.sThumbRY < INPUT_DEADZONE &&
-
5958 state.Gamepad.sThumbRY > -INPUT_DEADZONE))
-
5959 {
-
5960 state.Gamepad.sThumbRX = 0;
-
5961 state.Gamepad.sThumbRY = 0;
-
5962 }
-
5963
-
5964 e->axisesCount = 2;
-
5965 RGFW_point axis1 = RGFW_POINT(((float)state.Gamepad.sThumbLX / 32768.0f) * 100, ((float)state.Gamepad.sThumbLY / -32768.0f) * 100);
-
5966 RGFW_point axis2 = RGFW_POINT(((float)state.Gamepad.sThumbRX / 32768.0f) * 100, ((float)state.Gamepad.sThumbRY / -32768.0f) * 100);
-
5967
-
5968 if (axis1.x != e->axis[0].x || axis1.y != e->axis[0].y){
-
5969 win->event.whichAxis = 0;
-
5970
-
5971 e->type = RGFW_gamepadAxisMove;
-
5972 e->axis[0] = axis1;
-
5973 RGFW_gamepadAxes[i][0] = e->axis[0];
-
5974
-
5975 RGFW_gamepadAxisCallback(win, e->gamepad, e->axis, e->axisesCount, e->whichAxis);
-
5976 return 1;
-
5977 }
+
5894 RGFW_UNUSED(win);
+
5895 size_t i;
+
5896 for (i = 0; i < 4; i++) {
+
5897 XINPUT_KEYSTROKE keystroke;
+
5898
+
5899 if (XInputGetKeystroke == NULL)
+
5900 return 0;
+
5901
+
5902 DWORD result = XInputGetKeystroke((DWORD)i, 0, &keystroke);
+
5903
+
5904 if ((keystroke.Flags & XINPUT_KEYSTROKE_REPEAT) == 0 && result != ERROR_EMPTY) {
+
5905 if (result != ERROR_SUCCESS)
+
5906 return 0;
+
5907
+
5908 if (keystroke.VirtualKey > VK_PAD_RTHUMB_PRESS)
+
5909 continue;
+
5910
+
5911 //gamepad + 1 = RGFW_gamepadButtonReleased
+
5912 e->type = RGFW_gamepadButtonPressed + !(keystroke.Flags & XINPUT_KEYSTROKE_KEYDOWN);
+
5913 e->button = RGFW_xinput2RGFW[keystroke.VirtualKey - 0x5800];
+
5914 RGFW_gamepadPressed[i][e->button].prev = RGFW_gamepadPressed[i][e->button].current;
+
5915 RGFW_gamepadPressed[i][e->button].current = (keystroke.Flags & XINPUT_KEYSTROKE_KEYDOWN);
+
5916
+
5917 RGFW_gamepadButtonCallback(win, i, e->button, e->type == RGFW_gamepadButtonPressed);
+
5918 return 1;
+
5919 }
+
5920
+
5921 XINPUT_STATE state;
+
5922 if (XInputGetState == NULL ||
+
5923 XInputGetState((DWORD) i, &state) == ERROR_DEVICE_NOT_CONNECTED
+
5924 ) {
+
5925 if (RGFW_gamepads[i] == 0)
+
5926 continue;
+
5927
+
5928 RGFW_gamepads[i] = 0;
+
5929 RGFW_gamepadCount--;
+
5930
+
5931 win->event.type = RGFW_gamepadDisconnected;
+
5932 win->event.gamepad = i;
+
5933 RGFW_gamepadCallback(win, i, 0);
+
5934 return 1;
+
5935 }
+
5936
+
5937 if (RGFW_gamepads[i] == 0) {
+
5938 RGFW_gamepads[i] = 1;
+
5939 RGFW_gamepadCount++;
+
5940
+
5941 char str[] = "Microsoft X-Box (XInput device)";
+
5942 RGFW_MEMCPY(RGFW_gamepads_name[i], str, sizeof(str));
+
5943 RGFW_gamepads_name[i][sizeof(RGFW_gamepads_name[i]) - 1] = '\0';
+
5944 win->event.type = RGFW_gamepadConnected;
+
5945 win->event.gamepad = i;
+
5946 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
+
5947
+
5948 RGFW_gamepadCallback(win, i, 1);
+
5949 return 1;
+
5950 }
+
5951
+
5952#define INPUT_DEADZONE ( 0.24f * (float)(0x7FFF) ) // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
+
5953
+
5954 if ((state.Gamepad.sThumbLX < INPUT_DEADZONE &&
+
5955 state.Gamepad.sThumbLX > -INPUT_DEADZONE) &&
+
5956 (state.Gamepad.sThumbLY < INPUT_DEADZONE &&
+
5957 state.Gamepad.sThumbLY > -INPUT_DEADZONE))
+
5958 {
+
5959 state.Gamepad.sThumbLX = 0;
+
5960 state.Gamepad.sThumbLY = 0;
+
5961 }
+
5962
+
5963 if ((state.Gamepad.sThumbRX < INPUT_DEADZONE &&
+
5964 state.Gamepad.sThumbRX > -INPUT_DEADZONE) &&
+
5965 (state.Gamepad.sThumbRY < INPUT_DEADZONE &&
+
5966 state.Gamepad.sThumbRY > -INPUT_DEADZONE))
+
5967 {
+
5968 state.Gamepad.sThumbRX = 0;
+
5969 state.Gamepad.sThumbRY = 0;
+
5970 }
+
5971
+
5972 e->axisesCount = 2;
+
5973 RGFW_point axis1 = RGFW_POINT(((float)state.Gamepad.sThumbLX / 32768.0f) * 100, ((float)state.Gamepad.sThumbLY / -32768.0f) * 100);
+
5974 RGFW_point axis2 = RGFW_POINT(((float)state.Gamepad.sThumbRX / 32768.0f) * 100, ((float)state.Gamepad.sThumbRY / -32768.0f) * 100);
+
5975
+
5976 if (axis1.x != e->axis[0].x || axis1.y != e->axis[0].y){
+
5977 win->event.whichAxis = 0;
5978
-
5979 if (axis2.x != e->axis[1].x || axis2.y != e->axis[1].y) {
-
5980 win->event.whichAxis = 1;
-
5981 e->type = RGFW_gamepadAxisMove;
-
5982 e->axis[1] = axis2;
-
5983 RGFW_gamepadAxes[i][1] = e->axis[1];
-
5984
-
5985 RGFW_gamepadAxisCallback(win, e->gamepad, e->axis, e->axisesCount, e->whichAxis);
-
5986 return 1;
-
5987 }
-
5988 }
-
5989
-
5990 #endif
-
5991
-
5992 return 0;
-
5993}
-
5994
-
5995void RGFW_stopCheckEvents(void) {
-
5996 PostMessageW(RGFW_root->src.window, WM_NULL, 0, 0);
-
5997}
-
5998
-
5999void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
-
6000 RGFW_UNUSED(win);
-
6001
-
6002 MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (waitMS * 1e3), QS_ALLINPUT);
-
6003}
-
6004
- -
6006 RGFW_ASSERT(win != NULL);
-
6007
-
6008 if (win->event.type == RGFW_quit) {
-
6009 return NULL;
-
6010 }
-
6011
-
6012 MSG msg;
-
6013
-
6014 if (RGFW_eventWindow.src.window == win->src.window) {
-
6015 if (RGFW_eventWindow.r.x != -1) {
-
6016 win->r.x = RGFW_eventWindow.r.x;
-
6017 win->r.y = RGFW_eventWindow.r.y;
-
6018 win->event.type = RGFW_windowMoved;
-
6019 RGFW_windowMoveCallback(win, win->r);
-
6020 }
+
5979 e->type = RGFW_gamepadAxisMove;
+
5980 e->axis[0] = axis1;
+
5981 RGFW_gamepadAxes[i][0] = e->axis[0];
+
5982
+
5983 RGFW_gamepadAxisCallback(win, e->gamepad, e->axis, e->axisesCount, e->whichAxis);
+
5984 return 1;
+
5985 }
+
5986
+
5987 if (axis2.x != e->axis[1].x || axis2.y != e->axis[1].y) {
+
5988 win->event.whichAxis = 1;
+
5989 e->type = RGFW_gamepadAxisMove;
+
5990 e->axis[1] = axis2;
+
5991 RGFW_gamepadAxes[i][1] = e->axis[1];
+
5992
+
5993 RGFW_gamepadAxisCallback(win, e->gamepad, e->axis, e->axisesCount, e->whichAxis);
+
5994 return 1;
+
5995 }
+
5996 }
+
5997
+
5998 #endif
+
5999
+
6000 return 0;
+
6001}
+
6002
+
6003void RGFW_stopCheckEvents(void) {
+
6004 PostMessageW(RGFW_root->src.window, WM_NULL, 0, 0);
+
6005}
+
6006
+
6007void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
+
6008 RGFW_UNUSED(win);
+
6009
+
6010 MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (waitMS * 1e3), QS_ALLINPUT);
+
6011}
+
6012
+ +
6014 RGFW_ASSERT(win != NULL);
+
6015
+
6016 if (win->event.type == RGFW_quit) {
+
6017 return NULL;
+
6018 }
+
6019
+
6020 MSG msg;
6021
-
6022 if (RGFW_eventWindow.r.w != -1) {
-
6023 win->r.w = RGFW_eventWindow.r.w;
-
6024 win->r.h = RGFW_eventWindow.r.h;
-
6025 win->event.type = RGFW_windowResized;
-
6026 RGFW_windowResizeCallback(win, win->r);
-
6027 }
-
6028
-
6029 RGFW_eventWindow.src.window = NULL;
-
6030 RGFW_eventWindow.r = RGFW_RECT(-1, -1, -1, -1);
-
6031
-
6032 return &win->event;
-
6033 }
-
6034
-
6035
-
6036 static HDROP drop;
-
6037
-
6038 if (win->event.type == RGFW_DNDInit) {
-
6039 if (win->event.droppedFilesCount) {
-
6040 u32 i;
-
6041 for (i = 0; i < win->event.droppedFilesCount; i++)
-
6042 win->event.droppedFiles[i][0] = '\0';
-
6043 }
-
6044
-
6045 win->event.droppedFilesCount = 0;
-
6046 win->event.droppedFilesCount = DragQueryFileW(drop, 0xffffffff, NULL, 0);
-
6047
-
6048 u32 i;
-
6049 for (i = 0; i < win->event.droppedFilesCount; i++) {
-
6050 UINT length = DragQueryFileW(drop, i, NULL, 0);
-
6051 if (length == 0)
-
6052 continue;
-
6053
-
6054 WCHAR buffer[RGFW_MAX_PATH * 2];
-
6055 if (length > (RGFW_MAX_PATH * 2) - 1)
-
6056 length = RGFW_MAX_PATH * 2;
-
6057
-
6058 DragQueryFileW(drop, i, buffer, length + 1);
-
6059
-
6060 char* str = RGFW_createUTF8FromWideStringWin32(buffer);
-
6061 if (str != NULL)
-
6062 RGFW_MEMCPY(win->event.droppedFiles[i], str, length + 1);
-
6063
-
6064 win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0';
-
6065 }
-
6066
-
6067 DragFinish(drop);
-
6068 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
-
6069
-
6070 win->event.type = RGFW_DND;
-
6071 return &win->event;
-
6072 }
-
6073
-
6074 win->event.inFocus = (GetForegroundWindow() == win->src.window);
-
6075
-
6076 if (RGFW_checkXInput(win, &win->event))
-
6077 return &win->event;
-
6078
-
6079 static BYTE keyboardState[256];
-
6080 GetKeyboardState(keyboardState);
+
6022 if (RGFW_eventWindow.src.window == win->src.window) {
+
6023 if (RGFW_eventWindow.r.x != -1) {
+
6024 win->r.x = RGFW_eventWindow.r.x;
+
6025 win->r.y = RGFW_eventWindow.r.y;
+
6026 win->event.type = RGFW_windowMoved;
+
6027 RGFW_windowMoveCallback(win, win->r);
+
6028 }
+
6029
+
6030 if (RGFW_eventWindow.r.w != -1) {
+
6031 win->r.w = RGFW_eventWindow.r.w;
+
6032 win->r.h = RGFW_eventWindow.r.h;
+
6033 win->event.type = RGFW_windowResized;
+
6034 RGFW_windowResizeCallback(win, win->r);
+
6035 }
+
6036
+
6037 RGFW_eventWindow.src.window = NULL;
+
6038 RGFW_eventWindow.r = RGFW_RECT(-1, -1, -1, -1);
+
6039
+
6040 return &win->event;
+
6041 }
+
6042
+
6043
+
6044 static HDROP drop;
+
6045
+
6046 if (win->event.type == RGFW_DNDInit) {
+
6047 if (win->event.droppedFilesCount) {
+
6048 u32 i;
+
6049 for (i = 0; i < win->event.droppedFilesCount; i++)
+
6050 win->event.droppedFiles[i][0] = '\0';
+
6051 }
+
6052
+
6053 win->event.droppedFilesCount = 0;
+
6054 win->event.droppedFilesCount = DragQueryFileW(drop, 0xffffffff, NULL, 0);
+
6055
+
6056 u32 i;
+
6057 for (i = 0; i < win->event.droppedFilesCount; i++) {
+
6058 UINT length = DragQueryFileW(drop, i, NULL, 0);
+
6059 if (length == 0)
+
6060 continue;
+
6061
+
6062 WCHAR buffer[RGFW_MAX_PATH * 2];
+
6063 if (length > (RGFW_MAX_PATH * 2) - 1)
+
6064 length = RGFW_MAX_PATH * 2;
+
6065
+
6066 DragQueryFileW(drop, i, buffer, length + 1);
+
6067
+
6068 char* str = RGFW_createUTF8FromWideStringWin32(buffer);
+
6069 if (str != NULL)
+
6070 RGFW_MEMCPY(win->event.droppedFiles[i], str, length + 1);
+
6071
+
6072 win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0';
+
6073 }
+
6074
+
6075 DragFinish(drop);
+
6076 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
+
6077
+
6078 win->event.type = RGFW_DND;
+
6079 return &win->event;
+
6080 }
6081
-
6082
-
6083 if (!IsWindow(win->src.window)) {
-
6084 win->event.type = RGFW_quit;
-
6085 RGFW_windowQuitCallback(win);
-
6086 return &win->event;
-
6087 }
-
6088
-
6089 if (PeekMessageA(&msg, win->src.window, 0u, 0u, PM_REMOVE) == 0)
-
6090 return NULL;
-
6091
-
6092 switch (msg.message) {
-
6093 case WM_CLOSE:
-
6094 case WM_QUIT:
-
6095 RGFW_windowQuitCallback(win);
-
6096 win->event.type = RGFW_quit;
-
6097 break;
-
6098
-
6099 case WM_ACTIVATE:
-
6100 win->event.inFocus = (LOWORD(msg.wParam) == WA_INACTIVE);
-
6101
-
6102 if (win->event.inFocus) {
-
6103 win->event.type = RGFW_focusIn;
-
6104 RGFW_focusCallback(win, 1);
-
6105 }
-
6106 else {
-
6107 win->event.type = RGFW_focusOut;
-
6108 RGFW_focusCallback(win, 0);
-
6109 }
-
6110
-
6111 break;
-
6112
-
6113 case WM_PAINT:
-
6114 win->event.type = RGFW_windowRefresh;
-
6115 RGFW_windowRefreshCallback(win);
-
6116 break;
-
6117
-
6118 case WM_MOUSELEAVE:
-
6119 win->event.type = RGFW_mouseLeave;
-
6120 win->_flags |= RGFW_MOUSE_LEFT;
-
6121 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
-
6122 break;
-
6123
-
6124 case WM_KEYUP: {
-
6125 i32 scancode = (HIWORD(msg.lParam) & (KF_EXTENDED | 0xff));
-
6126 if (scancode == 0)
-
6127 scancode = MapVirtualKeyW((u32)msg.wParam, MAPVK_VK_TO_VSC);
-
6128
-
6129 switch (scancode) {
-
6130 case 0x54: scancode = 0x137; break; /* Alt+PrtS */
-
6131 case 0x146: scancode = 0x45; break; /* Ctrl+Pause */
-
6132 case 0x136: scancode = 0x36; break; /* CJK IME sets the extended bit for right Shift */
-
6133 default: break;
-
6134 }
-
6135
-
6136 win->event.key = RGFW_apiKeyToRGFW((u32) scancode);
-
6137
-
6138 if (msg.wParam == VK_CONTROL) {
-
6139 if (HIWORD(msg.lParam) & KF_EXTENDED)
-
6140 win->event.key = RGFW_controlR;
-
6141 else win->event.key = RGFW_controlL;
+
6082 win->event.inFocus = (GetForegroundWindow() == win->src.window);
+
6083
+
6084 if (RGFW_checkXInput(win, &win->event))
+
6085 return &win->event;
+
6086
+
6087 static BYTE keyboardState[256];
+
6088 GetKeyboardState(keyboardState);
+
6089
+
6090
+
6091 if (!IsWindow(win->src.window)) {
+
6092 win->event.type = RGFW_quit;
+
6093 RGFW_windowQuitCallback(win);
+
6094 return &win->event;
+
6095 }
+
6096
+
6097 if (PeekMessageA(&msg, win->src.window, 0u, 0u, PM_REMOVE) == 0)
+
6098 return NULL;
+
6099
+
6100 switch (msg.message) {
+
6101 case WM_CLOSE:
+
6102 case WM_QUIT:
+
6103 RGFW_windowQuitCallback(win);
+
6104 win->event.type = RGFW_quit;
+
6105 break;
+
6106
+
6107 case WM_ACTIVATE:
+
6108 win->event.inFocus = (LOWORD(msg.wParam) == WA_INACTIVE);
+
6109
+
6110 if (win->event.inFocus) {
+
6111 win->event.type = RGFW_focusIn;
+
6112 RGFW_focusCallback(win, 1);
+
6113 }
+
6114 else {
+
6115 win->event.type = RGFW_focusOut;
+
6116 RGFW_focusCallback(win, 0);
+
6117 }
+
6118
+
6119 break;
+
6120
+
6121 case WM_PAINT:
+
6122 win->event.type = RGFW_windowRefresh;
+
6123 RGFW_windowRefreshCallback(win);
+
6124 break;
+
6125
+
6126 case WM_MOUSELEAVE:
+
6127 win->event.type = RGFW_mouseLeave;
+
6128 win->_flags |= RGFW_MOUSE_LEFT;
+
6129 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
+
6130 break;
+
6131
+
6132 case WM_KEYUP: {
+
6133 i32 scancode = (HIWORD(msg.lParam) & (KF_EXTENDED | 0xff));
+
6134 if (scancode == 0)
+
6135 scancode = MapVirtualKeyW((u32)msg.wParam, MAPVK_VK_TO_VSC);
+
6136
+
6137 switch (scancode) {
+
6138 case 0x54: scancode = 0x137; break; /* Alt+PrtS */
+
6139 case 0x146: scancode = 0x45; break; /* Ctrl+Pause */
+
6140 case 0x136: scancode = 0x36; break; /* CJK IME sets the extended bit for right Shift */
+
6141 default: break;
6142 }
6143
-
6144 wchar_t charBuffer;
-
6145 ToUnicodeEx(msg.wParam, scancode, keyboardState, (wchar_t*)&charBuffer, 1, 0, NULL);
-
6146
-
6147 win->event.keyChar = (u8)charBuffer;
-
6148
-
6149 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
-
6150 win->event.type = RGFW_keyReleased;
-
6151 RGFW_keyboard[win->event.key].current = 0;
-
6152
-
6153 RGFW_updateKeyMods(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001));
+
6144 win->event.key = RGFW_apiKeyToRGFW((u32) scancode);
+
6145
+
6146 if (msg.wParam == VK_CONTROL) {
+
6147 if (HIWORD(msg.lParam) & KF_EXTENDED)
+
6148 win->event.key = RGFW_controlR;
+
6149 else win->event.key = RGFW_controlL;
+
6150 }
+
6151
+
6152 wchar_t charBuffer;
+
6153 ToUnicodeEx(msg.wParam, scancode, keyboardState, (wchar_t*)&charBuffer, 1, 0, NULL);
6154
-
6155 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 0);
-
6156 break;
-
6157 }
-
6158 case WM_KEYDOWN: {
-
6159 i32 scancode = (HIWORD(msg.lParam) & (KF_EXTENDED | 0xff));
-
6160 if (scancode == 0)
-
6161 scancode = MapVirtualKeyW((u32)msg.wParam, MAPVK_VK_TO_VSC);
+
6155 win->event.keyChar = (u8)charBuffer;
+
6156
+
6157 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
+
6158 win->event.type = RGFW_keyReleased;
+
6159 RGFW_keyboard[win->event.key].current = 0;
+
6160
+
6161 RGFW_updateKeyMods(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001));
6162
-
6163 switch (scancode) {
-
6164 case 0x54: scancode = 0x137; break; /* Alt+PrtS */
-
6165 case 0x146: scancode = 0x45; break; /* Ctrl+Pause */
-
6166 case 0x136: scancode = 0x36; break; /* CJK IME sets the extended bit for right Shift */
-
6167 default: break;
-
6168 }
-
6169
-
6170 win->event.key = RGFW_apiKeyToRGFW((u32) scancode);
-
6171
-
6172 if (msg.wParam == VK_CONTROL) {
-
6173 if (HIWORD(msg.lParam) & KF_EXTENDED)
-
6174 win->event.key = RGFW_controlR;
-
6175 else win->event.key = RGFW_controlL;
+
6163 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 0);
+
6164 break;
+
6165 }
+
6166 case WM_KEYDOWN: {
+
6167 i32 scancode = (HIWORD(msg.lParam) & (KF_EXTENDED | 0xff));
+
6168 if (scancode == 0)
+
6169 scancode = MapVirtualKeyW((u32)msg.wParam, MAPVK_VK_TO_VSC);
+
6170
+
6171 switch (scancode) {
+
6172 case 0x54: scancode = 0x137; break; /* Alt+PrtS */
+
6173 case 0x146: scancode = 0x45; break; /* Ctrl+Pause */
+
6174 case 0x136: scancode = 0x36; break; /* CJK IME sets the extended bit for right Shift */
+
6175 default: break;
6176 }
6177
-
6178 wchar_t charBuffer;
-
6179 ToUnicodeEx(msg.wParam, scancode, keyboardState, &charBuffer, 1, 0, NULL);
-
6180 win->event.keyChar = (u8)charBuffer;
-
6181
-
6182 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
-
6183
-
6184 win->event.type = RGFW_keyPressed;
-
6185 win->event.repeat = RGFW_isPressed(win, win->event.key);
-
6186 RGFW_keyboard[win->event.key].current = 1;
-
6187 RGFW_updateKeyMods(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001));
-
6188
-
6189 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 1);
-
6190 break;
-
6191 }
-
6192
-
6193 case WM_MOUSEMOVE: {
-
6194 if ((win->_flags & RGFW_HOLD_MOUSE))
-
6195 break;
+
6178 win->event.key = RGFW_apiKeyToRGFW((u32) scancode);
+
6179
+
6180 if (msg.wParam == VK_CONTROL) {
+
6181 if (HIWORD(msg.lParam) & KF_EXTENDED)
+
6182 win->event.key = RGFW_controlR;
+
6183 else win->event.key = RGFW_controlL;
+
6184 }
+
6185
+
6186 wchar_t charBuffer;
+
6187 ToUnicodeEx(msg.wParam, scancode, keyboardState, &charBuffer, 1, 0, NULL);
+
6188 win->event.keyChar = (u8)charBuffer;
+
6189
+
6190 RGFW_keyboard[win->event.key].prev = RGFW_isPressed(win, win->event.key);
+
6191
+
6192 win->event.type = RGFW_keyPressed;
+
6193 win->event.repeat = RGFW_isPressed(win, win->event.key);
+
6194 RGFW_keyboard[win->event.key].current = 1;
+
6195 RGFW_updateKeyMods(win, (GetKeyState(VK_CAPITAL) & 0x0001), (GetKeyState(VK_NUMLOCK) & 0x0001));
6196
-
6197 win->event.type = RGFW_mousePosChanged;
-
6198
-
6199 i32 x = GET_X_LPARAM(msg.lParam);
-
6200 i32 y = GET_Y_LPARAM(msg.lParam);
-
6201
-
6202 RGFW_mousePosCallback(win, win->event.point);
-
6203
-
6204 if (win->_flags & RGFW_MOUSE_LEFT) {
-
6205 win->_flags ^= RGFW_MOUSE_LEFT;
-
6206 win->event.type = RGFW_mouseEnter;
-
6207 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
-
6208 }
+
6197 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 1);
+
6198 break;
+
6199 }
+
6200
+
6201 case WM_MOUSEMOVE: {
+
6202 if ((win->_flags & RGFW_HOLD_MOUSE))
+
6203 break;
+
6204
+
6205 win->event.type = RGFW_mousePosChanged;
+
6206
+
6207 i32 x = GET_X_LPARAM(msg.lParam);
+
6208 i32 y = GET_Y_LPARAM(msg.lParam);
6209
-
6210 /*if ((win->_flags & RGFW_HOLD_MOUSE)) {
-
6211 RGFW_point p = RGFW_getGlobalMousePoint();
-
6212 //p = RGFW_POINT(p.x + win->r.x, p.y + win->r.y);
-
6213
-
6214 win->event.point.x = x - win->_lastMousePoint.x;
-
6215 win->event.point.y = y - win->_lastMousePoint.y;
-
6216
-
6217 win->_lastMousePoint = RGFW_POINT(x, y);
-
6218 break;
-
6219 }*/
-
6220
-
6221 win->event.point.x = x;
-
6222 win->event.point.y = y;
-
6223 win->_lastMousePoint = RGFW_POINT(x, y);
-
6224
-
6225 break;
-
6226 }
-
6227 case WM_INPUT: {
-
6228 if (!(win->_flags & RGFW_HOLD_MOUSE))
-
6229 break;
-
6230
-
6231 unsigned size = sizeof(RAWINPUT);
-
6232 static RAWINPUT raw = {};
-
6233
-
6234 GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, &raw, &size, sizeof(RAWINPUTHEADER));
-
6235
-
6236 if (raw.header.dwType != RIM_TYPEMOUSE || (raw.data.mouse.lLastX == 0 && raw.data.mouse.lLastY == 0) )
+
6210 RGFW_mousePosCallback(win, win->event.point);
+
6211
+
6212 if (win->_flags & RGFW_MOUSE_LEFT) {
+
6213 win->_flags ^= RGFW_MOUSE_LEFT;
+
6214 win->event.type = RGFW_mouseEnter;
+
6215 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
+
6216 }
+
6217
+
6218 /*if ((win->_flags & RGFW_HOLD_MOUSE)) {
+
6219 RGFW_point p = RGFW_getGlobalMousePoint();
+
6220 //p = RGFW_POINT(p.x + win->r.x, p.y + win->r.y);
+
6221
+
6222 win->event.point.x = x - win->_lastMousePoint.x;
+
6223 win->event.point.y = y - win->_lastMousePoint.y;
+
6224
+
6225 win->_lastMousePoint = RGFW_POINT(x, y);
+
6226 break;
+
6227 }*/
+
6228
+
6229 win->event.point.x = x;
+
6230 win->event.point.y = y;
+
6231 win->_lastMousePoint = RGFW_POINT(x, y);
+
6232
+
6233 break;
+
6234 }
+
6235 case WM_INPUT: {
+
6236 if (!(win->_flags & RGFW_HOLD_MOUSE))
6237 break;
6238
-
6239 if (raw.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) {
-
6240 POINT pos = {0, 0};
-
6241 int width, height;
-
6242
-
6243 if (raw.data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) {
-
6244 pos.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
-
6245 pos.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
-
6246 width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
-
6247 height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
-
6248 }
-
6249 else {
-
6250 width = GetSystemMetrics(SM_CXSCREEN);
-
6251 height = GetSystemMetrics(SM_CYSCREEN);
-
6252 }
-
6253
-
6254 pos.x += (int) ((raw.data.mouse.lLastX / 65535.f) * width);
-
6255 pos.y += (int) ((raw.data.mouse.lLastY / 65535.f) * height);
-
6256 ScreenToClient(win->src.window, &pos);
-
6257
-
6258 win->event.point.x = pos.x - win->_lastMousePoint.x;
-
6259 win->event.point.y = pos.y - win->_lastMousePoint.y;
-
6260 } else {
-
6261 win->event.point.x = raw.data.mouse.lLastX;
-
6262 win->event.point.y = raw.data.mouse.lLastY;
-
6263 }
-
6264
-
6265 win->event.type = RGFW_mousePosChanged;
-
6266 win->_lastMousePoint.x += win->event.point.x;
-
6267 win->_lastMousePoint.y += win->event.point.y;
-
6268 break;
-
6269 }
-
6270
-
6271 case WM_LBUTTONDOWN:
-
6272 win->event.button = RGFW_mouseLeft;
-
6273 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
6274 RGFW_mouseButtons[win->event.button].current = 1;
-
6275 win->event.type = RGFW_mouseButtonPressed;
-
6276 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
6277 break;
-
6278 case WM_RBUTTONDOWN:
-
6279 win->event.button = RGFW_mouseRight;
-
6280 win->event.type = RGFW_mouseButtonPressed;
+
6239 unsigned size = sizeof(RAWINPUT);
+
6240 static RAWINPUT raw = {};
+
6241
+
6242 GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, &raw, &size, sizeof(RAWINPUTHEADER));
+
6243
+
6244 if (raw.header.dwType != RIM_TYPEMOUSE || (raw.data.mouse.lLastX == 0 && raw.data.mouse.lLastY == 0) )
+
6245 break;
+
6246
+
6247 if (raw.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) {
+
6248 POINT pos = {0, 0};
+
6249 int width, height;
+
6250
+
6251 if (raw.data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) {
+
6252 pos.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
+
6253 pos.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
+
6254 width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+
6255 height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
+
6256 }
+
6257 else {
+
6258 width = GetSystemMetrics(SM_CXSCREEN);
+
6259 height = GetSystemMetrics(SM_CYSCREEN);
+
6260 }
+
6261
+
6262 pos.x += (int) ((raw.data.mouse.lLastX / 65535.f) * width);
+
6263 pos.y += (int) ((raw.data.mouse.lLastY / 65535.f) * height);
+
6264 ScreenToClient(win->src.window, &pos);
+
6265
+
6266 win->event.point.x = pos.x - win->_lastMousePoint.x;
+
6267 win->event.point.y = pos.y - win->_lastMousePoint.y;
+
6268 } else {
+
6269 win->event.point.x = raw.data.mouse.lLastX;
+
6270 win->event.point.y = raw.data.mouse.lLastY;
+
6271 }
+
6272
+
6273 win->event.type = RGFW_mousePosChanged;
+
6274 win->_lastMousePoint.x += win->event.point.x;
+
6275 win->_lastMousePoint.y += win->event.point.y;
+
6276 break;
+
6277 }
+
6278
+
6279 case WM_LBUTTONDOWN:
+
6280 win->event.button = RGFW_mouseLeft;
6281 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
6282 RGFW_mouseButtons[win->event.button].current = 1;
-
6283 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
6284 break;
-
6285 case WM_MBUTTONDOWN:
-
6286 win->event.button = RGFW_mouseMiddle;
-
6287 win->event.type = RGFW_mouseButtonPressed;
-
6288 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
6289 RGFW_mouseButtons[win->event.button].current = 1;
-
6290 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
6291 break;
-
6292
-
6293 case WM_MOUSEWHEEL:
-
6294 if (msg.wParam > 0)
-
6295 win->event.button = RGFW_mouseScrollUp;
-
6296 else
-
6297 win->event.button = RGFW_mouseScrollDown;
-
6298
-
6299 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
6300 RGFW_mouseButtons[win->event.button].current = 1;
-
6301
-
6302 win->event.scroll = (SHORT) HIWORD(msg.wParam) / (double) WHEEL_DELTA;
-
6303
-
6304 win->event.type = RGFW_mouseButtonPressed;
-
6305 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
6306 break;
-
6307
-
6308 case WM_LBUTTONUP:
+
6283 win->event.type = RGFW_mouseButtonPressed;
+
6284 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
6285 break;
+
6286 case WM_RBUTTONDOWN:
+
6287 win->event.button = RGFW_mouseRight;
+
6288 win->event.type = RGFW_mouseButtonPressed;
+
6289 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
6290 RGFW_mouseButtons[win->event.button].current = 1;
+
6291 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
6292 break;
+
6293 case WM_MBUTTONDOWN:
+
6294 win->event.button = RGFW_mouseMiddle;
+
6295 win->event.type = RGFW_mouseButtonPressed;
+
6296 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
6297 RGFW_mouseButtons[win->event.button].current = 1;
+
6298 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
6299 break;
+
6300
+
6301 case WM_MOUSEWHEEL:
+
6302 if (msg.wParam > 0)
+
6303 win->event.button = RGFW_mouseScrollUp;
+
6304 else
+
6305 win->event.button = RGFW_mouseScrollDown;
+
6306
+
6307 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
6308 RGFW_mouseButtons[win->event.button].current = 1;
6309
-
6310 win->event.button = RGFW_mouseLeft;
-
6311 win->event.type = RGFW_mouseButtonReleased;
-
6312
-
6313 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
6314 RGFW_mouseButtons[win->event.button].current = 0;
-
6315 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
-
6316 break;
-
6317 case WM_RBUTTONUP:
-
6318 win->event.button = RGFW_mouseRight;
+
6310 win->event.scroll = (SHORT) HIWORD(msg.wParam) / (double) WHEEL_DELTA;
+
6311
+
6312 win->event.type = RGFW_mouseButtonPressed;
+
6313 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
6314 break;
+
6315
+
6316 case WM_LBUTTONUP:
+
6317
+
6318 win->event.button = RGFW_mouseLeft;
6319 win->event.type = RGFW_mouseButtonReleased;
6320
6321 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
6322 RGFW_mouseButtons[win->event.button].current = 0;
6323 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
6324 break;
-
6325 case WM_MBUTTONUP:
-
6326 win->event.button = RGFW_mouseMiddle;
+
6325 case WM_RBUTTONUP:
+
6326 win->event.button = RGFW_mouseRight;
6327 win->event.type = RGFW_mouseButtonReleased;
6328
6329 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
6330 RGFW_mouseButtons[win->event.button].current = 0;
6331 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
6332 break;
-
6333 case WM_DROPFILES: {
-
6334 win->event.type = RGFW_DNDInit;
-
6335
-
6336 drop = (HDROP) msg.wParam;
-
6337 POINT pt;
-
6338
-
6339 /* Move the mouse to the position of the drop */
-
6340 DragQueryPoint(drop, &pt);
-
6341
-
6342 win->event.point.x = pt.x;
-
6343 win->event.point.y = pt.y;
-
6344
-
6345 RGFW_dndInitCallback(win, win->event.point);
-
6346 }
-
6347 break;
-
6348 case WM_GETMINMAXINFO:
-
6349 {
-
6350 MINMAXINFO* mmi = (MINMAXINFO*) msg.lParam;
-
6351 mmi->ptMinTrackSize.x = win->src.minSize.w;
-
6352 mmi->ptMinTrackSize.y = win->src.minSize.h;
-
6353
-
6354 if (win->src.maxSize.w == 0 && win->src.maxSize.h == 0)
-
6355 return RGFW_window_checkEvent(win);
-
6356
-
6357 mmi->ptMaxTrackSize.x = win->src.maxSize.w;
-
6358 mmi->ptMaxTrackSize.y = win->src.maxSize.h;
-
6359 return RGFW_window_checkEvent(win);
-
6360 }
-
6361 default:
-
6362 TranslateMessage(&msg);
-
6363 DispatchMessageA(&msg);
-
6364 return RGFW_window_checkEvent(win);
-
6365 }
-
6366
-
6367 TranslateMessage(&msg);
-
6368 DispatchMessageA(&msg);
-
6369
-
6370 return &win->event;
-
6371}
-
6372
- -
6374 RGFW_ASSERT(win != NULL);
-
6375
-
6376 #ifndef __cplusplus
-
6377 WINDOWPLACEMENT placement = { 0 };
-
6378 #else
-
6379 WINDOWPLACEMENT placement = { };
-
6380 #endif
-
6381 GetWindowPlacement(win->src.window, &placement);
-
6382 return placement.showCmd == SW_SHOWMAXIMIZED;
-
6383}
-
6384
- -
6386 RGFW_ASSERT(win != NULL);
-
6387
-
6388 return IsWindowVisible(win->src.window) == 0 && !RGFW_window_isMinimized(win);
-
6389}
-
6390
- -
6392 RGFW_ASSERT(win != NULL);
-
6393
-
6394 #ifndef __cplusplus
-
6395 WINDOWPLACEMENT placement = { 0 };
-
6396 #else
-
6397 WINDOWPLACEMENT placement = { };
-
6398 #endif
-
6399 GetWindowPlacement(win->src.window, &placement);
-
6400 return placement.showCmd == SW_SHOWMINIMIZED;
-
6401}
-
6402
- -
6404 RGFW_ASSERT(win != NULL);
-
6405
-
6406 #ifndef __cplusplus
-
6407 WINDOWPLACEMENT placement = { 0 };
-
6408 #else
-
6409 WINDOWPLACEMENT placement = { };
-
6410 #endif
-
6411 GetWindowPlacement(win->src.window, &placement);
-
6412 return placement.showCmd == SW_SHOWMAXIMIZED;
-
6413}
-
6414
-
6415typedef struct { int iIndex; HMONITOR hMonitor; } RGFW_mInfo;
-
6416BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
-
6417 RGFW_UNUSED(hdcMonitor);
-
6418 RGFW_UNUSED(lprcMonitor);
-
6419
-
6420 RGFW_mInfo* info = (RGFW_mInfo*) dwData;
-
6421 if (info->hMonitor == hMonitor)
-
6422 return FALSE;
-
6423
-
6424 info->iIndex++;
-
6425 return TRUE;
-
6426}
+
6333 case WM_MBUTTONUP:
+
6334 win->event.button = RGFW_mouseMiddle;
+
6335 win->event.type = RGFW_mouseButtonReleased;
+
6336
+
6337 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
6338 RGFW_mouseButtons[win->event.button].current = 0;
+
6339 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
+
6340 break;
+
6341 case WM_DROPFILES: {
+
6342 win->event.type = RGFW_DNDInit;
+
6343
+
6344 drop = (HDROP) msg.wParam;
+
6345 POINT pt;
+
6346
+
6347 /* Move the mouse to the position of the drop */
+
6348 DragQueryPoint(drop, &pt);
+
6349
+
6350 win->event.point.x = pt.x;
+
6351 win->event.point.y = pt.y;
+
6352
+
6353 RGFW_dndInitCallback(win, win->event.point);
+
6354 }
+
6355 break;
+
6356 case WM_GETMINMAXINFO:
+
6357 {
+
6358 MINMAXINFO* mmi = (MINMAXINFO*) msg.lParam;
+
6359 mmi->ptMinTrackSize.x = win->src.minSize.w;
+
6360 mmi->ptMinTrackSize.y = win->src.minSize.h;
+
6361
+
6362 if (win->src.maxSize.w == 0 && win->src.maxSize.h == 0)
+
6363 return RGFW_window_checkEvent(win);
+
6364
+
6365 mmi->ptMaxTrackSize.x = win->src.maxSize.w;
+
6366 mmi->ptMaxTrackSize.y = win->src.maxSize.h;
+
6367 return RGFW_window_checkEvent(win);
+
6368 }
+
6369 default:
+
6370 TranslateMessage(&msg);
+
6371 DispatchMessageA(&msg);
+
6372 return RGFW_window_checkEvent(win);
+
6373 }
+
6374
+
6375 TranslateMessage(&msg);
+
6376 DispatchMessageA(&msg);
+
6377
+
6378 return &win->event;
+
6379}
+
6380
+ +
6382 RGFW_ASSERT(win != NULL);
+
6383
+
6384 #ifndef __cplusplus
+
6385 WINDOWPLACEMENT placement = { 0 };
+
6386 #else
+
6387 WINDOWPLACEMENT placement = { };
+
6388 #endif
+
6389 GetWindowPlacement(win->src.window, &placement);
+
6390 return placement.showCmd == SW_SHOWMAXIMIZED;
+
6391}
+
6392
+ +
6394 RGFW_ASSERT(win != NULL);
+
6395
+
6396 return IsWindowVisible(win->src.window) == 0 && !RGFW_window_isMinimized(win);
+
6397}
+
6398
+ +
6400 RGFW_ASSERT(win != NULL);
+
6401
+
6402 #ifndef __cplusplus
+
6403 WINDOWPLACEMENT placement = { 0 };
+
6404 #else
+
6405 WINDOWPLACEMENT placement = { };
+
6406 #endif
+
6407 GetWindowPlacement(win->src.window, &placement);
+
6408 return placement.showCmd == SW_SHOWMINIMIZED;
+
6409}
+
6410
+ +
6412 RGFW_ASSERT(win != NULL);
+
6413
+
6414 #ifndef __cplusplus
+
6415 WINDOWPLACEMENT placement = { 0 };
+
6416 #else
+
6417 WINDOWPLACEMENT placement = { };
+
6418 #endif
+
6419 GetWindowPlacement(win->src.window, &placement);
+
6420 return placement.showCmd == SW_SHOWMAXIMIZED;
+
6421}
+
6422
+
6423typedef struct { int iIndex; HMONITOR hMonitor; } RGFW_mInfo;
+
6424BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
+
6425 RGFW_UNUSED(hdcMonitor);
+
6426 RGFW_UNUSED(lprcMonitor);
6427
-
6428#ifndef RGFW_NO_MONITOR
-
6429
-
6430RGFW_monitor win32CreateMonitor(HMONITOR src) {
-
6431 RGFW_monitor monitor;
-
6432 MONITORINFOEX monitorInfo;
-
6433
-
6434 monitorInfo.cbSize = sizeof(MONITORINFOEX);
-
6435 GetMonitorInfoA(src, (LPMONITORINFO)&monitorInfo);
-
6436
-
6437 RGFW_mInfo info;
-
6438 info.iIndex = 0;
-
6439 info.hMonitor = src;
-
6440
-
6441 /* get the monitor's index */
-
6442 if (EnumDisplayMonitors(NULL, NULL, GetMonitorByHandle, (LPARAM) &info)) {
-
6443 DISPLAY_DEVICEA dd;
-
6444 dd.cb = sizeof(dd);
-
6445
-
6446 /* loop through the devices until you find a device with the monitor's index */
-
6447 size_t deviceIndex;
-
6448 for (deviceIndex = 0; EnumDisplayDevicesA(0, (DWORD) deviceIndex, &dd, 0); deviceIndex++) {
-
6449 char* deviceName = dd.DeviceName;
-
6450 if (EnumDisplayDevicesA(deviceName, info.iIndex, &dd, 0)) {
-
6451 RGFW_MEMCPY(monitor.name, dd.DeviceString, 128);
-
6452 break;
-
6453 }
-
6454 }
-
6455 }
-
6456
-
6457 monitor.rect.x = monitorInfo.rcWork.left;
-
6458 monitor.rect.y = monitorInfo.rcWork.top;
-
6459 monitor.rect.w = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
-
6460 monitor.rect.h = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
-
6461
-
6462 HDC hdc = CreateDC(monitorInfo.szDevice, NULL, NULL, NULL);
-
6463 /* get pixels per inch */
-
6464 float dpiX = (float)GetDeviceCaps(hdc, LOGPIXELSX);
-
6465 float dpiY = (float)GetDeviceCaps(hdc, LOGPIXELSX);
-
6466
-
6467 monitor.scaleX = dpiX / 96.0f;
-
6468 monitor.scaleY = dpiY / 96.0f;
+
6428 RGFW_mInfo* info = (RGFW_mInfo*) dwData;
+
6429 if (info->hMonitor == hMonitor)
+
6430 return FALSE;
+
6431
+
6432 info->iIndex++;
+
6433 return TRUE;
+
6434}
+
6435
+
6436#ifndef RGFW_NO_MONITOR
+
6437
+
6438RGFW_monitor win32CreateMonitor(HMONITOR src) {
+
6439 RGFW_monitor monitor;
+
6440 MONITORINFOEX monitorInfo;
+
6441
+
6442 monitorInfo.cbSize = sizeof(MONITORINFOEX);
+
6443 GetMonitorInfoA(src, (LPMONITORINFO)&monitorInfo);
+
6444
+
6445 RGFW_mInfo info;
+
6446 info.iIndex = 0;
+
6447 info.hMonitor = src;
+
6448
+
6449 /* get the monitor's index */
+
6450 if (EnumDisplayMonitors(NULL, NULL, GetMonitorByHandle, (LPARAM) &info)) {
+
6451 DISPLAY_DEVICEA dd;
+
6452 dd.cb = sizeof(dd);
+
6453
+
6454 /* loop through the devices until you find a device with the monitor's index */
+
6455 size_t deviceIndex;
+
6456 for (deviceIndex = 0; EnumDisplayDevicesA(0, (DWORD) deviceIndex, &dd, 0); deviceIndex++) {
+
6457 char* deviceName = dd.DeviceName;
+
6458 if (EnumDisplayDevicesA(deviceName, info.iIndex, &dd, 0)) {
+
6459 RGFW_MEMCPY(monitor.name, dd.DeviceString, 128);
+
6460 break;
+
6461 }
+
6462 }
+
6463 }
+
6464
+
6465 monitor.rect.x = monitorInfo.rcWork.left;
+
6466 monitor.rect.y = monitorInfo.rcWork.top;
+
6467 monitor.rect.w = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
+
6468 monitor.rect.h = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
6469
-
6470 monitor.physW = GetDeviceCaps(hdc, HORZSIZE) / 25.4;
-
6471 monitor.physH = GetDeviceCaps(hdc, VERTSIZE) / 25.4;
-
6472 DeleteDC(hdc);
-
6473
-
6474 #ifndef RGFW_NO_DPI
-
6475 if (GetDpiForMonitor != NULL) {
-
6476 u32 x, y;
-
6477 GetDpiForMonitor(src, MDT_EFFECTIVE_DPI, &x, &y);
-
6478
-
6479 monitor.pixelRatio = (float) (x) / (float) dpiX;
-
6480 monitor.pixelRatio = (float) (y) / (float) dpiY;
-
6481 }
-
6482 #endif
-
6483
-
6484 #ifdef RGFW_DEBUG
-
6485 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
-
6486 #endif
-
6487
-
6488 return monitor;
-
6489}
-
6490#endif /* RGFW_NO_MONITOR */
+
6470 HDC hdc = CreateDC(monitorInfo.szDevice, NULL, NULL, NULL);
+
6471 /* get pixels per inch */
+
6472 float dpiX = (float)GetDeviceCaps(hdc, LOGPIXELSX);
+
6473 float dpiY = (float)GetDeviceCaps(hdc, LOGPIXELSX);
+
6474
+
6475 monitor.scaleX = dpiX / 96.0f;
+
6476 monitor.scaleY = dpiY / 96.0f;
+
6477
+
6478 monitor.physW = GetDeviceCaps(hdc, HORZSIZE) / 25.4;
+
6479 monitor.physH = GetDeviceCaps(hdc, VERTSIZE) / 25.4;
+
6480 DeleteDC(hdc);
+
6481
+
6482 #ifndef RGFW_NO_DPI
+
6483 if (GetDpiForMonitor != NULL) {
+
6484 u32 x, y;
+
6485 GetDpiForMonitor(src, MDT_EFFECTIVE_DPI, &x, &y);
+
6486
+
6487 monitor.pixelRatio = (float) (x) / (float) dpiX;
+
6488 monitor.pixelRatio = (float) (y) / (float) dpiY;
+
6489 }
+
6490 #endif
6491
-
6492#ifndef RGFW_NO_MONITOR
-
6493
-
6494RGFW_monitor RGFW_monitors[6];
-
6495BOOL CALLBACK GetMonitorHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
-
6496 RGFW_UNUSED(hdcMonitor);
-
6497 RGFW_UNUSED(lprcMonitor);
-
6498
-
6499 RGFW_mInfo* info = (RGFW_mInfo*) dwData;
-
6500
-
6501 if (info->iIndex >= 6)
-
6502 return FALSE;
-
6503
-
6504 RGFW_monitors[info->iIndex] = win32CreateMonitor(hMonitor);
-
6505 info->iIndex++;
+
6492 #ifdef RGFW_DEBUG
+
6493 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
+
6494 #endif
+
6495
+
6496 return monitor;
+
6497}
+
6498#endif /* RGFW_NO_MONITOR */
+
6499
+
6500#ifndef RGFW_NO_MONITOR
+
6501
+
6502RGFW_monitor RGFW_monitors[6];
+
6503BOOL CALLBACK GetMonitorHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
+
6504 RGFW_UNUSED(hdcMonitor);
+
6505 RGFW_UNUSED(lprcMonitor);
6506
-
6507 return TRUE;
-
6508}
-
6509
- -
6511 #ifdef __cplusplus
-
6512 return win32CreateMonitor(MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
-
6513 #else
-
6514 return win32CreateMonitor(MonitorFromPoint((POINT) { 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
-
6515 #endif
+
6507 RGFW_mInfo* info = (RGFW_mInfo*) dwData;
+
6508
+
6509 if (info->iIndex >= 6)
+
6510 return FALSE;
+
6511
+
6512 RGFW_monitors[info->iIndex] = win32CreateMonitor(hMonitor);
+
6513 info->iIndex++;
+
6514
+
6515 return TRUE;
6516}
6517
- -
6519 RGFW_mInfo info;
-
6520 info.iIndex = 0;
-
6521 while (EnumDisplayMonitors(NULL, NULL, GetMonitorHandle, (LPARAM) &info));
-
6522
-
6523 return RGFW_monitors;
+ +
6519 #ifdef __cplusplus
+
6520 return win32CreateMonitor(MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
+
6521 #else
+
6522 return win32CreateMonitor(MonitorFromPoint((POINT) { 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
+
6523 #endif
6524}
6525
- -
6527 HMONITOR src = MonitorFromWindow(win->src.window, MONITOR_DEFAULTTOPRIMARY);
-
6528 return win32CreateMonitor(src);
-
6529}
+ +
6527 RGFW_mInfo info;
+
6528 info.iIndex = 0;
+
6529 while (EnumDisplayMonitors(NULL, NULL, GetMonitorHandle, (LPARAM) &info));
6530
-
6531#endif
-
6532
-
6533HICON RGFW_loadHandleImage(u8* src, RGFW_area a, BOOL icon) {
-
6534 u32 i;
-
6535 HDC dc;
-
6536 HICON handle;
-
6537 HBITMAP color, mask;
-
6538 BITMAPV5HEADER bi;
-
6539 ICONINFO ii;
-
6540 u8* target = NULL;
-
6541 u8* source = src;
-
6542
-
6543 ZeroMemory(&bi, sizeof(bi));
-
6544 bi.bV5Size = sizeof(bi);
-
6545 bi.bV5Width = a.w;
-
6546 bi.bV5Height = -((LONG) a.h);
-
6547 bi.bV5Planes = 1;
-
6548 bi.bV5BitCount = 32;
-
6549 bi.bV5Compression = BI_BITFIELDS;
-
6550 bi.bV5RedMask = 0x00ff0000;
-
6551 bi.bV5GreenMask = 0x0000ff00;
-
6552 bi.bV5BlueMask = 0x000000ff;
-
6553 bi.bV5AlphaMask = 0xff000000;
-
6554
-
6555 dc = GetDC(NULL);
-
6556 color = CreateDIBSection(dc,
-
6557 (BITMAPINFO*) &bi,
-
6558 DIB_RGB_COLORS,
-
6559 (void**) &target,
-
6560 NULL,
-
6561 (DWORD) 0);
-
6562 ReleaseDC(NULL, dc);
-
6563
-
6564 mask = CreateBitmap(a.w, a.h, 1, 1, NULL);
-
6565
-
6566 for (i = 0; i < a.w * a.h; i++) {
-
6567 target[0] = source[2];
-
6568 target[1] = source[1];
-
6569 target[2] = source[0];
-
6570 target[3] = source[3];
-
6571 target += 4;
-
6572 source += 4;
-
6573 }
-
6574
-
6575 ZeroMemory(&ii, sizeof(ii));
-
6576 ii.fIcon = icon;
-
6577 ii.xHotspot = 0;
-
6578 ii.yHotspot = 0;
-
6579 ii.hbmMask = mask;
-
6580 ii.hbmColor = color;
-
6581
-
6582 handle = CreateIconIndirect(&ii);
-
6583
-
6584 DeleteObject(color);
-
6585 DeleteObject(mask);
-
6586
-
6587 return handle;
-
6588}
+
6531 return RGFW_monitors;
+
6532}
+
6533
+ +
6535 HMONITOR src = MonitorFromWindow(win->src.window, MONITOR_DEFAULTTOPRIMARY);
+
6536 return win32CreateMonitor(src);
+
6537}
+
6538
+
6539#endif
+
6540
+
6541HICON RGFW_loadHandleImage(u8* src, RGFW_area a, BOOL icon) {
+
6542 u32 i;
+
6543 HDC dc;
+
6544 HICON handle;
+
6545 HBITMAP color, mask;
+
6546 BITMAPV5HEADER bi;
+
6547 ICONINFO ii;
+
6548 u8* target = NULL;
+
6549 u8* source = src;
+
6550
+
6551 ZeroMemory(&bi, sizeof(bi));
+
6552 bi.bV5Size = sizeof(bi);
+
6553 bi.bV5Width = a.w;
+
6554 bi.bV5Height = -((LONG) a.h);
+
6555 bi.bV5Planes = 1;
+
6556 bi.bV5BitCount = 32;
+
6557 bi.bV5Compression = BI_BITFIELDS;
+
6558 bi.bV5RedMask = 0x00ff0000;
+
6559 bi.bV5GreenMask = 0x0000ff00;
+
6560 bi.bV5BlueMask = 0x000000ff;
+
6561 bi.bV5AlphaMask = 0xff000000;
+
6562
+
6563 dc = GetDC(NULL);
+
6564 color = CreateDIBSection(dc,
+
6565 (BITMAPINFO*) &bi,
+
6566 DIB_RGB_COLORS,
+
6567 (void**) &target,
+
6568 NULL,
+
6569 (DWORD) 0);
+
6570 ReleaseDC(NULL, dc);
+
6571
+
6572 mask = CreateBitmap(a.w, a.h, 1, 1, NULL);
+
6573
+
6574 for (i = 0; i < a.w * a.h; i++) {
+
6575 target[0] = source[2];
+
6576 target[1] = source[1];
+
6577 target[2] = source[0];
+
6578 target[3] = source[3];
+
6579 target += 4;
+
6580 source += 4;
+
6581 }
+
6582
+
6583 ZeroMemory(&ii, sizeof(ii));
+
6584 ii.fIcon = icon;
+
6585 ii.xHotspot = 0;
+
6586 ii.yHotspot = 0;
+
6587 ii.hbmMask = mask;
+
6588 ii.hbmColor = color;
6589
-
6590void* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
-
6591 RGFW_UNUSED(channels);
-
6592
-
6593 HCURSOR cursor = (HCURSOR) RGFW_loadHandleImage(icon, a, FALSE);
-
6594 return cursor;
-
6595}
-
6596
-
6597void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
-
6598 RGFW_ASSERT(win && mouse);
-
6599 SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) mouse);
-
6600 SetCursor((HCURSOR)mouse);
-
6601}
-
6602
-
6603void RGFW_freeMouse(RGFW_mouse* mouse) {
-
6604 RGFW_ASSERT(mouse);
-
6605 DestroyCursor((HCURSOR)mouse);
-
6606}
-
6607
- -
6609 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
-
6610}
-
6611
- -
6613 RGFW_ASSERT(win != NULL);
-
6614
-
6615 if (mouse > (sizeof(RGFW_mouseIconSrc) / sizeof(u32)))
-
6616 return 0;
-
6617
-
6618 char* icon = MAKEINTRESOURCEA(RGFW_mouseIconSrc[mouse]);
+
6590 handle = CreateIconIndirect(&ii);
+
6591
+
6592 DeleteObject(color);
+
6593 DeleteObject(mask);
+
6594
+
6595 return handle;
+
6596}
+
6597
+
6598void* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
+
6599 RGFW_UNUSED(channels);
+
6600
+
6601 HCURSOR cursor = (HCURSOR) RGFW_loadHandleImage(icon, a, FALSE);
+
6602 return cursor;
+
6603}
+
6604
+
6605void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
+
6606 RGFW_ASSERT(win && mouse);
+
6607 SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) mouse);
+
6608 SetCursor((HCURSOR)mouse);
+
6609}
+
6610
+
6611void RGFW_freeMouse(RGFW_mouse* mouse) {
+
6612 RGFW_ASSERT(mouse);
+
6613 DestroyCursor((HCURSOR)mouse);
+
6614}
+
6615
+ +
6617 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
+
6618}
6619
-
6620 SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) LoadCursorA(NULL, icon));
-
6621 SetCursor(LoadCursorA(NULL, icon));
-
6622 return 1;
-
6623}
-
6624
-
6625void RGFW_window_hide(RGFW_window* win) {
-
6626 ShowWindow(win->src.window, SW_HIDE);
-
6627}
-
6628
-
6629void RGFW_window_show(RGFW_window* win) {
-
6630 ShowWindow(win->src.window, SW_RESTORE);
+ +
6621 RGFW_ASSERT(win != NULL);
+
6622
+
6623 if (mouse > (sizeof(RGFW_mouseIconSrc) / sizeof(u32)))
+
6624 return 0;
+
6625
+
6626 char* icon = MAKEINTRESOURCEA(RGFW_mouseIconSrc[mouse]);
+
6627
+
6628 SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) LoadCursorA(NULL, icon));
+
6629 SetCursor(LoadCursorA(NULL, icon));
+
6630 return 1;
6631}
6632
-
6633#define RGFW_FREE_LIBRARY(x) if (x != NULL) FreeLibrary(x); x = NULL;
-
6634
-
6635void RGFW_window_close(RGFW_window* win) {
-
6636 RGFW_ASSERT(win != NULL);
-
6637 RGFW_windowsOpen--;
-
6638
-
6639 #ifdef RGFW_EGL
-
6640 RGFW_closeEGL(win);
-
6641 #endif
+
6633void RGFW_window_hide(RGFW_window* win) {
+
6634 ShowWindow(win->src.window, SW_HIDE);
+
6635}
+
6636
+
6637void RGFW_window_show(RGFW_window* win) {
+
6638 ShowWindow(win->src.window, SW_RESTORE);
+
6639}
+
6640
+
6641#define RGFW_FREE_LIBRARY(x) if (x != NULL) FreeLibrary(x); x = NULL;
6642
-
6643 #ifdef RGFW_DIRECTX
-
6644 win->src.swapchain->lpVtbl->Release(win->src.swapchain);
-
6645 win->src.renderTargetView->lpVtbl->Release(win->src.renderTargetView);
-
6646 win->src.pDepthStencilView->lpVtbl->Release(win->src.pDepthStencilView);
-
6647 #endif
-
6648
-
6649 #ifdef RGFW_BUFFER
-
6650 DeleteDC(win->src.hdcMem);
-
6651 DeleteObject(win->src.bitmap);
-
6652 #endif
-
6653
-
6654 #ifdef RGFW_OPENGL
-
6655 wglDeleteContext((HGLRC) win->src.ctx);
-
6656 #endif
-
6657 ReleaseDC(win->src.window, win->src.hdc);
-
6658 DestroyWindow(win->src.window);
-
6660 if (RGFW_windowsOpen <= 0) {
-
6661 #ifdef RGFW_DIRECTX
-
6662 RGFW_dxInfo.pDeviceContext->lpVtbl->Release(RGFW_dxInfo.pDeviceContext);
-
6663 RGFW_dxInfo.pDevice->lpVtbl->Release(RGFW_dxInfo.pDevice);
-
6664 RGFW_dxInfo.pAdapter->lpVtbl->Release(RGFW_dxInfo.pAdapter);
-
6665 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
-
6666 #endif
-
6667
-
6668 #ifndef RGFW_NO_XINPUT
-
6669 RGFW_FREE_LIBRARY(RGFW_XInput_dll);
-
6670 #endif
-
6671
-
6672 #ifndef RGFW_NO_DPI
-
6673 RGFW_FREE_LIBRARY(RGFW_Shcore_dll);
+
6643void RGFW_window_close(RGFW_window* win) {
+
6644 RGFW_ASSERT(win != NULL);
+
6645 RGFW_windowsOpen--;
+
6646
+
6647 #ifdef RGFW_EGL
+
6648 RGFW_closeEGL(win);
+
6649 #endif
+
6650
+
6651 #ifdef RGFW_DIRECTX
+
6652 win->src.swapchain->lpVtbl->Release(win->src.swapchain);
+
6653 win->src.renderTargetView->lpVtbl->Release(win->src.renderTargetView);
+
6654 win->src.pDepthStencilView->lpVtbl->Release(win->src.pDepthStencilView);
+
6655 #endif
+
6656
+
6657 #ifdef RGFW_BUFFER
+
6658 DeleteDC(win->src.hdcMem);
+
6659 DeleteObject(win->src.bitmap);
+
6660 #endif
+
6661
+
6662 #ifdef RGFW_OPENGL
+
6663 wglDeleteContext((HGLRC) win->src.ctx);
+
6664 #endif
+
6665 ReleaseDC(win->src.window, win->src.hdc);
+
6666 DestroyWindow(win->src.window);
+
6668 if (RGFW_windowsOpen <= 0) {
+
6669 #ifdef RGFW_DIRECTX
+
6670 RGFW_dxInfo.pDeviceContext->lpVtbl->Release(RGFW_dxInfo.pDeviceContext);
+
6671 RGFW_dxInfo.pDevice->lpVtbl->Release(RGFW_dxInfo.pDevice);
+
6672 RGFW_dxInfo.pAdapter->lpVtbl->Release(RGFW_dxInfo.pAdapter);
+
6673 RGFW_dxInfo.pFactory->lpVtbl->Release(RGFW_dxInfo.pFactory);
6674 #endif
6675
-
6676 #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
-
6677 RGFW_FREE_LIBRARY(RGFW_winmm_dll);
+
6676 #ifndef RGFW_NO_XINPUT
+
6677 RGFW_FREE_LIBRARY(RGFW_XInput_dll);
6678 #endif
6679
-
6680 RGFW_FREE_LIBRARY(RGFW_wgl_dll);
-
6681 RGFW_root = NULL;
-
6682
-
6683 if (RGFW_hiddenMouse != NULL) {
-
6684 RGFW_freeMouse(RGFW_hiddenMouse);
-
6685 RGFW_hiddenMouse = 0;
-
6686 }
-
6687 }
-
6688
-
6689 RGFW_clipboard_switch(NULL);
+
6680 #ifndef RGFW_NO_DPI
+
6681 RGFW_FREE_LIBRARY(RGFW_Shcore_dll);
+
6682 #endif
+
6683
+
6684 #if !defined(RGFW_NO_LOAD_WINMM) && !defined(RGFW_NO_WINMM)
+
6685 RGFW_FREE_LIBRARY(RGFW_winmm_dll);
+
6686 #endif
+
6687
+
6688 RGFW_FREE_LIBRARY(RGFW_wgl_dll);
+
6689 RGFW_root = NULL;
6690
-
6691 if ((win->_flags & RGFW_WINDOW_ALLOC))
-
6692 RGFW_FREE(win);
-
6693}
-
6694
- -
6696 RGFW_ASSERT(win != NULL);
-
6697
-
6698 win->r.x = v.x;
-
6699 win->r.y = v.y;
-
6700 SetWindowPos(win->src.window, HWND_TOP, win->r.x, win->r.y, 0, 0, SWP_NOSIZE);
+
6691 if (RGFW_hiddenMouse != NULL) {
+
6692 RGFW_freeMouse(RGFW_hiddenMouse);
+
6693 RGFW_hiddenMouse = 0;
+
6694 }
+
6695 }
+
6696
+
6697 RGFW_clipboard_switch(NULL);
+
6698
+
6699 if ((win->_flags & RGFW_WINDOW_ALLOC))
+
6700 RGFW_FREE(win);
6701}
6702
- +
6704 RGFW_ASSERT(win != NULL);
6705
-
6706 win->r.w = a.w;
-
6707 win->r.h = a.h;
-
6708 SetWindowPos(win->src.window, HWND_TOP, 0, 0, win->r.w, win->r.h + win->src.hOffset, SWP_NOMOVE);
+
6706 win->r.x = v.x;
+
6707 win->r.y = v.y;
+
6708 SetWindowPos(win->src.window, HWND_TOP, win->r.x, win->r.y, 0, 0, SWP_NOSIZE);
6709}
6710
-
6711
-
6712void RGFW_window_setName(RGFW_window* win, const char* name) {
-
6713 RGFW_ASSERT(win != NULL);
-
6714
-
6715 SetWindowTextA(win->src.window, name);
-
6716}
-
6717
-
6718#ifndef RGFW_NO_PASSTHROUGH
+ +
6712 RGFW_ASSERT(win != NULL);
+
6713
+
6714 win->r.w = a.w;
+
6715 win->r.h = a.h;
+
6716 SetWindowPos(win->src.window, HWND_TOP, 0, 0, win->r.w, win->r.h + win->src.hOffset, SWP_NOMOVE);
+
6717}
+
6718
6719
-
6720void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
+
6720void RGFW_window_setName(RGFW_window* win, const char* name) {
6721 RGFW_ASSERT(win != NULL);
6722
-
6723 COLORREF key = 0;
-
6724 BYTE alpha = 0;
-
6725 DWORD flags = 0;
-
6726 DWORD exStyle = GetWindowLongW(win->src.window, GWL_EXSTYLE);
+
6723 SetWindowTextA(win->src.window, name);
+
6724}
+
6725
+
6726#ifndef RGFW_NO_PASSTHROUGH
6727
-
6728 if (exStyle & WS_EX_LAYERED)
-
6729 GetLayeredWindowAttributes(win->src.window, &key, &alpha, &flags);
+
6728void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
+
6729 RGFW_ASSERT(win != NULL);
6730
-
6731 if (passthrough)
-
6732 exStyle |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
-
6733 else {
-
6734 exStyle &= ~WS_EX_TRANSPARENT;
-
6735 if (exStyle & WS_EX_LAYERED && !(flags & LWA_ALPHA))
-
6736 exStyle &= ~WS_EX_LAYERED;
-
6737 }
+
6731 COLORREF key = 0;
+
6732 BYTE alpha = 0;
+
6733 DWORD flags = 0;
+
6734 DWORD exStyle = GetWindowLongW(win->src.window, GWL_EXSTYLE);
+
6735
+
6736 if (exStyle & WS_EX_LAYERED)
+
6737 GetLayeredWindowAttributes(win->src.window, &key, &alpha, &flags);
6738
-
6739 SetWindowLongW(win->src.window, GWL_EXSTYLE, exStyle);
-
6740
-
6741 if (passthrough)
-
6742 SetLayeredWindowAttributes(win->src.window, key, alpha, flags);
-
6743}
-
6744#endif
-
6745
-
6746b32 RGFW_window_setIcon(RGFW_window* win, u8* src, RGFW_area a, i32 channels) {
-
6747 RGFW_ASSERT(win != NULL);
-
6748 #ifndef RGFW_WIN95
-
6749 RGFW_UNUSED(channels);
-
6750
-
6751 HICON handle = RGFW_loadHandleImage(src, a, TRUE);
-
6752
-
6753 SetClassLongPtrA(win->src.window, GCLP_HICON, (LPARAM) handle);
-
6754
-
6755 DestroyIcon(handle);
-
6756 return 1;
-
6757 #else
-
6758 RGFW_UNUSED(src);
-
6759 RGFW_UNUSED(a);
-
6760 RGFW_UNUSED(channels);
-
6761 return 0;
-
6762 #endif
-
6763}
-
6764
-
6765RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
-
6766 /* Open the clipboard */
-
6767 if (OpenClipboard(NULL) == 0)
-
6768 return -1;
-
6769
-
6770 /* Get the clipboard data as a Unicode string */
-
6771 HANDLE hData = GetClipboardData(CF_UNICODETEXT);
-
6772 if (hData == NULL) {
-
6773 CloseClipboard();
-
6774 return -1;
-
6775 }
-
6776
-
6777 wchar_t* wstr = (wchar_t*) GlobalLock(hData);
-
6778
-
6779 RGFW_ssize_t textLen = 0;
-
6780
-
6781 {
-
6782 setlocale(LC_ALL, "en_US.UTF-8");
-
6783
-
6784 textLen = wcstombs(NULL, wstr, 0) + 1;
-
6785 if (str != NULL && (RGFW_ssize_t)strCapacity <= textLen - 1)
-
6786 textLen = 0;
-
6787
-
6788 if (str != NULL && textLen) {
-
6789
-
6790 if (textLen > 1)
-
6791 wcstombs(str, wstr, (textLen) );
-
6792
-
6793 str[textLen] = '\0';
-
6794 }
-
6795 }
-
6796
-
6797 /* Release the clipboard data */
-
6798 GlobalUnlock(hData);
-
6799 CloseClipboard();
-
6800
-
6801 return textLen;
-
6802}
-
6803
-
6804void RGFW_writeClipboard(const char* text, u32 textLen) {
-
6805 HANDLE object;
-
6806 WCHAR* buffer;
-
6807
-
6808 object = GlobalAlloc(GMEM_MOVEABLE, (1 + textLen) * sizeof(WCHAR));
-
6809 if (!object)
-
6810 return;
+
6739 if (passthrough)
+
6740 exStyle |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
+
6741 else {
+
6742 exStyle &= ~WS_EX_TRANSPARENT;
+
6743 if (exStyle & WS_EX_LAYERED && !(flags & LWA_ALPHA))
+
6744 exStyle &= ~WS_EX_LAYERED;
+
6745 }
+
6746
+
6747 SetWindowLongW(win->src.window, GWL_EXSTYLE, exStyle);
+
6748
+
6749 if (passthrough)
+
6750 SetLayeredWindowAttributes(win->src.window, key, alpha, flags);
+
6751}
+
6752#endif
+
6753
+
6754b32 RGFW_window_setIcon(RGFW_window* win, u8* src, RGFW_area a, i32 channels) {
+
6755 RGFW_ASSERT(win != NULL);
+
6756 #ifndef RGFW_WIN95
+
6757 RGFW_UNUSED(channels);
+
6758
+
6759 HICON handle = RGFW_loadHandleImage(src, a, TRUE);
+
6760
+
6761 SetClassLongPtrA(win->src.window, GCLP_HICON, (LPARAM) handle);
+
6762
+
6763 DestroyIcon(handle);
+
6764 return 1;
+
6765 #else
+
6766 RGFW_UNUSED(src);
+
6767 RGFW_UNUSED(a);
+
6768 RGFW_UNUSED(channels);
+
6769 return 0;
+
6770 #endif
+
6771}
+
6772
+
6773RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
+
6774 /* Open the clipboard */
+
6775 if (OpenClipboard(NULL) == 0)
+
6776 return -1;
+
6777
+
6778 /* Get the clipboard data as a Unicode string */
+
6779 HANDLE hData = GetClipboardData(CF_UNICODETEXT);
+
6780 if (hData == NULL) {
+
6781 CloseClipboard();
+
6782 return -1;
+
6783 }
+
6784
+
6785 wchar_t* wstr = (wchar_t*) GlobalLock(hData);
+
6786
+
6787 RGFW_ssize_t textLen = 0;
+
6788
+
6789 {
+
6790 setlocale(LC_ALL, "en_US.UTF-8");
+
6791
+
6792 textLen = wcstombs(NULL, wstr, 0) + 1;
+
6793 if (str != NULL && (RGFW_ssize_t)strCapacity <= textLen - 1)
+
6794 textLen = 0;
+
6795
+
6796 if (str != NULL && textLen) {
+
6797
+
6798 if (textLen > 1)
+
6799 wcstombs(str, wstr, (textLen) );
+
6800
+
6801 str[textLen] = '\0';
+
6802 }
+
6803 }
+
6804
+
6805 /* Release the clipboard data */
+
6806 GlobalUnlock(hData);
+
6807 CloseClipboard();
+
6808
+
6809 return textLen;
+
6810}
6811
-
6812 buffer = (WCHAR*) GlobalLock(object);
-
6813 if (!buffer) {
-
6814 GlobalFree(object);
-
6815 return;
-
6816 }
-
6817
-
6818 MultiByteToWideChar(CP_UTF8, 0, text, -1, buffer, textLen);
-
6819 GlobalUnlock(object);
-
6820
-
6821 if (!OpenClipboard(RGFW_root->src.window)) {
+
6812void RGFW_writeClipboard(const char* text, u32 textLen) {
+
6813 HANDLE object;
+
6814 WCHAR* buffer;
+
6815
+
6816 object = GlobalAlloc(GMEM_MOVEABLE, (1 + textLen) * sizeof(WCHAR));
+
6817 if (!object)
+
6818 return;
+
6819
+
6820 buffer = (WCHAR*) GlobalLock(object);
+
6821 if (!buffer) {
6822 GlobalFree(object);
6823 return;
6824 }
6825
-
6826 EmptyClipboard();
-
6827 SetClipboardData(CF_UNICODETEXT, object);
-
6828 CloseClipboard();
-
6829}
-
6830
- -
6832 RGFW_ASSERT(win != NULL);
-
6833 win->_lastMousePoint = RGFW_POINT(p.x - win->r.x, p.y - win->r.y);
-
6834 SetCursorPos(p.x, p.y);
-
6835}
-
6836
-
6837#ifdef RGFW_OPENGL
- -
6839 if (win == NULL)
-
6840 wglMakeCurrent(NULL, NULL);
-
6841 else
-
6842 wglMakeCurrent(win->src.hdc, (HGLRC) win->src.ctx);
+
6826 MultiByteToWideChar(CP_UTF8, 0, text, -1, buffer, textLen);
+
6827 GlobalUnlock(object);
+
6828
+
6829 if (!OpenClipboard(RGFW_root->src.window)) {
+
6830 GlobalFree(object);
+
6831 return;
+
6832 }
+
6833
+
6834 EmptyClipboard();
+
6835 SetClipboardData(CF_UNICODETEXT, object);
+
6836 CloseClipboard();
+
6837}
+
6838
+ +
6840 RGFW_ASSERT(win != NULL);
+
6841 win->_lastMousePoint = RGFW_POINT(p.x - win->r.x, p.y - win->r.y);
+
6842 SetCursorPos(p.x, p.y);
6843}
-
6844#endif
-
6845
-
6846#ifndef RGFW_EGL
-
6847
-
6848void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
-
6849 RGFW_ASSERT(win != NULL);
-
6850
-
6851 #if defined(RGFW_OPENGL)
-
6852 typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALEXTPROC)(int interval);
-
6853 static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
-
6854 static void* loadSwapFunc = (void*) 1;
+
6844
+
6845#ifdef RGFW_OPENGL
+ +
6847 if (win == NULL)
+
6848 wglMakeCurrent(NULL, NULL);
+
6849 else
+
6850 wglMakeCurrent(win->src.hdc, (HGLRC) win->src.ctx);
+
6851}
+
6852#endif
+
6853
+
6854#ifndef RGFW_EGL
6855
-
6856 if (loadSwapFunc == NULL) {
-
6857 #ifdef RGFW_DEBUG
-
6858 fprintf(stderr, "wglSwapIntervalEXT not supported\n");
-
6859 #endif
-
6860 return;
-
6861 }
-
6862
-
6863 if (wglSwapIntervalEXT == NULL) {
-
6864 loadSwapFunc = (void*) wglGetProcAddress("wglSwapIntervalEXT");
-
6865 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) loadSwapFunc;
-
6866 }
-
6867
-
6868 if (wglSwapIntervalEXT(swapInterval) == FALSE) {
-
6869 #ifdef RGFW_DEBUG
-
6870 fprintf(stderr, "Failed to set swap interval\n");
-
6871 #endif
-
6872 }
-
6873 #else
-
6874 RGFW_UNUSED(swapInterval);
-
6875 #endif
-
6876}
-
6877
-
6878#endif
-
6879
- -
6881 RGFW_ASSERT(win != NULL);
-
6882 /* clear the window*/
-
6883
-
6884 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
-
6885 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
6886 HGDIOBJ oldbmp = SelectObject(win->src.hdcMem, win->src.bitmap);
-
6887 BitBlt(win->src.hdc, 0, 0, win->r.w, win->r.h, win->src.hdcMem, 0, 0, SRCCOPY);
-
6888 SelectObject(win->src.hdcMem, oldbmp);
-
6889 #endif
-
6890 }
+
6856void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
+
6857 RGFW_ASSERT(win != NULL);
+
6858
+
6859 #if defined(RGFW_OPENGL)
+
6860 typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALEXTPROC)(int interval);
+
6861 static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
+
6862 static void* loadSwapFunc = (void*) 1;
+
6863
+
6864 if (loadSwapFunc == NULL) {
+
6865 #ifdef RGFW_DEBUG
+
6866 fprintf(stderr, "wglSwapIntervalEXT not supported\n");
+
6867 #endif
+
6868 return;
+
6869 }
+
6870
+
6871 if (wglSwapIntervalEXT == NULL) {
+
6872 loadSwapFunc = (void*) wglGetProcAddress("wglSwapIntervalEXT");
+
6873 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) loadSwapFunc;
+
6874 }
+
6875
+
6876 if (wglSwapIntervalEXT(swapInterval) == FALSE) {
+
6877 #ifdef RGFW_DEBUG
+
6878 fprintf(stderr, "Failed to set swap interval\n");
+
6879 #endif
+
6880 }
+
6881 #else
+
6882 RGFW_UNUSED(swapInterval);
+
6883 #endif
+
6884}
+
6885
+
6886#endif
+
6887
+ +
6889 RGFW_ASSERT(win != NULL);
+
6890 /* clear the window*/
6891
-
6892 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
-
6893 #ifdef RGFW_EGL
-
6894 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
-
6895 #elif defined(RGFW_OPENGL)
-
6896 SwapBuffers(win->src.hdc);
-
6897 #endif
-
6898
-
6899 #if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX)
-
6900 win->src.swapchain->lpVtbl->Present(win->src.swapchain, 0, 0);
-
6901 #endif
-
6902 }
-
6903}
-
6904
-
6905char* RGFW_createUTF8FromWideStringWin32(const WCHAR* source) {
-
6906 if (source == NULL) {
-
6907 return NULL;
-
6908 }
-
6909 i32 size = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
-
6910 if (!size) {
-
6911 return NULL;
-
6912 }
-
6913
-
6914 static char target[RGFW_MAX_PATH * 2];
-
6915 if (size > RGFW_MAX_PATH * 2)
-
6916 size = RGFW_MAX_PATH * 2;
-
6917
-
6918 target[size] = 0;
-
6919
-
6920 if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL)) {
-
6921 return NULL;
-
6922 }
-
6923
-
6924 return target;
-
6925}
-
6926
-
6927static inline LARGE_INTEGER RGFW_win32_initTimer(void) {
-
6928 static LARGE_INTEGER frequency = {{0, 0}};
-
6929 if (frequency.QuadPart == 0) {
-
6930 #if !defined(RGFW_NO_WINMM)
-
6931 timeBeginPeriod(1);
-
6932 #endif
-
6933 QueryPerformanceFrequency(&frequency);
-
6934 }
-
6935
-
6936 return frequency;
-
6937}
-
6938
-
6939u64 RGFW_getTimeNS(void) {
-
6940 LARGE_INTEGER frequency = RGFW_win32_initTimer();
-
6941
-
6942 LARGE_INTEGER counter;
-
6943 QueryPerformanceCounter(&counter);
-
6944
-
6945 return (u64) ((counter.QuadPart * 1e9) / frequency.QuadPart);
-
6946}
-
6947
-
6948u64 RGFW_getTime(void) {
-
6949 LARGE_INTEGER frequency = RGFW_win32_initTimer();
-
6950
-
6951 LARGE_INTEGER counter;
-
6952 QueryPerformanceCounter(&counter);
-
6953 return (u64) (counter.QuadPart / (double) frequency.QuadPart);
-
6954}
+
6892 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
+
6893 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
6894 if (win->buffer != win->src.bitmapBits)
+
6895 memcpy(win->src.bitmapBits, win->buffer, win->bufferSize.w * win->bufferSize.h * 4);
+
6896
+
6897 HGDIOBJ oldbmp = SelectObject(win->src.hdcMem, win->src.bitmap);
+
6898 BitBlt(win->src.hdc, 0, 0, win->r.w, win->r.h, win->src.hdcMem, 0, 0, SRCCOPY);
+
6899 SelectObject(win->src.hdcMem, oldbmp);
+
6900 #endif
+
6901 }
+
6902
+
6903 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
+
6904 #ifdef RGFW_EGL
+
6905 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
+
6906 #elif defined(RGFW_OPENGL)
+
6907 SwapBuffers(win->src.hdc);
+
6908 #endif
+
6909
+
6910 #if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX)
+
6911 win->src.swapchain->lpVtbl->Present(win->src.swapchain, 0, 0);
+
6912 #endif
+
6913 }
+
6914}
+
6915
+
6916char* RGFW_createUTF8FromWideStringWin32(const WCHAR* source) {
+
6917 if (source == NULL) {
+
6918 return NULL;
+
6919 }
+
6920 i32 size = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL);
+
6921 if (!size) {
+
6922 return NULL;
+
6923 }
+
6924
+
6925 static char target[RGFW_MAX_PATH * 2];
+
6926 if (size > RGFW_MAX_PATH * 2)
+
6927 size = RGFW_MAX_PATH * 2;
+
6928
+
6929 target[size] = 0;
+
6930
+
6931 if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, size, NULL, NULL)) {
+
6932 return NULL;
+
6933 }
+
6934
+
6935 return target;
+
6936}
+
6937
+
6938static inline LARGE_INTEGER RGFW_win32_initTimer(void) {
+
6939 static LARGE_INTEGER frequency = {{0, 0}};
+
6940 if (frequency.QuadPart == 0) {
+
6941 #if !defined(RGFW_NO_WINMM)
+
6942 timeBeginPeriod(1);
+
6943 #endif
+
6944 QueryPerformanceFrequency(&frequency);
+
6945 }
+
6946
+
6947 return frequency;
+
6948}
+
6949
+
6950u64 RGFW_getTimeNS(void) {
+
6951 LARGE_INTEGER frequency = RGFW_win32_initTimer();
+
6952
+
6953 LARGE_INTEGER counter;
+
6954 QueryPerformanceCounter(&counter);
6955
-
6956void RGFW_sleep(u64 ms) {
-
6957 Sleep(ms);
-
6958}
-
6959
-
6960#ifndef RGFW_NO_THREADS
+
6956 return (u64) ((counter.QuadPart * 1e9) / frequency.QuadPart);
+
6957}
+
6958
+
6959u64 RGFW_getTime(void) {
+
6960 LARGE_INTEGER frequency = RGFW_win32_initTimer();
6961
-
6962RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args) { return CreateThread(NULL, 0, ptr, args, 0, NULL); }
-
6963void RGFW_cancelThread(RGFW_thread thread) { CloseHandle((HANDLE) thread); }
-
6964void RGFW_joinThread(RGFW_thread thread) { WaitForSingleObject((HANDLE) thread, INFINITE); }
-
6965void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { SetThreadPriority((HANDLE) thread, priority); }
+
6962 LARGE_INTEGER counter;
+
6963 QueryPerformanceCounter(&counter);
+
6964 return (u64) (counter.QuadPart / (double) frequency.QuadPart);
+
6965}
6966
-
6967#endif
-
6968#endif /* RGFW_WINDOWS */
-
6969
-
6970/*
-
6971 End of Windows defines
-
6972*/
-
6973
-
6974
-
6975
-
6976/*
-
6977
-
6978 Start of MacOS defines
-
6979
-
6980
-
6981*/
-
6982
-
6983#if defined(RGFW_MACOS)
-
6984/*
-
6985 based on silicon.h
-
6986 start of cocoa wrapper
-
6987*/
-
6988
-
6989#include <CoreGraphics/CoreGraphics.h>
-
6990#include <ApplicationServices/ApplicationServices.h>
-
6991#include <objc/runtime.h>
-
6992#include <objc/message.h>
-
6993#include <mach/mach_time.h>
-
6994
-
6995typedef CGRect NSRect;
-
6996typedef CGPoint NSPoint;
-
6997typedef CGSize NSSize;
-
6998
-
6999typedef const char* NSPasteboardType;
-
7000typedef unsigned long NSUInteger;
-
7001typedef long NSInteger;
-
7002typedef NSInteger NSModalResponse;
-
7003
-
7004#ifdef __arm64__
-
7005 /* ARM just uses objc_msgSend */
-
7006#define abi_objc_msgSend_stret objc_msgSend
-
7007#define abi_objc_msgSend_fpret objc_msgSend
-
7008#else /* __i386__ */
-
7009 /* x86 just uses abi_objc_msgSend_fpret and (NSColor *)objc_msgSend_id respectively */
-
7010#define abi_objc_msgSend_stret objc_msgSend_stret
-
7011#define abi_objc_msgSend_fpret objc_msgSend_fpret
-
7012#endif
-
7013
-
7014#define NSAlloc(nsclass) objc_msgSend_id((id)nsclass, sel_registerName("alloc"))
-
7015#define objc_msgSend_bool(x, y) ((BOOL (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
-
7016#define objc_msgSend_void(x, y) ((void (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
-
7017#define objc_msgSend_void_id(x, y, z) ((void (*)(id, SEL, id))objc_msgSend) ((id)x, (SEL)y, (id)z)
-
7018#define objc_msgSend_uint(x, y) ((NSUInteger (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
-
7019#define objc_msgSend_void_bool(x, y, z) ((void (*)(id, SEL, BOOL))objc_msgSend) ((id)(x), (SEL)y, (BOOL)z)
-
7020#define objc_msgSend_bool_void(x, y) ((BOOL (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
-
7021#define objc_msgSend_void_SEL(x, y, z) ((void (*)(id, SEL, SEL))objc_msgSend) ((id)(x), (SEL)y, (SEL)z)
-
7022#define objc_msgSend_id(x, y) ((id (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
-
7023#define objc_msgSend_id_id(x, y, z) ((id (*)(id, SEL, id))objc_msgSend) ((id)(x), (SEL)y, (id)z)
-
7024#define objc_msgSend_id_bool(x, y, z) ((BOOL (*)(id, SEL, id))objc_msgSend) ((id)(x), (SEL)y, (id)z)
-
7025#define objc_msgSend_int(x, y, z) ((id (*)(id, SEL, int))objc_msgSend) ((id)(x), (SEL)y, (int)z)
-
7026#define objc_msgSend_arr(x, y, z) ((id (*)(id, SEL, int))objc_msgSend) ((id)(x), (SEL)y, (int)z)
-
7027#define objc_msgSend_ptr(x, y, z) ((id (*)(id, SEL, void*))objc_msgSend) ((id)(x), (SEL)y, (void*)z)
-
7028#define objc_msgSend_class(x, y) ((id (*)(Class, SEL))objc_msgSend) ((Class)(x), (SEL)y)
-
7029#define objc_msgSend_class_char(x, y, z) ((id (*)(Class, SEL, char*))objc_msgSend) ((Class)(x), (SEL)y, (char*)z)
-
7030
-
7031id NSApp = NULL;
-
7032
-
7033#define NSRelease(obj) objc_msgSend_void((id)obj, sel_registerName("release"))
-
7034
-
7035id NSString_stringWithUTF8String(const char* str) {
-
7036 return ((id(*)(id, SEL, const char*))objc_msgSend)
-
7037 ((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), str);
-
7038}
-
7039
-
7040const char* NSString_to_char(id str) {
-
7041 return ((const char* (*)(id, SEL)) objc_msgSend) ((id)(id)str, sel_registerName("UTF8String"));
-
7042}
+
6967void RGFW_sleep(u64 ms) {
+
6968 Sleep(ms);
+
6969}
+
6970
+
6971#ifndef RGFW_NO_THREADS
+
6972
+
6973RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args) { return CreateThread(NULL, 0, ptr, args, 0, NULL); }
+
6974void RGFW_cancelThread(RGFW_thread thread) { CloseHandle((HANDLE) thread); }
+
6975void RGFW_joinThread(RGFW_thread thread) { WaitForSingleObject((HANDLE) thread, INFINITE); }
+
6976void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { SetThreadPriority((HANDLE) thread, priority); }
+
6977
+
6978#endif
+
6979#endif /* RGFW_WINDOWS */
+
6980
+
6981/*
+
6982 End of Windows defines
+
6983*/
+
6984
+
6985
+
6986
+
6987/*
+
6988
+
6989 Start of MacOS defines
+
6990
+
6991
+
6992*/
+
6993
+
6994#if defined(RGFW_MACOS)
+
6995/*
+
6996 based on silicon.h
+
6997 start of cocoa wrapper
+
6998*/
+
6999
+
7000#include <CoreGraphics/CoreGraphics.h>
+
7001#include <ApplicationServices/ApplicationServices.h>
+
7002#include <objc/runtime.h>
+
7003#include <objc/message.h>
+
7004#include <mach/mach_time.h>
+
7005
+
7006typedef CGRect NSRect;
+
7007typedef CGPoint NSPoint;
+
7008typedef CGSize NSSize;
+
7009
+
7010typedef const char* NSPasteboardType;
+
7011typedef unsigned long NSUInteger;
+
7012typedef long NSInteger;
+
7013typedef NSInteger NSModalResponse;
+
7014
+
7015#ifdef __arm64__
+
7016 /* ARM just uses objc_msgSend */
+
7017#define abi_objc_msgSend_stret objc_msgSend
+
7018#define abi_objc_msgSend_fpret objc_msgSend
+
7019#else /* __i386__ */
+
7020 /* x86 just uses abi_objc_msgSend_fpret and (NSColor *)objc_msgSend_id respectively */
+
7021#define abi_objc_msgSend_stret objc_msgSend_stret
+
7022#define abi_objc_msgSend_fpret objc_msgSend_fpret
+
7023#endif
+
7024
+
7025#define NSAlloc(nsclass) objc_msgSend_id((id)nsclass, sel_registerName("alloc"))
+
7026#define objc_msgSend_bool(x, y) ((BOOL (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
+
7027#define objc_msgSend_void(x, y) ((void (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
+
7028#define objc_msgSend_void_id(x, y, z) ((void (*)(id, SEL, id))objc_msgSend) ((id)x, (SEL)y, (id)z)
+
7029#define objc_msgSend_uint(x, y) ((NSUInteger (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
+
7030#define objc_msgSend_void_bool(x, y, z) ((void (*)(id, SEL, BOOL))objc_msgSend) ((id)(x), (SEL)y, (BOOL)z)
+
7031#define objc_msgSend_bool_void(x, y) ((BOOL (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
+
7032#define objc_msgSend_void_SEL(x, y, z) ((void (*)(id, SEL, SEL))objc_msgSend) ((id)(x), (SEL)y, (SEL)z)
+
7033#define objc_msgSend_id(x, y) ((id (*)(id, SEL))objc_msgSend) ((id)(x), (SEL)y)
+
7034#define objc_msgSend_id_id(x, y, z) ((id (*)(id, SEL, id))objc_msgSend) ((id)(x), (SEL)y, (id)z)
+
7035#define objc_msgSend_id_bool(x, y, z) ((BOOL (*)(id, SEL, id))objc_msgSend) ((id)(x), (SEL)y, (id)z)
+
7036#define objc_msgSend_int(x, y, z) ((id (*)(id, SEL, int))objc_msgSend) ((id)(x), (SEL)y, (int)z)
+
7037#define objc_msgSend_arr(x, y, z) ((id (*)(id, SEL, int))objc_msgSend) ((id)(x), (SEL)y, (int)z)
+
7038#define objc_msgSend_ptr(x, y, z) ((id (*)(id, SEL, void*))objc_msgSend) ((id)(x), (SEL)y, (void*)z)
+
7039#define objc_msgSend_class(x, y) ((id (*)(Class, SEL))objc_msgSend) ((Class)(x), (SEL)y)
+
7040#define objc_msgSend_class_char(x, y, z) ((id (*)(Class, SEL, char*))objc_msgSend) ((Class)(x), (SEL)y, (char*)z)
+
7041
+
7042id NSApp = NULL;
7043
-
7044void si_impl_func_to_SEL_with_name(const char* class_name, const char* register_name, void* function) {
-
7045 Class selected_class;
-
7046
-
7047 if (RGFW_STRNCMP(class_name, "NSView", 6) == 0) {
-
7048 selected_class = objc_getClass("ViewClass");
-
7049 } else if (RGFW_STRNCMP(class_name, "NSWindow", 8) == 0) {
-
7050 selected_class = objc_getClass("WindowClass");
-
7051 } else {
-
7052 selected_class = objc_getClass(class_name);
-
7053 }
+
7044#define NSRelease(obj) objc_msgSend_void((id)obj, sel_registerName("release"))
+
7045
+
7046id NSString_stringWithUTF8String(const char* str) {
+
7047 return ((id(*)(id, SEL, const char*))objc_msgSend)
+
7048 ((id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), str);
+
7049}
+
7050
+
7051const char* NSString_to_char(id str) {
+
7052 return ((const char* (*)(id, SEL)) objc_msgSend) ((id)(id)str, sel_registerName("UTF8String"));
+
7053}
7054
-
7055 class_addMethod(selected_class, sel_registerName(register_name), (IMP) function, 0);
-
7056}
+
7055void si_impl_func_to_SEL_with_name(const char* class_name, const char* register_name, void* function) {
+
7056 Class selected_class;
7057
-
7058/* Header for the array. */
-
7059typedef struct siArrayHeader {
-
7060 size_t count;
-
7061 /* TODO(EimaMei): Add a `type_width` later on. */
-
7062} siArrayHeader;
-
7063
-
7064/* Gets the header of the siArray. */
-
7065#define SI_ARRAY_HEADER(s) ((siArrayHeader*)s - 1)
-
7066#define si_array_len(array) (SI_ARRAY_HEADER(array)->count)
-
7067#define si_func_to_SEL(class_name, function) si_impl_func_to_SEL_with_name(class_name, #function":", (void*)function)
-
7068/* Creates an Objective-C method (SEL) from a regular C function with the option to set the register name.*/
-
7069#define si_func_to_SEL_with_name(class_name, register_name, function) si_impl_func_to_SEL_with_name(class_name, register_name":", (void*)function)
-
7070
-
7071unsigned char* NSBitmapImageRep_bitmapData(id imageRep) {
-
7072 return ((unsigned char* (*)(id, SEL))objc_msgSend) ((id)imageRep, sel_registerName("bitmapData"));
-
7073}
+
7058 if (RGFW_STRNCMP(class_name, "NSView", 6) == 0) {
+
7059 selected_class = objc_getClass("ViewClass");
+
7060 } else if (RGFW_STRNCMP(class_name, "NSWindow", 8) == 0) {
+
7061 selected_class = objc_getClass("WindowClass");
+
7062 } else {
+
7063 selected_class = objc_getClass(class_name);
+
7064 }
+
7065
+
7066 class_addMethod(selected_class, sel_registerName(register_name), (IMP) function, 0);
+
7067}
+
7068
+
7069/* Header for the array. */
+
7070typedef struct siArrayHeader {
+
7071 size_t count;
+
7072 /* TODO(EimaMei): Add a `type_width` later on. */
+
7073} siArrayHeader;
7074
-
7075typedef RGFW_ENUM(NSUInteger, NSBitmapFormat) {
-
7076 NSBitmapFormatAlphaFirst = 1 << 0, // 0 means is alpha last (RGBA, CMYKA, etc.)
-
7077 NSBitmapFormatAlphaNonpremultiplied = 1 << 1, // 0 means is premultiplied
-
7078 NSBitmapFormatFloatingpointSamples = 1 << 2, // 0 is integer
-
7079
-
7080 NSBitmapFormatSixteenBitLittleEndian API_AVAILABLE(macos(10.10)) = (1 << 8),
-
7081 NSBitmapFormatThirtyTwoBitLittleEndian API_AVAILABLE(macos(10.10)) = (1 << 9),
-
7082 NSBitmapFormatSixteenBitBigEndian API_AVAILABLE(macos(10.10)) = (1 << 10),
-
7083 NSBitmapFormatThirtyTwoBitBigEndian API_AVAILABLE(macos(10.10)) = (1 << 11)
-
7084};
+
7075/* Gets the header of the siArray. */
+
7076#define SI_ARRAY_HEADER(s) ((siArrayHeader*)s - 1)
+
7077#define si_array_len(array) (SI_ARRAY_HEADER(array)->count)
+
7078#define si_func_to_SEL(class_name, function) si_impl_func_to_SEL_with_name(class_name, #function":", (void*)function)
+
7079/* Creates an Objective-C method (SEL) from a regular C function with the option to set the register name.*/
+
7080#define si_func_to_SEL_with_name(class_name, register_name, function) si_impl_func_to_SEL_with_name(class_name, register_name":", (void*)function)
+
7081
+
7082unsigned char* NSBitmapImageRep_bitmapData(id imageRep) {
+
7083 return ((unsigned char* (*)(id, SEL))objc_msgSend) ((id)imageRep, sel_registerName("bitmapData"));
+
7084}
7085
-
7086id NSBitmapImageRep_initWithBitmapData(unsigned char** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, const char* colorSpaceName, NSBitmapFormat bitmapFormat, NSInteger rowBytes, NSInteger pixelBits) {
-
7087 SEL func = sel_registerName("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:");
-
7088
-
7089 return (id) ((id(*)(id, SEL, unsigned char**, NSInteger, NSInteger, NSInteger, NSInteger, bool, bool, id, NSBitmapFormat, NSInteger, NSInteger))objc_msgSend)
-
7090 (NSAlloc((id)objc_getClass("NSBitmapImageRep")), func, planes, width, height, bps, spp, alpha, isPlanar, NSString_stringWithUTF8String(colorSpaceName), bitmapFormat, rowBytes, pixelBits);
-
7091}
-
7092
-
7093id NSColor_colorWithSRGB(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) {
-
7094 void* nsclass = objc_getClass("NSColor");
-
7095 SEL func = sel_registerName("colorWithSRGBRed:green:blue:alpha:");
-
7096 return ((id(*)(id, SEL, CGFloat, CGFloat, CGFloat, CGFloat))objc_msgSend)
-
7097 ((id)nsclass, func, red, green, blue, alpha);
-
7098}
+
7086typedef RGFW_ENUM(NSUInteger, NSBitmapFormat) {
+
7087 NSBitmapFormatAlphaFirst = 1 << 0, // 0 means is alpha last (RGBA, CMYKA, etc.)
+
7088 NSBitmapFormatAlphaNonpremultiplied = 1 << 1, // 0 means is premultiplied
+
7089 NSBitmapFormatFloatingpointSamples = 1 << 2, // 0 is integer
+
7090
+
7091 NSBitmapFormatSixteenBitLittleEndian API_AVAILABLE(macos(10.10)) = (1 << 8),
+
7092 NSBitmapFormatThirtyTwoBitLittleEndian API_AVAILABLE(macos(10.10)) = (1 << 9),
+
7093 NSBitmapFormatSixteenBitBigEndian API_AVAILABLE(macos(10.10)) = (1 << 10),
+
7094 NSBitmapFormatThirtyTwoBitBigEndian API_AVAILABLE(macos(10.10)) = (1 << 11)
+
7095};
+
7096
+
7097id NSBitmapImageRep_initWithBitmapData(unsigned char** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, const char* colorSpaceName, NSBitmapFormat bitmapFormat, NSInteger rowBytes, NSInteger pixelBits) {
+
7098 SEL func = sel_registerName("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:");
7099
-
7100id NSCursor_initWithImage(id newImage, NSPoint aPoint) {
-
7101 SEL func = sel_registerName("initWithImage:hotSpot:");
-
7102 void* nsclass = objc_getClass("NSCursor");
+
7100 return (id) ((id(*)(id, SEL, unsigned char**, NSInteger, NSInteger, NSInteger, NSInteger, bool, bool, id, NSBitmapFormat, NSInteger, NSInteger))objc_msgSend)
+
7101 (NSAlloc((id)objc_getClass("NSBitmapImageRep")), func, planes, width, height, bps, spp, alpha, isPlanar, NSString_stringWithUTF8String(colorSpaceName), bitmapFormat, rowBytes, pixelBits);
+
7102}
7103
-
7104 return (id) ((id(*)(id, SEL, id, NSPoint))objc_msgSend)
-
7105 (NSAlloc(nsclass), func, newImage, aPoint);
-
7106}
-
7107
-
7108void NSImage_addRepresentation(id image, id imageRep) {
-
7109 SEL func = sel_registerName("addRepresentation:");
-
7110 objc_msgSend_void_id(image, func, (id)imageRep);
-
7111}
-
7112
-
7113id NSImage_initWithSize(NSSize size) {
-
7114 SEL func = sel_registerName("initWithSize:");
-
7115 return ((id(*)(id, SEL, NSSize))objc_msgSend)
-
7116 (NSAlloc((id)objc_getClass("NSImage")), func, size);
+
7104id NSColor_colorWithSRGB(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) {
+
7105 void* nsclass = objc_getClass("NSColor");
+
7106 SEL func = sel_registerName("colorWithSRGBRed:green:blue:alpha:");
+
7107 return ((id(*)(id, SEL, CGFloat, CGFloat, CGFloat, CGFloat))objc_msgSend)
+
7108 ((id)nsclass, func, red, green, blue, alpha);
+
7109}
+
7110
+
7111id NSCursor_initWithImage(id newImage, NSPoint aPoint) {
+
7112 SEL func = sel_registerName("initWithImage:hotSpot:");
+
7113 void* nsclass = objc_getClass("NSCursor");
+
7114
+
7115 return (id) ((id(*)(id, SEL, id, NSPoint))objc_msgSend)
+
7116 (NSAlloc(nsclass), func, newImage, aPoint);
7117}
-
7118#define NS_OPENGL_ENUM_DEPRECATED(minVers, maxVers) API_AVAILABLE(macos(minVers))
-
7119typedef RGFW_ENUM(NSInteger, NSOpenGLContextParameter) {
-
7120 NSOpenGLContextParameterSwapInterval NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 222, /* 1 param. 0 -> Don't sync, 1 -> Sync to vertical retrace */
-
7121 NSOpenGLContextParametectxaceOrder NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 235, /* 1 param. 1 -> Above Window (default), -1 -> Below Window */
-
7122 NSOpenGLContextParametectxaceOpacity NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 236, /* 1 param. 1-> Surface is opaque (default), 0 -> non-opaque */
-
7123 NSOpenGLContextParametectxaceBackingSize NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 304, /* 2 params. Width/height of surface backing size */
-
7124 NSOpenGLContextParameterReclaimResources NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 308, /* 0 params. */
-
7125 NSOpenGLContextParameterCurrentRendererID NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 309, /* 1 param. Retrieves the current renderer ID */
-
7126 NSOpenGLContextParameterGPUVertexProcessing NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 310, /* 1 param. Currently processing vertices with GPU (get) */
-
7127 NSOpenGLContextParameterGPUFragmentProcessing NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 311, /* 1 param. Currently processing fragments with GPU (get) */
-
7128 NSOpenGLContextParameterHasDrawable NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 314, /* 1 param. Boolean returned if drawable is attached */
-
7129 NSOpenGLContextParameterMPSwapsInFlight NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 315, /* 1 param. Max number of swaps queued by the MP GL engine */
-
7130
-
7131 NSOpenGLContextParameterSwapRectangle API_DEPRECATED("", macos(10.0, 10.14)) = 200, /* 4 params. Set or get the swap rectangle {x, y, w, h} */
-
7132 NSOpenGLContextParameterSwapRectangleEnable API_DEPRECATED("", macos(10.0, 10.14)) = 201, /* Enable or disable the swap rectangle */
-
7133 NSOpenGLContextParameterRasterizationEnable API_DEPRECATED("", macos(10.0, 10.14)) = 221, /* Enable or disable all rasterization */
-
7134 NSOpenGLContextParameterStateValidation API_DEPRECATED("", macos(10.0, 10.14)) = 301, /* Validate state for multi-screen functionality */
-
7135 NSOpenGLContextParametectxaceSurfaceVolatile API_DEPRECATED("", macos(10.0, 10.14)) = 306, /* 1 param. Surface volatile state */
-
7136};
-
7137
-
7138
-
7139void NSOpenGLContext_setValues(id context, const int* vals, NSOpenGLContextParameter param) {
-
7140 SEL func = sel_registerName("setValues:forParameter:");
-
7141 ((void (*)(id, SEL, const int*, NSOpenGLContextParameter))objc_msgSend)
-
7142 (context, func, vals, param);
-
7143}
-
7144
-
7145void* NSOpenGLPixelFormat_initWithAttributes(const uint32_t* attribs) {
-
7146 SEL func = sel_registerName("initWithAttributes:");
-
7147 return (void*) ((id(*)(id, SEL, const uint32_t*))objc_msgSend)
-
7148 (NSAlloc((id)objc_getClass("NSOpenGLPixelFormat")), func, attribs);
-
7149}
-
7150
-
7151id NSOpenGLView_initWithFrame(NSRect frameRect, uint32_t* format) {
-
7152 SEL func = sel_registerName("initWithFrame:pixelFormat:");
-
7153 return (id) ((id(*)(id, SEL, NSRect, uint32_t*))objc_msgSend)
-
7154 (NSAlloc((id)objc_getClass("NSOpenGLView")), func, frameRect, format);
-
7155}
-
7156
-
7157void NSCursor_performSelector(id cursor, SEL selector) {
-
7158 SEL func = sel_registerName("performSelector:");
-
7159 objc_msgSend_void_SEL(cursor, func, selector);
+
7118
+
7119void NSImage_addRepresentation(id image, id imageRep) {
+
7120 SEL func = sel_registerName("addRepresentation:");
+
7121 objc_msgSend_void_id(image, func, (id)imageRep);
+
7122}
+
7123
+
7124id NSImage_initWithSize(NSSize size) {
+
7125 SEL func = sel_registerName("initWithSize:");
+
7126 return ((id(*)(id, SEL, NSSize))objc_msgSend)
+
7127 (NSAlloc((id)objc_getClass("NSImage")), func, size);
+
7128}
+
7129#define NS_OPENGL_ENUM_DEPRECATED(minVers, maxVers) API_AVAILABLE(macos(minVers))
+
7130typedef RGFW_ENUM(NSInteger, NSOpenGLContextParameter) {
+
7131 NSOpenGLContextParameterSwapInterval NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 222, /* 1 param. 0 -> Don't sync, 1 -> Sync to vertical retrace */
+
7132 NSOpenGLContextParametectxaceOrder NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 235, /* 1 param. 1 -> Above Window (default), -1 -> Below Window */
+
7133 NSOpenGLContextParametectxaceOpacity NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 236, /* 1 param. 1-> Surface is opaque (default), 0 -> non-opaque */
+
7134 NSOpenGLContextParametectxaceBackingSize NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 304, /* 2 params. Width/height of surface backing size */
+
7135 NSOpenGLContextParameterReclaimResources NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 308, /* 0 params. */
+
7136 NSOpenGLContextParameterCurrentRendererID NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 309, /* 1 param. Retrieves the current renderer ID */
+
7137 NSOpenGLContextParameterGPUVertexProcessing NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 310, /* 1 param. Currently processing vertices with GPU (get) */
+
7138 NSOpenGLContextParameterGPUFragmentProcessing NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 311, /* 1 param. Currently processing fragments with GPU (get) */
+
7139 NSOpenGLContextParameterHasDrawable NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 314, /* 1 param. Boolean returned if drawable is attached */
+
7140 NSOpenGLContextParameterMPSwapsInFlight NS_OPENGL_ENUM_DEPRECATED(10.0, 10.14) = 315, /* 1 param. Max number of swaps queued by the MP GL engine */
+
7141
+
7142 NSOpenGLContextParameterSwapRectangle API_DEPRECATED("", macos(10.0, 10.14)) = 200, /* 4 params. Set or get the swap rectangle {x, y, w, h} */
+
7143 NSOpenGLContextParameterSwapRectangleEnable API_DEPRECATED("", macos(10.0, 10.14)) = 201, /* Enable or disable the swap rectangle */
+
7144 NSOpenGLContextParameterRasterizationEnable API_DEPRECATED("", macos(10.0, 10.14)) = 221, /* Enable or disable all rasterization */
+
7145 NSOpenGLContextParameterStateValidation API_DEPRECATED("", macos(10.0, 10.14)) = 301, /* Validate state for multi-screen functionality */
+
7146 NSOpenGLContextParametectxaceSurfaceVolatile API_DEPRECATED("", macos(10.0, 10.14)) = 306, /* 1 param. Surface volatile state */
+
7147};
+
7148
+
7149
+
7150void NSOpenGLContext_setValues(id context, const int* vals, NSOpenGLContextParameter param) {
+
7151 SEL func = sel_registerName("setValues:forParameter:");
+
7152 ((void (*)(id, SEL, const int*, NSOpenGLContextParameter))objc_msgSend)
+
7153 (context, func, vals, param);
+
7154}
+
7155
+
7156void* NSOpenGLPixelFormat_initWithAttributes(const uint32_t* attribs) {
+
7157 SEL func = sel_registerName("initWithAttributes:");
+
7158 return (void*) ((id(*)(id, SEL, const uint32_t*))objc_msgSend)
+
7159 (NSAlloc((id)objc_getClass("NSOpenGLPixelFormat")), func, attribs);
7160}
7161
-
7162id NSPasteboard_generalPasteboard(void) {
-
7163 return (id) objc_msgSend_id((id)objc_getClass("NSPasteboard"), sel_registerName("generalPasteboard"));
-
7164}
-
7165
-
7166id* cstrToNSStringArray(char** strs, size_t len) {
-
7167 static id nstrs[6];
-
7168 size_t i;
-
7169 for (i = 0; i < len; i++)
-
7170 nstrs[i] = NSString_stringWithUTF8String(strs[i]);
-
7171
-
7172 return nstrs;
-
7173}
-
7174
-
7175const char* NSPasteboard_stringForType(id pasteboard, NSPasteboardType dataType, size_t* len) {
-
7176 SEL func = sel_registerName("stringForType:");
-
7177 id nsstr = NSString_stringWithUTF8String(dataType);
-
7178 id nsString = ((id(*)(id, SEL, id))objc_msgSend)(pasteboard, func, nsstr);
-
7179 const char* str = NSString_to_char(nsString);
-
7180 if (len != NULL)
-
7181 *len = (size_t)((NSUInteger(*)(id, SEL, int))objc_msgSend)(nsString, sel_registerName("maximumLengthOfBytesUsingEncoding:"), 4);
-
7182 return str;
-
7183}
-
7184
-
7185id c_array_to_NSArray(void* array, size_t len) {
-
7186 SEL func = sel_registerName("initWithObjects:count:");
-
7187 void* nsclass = objc_getClass("NSArray");
-
7188 return ((id (*)(id, SEL, void*, NSUInteger))objc_msgSend)
-
7189 (NSAlloc(nsclass), func, array, len);
-
7190}
-
7191
-
7192void NSregisterForDraggedTypes(id view, NSPasteboardType* newTypes, size_t len) {
-
7193 id* ntypes = cstrToNSStringArray((char**)newTypes, len);
-
7194
-
7195 id array = c_array_to_NSArray(ntypes, len);
-
7196 objc_msgSend_void_id(view, sel_registerName("registerForDraggedTypes:"), array);
-
7197 NSRelease(array);
-
7198}
-
7199
-
7200NSInteger NSPasteBoard_declareTypes(id pasteboard, NSPasteboardType* newTypes, size_t len, void* owner) {
-
7201 id* ntypes = cstrToNSStringArray((char**)newTypes, len);
+
7162id NSOpenGLView_initWithFrame(NSRect frameRect, uint32_t* format) {
+
7163 SEL func = sel_registerName("initWithFrame:pixelFormat:");
+
7164 return (id) ((id(*)(id, SEL, NSRect, uint32_t*))objc_msgSend)
+
7165 (NSAlloc((id)objc_getClass("NSOpenGLView")), func, frameRect, format);
+
7166}
+
7167
+
7168void NSCursor_performSelector(id cursor, SEL selector) {
+
7169 SEL func = sel_registerName("performSelector:");
+
7170 objc_msgSend_void_SEL(cursor, func, selector);
+
7171}
+
7172
+
7173id NSPasteboard_generalPasteboard(void) {
+
7174 return (id) objc_msgSend_id((id)objc_getClass("NSPasteboard"), sel_registerName("generalPasteboard"));
+
7175}
+
7176
+
7177id* cstrToNSStringArray(char** strs, size_t len) {
+
7178 static id nstrs[6];
+
7179 size_t i;
+
7180 for (i = 0; i < len; i++)
+
7181 nstrs[i] = NSString_stringWithUTF8String(strs[i]);
+
7182
+
7183 return nstrs;
+
7184}
+
7185
+
7186const char* NSPasteboard_stringForType(id pasteboard, NSPasteboardType dataType, size_t* len) {
+
7187 SEL func = sel_registerName("stringForType:");
+
7188 id nsstr = NSString_stringWithUTF8String(dataType);
+
7189 id nsString = ((id(*)(id, SEL, id))objc_msgSend)(pasteboard, func, nsstr);
+
7190 const char* str = NSString_to_char(nsString);
+
7191 if (len != NULL)
+
7192 *len = (size_t)((NSUInteger(*)(id, SEL, int))objc_msgSend)(nsString, sel_registerName("maximumLengthOfBytesUsingEncoding:"), 4);
+
7193 return str;
+
7194}
+
7195
+
7196id c_array_to_NSArray(void* array, size_t len) {
+
7197 SEL func = sel_registerName("initWithObjects:count:");
+
7198 void* nsclass = objc_getClass("NSArray");
+
7199 return ((id (*)(id, SEL, void*, NSUInteger))objc_msgSend)
+
7200 (NSAlloc(nsclass), func, array, len);
+
7201}
7202
-
7203 SEL func = sel_registerName("declareTypes:owner:");
-
7204
-
7205 id array = c_array_to_NSArray(ntypes, len);
-
7206
-
7207 NSInteger output = ((NSInteger(*)(id, SEL, id, void*))objc_msgSend)
-
7208 (pasteboard, func, array, owner);
-
7209 NSRelease(array);
+
7203void NSregisterForDraggedTypes(id view, NSPasteboardType* newTypes, size_t len) {
+
7204 id* ntypes = cstrToNSStringArray((char**)newTypes, len);
+
7205
+
7206 id array = c_array_to_NSArray(ntypes, len);
+
7207 objc_msgSend_void_id(view, sel_registerName("registerForDraggedTypes:"), array);
+
7208 NSRelease(array);
+
7209}
7210
-
7211 return output;
-
7212}
+
7211NSInteger NSPasteBoard_declareTypes(id pasteboard, NSPasteboardType* newTypes, size_t len, void* owner) {
+
7212 id* ntypes = cstrToNSStringArray((char**)newTypes, len);
7213
-
7214bool NSPasteBoard_setString(id pasteboard, const char* stringToWrite, NSPasteboardType dataType) {
-
7215 SEL func = sel_registerName("setString:forType:");
-
7216 return ((bool (*)(id, SEL, id, id))objc_msgSend)
-
7217 (pasteboard, func, NSString_stringWithUTF8String(stringToWrite), NSString_stringWithUTF8String(dataType));
-
7218}
-
7219
-
7220#define NSRetain(obj) objc_msgSend_void((id)obj, sel_registerName("retain"))
+
7214 SEL func = sel_registerName("declareTypes:owner:");
+
7215
+
7216 id array = c_array_to_NSArray(ntypes, len);
+
7217
+
7218 NSInteger output = ((NSInteger(*)(id, SEL, id, void*))objc_msgSend)
+
7219 (pasteboard, func, array, owner);
+
7220 NSRelease(array);
7221
-
7222typedef enum NSApplicationActivationPolicy {
-
7223 NSApplicationActivationPolicyRegular,
-
7224 NSApplicationActivationPolicyAccessory,
-
7225 NSApplicationActivationPolicyProhibited
-
7226} NSApplicationActivationPolicy;
-
7227
-
7228typedef RGFW_ENUM(u32, NSBackingStoreType) {
-
7229 NSBackingStoreRetained = 0,
-
7230 NSBackingStoreNonretained = 1,
-
7231 NSBackingStoreBuffered = 2
-
7232};
-
7233
-
7234typedef RGFW_ENUM(u32, NSWindowStyleMask) {
-
7235 NSWindowStyleMaskBorderless = 0,
-
7236 NSWindowStyleMaskTitled = 1 << 0,
-
7237 NSWindowStyleMaskClosable = 1 << 1,
-
7238 NSWindowStyleMaskMiniaturizable = 1 << 2,
-
7239 NSWindowStyleMaskResizable = 1 << 3,
-
7240 NSWindowStyleMaskTexturedBackground = 1 << 8, /* deprecated */
-
7241 NSWindowStyleMaskUnifiedTitleAndToolbar = 1 << 12,
-
7242 NSWindowStyleMaskFullScreen = 1 << 14,
-
7243 NSWindowStyleMaskFullSizeContentView = 1 << 15,
-
7244 NSWindowStyleMaskUtilityWindow = 1 << 4,
-
7245 NSWindowStyleMaskDocModalWindow = 1 << 6,
-
7246 NSWindowStyleMaskNonactivatingpanel = 1 << 7,
-
7247 NSWindowStyleMaskHUDWindow = 1 << 13
-
7248};
-
7249
-
7250NSPasteboardType const NSPasteboardTypeString = "public.utf8-plain-text"; // Replaces NSStringPasteboardType
-
7251
-
7252
-
7253typedef RGFW_ENUM(i32, NSDragOperation) {
-
7254 NSDragOperationNone = 0,
-
7255 NSDragOperationCopy = 1,
-
7256 NSDragOperationLink = 2,
-
7257 NSDragOperationGeneric = 4,
-
7258 NSDragOperationPrivate = 8,
-
7259 NSDragOperationMove = 16,
-
7260 NSDragOperationDelete = 32,
-
7261 NSDragOperationEvery = ULONG_MAX,
+
7222 return output;
+
7223}
+
7224
+
7225bool NSPasteBoard_setString(id pasteboard, const char* stringToWrite, NSPasteboardType dataType) {
+
7226 SEL func = sel_registerName("setString:forType:");
+
7227 return ((bool (*)(id, SEL, id, id))objc_msgSend)
+
7228 (pasteboard, func, NSString_stringWithUTF8String(stringToWrite), NSString_stringWithUTF8String(dataType));
+
7229}
+
7230
+
7231#define NSRetain(obj) objc_msgSend_void((id)obj, sel_registerName("retain"))
+
7232
+
7233typedef enum NSApplicationActivationPolicy {
+
7234 NSApplicationActivationPolicyRegular,
+
7235 NSApplicationActivationPolicyAccessory,
+
7236 NSApplicationActivationPolicyProhibited
+
7237} NSApplicationActivationPolicy;
+
7238
+
7239typedef RGFW_ENUM(u32, NSBackingStoreType) {
+
7240 NSBackingStoreRetained = 0,
+
7241 NSBackingStoreNonretained = 1,
+
7242 NSBackingStoreBuffered = 2
+
7243};
+
7244
+
7245typedef RGFW_ENUM(u32, NSWindowStyleMask) {
+
7246 NSWindowStyleMaskBorderless = 0,
+
7247 NSWindowStyleMaskTitled = 1 << 0,
+
7248 NSWindowStyleMaskClosable = 1 << 1,
+
7249 NSWindowStyleMaskMiniaturizable = 1 << 2,
+
7250 NSWindowStyleMaskResizable = 1 << 3,
+
7251 NSWindowStyleMaskTexturedBackground = 1 << 8, /* deprecated */
+
7252 NSWindowStyleMaskUnifiedTitleAndToolbar = 1 << 12,
+
7253 NSWindowStyleMaskFullScreen = 1 << 14,
+
7254 NSWindowStyleMaskFullSizeContentView = 1 << 15,
+
7255 NSWindowStyleMaskUtilityWindow = 1 << 4,
+
7256 NSWindowStyleMaskDocModalWindow = 1 << 6,
+
7257 NSWindowStyleMaskNonactivatingpanel = 1 << 7,
+
7258 NSWindowStyleMaskHUDWindow = 1 << 13
+
7259};
+
7260
+
7261NSPasteboardType const NSPasteboardTypeString = "public.utf8-plain-text"; // Replaces NSStringPasteboardType
7262
-
7263 //NSDragOperationAll_Obsolete API_DEPRECATED("", macos(10.0,10.10)) = 15, // Use NSDragOperationEvery
-
7264 //NSDragOperationAll API_DEPRECATED("", macos(10.0,10.10)) = NSDragOperationAll_Obsolete, // Use NSDragOperationEvery
-
7265};
-
7266
-
7267void* NSArray_objectAtIndex(id array, NSUInteger index) {
-
7268 SEL func = sel_registerName("objectAtIndex:");
-
7269 return ((id(*)(id, SEL, NSUInteger))objc_msgSend)(array, func, index);
-
7270}
-
7271
-
7272id NSWindow_contentView(id window) {
-
7273 SEL func = sel_registerName("contentView");
-
7274 return objc_msgSend_id(window, func);
-
7275}
-
7276
-
7277/*
-
7278 End of cocoa wrapper
-
7279*/
-
7280
-
7281const char* RGFW_mouseIconSrc[] = {"arrowCursor", "arrowCursor", "IBeamCursor", "crosshairCursor", "pointingHandCursor", "resizeLeftRightCursor", "resizeUpDownCursor", "_windowResizeNorthWestSouthEastCursor", "_windowResizeNorthEastSouthWestCursor", "closedHandCursor", "operationNotAllowedCursor"};
+
7263
+
7264typedef RGFW_ENUM(i32, NSDragOperation) {
+
7265 NSDragOperationNone = 0,
+
7266 NSDragOperationCopy = 1,
+
7267 NSDragOperationLink = 2,
+
7268 NSDragOperationGeneric = 4,
+
7269 NSDragOperationPrivate = 8,
+
7270 NSDragOperationMove = 16,
+
7271 NSDragOperationDelete = 32,
+
7272 NSDragOperationEvery = ULONG_MAX,
+
7273
+
7274 //NSDragOperationAll_Obsolete API_DEPRECATED("", macos(10.0,10.10)) = 15, // Use NSDragOperationEvery
+
7275 //NSDragOperationAll API_DEPRECATED("", macos(10.0,10.10)) = NSDragOperationAll_Obsolete, // Use NSDragOperationEvery
+
7276};
+
7277
+
7278void* NSArray_objectAtIndex(id array, NSUInteger index) {
+
7279 SEL func = sel_registerName("objectAtIndex:");
+
7280 return ((id(*)(id, SEL, NSUInteger))objc_msgSend)(array, func, index);
+
7281}
7282
-
7283#ifdef RGFW_OPENGL
-
7284CFBundleRef RGFWnsglFramework = NULL;
-
7285
-
7286void* RGFW_getProcAddress(const char* procname) {
-
7287 if (RGFWnsglFramework == NULL)
-
7288 RGFWnsglFramework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
-
7289
-
7290 CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, procname, kCFStringEncodingASCII);
+
7283id NSWindow_contentView(id window) {
+
7284 SEL func = sel_registerName("contentView");
+
7285 return objc_msgSend_id(window, func);
+
7286}
+
7287
+
7288/*
+
7289 End of cocoa wrapper
+
7290*/
7291
-
7292 void* symbol = (void*)CFBundleGetFunctionPointerForName(RGFWnsglFramework, symbolName);
+
7292const char* RGFW_mouseIconSrc[] = {"arrowCursor", "arrowCursor", "IBeamCursor", "crosshairCursor", "pointingHandCursor", "resizeLeftRightCursor", "resizeUpDownCursor", "_windowResizeNorthWestSouthEastCursor", "_windowResizeNorthEastSouthWestCursor", "closedHandCursor", "operationNotAllowedCursor"};
7293
-
7294 CFRelease(symbolName);
-
7295
-
7296 return symbol;
-
7297}
-
7298#endif
-
7299
-
7300id NSWindow_delegate(RGFW_window* win) {
-
7301 return (id) objc_msgSend_id((id)win->src.window, sel_registerName("delegate"));
-
7302}
-
7303
-
7304u32 RGFW_OnClose(id self) {
-
7305 RGFW_window* win = NULL;
-
7306 object_getInstanceVariable(self, (const char*)"RGFW_window", (void**)&win);
-
7307 if (win == NULL)
-
7308 return true;
-
7309
-
7310 win->event.type = RGFW_quit;
-
7311 RGFW_windowQuitCallback(win);
-
7312
-
7313 return true;
-
7314}
-
7315
-
7316/* NOTE(EimaMei): Fixes the constant clicking when the app is running under a terminal. */
-
7317bool acceptsFirstResponder(void) { return true; }
-
7318bool performKeyEquivalent(id event) { RGFW_UNUSED(event); return true; }
-
7319
-
7320NSDragOperation draggingEntered(id self, SEL sel, id sender) {
-
7321 RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel);
-
7322
-
7323 return NSDragOperationCopy;
-
7324}
-
7325NSDragOperation draggingUpdated(id self, SEL sel, id sender) {
-
7326 RGFW_UNUSED(sel);
-
7327
-
7328 RGFW_window* win = NULL;
-
7329 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7330 if (win == NULL)
-
7331 return 0;
-
7332
-
7333 if (!(win->_flags & RGFW_windowAllowDND)) {
-
7334 return 0;
-
7335 }
-
7336
-
7337 win->event.type = RGFW_DNDInit;
-
7338 win->src.dndPassed = 0;
-
7339
-
7340 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(sender, sel_registerName("draggingLocation"));
-
7341
-
7342 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
-
7343 RGFW_dndInitCallback(win, win->event.point);
-
7344
-
7345 return NSDragOperationCopy;
-
7346}
-
7347bool prepareForDragOperation(id self) {
-
7348 RGFW_window* win = NULL;
-
7349 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7350 if (win == NULL)
-
7351 return true;
+
7294#ifdef RGFW_OPENGL
+
7295CFBundleRef RGFWnsglFramework = NULL;
+
7296
+
7297void* RGFW_getProcAddress(const char* procname) {
+
7298 if (RGFWnsglFramework == NULL)
+
7299 RGFWnsglFramework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+
7300
+
7301 CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, procname, kCFStringEncodingASCII);
+
7302
+
7303 void* symbol = (void*)CFBundleGetFunctionPointerForName(RGFWnsglFramework, symbolName);
+
7304
+
7305 CFRelease(symbolName);
+
7306
+
7307 return symbol;
+
7308}
+
7309#endif
+
7310
+
7311id NSWindow_delegate(RGFW_window* win) {
+
7312 return (id) objc_msgSend_id((id)win->src.window, sel_registerName("delegate"));
+
7313}
+
7314
+
7315u32 RGFW_OnClose(id self) {
+
7316 RGFW_window* win = NULL;
+
7317 object_getInstanceVariable(self, (const char*)"RGFW_window", (void**)&win);
+
7318 if (win == NULL)
+
7319 return true;
+
7320
+
7321 win->event.type = RGFW_quit;
+
7322 RGFW_windowQuitCallback(win);
+
7323
+
7324 return true;
+
7325}
+
7326
+
7327/* NOTE(EimaMei): Fixes the constant clicking when the app is running under a terminal. */
+
7328bool acceptsFirstResponder(void) { return true; }
+
7329bool performKeyEquivalent(id event) { RGFW_UNUSED(event); return true; }
+
7330
+
7331NSDragOperation draggingEntered(id self, SEL sel, id sender) {
+
7332 RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel);
+
7333
+
7334 return NSDragOperationCopy;
+
7335}
+
7336NSDragOperation draggingUpdated(id self, SEL sel, id sender) {
+
7337 RGFW_UNUSED(sel);
+
7338
+
7339 RGFW_window* win = NULL;
+
7340 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
+
7341 if (win == NULL)
+
7342 return 0;
+
7343
+
7344 if (!(win->_flags & RGFW_windowAllowDND)) {
+
7345 return 0;
+
7346 }
+
7347
+
7348 win->event.type = RGFW_DNDInit;
+
7349 win->src.dndPassed = 0;
+
7350
+
7351 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(sender, sel_registerName("draggingLocation"));
7352
-
7353 if (!(win->_flags & RGFW_windowAllowDND)) {
-
7354 return false;
-
7355 }
-
7356
-
7357 return true;
-
7358}
-
7359
-
7360void RGFW__osxDraggingEnded(id self, SEL sel, id sender) { RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); return; }
-
7361
-
7362/* NOTE(EimaMei): Usually, you never need 'id self, SEL cmd' for C -> Obj-C methods. This isn't the case. */
-
7363bool performDragOperation(id self, SEL sel, id sender) {
-
7364 RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel);
-
7365
-
7366 RGFW_window* win = NULL;
-
7367 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7368
-
7369 if (win == NULL)
-
7370 return false;
-
7371
-
7372 // id pasteBoard = objc_msgSend_id(sender, sel_registerName("draggingPasteboard"));
-
7373
-
7375 id pasteBoard = objc_msgSend_id(sender, sel_registerName("draggingPasteboard"));
+
7353 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
+
7354 RGFW_dndInitCallback(win, win->event.point);
+
7355
+
7356 return NSDragOperationCopy;
+
7357}
+
7358bool prepareForDragOperation(id self) {
+
7359 RGFW_window* win = NULL;
+
7360 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
+
7361 if (win == NULL)
+
7362 return true;
+
7363
+
7364 if (!(win->_flags & RGFW_windowAllowDND)) {
+
7365 return false;
+
7366 }
+
7367
+
7368 return true;
+
7369}
+
7370
+
7371void RGFW__osxDraggingEnded(id self, SEL sel, id sender) { RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); return; }
+
7372
+
7373/* NOTE(EimaMei): Usually, you never need 'id self, SEL cmd' for C -> Obj-C methods. This isn't the case. */
+
7374bool performDragOperation(id self, SEL sel, id sender) {
+
7375 RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel);
7376
-
7377 // Get the types of data available on the pasteboard
-
7378 id types = objc_msgSend_id(pasteBoard, sel_registerName("types"));
+
7377 RGFW_window* win = NULL;
+
7378 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
7379
-
7380 // Get the string type for file URLs
-
7381 id fileURLsType = objc_msgSend_class_char(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "NSFilenamesPboardType");
+
7380 if (win == NULL)
+
7381 return false;
7382
-
7383 // Check if the pasteboard contains file URLs
-
7384 if (objc_msgSend_id_bool(types, sel_registerName("containsObject:"), fileURLsType) == 0) {
-
7385 #ifdef RGFW_DEBUG
-
7386 printf("No files found on the pasteboard.\n");
-
7387 #endif
-
7388
-
7389 return 0;
-
7390 }
-
7391
-
7392 id fileURLs = objc_msgSend_id_id(pasteBoard, sel_registerName("propertyListForType:"), fileURLsType);
-
7393 int count = ((int (*)(id, SEL))objc_msgSend)(fileURLs, sel_registerName("count"));
-
7394
-
7395 if (count == 0)
-
7396 return 0;
-
7397
-
7398 for (int i = 0; i < count; i++) {
-
7399 id fileURL = objc_msgSend_arr(fileURLs, sel_registerName("objectAtIndex:"), i);
-
7400 const char *filePath = ((const char* (*)(id, SEL))objc_msgSend)(fileURL, sel_registerName("UTF8String"));
-
7401 RGFW_MEMCPY(win->event.droppedFiles[i], filePath, RGFW_MAX_PATH);
-
7402 win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0';
-
7403 }
-
7404 win->event.droppedFilesCount = count;
+
7383 // id pasteBoard = objc_msgSend_id(sender, sel_registerName("draggingPasteboard"));
+
7384
+
7386 id pasteBoard = objc_msgSend_id(sender, sel_registerName("draggingPasteboard"));
+
7387
+
7388 // Get the types of data available on the pasteboard
+
7389 id types = objc_msgSend_id(pasteBoard, sel_registerName("types"));
+
7390
+
7391 // Get the string type for file URLs
+
7392 id fileURLsType = objc_msgSend_class_char(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "NSFilenamesPboardType");
+
7393
+
7394 // Check if the pasteboard contains file URLs
+
7395 if (objc_msgSend_id_bool(types, sel_registerName("containsObject:"), fileURLsType) == 0) {
+
7396 #ifdef RGFW_DEBUG
+
7397 printf("No files found on the pasteboard.\n");
+
7398 #endif
+
7399
+
7400 return 0;
+
7401 }
+
7402
+
7403 id fileURLs = objc_msgSend_id_id(pasteBoard, sel_registerName("propertyListForType:"), fileURLsType);
+
7404 int count = ((int (*)(id, SEL))objc_msgSend)(fileURLs, sel_registerName("count"));
7405
-
7406 win->event.type = RGFW_DND;
-
7407 win->src.dndPassed = 0;
+
7406 if (count == 0)
+
7407 return 0;
7408
-
7409 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(sender, sel_registerName("draggingLocation"));
-
7410 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
-
7411
-
7412 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
-
7413
-
7414 return false;
-
7415}
+
7409 for (int i = 0; i < count; i++) {
+
7410 id fileURL = objc_msgSend_arr(fileURLs, sel_registerName("objectAtIndex:"), i);
+
7411 const char *filePath = ((const char* (*)(id, SEL))objc_msgSend)(fileURL, sel_registerName("UTF8String"));
+
7412 RGFW_MEMCPY(win->event.droppedFiles[i], filePath, RGFW_MAX_PATH);
+
7413 win->event.droppedFiles[i][RGFW_MAX_PATH - 1] = '\0';
+
7414 }
+
7415 win->event.droppedFilesCount = count;
7416
-
7417#ifndef RGFW_NO_IOKIT
-
7418#include <IOKit/IOKitLib.h>
-
7419#include <IOKit/hid/IOHIDManager.h>
-
7420
-
7421IOHIDDeviceRef RGFW_osxControllers[4] = {NULL};
+
7417 win->event.type = RGFW_DND;
+
7418 win->src.dndPassed = 0;
+
7419
+
7420 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(sender, sel_registerName("draggingLocation"));
+
7421 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
7422
-
7423int findControllerIndex(IOHIDDeviceRef device) {
-
7424 for (int i = 0; i < 4; i++)
-
7425 if (RGFW_osxControllers[i] == device)
-
7426 return i;
-
7427 return -1;
-
7428}
-
7429
-
7430#define RGFW_gamepadEventQueueMAX 11
-
7431RGFW_event RGFW_gamepadEventQueue[RGFW_gamepadEventQueueMAX];
-
7432size_t RGFW_gamepadEventQueueCount = 0;
+
7423 RGFW_dndCallback(win, win->event.droppedFiles, win->event.droppedFilesCount);
+
7424
+
7425 return false;
+
7426}
+
7427
+
7428#ifndef RGFW_NO_IOKIT
+
7429#include <IOKit/IOKitLib.h>
+
7430#include <IOKit/hid/IOHIDManager.h>
+
7431
+
7432IOHIDDeviceRef RGFW_osxControllers[4] = {NULL};
7433
-
7434void RGFW__osxInputValueChangedCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value) {
-
7435 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender);
-
7436
-
7437 if (RGFW_gamepadEventQueueCount >= RGFW_gamepadEventQueueMAX - 1)
-
7438 return;
-
7439
-
7440 IOHIDElementRef element = IOHIDValueGetElement(value);
-
7441
-
7442 IOHIDDeviceRef device = IOHIDElementGetDevice(element);
-
7443 size_t index = findControllerIndex(device);
+
7434int findControllerIndex(IOHIDDeviceRef device) {
+
7435 for (int i = 0; i < 4; i++)
+
7436 if (RGFW_osxControllers[i] == device)
+
7437 return i;
+
7438 return -1;
+
7439}
+
7440
+
7441#define RGFW_gamepadEventQueueMAX 11
+
7442RGFW_event RGFW_gamepadEventQueue[RGFW_gamepadEventQueueMAX];
+
7443size_t RGFW_gamepadEventQueueCount = 0;
7444
-
7445 uint32_t usagePage = IOHIDElementGetUsagePage(element);
-
7446 uint32_t usage = IOHIDElementGetUsage(element);
+
7445void RGFW__osxInputValueChangedCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value) {
+
7446 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender);
7447
-
7448 CFIndex intValue = IOHIDValueGetIntegerValue(value);
-
7449
-
7450 u8 RGFW_osx2RGFWSrc[2][RGFW_gamepadFinal] = {{
-
7451 0, RGFW_gamepadSelect, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadStart,
-
7452 RGFW_gamepadUp, RGFW_gamepadRight, RGFW_gamepadDown, RGFW_gamepadLeft,
-
7453 RGFW_gamepadL2, RGFW_gamepadR2, RGFW_gamepadL1, RGFW_gamepadR1,
-
7454 RGFW_gamepadY, RGFW_gamepadB, RGFW_gamepadA, RGFW_gamepadX, RGFW_gamepadHome},
-
7455 {0, RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadR3, RGFW_gamepadX,
-
7456 RGFW_gamepadY, RGFW_gamepadRight, RGFW_gamepadL1, RGFW_gamepadR1,
-
7457 RGFW_gamepadL2, RGFW_gamepadR2, RGFW_gamepadDown, RGFW_gamepadStart,
-
7458 RGFW_gamepadUp, RGFW_gamepadL3, RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome}
-
7459 };
+
7448 if (RGFW_gamepadEventQueueCount >= RGFW_gamepadEventQueueMAX - 1)
+
7449 return;
+
7450
+
7451 IOHIDElementRef element = IOHIDValueGetElement(value);
+
7452
+
7453 IOHIDDeviceRef device = IOHIDElementGetDevice(element);
+
7454 size_t index = findControllerIndex(device);
+
7455
+
7456 uint32_t usagePage = IOHIDElementGetUsagePage(element);
+
7457 uint32_t usage = IOHIDElementGetUsage(element);
+
7458
+
7459 CFIndex intValue = IOHIDValueGetIntegerValue(value);
7460
-
7461 u8* RGFW_osx2RGFW = RGFW_osx2RGFWSrc[0];
-
7462 if (RGFW_gamepads_type[index] == RGFW_gamepadMicrosoft)
-
7463 RGFW_osx2RGFW = RGFW_osx2RGFWSrc[1];
-
7464
-
7465 RGFW_event event;
-
7466
-
7467 switch (usagePage) {
-
7468 case kHIDPage_Button: {
-
7469 u8 button = 0;
-
7470 if (usage < sizeof(RGFW_osx2RGFW))
-
7471 button = RGFW_osx2RGFW[usage];
-
7472
-
7473 RGFW_gamepadButtonCallback(RGFW_root, index, button, intValue);
-
7474 RGFW_gamepadPressed[index][button].prev = RGFW_gamepadPressed[index][button].current;
-
7475 RGFW_gamepadPressed[index][button].current = intValue;
-
7476 event.type = intValue ? RGFW_gamepadButtonPressed: RGFW_gamepadButtonReleased;
-
7477 event.button = button;
-
7478 event.gamepad = index;
-
7479
-
7480 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = event;
-
7481 RGFW_gamepadEventQueueCount++;
-
7482 break;
-
7483 }
-
7484 case kHIDPage_GenericDesktop: {
-
7485 CFIndex logicalMin = IOHIDElementGetLogicalMin(element);
-
7486 CFIndex logicalMax = IOHIDElementGetLogicalMax(element);
-
7487
-
7488 if (logicalMax <= logicalMin) return;
-
7489 if (intValue < logicalMin) intValue = logicalMin;
-
7490 if (intValue > logicalMax) intValue = logicalMax;
-
7491
-
7492 i8 value = (i8)(-100.0 + ((intValue - logicalMin) * 200.0) / (logicalMax - logicalMin));
-
7493
-
7494 switch (usage) {
-
7495 case kHIDUsage_GD_X: RGFW_gamepadAxes[index][0].x = value; event.whichAxis = 0; break;
-
7496 case kHIDUsage_GD_Y: RGFW_gamepadAxes[index][0].y = value; event.whichAxis = 0; break;
-
7497 case kHIDUsage_GD_Z: RGFW_gamepadAxes[index][1].x = value; event.whichAxis = 1; break;
-
7498 case kHIDUsage_GD_Rz: RGFW_gamepadAxes[index][1].y = value; event.whichAxis = 1; break;
-
7499 default: return;
-
7500 }
-
7501
-
7502 event.type = RGFW_gamepadAxisMove;
-
7503 event.gamepad = index;
+
7461 u8 RGFW_osx2RGFWSrc[2][RGFW_gamepadFinal] = {{
+
7462 0, RGFW_gamepadSelect, RGFW_gamepadL3, RGFW_gamepadR3, RGFW_gamepadStart,
+
7463 RGFW_gamepadUp, RGFW_gamepadRight, RGFW_gamepadDown, RGFW_gamepadLeft,
+
7464 RGFW_gamepadL2, RGFW_gamepadR2, RGFW_gamepadL1, RGFW_gamepadR1,
+
7465 RGFW_gamepadY, RGFW_gamepadB, RGFW_gamepadA, RGFW_gamepadX, RGFW_gamepadHome},
+
7466 {0, RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadR3, RGFW_gamepadX,
+
7467 RGFW_gamepadY, RGFW_gamepadRight, RGFW_gamepadL1, RGFW_gamepadR1,
+
7468 RGFW_gamepadL2, RGFW_gamepadR2, RGFW_gamepadDown, RGFW_gamepadStart,
+
7469 RGFW_gamepadUp, RGFW_gamepadL3, RGFW_gamepadSelect, RGFW_gamepadStart, RGFW_gamepadHome}
+
7470 };
+
7471
+
7472 u8* RGFW_osx2RGFW = RGFW_osx2RGFWSrc[0];
+
7473 if (RGFW_gamepads_type[index] == RGFW_gamepadMicrosoft)
+
7474 RGFW_osx2RGFW = RGFW_osx2RGFWSrc[1];
+
7475
+
7476 RGFW_event event;
+
7477
+
7478 switch (usagePage) {
+
7479 case kHIDPage_Button: {
+
7480 u8 button = 0;
+
7481 if (usage < sizeof(RGFW_osx2RGFW))
+
7482 button = RGFW_osx2RGFW[usage];
+
7483
+
7484 RGFW_gamepadButtonCallback(RGFW_root, index, button, intValue);
+
7485 RGFW_gamepadPressed[index][button].prev = RGFW_gamepadPressed[index][button].current;
+
7486 RGFW_gamepadPressed[index][button].current = intValue;
+
7487 event.type = intValue ? RGFW_gamepadButtonPressed: RGFW_gamepadButtonReleased;
+
7488 event.button = button;
+
7489 event.gamepad = index;
+
7490
+
7491 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = event;
+
7492 RGFW_gamepadEventQueueCount++;
+
7493 break;
+
7494 }
+
7495 case kHIDPage_GenericDesktop: {
+
7496 CFIndex logicalMin = IOHIDElementGetLogicalMin(element);
+
7497 CFIndex logicalMax = IOHIDElementGetLogicalMax(element);
+
7498
+
7499 if (logicalMax <= logicalMin) return;
+
7500 if (intValue < logicalMin) intValue = logicalMin;
+
7501 if (intValue > logicalMax) intValue = logicalMax;
+
7502
+
7503 i8 value = (i8)(-100.0 + ((intValue - logicalMin) * 200.0) / (logicalMax - logicalMin));
7504
-
7505 event.axis[0] = RGFW_gamepadAxes[index][0];
-
7506 event.axis[1] = RGFW_gamepadAxes[index][1];
-
7507
-
7508 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = event;
-
7509 RGFW_gamepadEventQueueCount++;
-
7510
-
7511 RGFW_gamepadAxisCallback(RGFW_root, index, event.axis, 2, event.whichAxis);
-
7512 }
-
7513 }
-
7514}
+
7505 switch (usage) {
+
7506 case kHIDUsage_GD_X: RGFW_gamepadAxes[index][0].x = value; event.whichAxis = 0; break;
+
7507 case kHIDUsage_GD_Y: RGFW_gamepadAxes[index][0].y = value; event.whichAxis = 0; break;
+
7508 case kHIDUsage_GD_Z: RGFW_gamepadAxes[index][1].x = value; event.whichAxis = 1; break;
+
7509 case kHIDUsage_GD_Rz: RGFW_gamepadAxes[index][1].y = value; event.whichAxis = 1; break;
+
7510 default: return;
+
7511 }
+
7512
+
7513 event.type = RGFW_gamepadAxisMove;
+
7514 event.gamepad = index;
7515
-
7516void RGFW__osxDeviceAddedCallback(void* context, IOReturn result, void *sender, IOHIDDeviceRef device) {
-
7517 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender);
-
7518 CFTypeRef usageRef = (CFTypeRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDPrimaryUsageKey));
-
7519 int usage = 0;
-
7520 if (usageRef)
-
7521 CFNumberGetValue((CFNumberRef)usageRef, kCFNumberIntType, (void*)&usage);
-
7522
-
7523 if (usage != kHIDUsage_GD_Joystick && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController) {
-
7524 return;
-
7525 }
+
7516 event.axis[0] = RGFW_gamepadAxes[index][0];
+
7517 event.axis[1] = RGFW_gamepadAxes[index][1];
+
7518
+
7519 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = event;
+
7520 RGFW_gamepadEventQueueCount++;
+
7521
+
7522 RGFW_gamepadAxisCallback(RGFW_root, index, event.axis, 2, event.whichAxis);
+
7523 }
+
7524 }
+
7525}
7526
-
7527 for (size_t i = 0; i < 4; i++) {
-
7528 if (RGFW_osxControllers[i] != NULL)
-
7529 continue;
-
7530
-
7531 RGFW_osxControllers[i] = device;
-
7532
-
7533 IOHIDDeviceRegisterInputValueCallback(device, RGFW__osxInputValueChangedCallback, NULL);
-
7534
-
7535 CFStringRef deviceName = (CFStringRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
-
7536 if (deviceName)
-
7537 CFStringGetCString(deviceName, RGFW_gamepads_name[i], sizeof(RGFW_gamepads_name[i]), kCFStringEncodingUTF8);
-
7538
-
7539 RGFW_gamepads_type[i] = RGFW_gamepadUnknown;
-
7540 if (strstr(RGFW_gamepads_name[i], "Microsoft") || strstr(RGFW_gamepads_name[i], "X-Box") || strstr(RGFW_gamepads_name[i], "Xbox"))
-
7541 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
-
7542 else if (strstr(RGFW_gamepads_name[i], "PlayStation") || strstr(RGFW_gamepads_name[i], "PS3") || strstr(RGFW_gamepads_name[i], "PS4") || strstr(RGFW_gamepads_name[i], "PS5"))
-
7543 RGFW_gamepads_type[i] = RGFW_gamepadSony;
-
7544 else if (strstr(RGFW_gamepads_name[i], "Nintendo"))
-
7545 RGFW_gamepads_type[i] = RGFW_gamepadNintendo;
-
7546 else if (strstr(RGFW_gamepads_name[i], "Logitech"))
-
7547 RGFW_gamepads_type[i] = RGFW_gamepadLogitech;
-
7548
-
7549 RGFW_gamepads[i] = i;
-
7550 RGFW_gamepadCount++;
-
7551
-
7552 RGFW_event ev;
-
7553 ev.type = RGFW_gamepadConnected;
-
7554 ev.gamepad = i;
-
7555 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = ev;
-
7556 RGFW_gamepadEventQueueCount++;
-
7557 RGFW_gamepadCallback(RGFW_root, i, 1);
-
7558 break;
-
7559 }
-
7560}
-
7561
-
7562void RGFW__osxDeviceRemovedCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device) {
-
7563 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender); RGFW_UNUSED(device);
-
7564 CFNumberRef usageRef = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDPrimaryUsageKey));
-
7565 int usage = 0;
-
7566 if (usageRef)
-
7567 CFNumberGetValue(usageRef, kCFNumberIntType, &usage);
-
7568
-
7569 if (usage != kHIDUsage_GD_Joystick && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController) {
-
7570 return;
-
7571 }
+
7527void RGFW__osxDeviceAddedCallback(void* context, IOReturn result, void *sender, IOHIDDeviceRef device) {
+
7528 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender);
+
7529 CFTypeRef usageRef = (CFTypeRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDPrimaryUsageKey));
+
7530 int usage = 0;
+
7531 if (usageRef)
+
7532 CFNumberGetValue((CFNumberRef)usageRef, kCFNumberIntType, (void*)&usage);
+
7533
+
7534 if (usage != kHIDUsage_GD_Joystick && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController) {
+
7535 return;
+
7536 }
+
7537
+
7538 for (size_t i = 0; i < 4; i++) {
+
7539 if (RGFW_osxControllers[i] != NULL)
+
7540 continue;
+
7541
+
7542 RGFW_osxControllers[i] = device;
+
7543
+
7544 IOHIDDeviceRegisterInputValueCallback(device, RGFW__osxInputValueChangedCallback, NULL);
+
7545
+
7546 CFStringRef deviceName = (CFStringRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
+
7547 if (deviceName)
+
7548 CFStringGetCString(deviceName, RGFW_gamepads_name[i], sizeof(RGFW_gamepads_name[i]), kCFStringEncodingUTF8);
+
7549
+
7550 RGFW_gamepads_type[i] = RGFW_gamepadUnknown;
+
7551 if (strstr(RGFW_gamepads_name[i], "Microsoft") || strstr(RGFW_gamepads_name[i], "X-Box") || strstr(RGFW_gamepads_name[i], "Xbox"))
+
7552 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
+
7553 else if (strstr(RGFW_gamepads_name[i], "PlayStation") || strstr(RGFW_gamepads_name[i], "PS3") || strstr(RGFW_gamepads_name[i], "PS4") || strstr(RGFW_gamepads_name[i], "PS5"))
+
7554 RGFW_gamepads_type[i] = RGFW_gamepadSony;
+
7555 else if (strstr(RGFW_gamepads_name[i], "Nintendo"))
+
7556 RGFW_gamepads_type[i] = RGFW_gamepadNintendo;
+
7557 else if (strstr(RGFW_gamepads_name[i], "Logitech"))
+
7558 RGFW_gamepads_type[i] = RGFW_gamepadLogitech;
+
7559
+
7560 RGFW_gamepads[i] = i;
+
7561 RGFW_gamepadCount++;
+
7562
+
7563 RGFW_event ev;
+
7564 ev.type = RGFW_gamepadConnected;
+
7565 ev.gamepad = i;
+
7566 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = ev;
+
7567 RGFW_gamepadEventQueueCount++;
+
7568 RGFW_gamepadCallback(RGFW_root, i, 1);
+
7569 break;
+
7570 }
+
7571}
7572
-
7573 i32 index = findControllerIndex(device);
-
7574 if (index != -1)
-
7575 RGFW_osxControllers[index] = NULL;
-
7576
-
7577 RGFW_event ev;
-
7578 ev.type = RGFW_gamepadDisconnected;
-
7579 ev.gamepad = index;
-
7580 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = ev;
-
7581 RGFW_gamepadEventQueueCount++;
-
7582 RGFW_gamepadCallback(RGFW_root, index, 0);
+
7573void RGFW__osxDeviceRemovedCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef device) {
+
7574 RGFW_UNUSED(context); RGFW_UNUSED(result); RGFW_UNUSED(sender); RGFW_UNUSED(device);
+
7575 CFNumberRef usageRef = (CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDPrimaryUsageKey));
+
7576 int usage = 0;
+
7577 if (usageRef)
+
7578 CFNumberGetValue(usageRef, kCFNumberIntType, &usage);
+
7579
+
7580 if (usage != kHIDUsage_GD_Joystick && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController) {
+
7581 return;
+
7582 }
7583
-
7584 RGFW_gamepadCount--;
-
7585}
-
7586
-
7587RGFWDEF void RGFW_osxInitIOKit(void);
-
7588void RGFW_osxInitIOKit(void) {
-
7589 IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
-
7590 if (!hidManager) {
-
7591 fprintf(stderr, "Failed to create IOHIDManager.\n");
-
7592 return;
-
7593 }
+
7584 i32 index = findControllerIndex(device);
+
7585 if (index != -1)
+
7586 RGFW_osxControllers[index] = NULL;
+
7587
+
7588 RGFW_event ev;
+
7589 ev.type = RGFW_gamepadDisconnected;
+
7590 ev.gamepad = index;
+
7591 RGFW_gamepadEventQueue[RGFW_gamepadEventQueueCount] = ev;
+
7592 RGFW_gamepadEventQueueCount++;
+
7593 RGFW_gamepadCallback(RGFW_root, index, 0);
7594
-
7595 CFMutableDictionaryRef matchingDictionary = CFDictionaryCreateMutable(
-
7596 kCFAllocatorDefault,
-
7597 0,
-
7598 &kCFTypeDictionaryKeyCallBacks,
-
7599 &kCFTypeDictionaryValueCallBacks
-
7600 );
-
7601 if (!matchingDictionary) {
-
7602 fprintf(stderr, "Failed to create matching dictionary.\n");
-
7603 CFRelease(hidManager);
-
7604 return;
-
7605 }
-
7606
-
7607 CFDictionarySetValue(
-
7608 matchingDictionary,
-
7609 CFSTR(kIOHIDDeviceUsagePageKey),
-
7610 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, (int[]){kHIDPage_GenericDesktop})
+
7595 RGFW_gamepadCount--;
+
7596}
+
7597
+
7598RGFWDEF void RGFW_osxInitIOKit(void);
+
7599void RGFW_osxInitIOKit(void) {
+
7600 IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+
7601 if (!hidManager) {
+
7602 fprintf(stderr, "Failed to create IOHIDManager.\n");
+
7603 return;
+
7604 }
+
7605
+
7606 CFMutableDictionaryRef matchingDictionary = CFDictionaryCreateMutable(
+
7607 kCFAllocatorDefault,
+
7608 0,
+
7609 &kCFTypeDictionaryKeyCallBacks,
+
7610 &kCFTypeDictionaryValueCallBacks
7611 );
-
7612
-
7613 IOHIDManagerSetDeviceMatching(hidManager, matchingDictionary);
-
7614
-
7615 IOHIDManagerRegisterDeviceMatchingCallback(hidManager, RGFW__osxDeviceAddedCallback, NULL);
-
7616 IOHIDManagerRegisterDeviceRemovalCallback(hidManager, RGFW__osxDeviceRemovedCallback, NULL);
+
7612 if (!matchingDictionary) {
+
7613 fprintf(stderr, "Failed to create matching dictionary.\n");
+
7614 CFRelease(hidManager);
+
7615 return;
+
7616 }
7617
-
7618 IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
-
7619
-
7620 IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
-
7621
-
7622 // Execute the run loop once in order to register any initially-attached joysticks
-
7623 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
-
7624}
-
7625#endif
-
7626
-
7627void NSMoveToResourceDir(void) {
-
7628 char resourcesPath[255];
-
7629
-
7630 CFBundleRef bundle = CFBundleGetMainBundle();
-
7631 if (!bundle)
-
7632 return;
-
7633
-
7634 CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
-
7635 CFStringRef last = CFURLCopyLastPathComponent(resourcesURL);
-
7636
-
7637 if (
-
7638 CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo ||
-
7639 CFURLGetFileSystemRepresentation(resourcesURL, true, (u8*) resourcesPath, 255) == 0
-
7640 ) {
-
7641 CFRelease(last);
-
7642 CFRelease(resourcesURL);
+
7618 CFDictionarySetValue(
+
7619 matchingDictionary,
+
7620 CFSTR(kIOHIDDeviceUsagePageKey),
+
7621 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, (int[]){kHIDPage_GenericDesktop})
+
7622 );
+
7623
+
7624 IOHIDManagerSetDeviceMatching(hidManager, matchingDictionary);
+
7625
+
7626 IOHIDManagerRegisterDeviceMatchingCallback(hidManager, RGFW__osxDeviceAddedCallback, NULL);
+
7627 IOHIDManagerRegisterDeviceRemovalCallback(hidManager, RGFW__osxDeviceRemovedCallback, NULL);
+
7628
+
7629 IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+
7630
+
7631 IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
+
7632
+
7633 // Execute the run loop once in order to register any initially-attached joysticks
+
7634 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
+
7635}
+
7636#endif
+
7637
+
7638void NSMoveToResourceDir(void) {
+
7639 char resourcesPath[255];
+
7640
+
7641 CFBundleRef bundle = CFBundleGetMainBundle();
+
7642 if (!bundle)
7643 return;
-
7644 }
-
7645
-
7646 CFRelease(last);
-
7647 CFRelease(resourcesURL);
-
7648
-
7649 chdir(resourcesPath);
-
7650}
-
7651
-
7652
-
7653NSSize RGFW__osxWindowResize(id self, SEL sel, NSSize frameSize) {
-
7654 RGFW_UNUSED(sel);
-
7655
-
7656 RGFW_window* win = NULL;
-
7657 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7658 if (win == NULL)
-
7659 return frameSize;
-
7660
-
7661 win->r.w = frameSize.width;
-
7662 win->r.h = frameSize.height;
-
7663 win->event.type = RGFW_windowResized;
-
7664 RGFW_windowResizeCallback(win, win->r);
-
7665 return frameSize;
-
7666}
-
7667
-
7668void RGFW__osxWindowMove(id self, SEL sel) {
-
7669 RGFW_UNUSED(sel);
-
7670
-
7671 RGFW_window* win = NULL;
-
7672 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7673 if (win == NULL)
-
7674 return;
-
7675
-
7676 NSRect frame = ((NSRect(*)(id, SEL))abi_objc_msgSend_stret)((id)win->src.window, sel_registerName("frame"));
-
7677 win->r.x = (i32) frame.origin.x;
-
7678 win->r.y = (i32) frame.origin.y;
-
7679
-
7680 win->event.type = RGFW_windowMoved;
-
7681 RGFW_windowMoveCallback(win, win->r);
-
7682}
-
7683
-
7684void RGFW__osxUpdateLayer(id self, SEL sel) {
-
7685 RGFW_UNUSED(sel);
+
7644
+
7645 CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
+
7646 CFStringRef last = CFURLCopyLastPathComponent(resourcesURL);
+
7647
+
7648 if (
+
7649 CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo ||
+
7650 CFURLGetFileSystemRepresentation(resourcesURL, true, (u8*) resourcesPath, 255) == 0
+
7651 ) {
+
7652 CFRelease(last);
+
7653 CFRelease(resourcesURL);
+
7654 return;
+
7655 }
+
7656
+
7657 CFRelease(last);
+
7658 CFRelease(resourcesURL);
+
7659
+
7660 chdir(resourcesPath);
+
7661}
+
7662
+
7663
+
7664NSSize RGFW__osxWindowResize(id self, SEL sel, NSSize frameSize) {
+
7665 RGFW_UNUSED(sel);
+
7666
+
7667 RGFW_window* win = NULL;
+
7668 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
+
7669 if (win == NULL)
+
7670 return frameSize;
+
7671
+
7672 win->r.w = frameSize.width;
+
7673 win->r.h = frameSize.height;
+
7674 win->event.type = RGFW_windowResized;
+
7675 RGFW_windowResizeCallback(win, win->r);
+
7676 return frameSize;
+
7677}
+
7678
+
7679void RGFW__osxWindowMove(id self, SEL sel) {
+
7680 RGFW_UNUSED(sel);
+
7681
+
7682 RGFW_window* win = NULL;
+
7683 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
+
7684 if (win == NULL)
+
7685 return;
7686
-
7687 RGFW_window* win = NULL;
-
7688 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
-
7689 if (win == NULL)
-
7690 return;
-
7691
-
7692 win->event.type = RGFW_windowRefresh;
-
7693 RGFW_windowRefreshCallback(win);
-
7694}
-
7695
-
7696void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area) {
-
7697 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
7698 win->buffer = buffer
-
7699 win->bufferSize = area;
-
7700 win->_flags |= RGFW_BUFFER_ALLOC;
-
7701 #ifdef RGFW_OSMESA
-
7702 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
-
7703 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
-
7704 #endif
-
7705 #else
-
7706 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
-
7707 #endif
-
7708}
-
7709
-
7710void RGFW_window_cocoaSetLayer(RGFW_window* win, void* layer) {
-
7711 objc_msgSend_void_id((id)win->src.view, sel_registerName("setLayer"), (id)layer);
-
7712}
-
7713
-
7714void* RGFW_cocoaGetLayer(void) {
-
7715 return objc_msgSend_class((id)objc_getClass("CAMetalLayer"), (SEL)sel_registerName("layer"));
-
7716}
-
7717
-
7718
-
7719NSPasteboardType const NSPasteboardTypeURL = "public.url";
-
7720NSPasteboardType const NSPasteboardTypeFileURL = "public.file-url";
-
7721
-
7722RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
-
7723 static u8 RGFW_loaded = 0;
+
7687 NSRect frame = ((NSRect(*)(id, SEL))abi_objc_msgSend_stret)((id)win->src.window, sel_registerName("frame"));
+
7688 win->r.x = (i32) frame.origin.x;
+
7689 win->r.y = (i32) frame.origin.y;
+
7690
+
7691 win->event.type = RGFW_windowMoved;
+
7692 RGFW_windowMoveCallback(win, win->r);
+
7693}
+
7694
+
7695void RGFW__osxUpdateLayer(id self, SEL sel) {
+
7696 RGFW_UNUSED(sel);
+
7697
+
7698 RGFW_window* win = NULL;
+
7699 object_getInstanceVariable(self, "RGFW_window", (void**)&win);
+
7700 if (win == NULL)
+
7701 return;
+
7702
+
7703 win->event.type = RGFW_windowRefresh;
+
7704 RGFW_windowRefreshCallback(win);
+
7705}
+
7706
+
7707void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area) {
+
7708 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
7709 win->buffer = buffer
+
7710 win->bufferSize = area;
+
7711 win->_flags |= RGFW_BUFFER_ALLOC;
+
7712 #ifdef RGFW_OSMESA
+
7713 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
+
7714 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
+
7715 #endif
+
7716 #else
+
7717 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
+
7718 #endif
+
7719}
+
7720
+
7721void RGFW_window_cocoaSetLayer(RGFW_window* win, void* layer) {
+
7722 objc_msgSend_void_id((id)win->src.view, sel_registerName("setLayer"), (id)layer);
+
7723}
7724
-
7725 /* NOTE(EimaMei): Why does Apple hate good code? Like wtf, who thought of methods being a great idea???
-
7726 Imagine a universe, where MacOS had a proper system API (we would probably have like 20% better performance).
-
7727 */
-
7728 si_func_to_SEL_with_name("NSObject", "windowShouldClose", (void*)RGFW_OnClose);
+
7725void* RGFW_cocoaGetLayer(void) {
+
7726 return objc_msgSend_class((id)objc_getClass("CAMetalLayer"), (SEL)sel_registerName("layer"));
+
7727}
+
7728
7729
-
7730 /* NOTE(EimaMei): Fixes the 'Boop' sfx from constantly playing each time you click a key. Only a problem when running in the terminal. */
-
7731 si_func_to_SEL("NSWindow", acceptsFirstResponder);
-
7732 si_func_to_SEL("NSWindow", performKeyEquivalent);
-
7733
-
7734 // RR Create an autorelease pool
-
7735 id pool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
-
7736 pool = objc_msgSend_id(pool, sel_registerName("init"));
-
7737
-
7738 if (NSApp == NULL) {
-
7739 NSApp = objc_msgSend_id((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
+
7730NSPasteboardType const NSPasteboardTypeURL = "public.url";
+
7731NSPasteboardType const NSPasteboardTypeFileURL = "public.file-url";
+
7732
+
7733RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
+
7734 static u8 RGFW_loaded = 0;
+
7735
+
7736 /* NOTE(EimaMei): Why does Apple hate good code? Like wtf, who thought of methods being a great idea???
+
7737 Imagine a universe, where MacOS had a proper system API (we would probably have like 20% better performance).
+
7738 */
+
7739 si_func_to_SEL_with_name("NSObject", "windowShouldClose", (void*)RGFW_OnClose);
7740
-
7741 ((void (*)(id, SEL, NSUInteger))objc_msgSend)
-
7742 (NSApp, sel_registerName("setActivationPolicy:"), NSApplicationActivationPolicyRegular);
-
7743
-
7744 #ifndef RGFW_NO_IOKIT
-
7745 RGFW_osxInitIOKit();
-
7746 #endif
-
7747 }
+
7741 /* NOTE(EimaMei): Fixes the 'Boop' sfx from constantly playing each time you click a key. Only a problem when running in the terminal. */
+
7742 si_func_to_SEL("NSWindow", acceptsFirstResponder);
+
7743 si_func_to_SEL("NSWindow", performKeyEquivalent);
+
7744
+
7745 // RR Create an autorelease pool
+
7746 id pool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
+
7747 pool = objc_msgSend_id(pool, sel_registerName("init"));
7748
-
7749 RGFW_window_basic_init(win, rect, flags);
-
7750
- -
7752
-
7753 NSRect windowRect;
-
7754 windowRect.origin.x = win->r.x;
-
7755 windowRect.origin.y = win->r.y;
-
7756 windowRect.size.width = win->r.w;
-
7757 windowRect.size.height = win->r.h;
-
7758
-
7759 NSBackingStoreType macArgs = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSBackingStoreBuffered | NSWindowStyleMaskTitled;
-
7760
-
7761 if (!(flags & RGFW_windowNoResize))
-
7762 macArgs |= NSWindowStyleMaskResizable;
-
7763 if (!(flags & RGFW_windowNoBorder))
-
7764 macArgs |= NSWindowStyleMaskTitled;
-
7765 else
-
7766 macArgs = NSWindowStyleMaskBorderless;
-
7767 {
-
7768 void* nsclass = objc_getClass("NSWindow");
-
7769 SEL func = sel_registerName("initWithContentRect:styleMask:backing:defer:");
-
7770
-
7771 win->src.window = ((id(*)(id, SEL, NSRect, NSWindowStyleMask, NSBackingStoreType, bool))objc_msgSend)
-
7772 (NSAlloc(nsclass), func, windowRect, macArgs, macArgs, false);
-
7773 }
-
7774
-
7775 id str = NSString_stringWithUTF8String(name);
-
7776 objc_msgSend_void_id((id)win->src.window, sel_registerName("setTitle:"), str);
-
7777
-
7778 #ifdef RGFW_EGL
-
7779 if ((flags & RGFW_windowNoInitAPI) == 0)
-
7780 RGFW_createOpenGLContext(win);
-
7781 #endif
-
7782
-
7783 #ifdef RGFW_OPENGL
-
7784
-
7785 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
7786 void* attrs = RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
-
7787 void* format = NSOpenGLPixelFormat_initWithAttributes((uint32_t*)attrs);
+
7749 if (NSApp == NULL) {
+
7750 NSApp = objc_msgSend_id((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
+
7751
+
7752 ((void (*)(id, SEL, NSUInteger))objc_msgSend)
+
7753 (NSApp, sel_registerName("setActivationPolicy:"), NSApplicationActivationPolicyRegular);
+
7754
+
7755 #ifndef RGFW_NO_IOKIT
+
7756 RGFW_osxInitIOKit();
+
7757 #endif
+
7758 }
+
7759
+
7760 RGFW_window_basic_init(win, rect, flags);
+
7761
+ +
7763
+
7764 NSRect windowRect;
+
7765 windowRect.origin.x = win->r.x;
+
7766 windowRect.origin.y = win->r.y;
+
7767 windowRect.size.width = win->r.w;
+
7768 windowRect.size.height = win->r.h;
+
7769
+
7770 NSBackingStoreType macArgs = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSBackingStoreBuffered | NSWindowStyleMaskTitled;
+
7771
+
7772 if (!(flags & RGFW_windowNoResize))
+
7773 macArgs |= NSWindowStyleMaskResizable;
+
7774 if (!(flags & RGFW_windowNoBorder))
+
7775 macArgs |= NSWindowStyleMaskTitled;
+
7776 else
+
7777 macArgs = NSWindowStyleMaskBorderless;
+
7778 {
+
7779 void* nsclass = objc_getClass("NSWindow");
+
7780 SEL func = sel_registerName("initWithContentRect:styleMask:backing:defer:");
+
7781
+
7782 win->src.window = ((id(*)(id, SEL, NSRect, NSWindowStyleMask, NSBackingStoreType, bool))objc_msgSend)
+
7783 (NSAlloc(nsclass), func, windowRect, macArgs, macArgs, false);
+
7784 }
+
7785
+
7786 id str = NSString_stringWithUTF8String(name);
+
7787 objc_msgSend_void_id((id)win->src.window, sel_registerName("setTitle:"), str);
7788
-
7789 if (format == NULL) {
-
7790 #ifdef RGFW_DEBUG
-
7791 printf("Failed to load pixel format for OpenGL\n");
-
7792 #endif
+
7789 #ifdef RGFW_EGL
+
7790 if ((flags & RGFW_windowNoInitAPI) == 0)
+
7791 RGFW_createOpenGLContext(win);
+
7792 #endif
7793
-
7794 void* attrs = RGFW_initFormatAttribs(1);
-
7795 format = NSOpenGLPixelFormat_initWithAttributes((uint32_t*)attrs);
-
7796
-
7797 #ifdef RGFW_DEBUG
-
7798 if (format == NULL)
-
7799 printf("and loading software rendering OpenGL failed\n");
-
7800 else
-
7801 printf("Switching to software rendering\n");
-
7802 #endif
-
7803 }
+
7794 #ifdef RGFW_OPENGL
+
7795
+
7796 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
7797 void* attrs = RGFW_initFormatAttribs(flags & RGFW_windowOpenglSoftware);
+
7798 void* format = NSOpenGLPixelFormat_initWithAttributes((uint32_t*)attrs);
+
7799
+
7800 if (format == NULL) {
+
7801 #ifdef RGFW_DEBUG
+
7802 printf("Failed to load pixel format for OpenGL\n");
+
7803 #endif
7804
-
7805 /* the pixel format can be passed directly to opengl context creation to create a context
-
7806 this is because the format also includes information about the opengl version (which may be a bad thing) */
-
7807 win->src.view = NSOpenGLView_initWithFrame((NSRect){{0, 0}, {win->r.w, win->r.h}}, (uint32_t*)format);
-
7808 objc_msgSend_void(win->src.view, sel_registerName("prepareOpenGL"));
-
7809 win->src.ctx = objc_msgSend_id(win->src.view, sel_registerName("openGLContext"));
-
7810 } else
-
7811 #endif
-
7812 {
-
7813 NSRect contentRect = (NSRect){{0, 0}, {win->r.w, win->r.h}};
-
7814 win->src.view = ((id(*)(id, SEL, NSRect))objc_msgSend)
-
7815 (NSAlloc((id)objc_getClass("NSView")), sel_registerName("initWithFrame:"),
-
7816 contentRect);
-
7817 }
-
7818
-
7819 void* contentView = NSWindow_contentView((id)win->src.window);
-
7820 objc_msgSend_void_bool(contentView, sel_registerName("setWantsLayer:"), true);
-
7821
-
7822 objc_msgSend_void_id((id)win->src.window, sel_registerName("setContentView:"), win->src.view);
-
7823
-
7824 #ifdef RGFW_OPENGL
-
7825 if ((flags & RGFW_windowNoInitAPI) == 0)
-
7826 objc_msgSend_void(win->src.ctx, sel_registerName("makeCurrentContext"));
-
7827 #endif
-
7828
-
7829 if (flags & RGFW_windowTransparent) {
-
7830 #ifdef RGFW_OPENGL
-
7831 if ((flags & RGFW_windowNoInitAPI) == 0) {
-
7832 i32 opacity = 0;
-
7833 #define NSOpenGLCPSurfaceOpacity 236
-
7834 NSOpenGLContext_setValues((id)win->src.ctx, &opacity, NSOpenGLCPSurfaceOpacity);
-
7835 }
-
7836 #endif
-
7837
-
7838 objc_msgSend_void_bool(win->src.window, sel_registerName("setOpaque:"), false);
+
7805 void* attrs = RGFW_initFormatAttribs(1);
+
7806 format = NSOpenGLPixelFormat_initWithAttributes((uint32_t*)attrs);
+
7807
+
7808 #ifdef RGFW_DEBUG
+
7809 if (format == NULL)
+
7810 printf("and loading software rendering OpenGL failed\n");
+
7811 else
+
7812 printf("Switching to software rendering\n");
+
7813 #endif
+
7814 }
+
7815
+
7816 /* the pixel format can be passed directly to opengl context creation to create a context
+
7817 this is because the format also includes information about the opengl version (which may be a bad thing) */
+
7818 win->src.view = NSOpenGLView_initWithFrame((NSRect){{0, 0}, {win->r.w, win->r.h}}, (uint32_t*)format);
+
7819 objc_msgSend_void(win->src.view, sel_registerName("prepareOpenGL"));
+
7820 win->src.ctx = objc_msgSend_id(win->src.view, sel_registerName("openGLContext"));
+
7821 } else
+
7822 #endif
+
7823 {
+
7824 NSRect contentRect = (NSRect){{0, 0}, {win->r.w, win->r.h}};
+
7825 win->src.view = ((id(*)(id, SEL, NSRect))objc_msgSend)
+
7826 (NSAlloc((id)objc_getClass("NSView")), sel_registerName("initWithFrame:"),
+
7827 contentRect);
+
7828 }
+
7829
+
7830 void* contentView = NSWindow_contentView((id)win->src.window);
+
7831 objc_msgSend_void_bool(contentView, sel_registerName("setWantsLayer:"), true);
+
7832
+
7833 objc_msgSend_void_id((id)win->src.window, sel_registerName("setContentView:"), win->src.view);
+
7834
+
7835 #ifdef RGFW_OPENGL
+
7836 if ((flags & RGFW_windowNoInitAPI) == 0)
+
7837 objc_msgSend_void(win->src.ctx, sel_registerName("makeCurrentContext"));
+
7838 #endif
7839
-
7840 objc_msgSend_void_id((id)win->src.window, sel_registerName("setBackgroundColor:"),
-
7841 NSColor_colorWithSRGB(0, 0, 0, 0));
-
7842 }
-
7843
-
7844 #ifndef RGFW_NO_MONITOR
-
7845 if (flags & RGFW_windowScaleToMonitor)
- -
7847 #endif
+
7840 if (flags & RGFW_windowTransparent) {
+
7841 #ifdef RGFW_OPENGL
+
7842 if ((flags & RGFW_windowNoInitAPI) == 0) {
+
7843 i32 opacity = 0;
+
7844 #define NSOpenGLCPSurfaceOpacity 236
+
7845 NSOpenGLContext_setValues((id)win->src.ctx, &opacity, NSOpenGLCPSurfaceOpacity);
+
7846 }
+
7847 #endif
7848
-
7849 if (flags & RGFW_windowCenter) {
-
7850 RGFW_area screenR = RGFW_getScreenSize();
-
7851 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
-
7852 }
-
7853
-
7854 if (flags & RGFW_windowHideMouse)
-
7855 RGFW_window_showMouse(win, 0);
-
7856
-
7857 if (flags & RGFW_windowCocoaCHDirToRes)
-
7858 NSMoveToResourceDir();
+
7849 objc_msgSend_void_bool(win->src.window, sel_registerName("setOpaque:"), false);
+
7850
+
7851 objc_msgSend_void_id((id)win->src.window, sel_registerName("setBackgroundColor:"),
+
7852 NSColor_colorWithSRGB(0, 0, 0, 0));
+
7853 }
+
7854
+
7855 #ifndef RGFW_NO_MONITOR
+
7856 if (flags & RGFW_windowScaleToMonitor)
+ +
7858 #endif
7859
-
7860 Class delegateClass = objc_allocateClassPair(objc_getClass("NSObject"), "WindowDelegate", 0);
-
7861
-
7862 class_addIvar(
-
7863 delegateClass, "RGFW_window",
-
7864 sizeof(RGFW_window*), rint(log2(sizeof(RGFW_window*))),
-
7865 "L"
-
7866 );
+
7860 if (flags & RGFW_windowCenter) {
+
7861 RGFW_area screenR = RGFW_getScreenSize();
+
7862 RGFW_window_move(win, RGFW_POINT((screenR.w - win->r.w) / 2, (screenR.h - win->r.h) / 2));
+
7863 }
+
7864
+
7865 if (flags & RGFW_windowHideMouse)
+
7866 RGFW_window_showMouse(win, 0);
7867
-
7868 class_addMethod(delegateClass, sel_registerName("windowWillResize:toSize:"), (IMP) RGFW__osxWindowResize, "{NSSize=ff}@:{NSSize=ff}");
-
7869 class_addMethod(delegateClass, sel_registerName("updateLayer:"), (IMP) RGFW__osxUpdateLayer, "");
-
7870 class_addMethod(delegateClass, sel_registerName("windowWillMove:"), (IMP) RGFW__osxWindowMove, "");
-
7871 class_addMethod(delegateClass, sel_registerName("windowDidMove:"), (IMP) RGFW__osxWindowMove, "");
-
7872 class_addMethod(delegateClass, sel_registerName("draggingEntered:"), (IMP)draggingEntered, "l@:@");
-
7873 class_addMethod(delegateClass, sel_registerName("draggingUpdated:"), (IMP)draggingUpdated, "l@:@");
-
7874 class_addMethod(delegateClass, sel_registerName("draggingExited:"), (IMP)RGFW__osxDraggingEnded, "v@:@");
-
7875 class_addMethod(delegateClass, sel_registerName("draggingEnded:"), (IMP)RGFW__osxDraggingEnded, "v@:@");
-
7876 class_addMethod(delegateClass, sel_registerName("prepareForDragOperation:"), (IMP)prepareForDragOperation, "B@:@");
-
7877 class_addMethod(delegateClass, sel_registerName("performDragOperation:"), (IMP)performDragOperation, "B@:@");
+
7868 if (flags & RGFW_windowCocoaCHDirToRes)
+
7869 NSMoveToResourceDir();
+
7870
+
7871 Class delegateClass = objc_allocateClassPair(objc_getClass("NSObject"), "WindowDelegate", 0);
+
7872
+
7873 class_addIvar(
+
7874 delegateClass, "RGFW_window",
+
7875 sizeof(RGFW_window*), rint(log2(sizeof(RGFW_window*))),
+
7876 "L"
+
7877 );
7878
-
7879 id delegate = objc_msgSend_id(NSAlloc(delegateClass), sel_registerName("init"));
-
7880
-
7881 object_setInstanceVariable(delegate, "RGFW_window", win);
-
7882
-
7883 objc_msgSend_void_id((id)win->src.window, sel_registerName("setDelegate:"), delegate);
-
7884
-
7885 if (flags & RGFW_windowAllowDND) {
-
7886 win->_flags |= RGFW_windowAllowDND;
-
7887
-
7888 NSPasteboardType types[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString};
-
7889 NSregisterForDraggedTypes((id)win->src.window, types, 3);
-
7890 }
+
7879 class_addMethod(delegateClass, sel_registerName("windowWillResize:toSize:"), (IMP) RGFW__osxWindowResize, "{NSSize=ff}@:{NSSize=ff}");
+
7880 class_addMethod(delegateClass, sel_registerName("updateLayer:"), (IMP) RGFW__osxUpdateLayer, "");
+
7881 class_addMethod(delegateClass, sel_registerName("windowWillMove:"), (IMP) RGFW__osxWindowMove, "");
+
7882 class_addMethod(delegateClass, sel_registerName("windowDidMove:"), (IMP) RGFW__osxWindowMove, "");
+
7883 class_addMethod(delegateClass, sel_registerName("draggingEntered:"), (IMP)draggingEntered, "l@:@");
+
7884 class_addMethod(delegateClass, sel_registerName("draggingUpdated:"), (IMP)draggingUpdated, "l@:@");
+
7885 class_addMethod(delegateClass, sel_registerName("draggingExited:"), (IMP)RGFW__osxDraggingEnded, "v@:@");
+
7886 class_addMethod(delegateClass, sel_registerName("draggingEnded:"), (IMP)RGFW__osxDraggingEnded, "v@:@");
+
7887 class_addMethod(delegateClass, sel_registerName("prepareForDragOperation:"), (IMP)prepareForDragOperation, "B@:@");
+
7888 class_addMethod(delegateClass, sel_registerName("performDragOperation:"), (IMP)performDragOperation, "B@:@");
+
7889
+
7890 id delegate = objc_msgSend_id(NSAlloc(delegateClass), sel_registerName("init"));
7891
-
7892 // Show the window
-
7893 objc_msgSend_void_bool(NSApp, sel_registerName("activateIgnoringOtherApps:"), true);
-
7894 ((id(*)(id, SEL, SEL))objc_msgSend)((id)win->src.window, sel_registerName("makeKeyAndOrderFront:"), (SEL)NULL);
-
7895 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), true);
-
7896
-
7897 if (!RGFW_loaded) {
-
7898 objc_msgSend_void(win->src.window, sel_registerName("makeMainWindow"));
-
7899
-
7900 RGFW_loaded = 1;
+
7892 object_setInstanceVariable(delegate, "RGFW_window", win);
+
7893
+
7894 objc_msgSend_void_id((id)win->src.window, sel_registerName("setDelegate:"), delegate);
+
7895
+
7896 if (flags & RGFW_windowAllowDND) {
+
7897 win->_flags |= RGFW_windowAllowDND;
+
7898
+
7899 NSPasteboardType types[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString};
+
7900 NSregisterForDraggedTypes((id)win->src.window, types, 3);
7901 }
7902
-
7903 objc_msgSend_void(win->src.window, sel_registerName("makeKeyWindow"));
-
7904
-
7905 objc_msgSend_void(NSApp, sel_registerName("finishLaunching"));
-
7906
-
7907 NSRetain(win->src.window);
-
7908 NSRetain(NSApp);
-
7909
-
7910 #ifdef RGFW_DEBUG
-
7911 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
-
7912 #endif
-
7913 return win;
-
7914}
+
7903 // Show the window
+
7904 objc_msgSend_void_bool(NSApp, sel_registerName("activateIgnoringOtherApps:"), true);
+
7905 ((id(*)(id, SEL, SEL))objc_msgSend)((id)win->src.window, sel_registerName("makeKeyAndOrderFront:"), (SEL)NULL);
+
7906 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), true);
+
7907
+
7908 if (!RGFW_loaded) {
+
7909 objc_msgSend_void(win->src.window, sel_registerName("makeMainWindow"));
+
7910
+
7911 RGFW_loaded = 1;
+
7912 }
+
7913
+
7914 objc_msgSend_void(win->src.window, sel_registerName("makeKeyWindow"));
7915
-
7916void RGFW_window_setBorder(RGFW_window* win, u8 border) {
-
7917 NSBackingStoreType storeType = NSWindowStyleMaskBorderless;
-
7918 if (!border) {
-
7919 storeType = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
-
7920 }
-
7921 if (!(win->_flags & RGFW_windowNoResize)) {
-
7922 storeType |= NSWindowStyleMaskResizable;
-
7923 }
-
7924
-
7925 ((void (*)(id, SEL, NSBackingStoreType))objc_msgSend)((id)win->src.window, sel_registerName("setStyleMask:"), storeType);
+
7916 objc_msgSend_void(NSApp, sel_registerName("finishLaunching"));
+
7917
+
7918 NSRetain(win->src.window);
+
7919 NSRetain(NSApp);
+
7920
+
7921 #ifdef RGFW_DEBUG
+
7922 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
+
7923 #endif
+
7924 return win;
+
7925}
7926
-
7927 objc_msgSend_void_bool(win->src.window, sel_registerName("setHasShadow:"), border);
-
7928}
-
7929
- -
7931 static CGDirectDisplayID display = 0;
-
7932
-
7933 if (display == 0)
-
7934 display = CGMainDisplayID();
+
7927void RGFW_window_setBorder(RGFW_window* win, u8 border) {
+
7928 NSBackingStoreType storeType = NSWindowStyleMaskBorderless;
+
7929 if (!border) {
+
7930 storeType = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
+
7931 }
+
7932 if (!(win->_flags & RGFW_windowNoResize)) {
+
7933 storeType |= NSWindowStyleMaskResizable;
+
7934 }
7935
-
7936 return RGFW_AREA(CGDisplayPixelsWide(display), CGDisplayPixelsHigh(display));
-
7937}
-
7938
- -
7940 RGFW_ASSERT(RGFW_root != NULL);
-
7941
-
7942 CGEventRef e = CGEventCreate(NULL);
-
7943 CGPoint point = CGEventGetLocation(e);
-
7944 CFRelease(e);
-
7945
-
7946 return RGFW_POINT((u32) point.x, (u32) point.y);
-
7947}
-
7948
- -
7950 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)((id)win->src.window, sel_registerName("mouseLocationOutsideOfEventStream"));
-
7951
-
7952 return RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
-
7953}
-
7954
-
7955u32 RGFW_keysPressed[10]; /*10 keys at a time*/
-
7956typedef RGFW_ENUM(u32, NSEventType) { /* various types of events */
-
7957 NSEventTypeLeftMouseDown = 1,
-
7958 NSEventTypeLeftMouseUp = 2,
-
7959 NSEventTypeRightMouseDown = 3,
-
7960 NSEventTypeRightMouseUp = 4,
-
7961 NSEventTypeMouseMoved = 5,
-
7962 NSEventTypeLeftMouseDragged = 6,
-
7963 NSEventTypeRightMouseDragged = 7,
-
7964 NSEventTypeMouseEntered = 8,
-
7965 NSEventTypeMouseExited = 9,
-
7966 NSEventTypeKeyDown = 10,
-
7967 NSEventTypeKeyUp = 11,
-
7968 NSEventTypeFlagsChanged = 12,
-
7969 NSEventTypeAppKitDefined = 13,
-
7970 NSEventTypeSystemDefined = 14,
-
7971 NSEventTypeApplicationDefined = 15,
-
7972 NSEventTypePeriodic = 16,
-
7973 NSEventTypeCursorUpdate = 17,
-
7974 NSEventTypeScrollWheel = 22,
-
7975 NSEventTypeTabletPoint = 23,
-
7976 NSEventTypeTabletProximity = 24,
-
7977 NSEventTypeOtherMouseDown = 25,
-
7978 NSEventTypeOtherMouseUp = 26,
-
7979 NSEventTypeOtherMouseDragged = 27,
-
7980 /* The following event types are available on some hardware on 10.5.2 and later */
-
7981 NSEventTypeGesture API_AVAILABLE(macos(10.5)) = 29,
-
7982 NSEventTypeMagnify API_AVAILABLE(macos(10.5)) = 30,
-
7983 NSEventTypeSwipe API_AVAILABLE(macos(10.5)) = 31,
-
7984 NSEventTypeRotate API_AVAILABLE(macos(10.5)) = 18,
-
7985 NSEventTypeBeginGesture API_AVAILABLE(macos(10.5)) = 19,
-
7986 NSEventTypeEndGesture API_AVAILABLE(macos(10.5)) = 20,
-
7987
-
7988 NSEventTypeSmartMagnify API_AVAILABLE(macos(10.8)) = 32,
-
7989 NSEventTypeQuickLook API_AVAILABLE(macos(10.8)) = 33,
-
7990
-
7991 NSEventTypePressure API_AVAILABLE(macos(10.10.3)) = 34,
-
7992 NSEventTypeDirectTouch API_AVAILABLE(macos(10.10)) = 37,
-
7993
-
7994 NSEventTypeChangeMode API_AVAILABLE(macos(10.15)) = 38,
-
7995};
-
7996
-
7997typedef RGFW_ENUM(unsigned long long, NSEventMask) { /* masks for the types of events */
-
7998 NSEventMaskLeftMouseDown = 1ULL << NSEventTypeLeftMouseDown,
-
7999 NSEventMaskLeftMouseUp = 1ULL << NSEventTypeLeftMouseUp,
-
8000 NSEventMaskRightMouseDown = 1ULL << NSEventTypeRightMouseDown,
-
8001 NSEventMaskRightMouseUp = 1ULL << NSEventTypeRightMouseUp,
-
8002 NSEventMaskMouseMoved = 1ULL << NSEventTypeMouseMoved,
-
8003 NSEventMaskLeftMouseDragged = 1ULL << NSEventTypeLeftMouseDragged,
-
8004 NSEventMaskRightMouseDragged = 1ULL << NSEventTypeRightMouseDragged,
-
8005 NSEventMaskMouseEntered = 1ULL << NSEventTypeMouseEntered,
-
8006 NSEventMaskMouseExited = 1ULL << NSEventTypeMouseExited,
-
8007 NSEventMaskKeyDown = 1ULL << NSEventTypeKeyDown,
-
8008 NSEventMaskKeyUp = 1ULL << NSEventTypeKeyUp,
-
8009 NSEventMaskFlagsChanged = 1ULL << NSEventTypeFlagsChanged,
-
8010 NSEventMaskAppKitDefined = 1ULL << NSEventTypeAppKitDefined,
-
8011 NSEventMaskSystemDefined = 1ULL << NSEventTypeSystemDefined,
-
8012 NSEventMaskApplicationDefined = 1ULL << NSEventTypeApplicationDefined,
-
8013 NSEventMaskPeriodic = 1ULL << NSEventTypePeriodic,
-
8014 NSEventMaskCursorUpdate = 1ULL << NSEventTypeCursorUpdate,
-
8015 NSEventMaskScrollWheel = 1ULL << NSEventTypeScrollWheel,
-
8016 NSEventMaskTabletPoint = 1ULL << NSEventTypeTabletPoint,
-
8017 NSEventMaskTabletProximity = 1ULL << NSEventTypeTabletProximity,
-
8018 NSEventMaskOtherMouseDown = 1ULL << NSEventTypeOtherMouseDown,
-
8019 NSEventMaskOtherMouseUp = 1ULL << NSEventTypeOtherMouseUp,
-
8020 NSEventMaskOtherMouseDragged = 1ULL << NSEventTypeOtherMouseDragged,
-
8021 /* The following event masks are available on some hardware on 10.5.2 and later */
-
8022 NSEventMaskGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeGesture,
-
8023 NSEventMaskMagnify API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeMagnify,
-
8024 NSEventMaskSwipe API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeSwipe,
-
8025 NSEventMaskRotate API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeRotate,
-
8026 NSEventMaskBeginGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeBeginGesture,
-
8027 NSEventMaskEndGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeEndGesture,
-
8028
-
8029 /* Note: You can only use these event masks on 64 bit. In other words, you cannot setup a local, nor global, event monitor for these event types on 32 bit. Also, you cannot search the event queue for them (nextEventMatchingMask:...) on 32 bit.
-
8030 */
-
8031 NSEventMaskSmartMagnify API_AVAILABLE(macos(10.8)) = 1ULL << NSEventTypeSmartMagnify,
-
8032 NSEventMaskPressure API_AVAILABLE(macos(10.10.3)) = 1ULL << NSEventTypePressure,
-
8033 NSEventMaskDirectTouch API_AVAILABLE(macos(10.12.2)) = 1ULL << NSEventTypeDirectTouch,
-
8034
-
8035 NSEventMaskChangeMode API_AVAILABLE(macos(10.15)) = 1ULL << NSEventTypeChangeMode,
-
8036
-
8037 NSEventMaskAny = ULONG_MAX,
-
8038
-
8039};
-
8040
-
8041typedef enum NSEventModifierFlags {
-
8042 NSEventModifierFlagCapsLock = 1 << 16,
-
8043 NSEventModifierFlagShift = 1 << 17,
-
8044 NSEventModifierFlagControl = 1 << 18,
-
8045 NSEventModifierFlagOption = 1 << 19,
-
8046 NSEventModifierFlagCommand = 1 << 20,
-
8047 NSEventModifierFlagNumericPad = 1 << 21
-
8048} NSEventModifierFlags;
+
7936 ((void (*)(id, SEL, NSBackingStoreType))objc_msgSend)((id)win->src.window, sel_registerName("setStyleMask:"), storeType);
+
7937
+
7938 objc_msgSend_void_bool(win->src.window, sel_registerName("setHasShadow:"), border);
+
7939}
+
7940
+ +
7942 static CGDirectDisplayID display = 0;
+
7943
+
7944 if (display == 0)
+
7945 display = CGMainDisplayID();
+
7946
+
7947 return RGFW_AREA(CGDisplayPixelsWide(display), CGDisplayPixelsHigh(display));
+
7948}
+
7949
+ +
7951 RGFW_ASSERT(RGFW_root != NULL);
+
7952
+
7953 CGEventRef e = CGEventCreate(NULL);
+
7954 CGPoint point = CGEventGetLocation(e);
+
7955 CFRelease(e);
+
7956
+
7957 return RGFW_POINT((u32) point.x, (u32) point.y);
+
7958}
+
7959
+ +
7961 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)((id)win->src.window, sel_registerName("mouseLocationOutsideOfEventStream"));
+
7962
+
7963 return RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
+
7964}
+
7965
+
7966u32 RGFW_keysPressed[10]; /*10 keys at a time*/
+
7967typedef RGFW_ENUM(u32, NSEventType) { /* various types of events */
+
7968 NSEventTypeLeftMouseDown = 1,
+
7969 NSEventTypeLeftMouseUp = 2,
+
7970 NSEventTypeRightMouseDown = 3,
+
7971 NSEventTypeRightMouseUp = 4,
+
7972 NSEventTypeMouseMoved = 5,
+
7973 NSEventTypeLeftMouseDragged = 6,
+
7974 NSEventTypeRightMouseDragged = 7,
+
7975 NSEventTypeMouseEntered = 8,
+
7976 NSEventTypeMouseExited = 9,
+
7977 NSEventTypeKeyDown = 10,
+
7978 NSEventTypeKeyUp = 11,
+
7979 NSEventTypeFlagsChanged = 12,
+
7980 NSEventTypeAppKitDefined = 13,
+
7981 NSEventTypeSystemDefined = 14,
+
7982 NSEventTypeApplicationDefined = 15,
+
7983 NSEventTypePeriodic = 16,
+
7984 NSEventTypeCursorUpdate = 17,
+
7985 NSEventTypeScrollWheel = 22,
+
7986 NSEventTypeTabletPoint = 23,
+
7987 NSEventTypeTabletProximity = 24,
+
7988 NSEventTypeOtherMouseDown = 25,
+
7989 NSEventTypeOtherMouseUp = 26,
+
7990 NSEventTypeOtherMouseDragged = 27,
+
7991 /* The following event types are available on some hardware on 10.5.2 and later */
+
7992 NSEventTypeGesture API_AVAILABLE(macos(10.5)) = 29,
+
7993 NSEventTypeMagnify API_AVAILABLE(macos(10.5)) = 30,
+
7994 NSEventTypeSwipe API_AVAILABLE(macos(10.5)) = 31,
+
7995 NSEventTypeRotate API_AVAILABLE(macos(10.5)) = 18,
+
7996 NSEventTypeBeginGesture API_AVAILABLE(macos(10.5)) = 19,
+
7997 NSEventTypeEndGesture API_AVAILABLE(macos(10.5)) = 20,
+
7998
+
7999 NSEventTypeSmartMagnify API_AVAILABLE(macos(10.8)) = 32,
+
8000 NSEventTypeQuickLook API_AVAILABLE(macos(10.8)) = 33,
+
8001
+
8002 NSEventTypePressure API_AVAILABLE(macos(10.10.3)) = 34,
+
8003 NSEventTypeDirectTouch API_AVAILABLE(macos(10.10)) = 37,
+
8004
+
8005 NSEventTypeChangeMode API_AVAILABLE(macos(10.15)) = 38,
+
8006};
+
8007
+
8008typedef RGFW_ENUM(unsigned long long, NSEventMask) { /* masks for the types of events */
+
8009 NSEventMaskLeftMouseDown = 1ULL << NSEventTypeLeftMouseDown,
+
8010 NSEventMaskLeftMouseUp = 1ULL << NSEventTypeLeftMouseUp,
+
8011 NSEventMaskRightMouseDown = 1ULL << NSEventTypeRightMouseDown,
+
8012 NSEventMaskRightMouseUp = 1ULL << NSEventTypeRightMouseUp,
+
8013 NSEventMaskMouseMoved = 1ULL << NSEventTypeMouseMoved,
+
8014 NSEventMaskLeftMouseDragged = 1ULL << NSEventTypeLeftMouseDragged,
+
8015 NSEventMaskRightMouseDragged = 1ULL << NSEventTypeRightMouseDragged,
+
8016 NSEventMaskMouseEntered = 1ULL << NSEventTypeMouseEntered,
+
8017 NSEventMaskMouseExited = 1ULL << NSEventTypeMouseExited,
+
8018 NSEventMaskKeyDown = 1ULL << NSEventTypeKeyDown,
+
8019 NSEventMaskKeyUp = 1ULL << NSEventTypeKeyUp,
+
8020 NSEventMaskFlagsChanged = 1ULL << NSEventTypeFlagsChanged,
+
8021 NSEventMaskAppKitDefined = 1ULL << NSEventTypeAppKitDefined,
+
8022 NSEventMaskSystemDefined = 1ULL << NSEventTypeSystemDefined,
+
8023 NSEventMaskApplicationDefined = 1ULL << NSEventTypeApplicationDefined,
+
8024 NSEventMaskPeriodic = 1ULL << NSEventTypePeriodic,
+
8025 NSEventMaskCursorUpdate = 1ULL << NSEventTypeCursorUpdate,
+
8026 NSEventMaskScrollWheel = 1ULL << NSEventTypeScrollWheel,
+
8027 NSEventMaskTabletPoint = 1ULL << NSEventTypeTabletPoint,
+
8028 NSEventMaskTabletProximity = 1ULL << NSEventTypeTabletProximity,
+
8029 NSEventMaskOtherMouseDown = 1ULL << NSEventTypeOtherMouseDown,
+
8030 NSEventMaskOtherMouseUp = 1ULL << NSEventTypeOtherMouseUp,
+
8031 NSEventMaskOtherMouseDragged = 1ULL << NSEventTypeOtherMouseDragged,
+
8032 /* The following event masks are available on some hardware on 10.5.2 and later */
+
8033 NSEventMaskGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeGesture,
+
8034 NSEventMaskMagnify API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeMagnify,
+
8035 NSEventMaskSwipe API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeSwipe,
+
8036 NSEventMaskRotate API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeRotate,
+
8037 NSEventMaskBeginGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeBeginGesture,
+
8038 NSEventMaskEndGesture API_AVAILABLE(macos(10.5)) = 1ULL << NSEventTypeEndGesture,
+
8039
+
8040 /* Note: You can only use these event masks on 64 bit. In other words, you cannot setup a local, nor global, event monitor for these event types on 32 bit. Also, you cannot search the event queue for them (nextEventMatchingMask:...) on 32 bit.
+
8041 */
+
8042 NSEventMaskSmartMagnify API_AVAILABLE(macos(10.8)) = 1ULL << NSEventTypeSmartMagnify,
+
8043 NSEventMaskPressure API_AVAILABLE(macos(10.10.3)) = 1ULL << NSEventTypePressure,
+
8044 NSEventMaskDirectTouch API_AVAILABLE(macos(10.12.2)) = 1ULL << NSEventTypeDirectTouch,
+
8045
+
8046 NSEventMaskChangeMode API_AVAILABLE(macos(10.15)) = 1ULL << NSEventTypeChangeMode,
+
8047
+
8048 NSEventMaskAny = ULONG_MAX,
8049
-
8050void RGFW_stopCheckEvents(void) {
-
8051 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
-
8052 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
-
8053
-
8054 id e = (id) ((id(*)(id, SEL, NSEventType, NSPoint, NSEventModifierFlags, void*, NSInteger, void**, short, NSInteger, NSInteger))objc_msgSend)
-
8055 (NSApp, sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:"),
-
8056 NSEventTypeApplicationDefined, (NSPoint){0, 0}, (NSEventModifierFlags)0, NULL, (NSInteger)0, NULL, 0, 0, 0);
-
8057
-
8058 ((void (*)(id, SEL, id, bool))objc_msgSend)
-
8059 (NSApp, sel_registerName("postEvent:atStart:"), e, 1);
+
8050};
+
8051
+
8052typedef enum NSEventModifierFlags {
+
8053 NSEventModifierFlagCapsLock = 1 << 16,
+
8054 NSEventModifierFlagShift = 1 << 17,
+
8055 NSEventModifierFlagControl = 1 << 18,
+
8056 NSEventModifierFlagOption = 1 << 19,
+
8057 NSEventModifierFlagCommand = 1 << 20,
+
8058 NSEventModifierFlagNumericPad = 1 << 21
+
8059} NSEventModifierFlags;
8060
-
8061 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8062}
-
8063
-
8064void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
-
8065 RGFW_UNUSED(win);
-
8066
-
8067 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
-
8068 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
-
8069
-
8070 void* date = (void*) ((id(*)(Class, SEL, double))objc_msgSend)
-
8071 (objc_getClass("NSDate"), sel_registerName("dateWithTimeIntervalSinceNow:"), waitMS);
-
8072
-
8073 id e = (id) ((id(*)(id, SEL, NSEventMask, void*, id, bool))objc_msgSend)
-
8074 (NSApp, sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:"),
-
8075 ULONG_MAX, date, NSString_stringWithUTF8String("kCFRunLoopDefaultMode"), true);
-
8076
+
8061void RGFW_stopCheckEvents(void) {
+
8062 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
+
8063 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
+
8064
+
8065 id e = (id) ((id(*)(id, SEL, NSEventType, NSPoint, NSEventModifierFlags, void*, NSInteger, void**, short, NSInteger, NSInteger))objc_msgSend)
+
8066 (NSApp, sel_registerName("otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:"),
+
8067 NSEventTypeApplicationDefined, (NSPoint){0, 0}, (NSEventModifierFlags)0, NULL, (NSInteger)0, NULL, 0, 0, 0);
+
8068
+
8069 ((void (*)(id, SEL, id, bool))objc_msgSend)
+
8070 (NSApp, sel_registerName("postEvent:atStart:"), e, 1);
+
8071
+
8072 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
+
8073}
+
8074
+
8075void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
+
8076 RGFW_UNUSED(win);
8077
-
8078 if (e) {
-
8079 ((void (*)(id, SEL, id, bool))objc_msgSend)
-
8080 (NSApp, sel_registerName("postEvent:atStart:"), e, 1);
-
8081 }
-
8082
-
8083 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8084}
-
8085
- -
8087 RGFW_ASSERT(win != NULL);
+
8078 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
+
8079 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
+
8080
+
8081 void* date = (void*) ((id(*)(Class, SEL, double))objc_msgSend)
+
8082 (objc_getClass("NSDate"), sel_registerName("dateWithTimeIntervalSinceNow:"), waitMS);
+
8083
+
8084 id e = (id) ((id(*)(id, SEL, NSEventMask, void*, id, bool))objc_msgSend)
+
8085 (NSApp, sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:"),
+
8086 ULONG_MAX, date, NSString_stringWithUTF8String("kCFRunLoopDefaultMode"), true);
+
8087
8088
-
8089 if (win->event.type == RGFW_quit)
-
8090 return NULL;
-
8091
-
8092 if ((win->event.type == RGFW_DND || win->event.type == RGFW_DNDInit) && win->src.dndPassed == 0) {
-
8093 win->src.dndPassed = 1;
-
8094 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8095 return &win->event;
-
8096 }
-
8097
-
8098 #ifndef RGFW_NO_IOKIT
-
8099 if (RGFW_gamepadEventQueueCount && win == RGFW_root) {
-
8100 static u8 index = 0;
-
8101
-
8102 /* check queued events */
-
8103 RGFW_gamepadEventQueueCount--;
-
8104
-
8105 RGFW_event ev = RGFW_gamepadEventQueue[index];
-
8106 win->event.type = ev.type;
-
8107 win->event.gamepad = ev.gamepad;
-
8108 win->event.button = ev.button;
-
8109 win->event.whichAxis = ev.whichAxis;
-
8110 for (size_t i = 0; i < 4; i++)
-
8111 win->event.axis[i] = ev.axis[i];
+
8089 if (e) {
+
8090 ((void (*)(id, SEL, id, bool))objc_msgSend)
+
8091 (NSApp, sel_registerName("postEvent:atStart:"), e, 1);
+
8092 }
+
8093
+
8094 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
+
8095}
+
8096
+ +
8098 RGFW_ASSERT(win != NULL);
+
8099
+
8100 if (win->event.type == RGFW_quit)
+
8101 return NULL;
+
8102
+
8103 if ((win->event.type == RGFW_DND || win->event.type == RGFW_DNDInit) && win->src.dndPassed == 0) {
+
8104 win->src.dndPassed = 1;
+
8105 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8106 return &win->event;
+
8107 }
+
8108
+
8109 #ifndef RGFW_NO_IOKIT
+
8110 if (RGFW_gamepadEventQueueCount && win == RGFW_root) {
+
8111 static u8 index = 0;
8112
-
8113 if (RGFW_gamepadEventQueueCount) index++;
-
8114 else index = 0;
+
8113 /* check queued events */
+
8114 RGFW_gamepadEventQueueCount--;
8115
-
8116 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8117 return &win->event;
-
8118 }
-
8119 #endif
-
8120
-
8121 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
-
8122 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
+
8116 RGFW_event ev = RGFW_gamepadEventQueue[index];
+
8117 win->event.type = ev.type;
+
8118 win->event.gamepad = ev.gamepad;
+
8119 win->event.button = ev.button;
+
8120 win->event.whichAxis = ev.whichAxis;
+
8121 for (size_t i = 0; i < 4; i++)
+
8122 win->event.axis[i] = ev.axis[i];
8123
-
8124 static SEL eventFunc = (SEL)NULL;
-
8125 if (eventFunc == NULL)
-
8126 eventFunc = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:");
-
8127
-
8128 if ((win->event.type == RGFW_windowMoved || win->event.type == RGFW_windowResized || win->event.type == RGFW_windowRefresh) && win->event.key != 120) {
-
8129 win->event.key = 120;
-
8130 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8131 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8132 return &win->event;
-
8133 }
+
8124 if (RGFW_gamepadEventQueueCount) index++;
+
8125 else index = 0;
+
8126
+
8127 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8128 return &win->event;
+
8129 }
+
8130 #endif
+
8131
+
8132 id eventPool = objc_msgSend_class(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc"));
+
8133 eventPool = objc_msgSend_id(eventPool, sel_registerName("init"));
8134
-
8135 void* date = NULL;
-
8136
-
8137 id e = (id) ((id(*)(id, SEL, NSEventMask, void*, id, bool))objc_msgSend)
-
8138 (NSApp, eventFunc, ULONG_MAX, date, NSString_stringWithUTF8String("kCFRunLoopDefaultMode"), true);
-
8139
-
8140 if (e == NULL) {
+
8135 static SEL eventFunc = (SEL)NULL;
+
8136 if (eventFunc == NULL)
+
8137 eventFunc = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:");
+
8138
+
8139 if ((win->event.type == RGFW_windowMoved || win->event.type == RGFW_windowResized || win->event.type == RGFW_windowRefresh) && win->event.key != 120) {
+
8140 win->event.key = 120;
8141 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8142 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
-
8143 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8144 return NULL;
-
8145 }
-
8146
-
8147 if (objc_msgSend_id(e, sel_registerName("window")) != win->src.window) {
-
8148 ((void (*)(id, SEL, id, bool))objc_msgSend)
-
8149 (NSApp, sel_registerName("postEvent:atStart:"), e, 0);
+
8142 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8143 return &win->event;
+
8144 }
+
8145
+
8146 void* date = NULL;
+
8147
+
8148 id e = (id) ((id(*)(id, SEL, NSEventMask, void*, id, bool))objc_msgSend)
+
8149 (NSApp, eventFunc, ULONG_MAX, date, NSString_stringWithUTF8String("kCFRunLoopDefaultMode"), true);
8150
-
8151 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
+
8151 if (e == NULL) {
8152 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8153 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8154 return NULL;
-
8155 }
-
8156
-
8157 if (win->event.droppedFilesCount) {
-
8158 u32 i;
-
8159 for (i = 0; i < win->event.droppedFilesCount; i++)
-
8160 win->event.droppedFiles[i][0] = '\0';
-
8161 }
-
8162
-
8163 win->event.droppedFilesCount = 0;
-
8164 win->event.type = 0;
-
8165
-
8166 switch (objc_msgSend_uint(e, sel_registerName("type"))) {
-
8167 case NSEventTypeMouseEntered: {
-
8168 win->event.type = RGFW_mouseEnter;
-
8169 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow"));
-
8170
-
8171 win->event.point = RGFW_POINT((i32) p.x, (i32) (win->r.h - p.y));
-
8172 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
-
8173 break;
-
8174 }
-
8175
-
8176 case NSEventTypeMouseExited:
-
8177 win->event.type = RGFW_mouseLeave;
-
8178 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
-
8179 break;
-
8180
-
8181 case NSEventTypeKeyDown: {
-
8182 u32 key = (u16) objc_msgSend_uint(e, sel_registerName("keyCode"));
-
8183
-
8184 u32 mappedKey = *((u32*)((char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("charactersIgnoringModifiers")))));
-
8185 if (((u8)mappedKey) == 239)
-
8186 mappedKey = 0;
-
8187
-
8188 win->event.keyChar = (u8)mappedKey;
-
8189
-
8190 win->event.key = RGFW_apiKeyToRGFW(key);
-
8191 RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current;
-
8192
-
8193 win->event.type = RGFW_keyPressed;
-
8194 win->event.repeat = RGFW_isPressed(win, win->event.key);
-
8195 RGFW_keyboard[win->event.key].current = 1;
-
8196
-
8197 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 1);
-
8198 break;
-
8199 }
+
8153 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
+
8154 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8155 return NULL;
+
8156 }
+
8157
+
8158 if (objc_msgSend_id(e, sel_registerName("window")) != win->src.window) {
+
8159 ((void (*)(id, SEL, id, bool))objc_msgSend)
+
8160 (NSApp, sel_registerName("postEvent:atStart:"), e, 0);
+
8161
+
8162 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
+
8163 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
+
8164 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8165 return NULL;
+
8166 }
+
8167
+
8168 if (win->event.droppedFilesCount) {
+
8169 u32 i;
+
8170 for (i = 0; i < win->event.droppedFilesCount; i++)
+
8171 win->event.droppedFiles[i][0] = '\0';
+
8172 }
+
8173
+
8174 win->event.droppedFilesCount = 0;
+
8175 win->event.type = 0;
+
8176
+
8177 switch (objc_msgSend_uint(e, sel_registerName("type"))) {
+
8178 case NSEventTypeMouseEntered: {
+
8179 win->event.type = RGFW_mouseEnter;
+
8180 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow"));
+
8181
+
8182 win->event.point = RGFW_POINT((i32) p.x, (i32) (win->r.h - p.y));
+
8183 RGFW_mouseNotifyCallBack(win, win->event.point, 1);
+
8184 break;
+
8185 }
+
8186
+
8187 case NSEventTypeMouseExited:
+
8188 win->event.type = RGFW_mouseLeave;
+
8189 RGFW_mouseNotifyCallBack(win, win->event.point, 0);
+
8190 break;
+
8191
+
8192 case NSEventTypeKeyDown: {
+
8193 u32 key = (u16) objc_msgSend_uint(e, sel_registerName("keyCode"));
+
8194
+
8195 u32 mappedKey = *((u32*)((char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("charactersIgnoringModifiers")))));
+
8196 if (((u8)mappedKey) == 239)
+
8197 mappedKey = 0;
+
8198
+
8199 win->event.keyChar = (u8)mappedKey;
8200
-
8201 case NSEventTypeKeyUp: {
-
8202 u32 key = (u16) objc_msgSend_uint(e, sel_registerName("keyCode"));
+
8201 win->event.key = RGFW_apiKeyToRGFW(key);
+
8202 RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current;
8203
-
8204 u32 mappedKey = *((u32*)((char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("charactersIgnoringModifiers")))));
-
8205 if (((u8)mappedKey) == 239)
-
8206 mappedKey = 0;
+
8204 win->event.type = RGFW_keyPressed;
+
8205 win->event.repeat = RGFW_isPressed(win, win->event.key);
+
8206 RGFW_keyboard[win->event.key].current = 1;
8207
-
8208 win->event.keyChar = (u8)mappedKey;
-
8209
-
8210 win->event.key = RGFW_apiKeyToRGFW(key);
+
8208 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 1);
+
8209 break;
+
8210 }
8211
-
8212 RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current;
-
8213
-
8214 win->event.type = RGFW_keyReleased;
-
8215
-
8216 RGFW_keyboard[win->event.key].current = 0;
-
8217 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 0);
-
8218 break;
-
8219 }
+
8212 case NSEventTypeKeyUp: {
+
8213 u32 key = (u16) objc_msgSend_uint(e, sel_registerName("keyCode"));
+
8214
+
8215 u32 mappedKey = *((u32*)((char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("charactersIgnoringModifiers")))));
+
8216 if (((u8)mappedKey) == 239)
+
8217 mappedKey = 0;
+
8218
+
8219 win->event.keyChar = (u8)mappedKey;
8220
-
8221 case NSEventTypeFlagsChanged: {
-
8222 u32 flags = objc_msgSend_uint(e, sel_registerName("modifierFlags"));
-
8223 RGFW_updateKeyModsPro(win, ((u32)(flags & NSEventModifierFlagCapsLock) % 255), ((flags & NSEventModifierFlagNumericPad) % 255),
-
8224 ((flags & NSEventModifierFlagControl) % 255), ((flags & NSEventModifierFlagOption) % 255),
-
8225 ((flags & NSEventModifierFlagShift) % 255), ((flags & NSEventModifierFlagCommand) % 255));
-
8226 u8 i;
-
8227 for (i = 0; i < 9; i++)
-
8228 RGFW_keyboard[i + RGFW_capsLock].prev = 0;
-
8229
-
8230 for (i = 0; i < 5; i++) {
-
8231 u32 shift = (1 << (i + 16));
-
8232 u32 key = i + RGFW_capsLock;
-
8233
-
8234 if ((flags & shift) && !RGFW_wasPressed(win, key)) {
-
8235 RGFW_keyboard[key].current = 1;
-
8236
-
8237 if (key != RGFW_capsLock)
-
8238 RGFW_keyboard[key+ 4].current = 1;
-
8239
-
8240 win->event.type = RGFW_keyPressed;
-
8241 win->event.key = key;
-
8242 break;
-
8243 }
+
8221 win->event.key = RGFW_apiKeyToRGFW(key);
+
8222
+
8223 RGFW_keyboard[win->event.key].prev = RGFW_keyboard[win->event.key].current;
+
8224
+
8225 win->event.type = RGFW_keyReleased;
+
8226
+
8227 RGFW_keyboard[win->event.key].current = 0;
+
8228 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, 0);
+
8229 break;
+
8230 }
+
8231
+
8232 case NSEventTypeFlagsChanged: {
+
8233 u32 flags = objc_msgSend_uint(e, sel_registerName("modifierFlags"));
+
8234 RGFW_updateKeyModsPro(win, ((u32)(flags & NSEventModifierFlagCapsLock) % 255), ((flags & NSEventModifierFlagNumericPad) % 255),
+
8235 ((flags & NSEventModifierFlagControl) % 255), ((flags & NSEventModifierFlagOption) % 255),
+
8236 ((flags & NSEventModifierFlagShift) % 255), ((flags & NSEventModifierFlagCommand) % 255));
+
8237 u8 i;
+
8238 for (i = 0; i < 9; i++)
+
8239 RGFW_keyboard[i + RGFW_capsLock].prev = 0;
+
8240
+
8241 for (i = 0; i < 5; i++) {
+
8242 u32 shift = (1 << (i + 16));
+
8243 u32 key = i + RGFW_capsLock;
8244
-
8245 if (!(flags & shift) && RGFW_wasPressed(win, key)) {
-
8246 RGFW_keyboard[key].current = 0;
+
8245 if ((flags & shift) && !RGFW_wasPressed(win, key)) {
+
8246 RGFW_keyboard[key].current = 1;
8247
8248 if (key != RGFW_capsLock)
-
8249 RGFW_keyboard[key + 4].current = 0;
+
8249 RGFW_keyboard[key+ 4].current = 1;
8250
-
8251 win->event.type = RGFW_keyReleased;
+
8251 win->event.type = RGFW_keyPressed;
8252 win->event.key = key;
8253 break;
8254 }
-
8255 }
-
8256
-
8257 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, win->event.type == RGFW_keyPressed);
+
8255
+
8256 if (!(flags & shift) && RGFW_wasPressed(win, key)) {
+
8257 RGFW_keyboard[key].current = 0;
8258
-
8259 break;
-
8260 }
-
8261 case NSEventTypeLeftMouseDragged:
-
8262 case NSEventTypeOtherMouseDragged:
-
8263 case NSEventTypeRightMouseDragged:
-
8264 case NSEventTypeMouseMoved: {
-
8265 win->event.type = RGFW_mousePosChanged;
-
8266 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow"));
-
8267 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
-
8268
-
8269 if ((win->_flags & RGFW_HOLD_MOUSE)) {
-
8270 p.x = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaX"));
-
8271 p.y = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY"));
-
8272
-
8273 win->event.point = RGFW_POINT((i32)p.x, (i32)p.y);
-
8274 }
-
8275
-
8276 RGFW_mousePosCallback(win, win->event.point);
-
8277 break;
-
8278 }
-
8279 case NSEventTypeLeftMouseDown:
-
8280 win->event.button = RGFW_mouseLeft;
-
8281 win->event.type = RGFW_mouseButtonPressed;
-
8282 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8283 RGFW_mouseButtons[win->event.button].current = 1;
-
8284 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
8285 break;
+
8259 if (key != RGFW_capsLock)
+
8260 RGFW_keyboard[key + 4].current = 0;
+
8261
+
8262 win->event.type = RGFW_keyReleased;
+
8263 win->event.key = key;
+
8264 break;
+
8265 }
+
8266 }
+
8267
+
8268 RGFW_keyCallback(win, win->event.key, win->event.keyChar, win->event.keyMod, win->event.type == RGFW_keyPressed);
+
8269
+
8270 break;
+
8271 }
+
8272 case NSEventTypeLeftMouseDragged:
+
8273 case NSEventTypeOtherMouseDragged:
+
8274 case NSEventTypeRightMouseDragged:
+
8275 case NSEventTypeMouseMoved: {
+
8276 win->event.type = RGFW_mousePosChanged;
+
8277 NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow"));
+
8278 win->event.point = RGFW_POINT((u32) p.x, (u32) (win->r.h - p.y));
+
8279
+
8280 if ((win->_flags & RGFW_HOLD_MOUSE)) {
+
8281 p.x = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaX"));
+
8282 p.y = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY"));
+
8283
+
8284 win->event.point = RGFW_POINT((i32)p.x, (i32)p.y);
+
8285 }
8286
-
8287 case NSEventTypeOtherMouseDown:
-
8288 win->event.button = RGFW_mouseMiddle;
-
8289 win->event.type = RGFW_mouseButtonPressed;
-
8290 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8291 RGFW_mouseButtons[win->event.button].current = 1;
-
8292 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
8293 break;
-
8294
-
8295 case NSEventTypeRightMouseDown:
-
8296 win->event.button = RGFW_mouseRight;
-
8297 win->event.type = RGFW_mouseButtonPressed;
-
8298 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8299 RGFW_mouseButtons[win->event.button].current = 1;
-
8300 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
8301 break;
-
8302
-
8303 case NSEventTypeLeftMouseUp:
-
8304 win->event.button = RGFW_mouseLeft;
-
8305 win->event.type = RGFW_mouseButtonReleased;
-
8306 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8307 RGFW_mouseButtons[win->event.button].current = 0;
-
8308 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
-
8309 break;
-
8310
-
8311 case NSEventTypeOtherMouseUp:
-
8312 win->event.button = RGFW_mouseMiddle;
-
8313 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8314 RGFW_mouseButtons[win->event.button].current = 0;
-
8315 win->event.type = RGFW_mouseButtonReleased;
-
8316 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
-
8317 break;
-
8318
-
8319 case NSEventTypeRightMouseUp:
-
8320 win->event.button = RGFW_mouseRight;
-
8321 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8322 RGFW_mouseButtons[win->event.button].current = 0;
-
8323 win->event.type = RGFW_mouseButtonReleased;
-
8324 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
-
8325 break;
-
8326
-
8327 case NSEventTypeScrollWheel: {
-
8328 double deltaY = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY"));
+
8287 RGFW_mousePosCallback(win, win->event.point);
+
8288 break;
+
8289 }
+
8290 case NSEventTypeLeftMouseDown:
+
8291 win->event.button = RGFW_mouseLeft;
+
8292 win->event.type = RGFW_mouseButtonPressed;
+
8293 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8294 RGFW_mouseButtons[win->event.button].current = 1;
+
8295 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
8296 break;
+
8297
+
8298 case NSEventTypeOtherMouseDown:
+
8299 win->event.button = RGFW_mouseMiddle;
+
8300 win->event.type = RGFW_mouseButtonPressed;
+
8301 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8302 RGFW_mouseButtons[win->event.button].current = 1;
+
8303 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
8304 break;
+
8305
+
8306 case NSEventTypeRightMouseDown:
+
8307 win->event.button = RGFW_mouseRight;
+
8308 win->event.type = RGFW_mouseButtonPressed;
+
8309 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8310 RGFW_mouseButtons[win->event.button].current = 1;
+
8311 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
8312 break;
+
8313
+
8314 case NSEventTypeLeftMouseUp:
+
8315 win->event.button = RGFW_mouseLeft;
+
8316 win->event.type = RGFW_mouseButtonReleased;
+
8317 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8318 RGFW_mouseButtons[win->event.button].current = 0;
+
8319 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
+
8320 break;
+
8321
+
8322 case NSEventTypeOtherMouseUp:
+
8323 win->event.button = RGFW_mouseMiddle;
+
8324 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8325 RGFW_mouseButtons[win->event.button].current = 0;
+
8326 win->event.type = RGFW_mouseButtonReleased;
+
8327 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
+
8328 break;
8329
-
8330 if (deltaY > 0) {
-
8331 win->event.button = RGFW_mouseScrollUp;
-
8332 }
-
8333 else if (deltaY < 0) {
-
8334 win->event.button = RGFW_mouseScrollDown;
-
8335 }
-
8336
-
8337 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
-
8338 RGFW_mouseButtons[win->event.button].current = 1;
-
8339
-
8340 win->event.scroll = deltaY;
-
8341
-
8342 win->event.type = RGFW_mouseButtonPressed;
-
8343 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
-
8344 break;
-
8345 }
-
8346
-
8347 default:
-
8348 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
-
8349 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8350 return RGFW_window_checkEvent(win);
-
8351 }
+
8330 case NSEventTypeRightMouseUp:
+
8331 win->event.button = RGFW_mouseRight;
+
8332 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8333 RGFW_mouseButtons[win->event.button].current = 0;
+
8334 win->event.type = RGFW_mouseButtonReleased;
+
8335 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 0);
+
8336 break;
+
8337
+
8338 case NSEventTypeScrollWheel: {
+
8339 double deltaY = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY"));
+
8340
+
8341 if (deltaY > 0) {
+
8342 win->event.button = RGFW_mouseScrollUp;
+
8343 }
+
8344 else if (deltaY < 0) {
+
8345 win->event.button = RGFW_mouseScrollDown;
+
8346 }
+
8347
+
8348 RGFW_mouseButtons[win->event.button].prev = RGFW_mouseButtons[win->event.button].current;
+
8349 RGFW_mouseButtons[win->event.button].current = 1;
+
8350
+
8351 win->event.scroll = deltaY;
8352
-
8353 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
-
8354 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
-
8355
-
8356 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
-
8357 return &win->event;
-
8358}
-
8359
-
8360
- -
8362 RGFW_ASSERT(win != NULL);
+
8353 win->event.type = RGFW_mouseButtonPressed;
+
8354 RGFW_mouseButtonCallback(win, win->event.button, win->event.scroll, 1);
+
8355 break;
+
8356 }
+
8357
+
8358 default:
+
8359 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
+
8360 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8361 return RGFW_window_checkEvent(win);
+
8362 }
8363
-
8364 win->r.x = v.x;
-
8365 win->r.y = v.y;
-
8366 ((void(*)(id, SEL, NSRect, bool, bool))objc_msgSend)
-
8367 ((id)win->src.window, sel_registerName("setFrame:display:animate:"), (NSRect){{win->r.x, win->r.y}, {win->r.w, win->r.h}}, true, true);
-
8368}
-
8369
- -
8371 RGFW_ASSERT(win != NULL);
-
8372
-
8373 win->r.w = a.w;
-
8374 win->r.h = a.h;
-
8375 ((void(*)(id, SEL, NSRect, bool, bool))objc_msgSend)
-
8376 ((id)win->src.window, sel_registerName("setFrame:display:animate:"), (NSRect){{win->r.x, win->r.y}, {win->r.w, win->r.h}}, true, true);
-
8377}
-
8378
- -
8380 RGFW_ASSERT(win != NULL);
-
8381
-
8382 objc_msgSend_void_SEL(win->src.window, sel_registerName("performMiniaturize:"), NULL);
-
8383}
-
8384
- -
8386 RGFW_ASSERT(win != NULL);
-
8387
-
8388 objc_msgSend_void_SEL(win->src.window, sel_registerName("deminiaturize:"), NULL);
-
8389}
-
8390
-
8391void RGFW_window_setName(RGFW_window* win, const char* name) {
-
8392 RGFW_ASSERT(win != NULL);
-
8393
-
8394 id str = NSString_stringWithUTF8String(name);
-
8395 objc_msgSend_void_id((id)win->src.window, sel_registerName("setTitle:"), str);
-
8396}
-
8397
-
8398#ifndef RGFW_NO_PASSTHROUGH
-
8399void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
-
8400 objc_msgSend_void_bool(win->src.window, sel_registerName("setIgnoresMouseEvents:"), passthrough);
-
8401}
-
8402#endif
-
8403
- -
8405 if (a.w == 0 && a.h == 0)
-
8406 return;
-
8407
-
8408 ((void (*)(id, SEL, NSSize))objc_msgSend)
-
8409 ((id)win->src.window, sel_registerName("setMinSize:"), (NSSize){a.w, a.h});
-
8410}
-
8411
- -
8413 if (a.w == 0 && a.h == 0)
-
8414 return;
-
8415
-
8416 ((void (*)(id, SEL, NSSize))objc_msgSend)
-
8417 ((id)win->src.window, sel_registerName("setMaxSize:"), (NSSize){a.w, a.h});
-
8418}
-
8419
-
8420b32 RGFW_window_setIcon(RGFW_window* win, u8* data, RGFW_area area, i32 channels) {
-
8421 RGFW_ASSERT(win != NULL);
+
8364 objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e);
+
8365 ((void(*)(id, SEL))objc_msgSend)(NSApp, sel_registerName("updateWindows"));
+
8366
+
8367 objc_msgSend_bool_void(eventPool, sel_registerName("drain"));
+
8368 return &win->event;
+
8369}
+
8370
+
8371
+ +
8373 RGFW_ASSERT(win != NULL);
+
8374
+
8375 win->r.x = v.x;
+
8376 win->r.y = v.y;
+
8377 ((void(*)(id, SEL, NSRect, bool, bool))objc_msgSend)
+
8378 ((id)win->src.window, sel_registerName("setFrame:display:animate:"), (NSRect){{win->r.x, win->r.y}, {win->r.w, win->r.h}}, true, true);
+
8379}
+
8380
+ +
8382 RGFW_ASSERT(win != NULL);
+
8383
+
8384 win->r.w = a.w;
+
8385 win->r.h = a.h;
+
8386 ((void(*)(id, SEL, NSRect, bool, bool))objc_msgSend)
+
8387 ((id)win->src.window, sel_registerName("setFrame:display:animate:"), (NSRect){{win->r.x, win->r.y}, {win->r.w, win->r.h}}, true, true);
+
8388}
+
8389
+ +
8391 RGFW_ASSERT(win != NULL);
+
8392
+
8393 objc_msgSend_void_SEL(win->src.window, sel_registerName("performMiniaturize:"), NULL);
+
8394}
+
8395
+ +
8397 RGFW_ASSERT(win != NULL);
+
8398
+
8399 objc_msgSend_void_SEL(win->src.window, sel_registerName("deminiaturize:"), NULL);
+
8400}
+
8401
+
8402void RGFW_window_setName(RGFW_window* win, const char* name) {
+
8403 RGFW_ASSERT(win != NULL);
+
8404
+
8405 id str = NSString_stringWithUTF8String(name);
+
8406 objc_msgSend_void_id((id)win->src.window, sel_registerName("setTitle:"), str);
+
8407}
+
8408
+
8409#ifndef RGFW_NO_PASSTHROUGH
+
8410void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
+
8411 objc_msgSend_void_bool(win->src.window, sel_registerName("setIgnoresMouseEvents:"), passthrough);
+
8412}
+
8413#endif
+
8414
+ +
8416 if (a.w == 0 && a.h == 0)
+
8417 return;
+
8418
+
8419 ((void (*)(id, SEL, NSSize))objc_msgSend)
+
8420 ((id)win->src.window, sel_registerName("setMinSize:"), (NSSize){a.w, a.h});
+
8421}
8422
-
8423 /* code by EimaMei */
-
8424 // Make a bitmap representation, then copy the loaded image into it.
-
8425 id representation = NSBitmapImageRep_initWithBitmapData(NULL, area.w, area.h, 8, channels, (channels == 4), false, "NSCalibratedRGBColorSpace", 1 << 1, area.w * channels, 8 * channels);
-
8426 RGFW_MEMCPY(NSBitmapImageRep_bitmapData(representation), data, area.w * area.h * channels);
-
8427
-
8428 // Add ze representation.
-
8429 id dock_image = NSImage_initWithSize((NSSize){area.w, area.h});
-
8430 NSImage_addRepresentation(dock_image, representation);
-
8431
-
8432 // Finally, set the dock image to it.
-
8433 objc_msgSend_void_id(NSApp, sel_registerName("setApplicationIconImage:"), dock_image);
-
8434 // Free the garbage.
-
8435 NSRelease(dock_image);
-
8436 NSRelease(representation);
-
8437
-
8438 return 1;
-
8439}
-
8440
-
8441id NSCursor_arrowStr(const char* str) {
-
8442 void* nclass = objc_getClass("NSCursor");
-
8443 SEL func = sel_registerName(str);
-
8444 return (id) objc_msgSend_id(nclass, func);
-
8445}
-
8446
-
8447RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
-
8448 if (icon == NULL) {
-
8449 objc_msgSend_void(NSCursor_arrowStr("arrowCursor"), sel_registerName("set"));
-
8450 return NULL;
-
8451 }
-
8452
-
8453 /* NOTE(EimaMei): Code by yours truly. */
-
8454 // Make a bitmap representation, then copy the loaded image into it.
-
8455 id representation = NSBitmapImageRep_initWithBitmapData(NULL, a.w, a.h, 8, channels, (channels == 4), false, "NSCalibratedRGBColorSpace", 1 << 1, a.w * channels, 8 * channels);
-
8456 RGFW_MEMCPY(NSBitmapImageRep_bitmapData(representation), icon, a.w * a.h * channels);
+ +
8424 if (a.w == 0 && a.h == 0)
+
8425 return;
+
8426
+
8427 ((void (*)(id, SEL, NSSize))objc_msgSend)
+
8428 ((id)win->src.window, sel_registerName("setMaxSize:"), (NSSize){a.w, a.h});
+
8429}
+
8430
+
8431b32 RGFW_window_setIcon(RGFW_window* win, u8* data, RGFW_area area, i32 channels) {
+
8432 RGFW_ASSERT(win != NULL);
+
8433
+
8434 /* code by EimaMei */
+
8435 // Make a bitmap representation, then copy the loaded image into it.
+
8436 id representation = NSBitmapImageRep_initWithBitmapData(NULL, area.w, area.h, 8, channels, (channels == 4), false, "NSCalibratedRGBColorSpace", 1 << 1, area.w * channels, 8 * channels);
+
8437 RGFW_MEMCPY(NSBitmapImageRep_bitmapData(representation), data, area.w * area.h * channels);
+
8438
+
8439 // Add ze representation.
+
8440 id dock_image = NSImage_initWithSize((NSSize){area.w, area.h});
+
8441 NSImage_addRepresentation(dock_image, representation);
+
8442
+
8443 // Finally, set the dock image to it.
+
8444 objc_msgSend_void_id(NSApp, sel_registerName("setApplicationIconImage:"), dock_image);
+
8445 // Free the garbage.
+
8446 NSRelease(dock_image);
+
8447 NSRelease(representation);
+
8448
+
8449 return 1;
+
8450}
+
8451
+
8452id NSCursor_arrowStr(const char* str) {
+
8453 void* nclass = objc_getClass("NSCursor");
+
8454 SEL func = sel_registerName(str);
+
8455 return (id) objc_msgSend_id(nclass, func);
+
8456}
8457
-
8458 // Add ze representation.
-
8459 id cursor_image = NSImage_initWithSize((NSSize){a.w, a.h});
-
8460 NSImage_addRepresentation(cursor_image, representation);
-
8461
-
8462 // Finally, set the cursor image.
-
8463 id cursor = NSCursor_initWithImage(cursor_image, (NSPoint){0.0, 0.0});
-
8464
-
8465 // Free the garbage.
-
8466 NSRelease(cursor_image);
-
8467 NSRelease(representation);
+
8458RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
+
8459 if (icon == NULL) {
+
8460 objc_msgSend_void(NSCursor_arrowStr("arrowCursor"), sel_registerName("set"));
+
8461 return NULL;
+
8462 }
+
8463
+
8464 /* NOTE(EimaMei): Code by yours truly. */
+
8465 // Make a bitmap representation, then copy the loaded image into it.
+
8466 id representation = NSBitmapImageRep_initWithBitmapData(NULL, a.w, a.h, 8, channels, (channels == 4), false, "NSCalibratedRGBColorSpace", 1 << 1, a.w * channels, 8 * channels);
+
8467 RGFW_MEMCPY(NSBitmapImageRep_bitmapData(representation), icon, a.w * a.h * channels);
8468
-
8469 return (void*)cursor;
-
8470}
-
8471
-
8472void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
-
8473 RGFW_ASSERT(win); RGFW_ASSERT(mouse);
-
8474 objc_msgSend_void((id)mouse, sel_registerName("set"));
-
8475}
-
8476
-
8477void RGFW_freeMouse(RGFW_mouse* mouse) {
-
8478 RGFW_ASSERT(mouse);
-
8479 NSRelease((id)mouse);
-
8480}
-
8481
- -
8483 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
-
8484}
-
8485
-
8486void RGFW_window_showMouse(RGFW_window* win, i8 show) {
-
8487 RGFW_UNUSED(win);
-
8488
-
8489 if (show) {
-
8490 CGDisplayShowCursor(kCGDirectMainDisplay);
-
8491 }
-
8492 else {
-
8493 CGDisplayHideCursor(kCGDirectMainDisplay);
-
8494 }
+
8469 // Add ze representation.
+
8470 id cursor_image = NSImage_initWithSize((NSSize){a.w, a.h});
+
8471 NSImage_addRepresentation(cursor_image, representation);
+
8472
+
8473 // Finally, set the cursor image.
+
8474 id cursor = NSCursor_initWithImage(cursor_image, (NSPoint){0.0, 0.0});
+
8475
+
8476 // Free the garbage.
+
8477 NSRelease(cursor_image);
+
8478 NSRelease(representation);
+
8479
+
8480 return (void*)cursor;
+
8481}
+
8482
+
8483void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) {
+
8484 RGFW_ASSERT(win); RGFW_ASSERT(mouse);
+
8485 objc_msgSend_void((id)mouse, sel_registerName("set"));
+
8486}
+
8487
+
8488void RGFW_freeMouse(RGFW_mouse* mouse) {
+
8489 RGFW_ASSERT(mouse);
+
8490 NSRelease((id)mouse);
+
8491}
+
8492
+ +
8494 return RGFW_window_setMouseStandard(win, RGFW_mouseArrow);
8495}
8496
- -
8498 if (stdMouses > ((sizeof(RGFW_mouseIconSrc)) / (sizeof(char*))))
-
8499 return 0;
-
8500
-
8501 const char* mouseStr = RGFW_mouseIconSrc[stdMouses];
-
8502 id mouse = NSCursor_arrowStr(mouseStr);
-
8503
-
8504 if (mouse == NULL)
-
8505 return 0;
-
8506
-
8507 RGFW_UNUSED(win);
-
8508 CGDisplayShowCursor(kCGDirectMainDisplay);
-
8509 objc_msgSend_void(mouse, sel_registerName("set"));
-
8510
-
8511 return 1;
-
8512}
-
8513
-
8514void RGFW_releaseCursor(RGFW_window* win) {
-
8515 RGFW_UNUSED(win);
-
8516 CGAssociateMouseAndMouseCursorPosition(1);
-
8517}
-
8518
-
8519void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
-
8520 RGFW_UNUSED(win);
+
8497void RGFW_window_showMouse(RGFW_window* win, i8 show) {
+
8498 RGFW_UNUSED(win);
+
8499
+
8500 if (show) {
+
8501 CGDisplayShowCursor(kCGDirectMainDisplay);
+
8502 }
+
8503 else {
+
8504 CGDisplayHideCursor(kCGDirectMainDisplay);
+
8505 }
+
8506}
+
8507
+ +
8509 if (stdMouses > ((sizeof(RGFW_mouseIconSrc)) / (sizeof(char*))))
+
8510 return 0;
+
8511
+
8512 const char* mouseStr = RGFW_mouseIconSrc[stdMouses];
+
8513 id mouse = NSCursor_arrowStr(mouseStr);
+
8514
+
8515 if (mouse == NULL)
+
8516 return 0;
+
8517
+
8518 RGFW_UNUSED(win);
+
8519 CGDisplayShowCursor(kCGDirectMainDisplay);
+
8520 objc_msgSend_void(mouse, sel_registerName("set"));
8521
-
8522 CGWarpMouseCursorPosition(CGPointMake(r.x + (r.w / 2), r.y + (r.h / 2)));
-
8523 CGAssociateMouseAndMouseCursorPosition(0);
-
8524}
-
8525
- -
8527 RGFW_UNUSED(win);
-
8528
-
8529 win->_lastMousePoint = RGFW_POINT(v.x - win->r.x, v.y - win->r.y);
-
8530 CGWarpMouseCursorPosition(CGPointMake(v.x, v.y));
-
8531}
+
8522 return 1;
+
8523}
+
8524
+
8525void RGFW_releaseCursor(RGFW_window* win) {
+
8526 RGFW_UNUSED(win);
+
8527 CGAssociateMouseAndMouseCursorPosition(1);
+
8528}
+
8529
+
8530void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
+
8531 RGFW_UNUSED(win);
8532
-
8533
-
8534void RGFW_window_hide(RGFW_window* win) {
-
8535 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), false);
-
8536}
-
8537
-
8538void RGFW_window_show(RGFW_window* win) {
-
8539 ((id(*)(id, SEL, SEL))objc_msgSend)((id)win->src.window, sel_registerName("makeKeyAndOrderFront:"), NULL);
-
8540 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), true);
-
8541}
-
8542
- -
8544 RGFW_ASSERT(win != NULL);
-
8545
-
8546 NSWindowStyleMask mask = (NSWindowStyleMask) objc_msgSend_uint(win->src.window, sel_registerName("styleMask"));
-
8547 return (mask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;
-
8548}
-
8549
- -
8551 RGFW_ASSERT(win != NULL);
-
8552
-
8553 bool visible = objc_msgSend_bool(win->src.window, sel_registerName("isVisible"));
-
8554 return visible == NO && !RGFW_window_isMinimized(win);
-
8555}
+
8533 CGWarpMouseCursorPosition(CGPointMake(r.x + (r.w / 2), r.y + (r.h / 2)));
+
8534 CGAssociateMouseAndMouseCursorPosition(0);
+
8535}
+
8536
+ +
8538 RGFW_UNUSED(win);
+
8539
+
8540 win->_lastMousePoint = RGFW_POINT(v.x - win->r.x, v.y - win->r.y);
+
8541 CGWarpMouseCursorPosition(CGPointMake(v.x, v.y));
+
8542}
+
8543
+
8544
+
8545void RGFW_window_hide(RGFW_window* win) {
+
8546 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), false);
+
8547}
+
8548
+
8549void RGFW_window_show(RGFW_window* win) {
+
8550 ((id(*)(id, SEL, SEL))objc_msgSend)((id)win->src.window, sel_registerName("makeKeyAndOrderFront:"), NULL);
+
8551 objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), true);
+
8552}
+
8553
+ +
8555 RGFW_ASSERT(win != NULL);
8556
- -
8558 RGFW_ASSERT(win != NULL);
-
8559
-
8560 return objc_msgSend_bool(win->src.window, sel_registerName("isMiniaturized")) == YES;
-
8561}
-
8562
- -
8564 RGFW_ASSERT(win != NULL);
-
8565
-
8566 return objc_msgSend_bool(win->src.window, sel_registerName("isZoomed"));
-
8567}
-
8568
-
8569id RGFW_getNSScreenForDisplayID(CGDirectDisplayID display) {
-
8570 Class NSScreenClass = objc_getClass("NSScreen");
-
8571
-
8572 id screens = objc_msgSend_id(NSScreenClass, sel_registerName("screens"));
+
8557 NSWindowStyleMask mask = (NSWindowStyleMask) objc_msgSend_uint(win->src.window, sel_registerName("styleMask"));
+
8558 return (mask & NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;
+
8559}
+
8560
+ +
8562 RGFW_ASSERT(win != NULL);
+
8563
+
8564 bool visible = objc_msgSend_bool(win->src.window, sel_registerName("isVisible"));
+
8565 return visible == NO && !RGFW_window_isMinimized(win);
+
8566}
+
8567
+ +
8569 RGFW_ASSERT(win != NULL);
+
8570
+
8571 return objc_msgSend_bool(win->src.window, sel_registerName("isMiniaturized")) == YES;
+
8572}
8573
-
8574 NSUInteger count = (NSUInteger)objc_msgSend_uint(screens, sel_registerName("count"));
-
8575
-
8576 for (NSUInteger i = 0; i < count; i++) {
-
8577 id screen = ((id (*)(id, SEL, int))objc_msgSend) (screens, sel_registerName("objectAtIndex:"), (int)i);
-
8578 id description = objc_msgSend_id(screen, sel_registerName("deviceDescription"));
-
8579 id screenNumberKey = NSString_stringWithUTF8String("NSScreenNumber");
-
8580 id screenNumber = objc_msgSend_id_id(description, sel_registerName("objectForKey:"), screenNumberKey);
-
8581
-
8582 if ((CGDirectDisplayID)objc_msgSend_uint(screenNumber, sel_registerName("unsignedIntValue")) == display) {
-
8583 return screen;
-
8584 }
-
8585 }
+ +
8575 RGFW_ASSERT(win != NULL);
+
8576
+
8577 return objc_msgSend_bool(win->src.window, sel_registerName("isZoomed"));
+
8578}
+
8579
+
8580id RGFW_getNSScreenForDisplayID(CGDirectDisplayID display) {
+
8581 Class NSScreenClass = objc_getClass("NSScreen");
+
8582
+
8583 id screens = objc_msgSend_id(NSScreenClass, sel_registerName("screens"));
+
8584
+
8585 NSUInteger count = (NSUInteger)objc_msgSend_uint(screens, sel_registerName("count"));
8586
-
8587 return NULL;
-
8588}
-
8589
-
8590RGFW_monitor RGFW_NSCreateMonitor(CGDirectDisplayID display, id screen) {
-
8591 RGFW_monitor monitor;
+
8587 for (NSUInteger i = 0; i < count; i++) {
+
8588 id screen = ((id (*)(id, SEL, int))objc_msgSend) (screens, sel_registerName("objectAtIndex:"), (int)i);
+
8589 id description = objc_msgSend_id(screen, sel_registerName("deviceDescription"));
+
8590 id screenNumberKey = NSString_stringWithUTF8String("NSScreenNumber");
+
8591 id screenNumber = objc_msgSend_id_id(description, sel_registerName("objectForKey:"), screenNumberKey);
8592
-
8593 const char name[] = "MacOS\0";
-
8594 RGFW_MEMCPY(monitor.name, name, 6);
-
8595
-
8596 CGRect bounds = CGDisplayBounds(display);
-
8597 monitor.rect = RGFW_RECT((int) bounds.origin.x, (int) bounds.origin.y, (int) bounds.size.width, (int) bounds.size.height);
-
8598
-
8599 CGSize screenSizeMM = CGDisplayScreenSize(display);
-
8600 monitor.physW = (float)screenSizeMM.width / 25.4f;
-
8601 monitor.physH = (float)screenSizeMM.height / 25.4f;
-
8602
-
8603 float ppi_width = (monitor.rect.w/monitor.physW);
-
8604 float ppi_height = (monitor.rect.h/monitor.physH);
-
8605
-
8606 monitor.pixelRatio = ((CGFloat (*)(id, SEL))abi_objc_msgSend_fpret) (screen, sel_registerName("backingScaleFactor"));
-
8607 float dpi = 96.0f * monitor.pixelRatio;
-
8608
-
8609 monitor.scaleX = ((i32)(((float) (ppi_width) / dpi) * 10.0f)) / 10.0f;
-
8610 monitor.scaleY = ((i32)(((float) (ppi_height) / dpi) * 10.0f)) / 10.0f;
-
8611
-
8612 #ifdef RGFW_DEBUG
-
8613 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
-
8614 #endif
-
8615
-
8616 return monitor;
-
8617}
-
8618
+
8593 if ((CGDirectDisplayID)objc_msgSend_uint(screenNumber, sel_registerName("unsignedIntValue")) == display) {
+
8594 return screen;
+
8595 }
+
8596 }
+
8597
+
8598 return NULL;
+
8599}
+
8600
+
8601RGFW_monitor RGFW_NSCreateMonitor(CGDirectDisplayID display, id screen) {
+
8602 RGFW_monitor monitor;
+
8603
+
8604 const char name[] = "MacOS\0";
+
8605 RGFW_MEMCPY(monitor.name, name, 6);
+
8606
+
8607 CGRect bounds = CGDisplayBounds(display);
+
8608 monitor.rect = RGFW_RECT((int) bounds.origin.x, (int) bounds.origin.y, (int) bounds.size.width, (int) bounds.size.height);
+
8609
+
8610 CGSize screenSizeMM = CGDisplayScreenSize(display);
+
8611 monitor.physW = (float)screenSizeMM.width / 25.4f;
+
8612 monitor.physH = (float)screenSizeMM.height / 25.4f;
+
8613
+
8614 float ppi_width = (monitor.rect.w/monitor.physW);
+
8615 float ppi_height = (monitor.rect.h/monitor.physH);
+
8616
+
8617 monitor.pixelRatio = ((CGFloat (*)(id, SEL))abi_objc_msgSend_fpret) (screen, sel_registerName("backingScaleFactor"));
+
8618 float dpi = 96.0f * monitor.pixelRatio;
8619
-
8620RGFW_monitor RGFW_monitors[7];
-
8621
- -
8623 static CGDirectDisplayID displays[7];
-
8624 u32 count;
-
8625
-
8626 if (CGGetActiveDisplayList(6, displays, &count) != kCGErrorSuccess)
-
8627 return NULL;
-
8628
-
8629 for (u32 i = 0; i < count; i++)
-
8630 RGFW_monitors[i] = RGFW_NSCreateMonitor(displays[i], RGFW_getNSScreenForDisplayID(displays[i]));
-
8631
-
8632 return RGFW_monitors;
-
8633}
-
8634
- -
8636 CGDirectDisplayID primary = CGMainDisplayID();
-
8637 return RGFW_NSCreateMonitor(primary, RGFW_getNSScreenForDisplayID(primary));
-
8638}
+
8620 monitor.scaleX = ((i32)(((float) (ppi_width) / dpi) * 10.0f)) / 10.0f;
+
8621 monitor.scaleY = ((i32)(((float) (ppi_height) / dpi) * 10.0f)) / 10.0f;
+
8622
+
8623 #ifdef RGFW_DEBUG
+
8624 printf("RGFW INFO: monitor found: scale (%s):\n rect: {%i, %i, %i, %i}\n physical size:%f %f\n scale: %f %f\n pixelRatio: %f\n", monitor.name, monitor.rect.x, monitor.rect.y, monitor.rect.w, monitor.rect.h, monitor.physW, monitor.physH, monitor.scaleX, monitor.scaleY, monitor.pixelRatio);
+
8625 #endif
+
8626
+
8627 return monitor;
+
8628}
+
8629
+
8630
+
8631RGFW_monitor RGFW_monitors[7];
+
8632
+ +
8634 static CGDirectDisplayID displays[7];
+
8635 u32 count;
+
8636
+
8637 if (CGGetActiveDisplayList(6, displays, &count) != kCGErrorSuccess)
+
8638 return NULL;
8639
- -
8641 id screen = objc_msgSend_id(win->src.window, sel_registerName("screen"));
-
8642 id description = objc_msgSend_id(screen, sel_registerName("deviceDescription"));
-
8643 id screenNumberKey = NSString_stringWithUTF8String("NSScreenNumber");
-
8644 id screenNumber = objc_msgSend_id_id(description, sel_registerName("objectForKey:"), screenNumberKey);
+
8640 for (u32 i = 0; i < count; i++)
+
8641 RGFW_monitors[i] = RGFW_NSCreateMonitor(displays[i], RGFW_getNSScreenForDisplayID(displays[i]));
+
8642
+
8643 return RGFW_monitors;
+
8644}
8645
-
8646 CGDirectDisplayID display = (CGDirectDisplayID)objc_msgSend_uint(screenNumber, sel_registerName("unsignedIntValue"));
-
8647
-
8648 return RGFW_NSCreateMonitor(display, screen);
+ +
8647 CGDirectDisplayID primary = CGMainDisplayID();
+
8648 return RGFW_NSCreateMonitor(primary, RGFW_getNSScreenForDisplayID(primary));
8649}
8650
-
8651RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
-
8652 size_t clip_len;
-
8653 char* clip = (char*)NSPasteboard_stringForType(NSPasteboard_generalPasteboard(), NSPasteboardTypeString, &clip_len);
-
8654 if (clip == NULL) return -1;
-
8655
-
8656 if (str != NULL) {
-
8657 if (strCapacity < clip_len)
-
8658 return 0;
-
8659
-
8660 RGFW_MEMCPY(str, clip, clip_len);
+ +
8652 id screen = objc_msgSend_id(win->src.window, sel_registerName("screen"));
+
8653 id description = objc_msgSend_id(screen, sel_registerName("deviceDescription"));
+
8654 id screenNumberKey = NSString_stringWithUTF8String("NSScreenNumber");
+
8655 id screenNumber = objc_msgSend_id_id(description, sel_registerName("objectForKey:"), screenNumberKey);
+
8656
+
8657 CGDirectDisplayID display = (CGDirectDisplayID)objc_msgSend_uint(screenNumber, sel_registerName("unsignedIntValue"));
+
8658
+
8659 return RGFW_NSCreateMonitor(display, screen);
+
8660}
8661
-
8662 str[clip_len] = '\0';
-
8663 }
-
8664
-
8665 return (RGFW_ssize_t)clip_len;
-
8666}
-
8667
-
8668void RGFW_writeClipboard(const char* text, u32 textLen) {
-
8669 RGFW_UNUSED(textLen);
-
8670
-
8671 NSPasteboardType array[] = { NSPasteboardTypeString, NULL };
-
8672 NSPasteBoard_declareTypes(NSPasteboard_generalPasteboard(), array, 1, NULL);
-
8673
-
8674 NSPasteBoard_setString(NSPasteboard_generalPasteboard(), text, NSPasteboardTypeString);
-
8675}
-
8676
-
8677 #ifdef RGFW_OPENGL
- -
8679 RGFW_ASSERT(win != NULL);
-
8680 objc_msgSend_void(win->src.ctx, sel_registerName("makeCurrentContext"));
-
8681 }
-
8682 #endif
-
8683
-
8684 #if !defined(RGFW_EGL)
-
8685
-
8686 void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
-
8687 RGFW_ASSERT(win != NULL);
-
8688 #if defined(RGFW_OPENGL)
-
8689
-
8690 NSOpenGLContext_setValues((id)win->src.ctx, &swapInterval, 222);
-
8691 #else
-
8692 RGFW_UNUSED(swapInterval);
-
8693 #endif
-
8694 }
-
8695
-
8696 #endif
-
8697
-
8698// Function to create a CGImageRef from an array of bytes
-
8699CGImageRef createImageFromBytes(unsigned char *buffer, int width, int height)
-
8700{
-
8701 // Define color space
-
8702 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-
8703 // Create bitmap context
-
8704 CGContextRef context = CGBitmapContextCreate(
-
8705 buffer,
-
8706 width, height,
-
8707 8,
-
8708 width * 4,
-
8709 colorSpace,
-
8710 kCGImageAlphaPremultipliedLast);
-
8711 // Create image from bitmap context
-
8712 CGImageRef image = CGBitmapContextCreateImage(context);
-
8713 // Release the color space and context
-
8714 CGColorSpaceRelease(colorSpace);
-
8715 CGContextRelease(context);
-
8716
-
8717 return image;
-
8718}
-
8719
- -
8721 RGFW_ASSERT(win != NULL);
-
8722 /* clear the window*/
-
8723
-
8724 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
-
8725#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
8726 id view = NSWindow_contentView((id)win->src.window);
-
8727 id layer = objc_msgSend_id(view, sel_registerName("layer"));
-
8728
-
8729 ((void(*)(id, SEL, NSRect))objc_msgSend)(layer,
-
8730 sel_registerName("setFrame:"),
-
8731 (NSRect){{0, 0}, {win->r.w, win->r.h}});
-
8732
-
8733 CGImageRef image = createImageFromBytes(win->buffer, win->r.w, win->r.h);
-
8734 // Get the current graphics context
-
8735 id graphicsContext = objc_msgSend_class(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext"));
-
8736 // Get the CGContext from the current NSGraphicsContext
-
8737 id cgContext = objc_msgSend_id(graphicsContext, sel_registerName("graphicsPort"));
-
8738 // Draw the image in the context
-
8739 NSRect bounds = (NSRect){{0,0}, {win->r.w, win->r.h}};
-
8740 CGContextDrawImage((void*)cgContext, *(CGRect*)&bounds, image);
-
8741 // Flush the graphics context to ensure the drawing is displayed
-
8742 objc_msgSend_id(graphicsContext, sel_registerName("flushGraphics"));
+
8662RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
+
8663 size_t clip_len;
+
8664 char* clip = (char*)NSPasteboard_stringForType(NSPasteboard_generalPasteboard(), NSPasteboardTypeString, &clip_len);
+
8665 if (clip == NULL) return -1;
+
8666
+
8667 if (str != NULL) {
+
8668 if (strCapacity < clip_len)
+
8669 return 0;
+
8670
+
8671 RGFW_MEMCPY(str, clip, clip_len);
+
8672
+
8673 str[clip_len] = '\0';
+
8674 }
+
8675
+
8676 return (RGFW_ssize_t)clip_len;
+
8677}
+
8678
+
8679void RGFW_writeClipboard(const char* text, u32 textLen) {
+
8680 RGFW_UNUSED(textLen);
+
8681
+
8682 NSPasteboardType array[] = { NSPasteboardTypeString, NULL };
+
8683 NSPasteBoard_declareTypes(NSPasteboard_generalPasteboard(), array, 1, NULL);
+
8684
+
8685 NSPasteBoard_setString(NSPasteboard_generalPasteboard(), text, NSPasteboardTypeString);
+
8686}
+
8687
+
8688 #ifdef RGFW_OPENGL
+ +
8690 RGFW_ASSERT(win != NULL);
+
8691 objc_msgSend_void(win->src.ctx, sel_registerName("makeCurrentContext"));
+
8692 }
+
8693 #endif
+
8694
+
8695 #if !defined(RGFW_EGL)
+
8696
+
8697 void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
+
8698 RGFW_ASSERT(win != NULL);
+
8699 #if defined(RGFW_OPENGL)
+
8700
+
8701 NSOpenGLContext_setValues((id)win->src.ctx, &swapInterval, 222);
+
8702 #else
+
8703 RGFW_UNUSED(swapInterval);
+
8704 #endif
+
8705 }
+
8706
+
8707 #endif
+
8708
+
8709// Function to create a CGImageRef from an array of bytes
+
8710CGImageRef createImageFromBytes(unsigned char *buffer, int width, int height)
+
8711{
+
8712 // Define color space
+
8713 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+
8714 // Create bitmap context
+
8715 CGContextRef context = CGBitmapContextCreate(
+
8716 buffer,
+
8717 width, height,
+
8718 8,
+
8719 width * 4,
+
8720 colorSpace,
+
8721 kCGImageAlphaPremultipliedLast);
+
8722 // Create image from bitmap context
+
8723 CGImageRef image = CGBitmapContextCreateImage(context);
+
8724 // Release the color space and context
+
8725 CGColorSpaceRelease(colorSpace);
+
8726 CGContextRelease(context);
+
8727
+
8728 return image;
+
8729}
+
8730
+ +
8732 RGFW_ASSERT(win != NULL);
+
8733 /* clear the window*/
+
8734
+
8735 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
+
8736#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
8737 id view = NSWindow_contentView((id)win->src.window);
+
8738 id layer = objc_msgSend_id(view, sel_registerName("layer"));
+
8739
+
8740 ((void(*)(id, SEL, NSRect))objc_msgSend)(layer,
+
8741 sel_registerName("setFrame:"),
+
8742 (NSRect){{0, 0}, {win->r.w, win->r.h}});
8743
-
8744 objc_msgSend_void_id(layer, sel_registerName("setContents:"), (id)image);
-
8745 objc_msgSend_id(layer, sel_registerName("setNeedsDisplay"));
-
8746
-
8747 CGImageRelease(image);
-
8748#endif
-
8749 }
-
8750
-
8751 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
-
8752 #ifdef RGFW_EGL
-
8753 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
-
8754 #elif defined(RGFW_OPENGL)
-
8755 objc_msgSend_void(win->src.ctx, sel_registerName("flushBuffer"));
-
8756 #endif
-
8757 }
-
8758}
-
8759
-
8760void RGFW_window_close(RGFW_window* win) {
-
8761 RGFW_ASSERT(win != NULL);
-
8762 NSRelease(win->src.view);
-
8763
-
8764 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
8765 NSRelease(win->src.bitmap);
-
8766 NSRelease(win->src.image);
-
8767 if ((win->_flags & RGFW_BUFFER_ALLOC))
-
8768 RGFW_FREE(win->buffer);
-
8769 #endif
+
8744 CGImageRef image = createImageFromBytes(win->buffer, win->r.w, win->r.h);
+
8745 // Get the current graphics context
+
8746 id graphicsContext = objc_msgSend_class(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext"));
+
8747 // Get the CGContext from the current NSGraphicsContext
+
8748 id cgContext = objc_msgSend_id(graphicsContext, sel_registerName("graphicsPort"));
+
8749 // Draw the image in the context
+
8750 NSRect bounds = (NSRect){{0,0}, {win->r.w, win->r.h}};
+
8751 CGContextDrawImage((void*)cgContext, *(CGRect*)&bounds, image);
+
8752 // Flush the graphics context to ensure the drawing is displayed
+
8753 objc_msgSend_id(graphicsContext, sel_registerName("flushGraphics"));
+
8754
+
8755 objc_msgSend_void_id(layer, sel_registerName("setContents:"), (id)image);
+
8756 objc_msgSend_id(layer, sel_registerName("setNeedsDisplay"));
+
8757
+
8758 CGImageRelease(image);
+
8759#endif
+
8760 }
+
8761
+
8762 if (!(win->_flags & RGFW_NO_GPU_RENDER)) {
+
8763 #ifdef RGFW_EGL
+
8764 eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface);
+
8765 #elif defined(RGFW_OPENGL)
+
8766 objc_msgSend_void(win->src.ctx, sel_registerName("flushBuffer"));
+
8767 #endif
+
8768 }
+
8769}
8770
-
8771 RGFW_clipboard_switch(NULL);
-
8772
-
8773 if ((win->_flags & RGFW_WINDOW_ALLOC))
-
8774 RGFW_FREE(win);
-
8775}
-
8776
-
8777u64 RGFW_getTimeNS(void) {
-
8778 static mach_timebase_info_data_t timebase_info;
-
8779 if (timebase_info.denom == 0) {
-
8780 mach_timebase_info(&timebase_info);
-
8781 }
-
8782 return mach_absolute_time() * timebase_info.numer / timebase_info.denom;
-
8783}
-
8784
-
8785u64 RGFW_getTime(void) {
-
8786 static mach_timebase_info_data_t timebase_info;
-
8787 if (timebase_info.denom == 0) {
-
8788 mach_timebase_info(&timebase_info);
-
8789 }
-
8790 return (double) mach_absolute_time() * (double) timebase_info.numer / ((double) timebase_info.denom * 1e9);
-
8791}
-
8792#endif /* RGFW_MACOS */
-
8793
-
8794/*
-
8795 End of MaOS defines
-
8796*/
-
8797
-
8798/*
-
8799 WEBASM defines
-
8800*/
-
8801
-
8802#ifdef RGFW_WEBASM
-
8803RGFW_event RGFW_events[20];
-
8804size_t RGFW_eventLen = 0;
-
8805
-
8806EM_BOOL Emscripten_on_resize(int eventType, const EmscriptenUiEvent* e, void* userData) {
-
8807 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8771void RGFW_window_close(RGFW_window* win) {
+
8772 RGFW_ASSERT(win != NULL);
+
8773 NSRelease(win->src.view);
+
8774
+
8775 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
8776 NSRelease(win->src.bitmap);
+
8777 NSRelease(win->src.image);
+
8778 if ((win->_flags & RGFW_BUFFER_ALLOC))
+
8779 RGFW_FREE(win->buffer);
+
8780 #endif
+
8781
+
8782 RGFW_clipboard_switch(NULL);
+
8783
+
8784 if ((win->_flags & RGFW_WINDOW_ALLOC))
+
8785 RGFW_FREE(win);
+
8786}
+
8787
+
8788u64 RGFW_getTimeNS(void) {
+
8789 static mach_timebase_info_data_t timebase_info;
+
8790 if (timebase_info.denom == 0) {
+
8791 mach_timebase_info(&timebase_info);
+
8792 }
+
8793 return mach_absolute_time() * timebase_info.numer / timebase_info.denom;
+
8794}
+
8795
+
8796u64 RGFW_getTime(void) {
+
8797 static mach_timebase_info_data_t timebase_info;
+
8798 if (timebase_info.denom == 0) {
+
8799 mach_timebase_info(&timebase_info);
+
8800 }
+
8801 return (double) mach_absolute_time() * (double) timebase_info.numer / ((double) timebase_info.denom * 1e9);
+
8802}
+
8803#endif /* RGFW_MACOS */
+
8804
+
8805/*
+
8806 End of MaOS defines
+
8807*/
8808
-
8809 RGFW_events[RGFW_eventLen].type = RGFW_windowResized;
-
8810 RGFW_eventLen++;
-
8811
-
8812 RGFW_windowResizeCallback(RGFW_root, RGFW_RECT(0, 0, e->windowInnerWidth, e->windowInnerHeight));
-
8813 return EM_TRUE;
-
8814}
-
8815
-
8816EM_BOOL Emscripten_on_fullscreenchange(int eventType, const EmscriptenFullscreenChangeEvent* e, void* userData) {
-
8817 static u8 fullscreen = RGFW_FALSE;
-
8818 static RGFW_rect ogRect;
+
8809/*
+
8810 WEBASM defines
+
8811*/
+
8812
+
8813#ifdef RGFW_WEBASM
+
8814RGFW_event RGFW_events[20];
+
8815size_t RGFW_eventLen = 0;
+
8816
+
8817EM_BOOL Emscripten_on_resize(int eventType, const EmscriptenUiEvent* e, void* userData) {
+
8818 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
8819
-
8820 if (fullscreen == RGFW_FALSE) {
-
8821 ogRect = RGFW_root->r;
-
8822 }
-
8823
-
8824 fullscreen = !fullscreen;
-
8825
-
8826 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
-
8827
-
8828 RGFW_events[RGFW_eventLen].type = RGFW_windowResized;
-
8829 RGFW_eventLen++;
+
8820 RGFW_events[RGFW_eventLen].type = RGFW_windowResized;
+
8821 RGFW_eventLen++;
+
8822
+
8823 RGFW_windowResizeCallback(RGFW_root, RGFW_RECT(0, 0, e->windowInnerWidth, e->windowInnerHeight));
+
8824 return EM_TRUE;
+
8825}
+
8826
+
8827EM_BOOL Emscripten_on_fullscreenchange(int eventType, const EmscriptenFullscreenChangeEvent* e, void* userData) {
+
8828 static u8 fullscreen = RGFW_FALSE;
+
8829 static RGFW_rect ogRect;
8830
-
8831 RGFW_root->r = RGFW_RECT(0, 0, e->screenWidth, e->screenHeight);
-
8832
-
8833 EM_ASM("Module.canvas.focus();");
+
8831 if (fullscreen == RGFW_FALSE) {
+
8832 ogRect = RGFW_root->r;
+
8833 }
8834
-
8835 if (fullscreen == RGFW_FALSE) {
-
8836 RGFW_root->r = RGFW_RECT(0, 0, ogRect.w, ogRect.h);
-
8837 // emscripten_request_fullscreen("#canvas", 0);
-
8838 } else {
-
8839 #if __EMSCRIPTEN_major__ >= 1 && __EMSCRIPTEN_minor__ >= 29 && __EMSCRIPTEN_tiny__ >= 0
-
8840 EmscriptenFullscreenStrategy FSStrat = {0};
-
8841 FSStrat.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;//EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;// : EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
-
8842 FSStrat.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
-
8843 FSStrat.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
-
8844 emscripten_request_fullscreen_strategy("#canvas", 1, &FSStrat);
-
8845 #else
-
8846 emscripten_request_fullscreen("#canvas", 1);
-
8847 #endif
-
8848 }
-
8849
-
8850 emscripten_set_canvas_element_size("#canvas", RGFW_root->r.w, RGFW_root->r.h);
-
8851
-
8852 RGFW_windowResizeCallback(RGFW_root, RGFW_root->r);
-
8853 return EM_TRUE;
-
8854}
-
8855
-
8856
-
8857
-
8858EM_BOOL Emscripten_on_focusin(int eventType, const EmscriptenFocusEvent* e, void* userData) {
-
8859 RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e);
+
8835 fullscreen = !fullscreen;
+
8836
+
8837 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8838
+
8839 RGFW_events[RGFW_eventLen].type = RGFW_windowResized;
+
8840 RGFW_eventLen++;
+
8841
+
8842 RGFW_root->r = RGFW_RECT(0, 0, e->screenWidth, e->screenHeight);
+
8843
+
8844 EM_ASM("Module.canvas.focus();");
+
8845
+
8846 if (fullscreen == RGFW_FALSE) {
+
8847 RGFW_root->r = RGFW_RECT(0, 0, ogRect.w, ogRect.h);
+
8848 // emscripten_request_fullscreen("#canvas", 0);
+
8849 } else {
+
8850 #if __EMSCRIPTEN_major__ >= 1 && __EMSCRIPTEN_minor__ >= 29 && __EMSCRIPTEN_tiny__ >= 0
+
8851 EmscriptenFullscreenStrategy FSStrat = {0};
+
8852 FSStrat.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;//EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;// : EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
+
8853 FSStrat.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
+
8854 FSStrat.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+
8855 emscripten_request_fullscreen_strategy("#canvas", 1, &FSStrat);
+
8856 #else
+
8857 emscripten_request_fullscreen("#canvas", 1);
+
8858 #endif
+
8859 }
8860
-
8861 RGFW_events[RGFW_eventLen].type = RGFW_focusIn;
-
8862 RGFW_eventLen++;
-
8863
-
8864 RGFW_root->event.inFocus = 1;
-
8865 RGFW_focusCallback(RGFW_root, 1);
-
8866 return EM_TRUE;
-
8867}
+
8861 emscripten_set_canvas_element_size("#canvas", RGFW_root->r.w, RGFW_root->r.h);
+
8862
+
8863 RGFW_windowResizeCallback(RGFW_root, RGFW_root->r);
+
8864 return EM_TRUE;
+
8865}
+
8866
+
8867
8868
-
8869EM_BOOL Emscripten_on_focusout(int eventType, const EmscriptenFocusEvent* e, void* userData) {
+
8869EM_BOOL Emscripten_on_focusin(int eventType, const EmscriptenFocusEvent* e, void* userData) {
8870 RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e);
8871
-
8872 RGFW_events[RGFW_eventLen].type = RGFW_focusOut;
+
8872 RGFW_events[RGFW_eventLen].type = RGFW_focusIn;
8873 RGFW_eventLen++;
8874
-
8875 RGFW_root->event.inFocus = 0;
-
8876 RGFW_focusCallback(RGFW_root, 0);
+
8875 RGFW_root->event.inFocus = 1;
+
8876 RGFW_focusCallback(RGFW_root, 1);
8877 return EM_TRUE;
8878}
8879
-
8880EM_BOOL Emscripten_on_mousemove(int eventType, const EmscriptenMouseEvent* e, void* userData) {
-
8881 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8880EM_BOOL Emscripten_on_focusout(int eventType, const EmscriptenFocusEvent* e, void* userData) {
+
8881 RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e);
8882
-
8883 RGFW_events[RGFW_eventLen].type = RGFW_mousePosChanged;
-
8884
-
8885 if ((RGFW_root->_flags & RGFW_HOLD_MOUSE)) {
-
8886 RGFW_point p = RGFW_POINT(e->movementX, e->movementY);
-
8887 RGFW_events[RGFW_eventLen].point = p;
-
8888 }
-
8889 else
-
8890 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
-
8891 RGFW_eventLen++;
-
8892
-
8893 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
-
8894 return EM_TRUE;
-
8895}
-
8896
-
8897EM_BOOL Emscripten_on_mousedown(int eventType, const EmscriptenMouseEvent* e, void* userData) {
-
8898 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
-
8899
-
8900 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
-
8901 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
-
8902 RGFW_events[RGFW_eventLen].button = e->button + 1;
-
8903 RGFW_events[RGFW_eventLen].scroll = 0;
-
8904
-
8905 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
-
8906 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
+
8883 RGFW_events[RGFW_eventLen].type = RGFW_focusOut;
+
8884 RGFW_eventLen++;
+
8885
+
8886 RGFW_root->event.inFocus = 0;
+
8887 RGFW_focusCallback(RGFW_root, 0);
+
8888 return EM_TRUE;
+
8889}
+
8890
+
8891EM_BOOL Emscripten_on_mousemove(int eventType, const EmscriptenMouseEvent* e, void* userData) {
+
8892 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8893
+
8894 RGFW_events[RGFW_eventLen].type = RGFW_mousePosChanged;
+
8895
+
8896 if ((RGFW_root->_flags & RGFW_HOLD_MOUSE)) {
+
8897 RGFW_point p = RGFW_POINT(e->movementX, e->movementY);
+
8898 RGFW_events[RGFW_eventLen].point = p;
+
8899 }
+
8900 else
+
8901 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
+
8902 RGFW_eventLen++;
+
8903
+
8904 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
+
8905 return EM_TRUE;
+
8906}
8907
-
8908 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
-
8909 RGFW_eventLen++;
+
8908EM_BOOL Emscripten_on_mousedown(int eventType, const EmscriptenMouseEvent* e, void* userData) {
+
8909 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
8910
-
8911 return EM_TRUE;
-
8912}
-
8913
-
8914EM_BOOL Emscripten_on_mouseup(int eventType, const EmscriptenMouseEvent* e, void* userData) {
-
8915 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
-
8916
-
8917 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonReleased;
-
8918 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
-
8919 RGFW_events[RGFW_eventLen].button = e->button + 1;
-
8920 RGFW_events[RGFW_eventLen].scroll = 0;
+
8911 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
+
8912 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
+
8913 RGFW_events[RGFW_eventLen].button = e->button + 1;
+
8914 RGFW_events[RGFW_eventLen].scroll = 0;
+
8915
+
8916 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
+
8917 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
+
8918
+
8919 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
+
8920 RGFW_eventLen++;
8921
-
8922 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
-
8923 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 0;
+
8922 return EM_TRUE;
+
8923}
8924
-
8925 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 0);
-
8926 RGFW_eventLen++;
-
8927 return EM_TRUE;
-
8928}
-
8929
-
8930EM_BOOL Emscripten_on_wheel(int eventType, const EmscriptenWheelEvent* e, void* userData) {
-
8931 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8925EM_BOOL Emscripten_on_mouseup(int eventType, const EmscriptenMouseEvent* e, void* userData) {
+
8926 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8927
+
8928 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonReleased;
+
8929 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->targetX, e->targetY);
+
8930 RGFW_events[RGFW_eventLen].button = e->button + 1;
+
8931 RGFW_events[RGFW_eventLen].scroll = 0;
8932
-
8933 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
-
8934 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->mouse.targetX, e->mouse.targetY);
-
8935 RGFW_events[RGFW_eventLen].button = RGFW_mouseScrollUp + (e->deltaY < 0);
-
8936 RGFW_events[RGFW_eventLen].scroll = e->deltaY < 0 ? 1 : -1;
-
8937
-
8938 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
-
8939 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
+
8933 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
+
8934 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 0;
+
8935
+
8936 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 0);
+
8937 RGFW_eventLen++;
+
8938 return EM_TRUE;
+
8939}
8940
-
8941 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
-
8942 RGFW_eventLen++;
+
8941EM_BOOL Emscripten_on_wheel(int eventType, const EmscriptenWheelEvent* e, void* userData) {
+
8942 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
8943
-
8944 return EM_TRUE;
-
8945}
-
8946
-
8947EM_BOOL Emscripten_on_touchstart(int eventType, const EmscriptenTouchEvent* e, void* userData) {
-
8948 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
-
8949
-
8950 size_t i;
-
8951 for (i = 0; i < (size_t)e->numTouches; i++) {
-
8952 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
-
8953 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
-
8954 RGFW_events[RGFW_eventLen].button = 1;
-
8955 RGFW_events[RGFW_eventLen].scroll = 0;
-
8956
+
8944 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
+
8945 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->mouse.targetX, e->mouse.targetY);
+
8946 RGFW_events[RGFW_eventLen].button = RGFW_mouseScrollUp + (e->deltaY < 0);
+
8947 RGFW_events[RGFW_eventLen].scroll = e->deltaY < 0 ? 1 : -1;
+
8948
+
8949 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
+
8950 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
+
8951
+
8952 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
+
8953 RGFW_eventLen++;
+
8954
+
8955 return EM_TRUE;
+
8956}
8957
-
8958 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
-
8959 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
+
8958EM_BOOL Emscripten_on_touchstart(int eventType, const EmscriptenTouchEvent* e, void* userData) {
+
8959 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
8960
-
8961 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
-
8962
-
8963 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
-
8964 RGFW_eventLen++;
-
8965 }
-
8966
-
8967 return EM_TRUE;
-
8968}
-
8969EM_BOOL Emscripten_on_touchmove(int eventType, const EmscriptenTouchEvent* e, void* userData) {
-
8970 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8961 size_t i;
+
8962 for (i = 0; i < (size_t)e->numTouches; i++) {
+
8963 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
+
8964 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
+
8965 RGFW_events[RGFW_eventLen].button = 1;
+
8966 RGFW_events[RGFW_eventLen].scroll = 0;
+
8967
+
8968
+
8969 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
+
8970 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
8971
-
8972 size_t i;
-
8973 for (i = 0; i < (size_t)e->numTouches; i++) {
-
8974 RGFW_events[RGFW_eventLen].type = RGFW_mousePosChanged;
-
8975 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
-
8976
-
8977 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
-
8978 RGFW_eventLen++;
-
8979 }
-
8980 return EM_TRUE;
-
8981}
+
8972 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
+
8973
+
8974 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 1);
+
8975 RGFW_eventLen++;
+
8976 }
+
8977
+
8978 return EM_TRUE;
+
8979}
+
8980EM_BOOL Emscripten_on_touchmove(int eventType, const EmscriptenTouchEvent* e, void* userData) {
+
8981 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
8982
-
8983EM_BOOL Emscripten_on_touchend(int eventType, const EmscriptenTouchEvent* e, void* userData) {
-
8984 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
-
8985
-
8986 size_t i;
-
8987 for (i = 0; i < (size_t)e->numTouches; i++) {
-
8988 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonReleased;
-
8989 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
-
8990 RGFW_events[RGFW_eventLen].button = 1;
-
8991 RGFW_events[RGFW_eventLen].scroll = 0;
-
8992
-
8993 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
-
8994 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 0;
-
8995
-
8996 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 0);
-
8997 RGFW_eventLen++;
-
8998 }
-
8999 return EM_TRUE;
-
9000}
-
9001
-
9002EM_BOOL Emscripten_on_touchcancel(int eventType, const EmscriptenTouchEvent* e, void* userData) { RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e); return EM_TRUE; }
+
8983 size_t i;
+
8984 for (i = 0; i < (size_t)e->numTouches; i++) {
+
8985 RGFW_events[RGFW_eventLen].type = RGFW_mousePosChanged;
+
8986 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
+
8987
+
8988 RGFW_mousePosCallback(RGFW_root, RGFW_events[RGFW_eventLen].point);
+
8989 RGFW_eventLen++;
+
8990 }
+
8991 return EM_TRUE;
+
8992}
+
8993
+
8994EM_BOOL Emscripten_on_touchend(int eventType, const EmscriptenTouchEvent* e, void* userData) {
+
8995 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
8996
+
8997 size_t i;
+
8998 for (i = 0; i < (size_t)e->numTouches; i++) {
+
8999 RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonReleased;
+
9000 RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->touches[i].targetX, e->touches[i].targetY);
+
9001 RGFW_events[RGFW_eventLen].button = 1;
+
9002 RGFW_events[RGFW_eventLen].scroll = 0;
9003
-
9004EM_BOOL Emscripten_on_gamepad(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) {
-
9005 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
9004 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
+
9005 RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 0;
9006
-
9007 if (gamepadEvent->index >= 4)
-
9008 return 0;
-
9009
-
9010 size_t i = gamepadEvent->index;
-
9011 if (gamepadEvent->connected) {
-
9012 RGFW_MEMCPY(RGFW_gamepads_name[gamepadEvent->index], gamepadEvent->id, sizeof(RGFW_gamepads_name[gamepadEvent->index]));
-
9013 RGFW_gamepads_type[i] = RGFW_gamepadUnknown;
-
9014 if (strstr(RGFW_gamepads_name[i], "Microsoft") || strstr(RGFW_gamepads_name[i], "X-Box"))
-
9015 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
-
9016 else if (strstr(RGFW_gamepads_name[i], "PlayStation") || strstr(RGFW_gamepads_name[i], "PS3") || strstr(RGFW_gamepads_name[i], "PS4") || strstr(RGFW_gamepads_name[i], "PS5"))
-
9017 RGFW_gamepads_type[i] = RGFW_gamepadSony;
-
9018 else if (strstr(RGFW_gamepads_name[i], "Nintendo"))
-
9019 RGFW_gamepads_type[i] = RGFW_gamepadNintendo;
-
9020 else if (strstr(RGFW_gamepads_name[i], "Logitech"))
-
9021 RGFW_gamepads_type[i] = RGFW_gamepadLogitech;
-
9022
-
9023 RGFW_gamepadCount++;
-
9024 RGFW_events[RGFW_eventLen].type = RGFW_gamepadConnected;
-
9025 } else {
-
9026 RGFW_gamepadCount--;
-
9027 RGFW_events[RGFW_eventLen].type = RGFW_gamepadDisconnected;
-
9028 }
-
9029
-
9030 RGFW_events[RGFW_eventLen].gamepad = gamepadEvent->index;
-
9031 RGFW_eventLen++;
-
9032
-
9033 RGFW_gamepadCallback(RGFW_root, gamepadEvent->index, gamepadEvent->connected);
-
9034
-
9035 RGFW_gamepads[gamepadEvent->index] = gamepadEvent->connected;
-
9036
-
9037 return 1; // The event was consumed by the callback handler
-
9038}
-
9039
-
9040u32 RGFW_webasmPhysicalToRGFW(u32 hash) {
-
9041 switch(hash) { /* 0x0000 */
-
9042 case 0x67243A2DU /* Escape */: return RGFW_escape; /* 0x0001 */
-
9043 case 0x67251058U /* Digit0 */: return RGFW_0; /* 0x0002 */
-
9044 case 0x67251059U /* Digit1 */: return RGFW_1; /* 0x0003 */
-
9045 case 0x6725105AU /* Digit2 */: return RGFW_2; /* 0x0004 */
-
9046 case 0x6725105BU /* Digit3 */: return RGFW_3; /* 0x0005 */
-
9047 case 0x6725105CU /* Digit4 */: return RGFW_4; /* 0x0006 */
-
9048 case 0x6725105DU /* Digit5 */: return RGFW_5; /* 0x0007 */
-
9049 case 0x6725105EU /* Digit6 */: return RGFW_6; /* 0x0008 */
-
9050 case 0x6725105FU /* Digit7 */: return RGFW_7; /* 0x0009 */
-
9051 case 0x67251050U /* Digit8 */: return RGFW_8; /* 0x000A */
-
9052 case 0x67251051U /* Digit9 */: return RGFW_9; /* 0x000B */
-
9053 case 0x92E14DD3U /* Minus */: return RGFW_minus; /* 0x000C */
-
9054 case 0x92E1FBACU /* Equal */: return RGFW_equals; /* 0x000D */
-
9055 case 0x36BF1CB5U /* Backspace */: return RGFW_backSpace; /* 0x000E */
-
9056 case 0x7B8E51E2U /* Tab */: return RGFW_tab; /* 0x000F */
-
9057 case 0x2C595B51U /* KeyQ */: return RGFW_q; /* 0x0010 */
-
9058 case 0x2C595B57U /* KeyW */: return RGFW_w; /* 0x0011 */
-
9059 case 0x2C595B45U /* KeyE */: return RGFW_e; /* 0x0012 */
-
9060 case 0x2C595B52U /* KeyR */: return RGFW_r; /* 0x0013 */
-
9061 case 0x2C595B54U /* KeyT */: return RGFW_t; /* 0x0014 */
-
9062 case 0x2C595B59U /* KeyY */: return RGFW_y; /* 0x0015 */
-
9063 case 0x2C595B55U /* KeyU */: return RGFW_u; /* 0x0016 */
-
9064 case 0x2C595B4FU /* KeyO */: return RGFW_o; /* 0x0018 */
-
9065 case 0x2C595B50U /* KeyP */: return RGFW_p; /* 0x0019 */
-
9066 case 0x45D8158CU /* BracketLeft */: return RGFW_closeBracket; /* 0x001A */
-
9067 case 0xDEEABF7CU /* BracketRight */: return RGFW_bracket; /* 0x001B */
-
9068 case 0x92E1C5D2U /* Enter */: return RGFW_return; /* 0x001C */
-
9069 case 0xE058958CU /* ControlLeft */: return RGFW_controlL; /* 0x001D */
-
9070 case 0x2C595B41U /* KeyA */: return RGFW_a; /* 0x001E */
-
9071 case 0x2C595B53U /* KeyS */: return RGFW_s; /* 0x001F */
-
9072 case 0x2C595B44U /* KeyD */: return RGFW_d; /* 0x0020 */
-
9073 case 0x2C595B46U /* KeyF */: return RGFW_f; /* 0x0021 */
-
9074 case 0x2C595B47U /* KeyG */: return RGFW_g; /* 0x0022 */
-
9075 case 0x2C595B48U /* KeyH */: return RGFW_h; /* 0x0023 */
-
9076 case 0x2C595B4AU /* KeyJ */: return RGFW_j; /* 0x0024 */
-
9077 case 0x2C595B4BU /* KeyK */: return RGFW_k; /* 0x0025 */
-
9078 case 0x2C595B4CU /* KeyL */: return RGFW_l; /* 0x0026 */
-
9079 case 0x2707219EU /* Semicolon */: return RGFW_semicolon; /* 0x0027 */
-
9080 case 0x92E0B58DU /* Quote */: return RGFW_apostrophe; /* 0x0028 */
-
9081 case 0x36BF358DU /* Backquote */: return RGFW_backtick; /* 0x0029 */
-
9082 case 0x26B1958CU /* ShiftLeft */: return RGFW_shiftL; /* 0x002A */
-
9083 case 0x36BF2438U /* Backslash */: return RGFW_backSlash; /* 0x002B */
-
9084 case 0x2C595B5AU /* KeyZ */: return RGFW_z; /* 0x002C */
-
9085 case 0x2C595B58U /* KeyX */: return RGFW_x; /* 0x002D */
-
9086 case 0x2C595B43U /* KeyC */: return RGFW_c; /* 0x002E */
-
9087 case 0x2C595B56U /* KeyV */: return RGFW_v; /* 0x002F */
-
9088 case 0x2C595B42U /* KeyB */: return RGFW_b; /* 0x0030 */
-
9089 case 0x2C595B4EU /* KeyN */: return RGFW_n; /* 0x0031 */
-
9090 case 0x2C595B4DU /* KeyM */: return RGFW_m; /* 0x0032 */
-
9091 case 0x92E1A1C1U /* Comma */: return RGFW_comma; /* 0x0033 */
-
9092 case 0x672FFAD4U /* Period */: return RGFW_period; /* 0x0034 */
-
9093 case 0x92E0A438U /* Slash */: return RGFW_slash; /* 0x0035 */
-
9094 case 0xC5A6BF7CU /* ShiftRight */: return RGFW_shiftR;
-
9095 case 0x5D64DA91U /* NumpadMultiply */: return RGFW_multiply;
-
9096 case 0xC914958CU /* AltLeft */: return RGFW_altL; /* 0x0038 */
-
9097 case 0x92E09CB5U /* Space */: return RGFW_space; /* 0x0039 */
-
9098 case 0xB8FAE73BU /* CapsLock */: return RGFW_capsLock; /* 0x003A */
-
9099 case 0x7174B789U /* F1 */: return RGFW_F1; /* 0x003B */
-
9100 case 0x7174B78AU /* F2 */: return RGFW_F2; /* 0x003C */
-
9101 case 0x7174B78BU /* F3 */: return RGFW_F3; /* 0x003D */
-
9102 case 0x7174B78CU /* F4 */: return RGFW_F4; /* 0x003E */
-
9103 case 0x7174B78DU /* F5 */: return RGFW_F5; /* 0x003F */
-
9104 case 0x7174B78EU /* F6 */: return RGFW_F6; /* 0x0040 */
-
9105 case 0x7174B78FU /* F7 */: return RGFW_F7; /* 0x0041 */
-
9106 case 0x7174B780U /* F8 */: return RGFW_F8; /* 0x0042 */
-
9107 case 0x7174B781U /* F9 */: return RGFW_F9; /* 0x0043 */
-
9108 case 0x7B8E57B0U /* F10 */: return RGFW_F10; /* 0x0044 */
-
9109 case 0xC925FCDFU /* Numpad7 */: return RGFW_multiply; /* 0x0047 */
-
9110 case 0xC925FCD0U /* Numpad8 */: return RGFW_KP_8; /* 0x0048 */
-
9111 case 0xC925FCD1U /* Numpad9 */: return RGFW_KP_9; /* 0x0049 */
-
9112 case 0x5EA3E8A4U /* NumpadSubtract */: return RGFW_minus; /* 0x004A */
-
9113 case 0xC925FCDCU /* Numpad4 */: return RGFW_KP_4; /* 0x004B */
-
9114 case 0xC925FCDDU /* Numpad5 */: return RGFW_KP_5; /* 0x004C */
-
9115 case 0xC925FCDEU /* Numpad6 */: return RGFW_KP_6; /* 0x004D */
-
9116 case 0xC925FCD9U /* Numpad1 */: return RGFW_KP_1; /* 0x004F */
-
9117 case 0xC925FCDAU /* Numpad2 */: return RGFW_KP_2; /* 0x0050 */
-
9118 case 0xC925FCDBU /* Numpad3 */: return RGFW_KP_3; /* 0x0051 */
-
9119 case 0xC925FCD8U /* Numpad0 */: return RGFW_KP_0; /* 0x0052 */
-
9120 case 0x95852DACU /* NumpadDecimal */: return RGFW_period; /* 0x0053 */
-
9121 case 0x7B8E57B1U /* F11 */: return RGFW_F11; /* 0x0057 */
-
9122 case 0x7B8E57B2U /* F12 */: return RGFW_F12; /* 0x0058 */
-
9123 case 0x7393FBACU /* NumpadEqual */: return RGFW_KP_Return;
-
9124 case 0xB88EBF7CU /* AltRight */: return RGFW_altR; /* 0xE038 */
-
9125 case 0xC925873BU /* NumLock */: return RGFW_numLock; /* 0xE045 */
-
9126 case 0x2C595F45U /* Home */: return RGFW_home; /* 0xE047 */
-
9127 case 0xC91BB690U /* ArrowUp */: return RGFW_up; /* 0xE048 */
-
9128 case 0x672F9210U /* PageUp */: return RGFW_pageUp; /* 0xE049 */
-
9129 case 0x3799258CU /* ArrowLeft */: return RGFW_left; /* 0xE04B */
-
9130 case 0x4CE33F7CU /* ArrowRight */: return RGFW_right; /* 0xE04D */
-
9131 case 0x7B8E55DCU /* End */: return RGFW_end; /* 0xE04F */
-
9132 case 0x3799379EU /* ArrowDown */: return RGFW_down; /* 0xE050 */
-
9133 case 0xBA90179EU /* PageDown */: return RGFW_pageDown; /* 0xE051 */
-
9134 case 0x6723CB2CU /* Insert */: return RGFW_insert; /* 0xE052 */
-
9135 case 0x6725C50DU /* Delete */: return RGFW_delete; /* 0xE053 */
-
9136 case 0x6723658CU /* OSLeft */: return RGFW_superL; /* 0xE05B */
-
9137 case 0x39643F7CU /* MetaRight */: return RGFW_superR; /* 0xE05C */
-
9138 }
-
9139
-
9140 return 0;
-
9141}
-
9142
-
9143void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyEvent(char* key, char* code, b8 press) {
-
9144 const char* iCode = code;
-
9145
-
9146 u32 hash = 0;
-
9147 while(*iCode) hash = ((hash ^ 0x7E057D79U) << 3) ^ (unsigned int)*iCode++;
-
9148
-
9149 u32 physicalKey = RGFW_webasmPhysicalToRGFW(hash);
+
9007 RGFW_mouseButtonCallback(RGFW_root, RGFW_events[RGFW_eventLen].button, RGFW_events[RGFW_eventLen].scroll, 0);
+
9008 RGFW_eventLen++;
+
9009 }
+
9010 return EM_TRUE;
+
9011}
+
9012
+
9013EM_BOOL Emscripten_on_touchcancel(int eventType, const EmscriptenTouchEvent* e, void* userData) { RGFW_UNUSED(eventType); RGFW_UNUSED(userData); RGFW_UNUSED(e); return EM_TRUE; }
+
9014
+
9015EM_BOOL Emscripten_on_gamepad(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) {
+
9016 RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
+
9017
+
9018 if (gamepadEvent->index >= 4)
+
9019 return 0;
+
9020
+
9021 size_t i = gamepadEvent->index;
+
9022 if (gamepadEvent->connected) {
+
9023 RGFW_MEMCPY(RGFW_gamepads_name[gamepadEvent->index], gamepadEvent->id, sizeof(RGFW_gamepads_name[gamepadEvent->index]));
+
9024 RGFW_gamepads_type[i] = RGFW_gamepadUnknown;
+
9025 if (strstr(RGFW_gamepads_name[i], "Microsoft") || strstr(RGFW_gamepads_name[i], "X-Box"))
+
9026 RGFW_gamepads_type[i] = RGFW_gamepadMicrosoft;
+
9027 else if (strstr(RGFW_gamepads_name[i], "PlayStation") || strstr(RGFW_gamepads_name[i], "PS3") || strstr(RGFW_gamepads_name[i], "PS4") || strstr(RGFW_gamepads_name[i], "PS5"))
+
9028 RGFW_gamepads_type[i] = RGFW_gamepadSony;
+
9029 else if (strstr(RGFW_gamepads_name[i], "Nintendo"))
+
9030 RGFW_gamepads_type[i] = RGFW_gamepadNintendo;
+
9031 else if (strstr(RGFW_gamepads_name[i], "Logitech"))
+
9032 RGFW_gamepads_type[i] = RGFW_gamepadLogitech;
+
9033
+
9034 RGFW_gamepadCount++;
+
9035 RGFW_events[RGFW_eventLen].type = RGFW_gamepadConnected;
+
9036 } else {
+
9037 RGFW_gamepadCount--;
+
9038 RGFW_events[RGFW_eventLen].type = RGFW_gamepadDisconnected;
+
9039 }
+
9040
+
9041 RGFW_events[RGFW_eventLen].gamepad = gamepadEvent->index;
+
9042 RGFW_eventLen++;
+
9043
+
9044 RGFW_gamepadCallback(RGFW_root, gamepadEvent->index, gamepadEvent->connected);
+
9045
+
9046 RGFW_gamepads[gamepadEvent->index] = gamepadEvent->connected;
+
9047
+
9048 return 1; // The event was consumed by the callback handler
+
9049}
+
9050
+
9051u32 RGFW_webasmPhysicalToRGFW(u32 hash) {
+
9052 switch(hash) { /* 0x0000 */
+
9053 case 0x67243A2DU /* Escape */: return RGFW_escape; /* 0x0001 */
+
9054 case 0x67251058U /* Digit0 */: return RGFW_0; /* 0x0002 */
+
9055 case 0x67251059U /* Digit1 */: return RGFW_1; /* 0x0003 */
+
9056 case 0x6725105AU /* Digit2 */: return RGFW_2; /* 0x0004 */
+
9057 case 0x6725105BU /* Digit3 */: return RGFW_3; /* 0x0005 */
+
9058 case 0x6725105CU /* Digit4 */: return RGFW_4; /* 0x0006 */
+
9059 case 0x6725105DU /* Digit5 */: return RGFW_5; /* 0x0007 */
+
9060 case 0x6725105EU /* Digit6 */: return RGFW_6; /* 0x0008 */
+
9061 case 0x6725105FU /* Digit7 */: return RGFW_7; /* 0x0009 */
+
9062 case 0x67251050U /* Digit8 */: return RGFW_8; /* 0x000A */
+
9063 case 0x67251051U /* Digit9 */: return RGFW_9; /* 0x000B */
+
9064 case 0x92E14DD3U /* Minus */: return RGFW_minus; /* 0x000C */
+
9065 case 0x92E1FBACU /* Equal */: return RGFW_equals; /* 0x000D */
+
9066 case 0x36BF1CB5U /* Backspace */: return RGFW_backSpace; /* 0x000E */
+
9067 case 0x7B8E51E2U /* Tab */: return RGFW_tab; /* 0x000F */
+
9068 case 0x2C595B51U /* KeyQ */: return RGFW_q; /* 0x0010 */
+
9069 case 0x2C595B57U /* KeyW */: return RGFW_w; /* 0x0011 */
+
9070 case 0x2C595B45U /* KeyE */: return RGFW_e; /* 0x0012 */
+
9071 case 0x2C595B52U /* KeyR */: return RGFW_r; /* 0x0013 */
+
9072 case 0x2C595B54U /* KeyT */: return RGFW_t; /* 0x0014 */
+
9073 case 0x2C595B59U /* KeyY */: return RGFW_y; /* 0x0015 */
+
9074 case 0x2C595B55U /* KeyU */: return RGFW_u; /* 0x0016 */
+
9075 case 0x2C595B4FU /* KeyO */: return RGFW_o; /* 0x0018 */
+
9076 case 0x2C595B50U /* KeyP */: return RGFW_p; /* 0x0019 */
+
9077 case 0x45D8158CU /* BracketLeft */: return RGFW_closeBracket; /* 0x001A */
+
9078 case 0xDEEABF7CU /* BracketRight */: return RGFW_bracket; /* 0x001B */
+
9079 case 0x92E1C5D2U /* Enter */: return RGFW_return; /* 0x001C */
+
9080 case 0xE058958CU /* ControlLeft */: return RGFW_controlL; /* 0x001D */
+
9081 case 0x2C595B41U /* KeyA */: return RGFW_a; /* 0x001E */
+
9082 case 0x2C595B53U /* KeyS */: return RGFW_s; /* 0x001F */
+
9083 case 0x2C595B44U /* KeyD */: return RGFW_d; /* 0x0020 */
+
9084 case 0x2C595B46U /* KeyF */: return RGFW_f; /* 0x0021 */
+
9085 case 0x2C595B47U /* KeyG */: return RGFW_g; /* 0x0022 */
+
9086 case 0x2C595B48U /* KeyH */: return RGFW_h; /* 0x0023 */
+
9087 case 0x2C595B4AU /* KeyJ */: return RGFW_j; /* 0x0024 */
+
9088 case 0x2C595B4BU /* KeyK */: return RGFW_k; /* 0x0025 */
+
9089 case 0x2C595B4CU /* KeyL */: return RGFW_l; /* 0x0026 */
+
9090 case 0x2707219EU /* Semicolon */: return RGFW_semicolon; /* 0x0027 */
+
9091 case 0x92E0B58DU /* Quote */: return RGFW_apostrophe; /* 0x0028 */
+
9092 case 0x36BF358DU /* Backquote */: return RGFW_backtick; /* 0x0029 */
+
9093 case 0x26B1958CU /* ShiftLeft */: return RGFW_shiftL; /* 0x002A */
+
9094 case 0x36BF2438U /* Backslash */: return RGFW_backSlash; /* 0x002B */
+
9095 case 0x2C595B5AU /* KeyZ */: return RGFW_z; /* 0x002C */
+
9096 case 0x2C595B58U /* KeyX */: return RGFW_x; /* 0x002D */
+
9097 case 0x2C595B43U /* KeyC */: return RGFW_c; /* 0x002E */
+
9098 case 0x2C595B56U /* KeyV */: return RGFW_v; /* 0x002F */
+
9099 case 0x2C595B42U /* KeyB */: return RGFW_b; /* 0x0030 */
+
9100 case 0x2C595B4EU /* KeyN */: return RGFW_n; /* 0x0031 */
+
9101 case 0x2C595B4DU /* KeyM */: return RGFW_m; /* 0x0032 */
+
9102 case 0x92E1A1C1U /* Comma */: return RGFW_comma; /* 0x0033 */
+
9103 case 0x672FFAD4U /* Period */: return RGFW_period; /* 0x0034 */
+
9104 case 0x92E0A438U /* Slash */: return RGFW_slash; /* 0x0035 */
+
9105 case 0xC5A6BF7CU /* ShiftRight */: return RGFW_shiftR;
+
9106 case 0x5D64DA91U /* NumpadMultiply */: return RGFW_multiply;
+
9107 case 0xC914958CU /* AltLeft */: return RGFW_altL; /* 0x0038 */
+
9108 case 0x92E09CB5U /* Space */: return RGFW_space; /* 0x0039 */
+
9109 case 0xB8FAE73BU /* CapsLock */: return RGFW_capsLock; /* 0x003A */
+
9110 case 0x7174B789U /* F1 */: return RGFW_F1; /* 0x003B */
+
9111 case 0x7174B78AU /* F2 */: return RGFW_F2; /* 0x003C */
+
9112 case 0x7174B78BU /* F3 */: return RGFW_F3; /* 0x003D */
+
9113 case 0x7174B78CU /* F4 */: return RGFW_F4; /* 0x003E */
+
9114 case 0x7174B78DU /* F5 */: return RGFW_F5; /* 0x003F */
+
9115 case 0x7174B78EU /* F6 */: return RGFW_F6; /* 0x0040 */
+
9116 case 0x7174B78FU /* F7 */: return RGFW_F7; /* 0x0041 */
+
9117 case 0x7174B780U /* F8 */: return RGFW_F8; /* 0x0042 */
+
9118 case 0x7174B781U /* F9 */: return RGFW_F9; /* 0x0043 */
+
9119 case 0x7B8E57B0U /* F10 */: return RGFW_F10; /* 0x0044 */
+
9120 case 0xC925FCDFU /* Numpad7 */: return RGFW_multiply; /* 0x0047 */
+
9121 case 0xC925FCD0U /* Numpad8 */: return RGFW_KP_8; /* 0x0048 */
+
9122 case 0xC925FCD1U /* Numpad9 */: return RGFW_KP_9; /* 0x0049 */
+
9123 case 0x5EA3E8A4U /* NumpadSubtract */: return RGFW_minus; /* 0x004A */
+
9124 case 0xC925FCDCU /* Numpad4 */: return RGFW_KP_4; /* 0x004B */
+
9125 case 0xC925FCDDU /* Numpad5 */: return RGFW_KP_5; /* 0x004C */
+
9126 case 0xC925FCDEU /* Numpad6 */: return RGFW_KP_6; /* 0x004D */
+
9127 case 0xC925FCD9U /* Numpad1 */: return RGFW_KP_1; /* 0x004F */
+
9128 case 0xC925FCDAU /* Numpad2 */: return RGFW_KP_2; /* 0x0050 */
+
9129 case 0xC925FCDBU /* Numpad3 */: return RGFW_KP_3; /* 0x0051 */
+
9130 case 0xC925FCD8U /* Numpad0 */: return RGFW_KP_0; /* 0x0052 */
+
9131 case 0x95852DACU /* NumpadDecimal */: return RGFW_period; /* 0x0053 */
+
9132 case 0x7B8E57B1U /* F11 */: return RGFW_F11; /* 0x0057 */
+
9133 case 0x7B8E57B2U /* F12 */: return RGFW_F12; /* 0x0058 */
+
9134 case 0x7393FBACU /* NumpadEqual */: return RGFW_KP_Return;
+
9135 case 0xB88EBF7CU /* AltRight */: return RGFW_altR; /* 0xE038 */
+
9136 case 0xC925873BU /* NumLock */: return RGFW_numLock; /* 0xE045 */
+
9137 case 0x2C595F45U /* Home */: return RGFW_home; /* 0xE047 */
+
9138 case 0xC91BB690U /* ArrowUp */: return RGFW_up; /* 0xE048 */
+
9139 case 0x672F9210U /* PageUp */: return RGFW_pageUp; /* 0xE049 */
+
9140 case 0x3799258CU /* ArrowLeft */: return RGFW_left; /* 0xE04B */
+
9141 case 0x4CE33F7CU /* ArrowRight */: return RGFW_right; /* 0xE04D */
+
9142 case 0x7B8E55DCU /* End */: return RGFW_end; /* 0xE04F */
+
9143 case 0x3799379EU /* ArrowDown */: return RGFW_down; /* 0xE050 */
+
9144 case 0xBA90179EU /* PageDown */: return RGFW_pageDown; /* 0xE051 */
+
9145 case 0x6723CB2CU /* Insert */: return RGFW_insert; /* 0xE052 */
+
9146 case 0x6725C50DU /* Delete */: return RGFW_delete; /* 0xE053 */
+
9147 case 0x6723658CU /* OSLeft */: return RGFW_superL; /* 0xE05B */
+
9148 case 0x39643F7CU /* MetaRight */: return RGFW_superR; /* 0xE05C */
+
9149 }
9150
-
9151 u8 mappedKey = (u8)(*((u32*)key));
-
9152
-
9153 if (*((u16*)key) != mappedKey) {
-
9154 mappedKey = 0;
-
9155 if (*((u32*)key) == *((u32*)"Tab")) mappedKey = RGFW_tab;
-
9156 }
-
9157
-
9158 RGFW_events[RGFW_eventLen].type = press ? RGFW_keyPressed : RGFW_keyReleased;
-
9159 RGFW_events[RGFW_eventLen].key = physicalKey;
-
9160 RGFW_events[RGFW_eventLen].keyChar = mappedKey;
-
9161 RGFW_events[RGFW_eventLen].keyMod = RGFW_root->event.keyMod;
-
9162 RGFW_eventLen++;
+
9151 return 0;
+
9152}
+
9153
+
9154void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyEvent(char* key, char* code, b8 press) {
+
9155 const char* iCode = code;
+
9156
+
9157 u32 hash = 0;
+
9158 while(*iCode) hash = ((hash ^ 0x7E057D79U) << 3) ^ (unsigned int)*iCode++;
+
9159
+
9160 u32 physicalKey = RGFW_webasmPhysicalToRGFW(hash);
+
9161
+
9162 u8 mappedKey = (u8)(*((u32*)key));
9163
-
9164 RGFW_keyboard[physicalKey].prev = RGFW_keyboard[physicalKey].current;
-
9165 RGFW_keyboard[physicalKey].current = press;
-
9166
-
9167 RGFW_keyCallback(RGFW_root, physicalKey, mappedKey, RGFW_root->event.keyMod, press);
-
9168}
-
9169
-
9170void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyMods(b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super) {
-
9171 RGFW_updateKeyModsPro(RGFW_root, capital, numlock, control, alt, shift, super);
-
9172}
-
9173
-
9174void EMSCRIPTEN_KEEPALIVE Emscripten_onDrop(size_t count) {
-
9175 if (!(RGFW_root->_flags & RGFW_windowAllowDND))
-
9176 return;
+
9164 if (*((u16*)key) != mappedKey) {
+
9165 mappedKey = 0;
+
9166 if (*((u32*)key) == *((u32*)"Tab")) mappedKey = RGFW_tab;
+
9167 }
+
9168
+
9169 RGFW_events[RGFW_eventLen].type = press ? RGFW_keyPressed : RGFW_keyReleased;
+
9170 RGFW_events[RGFW_eventLen].key = physicalKey;
+
9171 RGFW_events[RGFW_eventLen].keyChar = mappedKey;
+
9172 RGFW_events[RGFW_eventLen].keyMod = RGFW_root->event.keyMod;
+
9173 RGFW_eventLen++;
+
9174
+
9175 RGFW_keyboard[physicalKey].prev = RGFW_keyboard[physicalKey].current;
+
9176 RGFW_keyboard[physicalKey].current = press;
9177
-
9178 RGFW_events[RGFW_eventLen].droppedFilesCount = count;
-
9179 RGFW_dndCallback(RGFW_root, RGFW_events[RGFW_eventLen].droppedFiles, count);
-
9180 RGFW_eventLen++;
-
9181}
-
9182
-
9183b8 RGFW_stopCheckEvents_bool = RGFW_FALSE;
-
9184void RGFW_stopCheckEvents(void) {
-
9185 RGFW_stopCheckEvents_bool = RGFW_TRUE;
-
9186}
-
9187
-
9188void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
-
9189 RGFW_UNUSED(win);
-
9190
-
9191 if (waitMS == 0)
-
9192 return;
+
9178 RGFW_keyCallback(RGFW_root, physicalKey, mappedKey, RGFW_root->event.keyMod, press);
+
9179}
+
9180
+
9181void EMSCRIPTEN_KEEPALIVE RGFW_handleKeyMods(b8 capital, b8 numlock, b8 control, b8 alt, b8 shift, b8 super) {
+
9182 RGFW_updateKeyModsPro(RGFW_root, capital, numlock, control, alt, shift, super);
+
9183}
+
9184
+
9185void EMSCRIPTEN_KEEPALIVE Emscripten_onDrop(size_t count) {
+
9186 if (!(RGFW_root->_flags & RGFW_windowAllowDND))
+
9187 return;
+
9188
+
9189 RGFW_events[RGFW_eventLen].droppedFilesCount = count;
+
9190 RGFW_dndCallback(RGFW_root, RGFW_events[RGFW_eventLen].droppedFiles, count);
+
9191 RGFW_eventLen++;
+
9192}
9193
-
9194 u32 start = (u32)(((u64)RGFW_getTimeNS()) / 1e+6);
-
9195
-
9196 while ((RGFW_eventLen == 0) && RGFW_stopCheckEvents_bool == RGFW_FALSE &&
-
9197 (waitMS < 0 || (RGFW_getTimeNS() / 1e+6) - start < waitMS)
-
9198 ) {
-
9199 emscripten_sleep(0);
-
9200 }
+
9194b8 RGFW_stopCheckEvents_bool = RGFW_FALSE;
+
9195void RGFW_stopCheckEvents(void) {
+
9196 RGFW_stopCheckEvents_bool = RGFW_TRUE;
+
9197}
+
9198
+
9199void RGFW_window_eventWait(RGFW_window* win, i32 waitMS) {
+
9200 RGFW_UNUSED(win);
9201
-
9202 RGFW_stopCheckEvents_bool = RGFW_FALSE;
-
9203}
+
9202 if (waitMS == 0)
+
9203 return;
9204
-
9205void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area){
-
9206 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
9207 win->buffer = buffer;
-
9208 win->bufferSize = area;
-
9209 #ifdef RGFW_OSMESA
-
9210 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
-
9211 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
-
9212 #endif
-
9213 #else
-
9214 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
-
9215 #endif
-
9216}
-
9217
-
9218void EMSCRIPTEN_KEEPALIVE RGFW_makeSetValue(size_t index, char* file) {
-
9219 /* This seems like a terrible idea, don't replicate this unless you hate yourself or the OS */
-
9220 /* TODO: find a better way to do this
-
9221 */
-
9222
-
9223 RGFW_events[RGFW_eventLen].type = RGFW_DND;
-
9224 RGFW_MEMCPY((char*)RGFW_events[RGFW_eventLen].droppedFiles[index], file, RGFW_MAX_PATH);
-
9225}
-
9226
-
9227#include <sys/stat.h>
-
9228#include <sys/types.h>
-
9229#include <errno.h>
-
9230#include <stdio.h>
-
9231
-
9232void EMSCRIPTEN_KEEPALIVE RGFW_mkdir(char* name) { mkdir(name, 0755); }
+
9205 u32 start = (u32)(((u64)RGFW_getTimeNS()) / 1e+6);
+
9206
+
9207 while ((RGFW_eventLen == 0) && RGFW_stopCheckEvents_bool == RGFW_FALSE &&
+
9208 (waitMS < 0 || (RGFW_getTimeNS() / 1e+6) - start < waitMS)
+
9209 ) {
+
9210 emscripten_sleep(0);
+
9211 }
+
9212
+
9213 RGFW_stopCheckEvents_bool = RGFW_FALSE;
+
9214}
+
9215
+
9216void RGFW_window_initBufferPtr(RGFW_window* win, u8* buffer, RGFW_area area){
+
9217 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
9218 win->buffer = buffer;
+
9219 win->bufferSize = area;
+
9220 #ifdef RGFW_OSMESA
+
9221 win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
+
9222 OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
+
9223 #endif
+
9224 #else
+
9225 RGFW_UNUSED(win); RGFW_UNUSED(buffer); RGFW_UNUSED(area);
+
9226 #endif
+
9227}
+
9228
+
9229void EMSCRIPTEN_KEEPALIVE RGFW_makeSetValue(size_t index, char* file) {
+
9230 /* This seems like a terrible idea, don't replicate this unless you hate yourself or the OS */
+
9231 /* TODO: find a better way to do this
+
9232 */
9233
-
9234void EMSCRIPTEN_KEEPALIVE RGFW_writeFile(const char *path, const char *data, size_t len) {
-
9235 FILE* file = fopen(path, "w+");
-
9236 if (file == NULL)
-
9237 return;
-
9238
-
9239 fwrite(data, sizeof(char), len, file);
-
9240 fclose(file);
-
9241}
+
9234 RGFW_events[RGFW_eventLen].type = RGFW_DND;
+
9235 RGFW_MEMCPY((char*)RGFW_events[RGFW_eventLen].droppedFiles[index], file, RGFW_MAX_PATH);
+
9236}
+
9237
+
9238#include <sys/stat.h>
+
9239#include <sys/types.h>
+
9240#include <errno.h>
+
9241#include <stdio.h>
9242
-
9243RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
-
9244 RGFW_UNUSED(name);
-
9245
-
9246 RGFW_window_basic_init(win, rect, flags);
-
9247
-
9248 #ifndef RGFW_WEBGPU
-
9249 EmscriptenWebGLContextAttributes attrs;
-
9250 attrs.alpha = EM_TRUE;
-
9251 attrs.depth = EM_TRUE;
-
9252 attrs.alpha = EM_TRUE;
-
9253 attrs.stencil = RGFW_STENCIL;
-
9254 attrs.antialias = RGFW_SAMPLES;
-
9255 attrs.premultipliedAlpha = EM_TRUE;
-
9256 attrs.preserveDrawingBuffer = EM_FALSE;
-
9257
-
9258 if (RGFW_DOUBLE_BUFFER == 0)
-
9259 attrs.renderViaOffscreenBackBuffer = 0;
-
9260 else
-
9261 attrs.renderViaOffscreenBackBuffer = RGFW_AUX_BUFFERS;
-
9262
-
9263 attrs.failIfMajorPerformanceCaveat = EM_FALSE;
-
9264 attrs.majorVersion = (RGFW_majorVersion == 0) ? 1 : RGFW_majorVersion;
-
9265 attrs.minorVersion = RGFW_minorVersion;
-
9266
-
9267 attrs.enableExtensionsByDefault = EM_TRUE;
-
9268 attrs.explicitSwapControl = EM_TRUE;
-
9269
-
9270 emscripten_webgl_init_context_attributes(&attrs);
-
9271 win->src.ctx = emscripten_webgl_create_context("#canvas", &attrs);
-
9272 emscripten_webgl_make_context_current(win->src.ctx);
+
9243void EMSCRIPTEN_KEEPALIVE RGFW_mkdir(char* name) { mkdir(name, 0755); }
+
9244
+
9245void EMSCRIPTEN_KEEPALIVE RGFW_writeFile(const char *path, const char *data, size_t len) {
+
9246 FILE* file = fopen(path, "w+");
+
9247 if (file == NULL)
+
9248 return;
+
9249
+
9250 fwrite(data, sizeof(char), len, file);
+
9251 fclose(file);
+
9252}
+
9253
+
9254RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowFlags flags, RGFW_window* win) {
+
9255 RGFW_UNUSED(name);
+
9256
+
9257 RGFW_window_basic_init(win, rect, flags);
+
9258
+
9259 #ifndef RGFW_WEBGPU
+
9260 EmscriptenWebGLContextAttributes attrs;
+
9261 attrs.alpha = EM_TRUE;
+
9262 attrs.depth = EM_TRUE;
+
9263 attrs.alpha = EM_TRUE;
+
9264 attrs.stencil = RGFW_STENCIL;
+
9265 attrs.antialias = RGFW_SAMPLES;
+
9266 attrs.premultipliedAlpha = EM_TRUE;
+
9267 attrs.preserveDrawingBuffer = EM_FALSE;
+
9268
+
9269 if (RGFW_DOUBLE_BUFFER == 0)
+
9270 attrs.renderViaOffscreenBackBuffer = 0;
+
9271 else
+
9272 attrs.renderViaOffscreenBackBuffer = RGFW_AUX_BUFFERS;
9273
-
9274 #ifdef LEGACY_GL_EMULATION
-
9275 EM_ASM("Module.useWebGL = true; GLImmediate.init();");
-
9276 #endif
-
9277 #else
-
9278 win->src.ctx = wgpuCreateInstance(NULL);
-
9279 win->src.device = emscripten_webgpu_get_device();
-
9280 win->src.queue = wgpuDeviceGetQueue(win->src.device);
-
9281 #endif
-
9282
-
9283 emscripten_set_canvas_element_size("#canvas", rect.w, rect.h);
-
9284 emscripten_set_window_title(name);
-
9285
-
9286 /* load callbacks */
-
9287 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_resize);
-
9288 emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, EM_FALSE, Emscripten_on_fullscreenchange);
-
9289 emscripten_set_mousemove_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mousemove);
-
9290 emscripten_set_touchstart_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchstart);
-
9291 emscripten_set_touchend_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchend);
-
9292 emscripten_set_touchmove_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchmove);
-
9293 emscripten_set_touchcancel_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchcancel);
-
9294 emscripten_set_mousedown_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mousedown);
-
9295 emscripten_set_mouseup_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mouseup);
-
9296 emscripten_set_wheel_callback("#canvas", NULL, EM_FALSE, Emscripten_on_wheel);
-
9297 emscripten_set_focusin_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_focusin);
-
9298 emscripten_set_focusout_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_focusout);
-
9299 emscripten_set_gamepadconnected_callback(NULL, 1, Emscripten_on_gamepad);
-
9300 emscripten_set_gamepaddisconnected_callback(NULL, 1, Emscripten_on_gamepad);
-
9301
-
9302 if (flags & RGFW_windowAllowDND) {
-
9303 win->_flags |= RGFW_windowAllowDND;
-
9304 }
-
9305
-
9306 EM_ASM({
-
9307 window.addEventListener("keydown",
-
9308 (event) => {
-
9309 var key = stringToNewUTF8(event.key); var code = stringToNewUTF8(event.code);
-
9310 Module._RGFW_handleKeyMods(event.getModifierState("CapsLock"), event.getModifierState("NumLock"), event.getModifierState("Control"), event.getModifierState("Alt"), event.getModifierState("Shift"), event.getModifierState("Meta"));
-
9311 Module._RGFW_handleKeyEvent(key, code, 1);
-
9312 _free(key); _free(code);
-
9313 },
-
9314 true);
-
9315 window.addEventListener("keyup",
-
9316 (event) => {
-
9317 var key = stringToNewUTF8(event.key); var code = stringToNewUTF8(event.code);
-
9318 Module._RGFW_handoleKeyMods(event.getModifierState("CapsLock"), event.getModifierState("NumLock"), event.getModifierState("Control"), event.getModifierState("Alt"), event.getModifierState("Shift"), event.getModifierState("Meta"));
-
9319 Module._RGFW_handleKeyEvent(key, code, 0);
-
9320 _free(key); _free(code);
-
9321ode },
-
9322 true);
-
9323 });
-
9324
-
9325 EM_ASM({
-
9326 var canvas = document.getElementById('canvas');
-
9327 canvas.addEventListener('drop', function(e) {
-
9328 e.preventDefault();
-
9329 if (e.dataTransfer.file < 0)
-
9330 return;
-
9331
-
9332 var filenamesArray = [];
-
9333 var count = e.dataTransfer.files.length;
-
9334
-
9335 /* Read and save the files to emscripten's files */
-
9336 var drop_dir = '.rgfw_dropped_files';
-
9337 Module._RGFW_mkdir(drop_dir);
-
9338
-
9339 for (var i = 0; i < count; i++) {
-
9340 var file = e.dataTransfer.files[i];
-
9341
-
9342 var path = '/' + drop_dir + '/' + file.name.replace("//", '_');
-
9343 var reader = new FileReader();
-
9344
-
9345 reader.onloadend = (e) => {
-
9346 if (reader.readyState != 2) {
-
9347 out('failed to read dropped file: '+file.name+': '+reader.error);
-
9348 }
-
9349 else {
-
9350 var data = e.target.result;
-
9351
-
9352 _RGFW_writeFile(path, new Uint8Array(data), file.size);
-
9353 }
-
9354 };
+
9274 attrs.failIfMajorPerformanceCaveat = EM_FALSE;
+
9275 attrs.majorVersion = (RGFW_majorVersion == 0) ? 1 : RGFW_majorVersion;
+
9276 attrs.minorVersion = RGFW_minorVersion;
+
9277
+
9278 attrs.enableExtensionsByDefault = EM_TRUE;
+
9279 attrs.explicitSwapControl = EM_TRUE;
+
9280
+
9281 emscripten_webgl_init_context_attributes(&attrs);
+
9282 win->src.ctx = emscripten_webgl_create_context("#canvas", &attrs);
+
9283 emscripten_webgl_make_context_current(win->src.ctx);
+
9284
+
9285 #ifdef LEGACY_GL_EMULATION
+
9286 EM_ASM("Module.useWebGL = true; GLImmediate.init();");
+
9287 #endif
+
9288 #else
+
9289 win->src.ctx = wgpuCreateInstance(NULL);
+
9290 win->src.device = emscripten_webgpu_get_device();
+
9291 win->src.queue = wgpuDeviceGetQueue(win->src.device);
+
9292 #endif
+
9293
+
9294 emscripten_set_canvas_element_size("#canvas", rect.w, rect.h);
+
9295 emscripten_set_window_title(name);
+
9296
+
9297 /* load callbacks */
+
9298 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_resize);
+
9299 emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, EM_FALSE, Emscripten_on_fullscreenchange);
+
9300 emscripten_set_mousemove_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mousemove);
+
9301 emscripten_set_touchstart_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchstart);
+
9302 emscripten_set_touchend_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchend);
+
9303 emscripten_set_touchmove_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchmove);
+
9304 emscripten_set_touchcancel_callback("#canvas", NULL, EM_FALSE, Emscripten_on_touchcancel);
+
9305 emscripten_set_mousedown_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mousedown);
+
9306 emscripten_set_mouseup_callback("#canvas", NULL, EM_FALSE, Emscripten_on_mouseup);
+
9307 emscripten_set_wheel_callback("#canvas", NULL, EM_FALSE, Emscripten_on_wheel);
+
9308 emscripten_set_focusin_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_focusin);
+
9309 emscripten_set_focusout_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, EM_FALSE, Emscripten_on_focusout);
+
9310 emscripten_set_gamepadconnected_callback(NULL, 1, Emscripten_on_gamepad);
+
9311 emscripten_set_gamepaddisconnected_callback(NULL, 1, Emscripten_on_gamepad);
+
9312
+
9313 if (flags & RGFW_windowAllowDND) {
+
9314 win->_flags |= RGFW_windowAllowDND;
+
9315 }
+
9316
+
9317 EM_ASM({
+
9318 window.addEventListener("keydown",
+
9319 (event) => {
+
9320 var key = stringToNewUTF8(event.key); var code = stringToNewUTF8(event.code);
+
9321 Module._RGFW_handleKeyMods(event.getModifierState("CapsLock"), event.getModifierState("NumLock"), event.getModifierState("Control"), event.getModifierState("Alt"), event.getModifierState("Shift"), event.getModifierState("Meta"));
+
9322 Module._RGFW_handleKeyEvent(key, code, 1);
+
9323 _free(key); _free(code);
+
9324 },
+
9325 true);
+
9326 window.addEventListener("keyup",
+
9327 (event) => {
+
9328 var key = stringToNewUTF8(event.key); var code = stringToNewUTF8(event.code);
+
9329 Module._RGFW_handoleKeyMods(event.getModifierState("CapsLock"), event.getModifierState("NumLock"), event.getModifierState("Control"), event.getModifierState("Alt"), event.getModifierState("Shift"), event.getModifierState("Meta"));
+
9330 Module._RGFW_handleKeyEvent(key, code, 0);
+
9331 _free(key); _free(code);
+
9332ode },
+
9333 true);
+
9334 });
+
9335
+
9336 EM_ASM({
+
9337 var canvas = document.getElementById('canvas');
+
9338 canvas.addEventListener('drop', function(e) {
+
9339 e.preventDefault();
+
9340 if (e.dataTransfer.file < 0)
+
9341 return;
+
9342
+
9343 var filenamesArray = [];
+
9344 var count = e.dataTransfer.files.length;
+
9345
+
9346 /* Read and save the files to emscripten's files */
+
9347 var drop_dir = '.rgfw_dropped_files';
+
9348 Module._RGFW_mkdir(drop_dir);
+
9349
+
9350 for (var i = 0; i < count; i++) {
+
9351 var file = e.dataTransfer.files[i];
+
9352
+
9353 var path = '/' + drop_dir + '/' + file.name.replace("//", '_');
+
9354 var reader = new FileReader();
9355
-
9356 reader.readAsArrayBuffer(file);
-
9357 // This works weird on modern opengl
-
9358 var filename = stringToNewUTF8(path);
-
9359
-
9360 filenamesArray.push(filename);
-
9361
-
9362 Module._RGFW_makeSetValue(i, filename);
-
9363 }
-
9364
-
9365 Module._Emscripten_onDrop(count);
+
9356 reader.onloadend = (e) => {
+
9357 if (reader.readyState != 2) {
+
9358 out('failed to read dropped file: '+file.name+': '+reader.error);
+
9359 }
+
9360 else {
+
9361 var data = e.target.result;
+
9362
+
9363 _RGFW_writeFile(path, new Uint8Array(data), file.size);
+
9364 }
+
9365 };
9366
-
9367 for (var i = 0; i < count; ++i) {
-
9368 _free(filenamesArray[i]);
-
9369 }
-
9370 }, true);
-
9371
-
9372 canvas.addEventListener('dragover', function(e) { e.preventDefault(); return false; }, true);
-
9373 });
-
9374
-
9375 glViewport(0, 0, rect.w, rect.h);
-
9376
-
9377 if (flags & RGFW_windowHideMouse) {
-
9378 RGFW_window_showMouse(win, 0);
-
9379 }
-
9380
-
9381 if (flags & RGFW_windowFullscreen) {
- -
9383 }
-
9384
-
9385 #ifdef RGFW_DEBUG
-
9386 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
-
9387 #endif
-
9388
-
9389 return win;
-
9390}
+
9367 reader.readAsArrayBuffer(file);
+
9368 // This works weird on modern opengl
+
9369 var filename = stringToNewUTF8(path);
+
9370
+
9371 filenamesArray.push(filename);
+
9372
+
9373 Module._RGFW_makeSetValue(i, filename);
+
9374 }
+
9375
+
9376 Module._Emscripten_onDrop(count);
+
9377
+
9378 for (var i = 0; i < count; ++i) {
+
9379 _free(filenamesArray[i]);
+
9380 }
+
9381 }, true);
+
9382
+
9383 canvas.addEventListener('dragover', function(e) { e.preventDefault(); return false; }, true);
+
9384 });
+
9385
+
9386 glViewport(0, 0, rect.w, rect.h);
+
9387
+
9388 if (flags & RGFW_windowHideMouse) {
+
9389 RGFW_window_showMouse(win, 0);
+
9390 }
9391
- -
9393 static u8 index = 0;
-
9394
-
9395 if (index == 0) {
-
9396 RGFW_resetKey();
-
9397 }
-
9398
-
9399 emscripten_sample_gamepad_data();
-
9400 /* check gamepads */
-
9401 for (int i = 0; (i < emscripten_get_num_gamepads()) && (i < 4); i++) {
-
9402 if (RGFW_gamepads[i] == 0)
-
9403 continue;
-
9404 EmscriptenGamepadEvent gamepadState;
+
9392 if (flags & RGFW_windowFullscreen) {
+ +
9394 }
+
9395
+
9396 #ifdef RGFW_DEBUG
+
9397 printf("RGFW INFO: a window with a rect of {%i, %i, %i, %i} \n", win->r.x, win->r.y, win->r.w, win->r.h);
+
9398 #endif
+
9399
+
9400 return win;
+
9401}
+
9402
+ +
9404 static u8 index = 0;
9405
-
9406 if (emscripten_get_gamepad_status(i, &gamepadState) != EMSCRIPTEN_RESULT_SUCCESS)
-
9407 break;
-
9408
-
9409 // Register buttons data for every connected gamepad
-
9410 for (int j = 0; (j < gamepadState.numButtons) && (j < 16); j++) {
-
9411 u32 map[] = {
-
9412 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY,
-
9413 RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
-
9414 RGFW_gamepadSelect, RGFW_gamepadStart,
-
9415 RGFW_gamepadL3, RGFW_gamepadR3,
-
9416 RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight, RGFW_gamepadHome
-
9417 };
-
9418
+
9406 if (index == 0) {
+
9407 RGFW_resetKey();
+
9408 }
+
9409
+
9410 emscripten_sample_gamepad_data();
+
9411 /* check gamepads */
+
9412 for (int i = 0; (i < emscripten_get_num_gamepads()) && (i < 4); i++) {
+
9413 if (RGFW_gamepads[i] == 0)
+
9414 continue;
+
9415 EmscriptenGamepadEvent gamepadState;
+
9416
+
9417 if (emscripten_get_gamepad_status(i, &gamepadState) != EMSCRIPTEN_RESULT_SUCCESS)
+
9418 break;
9419
-
9420 u32 button = map[j];
-
9421 if (button == 404)
-
9422 continue;
-
9423
-
9424 if (RGFW_gamepadPressed[i][button].current != gamepadState.digitalButton[j]) {
-
9425 if (gamepadState.digitalButton[j])
-
9426 win->event.type = RGFW_gamepadButtonPressed;
-
9427 else
-
9428 win->event.type = RGFW_gamepadButtonReleased;
+
9420 // Register buttons data for every connected gamepad
+
9421 for (int j = 0; (j < gamepadState.numButtons) && (j < 16); j++) {
+
9422 u32 map[] = {
+
9423 RGFW_gamepadA, RGFW_gamepadB, RGFW_gamepadX, RGFW_gamepadY,
+
9424 RGFW_gamepadL1, RGFW_gamepadR1, RGFW_gamepadL2, RGFW_gamepadR2,
+
9425 RGFW_gamepadSelect, RGFW_gamepadStart,
+
9426 RGFW_gamepadL3, RGFW_gamepadR3,
+
9427 RGFW_gamepadUp, RGFW_gamepadDown, RGFW_gamepadLeft, RGFW_gamepadRight, RGFW_gamepadHome
+
9428 };
9429
-
9430 win->event.gamepad = i;
-
9431 win->event.button = map[j];
-
9432
-
9433 RGFW_gamepadPressed[i][button].prev = RGFW_gamepadPressed[i][button].current;
-
9434 RGFW_gamepadPressed[i][button].current = gamepadState.digitalButton[j];
-
9435
-
9436 RGFW_gamepadButtonCallback(win, win->event.gamepad, win->event.button, gamepadState.digitalButton[j]);
-
9437 return &win->event;
-
9438 }
-
9439 }
+
9430
+
9431 u32 button = map[j];
+
9432 if (button == 404)
+
9433 continue;
+
9434
+
9435 if (RGFW_gamepadPressed[i][button].current != gamepadState.digitalButton[j]) {
+
9436 if (gamepadState.digitalButton[j])
+
9437 win->event.type = RGFW_gamepadButtonPressed;
+
9438 else
+
9439 win->event.type = RGFW_gamepadButtonReleased;
9440
-
9441 for (int j = 0; (j < gamepadState.numAxes) && (j < 4); j += 2) {
-
9442 win->event.axisesCount = gamepadState.numAxes / 2;
-
9443 if (RGFW_gamepadAxes[i][(size_t)(j / 2)].x != (i8)(gamepadState.axis[j] * 100.0f) ||
-
9444 RGFW_gamepadAxes[i][(size_t)(j / 2)].y != (i8)(gamepadState.axis[j + 1] * 100.0f)
-
9445 ) {
+
9441 win->event.gamepad = i;
+
9442 win->event.button = map[j];
+
9443
+
9444 RGFW_gamepadPressed[i][button].prev = RGFW_gamepadPressed[i][button].current;
+
9445 RGFW_gamepadPressed[i][button].current = gamepadState.digitalButton[j];
9446
-
9447 RGFW_gamepadAxes[i][(size_t)(j / 2)].x = (i8)(gamepadState.axis[j] * 100.0f);
-
9448 RGFW_gamepadAxes[i][(size_t)(j / 2)].y = (i8)(gamepadState.axis[j + 1] * 100.0f);
-
9449 win->event.axis[(size_t)(j / 2)] = RGFW_gamepadAxes[i][(size_t)(j / 2)];
-
9450
-
9451 win->event.type = RGFW_gamepadAxisMove;
-
9452 win->event.gamepad = i;
-
9453 win->event.whichAxis = j / 2;
-
9454
-
9455 RGFW_gamepadAxisCallback(win, win->event.gamepad, win->event.axis, win->event.axisesCount, win->event.whichAxis);
-
9456 return &win->event;
-
9457 }
-
9458 }
-
9459 }
-
9460
-
9461 /* check queued events */
-
9462 if (RGFW_eventLen == 0)
-
9463 return NULL;
-
9464
-
9465 RGFW_events[index].frameTime = win->event.frameTime;
-
9466 RGFW_events[index].frameTime2 = win->event.frameTime2;
-
9467 RGFW_events[index].inFocus = win->event.inFocus;
-
9468
-
9469 win->event = RGFW_events[index];
-
9470
-
9471 RGFW_eventLen--;
-
9472
-
9473 if (RGFW_eventLen)
-
9474 index++;
-
9475 else
-
9476 index = 0;
-
9477
-
9478 return &win->event;
-
9479}
-
9480
- -
9482 RGFW_UNUSED(win);
-
9483 emscripten_set_canvas_element_size("#canvas", a.w, a.h);
-
9484}
-
9485
-
9486/* NOTE: I don't know if this is possible */
- -
9488/* this one might be possible but it looks iffy */
-
9489RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) { RGFW_UNUSED(channels); RGFW_UNUSED(a); RGFW_UNUSED(icon); return NULL; }
-
9490
-
9491void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) { RGFW_UNUSED(win); RGFW_UNUSED(mouse); }
-
9492void RGFW_freeMouse(RGFW_mouse* mouse) { RGFW_UNUSED(mouse); }
-
9493
-
9494const char RGFW_CURSORS[11][12] = {
-
9495 "default",
-
9496 "default",
-
9497 "text",
-
9498 "crosshair",
-
9499 "pointer",
-
9500 "ew-resize",
-
9501 "ns-resize",
-
9502 "nwse-resize",
-
9503 "nesw-resize",
-
9504 "move",
-
9505 "not-allowed"
-
9506};
-
9507
- -
9509 RGFW_UNUSED(win);
-
9510 EM_ASM( { document.getElementById("canvas").style.cursor = UTF8ToString($0); }, RGFW_CURSORS[mouse]);
-
9511 return 1;
-
9512}
-
9513
- -
9515 return RGFW_window_setMouseStandard(win, RGFW_mouseNormal);
-
9516}
-
9517
-
9518void RGFW_window_showMouse(RGFW_window* win, i8 show) {
-
9519 if (show)
- -
9521 else
-
9522 EM_ASM(document.getElementById('canvas').style.cursor = 'none';);
+
9447 RGFW_gamepadButtonCallback(win, win->event.gamepad, win->event.button, gamepadState.digitalButton[j]);
+
9448 return &win->event;
+
9449 }
+
9450 }
+
9451
+
9452 for (int j = 0; (j < gamepadState.numAxes) && (j < 4); j += 2) {
+
9453 win->event.axisesCount = gamepadState.numAxes / 2;
+
9454 if (RGFW_gamepadAxes[i][(size_t)(j / 2)].x != (i8)(gamepadState.axis[j] * 100.0f) ||
+
9455 RGFW_gamepadAxes[i][(size_t)(j / 2)].y != (i8)(gamepadState.axis[j + 1] * 100.0f)
+
9456 ) {
+
9457
+
9458 RGFW_gamepadAxes[i][(size_t)(j / 2)].x = (i8)(gamepadState.axis[j] * 100.0f);
+
9459 RGFW_gamepadAxes[i][(size_t)(j / 2)].y = (i8)(gamepadState.axis[j + 1] * 100.0f);
+
9460 win->event.axis[(size_t)(j / 2)] = RGFW_gamepadAxes[i][(size_t)(j / 2)];
+
9461
+
9462 win->event.type = RGFW_gamepadAxisMove;
+
9463 win->event.gamepad = i;
+
9464 win->event.whichAxis = j / 2;
+
9465
+
9466 RGFW_gamepadAxisCallback(win, win->event.gamepad, win->event.axis, win->event.axisesCount, win->event.whichAxis);
+
9467 return &win->event;
+
9468 }
+
9469 }
+
9470 }
+
9471
+
9472 /* check queued events */
+
9473 if (RGFW_eventLen == 0)
+
9474 return NULL;
+
9475
+
9476 RGFW_events[index].frameTime = win->event.frameTime;
+
9477 RGFW_events[index].frameTime2 = win->event.frameTime2;
+
9478 RGFW_events[index].inFocus = win->event.inFocus;
+
9479
+
9480 win->event = RGFW_events[index];
+
9481
+
9482 RGFW_eventLen--;
+
9483
+
9484 if (RGFW_eventLen)
+
9485 index++;
+
9486 else
+
9487 index = 0;
+
9488
+
9489 return &win->event;
+
9490}
+
9491
+ +
9493 RGFW_UNUSED(win);
+
9494 emscripten_set_canvas_element_size("#canvas", a.w, a.h);
+
9495}
+
9496
+
9497/* NOTE: I don't know if this is possible */
+ +
9499/* this one might be possible but it looks iffy */
+
9500RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) { RGFW_UNUSED(channels); RGFW_UNUSED(a); RGFW_UNUSED(icon); return NULL; }
+
9501
+
9502void RGFW_window_setMouse(RGFW_window* win, RGFW_mouse* mouse) { RGFW_UNUSED(win); RGFW_UNUSED(mouse); }
+
9503void RGFW_freeMouse(RGFW_mouse* mouse) { RGFW_UNUSED(mouse); }
+
9504
+
9505const char RGFW_CURSORS[11][12] = {
+
9506 "default",
+
9507 "default",
+
9508 "text",
+
9509 "crosshair",
+
9510 "pointer",
+
9511 "ew-resize",
+
9512 "ns-resize",
+
9513 "nwse-resize",
+
9514 "nesw-resize",
+
9515 "move",
+
9516 "not-allowed"
+
9517};
+
9518
+ +
9520 RGFW_UNUSED(win);
+
9521 EM_ASM( { document.getElementById("canvas").style.cursor = UTF8ToString($0); }, RGFW_CURSORS[mouse]);
+
9522 return 1;
9523}
9524
- -
9526 RGFW_point point;
-
9527 point.x = EM_ASM_INT({
-
9528 return window.mouseX || 0;
-
9529 });
-
9530 point.y = EM_ASM_INT({
-
9531 return window.mouseY || 0;
-
9532 });
-
9533 return point;
+ +
9526 return RGFW_window_setMouseStandard(win, RGFW_mouseNormal);
+
9527}
+
9528
+
9529void RGFW_window_showMouse(RGFW_window* win, i8 show) {
+
9530 if (show)
+ +
9532 else
+
9533 EM_ASM(document.getElementById('canvas').style.cursor = 'none';);
9534}
9535
- -
9537 RGFW_UNUSED(win);
-
9538
-
9539 EmscriptenMouseEvent mouseEvent;
-
9540 emscripten_get_mouse_status(&mouseEvent);
-
9541 return RGFW_POINT( mouseEvent.targetX, mouseEvent.targetY);
-
9542}
-
9543
-
9544void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
-
9545 RGFW_UNUSED(win);
+ +
9537 RGFW_point point;
+
9538 point.x = EM_ASM_INT({
+
9539 return window.mouseX || 0;
+
9540 });
+
9541 point.y = EM_ASM_INT({
+
9542 return window.mouseY || 0;
+
9543 });
+
9544 return point;
+
9545}
9546
-
9547 EM_ASM_({
-
9548 var canvas = document.getElementById('canvas');
-
9549 if ($0) {
-
9550 canvas.style.pointerEvents = 'none';
-
9551 } else {
-
9552 canvas.style.pointerEvents = 'auto';
-
9553 }
-
9554 }, passthrough);
-
9555}
-
9556
-
9557void RGFW_writeClipboard(const char* text, u32 textLen) {
-
9558 RGFW_UNUSED(textLen);
-
9559 EM_ASM({ navigator.clipboard.writeText(UTF8ToString($0)); }, text);
-
9560}
-
9561
-
9562
-
9563RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
-
9564 RGFW_UNUSED(str); RGFW_UNUSED(strCapacity);
-
9565 /*
-
9566 placeholder code for later
-
9567 I'm not sure if this is possible do the the async stuff
-
9568 */
-
9569 return 0;
-
9570}
-
9571
- -
9573 RGFW_UNUSED(win);
-
9574
-
9575 #ifdef RGFW_BUFFER
-
9576 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
-
9577 glEnable(GL_TEXTURE_2D);
-
9578
-
9579 GLuint texture;
-
9580 glGenTextures(1,&texture);
-
9581
-
9582 glBindTexture(GL_TEXTURE_2D,texture);
-
9583
-
9584 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-
9585 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
9586 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
9587 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
9588
-
9589 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win->bufferSize.w, win->bufferSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, win->buffer);
-
9590
-
9591 float ratioX = ((float)win->r.w / (float)win->bufferSize.w);
-
9592 float ratioY = ((float)win->r.h / (float)win->bufferSize.h);
-
9593
-
9594 // Set up the viewport
-
9595 glClear(GL_COLOR_BUFFER_BIT);
-
9596
-
9597 glBegin(GL_TRIANGLES);
-
9598 glTexCoord2f(0, ratioY); glColor3f(1, 1, 1); glVertex2f(-1, -1);
-
9599 glTexCoord2f(0, 0); glColor3f(1, 1, 1); glVertex2f(-1, 1);
-
9600 glTexCoord2f(ratioX, ratioY); glColor3f(1, 1, 1); glVertex2f(1, -1);
+ +
9548 RGFW_UNUSED(win);
+
9549
+
9550 EmscriptenMouseEvent mouseEvent;
+
9551 emscripten_get_mouse_status(&mouseEvent);
+
9552 return RGFW_POINT( mouseEvent.targetX, mouseEvent.targetY);
+
9553}
+
9554
+
9555void RGFW_window_setMousePassthrough(RGFW_window* win, b8 passthrough) {
+
9556 RGFW_UNUSED(win);
+
9557
+
9558 EM_ASM_({
+
9559 var canvas = document.getElementById('canvas');
+
9560 if ($0) {
+
9561 canvas.style.pointerEvents = 'none';
+
9562 } else {
+
9563 canvas.style.pointerEvents = 'auto';
+
9564 }
+
9565 }, passthrough);
+
9566}
+
9567
+
9568void RGFW_writeClipboard(const char* text, u32 textLen) {
+
9569 RGFW_UNUSED(textLen);
+
9570 EM_ASM({ navigator.clipboard.writeText(UTF8ToString($0)); }, text);
+
9571}
+
9572
+
9573
+
9574RGFW_ssize_t RGFW_readClipboardPtr(char* str, size_t strCapacity) {
+
9575 RGFW_UNUSED(str); RGFW_UNUSED(strCapacity);
+
9576 /*
+
9577 placeholder code for later
+
9578 I'm not sure if this is possible do the the async stuff
+
9579 */
+
9580 return 0;
+
9581}
+
9582
+ +
9584 RGFW_UNUSED(win);
+
9585
+
9586 #ifdef RGFW_BUFFER
+
9587 if (!(win->_flags & RGFW_NO_CPU_RENDER)) {
+
9588 glEnable(GL_TEXTURE_2D);
+
9589
+
9590 GLuint texture;
+
9591 glGenTextures(1,&texture);
+
9592
+
9593 glBindTexture(GL_TEXTURE_2D,texture);
+
9594
+
9595 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+
9596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
9597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
9598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
9599
+
9600 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win->bufferSize.w, win->bufferSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, win->buffer);
9601
-
9602 glTexCoord2f(ratioX, 0); glColor3f(1, 1, 1); glVertex2f(1, 1);
-
9603 glTexCoord2f(ratioX, ratioY); glColor3f(1, 1, 1); glVertex2f(1, -1);
-
9604 glTexCoord2f(0, 0); glColor3f(1, 1, 1); glVertex2f(-1, 1);
-
9605 glEnd();
-
9606
-
9607 glDeleteTextures(1, &texture);
-
9608 }
-
9609 #endif
-
9610
-
9611#ifndef RGFW_WEBGPU
-
9612 emscripten_webgl_commit_frame();
-
9613#endif
-
9614 emscripten_sleep(0);
-
9615}
-
9616
+
9602 float ratioX = ((float)win->r.w / (float)win->bufferSize.w);
+
9603 float ratioY = ((float)win->r.h / (float)win->bufferSize.h);
+
9604
+
9605 // Set up the viewport
+
9606 glClear(GL_COLOR_BUFFER_BIT);
+
9607
+
9608 glBegin(GL_TRIANGLES);
+
9609 glTexCoord2f(0, ratioY); glColor3f(1, 1, 1); glVertex2f(-1, -1);
+
9610 glTexCoord2f(0, 0); glColor3f(1, 1, 1); glVertex2f(-1, 1);
+
9611 glTexCoord2f(ratioX, ratioY); glColor3f(1, 1, 1); glVertex2f(1, -1);
+
9612
+
9613 glTexCoord2f(ratioX, 0); glColor3f(1, 1, 1); glVertex2f(1, 1);
+
9614 glTexCoord2f(ratioX, ratioY); glColor3f(1, 1, 1); glVertex2f(1, -1);
+
9615 glTexCoord2f(0, 0); glColor3f(1, 1, 1); glVertex2f(-1, 1);
+
9616 glEnd();
9617
- -
9619#ifndef RGFW_WEBGPU
-
9620 if (win == NULL)
-
9621 emscripten_webgl_make_context_current(0);
-
9622 else
-
9623 emscripten_webgl_make_context_current(win->src.ctx);
+
9618 glDeleteTextures(1, &texture);
+
9619 }
+
9620 #endif
+
9621
+
9622#ifndef RGFW_WEBGPU
+
9623 emscripten_webgl_commit_frame();
9624#endif
-
9625}
-
9626
-
9627#ifndef RGFW_EGL
-
9628void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { RGFW_UNUSED(win); RGFW_UNUSED(swapInterval); }
-
9629#endif
-
9630
-
9631void RGFW_window_close(RGFW_window* win) {
-
9632#ifndef RGFW_WEBGPU
-
9633 emscripten_webgl_destroy_context(win->src.ctx);
-
9634#endif
-
9635
-
9636 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
-
9637 if ((win->_flags & RGFW_BUFFER_ALLOC))
-
9638 RGFW_FREE(win->buffer);
-
9639 #endif
-
9640
-
9641 RGFW_clipboard_switch(NULL);
-
9642
-
9643 if ((win->_flags & RGFW_WINDOW_ALLOC))
-
9644 RGFW_FREE(win);
-
9645}
+
9625 emscripten_sleep(0);
+
9626}
+
9627
+
9628
+ +
9630#ifndef RGFW_WEBGPU
+
9631 if (win == NULL)
+
9632 emscripten_webgl_make_context_current(0);
+
9633 else
+
9634 emscripten_webgl_make_context_current(win->src.ctx);
+
9635#endif
+
9636}
+
9637
+
9638#ifndef RGFW_EGL
+
9639void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) { RGFW_UNUSED(win); RGFW_UNUSED(swapInterval); }
+
9640#endif
+
9641
+
9642void RGFW_window_close(RGFW_window* win) {
+
9643#ifndef RGFW_WEBGPU
+
9644 emscripten_webgl_destroy_context(win->src.ctx);
+
9645#endif
9646
-
9647int RGFW_innerWidth(void) { return EM_ASM_INT({ return window.innerWidth; }); }
-
9648int RGFW_innerHeight(void) { return EM_ASM_INT({ return window.innerHeight; }); }
-
9649
- -
9651 return RGFW_AREA(RGFW_innerWidth(), RGFW_innerHeight());
-
9652}
+
9647 #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
+
9648 if ((win->_flags & RGFW_BUFFER_ALLOC))
+
9649 RGFW_FREE(win->buffer);
+
9650 #endif
+
9651
+
9652 RGFW_clipboard_switch(NULL);
9653
-
9654void* RGFW_getProcAddress(const char* procname) {
-
9655 return emscripten_webgl_get_proc_address(procname);
+
9654 if ((win->_flags & RGFW_WINDOW_ALLOC))
+
9655 RGFW_FREE(win);
9656}
9657
-
9658void RGFW_sleep(u64 milisecond) {
-
9659 emscripten_sleep(milisecond);
-
9660}
-
9661
-
9662u64 RGFW_getTimeNS(void) {
-
9663 return emscripten_get_now() * 1e+6;
-
9664}
-
9665
-
9666u64 RGFW_getTime(void) {
-
9667 return emscripten_get_now() * 1000;
-
9668}
-
9669
-
9670void RGFW_releaseCursor(RGFW_window* win) {
-
9671 RGFW_UNUSED(win);
-
9672 emscripten_exit_pointerlock();
-
9673}
-
9674
-
9675void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
-
9676 RGFW_UNUSED(win); RGFW_UNUSED(r);
-
9677
-
9678 emscripten_request_pointerlock("#canvas", 1);
+
9658int RGFW_innerWidth(void) { return EM_ASM_INT({ return window.innerWidth; }); }
+
9659int RGFW_innerHeight(void) { return EM_ASM_INT({ return window.innerHeight; }); }
+
9660
+ +
9662 return RGFW_AREA(RGFW_innerWidth(), RGFW_innerHeight());
+
9663}
+
9664
+
9665void* RGFW_getProcAddress(const char* procname) {
+
9666 return emscripten_webgl_get_proc_address(procname);
+
9667}
+
9668
+
9669void RGFW_sleep(u64 milisecond) {
+
9670 emscripten_sleep(milisecond);
+
9671}
+
9672
+
9673u64 RGFW_getTimeNS(void) {
+
9674 return emscripten_get_now() * 1e+6;
+
9675}
+
9676
+
9677u64 RGFW_getTime(void) {
+
9678 return emscripten_get_now() * 1000;
9679}
9680
-
9681
-
9682void RGFW_window_setName(RGFW_window* win, const char* name) {
-
9683 RGFW_UNUSED(win);
-
9684 emscripten_set_window_title(name);
-
9685}
-
9686
-
9687/* unsupported functions */
-
9688RGFW_monitor* RGFW_getMonitors(void) { return NULL; }
- - - - -
9693void RGFW_window_minimize(RGFW_window* win) { RGFW_UNUSED(win); }
-
9694void RGFW_window_restore(RGFW_window* win) { RGFW_UNUSED(win); }
-
9695void RGFW_window_setBorder(RGFW_window* win, b8 border) { RGFW_UNUSED(win); RGFW_UNUSED(border); }
-
9696b32 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); return 0; }
-
9697void RGFW_window_hide(RGFW_window* win) { RGFW_UNUSED(win); }
-
9698void RGFW_window_show(RGFW_window* win) {RGFW_UNUSED(win); }
-
9699b8 RGFW_window_isHidden(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
-
9700b8 RGFW_window_isMinimized(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
-
9701b8 RGFW_window_isMaximized(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
- -
9703#endif
-
9704
-
9705/* end of web asm defines */
-
9706
-
9707/* unix (macOS, linux, web asm) only stuff */
-
9708#if defined(RGFW_X11) || defined(RGFW_MACOS) || defined(RGFW_WEBASM) || defined(RGFW_WAYLAND)
-
9709
-
9710/* unix threading */
-
9711#ifndef RGFW_NO_THREADS
-
9712#include <pthread.h>
-
9713
- -
9715 RGFW_UNUSED(args);
-
9716
-
9717 RGFW_thread t;
-
9718 pthread_create((pthread_t*) &t, NULL, *ptr, NULL);
-
9719 return t;
-
9720}
-
9721void RGFW_cancelThread(RGFW_thread thread) { pthread_cancel((pthread_t) thread); }
-
9722void RGFW_joinThread(RGFW_thread thread) { pthread_join((pthread_t) thread, NULL); }
-
9723
-
9724#if defined(__linux__)
-
9725void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { pthread_setschedprio((pthread_t)thread, priority); }
-
9726#else
-
9727void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { RGFW_UNUSED(thread); RGFW_UNUSED(priority); }
-
9728#endif
-
9729#endif
-
9730
-
9731#ifndef RGFW_WEBASM
-
9732
-
9733/* unix sleep */
-
9734void RGFW_sleep(u64 ms) {
-
9735 struct timespec time;
-
9736 time.tv_sec = 0;
-
9737 time.tv_nsec = ms * 1e+6;
-
9738
-
9739 #ifndef RGFW_NO_UNIX_CLOCK
-
9740 nanosleep(&time, NULL);
-
9741 #endif
-
9742}
+
9681void RGFW_releaseCursor(RGFW_window* win) {
+
9682 RGFW_UNUSED(win);
+
9683 emscripten_exit_pointerlock();
+
9684}
+
9685
+
9686void RGFW_captureCursor(RGFW_window* win, RGFW_rect r) {
+
9687 RGFW_UNUSED(win); RGFW_UNUSED(r);
+
9688
+
9689 emscripten_request_pointerlock("#canvas", 1);
+
9690}
+
9691
+
9692
+
9693void RGFW_window_setName(RGFW_window* win, const char* name) {
+
9694 RGFW_UNUSED(win);
+
9695 emscripten_set_window_title(name);
+
9696}
+
9697
+
9698/* unsupported functions */
+
9699RGFW_monitor* RGFW_getMonitors(void) { return NULL; }
+ + + + +
9704void RGFW_window_minimize(RGFW_window* win) { RGFW_UNUSED(win); }
+
9705void RGFW_window_restore(RGFW_window* win) { RGFW_UNUSED(win); }
+
9706void RGFW_window_setBorder(RGFW_window* win, b8 border) { RGFW_UNUSED(win); RGFW_UNUSED(border); }
+
9707b32 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); return 0; }
+
9708void RGFW_window_hide(RGFW_window* win) { RGFW_UNUSED(win); }
+
9709void RGFW_window_show(RGFW_window* win) {RGFW_UNUSED(win); }
+
9710b8 RGFW_window_isHidden(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
+
9711b8 RGFW_window_isMinimized(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
+
9712b8 RGFW_window_isMaximized(RGFW_window* win) { RGFW_UNUSED(win); return 0; }
+ +
9714#endif
+
9715
+
9716/* end of web asm defines */
+
9717
+
9718/* unix (macOS, linux, web asm) only stuff */
+
9719#if defined(RGFW_X11) || defined(RGFW_MACOS) || defined(RGFW_WEBASM) || defined(RGFW_WAYLAND)
+
9720
+
9721/* unix threading */
+
9722#ifndef RGFW_NO_THREADS
+
9723#include <pthread.h>
+
9724
+ +
9726 RGFW_UNUSED(args);
+
9727
+
9728 RGFW_thread t;
+
9729 pthread_create((pthread_t*) &t, NULL, *ptr, NULL);
+
9730 return t;
+
9731}
+
9732void RGFW_cancelThread(RGFW_thread thread) { pthread_cancel((pthread_t) thread); }
+
9733void RGFW_joinThread(RGFW_thread thread) { pthread_join((pthread_t) thread, NULL); }
+
9734
+
9735#if defined(__linux__)
+
9736void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { pthread_setschedprio((pthread_t)thread, priority); }
+
9737#else
+
9738void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { RGFW_UNUSED(thread); RGFW_UNUSED(priority); }
+
9739#endif
+
9740#endif
+
9741
+
9742#ifndef RGFW_WEBASM
9743
-
9744#endif
-
9745
-
9746#endif /* end of unix / mac stuff*/
-
9747#endif /*RGFW_IMPLEMENTATION*/
-
9748
-
9749#if defined(__cplusplus) && !defined(__EMSCRIPTEN__)
-
9750}
-
9751 #ifdef __clang__
-
9752 #pragma clang diagnostic pop
-
9753 #endif
-
9754#endif
+
9744/* unix sleep */
+
9745void RGFW_sleep(u64 ms) {
+
9746 struct timespec time;
+
9747 time.tv_sec = 0;
+
9748 time.tv_nsec = ms * 1e+6;
+
9749
+
9750 #ifndef RGFW_NO_UNIX_CLOCK
+
9751 nanosleep(&time, NULL);
+
9752 #endif
+
9753}
+
9754
+
9755#endif
+
9756
+
9757#endif /* end of unix / mac stuff*/
+
9758#endif /*RGFW_IMPLEMENTATION*/
+
9759
+
9760#if defined(__cplusplus) && !defined(__EMSCRIPTEN__)
+
9761}
+
9762 #ifdef __clang__
+
9763 #pragma clang diagnostic pop
+
9764 #endif
+
9765#endif
#define RGFW_STRNCMP(s1, s2, max)
Definition: RGFW.h:195
u8 RGFW_key
Definition: RGFW.h:411
#define RGFW_ROUND(x)
Definition: RGFW.h:177
RGFWDEF RGFW_mouse * RGFW_loadMouse(u8 *icon, RGFW_area a, i32 channels)
#define RGFW_FREE
Definition: RGFW.h:188
#define RGFW_RECT(x, y, w, h)
Definition: RGFW.h:542
-
void * RGFW_thread
Definition: RGFW.h:753
+
void * RGFW_thread
Definition: RGFW.h:754
RGFWDEF void RGFW_useWayland(b8 wayland)
#define b8
Definition: RGFW.h:284
uint64_t u64
Definition: RGFW.h:275
@@ -9701,36 +9712,36 @@
#define glXSwapBuffers
Definition: XDL.h:454
#define XkbKeycodeToKeysym
Definition: XDL.h:426
#define glXDestroyContext
Definition: XDL.h:460
-
void(* RGFW_mousebuttonfunc)(RGFW_window *win, RGFW_mouseButton button, double scroll, b8 pressed)
Definition: RGFW.h:1009
-
void(* RGFW_dndInitfunc)(RGFW_window *win, RGFW_point point)
Definition: RGFW.h:1003
-
void(* RGFW_windowquitfunc)(RGFW_window *win)
Definition: RGFW.h:995
+
void(* RGFW_mousebuttonfunc)(RGFW_window *win, RGFW_mouseButton button, double scroll, b8 pressed)
Definition: RGFW.h:1010
+
void(* RGFW_dndInitfunc)(RGFW_window *win, RGFW_point point)
Definition: RGFW.h:1004
+
void(* RGFW_windowquitfunc)(RGFW_window *win)
Definition: RGFW.h:996
RGFWDEF RGFW_gamepadButtonfunc RGFW_setgamepadButtonCallback(RGFW_gamepadButtonfunc func)
RGFWDEF RGFW_dndfunc RGFW_setDndCallback(RGFW_dndfunc func)
-
void(* RGFW_mouseposfunc)(RGFW_window *win, RGFW_point point)
Definition: RGFW.h:1001
+
void(* RGFW_mouseposfunc)(RGFW_window *win, RGFW_point point)
Definition: RGFW.h:1002
RGFWDEF RGFW_windowrefreshfunc RGFW_setWindowRefreshCallback(RGFW_windowrefreshfunc func)
-
void(* RGFW_gamepadButtonfunc)(RGFW_window *win, u16 gamepad, u8 button, b8 pressed)
Definition: RGFW.h:1011
-
void(* RGFW_windowrefreshfunc)(RGFW_window *win)
Definition: RGFW.h:1005
+
void(* RGFW_gamepadButtonfunc)(RGFW_window *win, u16 gamepad, u8 button, b8 pressed)
Definition: RGFW.h:1012
+
void(* RGFW_windowrefreshfunc)(RGFW_window *win)
Definition: RGFW.h:1006
RGFWDEF RGFW_mousebuttonfunc RGFW_setMouseButtonCallback(RGFW_mousebuttonfunc func)
RGFWDEF RGFW_windowresizefunc RGFW_setWindowResizeCallback(RGFW_windowresizefunc func)
RGFWDEF RGFW_mouseNotifyfunc RGFW_setMouseNotifyCallBack(RGFW_mouseNotifyfunc func)
RGFWDEF RGFW_gamepadAxisfunc RGFW_setgamepadAxisCallback(RGFW_gamepadAxisfunc func)
-
void(* RGFW_mouseNotifyfunc)(RGFW_window *win, RGFW_point point, b8 status)
Definition: RGFW.h:999
-
void(* RGFW_dndfunc)(RGFW_window *win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount)
Definition: RGFW.h:1018
+
void(* RGFW_mouseNotifyfunc)(RGFW_window *win, RGFW_point point, b8 status)
Definition: RGFW.h:1000
+
void(* RGFW_dndfunc)(RGFW_window *win, char droppedFiles[RGFW_MAX_DROPS][RGFW_MAX_PATH], u32 droppedFilesCount)
Definition: RGFW.h:1019
RGFWDEF RGFW_dndInitfunc RGFW_setDndInitCallback(RGFW_dndInitfunc func)
RGFWDEF RGFW_focusfunc RGFW_setFocusCallback(RGFW_focusfunc func)
RGFWDEF RGFW_gamepadfunc RGFW_setGamepadCallback(RGFW_gamepadfunc func)
RGFWDEF RGFW_windowquitfunc RGFW_setWindowQuitCallback(RGFW_windowquitfunc func)
RGFWDEF RGFW_mouseposfunc RGFW_setMousePosCallback(RGFW_mouseposfunc func)
-
void(* RGFW_keyfunc)(RGFW_window *win, u8 key, char keyChar, RGFW_keymod keyMod, b8 pressed)
Definition: RGFW.h:1007
+
void(* RGFW_keyfunc)(RGFW_window *win, u8 key, char keyChar, RGFW_keymod keyMod, b8 pressed)
Definition: RGFW.h:1008
RGFWDEF RGFW_keyfunc RGFW_setKeyCallback(RGFW_keyfunc func)
-
void(* RGFW_windowresizefunc)(RGFW_window *win, RGFW_rect r)
Definition: RGFW.h:993
+
void(* RGFW_windowresizefunc)(RGFW_window *win, RGFW_rect r)
Definition: RGFW.h:994
RGFWDEF RGFW_windowmovefunc RGFW_setWindowMoveCallback(RGFW_windowmovefunc func)
-
void(* RGFW_gamepadAxisfunc)(RGFW_window *win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis)
Definition: RGFW.h:1013
-
void(* RGFW_gamepadfunc)(RGFW_window *win, u16 gamepad, b8 connected)
Definition: RGFW.h:1015
-
void(* RGFW_windowmovefunc)(RGFW_window *win, RGFW_rect r)
Definition: RGFW.h:991
-
void(* RGFW_focusfunc)(RGFW_window *win, b8 inFocus)
Definition: RGFW.h:997
+
void(* RGFW_gamepadAxisfunc)(RGFW_window *win, u16 gamepad, RGFW_point axis[2], u8 axisesCount, u8 whichAxis)
Definition: RGFW.h:1014
+
void(* RGFW_gamepadfunc)(RGFW_window *win, u16 gamepad, b8 connected)
Definition: RGFW.h:1016
+
void(* RGFW_windowmovefunc)(RGFW_window *win, RGFW_rect r)
Definition: RGFW.h:992
+
void(* RGFW_focusfunc)(RGFW_window *win, b8 inFocus)
Definition: RGFW.h:998
RGFWDEF void RGFW_writeClipboard(const char *text, u32 textLen)
-
ptrdiff_t RGFW_ssize_t
Definition: RGFW.h:971
+
ptrdiff_t RGFW_ssize_t
Definition: RGFW.h:972
RGFWDEF const char * RGFW_readClipboard(size_t *size)
RGFWDEF RGFW_ssize_t RGFW_readClipboardPtr(char *str, size_t strCapacity)
RGFWDEF b8 RGFW_wasMousePressed(RGFW_window *win, RGFW_mouseButton button)
@@ -9748,7 +9759,7 @@
RGFWDEF void RGFW_sleep(u64 milisecond)
RGFWDEF u64 RGFW_getTime(void)
RGFWDEF u32 RGFW_apiKeyToRGFW(u32 keycode)
-
DWORD(__stdcall * RGFW_threadFunc_ptr)(LPVOID lpThreadParameter)
Definition: RGFW.h:1067
+
DWORD(__stdcall * RGFW_threadFunc_ptr)(LPVOID lpThreadParameter)
Definition: RGFW.h:1068
RGFWDEF void RGFW_joinThread(RGFW_thread thread)
RGFWDEF void RGFW_setThreadPriority(RGFW_thread thread, u8 priority)
RGFWDEF void RGFW_cancelThread(RGFW_thread thread)
@@ -9854,13 +9865,13 @@
i32 y
Definition: RGFW.h:533
i32 x
Definition: RGFW.h:533
i32 w
Definition: RGFW.h:533
-
Definition: RGFW.h:731
-
RGFW_point _lastMousePoint
Definition: RGFW.h:745
-
u32 _flags
Definition: RGFW.h:747
-
RGFW_rect r
Definition: RGFW.h:743
-
RGFW_window_src src
Definition: RGFW.h:732
-
void * userPtr
Definition: RGFW.h:739
-
RGFW_event event
Definition: RGFW.h:741
+
Definition: RGFW.h:732
+
RGFW_point _lastMousePoint
Definition: RGFW.h:746
+
u32 _flags
Definition: RGFW.h:748
+
RGFW_rect r
Definition: RGFW.h:744
+
RGFW_window_src src
Definition: RGFW.h:733
+
void * userPtr
Definition: RGFW.h:740
+
RGFW_event event
Definition: RGFW.h:742