Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetCursor event + window handle #78

Closed
septag opened this issue Oct 15, 2018 · 5 comments
Closed

SetCursor event + window handle #78

septag opened this issue Oct 15, 2018 · 5 comments
Assignees

Comments

@septag
Copy link
Contributor

septag commented Oct 15, 2018

Hi,
I was wondering if sokol could implement SetCursor event for desktop apps
I don't know about linux/mac platforms, but in windows I'd like to use WM_SETCURSOR to change the cursor in gui (like imgui). I could add the support to windows easily by adding these lines to _sapp_win32_wndproc's switch:

            case WM_SETCURSOR:
                if (LOWORD(lParam) == HTCLIENT) {
                    _sapp_win32_app_event(SAPP_EVENTTYPE_SETCURSOR);
                    return 1;
                }
                break;

Also, is there any way to fetch the window handle in order to implement some extra functions like SetCapture, ReleaseCapture (for drag&drop)

@floooh floooh self-assigned this Oct 16, 2018
@floooh
Copy link
Owner

floooh commented Oct 16, 2018

Both are good suggestions. I didn't want to add complete custom-cursor-image support (at least not yet), so exposing an WM_SETCURSOR as event looks like a good first step in that direction. I need to figure out how that would work on OSX and Linux (...basically what GLFW does).

For exposing the window handles (and maybe a few other things) I think it makes sense to add platform-specific functions (similar to the sapp_d3d11_* and sapp_metal_* functions that already exist).

For instance sapp_win32_get_hwnd() to get the Win32 HWND. It would have to return a 'neutral type', like 'const void*' or maybe better 'uintptr_t', because the function should still exist when compiling on non-Windows-platforms (but return zero there).

I'll try to look into this over the next days.

@floooh
Copy link
Owner

floooh commented Oct 16, 2018

Ok, a first Windows version is in:

656f085

I had to add a member ".user_cursor" to the sapp_desc struct, and in order to receive SAPP_EVENTTYPE_UPDATE_CURSOR events you'll need to set this to true. The reason for this is that Windows won't update the "system mouse cursor" image anymore if WM_SETCURSOR returns with 1 (or TRUE), so I only do this when the user requests to manage the cursor image/visibility himself.

I also found a difference between MacOS and Windows: on Windows, WM_SETCURSOR is sent each frame when the mouse is moved inside the window client area. On Mac, a similar message is only sent once when the mouse enters the window.

In your use case, do you require the Windows behaviour (sent each frame when mouse moves in window), or would you be ok with only receiving a single message when the mouse enters the window?

PS: there's now also a function const void* sapp_win32_get_hwnd(). On Windows, this returns the HWND, on other platforms null.

@septag
Copy link
Contributor Author

septag commented Oct 17, 2018

awesome, works in windows
thanks

@floooh
Copy link
Owner

floooh commented Feb 11, 2021

Closing this, although "proper" cursor image handling would be nice. Should be a separate issue though.

@floooh
Copy link
Owner

floooh commented Jul 6, 2022

Hi @septag sokol_app.h is getting "official" cursor types support now (basically the cursor images required by Dear ImGui, see: #678

Because of this I would like to remove the entire "user cursor" stuff (SAPP_EVENTTYPE_UPDATE_CURSOR and sapp_desc.user_cursor). Any objectsion from your side? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants