@@ -198,6 +198,8 @@ int main() {
198198
199199 #define RGFW_MEMCPY (dist , src , len ) memcpy(dist, src, len)
200200 #define RGFW_STRNCMP (s1 , s2 , max ) strncmp(s1, s2, max)
201+ //required for X11
202+ #define RGFW_STRTOL (str , endptr , base ) strtol(str, endptr, base)
201203#endif
202204
203205#if !_MSC_VER
@@ -2643,8 +2645,8 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, RGFW_windowArgs
26432645
26442646 XInitThreads (); /*!< init X11 threading*/
26452647
2646- // if (args & RGFW_openglSoftware)
2647- // setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
2648+ if (args & RGFW_openglSoftware )
2649+ setenv ("LIBGL_ALWAYS_SOFTWARE" , "1" , 1 );
26482650
26492651 RGFW_window * win = RGFW_window_basic_init (rect , args );
26502652
@@ -3312,7 +3314,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {
33123314 while (* line ) {
33133315 if (line [0 ] == '%' && line [1 ] && line [2 ]) {
33143316 const char digits [3 ] = { line [1 ], line [2 ], '\0' };
3315- path [index ] = (char ) strtol (digits , NULL , 16 );
3317+ path [index ] = (char ) RGFW_STRTOL (digits , NULL , 16 );
33163318 line += 2 ;
33173319 } else
33183320 path [index ] = * line ;
@@ -3940,39 +3942,43 @@ RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
39403942
39413943 float dpi = XGetSystemContentDPI (display , screen );
39423944 monitor .pixelRatio = dpi / 96.0f ;
3943- XRRScreenResources * sr = XRRGetScreenResourcesCurrent (display , RootWindow (display , screen ));
39443945
3945- XRRCrtcInfo * ci = NULL ;
3946- int crtc = screen ;
3946+ #ifndef RGFW_NO_DPI
3947+ XRRScreenResources * sr = XRRGetScreenResourcesCurrent ( display , RootWindow ( display , screen )) ;
39473948
3948- if (sr -> ncrtc > crtc ) {
3949- ci = XRRGetCrtcInfo (display , sr , sr -> crtcs [crtc ]);
3950- }
3949+ XRRCrtcInfo * ci = NULL ;
3950+ int crtc = screen ;
3951+
3952+ if (sr -> ncrtc > crtc ) {
3953+ ci = XRRGetCrtcInfo (display , sr , sr -> crtcs [crtc ]);
3954+ }
3955+ #endif
39513956
39523957 float ppi_width = RGFW_ROUND ((float )monitor .rect .w /(float )monitor .physW );
39533958 float ppi_height = RGFW_ROUND ((float )monitor .rect .h /(float )monitor .physH );
39543959
39553960 monitor .scaleX = (float ) (ppi_width ) / dpi ;
39563961 monitor .scaleY = (float ) (ppi_height ) / dpi ;
39573962
3958- XRROutputInfo * info = XRRGetOutputInfo (display , sr , sr -> outputs [screen ]);
3959-
3960- if (info == NULL || ci == NULL ) {
3961- XRRFreeScreenResources (sr );
3962- XCloseDisplay (display );
3963+ #ifndef RGFW_NO_DPI
3964+ XRROutputInfo * info = XRRGetOutputInfo (display , sr , sr -> outputs [screen ]);
39633965
3964- #ifdef RGFW_DEBUG
3965- 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 );
3966- #endif
3967- return monitor ;
3968- }
3969-
3970-
3971- float physW = info -> mm_width / 25.4 ;
3972- float physH = info -> mm_height / 25.4 ;
3966+ if ( info == NULL || ci == NULL ) {
3967+ XRRFreeScreenResources ( sr );
3968+ XCloseDisplay ( display );
3969+
3970+ #ifdef RGFW_DEBUG
3971+ 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 );
3972+ #endif
3973+ return monitor ;
3974+ }
39733975
3974- RGFW_MEMCPY (monitor .name , info -> name , 128 );
39753976
3977+ float physW = info -> mm_width / 25.4 ;
3978+ float physH = info -> mm_height / 25.4 ;
3979+
3980+ RGFW_MEMCPY (monitor .name , info -> name , 128 );
3981+
39763982 if (physW && physH ) {
39773983 monitor .physW = physW ;
39783984 monitor .physH = physH ;
@@ -3983,10 +3989,12 @@ RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
39833989
39843990 float w = ci -> width ;
39853991 float h = ci -> height ;
3992+
39863993 if (w && h ) {
39873994 monitor .rect .w = w ;
39883995 monitor .rect .h = h ;
39893996 }
3997+ #endif
39903998
39913999 if (monitor .physW == 0 || monitor .physH == 0 ) {
39924000 monitor .scaleX = 0 ;
@@ -4005,8 +4013,10 @@ RGFW_monitor RGFW_XCreateMonitor(i32 screen) {
40054013 monitor .scaleY = 1 ;
40064014 }
40074015
4008- XRRFreeCrtcInfo (ci );
4009- XRRFreeScreenResources (sr );
4016+ #ifndef RGFW_NO_DPI
4017+ XRRFreeCrtcInfo (ci );
4018+ XRRFreeScreenResources (sr );
4019+ #endif
40104020
40114021 XCloseDisplay (display );
40124022
@@ -4034,16 +4044,17 @@ RGFW_monitor RGFW_getPrimaryMonitor(void) {
40344044RGFW_monitor RGFW_window_getMonitor (RGFW_window * win ) {
40354045 RGFW_ASSERT (win != NULL );
40364046
4037- XRRScreenResources * screenRes = XRRGetScreenResources (win -> src .display , DefaultRootWindow (win -> src .display ));
4038- if (screenRes == NULL ) {
4039- return (RGFW_monitor ){};
4040- }
4041-
40424047 XWindowAttributes attrs ;
40434048 if (!XGetWindowAttributes (win -> src .display , win -> src .window , & attrs )) {
40444049 return (RGFW_monitor ){};
40454050 }
40464051
4052+ #ifndef RGFW_NO_DPI
4053+ XRRScreenResources * screenRes = XRRGetScreenResources (win -> src .display , DefaultRootWindow (win -> src .display ));
4054+ if (screenRes == NULL ) {
4055+ return (RGFW_monitor ){};
4056+ }
4057+
40474058 for (int i = 0 ; i < screenRes -> ncrtc ; i ++ ) {
40484059 XRRCrtcInfo * crtcInfo = XRRGetCrtcInfo (win -> src .display , screenRes , screenRes -> crtcs [i ]);
40494060 if (!crtcInfo ) continue ;
@@ -4066,6 +4077,15 @@ RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) {
40664077 }
40674078
40684079 XRRFreeScreenResources (screenRes );
4080+ #else
4081+ size_t i ;
4082+ for (i = 0 ; i < (size_t )ScreenCount (RGFW_root -> src .display ) && i < 6 ; i ++ ) {
4083+ Screen * screen = ScreenOfDisplay (RGFW_root -> src .display , i );
4084+ if (attrs .x >= 0 && attrs .x < 0 + XWidthOfScreen (screen ) &&
4085+ attrs .y >= 0 && attrs .y < 0 + XHeightOfScreen (screen ))
4086+ return RGFW_XCreateMonitor (i );
4087+ }
4088+ #endif
40694089 return (RGFW_monitor ){};
40704090}
40714091
@@ -6914,19 +6934,19 @@ void RGFW_window_swapInterval(RGFW_window* win, i32 swapInterval) {
69146934#endif
69156935
69166936void RGFW_window_swapBuffers (RGFW_window * win ) {
6917- //RGFW_ASSERT(win != NULL);
6918- /* clear the window*/
6919-
6920- if (!(win -> _winArgs & RGFW_noCPURender )) {
6921- #if defined(RGFW_OSMESA ) || defined(RGFW_BUFFER )
6922- #ifdef RGFW_OSMESA
6923- RGFW_OSMesa_reorganize ();
6924- #endif
6925- HGDIOBJ oldbmp = SelectObject (win -> src .hdcMem , win -> src .bitmap );
6926- BitBlt (win -> src .hdc , 0 , 0 , win -> r .w , win -> r .h , win -> src .hdcMem , 0 , 0 , SRCCOPY );
6927- SelectObject (win -> src .hdcMem , oldbmp );
6937+ RGFW_ASSERT (win != NULL );
6938+ /* clear the window*/
6939+
6940+ if (!(win -> _winArgs & RGFW_noCPURender )) {
6941+ #if defined(RGFW_OSMESA ) || defined(RGFW_BUFFER )
6942+ #ifdef RGFW_OSMESA
6943+ RGFW_OSMesa_reorganize ();
69286944 #endif
6929- }
6945+ HGDIOBJ oldbmp = SelectObject (win -> src .hdcMem , win -> src .bitmap );
6946+ BitBlt (win -> src .hdc , 0 , 0 , win -> r .w , win -> r .h , win -> src .hdcMem , 0 , 0 , SRCCOPY );
6947+ SelectObject (win -> src .hdcMem , oldbmp );
6948+ #endif
6949+ }
69306950
69316951 if (!(win -> _winArgs & RGFW_noGPURender )) {
69326952 #ifdef RGFW_EGL
0 commit comments