displaywidget.h (2060B)
1 // SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include "util/window_info.h" 7 8 #include "common/types.h" 9 10 #include <QtWidgets/QStackedWidget> 11 #include <QtWidgets/QWidget> 12 #include <optional> 13 14 class QCloseEvent; 15 16 class DisplayWidget final : public QWidget 17 { 18 Q_OBJECT 19 20 public: 21 explicit DisplayWidget(QWidget* parent); 22 ~DisplayWidget(); 23 24 QPaintEngine* paintEngine() const override; 25 26 int scaledWindowWidth() const; 27 int scaledWindowHeight() const; 28 29 std::optional<WindowInfo> getWindowInfo(); 30 31 void updateRelativeMode(bool enabled); 32 void updateCursor(bool hidden); 33 34 void handleCloseEvent(QCloseEvent* event); 35 void destroy(); 36 37 Q_SIGNALS: 38 void windowResizedEvent(int width, int height, float scale); 39 void windowRestoredEvent(); 40 void windowKeyEvent(int key_code, bool pressed); 41 void windowTextEntered(const QString& text); 42 void windowMouseButtonEvent(int button, bool pressed); 43 void windowMouseWheelEvent(const QPoint& angle_delta); 44 45 protected: 46 bool event(QEvent* event) override; 47 48 private: 49 bool isActuallyFullscreen() const; 50 void updateCenterPos(); 51 52 QPoint m_relative_mouse_start_pos{}; 53 QPoint m_relative_mouse_center_pos{}; 54 bool m_relative_mouse_enabled = false; 55 #ifdef _WIN32 56 bool m_clip_mouse_enabled = false; 57 #endif 58 bool m_cursor_hidden = false; 59 bool m_destroying = false; 60 61 std::vector<u32> m_keys_pressed_with_modifiers; 62 63 u32 m_last_window_width = 0; 64 u32 m_last_window_height = 0; 65 float m_last_window_scale = 1.0f; 66 }; 67 68 class DisplayContainer final : public QStackedWidget 69 { 70 Q_OBJECT 71 72 public: 73 DisplayContainer(); 74 ~DisplayContainer(); 75 76 // Wayland is broken in lots of ways, so we need to check for it. 77 static bool isRunningOnWayland(); 78 79 static bool isNeeded(bool fullscreen, bool render_to_main); 80 81 void setDisplayWidget(DisplayWidget* widget); 82 DisplayWidget* removeDisplayWidget(); 83 84 protected: 85 bool event(QEvent* event) override; 86 87 private: 88 DisplayWidget* m_display_widget = nullptr; 89 };