mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Ensures keyboard events are restricted to single windows.
This commit is contained in:
parent
b850183a1e
commit
8bf5ed52ea
@ -1,7 +1,9 @@
|
||||
#include <QtWidgets>
|
||||
#include <QObject>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "timer.h"
|
||||
@ -217,7 +219,9 @@ void MainWindow::tile(const QMainWindow *previous) {
|
||||
topFrameWidth = 40;
|
||||
|
||||
const QPoint pos = previous->pos() + 2 * QPoint(topFrameWidth, topFrameWidth);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
if (screen()->availableGeometry().contains(rect().bottomRight() + pos))
|
||||
#endif
|
||||
move(pos);
|
||||
}
|
||||
|
||||
@ -687,25 +691,6 @@ void MainWindow::dropEvent(QDropEvent* event) {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Input capture.
|
||||
|
||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
|
||||
switch(event->type()) {
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease: {
|
||||
const auto keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if(!processEvent(keyEvent)) {
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void MainWindow::setUIPhase(UIPhase phase) {
|
||||
uiPhase = phase;
|
||||
|
||||
@ -750,6 +735,14 @@ void MainWindow::setUIPhase(UIPhase phase) {
|
||||
|
||||
// MARK: - Event Processing
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event) {
|
||||
processEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::keyReleaseEvent(QKeyEvent *event) {
|
||||
processEvent(event);
|
||||
}
|
||||
|
||||
bool MainWindow::processEvent(QKeyEvent *event) {
|
||||
if(!machine) return true;
|
||||
|
||||
|
@ -32,7 +32,8 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
||||
explicit MainWindow(const QString &fileName);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::MainWindow> ui;
|
||||
|
Loading…
x
Reference in New Issue
Block a user