diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 101 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 16 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 12 | ||||
| -rw-r--r-- | src/yuzu/main.h | 4 |
4 files changed, 78 insertions, 55 deletions
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 8b4e59eb3..e1825e607 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -122,9 +122,51 @@ public: | |||
| 122 | parent->OnFramebufferSizeChanged(); | 122 | parent->OnFramebufferSizeChanged(); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | void keyPressEvent(QKeyEvent* event) override { | ||
| 126 | InputCommon::GetKeyboard()->PressKey(event->key()); | ||
| 127 | } | ||
| 128 | |||
| 129 | void keyReleaseEvent(QKeyEvent* event) override { | ||
| 130 | InputCommon::GetKeyboard()->ReleaseKey(event->key()); | ||
| 131 | } | ||
| 132 | |||
| 133 | void mousePressEvent(QMouseEvent* event) override { | ||
| 134 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 135 | return; // touch input is handled in TouchBeginEvent | ||
| 136 | |||
| 137 | const auto pos{event->pos()}; | ||
| 138 | if (event->button() == Qt::LeftButton) { | ||
| 139 | const auto [x, y] = parent->ScaleTouch(pos); | ||
| 140 | parent->TouchPressed(x, y); | ||
| 141 | } else if (event->button() == Qt::RightButton) { | ||
| 142 | InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y()); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | void mouseMoveEvent(QMouseEvent* event) override { | ||
| 147 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 148 | return; // touch input is handled in TouchUpdateEvent | ||
| 149 | |||
| 150 | const auto pos{event->pos()}; | ||
| 151 | const auto [x, y] = parent->ScaleTouch(pos); | ||
| 152 | parent->TouchMoved(x, y); | ||
| 153 | InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y()); | ||
| 154 | } | ||
| 155 | |||
| 156 | void mouseReleaseEvent(QMouseEvent* event) override { | ||
| 157 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 158 | return; // touch input is handled in TouchEndEvent | ||
| 159 | |||
| 160 | if (event->button() == Qt::LeftButton) | ||
| 161 | parent->TouchReleased(); | ||
| 162 | else if (event->button() == Qt::RightButton) | ||
| 163 | InputCommon::GetMotionEmu()->EndTilt(); | ||
| 164 | } | ||
| 165 | |||
| 125 | void DisablePainting() { | 166 | void DisablePainting() { |
| 126 | do_painting = false; | 167 | do_painting = false; |
| 127 | } | 168 | } |
| 169 | |||
| 128 | void EnablePainting() { | 170 | void EnablePainting() { |
| 129 | do_painting = true; | 171 | do_painting = true; |
| 130 | } | 172 | } |
| @@ -196,12 +238,24 @@ void GRenderWindow::PollEvents() {} | |||
| 196 | void GRenderWindow::OnFramebufferSizeChanged() { | 238 | void GRenderWindow::OnFramebufferSizeChanged() { |
| 197 | // Screen changes potentially incur a change in screen DPI, hence we should update the | 239 | // Screen changes potentially incur a change in screen DPI, hence we should update the |
| 198 | // framebuffer size | 240 | // framebuffer size |
| 199 | qreal pixelRatio = windowPixelRatio(); | 241 | qreal pixelRatio = GetWindowPixelRatio(); |
| 200 | unsigned width = child->QPaintDevice::width() * pixelRatio; | 242 | unsigned width = child->QPaintDevice::width() * pixelRatio; |
| 201 | unsigned height = child->QPaintDevice::height() * pixelRatio; | 243 | unsigned height = child->QPaintDevice::height() * pixelRatio; |
| 202 | UpdateCurrentFramebufferLayout(width, height); | 244 | UpdateCurrentFramebufferLayout(width, height); |
| 203 | } | 245 | } |
| 204 | 246 | ||
| 247 | void GRenderWindow::ForwardKeyPressEvent(QKeyEvent* event) { | ||
| 248 | if (child) { | ||
| 249 | child->keyPressEvent(event); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | void GRenderWindow::ForwardKeyReleaseEvent(QKeyEvent* event) { | ||
| 254 | if (child) { | ||
| 255 | child->keyReleaseEvent(event); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 205 | void GRenderWindow::BackupGeometry() { | 259 | void GRenderWindow::BackupGeometry() { |
| 206 | geometry = ((QWidget*)this)->saveGeometry(); | 260 | geometry = ((QWidget*)this)->saveGeometry(); |
| 207 | } | 261 | } |
| @@ -226,13 +280,13 @@ QByteArray GRenderWindow::saveGeometry() { | |||
| 226 | return geometry; | 280 | return geometry; |
| 227 | } | 281 | } |
| 228 | 282 | ||
| 229 | qreal GRenderWindow::windowPixelRatio() const { | 283 | qreal GRenderWindow::GetWindowPixelRatio() const { |
| 230 | // windowHandle() might not be accessible until the window is displayed to screen. | 284 | // windowHandle() might not be accessible until the window is displayed to screen. |
| 231 | return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; | 285 | return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; |
| 232 | } | 286 | } |
| 233 | 287 | ||
| 234 | std::pair<unsigned, unsigned> GRenderWindow::ScaleTouch(const QPointF pos) const { | 288 | std::pair<unsigned, unsigned> GRenderWindow::ScaleTouch(const QPointF pos) const { |
| 235 | const qreal pixel_ratio = windowPixelRatio(); | 289 | const qreal pixel_ratio = GetWindowPixelRatio(); |
| 236 | return {static_cast<unsigned>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), | 290 | return {static_cast<unsigned>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), |
| 237 | static_cast<unsigned>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; | 291 | static_cast<unsigned>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; |
| 238 | } | 292 | } |
| @@ -242,47 +296,6 @@ void GRenderWindow::closeEvent(QCloseEvent* event) { | |||
| 242 | QWidget::closeEvent(event); | 296 | QWidget::closeEvent(event); |
| 243 | } | 297 | } |
| 244 | 298 | ||
| 245 | void GRenderWindow::keyPressEvent(QKeyEvent* event) { | ||
| 246 | InputCommon::GetKeyboard()->PressKey(event->key()); | ||
| 247 | } | ||
| 248 | |||
| 249 | void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { | ||
| 250 | InputCommon::GetKeyboard()->ReleaseKey(event->key()); | ||
| 251 | } | ||
| 252 | |||
| 253 | void GRenderWindow::mousePressEvent(QMouseEvent* event) { | ||
| 254 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 255 | return; // touch input is handled in TouchBeginEvent | ||
| 256 | |||
| 257 | auto pos = event->pos(); | ||
| 258 | if (event->button() == Qt::LeftButton) { | ||
| 259 | const auto [x, y] = ScaleTouch(pos); | ||
| 260 | this->TouchPressed(x, y); | ||
| 261 | } else if (event->button() == Qt::RightButton) { | ||
| 262 | InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y()); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { | ||
| 267 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 268 | return; // touch input is handled in TouchUpdateEvent | ||
| 269 | |||
| 270 | auto pos = event->pos(); | ||
| 271 | const auto [x, y] = ScaleTouch(pos); | ||
| 272 | this->TouchMoved(x, y); | ||
| 273 | InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y()); | ||
| 274 | } | ||
| 275 | |||
| 276 | void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { | ||
| 277 | if (event->source() == Qt::MouseEventSynthesizedBySystem) | ||
| 278 | return; // touch input is handled in TouchEndEvent | ||
| 279 | |||
| 280 | if (event->button() == Qt::LeftButton) | ||
| 281 | this->TouchReleased(); | ||
| 282 | else if (event->button() == Qt::RightButton) | ||
| 283 | InputCommon::GetMotionEmu()->EndTilt(); | ||
| 284 | } | ||
| 285 | |||
| 286 | void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { | 299 | void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { |
| 287 | // TouchBegin always has exactly one touch point, so take the .first() | 300 | // TouchBegin always has exactly one touch point, so take the .first() |
| 288 | const auto [x, y] = ScaleTouch(event->touchPoints().first().pos()); | 301 | const auto [x, y] = ScaleTouch(event->touchPoints().first().pos()); |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index c2f2fe87e..288ce1572 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -119,24 +119,19 @@ public: | |||
| 119 | void PollEvents() override; | 119 | void PollEvents() override; |
| 120 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; | 120 | std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; |
| 121 | 121 | ||
| 122 | void ForwardKeyPressEvent(QKeyEvent* event); | ||
| 123 | void ForwardKeyReleaseEvent(QKeyEvent* event); | ||
| 124 | |||
| 122 | void BackupGeometry(); | 125 | void BackupGeometry(); |
| 123 | void RestoreGeometry(); | 126 | void RestoreGeometry(); |
| 124 | void restoreGeometry(const QByteArray& geometry); // overridden | 127 | void restoreGeometry(const QByteArray& geometry); // overridden |
| 125 | QByteArray saveGeometry(); // overridden | 128 | QByteArray saveGeometry(); // overridden |
| 126 | 129 | ||
| 127 | qreal windowPixelRatio() const; | 130 | qreal GetWindowPixelRatio() const; |
| 131 | std::pair<unsigned, unsigned> ScaleTouch(const QPointF pos) const; | ||
| 128 | 132 | ||
| 129 | void closeEvent(QCloseEvent* event) override; | 133 | void closeEvent(QCloseEvent* event) override; |
| 130 | |||
| 131 | void keyPressEvent(QKeyEvent* event) override; | ||
| 132 | void keyReleaseEvent(QKeyEvent* event) override; | ||
| 133 | |||
| 134 | void mousePressEvent(QMouseEvent* event) override; | ||
| 135 | void mouseMoveEvent(QMouseEvent* event) override; | ||
| 136 | void mouseReleaseEvent(QMouseEvent* event) override; | ||
| 137 | |||
| 138 | bool event(QEvent* event) override; | 134 | bool event(QEvent* event) override; |
| 139 | |||
| 140 | void focusOutEvent(QFocusEvent* event) override; | 135 | void focusOutEvent(QFocusEvent* event) override; |
| 141 | 136 | ||
| 142 | void OnClientAreaResized(unsigned width, unsigned height); | 137 | void OnClientAreaResized(unsigned width, unsigned height); |
| @@ -158,7 +153,6 @@ signals: | |||
| 158 | void FirstFrameDisplayed(); | 153 | void FirstFrameDisplayed(); |
| 159 | 154 | ||
| 160 | private: | 155 | private: |
| 161 | std::pair<unsigned, unsigned> ScaleTouch(const QPointF pos) const; | ||
| 162 | void TouchBeginEvent(const QTouchEvent* event); | 156 | void TouchBeginEvent(const QTouchEvent* event); |
| 163 | void TouchUpdateEvent(const QTouchEvent* event); | 157 | void TouchUpdateEvent(const QTouchEvent* event); |
| 164 | void TouchEndEvent(); | 158 | void TouchEndEvent(); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c8db7b907..ae3b49709 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1965,6 +1965,18 @@ void GMainWindow::dragMoveEvent(QDragMoveEvent* event) { | |||
| 1965 | event->acceptProposedAction(); | 1965 | event->acceptProposedAction(); |
| 1966 | } | 1966 | } |
| 1967 | 1967 | ||
| 1968 | void GMainWindow::keyPressEvent(QKeyEvent* event) { | ||
| 1969 | if (render_window) { | ||
| 1970 | render_window->ForwardKeyPressEvent(event); | ||
| 1971 | } | ||
| 1972 | } | ||
| 1973 | |||
| 1974 | void GMainWindow::keyReleaseEvent(QKeyEvent* event) { | ||
| 1975 | if (render_window) { | ||
| 1976 | render_window->ForwardKeyReleaseEvent(event); | ||
| 1977 | } | ||
| 1978 | } | ||
| 1979 | |||
| 1968 | bool GMainWindow::ConfirmChangeGame() { | 1980 | bool GMainWindow::ConfirmChangeGame() { |
| 1969 | if (emu_thread == nullptr) | 1981 | if (emu_thread == nullptr) |
| 1970 | return true; | 1982 | return true; |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index e07c892cf..080484995 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -251,4 +251,8 @@ protected: | |||
| 251 | void dropEvent(QDropEvent* event) override; | 251 | void dropEvent(QDropEvent* event) override; |
| 252 | void dragEnterEvent(QDragEnterEvent* event) override; | 252 | void dragEnterEvent(QDragEnterEvent* event) override; |
| 253 | void dragMoveEvent(QDragMoveEvent* event) override; | 253 | void dragMoveEvent(QDragMoveEvent* event) override; |
| 254 | |||
| 255 | // Overrides used to forward signals to the render window when the focus moves out. | ||
| 256 | void keyPressEvent(QKeyEvent* event) override; | ||
| 257 | void keyReleaseEvent(QKeyEvent* event) override; | ||
| 254 | }; | 258 | }; |