qt(windows): don't process raw input events when in menu or other window
This commit is contained in:
@@ -107,7 +107,7 @@ int main(int argc, char* argv[]) {
|
||||
app.installEventFilter(main_window);
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
auto rawInputFilter = WindowsRawInputFilter::Register();
|
||||
auto rawInputFilter = WindowsRawInputFilter::Register(main_window);
|
||||
if (rawInputFilter)
|
||||
{
|
||||
app.installNativeEventFilter(rawInputFilter.get());
|
||||
|
@@ -32,6 +32,8 @@
|
||||
|
||||
#include "qt_winrawinputfilter.hpp"
|
||||
|
||||
#include <QMenuBar>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <86box/keyboard.h>
|
||||
@@ -42,34 +44,44 @@
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
std::unique_ptr<WindowsRawInputFilter> WindowsRawInputFilter::Register()
|
||||
std::unique_ptr<WindowsRawInputFilter> WindowsRawInputFilter::Register(QMainWindow *window)
|
||||
{
|
||||
HWND wnd = (HWND)window->winId();
|
||||
|
||||
RAWINPUTDEVICE rid[2] =
|
||||
{
|
||||
{
|
||||
.usUsagePage = 0x01,
|
||||
.usUsage = 0x06,
|
||||
.dwFlags = RIDEV_NOHOTKEYS,
|
||||
.hwndTarget = NULL
|
||||
.hwndTarget = wnd
|
||||
},
|
||||
{
|
||||
.usUsagePage = 0x01,
|
||||
.usUsage = 0x02,
|
||||
.dwFlags = 0,
|
||||
.hwndTarget = NULL
|
||||
.hwndTarget = wnd
|
||||
}
|
||||
};
|
||||
|
||||
if (RegisterRawInputDevices(rid, 2, sizeof(rid[0])) == FALSE)
|
||||
return std::unique_ptr<WindowsRawInputFilter>(nullptr);
|
||||
|
||||
std::unique_ptr<WindowsRawInputFilter> inputfilter(new WindowsRawInputFilter());
|
||||
std::unique_ptr<WindowsRawInputFilter> inputfilter(new WindowsRawInputFilter(window));
|
||||
|
||||
return inputfilter;
|
||||
}
|
||||
|
||||
WindowsRawInputFilter::WindowsRawInputFilter()
|
||||
WindowsRawInputFilter::WindowsRawInputFilter(QMainWindow *window)
|
||||
{
|
||||
this->window = window;
|
||||
|
||||
for (auto menu : window->findChildren<QMenu*>())
|
||||
{
|
||||
connect(menu, &QMenu::aboutToShow, this, [=]() { menus_open++; });
|
||||
connect(menu, &QMenu::aboutToHide, this, [=]() { menus_open--; });
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(scancode_map) / sizeof(scancode_map[0]); i++)
|
||||
scancode_map[i] = i;
|
||||
|
||||
@@ -105,7 +117,7 @@ bool WindowsRawInputFilter::nativeEventFilter(const QByteArray &eventType, void
|
||||
|
||||
if (msg->message == WM_INPUT)
|
||||
{
|
||||
//if (infocus) /* TODO: Need way to tell if in menu or settings dialog */
|
||||
if (window->isActiveWindow() && menus_open == 0)
|
||||
handle_input((HRAWINPUT)msg->lParam);
|
||||
|
||||
return true;
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#define QT_WINDOWSRAWINPUTFILTER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QByteArray>
|
||||
|
||||
@@ -44,7 +45,7 @@ class WindowsRawInputFilter : public QObject, public QAbstractNativeEventFilter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static std::unique_ptr<WindowsRawInputFilter> Register();
|
||||
static std::unique_ptr<WindowsRawInputFilter> Register(QMainWindow *window);
|
||||
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
||||
|
||||
@@ -54,13 +55,15 @@ public slots:
|
||||
void mousePoll();
|
||||
|
||||
private:
|
||||
QMainWindow *window;
|
||||
uint16_t scancode_map[768];
|
||||
int buttons = 0;
|
||||
int dx = 0;
|
||||
int dy = 0;
|
||||
int dwheel = 0;
|
||||
int menus_open = 0;
|
||||
|
||||
WindowsRawInputFilter();
|
||||
WindowsRawInputFilter(QMainWindow *window);
|
||||
|
||||
void handle_input(HRAWINPUT input);
|
||||
void keyboard_handle(PRAWINPUT raw);
|
||||
|
Reference in New Issue
Block a user