From 1bdff37e3865b37db76cb8c07778b500d8f9ba7c Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 29 Dec 2021 23:49:09 +0600 Subject: [PATCH 1/2] * Turned the software renderer into a window as well * Fix inability to move window on GNOME * Fix status bar icons being frozen after icon set switch --- src/qt/qt_hardwarerenderer.cpp | 18 +++--------------- src/qt/qt_hardwarerenderer.hpp | 1 - src/qt/qt_main.cpp | 8 -------- src/qt/qt_mainwindow.cpp | 15 +++++++-------- src/qt/qt_progsettings.cpp | 4 ++++ src/qt/qt_renderercomon.cpp | 26 ++++++++++++++++++++++++++ src/qt/qt_renderercomon.hpp | 2 ++ src/qt/qt_rendererstack.cpp | 9 ++++++++- src/qt/qt_rendererstack.hpp | 2 ++ src/qt/qt_softwarerenderer.cpp | 12 ++++++++++-- src/qt/qt_softwarerenderer.hpp | 4 +++- 11 files changed, 65 insertions(+), 36 deletions(-) diff --git a/src/qt/qt_hardwarerenderer.cpp b/src/qt/qt_hardwarerenderer.cpp index ac0acb8b5..02f19f28b 100644 --- a/src/qt/qt_hardwarerenderer.cpp +++ b/src/qt/qt_hardwarerenderer.cpp @@ -183,19 +183,7 @@ void HardwareRenderer::resizeEvent(QResizeEvent *event) { bool HardwareRenderer::event(QEvent *event) { - switch (event->type()) - { - default: - return QOpenGLWindow::event(event); - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - case QEvent::KeyPress: - case QEvent::KeyRelease: - case QEvent::Wheel: - case QEvent::Enter: - case QEvent::Leave: - return QApplication::sendEvent(parentWidget, event); - } - return false; + bool res = false; + if (!eventDelegate(event, res)) return QOpenGLWindow::event(event); + return res; } diff --git a/src/qt/qt_hardwarerenderer.hpp b/src/qt/qt_hardwarerenderer.hpp index 6e2103071..4fb132da6 100644 --- a/src/qt/qt_hardwarerenderer.hpp +++ b/src/qt/qt_hardwarerenderer.hpp @@ -29,7 +29,6 @@ class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, publi private: bool wayland = false; - QWidget* parentWidget{nullptr}; QOpenGLContext* m_context; QOpenGLTexture* m_texture{nullptr}; QOpenGLShaderProgram* m_prog{nullptr}; diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 91fee7408..2fb4e35fe 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -120,7 +120,6 @@ int main(int argc, char* argv[]) { main_window = new MainWindow(); main_window->show(); - main_window->setFocus(); app.installEventFilter(main_window); #ifdef Q_OS_WINDOWS @@ -134,13 +133,6 @@ int main(int argc, char* argv[]) { } #endif - auto widgetList = app.allWidgets(); - for (auto curWidget : widgetList) - { - curWidget->setFocusPolicy(Qt::NoFocus); - } - main_window->setFocusPolicy(Qt::StrongFocus); - pc_reset_hard_init(); /* Set the PAUSE mode depending on the renderer. */ diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 0d89d44f4..6fa2417b3 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -97,6 +97,7 @@ MainWindow::MainWindow(QWidget *parent) : qt_mouse_capture(mouse_capture); if (mouse_capture) { ui->stackedWidget->grabMouse(); + this->grabKeyboard(); #ifdef WAYLAND if (QGuiApplication::platformName().contains("wayland")) { wl_mouse_capture(this->windowHandle()); @@ -104,6 +105,7 @@ MainWindow::MainWindow(QWidget *parent) : #endif } else { ui->stackedWidget->releaseMouse(); + this->releaseKeyboard(); #ifdef WAYLAND if (QGuiApplication::platformName().contains("wayland")) { wl_mouse_uncapture(); @@ -125,8 +127,12 @@ MainWindow::MainWindow(QWidget *parent) : } }); - connect(ui->menubar, &QMenuBar::triggered, this, [] { + connect(ui->menubar, &QMenuBar::triggered, this, [this] { config_save(); + if (QApplication::activeWindow() == this) + { + ui->stackedWidget->current->setFocus(); + } }); connect(this, &MainWindow::updateStatusBarPanes, this, [this] { @@ -278,13 +284,6 @@ MainWindow::MainWindow(QWidget *parent) : ui->actionChange_contrast_for_monochrome_display->setChecked(true); } - setFocusPolicy(Qt::StrongFocus); - ui->stackedWidget->setFocusPolicy(Qt::NoFocus); - ui->centralwidget->setFocusPolicy(Qt::NoFocus); - menuBar()->setFocusPolicy(Qt::NoFocus); - menuWidget()->setFocusPolicy(Qt::NoFocus); - statusBar()->setFocusPolicy(Qt::NoFocus); - video_setblit(qt_blit); } diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 930efb6f3..a228b55c1 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -79,6 +79,10 @@ void ProgSettings::accept() main_window->status.reset(new MachineStatus(main_window)); main_window->refreshMediaMenu(); main_window->status->message(msg); + connect(main_window, &MainWindow::updateStatusBarTip, main_window->status.get(), &MachineStatus::updateTip); + 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); QDialog::accept(); } diff --git a/src/qt/qt_renderercomon.cpp b/src/qt/qt_renderercomon.cpp index 144bb88af..ed55e9a71 100644 --- a/src/qt/qt_renderercomon.cpp +++ b/src/qt/qt_renderercomon.cpp @@ -1,7 +1,10 @@ #include "qt_renderercomon.hpp" +#include "qt_mainwindow.hpp" #include #include +#include +#include #include @@ -12,6 +15,7 @@ extern "C" { RendererCommon::RendererCommon() = default; +extern MainWindow* main_window; void RendererCommon::onPaint(QPaintDevice* device) { QPainter painter(device); painter.setRenderHint(QPainter::SmoothPixmapTransform, video_filter_method > 0 ? true : false); @@ -86,3 +90,25 @@ void RendererCommon::onResize(int width, int height) { break; } } + +bool RendererCommon::eventDelegate(QEvent *event, bool& result) +{ + switch (event->type()) + { + default: + return false; + case QEvent::KeyPress: + case QEvent::KeyRelease: + result = QApplication::sendEvent(main_window, event); + return true; + case QEvent::MouseButtonPress: + case QEvent::MouseMove: + case QEvent::MouseButtonRelease: + case QEvent::Wheel: + case QEvent::Enter: + case QEvent::Leave: + result = QApplication::sendEvent(parentWidget, event); + return true; + } + return false; +} diff --git a/src/qt/qt_renderercomon.hpp b/src/qt/qt_renderercomon.hpp index 8cad5f92c..cf05a7321 100644 --- a/src/qt/qt_renderercomon.hpp +++ b/src/qt/qt_renderercomon.hpp @@ -13,7 +13,9 @@ public: void onResize(int width, int height); protected: void onPaint(QPaintDevice* device); + bool eventDelegate(QEvent* event, bool& result); QImage image{QSize(2048, 2048), QImage::Format_RGB32}; QRect source, destination; + QWidget* parentWidget{nullptr}; }; diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index d165c007b..fab8783b9 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -4,6 +4,8 @@ #include "qt_softwarerenderer.hpp" #include "qt_hardwarerenderer.hpp" +#include "qt_mainwindow.hpp" + #include "evdev_mouse.hpp" #include @@ -19,6 +21,7 @@ extern "C" #include <86box/video.h> } +extern MainWindow* main_window; RendererStack::RendererStack(QWidget *parent) : QStackedWidget(parent), ui(new Ui::RendererStack) @@ -116,6 +119,10 @@ void RendererStack::mousePressEvent(QMouseEvent *event) { mousedata.mousebuttons |= event->button(); } + if (main_window->frameGeometry().contains(event->pos()) && !geometry().contains(event->pos())) + { + main_window->windowHandle()->startSystemMove(); + } event->accept(); } void RendererStack::wheelEvent(QWheelEvent *event) @@ -177,7 +184,7 @@ void RendererStack::switchRenderer(Renderer renderer) { { auto sw = new SoftwareRenderer(this); connect(this, &RendererStack::blitToRenderer, sw, &SoftwareRenderer::onBlit, Qt::QueuedConnection); - current.reset(sw); + current.reset(this->createWindowContainer(sw, this)); } break; case Renderer::OpenGL: diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 5edd40f08..8ad1e39db 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -68,6 +68,8 @@ private: /* atomic flag for each buffer to not overload the renderer */ std::vector buffers_in_use; + + friend class MainWindow; }; #endif // QT_RENDERERCONTAINER_HPP diff --git a/src/qt/qt_softwarerenderer.cpp b/src/qt/qt_softwarerenderer.cpp index d9195d7b6..962260fd8 100644 --- a/src/qt/qt_softwarerenderer.cpp +++ b/src/qt/qt_softwarerenderer.cpp @@ -1,6 +1,7 @@ #include "qt_softwarerenderer.hpp" +#include -SoftwareRenderer::SoftwareRenderer(QWidget *parent) : QWidget(parent) {} +SoftwareRenderer::SoftwareRenderer(QWidget *parent) : QRasterWindow(parent->windowHandle()) { parentWidget = parent; } void SoftwareRenderer::paintEvent(QPaintEvent *event) { (void) event; @@ -19,5 +20,12 @@ void SoftwareRenderer::onBlit(const std::unique_ptr* img, int x, int y, void SoftwareRenderer::resizeEvent(QResizeEvent *event) { onResize(width(), height()); - QWidget::resizeEvent(event); + QRasterWindow::resizeEvent(event); +} + +bool SoftwareRenderer::event(QEvent *event) +{ + bool res = false; + if (!eventDelegate(event, res)) return QRasterWindow::event(event); + return res; } diff --git a/src/qt/qt_softwarerenderer.hpp b/src/qt/qt_softwarerenderer.hpp index c30303cc5..c60ab110c 100644 --- a/src/qt/qt_softwarerenderer.hpp +++ b/src/qt/qt_softwarerenderer.hpp @@ -2,10 +2,11 @@ #define SOFTWARERENDERER_HPP #include +#include #include #include "qt_renderercomon.hpp" -class SoftwareRenderer : public QWidget, public RendererCommon +class SoftwareRenderer : public QRasterWindow, public RendererCommon { Q_OBJECT public: @@ -17,6 +18,7 @@ public slots: protected: void resizeEvent(QResizeEvent *event) override; + bool event(QEvent *event) override; }; #endif // SOFTWARERENDERER_HPP From 087e978a1845e9c52578fad95a5de5f6e225521b Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 30 Dec 2021 00:07:29 +0600 Subject: [PATCH 2/2] Fix missing FluidSynth message string --- src/qt/qt.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qt/qt.c b/src/qt/qt.c index 7207a67e2..2a4e83e71 100644 --- a/src/qt/qt.c +++ b/src/qt/qt.c @@ -21,6 +21,12 @@ int qt_nvr_save(void) { char icon_set[256] = ""; /* name of the iconset to be used */ +#ifdef _WIN32 +#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" +#else +#define LIB_NAME_FLUIDSYNTH "libfluidsynth" +#endif + wchar_t* plat_get_string(int i) { switch (i) @@ -55,6 +61,8 @@ wchar_t* plat_get_string(int i) return L"libfreetype is required for ESC/P printer emulation."; case IDS_2132: return L"libgs is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."; + case IDS_2133: + return L""LIB_NAME_FLUIDSYNTH" is required for FluidSynth MIDI output."; case IDS_2129: return L"Make sure libpcap is installed and that you are on a libpcap-compatible network connection."; case IDS_2114: