Completely reworked mouse handling - should now be smoother due to there no longer being a multi-layered game of telephone going on with all the various interim coordinate counters, also rewritten the serial mouse emulation ground ground up.
This commit is contained in:
@@ -49,26 +49,19 @@
|
||||
extern "C" {
|
||||
#include <86box/86box.h>
|
||||
#include <86box/config.h>
|
||||
#include <86box/mouse.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/video.h>
|
||||
|
||||
double mouse_sensitivity = 1.0;
|
||||
double mouse_x_error = 0.0, mouse_y_error = 0.0;
|
||||
#include <86box/mouse.h>
|
||||
}
|
||||
|
||||
struct mouseinputdata {
|
||||
atomic_int deltax;
|
||||
atomic_int deltay;
|
||||
atomic_int deltaz;
|
||||
atomic_int mousebuttons;
|
||||
atomic_bool mouse_tablet_in_proximity;
|
||||
|
||||
std::atomic<double> x_abs;
|
||||
std::atomic<double> y_abs;
|
||||
};
|
||||
static mouseinputdata mousedata;
|
||||
|
||||
extern "C" void macos_poll_mouse();
|
||||
extern MainWindow *main_window;
|
||||
RendererStack::RendererStack(QWidget *parent, int monitor_index)
|
||||
: QStackedWidget(parent)
|
||||
@@ -94,29 +87,21 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index)
|
||||
# ifdef WAYLAND
|
||||
if (!stricmp(mouse_type, "wayland")) {
|
||||
wl_init();
|
||||
this->mouse_poll_func = wl_mouse_poll;
|
||||
this->mouse_capture_func = wl_mouse_capture;
|
||||
this->mouse_uncapture_func = wl_mouse_uncapture;
|
||||
}
|
||||
# endif
|
||||
# ifdef EVDEV_INPUT
|
||||
if (!stricmp(mouse_type, "evdev")) {
|
||||
if (!stricmp(mouse_type, "evdev"))
|
||||
evdev_init();
|
||||
this->mouse_poll_func = evdev_mouse_poll;
|
||||
}
|
||||
# endif
|
||||
if (!stricmp(mouse_type, "xinput2")) {
|
||||
extern void xinput2_init();
|
||||
extern void xinput2_poll();
|
||||
extern void xinput2_exit();
|
||||
xinput2_init();
|
||||
this->mouse_poll_func = xinput2_poll;
|
||||
this->mouse_exit_func = xinput2_exit;
|
||||
}
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
this->mouse_poll_func = macos_poll_mouse;
|
||||
#endif
|
||||
}
|
||||
|
||||
RendererStack::~RendererStack()
|
||||
@@ -149,49 +134,25 @@ RendererStack::mousePoll()
|
||||
{
|
||||
if (m_monitor_index >= 1) {
|
||||
if (mouse_mode >= 1) {
|
||||
mouse_x_abs = mousedata.x_abs;
|
||||
mouse_y_abs = mousedata.y_abs;
|
||||
if (!mouse_tablet_in_proximity) {
|
||||
mouse_x_abs = mousedata.x_abs;
|
||||
mouse_y_abs = mousedata.y_abs;
|
||||
if (!mouse_tablet_in_proximity)
|
||||
mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity;
|
||||
}
|
||||
if (mousedata.mouse_tablet_in_proximity) {
|
||||
mouse_buttons = mousedata.mousebuttons;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
if (mouse_mode == 0) {
|
||||
mouse_x_abs = mousedata.x_abs;
|
||||
mouse_y_abs = mousedata.y_abs;
|
||||
mouse_x_abs = mousedata.x_abs;
|
||||
mouse_y_abs = mousedata.y_abs;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __APPLE__
|
||||
mouse_x = mousedata.deltax;
|
||||
mouse_y = mousedata.deltay;
|
||||
mouse_z = mousedata.deltaz;
|
||||
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
|
||||
mouse_buttons = mousedata.mousebuttons;
|
||||
|
||||
if (this->mouse_poll_func)
|
||||
#endif
|
||||
this->mouse_poll_func();
|
||||
|
||||
mouse_x_abs = mousedata.x_abs;
|
||||
mouse_y_abs = mousedata.y_abs;
|
||||
mouse_tablet_in_proximity = mousedata.mouse_tablet_in_proximity;
|
||||
|
||||
double scaled_x = mouse_x * mouse_sensitivity + mouse_x_error;
|
||||
double scaled_y = mouse_y * mouse_sensitivity + mouse_y_error;
|
||||
|
||||
mouse_x = static_cast<int>(scaled_x);
|
||||
mouse_y = static_cast<int>(scaled_y);
|
||||
|
||||
mouse_x_error = scaled_x - mouse_x;
|
||||
mouse_y_error = scaled_y - mouse_y;
|
||||
}
|
||||
|
||||
int ignoreNextMouseEvent = 1;
|
||||
@@ -212,8 +173,9 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event)
|
||||
isMouseDown &= ~1;
|
||||
return;
|
||||
}
|
||||
if (mouse_capture || mouse_mode >= 1) {
|
||||
mousedata.mousebuttons &= ~event->button();
|
||||
if (mouse_capture || (mouse_mode >= 1)) {
|
||||
if ((mouse_mode >= 1) && ((m_monitor_index < 1) || mousedata.mouse_tablet_in_proximity))
|
||||
mouse_set_buttons_ex(mouse_get_buttons_ex() & ~event->button());
|
||||
}
|
||||
isMouseDown &= ~1;
|
||||
}
|
||||
@@ -222,8 +184,9 @@ void
|
||||
RendererStack::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
isMouseDown |= 1;
|
||||
if (mouse_capture || mouse_mode >= 1) {
|
||||
mousedata.mousebuttons |= event->button();
|
||||
if (mouse_capture || (mouse_mode >= 1)) {
|
||||
if ((mouse_mode >= 1) && ((m_monitor_index < 1) || mousedata.mouse_tablet_in_proximity))
|
||||
mouse_set_buttons_ex(mouse_get_buttons_ex() | event->button());
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
@@ -231,9 +194,7 @@ RendererStack::mousePressEvent(QMouseEvent *event)
|
||||
void
|
||||
RendererStack::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (mouse_capture) {
|
||||
mousedata.deltaz += event->pixelDelta().y();
|
||||
}
|
||||
mouse_set_z(event->pixelDelta().y());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -258,8 +219,12 @@ RendererStack::mouseMoveEvent(QMouseEvent *event)
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
mousedata.deltax += event->pos().x() - oldPos.x();
|
||||
mousedata.deltay += event->pos().y() - oldPos.y();
|
||||
|
||||
#if defined __unix__ && !defined __HAIKU__
|
||||
if (!stricmp(mouse_type, "wayland"))
|
||||
mouse_scale(event->pos().x() - oldPos.x(), event->pos().y() - oldPos.y());
|
||||
#endif
|
||||
|
||||
if (QApplication::platformName() == "eglfs") {
|
||||
leaveEvent((QEvent *) event);
|
||||
ignoreNextMouseEvent--;
|
||||
|
||||
Reference in New Issue
Block a user