Skip to content

Commit

Permalink
Merge remote-tracking branch 'floooh/master' into sokol-audio-android…
Browse files Browse the repository at this point in the history
…-aaudio
  • Loading branch information
oviano committed Feb 24, 2021
2 parents 2b5b75a + 4cd2da8 commit 39bad15
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,28 @@ jobs:
run: |
cd workspace/sokol-samples
python fips make cube-emsc wasm-ninja-release
# android:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - name: prepare
# run: |
# mkdir workspace
# cd workspace
# git clone https://github.com/floooh/sokol-samples
# cd sokol-samples
# yes | python fips setup android
# - name: sapp-android-make-debug
# run: |
# cd workspace/sokol-samples
# python fips build sapp-android-make-debug
# - name: sapp-android-make-release
# run: |
# cd workspace/sokol-samples
# python fips build sapp-android-make-release
android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '8'
- name: prepare
run: |
mkdir workspace
cd workspace
git clone https://github.com/floooh/sokol-samples
cd sokol-samples
yes | python fips setup android
- name: sapp-android-make-debug
run: |
cd workspace/sokol-samples
python fips build sapp-android-make-debug
- name: sapp-android-make-release
run: |
cd workspace/sokol-samples
python fips build sapp-android-make-release
uwp:
runs-on: windows-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Updates

> NOTE: this list will usually only be updated with changes that affect the public APIs
- **22-Feb-2021**: Mouse input latency in sokol_app.h's macOS backend has been
quite significantly reduced, please see the detailed explanation [in this
PR](https://github.com/floooh/sokol/pull/483). Many thanks to @randrew for
the PR!

- **19-Feb-2021**: sokol_app.h learned some Windows-specific config options
to redirect stdout/stderr to the parent terminal or a separate console
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Simple
[STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)
cross-platform libraries for C and C++, written in C.

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**19-Feb-2021**: sokol_app.h learned some Windows-specific stdout/stderr console configuration options)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**22-Feb-2021** sokol_app.h: mouse latency reduction on macOS)

## Examples and Related Projects

Expand Down
69 changes: 61 additions & 8 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,12 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#if !defined(SOKOL_WIN32_FORCE_MAIN)
#pragma comment (linker, "/subsystem:windows")
#if !defined(SOKOL_NO_ENTRY) // if SOKOL_NO_ENTRY is defined, it's the applications' responsibility to use the right subsystem
#if defined(SOKOL_WIN32_FORCE_MAIN)
#pragma comment (linker, "/subsystem:console")
#else
#pragma comment (linker, "/subsystem:windows")
#endif
#endif
#include <stdio.h> /* freopen() */

Expand Down Expand Up @@ -2954,9 +2958,9 @@ _SOKOL_PRIVATE void _sapp_macos_update_window_title(void) {
[_sapp.macos.window setTitle: [NSString stringWithUTF8String:_sapp.window_title]];
}

_SOKOL_PRIVATE void _sapp_macos_update_mouse(void) {
_SOKOL_PRIVATE void _sapp_macos_update_mouse(NSEvent* event) {
if (!_sapp.mouse.locked) {
const NSPoint mouse_pos = [_sapp.macos.window mouseLocationOutsideOfEventStream];
const NSPoint mouse_pos = event.locationInWindow;
float new_x = mouse_pos.x * _sapp.dpi_scale;
float new_y = _sapp.framebuffer_height - (mouse_pos.y * _sapp.dpi_scale) - 1;
/* don't update dx/dy in the very first update */
Expand Down Expand Up @@ -2998,19 +3002,16 @@ _SOKOL_PRIVATE void _sapp_macos_lock_mouse(bool lock) {
stack with calls to sapp_show_mouse()
*/
if (_sapp.mouse.locked) {
[NSEvent setMouseCoalescingEnabled:NO];
CGAssociateMouseAndMouseCursorPosition(NO);
CGDisplayHideCursor(kCGDirectMainDisplay);
}
else {
CGDisplayShowCursor(kCGDirectMainDisplay);
CGAssociateMouseAndMouseCursorPosition(YES);
[NSEvent setMouseCoalescingEnabled:YES];
}
}

_SOKOL_PRIVATE void _sapp_macos_frame(void) {
_sapp_macos_update_mouse();
_sapp_frame();
if (_sapp.quit_requested || _sapp.quit_ordered) {
[_sapp.macos.window performClose:nil];
Expand Down Expand Up @@ -3120,6 +3121,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}
[_sapp.macos.window makeKeyAndOrderFront:nil];
_sapp_macos_update_dimensions();
[NSEvent setMouseCoalescingEnabled:NO];
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
Expand Down Expand Up @@ -3193,7 +3195,9 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
backing:(NSBackingStoreType)backingStoreType
defer:(BOOL)flag {
if (self = [super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:flag]) {
[self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]];
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
[self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]];
#endif
}
return self;
}
Expand All @@ -3207,6 +3211,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}

- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
NSPasteboard *pboard = [sender draggingPasteboard];
if ([pboard.types containsObject:NSPasteboardTypeFileURL]) {
_sapp_clear_drop_buffer();
Expand All @@ -3232,6 +3237,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}
return YES;
}
#endif
return NO;
}
@end
Expand Down Expand Up @@ -3264,8 +3270,42 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}
#endif

