Fix macOS builds

This commit is contained in:
Cacodemon345
2021-12-01 11:15:42 +06:00
parent cee1c93d49
commit 2297c33751
6 changed files with 22 additions and 23 deletions

View File

@@ -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

View File

@@ -7,4 +7,4 @@ public:
CocoaEventFilter() {};
~CocoaEventFilter();
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
};
};

View File

@@ -1,5 +1,5 @@
#include <SDL.h>
#include "86box/plat.h"
//#include "86box/plat.h"
#include "cocoa_mouse.hpp"
#import <AppKit/AppKit.h>
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;
}

View File

@@ -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)

View File

@@ -29,6 +29,8 @@ extern uint64_t tsc;
#include <QTimer>
#include <QStatusBar>
#include <array>
namespace {
struct PixmapSetActive {
QPixmap normal;

View File

@@ -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<int*>(ret);
return (retval < 0) ? nullptr : ret;
#endif
#endif
}
void