diff --git a/CMakeLists.txt b/CMakeLists.txt index 007c1ffd8..a6ffa89e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ if(WIN32) # Default value for the `WIN32` target property, which specifies whether # to build the application for the Windows GUI or console subsystem - option(CMAKE_WIN32_EXECUTABLE "Build a Windows GUI executable" ON) + option(CMAKE_WIN32_EXECUTABLE "Build a Windows GUI executable" OFF) else() # Prefer dynamic builds everywhere else set(PREFER_STATIC OFF) diff --git a/src/86box.c b/src/86box.c index 168e8a8dc..d8c05c8bb 100644 --- a/src/86box.c +++ b/src/86box.c @@ -222,6 +222,9 @@ int other_ide_present = 0; /* IDE control int other_scsi_present = 0; /* SCSI controllers from non-SCSI cards are present */ +// Accelerator key array +struct accelKey acc_keys[NUM_ACCELS]; + /* Statistics. */ extern int mmuflush; extern int readlnum; @@ -654,7 +657,6 @@ usage: #ifdef USE_INSTRUMENT printf("-J or --instrument name - set 'name' to be the profiling instrument\n"); #endif - printf("-K or --keycodes codes - set 'codes' to be the uncapture combination\n"); printf("-L or --logfile path - set 'path' to be the logfile\n"); printf("-M or --missing - dump missing machines and video cards\n"); printf("-N or --noconfirm - do not ask for confirmation on quit\n"); @@ -745,13 +747,6 @@ usage: do_nothing = 1; } else if (!strcasecmp(argv[c], "--nohook") || !strcasecmp(argv[c], "-W")) { hook_enabled = 0; - } else if (!strcasecmp(argv[c], "--keycodes") || !strcasecmp(argv[c], "-K")) { - if ((c + 1) == argc) - goto usage; - - sscanf(argv[++c], "%03hX,%03hX,%03hX,%03hX,%03hX,%03hX", - &key_prefix_1_1, &key_prefix_1_2, &key_prefix_2_1, &key_prefix_2_2, - &key_uncapture_1, &key_uncapture_2); } else if (!strcasecmp(argv[c], "--clearboth") || !strcasecmp(argv[c], "-X")) { if ((c + 1) == argc) goto usage; @@ -1789,3 +1784,16 @@ do_pause(int p) } atomic_store(&pause_ack, 0); } + +// Helper to find an accelerator key and return it's index in acc_keys +int FindAccelerator(const char *name) { + for(int x=0;x= QT_VERSION_CHECK(6, 0, 0) - auto windowedShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_PageDown), this); + windowedShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_PageDown), this); #else - auto windowedShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_PageDown), this); + windowedShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_PageDown), this); #endif windowedShortcut->setContext(Qt::ShortcutContext::ApplicationShortcut); connect(windowedShortcut, &QShortcut::activated, this, [this] () { @@ -761,6 +762,8 @@ MainWindow::MainWindow(QWidget *parent) }); } #endif + + updateShortcuts(); } void @@ -826,6 +829,56 @@ MainWindow::closeEvent(QCloseEvent *event) event->accept(); } + +void MainWindow::updateShortcuts() +{ + // Update menu shortcuts from accelerator table + // Note that the "Release mouse" shortcut is hardcoded elsewhere + // This section only applies to shortcuts anchored to UI elements + + ui->actionTake_screenshot->setShortcut(QKeySequence()); + ui->actionCtrl_Alt_Del->setShortcut(QKeySequence()); + ui->actionCtrl_Alt_Esc->setShortcut(QKeySequence()); + ui->actionFullscreen->setShortcut(QKeySequence()); + ui->actionHard_Reset->setShortcut(QKeySequence()); + + int accID; + QKeySequence seq; + + accID = FindAccelerator("screenshot"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionTake_screenshot->setShortcut(seq); + + accID = FindAccelerator("send_ctrl_alt_del"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionCtrl_Alt_Del->setShortcut(seq); + + accID = FindAccelerator("send_ctrl_alt_esc"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionCtrl_Alt_Esc->setShortcut(seq); + + accID = FindAccelerator("fullscreen"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + //printf("shortcut: %s\n", qPrintable(ui->actionFullscreen->shortcut().toString())); + ui->actionFullscreen->setShortcut(seq); + + accID = FindAccelerator("hard_reset"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + ui->actionHard_Reset->setShortcut(seq); + + // To rebind leave_fullscreen we have to disconnect the existing signal, + // build a new shortcut, then connect it. + accID = FindAccelerator("leave_fullscreen"); + seq = QKeySequence::fromString(acc_keys[accID].seq); + disconnect(windowedShortcut,0,0,0); + windowedShortcut = new QShortcut(seq, this); + windowedShortcut->setContext(Qt::ShortcutContext::ApplicationShortcut); + connect(windowedShortcut, &QShortcut::activated, this, [this] () { + if (video_fullscreen) + ui->actionFullscreen->trigger(); + }); +} + void MainWindow::resizeEvent(QResizeEvent *event) { @@ -1026,6 +1079,8 @@ MainWindow::on_actionSettings_triggered() case QDialog::Accepted: settings.save(); config_changed = 2; + printf("about to try\n"); + updateShortcuts(); pc_reset_hard(); break; case QDialog::Rejected: @@ -1394,9 +1449,14 @@ MainWindow::keyPressEvent(QKeyEvent *event) #endif } - if (keyboard_ismsexit()) - plat_mouse_capture(0); - + // Check if mouse release combo has been entered + int accID = FindAccelerator("release_mouse"); + QKeySequence seq = QKeySequence::fromString(acc_keys[accID].seq); + if (seq[0] == (event->key() | event->modifiers())) + plat_mouse_capture(0); + + // TODO: Other accelerators should probably be here? + event->accept(); } diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 739d179ff..99b0021c2 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,8 @@ public: QSize getRenderWidgetSize(); void setSendKeyboardInput(bool enabled); void reloadAllRenderers(); - + QShortcut *windowedShortcut; + std::array, 8> renderers; signals: void paint(const QImage &image); @@ -159,6 +161,7 @@ private: std::unique_ptr status; std::shared_ptr mm; + void updateShortcuts(); void processKeyboardInput(bool down, uint32_t keycode); #ifdef Q_OS_MACOS uint32_t last_modifiers = 0; @@ -184,7 +187,6 @@ private: friend class RendererStack; // For UI variable access by non-primary renderer windows. friend class WindowsRawInputFilter; // Needed to reload renderers on style sheet changes. - bool isShowMessage = false; }; diff --git a/src/qt/qt_settingsinput.cpp b/src/qt/qt_settingsinput.cpp index d7c61e8d2..924594083 100644 --- a/src/qt/qt_settingsinput.cpp +++ b/src/qt/qt_settingsinput.cpp @@ -16,8 +16,11 @@ */ #include "qt_settingsinput.hpp" #include "ui_qt_settingsinput.h" +#include "qt_mainwindow.hpp" #include +#include +#include extern "C" { #include <86box/86box.h> @@ -25,11 +28,18 @@ extern "C" { #include <86box/machine.h> #include <86box/mouse.h> #include <86box/gameport.h> +#include <86box/ui.h> } #include "qt_models_common.hpp" #include "qt_deviceconfig.hpp" #include "qt_joystickconfiguration.hpp" +#include "qt_keybind.hpp" + +extern MainWindow *main_window; + +// Temporary working copy of key list +accelKey acc_keys_t[NUM_ACCELS]; SettingsInput::SettingsInput(QWidget *parent) : QWidget(parent) @@ -37,9 +47,55 @@ SettingsInput::SettingsInput(QWidget *parent) { ui->setupUi(this); + QStandardItemModel *model; + QStringList horizontalHeader; + QStringList verticalHeader; + + horizontalHeader.append("Action"); + horizontalHeader.append("Keybind"); + + QTableWidget *keyTable = ui->tableKeys; + keyTable->setRowCount(10); + keyTable->setColumnCount(3); + keyTable->setColumnHidden(2, true); + keyTable->setColumnWidth(0, 200); + keyTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + QStringList headers; + headers << "Action" << "Bound key"; + keyTable->setHorizontalHeaderLabels(headers); + keyTable->verticalHeader()->setVisible(false); + keyTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + keyTable->setSelectionBehavior(QAbstractItemView::SelectRows); + keyTable->setSelectionMode(QAbstractItemView::SingleSelection); + keyTable->setShowGrid(true); + keyTable->setStyleSheet("QTableWidget::item:hover { }"); + keyTable->setFocusPolicy(Qt::NoFocus); + keyTable->setSelectionMode(QAbstractItemView::NoSelection); + + // Make a working copy of acc_keys so we can check for dupes later without getting + // confused + printf("Instantiating list\n"); + for(int x=0;xtableKeys, &QTableWidget::cellDoubleClicked, + this, &SettingsInput::on_tableKeys_doubleClicked); + + connect(ui->pushButtonBind, &QPushButton::clicked, + this, &SettingsInput::on_pushButtonBind_Clicked); + + connect(ui->pushButtonClearBind, &QPushButton::clicked, + this, &SettingsInput::on_pushButtonClearBind_Clicked); + onCurrentMachineChanged(machine); } + SettingsInput::~SettingsInput() { delete ui; @@ -50,8 +106,15 @@ SettingsInput::save() { mouse_type = ui->comboBoxMouse->currentData().toInt(); joystick_type = ui->comboBoxJoystick->currentData().toInt(); + + // Copy accelerators from working set to global set + for(int x=0;xcomboBoxJoystick->setCurrentIndex(selectedRow); } +void +SettingsInput::refreshInputList() +{ + + for (int x=0;xtableKeys->setItem(x, 0, new QTableWidgetItem(acc_keys_t[x].desc)); + ui->tableKeys->setItem(x, 1, new QTableWidgetItem(acc_keys_t[x].seq)); + ui->tableKeys->setItem(x, 2, new QTableWidgetItem(acc_keys_t[x].name)); + } +} + +void +SettingsInput::on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +{ + // Enable/disable bind/clear buttons if user clicked valid row + QTableWidgetItem *cell = ui->tableKeys->item(currentRow,1); + if (!cell) + { + ui->pushButtonBind->setEnabled(false); + ui->pushButtonClearBind->setEnabled(false); + } + else + { + ui->pushButtonBind->setEnabled(true); + ui->pushButtonClearBind->setEnabled(true); + } +} + +void +SettingsInput::on_tableKeys_doubleClicked(int row, int col) +{ + // Edit bind + QTableWidgetItem *cell = ui->tableKeys->item(row,1); + if (!cell) return; + + QKeySequence keyseq = KeyBinder::BindKey(cell->text()); + if (keyseq != false) { + // If no change was made, don't change anything. + if (keyseq.toString(QKeySequence::NativeText) == cell->text()) return; + + // Otherwise, check for conflicts. + // Check against the *working* copy - NOT the one in use by the app, + // so we don't test against shortcuts the user already changed. + for(int x=0;xshowMessage(MBX_ANSI & MBX_INFO, "Bind conflict", "This key combo is already in use", false); + return; + } + } + // If we made it here, there were no conflicts. + // Go ahead and apply the bind. + + // Find the correct accelerator key entry + int accKeyID = FindAccelerator(qPrintable(ui->tableKeys->item(row,2)->text())); + if (!accKeyID) return; // this should never happen + + // Make the change + cell->setText(keyseq.toString(QKeySequence::NativeText)); + strcpy(acc_keys_t[accKeyID].seq, qPrintable(keyseq.toString(QKeySequence::NativeText))); + + refreshInputList(); + } +} + +void +SettingsInput::on_pushButtonBind_Clicked() +{ + // Edit bind + QTableWidgetItem *cell = ui->tableKeys->currentItem(); + if (!cell) return; + + on_tableKeys_doubleClicked(cell->row(), cell->column()); +} + +void +SettingsInput::on_pushButtonClearBind_Clicked() +{ + // Wipe bind + QTableWidgetItem *cell = ui->tableKeys->currentItem(); + if (!cell) return; + + cell->setText(""); + // Find the correct accelerator key entry + int accKeyID = FindAccelerator(qPrintable(ui->tableKeys->item(cell->row(),2)->text())); + if (!accKeyID) return; // this should never happen + + // Make the change + cell->setText(""); + strcpy(acc_keys_t[accKeyID].seq, ""); +} + void SettingsInput::on_comboBoxMouse_currentIndexChanged(int index) { diff --git a/src/qt/qt_settingsinput.hpp b/src/qt/qt_settingsinput.hpp index 0b8b665aa..ec7dc393b 100644 --- a/src/qt/qt_settingsinput.hpp +++ b/src/qt/qt_settingsinput.hpp @@ -2,6 +2,12 @@ #define QT_SETTINGSINPUT_HPP #include +#include +#include +#include +#include +#include +#include namespace Ui { class SettingsInput; @@ -27,10 +33,15 @@ private slots: void on_pushButtonJoystick2_clicked(); void on_pushButtonJoystick3_clicked(); void on_pushButtonJoystick4_clicked(); + void on_tableKeys_doubleClicked(int row, int col); + void on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); + void on_pushButtonBind_Clicked(); + void on_pushButtonClearBind_Clicked(); private: Ui::SettingsInput *ui; int machineId = 0; + void refreshInputList(); }; #endif // QT_SETTINGSINPUT_HPP diff --git a/src/qt/qt_settingsinput.ui b/src/qt/qt_settingsinput.ui index 839461119..b7074eeaa 100644 --- a/src/qt/qt_settingsinput.ui +++ b/src/qt/qt_settingsinput.ui @@ -23,17 +23,16 @@ 0 - - - - Joystick 2... + + + + + 0 + 0 + - - - - - - Joystick: + + 30 @@ -44,13 +43,6 @@ - - - - Mouse: - - - @@ -58,21 +50,15 @@ - - - - Qt::Vertical + + + + false - - QSizePolicy::Expanding + + Bind - - - 20 - 40 - - - + @@ -81,6 +67,44 @@ + + + + 30 + + + + + + + Mouse: + + + + + + + false + + + Clear binding + + + + + + + Joystick: + + + + + + + Joystick 2... + + + @@ -94,23 +118,29 @@ - - - - 30 - - - - 0 - 0 - + + + + Key Bindings: - - - - 30 + + + + QAbstractItemView::EditTrigger::NoEditTriggers + + + false + + + false + + + true + + + QAbstractItemView::SelectionBehavior::SelectRows