_SOKOL_PRIVATE void _sapp_macos_poll_input_events() {
const NSEventMask mask = NSEventMaskLeftMouseDown |
NSEventMaskLeftMouseUp|
NSEventMaskRightMouseDown |
NSEventMaskRightMouseUp |
NSEventMaskMouseMoved |
NSEventMaskLeftMouseDragged |
NSEventMaskRightMouseDragged |
NSEventMaskMouseEntered |
NSEventMaskMouseExited |
NSEventMaskKeyDown |
NSEventMaskKeyUp |
NSEventMaskCursorUpdate |
NSEventMaskScrollWheel |
NSEventMaskTabletPoint |
NSEventMaskTabletProximity |
NSEventMaskOtherMouseDown |
NSEventMaskOtherMouseUp |
NSEventMaskOtherMouseDragged |
NSEventMaskPressure |
NSEventMaskDirectTouch;
@autoreleasepool {
for (;;) {
NSEvent* event = [NSApp nextEventMatchingMask:mask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
if (event == nil) {
break;
}
[NSApp sendEvent:event];
}
}
}

- (void)drawRect:(NSRect)rect {
_SOKOL_UNUSED(rect);
/* Catch any last-moment input events */
_sapp_macos_poll_input_events();
_sapp_macos_frame();
#if !defined(SOKOL_METAL)
[[_sapp.macos.view openGLContext] flushBuffer];
Expand Down Expand Up @@ -3297,6 +3337,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
[super updateTrackingAreas];
}
- (void)mouseEntered:(NSEvent*)event {
_sapp_macos_update_mouse(event);
/* don't send mouse enter/leave while dragging (so that it behaves the same as
on Windows while SetCapture is active
*/
Expand All @@ -3305,39 +3346,47 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}
}
- (void)mouseExited:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (0 == _sapp.macos.mouse_buttons) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_LEAVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mod(event.modifierFlags));
}
}
- (void)mouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_LEFT);
}
- (void)mouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_LEFT, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_LEFT);
}
- (void)rightMouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_RIGHT);
}
- (void)rightMouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_RIGHT, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons &= ~(1<<SAPP_MOUSEBUTTON_RIGHT);
}
- (void)otherMouseDown:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_DOWN, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons |= (1<<SAPP_MOUSEBUTTON_MIDDLE);
}
}
- (void)otherMouseUp:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (2 == event.buttonNumber) {
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_UP, SAPP_MOUSEBUTTON_MIDDLE, _sapp_macos_mod(event.modifierFlags));
_sapp.macos.mouse_buttons &= (1<<SAPP_MOUSEBUTTON_MIDDLE);
}
}
- (void)otherMouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (2 == event.buttonNumber) {
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
Expand All @@ -3347,27 +3396,31 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
}
}
- (void)mouseMoved:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mod(event.modifierFlags));
}
- (void)mouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID , _sapp_macos_mod(event.modifierFlags));
}
- (void)rightMouseDragged:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (_sapp.mouse.locked) {
_sapp.mouse.dx = [event deltaX];
_sapp.mouse.dy = [event deltaY];
}
_sapp_macos_mouse_event(SAPP_EVENTTYPE_MOUSE_MOVE, SAPP_MOUSEBUTTON_INVALID, _sapp_macos_mod(event.modifierFlags));
}
- (void)scrollWheel:(NSEvent*)event {
_sapp_macos_update_mouse(event);
if (_sapp_events_enabled()) {
float dx = (float) event.scrollingDeltaX;
float dy = (float) event.scrollingDeltaY;
Expand Down
2 changes: 2 additions & 0 deletions sokol_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,9 @@ _SOKOL_PRIVATE void _saudio_backend_shutdown(void) { };

-(void)dealloc {
[self remove_handler];
#if !__has_feature(objc_arc)
[super dealloc];
#endif
}

-(void)remove_handler {
Expand Down

0 comments on commit 39bad15

Please sign in to comment.