From 2297c337513d4facaf7fe326b647fe100818cc7d Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 1 Dec 2021 11:15:42 +0600 Subject: [PATCH] Fix macOS builds --- src/qt/CMakeLists.txt | 2 +- src/qt/cocoa_mouse.hpp | 2 +- src/qt/macos_event_filter.mm | 31 ++++++++++++------------------- src/qt/qt_gleswidget.cpp | 6 +++++- src/qt/qt_machinestatus.cpp | 2 ++ src/qt/qt_platform.cpp | 2 +- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index bf4b561c0..b3ce7121b 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(ui STATIC qt_mainwindow.ui qt_machinestatus.cpp qt_machinestatus.hpp - qt_machinestatus.ui + #qt_machinestatus.ui qt_gleswidget.cpp qt_gleswidget.hpp diff --git a/src/qt/cocoa_mouse.hpp b/src/qt/cocoa_mouse.hpp index 83939a233..6d481fd89 100644 --- a/src/qt/cocoa_mouse.hpp +++ b/src/qt/cocoa_mouse.hpp @@ -7,4 +7,4 @@ public: CocoaEventFilter() {}; ~CocoaEventFilter(); virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; -}; \ No newline at end of file +}; diff --git a/src/qt/macos_event_filter.mm b/src/qt/macos_event_filter.mm index e942b5f49..4dd7ef2ae 100644 --- a/src/qt/macos_event_filter.mm +++ b/src/qt/macos_event_filter.mm @@ -1,5 +1,5 @@ #include -#include "86box/plat.h" +//#include "86box/plat.h" #include "cocoa_mouse.hpp" #import extern "C" @@ -15,6 +15,7 @@ extern "C" #include <86box/ui.h> #include <86box/video.h> extern int mouse_capture; +extern void plat_mouse_capture(int); } typedef struct mouseinputdata @@ -23,8 +24,7 @@ typedef struct mouseinputdata int mousebuttons; } mouseinputdata; -extern SDL_mutex* mousemutex; -extern mouseinputdata mousedata; +static mouseinputdata mousedata; CocoaEventFilter::~CocoaEventFilter() { @@ -40,17 +40,13 @@ bool CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *mess NSEvent* event = (NSEvent*)message; if ([event type] == NSEventTypeMouseMoved) { - SDL_LockMutex(mousemutex); mousedata.deltax += [event deltaX]; mousedata.deltay += [event deltaY]; - SDL_UnlockMutex(mousemutex); return true; } if ([event type] == NSEventTypeScrollWheel) { - SDL_LockMutex(mousemutex); mousedata.deltaz += [event deltaY]; - SDL_UnlockMutex(mousemutex); return true; } switch ([event type]) @@ -58,45 +54,33 @@ bool CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *mess default: return false; case NSEventTypeLeftMouseDown: { - SDL_LockMutex(mousemutex); mousedata.mousebuttons |= 1; - SDL_UnlockMutex(mousemutex); break; } case NSEventTypeLeftMouseUp: { - SDL_LockMutex(mousemutex); mousedata.mousebuttons &= ~1; - SDL_UnlockMutex(mousemutex); break; } case NSEventTypeRightMouseDown: { - SDL_LockMutex(mousemutex); mousedata.mousebuttons |= 2; - SDL_UnlockMutex(mousemutex); break; } case NSEventTypeRightMouseUp: { - SDL_LockMutex(mousemutex); mousedata.mousebuttons &= ~2; - SDL_UnlockMutex(mousemutex); break; } case NSEventTypeOtherMouseDown: { - SDL_LockMutex(mousemutex); mousedata.mousebuttons |= 4; - SDL_UnlockMutex(mousemutex); break; } case NSEventTypeOtherMouseUp: { if (mouse_get_buttons() < 3) { plat_mouse_capture(0); return true; } - SDL_LockMutex(mousemutex); mousedata.mousebuttons &= ~4; - SDL_UnlockMutex(mousemutex); break; } } @@ -105,3 +89,12 @@ bool CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *mess } return false; } + +extern "C" void macos_poll_mouse() +{ + mouse_x = mousedata.deltax; + mouse_y = mousedata.deltay; + mouse_z = mousedata.deltaz; + mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; + mouse_buttons = mousedata.mousebuttons; +} diff --git a/src/qt/qt_gleswidget.cpp b/src/qt/qt_gleswidget.cpp index 3cd91c5a7..24c9e4a36 100644 --- a/src/qt/qt_gleswidget.cpp +++ b/src/qt/qt_gleswidget.cpp @@ -11,7 +11,7 @@ extern "C" #include <86box/video.h> } - +extern "C" void macos_poll_mouse(); void qt_mouse_capture(int on) { @@ -34,11 +34,15 @@ qt_mouse_capture(int on) void GLESWidget::qt_mouse_poll() { +#ifdef __APPLE__ + return macos_poll_mouse(); +#else mouse_x = mousedata.deltax; mouse_y = mousedata.deltay; mouse_z = mousedata.deltaz; mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; +#endif } void GLESWidget::resizeGL(int w, int h) diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index d61e2f04a..b2c8d0ad1 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -29,6 +29,8 @@ extern uint64_t tsc; #include #include +#include + namespace { struct PixmapSetActive { QPixmap normal; diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 47a771442..6be563814 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -283,10 +283,10 @@ plat_mmap(size_t size, uint8_t executable) void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE | (executable ? MAP_JIT : 0), 0, 0); #else void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, 0, 0); +#endif auto retval = *reinterpret_cast(ret); return (retval < 0) ? nullptr : ret; #endif -#endif } void