From 3b74aad9d619c8144e719cb10e0ab2aec62181fd Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 1 Jun 2022 15:31:58 +0600 Subject: [PATCH 1/5] qt: Add mouse sensitivity setting --- src/config.c | 11 +++ src/include/86box/86box.h | 1 + src/qt/qt_progsettings.cpp | 10 +++ src/qt/qt_progsettings.hpp | 3 + src/qt/qt_progsettings.ui | 141 +++++++++++++++++++++++------------- src/qt/qt_rendererstack.cpp | 5 ++ src/unix/unix_sdl.c | 1 + src/win/win_mouse.c | 1 + 8 files changed, 122 insertions(+), 51 deletions(-) diff --git a/src/config.c b/src/config.c index 6f923b28a..763453a36 100644 --- a/src/config.c +++ b/src/config.c @@ -599,6 +599,12 @@ load_general(void) lang_id = plat_language_code(p); } + mouse_sensitivity = config_get_double(cat, "mouse_sensitivity", 1.0); + if (mouse_sensitivity < 0.5) + mouse_sensitivity = 0.5; + else if (mouse_sensitivity > 2.0) + mouse_sensitivity = 2.0; + p = config_get_string(cat, "iconset", NULL); if (p != NULL) strcpy(icon_set, p); @@ -2307,6 +2313,11 @@ save_general(void) else config_delete_var(cat, "confirm_save"); + if (mouse_sensitivity != 1.0) + config_set_double(cat, "mouse_sensitivity", mouse_sensitivity); + else + config_delete_var(cat, "mouse_sensitivity"); + if (lang_id == DEFAULT_LANGUAGE) config_delete_var(cat, "language"); else diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 220d120fa..61269fddb 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -131,6 +131,7 @@ extern int enable_discord; /* (C) enable Discord integration */ extern int is_pentium; /* TODO: Move back to cpu/cpu.h when it's figured out, how to remove that hack from the ET4000/W32p. */ extern int fixed_size_x, fixed_size_y; +extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */ extern char exe_path[2048]; /* path (dir) of executable */ diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index d5bfdaa2f..3d895cf41 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -110,6 +110,9 @@ ProgSettings::ProgSettings(QWidget *parent) : ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i.key())); } } + + mouseSensitivity = mouse_sensitivity; + ui->horizontalSlider->setValue(mouseSensitivity * 100.); } void ProgSettings::accept() @@ -132,6 +135,7 @@ void ProgSettings::accept() connect(main_window, &MainWindow::updateStatusBarActivity, main_window->status.get(), &MachineStatus::setActivity); connect(main_window, &MainWindow::updateStatusBarEmpty, main_window->status.get(), &MachineStatus::setEmpty); connect(main_window, &MainWindow::statusBarMessage, main_window->status.get(), &MachineStatus::message, Qt::QueuedConnection); + mouse_sensitivity = mouseSensitivity; QDialog::accept(); } @@ -193,3 +197,9 @@ void ProgSettings::on_pushButtonLanguage_released() { ui->comboBoxLanguage->setCurrentIndex(0); } + +void ProgSettings::on_horizontalSlider_valueChanged(int value) +{ + mouseSensitivity = (double)value / 100.; +} + diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp index 75fba149a..6e0b49c8c 100644 --- a/src/qt/qt_progsettings.hpp +++ b/src/qt/qt_progsettings.hpp @@ -57,10 +57,13 @@ private slots: void on_pushButton_released(); void on_pushButtonLanguage_released(); + void on_horizontalSlider_valueChanged(int value); + private: Ui::ProgSettings *ui; friend class MainWindow; + double mouseSensitivity; }; #endif // QT_PROGSETTINGS_HPP diff --git a/src/qt/qt_progsettings.ui b/src/qt/qt_progsettings.ui index b64272f8b..11bb39b74 100644 --- a/src/qt/qt_progsettings.ui +++ b/src/qt/qt_progsettings.ui @@ -6,35 +6,38 @@ 0 0 - 370 - 228 + 458 + 303 - 370 - 228 + 0 + 0 - 370 - 228 + 16777215 + 16777215 Preferences - - + + QLayout::SetFixedSize + + + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 @@ -48,6 +51,13 @@ + + + + Mouse sensitivity: + + + @@ -55,26 +65,7 @@ - - - - Language: - - - - - - - false - - - - (Default) - - - - - + Qt::Horizontal @@ -84,6 +75,47 @@ + + + + Default + + + + + + + Icon set: + + + + + + + Default + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Language: + + + @@ -97,32 +129,39 @@ - - - - Icon set: + + + + 50 - - - - - - Default + + 200 + + + 10 + + + 20 + + + 100 - - - - Qt::Horizontal - - - 40 - 20 - + + + + + + false - + + + (Default) + + + diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 1b43fe70c..cafba579b 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -44,6 +44,8 @@ extern "C" { #include <86box/mouse.h> #include <86box/plat.h> #include <86box/video.h> + +double mouse_sensitivity = 1.0; } extern "C" void macos_poll_mouse(); @@ -123,6 +125,9 @@ RendererStack::mousePoll() if (this->mouse_poll_func) #endif this->mouse_poll_func(); + + mouse_x *= mouse_sensitivity; + mouse_y *= mouse_sensitivity; } int ignoreNextMouseEvent = 1; diff --git a/src/unix/unix_sdl.c b/src/unix/unix_sdl.c index d86b5f72c..aeeb9d60c 100644 --- a/src/unix/unix_sdl.c +++ b/src/unix/unix_sdl.c @@ -43,6 +43,7 @@ int title_set = 0; int resize_pending = 0; int resize_w = 0; int resize_h = 0; +double mouse_sensitivity = 1.0; /* Unused. */ static uint8_t interpixels[17842176]; extern void RenderImGui(); diff --git a/src/win/win_mouse.c b/src/win/win_mouse.c index e5d1c229a..b69646a6e 100644 --- a/src/win/win_mouse.c +++ b/src/win/win_mouse.c @@ -28,6 +28,7 @@ #include <86box/win.h> int mouse_capture; +double mouse_sensitivity = 1.0; /* Unused. */ typedef struct { int buttons; From 0636e1cbbcc13502d727485074d1dc9819d583ca Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 1 Jun 2022 16:31:06 +0600 Subject: [PATCH 2/5] qt: Make default button actually work --- src/qt/qt_progsettings.cpp | 7 +++++++ src/qt/qt_progsettings.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 3d895cf41..803fddc24 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -203,3 +203,10 @@ void ProgSettings::on_horizontalSlider_valueChanged(int value) mouseSensitivity = (double)value / 100.; } + +void ProgSettings::on_pushButton_2_clicked() +{ + mouseSensitivity = 1.0; + ui->horizontalSlider->setValue(100); +} + diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp index 6e0b49c8c..07cf62051 100644 --- a/src/qt/qt_progsettings.hpp +++ b/src/qt/qt_progsettings.hpp @@ -59,6 +59,8 @@ private slots: void on_horizontalSlider_valueChanged(int value); + void on_pushButton_2_clicked(); + private: Ui::ProgSettings *ui; From 6a5331ebb9cdd19c44907996782136d87cfa10a8 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 3 Jun 2022 14:31:20 +0600 Subject: [PATCH 3/5] qt: Fix Wayland crashes after a while --- src/qt/wl_mouse.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 75a03813c..0419c574d 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -25,6 +25,11 @@ #include #include +extern "C" +{ +#include <86box/plat.h> +} + static zwp_relative_pointer_manager_v1* rel_manager = nullptr; static zwp_relative_pointer_v1* rel_pointer = nullptr; static zwp_pointer_constraints_v1* conf_pointer_interface = nullptr; @@ -70,9 +75,15 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id, } } +static void +display_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name) +{ + plat_mouse_capture(0); +} + static const struct wl_registry_listener registry_listener = { display_handle_global, - nullptr + display_global_remove }; void wl_init() From 5e7faecd464e404dbc9c22d09f33d1c4c1a2d58f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 3 Jun 2022 16:22:35 +0600 Subject: [PATCH 4/5] wl_mouse: Account properly for the lack of zwp_pointer_constraints and relative mouse interface --- src/qt/wl_mouse.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 0419c574d..916fe2338 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -79,6 +79,10 @@ static void display_global_remove(void *data, struct wl_registry *wl_registry, uint32_t name) { plat_mouse_capture(0); + zwp_relative_pointer_manager_v1_destroy(rel_manager); + zwp_pointer_constraints_v1_destroy(conf_pointer_interface); + rel_manager = nullptr; + conf_pointer_interface = nullptr; } static const struct wl_registry_listener registry_listener = { @@ -102,9 +106,11 @@ void wl_init() void wl_mouse_capture(QWindow *window) { - rel_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(rel_manager, (wl_pointer*)QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_pointer")); - zwp_relative_pointer_v1_add_listener(rel_pointer, &rel_listener, nullptr); - conf_pointer = zwp_pointer_constraints_v1_lock_pointer(conf_pointer_interface, (wl_surface*)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window), (wl_pointer*)QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_pointer"), nullptr, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); + if (rel_manager) { + rel_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(rel_manager, (wl_pointer*)QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_pointer")); + zwp_relative_pointer_v1_add_listener(rel_pointer, &rel_listener, nullptr); + } + if (conf_pointer_interface) conf_pointer = zwp_pointer_constraints_v1_lock_pointer(conf_pointer_interface, (wl_surface*)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("surface", window), (wl_pointer*)QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_pointer"), nullptr, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); } void wl_mouse_uncapture() From c61c9f5e0aacf6399f081c7de044df9f1e29fc3b Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 4 Jun 2022 14:15:31 +0600 Subject: [PATCH 5/5] qt: Hide MCA devices item on non-MCA machines --- src/qt/qt_mainwindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 4c7a19402..fff1cde05 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -38,6 +38,7 @@ extern "C" { #include <86box/plat.h> #include <86box/discord.h> #include <86box/video.h> +#include <86box/machine.h> #include <86box/vid_ega.h> #include <86box/version.h> @@ -1435,6 +1436,7 @@ bool MainWindow::eventFilter(QObject* receiver, QEvent* event) void MainWindow::refreshMediaMenu() { mm->refresh(ui->menuMedia); status->refresh(ui->statusbar); + ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA)); } void MainWindow::showMessage(const QString& header, const QString& message) {