summaryrefslogtreecommitdiff
path: root/src/yuzu_cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu_cmd')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp100
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h20
-rw-r--r--src/yuzu_cmd/yuzu.cpp6
3 files changed, 64 insertions, 62 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 521209622..c4a4a36be 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -121,62 +121,64 @@ void EmuWindow_SDL2::Fullscreen() {
121 SDL_MaximizeWindow(render_window); 121 SDL_MaximizeWindow(render_window);
122} 122}
123 123
124void EmuWindow_SDL2::PollEvents() { 124void EmuWindow_SDL2::WaitEvent() {
125 // Called on main thread
125 SDL_Event event; 126 SDL_Event event;
126 127
127 // SDL_PollEvent returns 0 when there are no more events in the event queue 128 if (!SDL_WaitEvent(&event)) {
128 while (SDL_PollEvent(&event)) { 129 LOG_CRITICAL(Frontend, "SDL_WaitEvent failed: {}", SDL_GetError());
129 switch (event.type) { 130 exit(1);
130 case SDL_WINDOWEVENT: 131 }
131 switch (event.window.event) { 132
132 case SDL_WINDOWEVENT_SIZE_CHANGED: 133 switch (event.type) {
133 case SDL_WINDOWEVENT_RESIZED: 134 case SDL_WINDOWEVENT:
134 case SDL_WINDOWEVENT_MAXIMIZED: 135 switch (event.window.event) {
135 case SDL_WINDOWEVENT_RESTORED: 136 case SDL_WINDOWEVENT_SIZE_CHANGED:
136 OnResize(); 137 case SDL_WINDOWEVENT_RESIZED:
137 break; 138 case SDL_WINDOWEVENT_MAXIMIZED:
138 case SDL_WINDOWEVENT_MINIMIZED: 139 case SDL_WINDOWEVENT_RESTORED:
139 case SDL_WINDOWEVENT_EXPOSED: 140 OnResize();
140 is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED;
141 OnResize();
142 break;
143 case SDL_WINDOWEVENT_CLOSE:
144 is_open = false;
145 break;
146 }
147 break;
148 case SDL_KEYDOWN:
149 case SDL_KEYUP:
150 OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
151 break;
152 case SDL_MOUSEMOTION:
153 // ignore if it came from touch
154 if (event.button.which != SDL_TOUCH_MOUSEID)
155 OnMouseMotion(event.motion.x, event.motion.y);
156 break;
157 case SDL_MOUSEBUTTONDOWN:
158 case SDL_MOUSEBUTTONUP:
159 // ignore if it came from touch
160 if (event.button.which != SDL_TOUCH_MOUSEID) {
161 OnMouseButton(event.button.button, event.button.state, event.button.x,
162 event.button.y);
163 }
164 break;
165 case SDL_FINGERDOWN:
166 OnFingerDown(event.tfinger.x, event.tfinger.y);
167 break;
168 case SDL_FINGERMOTION:
169 OnFingerMotion(event.tfinger.x, event.tfinger.y);
170 break; 141 break;
171 case SDL_FINGERUP: 142 case SDL_WINDOWEVENT_MINIMIZED:
172 OnFingerUp(); 143 case SDL_WINDOWEVENT_EXPOSED:
144 is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED;
145 OnResize();
173 break; 146 break;
174 case SDL_QUIT: 147 case SDL_WINDOWEVENT_CLOSE:
175 is_open = false; 148 is_open = false;
176 break; 149 break;
177 default:
178 break;
179 } 150 }
151 break;
152 case SDL_KEYDOWN:
153 case SDL_KEYUP:
154 OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
155 break;
156 case SDL_MOUSEMOTION:
157 // ignore if it came from touch
158 if (event.button.which != SDL_TOUCH_MOUSEID)
159 OnMouseMotion(event.motion.x, event.motion.y);
160 break;
161 case SDL_MOUSEBUTTONDOWN:
162 case SDL_MOUSEBUTTONUP:
163 // ignore if it came from touch
164 if (event.button.which != SDL_TOUCH_MOUSEID) {
165 OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y);
166 }
167 break;
168 case SDL_FINGERDOWN:
169 OnFingerDown(event.tfinger.x, event.tfinger.y);
170 break;
171 case SDL_FINGERMOTION:
172 OnFingerMotion(event.tfinger.x, event.tfinger.y);
173 break;
174 case SDL_FINGERUP:
175 OnFingerUp();
176 break;
177 case SDL_QUIT:
178 is_open = false;
179 break;
180 default:
181 break;
180 } 182 }
181 183
182 const u32 current_time = SDL_GetTicks(); 184 const u32 current_time = SDL_GetTicks();
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
index 53d756c3c..a93141240 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
@@ -23,38 +23,38 @@ public:
23 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); 23 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem);
24 ~EmuWindow_SDL2(); 24 ~EmuWindow_SDL2();
25 25
26 /// Polls window events
27 void PollEvents() override;
28
29 /// Whether the window is still open, and a close request hasn't yet been sent 26 /// Whether the window is still open, and a close request hasn't yet been sent
30 bool IsOpen() const; 27 bool IsOpen() const;
31 28
32 /// Returns if window is shown (not minimized) 29 /// Returns if window is shown (not minimized)
33 bool IsShown() const override; 30 bool IsShown() const override;
34 31
32 /// Wait for the next event on the main thread.
33 void WaitEvent();
34
35protected: 35protected:
36 /// Called by PollEvents when a key is pressed or released. 36 /// Called by WaitEvent when a key is pressed or released.
37 void OnKeyEvent(int key, u8 state); 37 void OnKeyEvent(int key, u8 state);
38 38
39 /// Called by PollEvents when the mouse moves. 39 /// Called by WaitEvent when the mouse moves.
40 void OnMouseMotion(s32 x, s32 y); 40 void OnMouseMotion(s32 x, s32 y);
41 41
42 /// Called by PollEvents when a mouse button is pressed or released 42 /// Called by WaitEvent when a mouse button is pressed or released
43 void OnMouseButton(u32 button, u8 state, s32 x, s32 y); 43 void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
44 44
45 /// Translates pixel position (0..1) to pixel positions 45 /// Translates pixel position (0..1) to pixel positions
46 std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const; 46 std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
47 47
48 /// Called by PollEvents when a finger starts touching the touchscreen 48 /// Called by WaitEvent when a finger starts touching the touchscreen
49 void OnFingerDown(float x, float y); 49 void OnFingerDown(float x, float y);
50 50
51 /// Called by PollEvents when a finger moves while touching the touchscreen 51 /// Called by WaitEvent when a finger moves while touching the touchscreen
52 void OnFingerMotion(float x, float y); 52 void OnFingerMotion(float x, float y);
53 53
54 /// Called by PollEvents when a finger stops touching the touchscreen 54 /// Called by WaitEvent when a finger stops touching the touchscreen
55 void OnFingerUp(); 55 void OnFingerUp();
56 56
57 /// Called by PollEvents when any event that may cause the window to be resized occurs 57 /// Called by WaitEvent when any event that may cause the window to be resized occurs
58 void OnResize(); 58 void OnResize();
59 59
60 /// Called when user passes the fullscreen parameter flag 60 /// Called when user passes the fullscreen parameter flag
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 3a76c785f..ba6e89249 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -240,11 +240,11 @@ int main(int argc, char** argv) {
240 system.CurrentProcess()->GetTitleID(), false, 240 system.CurrentProcess()->GetTitleID(), false,
241 [](VideoCore::LoadCallbackStage, size_t value, size_t total) {}); 241 [](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
242 242
243 system.Run(); 243 void(system.Run());
244 while (emu_window->IsOpen()) { 244 while (emu_window->IsOpen()) {
245 std::this_thread::sleep_for(std::chrono::milliseconds(1)); 245 emu_window->WaitEvent();
246 } 246 }
247 system.Pause(); 247 void(system.Pause());
248 system.Shutdown(); 248 system.Shutdown();
249 249
250 detached_tasks.WaitForAllTasks(); 250 detached_tasks.WaitForAllTasks();