Skip to content

Commit 09ba0ab

Browse files
fix RGFW_mouse bugs
1 parent f0c617b commit 09ba0ab

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

RGFW.h

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,8 @@ RGFWDEF void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windo
17341734
RGFW_mouse* RGFW_hiddenMouse = NULL;
17351735
#endif
17361736

1737+
RGFW_window* RGFW_root = NULL;
1738+
17371739
/* do a basic initialization for RGFW_window, this is to standard it for each OS */
17381740
void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags flags) {
17391741
/* clear out dnd info */
@@ -1761,6 +1763,10 @@ void RGFW_window_basic_init(RGFW_window* win, RGFW_rect rect, RGFW_windowFlags f
17611763
if (flags & RGFW_windowFullscreen)
17621764
rect = RGFW_RECT(0, 0, screenR.w, screenR.h);
17631765

1766+
if (RGFW_root == NULL) {
1767+
RGFW_root = win;
1768+
}
1769+
17641770
#if defined(RGFW_X11) || defined(RGFW_WINDOWS)
17651771
if (RGFW_hiddenMouse == NULL) {
17661772
u8 RGFW_blk[] = { 0, 0, 0, 0 };
@@ -1793,8 +1799,6 @@ void RGFW_window_setBufferPtr(RGFW_window* win, u8* ptr, RGFW_area size) {
17931799
#endif
17941800
}
17951801

1796-
RGFW_window* RGFW_root = NULL;
1797-
17981802
#ifdef RGFW_MACOS
17991803
RGFWDEF void RGFW_window_cocoaSetLayer(RGFW_window* win, void* layer);
18001804
RGFWDEF void* RGFW_cocoaGetLayer(void);
@@ -2905,8 +2909,6 @@ RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowF
29052909

29062910
win->src.ctx = glXCreateContextAttribsARB((Display*) win->src.display, bestFbc, ctx, True, context_attribs);
29072911
#endif
2908-
if (RGFW_root == NULL)
2909-
RGFW_root = win;
29102912

29112913
RGFW_init_buffer(win, vi);
29122914
}
@@ -3684,7 +3686,7 @@ b32 RGFW_window_setIcon(RGFW_window* win, u8* icon, RGFW_area a, i32 channels) {
36843686
RGFW_mouse* RGFW_loadMouse(u8* icon, RGFW_area a, i32 channels) {
36853687
assert(icon);
36863688
assert(channels == 3 || channels == 4);
3687-
3689+
36883690
#ifndef RGFW_NO_X11_CURSOR
36893691
XcursorImage* native = XcursorImageCreate(a.w, a.h);
36903692
native->xhot = 0;
@@ -4236,6 +4238,11 @@ void RGFW_window_close(RGFW_window* win) {
42364238
RGFW_closeEGL(win);
42374239
#endif
42384240

4241+
if (RGFW_hiddenMouse != NULL && (RGFW_windowsOpen - 1) <= 0) {
4242+
RGFW_freeMouse(RGFW_hiddenMouse);
4243+
RGFW_hiddenMouse = 0;
4244+
}
4245+
42394246
#if defined(RGFW_OSMESA) || defined(RGFW_BUFFER)
42404247
if (win->buffer != NULL) {
42414248
if ((win->_flags & RGFW_BUFFER_ALLOC))
@@ -4305,11 +4312,6 @@ void RGFW_window_close(RGFW_window* win) {
43054312
close(RGFW_gamepads[i]);
43064313
}
43074314
#endif
4308-
4309-
if (RGFW_hiddenMouse != NULL) {
4310-
RGFW_freeMouse(RGFW_hiddenMouse);
4311-
RGFW_hiddenMouse = 0;
4312-
}
43134315
}
43144316

43154317
RGFW_clipboard_switch(NULL);
@@ -5060,10 +5062,6 @@ RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowF
50605062
RGFW_window_showMouse(win, 0);
50615063
}
50625064

5063-
if (RGFW_root == NULL) {
5064-
RGFW_root = win;
5065-
}
5066-
50675065
win->src.eventIndex = 0;
50685066
win->src.eventLen = 0;
50695067

@@ -5913,9 +5911,6 @@ RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowF
59135911

59145912
ShowWindow(win->src.window, SW_SHOWNORMAL);
59155913

5916-
if (RGFW_root == NULL)
5917-
RGFW_root = win;
5918-
59195914
#ifdef RGFW_OPENGL
59205915
else
59215916
wglShareLists(RGFW_root->src.ctx, win->src.ctx);
@@ -8052,9 +8047,6 @@ RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowF
80528047

80538048
objc_msgSend_void(NSApp, sel_registerName("finishLaunching"));
80548049

8055-
if (RGFW_root == NULL)
8056-
RGFW_root = win;
8057-
80588050
NSRetain(win->src.window);
80598051
NSRetain(NSApp);
80608052

@@ -9544,8 +9536,6 @@ RGFW_window* RGFW_createWindowPtr(const char* name, RGFW_rect rect, RGFW_windowF
95449536
RGFW_init_buffer(win);
95459537
glViewport(0, 0, rect.w, rect.h);
95469538

9547-
RGFW_root = win;
9548-
95499539
if (flags & RGFW_windowHideMouse) {
95509540
RGFW_window_showMouse(win, 0);
95519541
}

0 commit comments

Comments
 (0)