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