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

sokol_app.h: initial mouse position #1170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3299,6 +3299,17 @@ _SOKOL_PRIVATE void _sapp_frame(void) {
if (_sapp.first_frame) {
_sapp.first_frame = false;
_sapp_call_init();

// Send an initial mouse move event so the app knows where the cursor is
// before the mouse is actually moved.
// NOTE: This must be done after calling the app's init callback, because
// the app might want to initialize whatever will recieve the sokol events
// (e.g. dearimgui) in init. It must be done before the first frame_cb call
// so there is no frame in which the app doesn't know the mouse position.
if (_sapp_events_enabled()) {
_sapp_init_event(SAPP_EVENTTYPE_MOUSE_MOVE);
_sapp_call_event(&_sapp.event);
}
}
_sapp_call_frame();
_sapp.frame_count++;
Expand Down Expand Up @@ -4075,6 +4086,10 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
data1:0
data2:0];
[NSApp postEvent:focusevent atStart:YES];

// Update the mouse position so the app knows where the cursor is before the
// mouse is actually moved. An event is sent in _sapp_frame.
_sapp_macos_mouse_update_from_nspoint([_sapp.macos.window mouseLocationOutsideOfEventStream], true);
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
Expand Down
Loading