Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

refactor

Layle8285898c255e
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index d67bd03..6d2a754 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -1060,10 +1060,6 @@ impl App {
};
let capture = capture && player.game.platform == Platform::Wii;
- if player.captured == capture && !(capture && player::MouseCapture::RECLIP_ON_MOVE) {
- return Task::none();
- }
-
player.captured = capture;
let mouse_capture = player.mouse_capture.clone();
diff --git a/crates/app/src/player/mouse_capture.rs b/crates/app/src/player/mouse_capture.rs
index 12b3a0b..aa666de 100644
--- a/crates/app/src/player/mouse_capture.rs
+++ b/crates/app/src/player/mouse_capture.rs
@@ -15,7 +15,7 @@ impl MouseCapture {
return Ok(());
}
- self::confine(self, window, capture)?;
+ self.confine(window, capture)?;
self.active = capture;
Ok(())
@@ -30,23 +30,25 @@ impl MouseCapture {
}
#[cfg(target_os = "linux")]
-fn confine(capture_state: &mut MouseCapture, window: &dyn Window, capture: bool) -> anyhow::Result<()> {
- use iced::window::raw_window_handle::RawWindowHandle;
+impl MouseCapture {
+ fn confine(&mut self, window: &dyn Window, capture: bool) -> anyhow::Result<()> {
+ use iced::window::raw_window_handle::RawWindowHandle;
- match window.window_handle()?.as_raw() {
- RawWindowHandle::Wayland(surface) => {
- if capture_state.wayland.is_none() && capture {
- capture_state.wayland = Some(wayland::Capture::new(window, surface)?);
- }
+ match window.window_handle()?.as_raw() {
+ RawWindowHandle::Wayland(surface) => {
+ if self.wayland.is_none() && capture {
+ self.wayland = Some(wayland::Capture::new(window, surface)?);
+ }
- if let Some(wayland) = &mut capture_state.wayland {
- wayland.set(capture)?;
- }
+ if let Some(wayland) = &mut self.wayland {
+ wayland.set(capture)?;
+ }
- Ok(())
+ Ok(())
+ }
+ RawWindowHandle::Xlib(handle) => self::confine_x11(window, handle.window, capture),
+ _ => anyhow::bail!("mouse confinement is unsupported on this window system"),
}
- RawWindowHandle::Xlib(handle) => self::confine_x11(window, handle.window, capture),
- _ => anyhow::bail!("mouse confinement is unsupported on this window system"),
}
}
@@ -98,45 +100,49 @@ fn confine_x11(window: &dyn Window, target: u64, capture: bool) -> anyhow::Resul
}
#[cfg(target_os = "windows")]
-fn confine(_capture_state: &mut MouseCapture, window: &dyn Window, capture: bool) -> anyhow::Result<()> {
- use iced::window::raw_window_handle::RawWindowHandle;
- use windows_sys::Win32::Foundation::{POINT, RECT};
- use windows_sys::Win32::Graphics::Gdi::ClientToScreen;
- use windows_sys::Win32::UI::WindowsAndMessaging::{ClipCursor, GetClientRect};
-
- let RawWindowHandle::Win32(handle) = window.window_handle()?.as_raw() else {
- anyhow::bail!("mouse confinement is unsupported on this window system");
- };
-
- // SAFETY: iced lends a live HWND; all output pointers are valid stack storage.
- unsafe {
- let mut rect = RECT::default();
-
- if capture {
- let hwnd = handle.hwnd.get() as _;
- anyhow::ensure!(GetClientRect(hwnd, &mut rect) != 0, "GetClientRect failed");
-
- let mut origin = POINT::default();
- anyhow::ensure!(ClientToScreen(hwnd, &mut origin) != 0, "ClientToScreen failed");
+impl MouseCapture {
+ fn confine(&mut self, window: &dyn Window, capture: bool) -> anyhow::Result<()> {
+ use iced::window::raw_window_handle::RawWindowHandle;
+ use windows_sys::Win32::Foundation::{POINT, RECT};
+ use windows_sys::Win32::Graphics::Gdi::ClientToScreen;
+ use windows_sys::Win32::UI::WindowsAndMessaging::{ClipCursor, GetClientRect};
+
+ let RawWindowHandle::Win32(handle) = window.window_handle()?.as_raw() else {
+ anyhow::bail!("mouse confinement is unsupported on this window system");
+ };
+
+ // SAFETY: iced lends a live HWND; all output pointers are valid stack storage.
+ unsafe {
+ let mut rect = RECT::default();
+
+ if capture {
+ let hwnd = handle.hwnd.get() as _;
+ anyhow::ensure!(GetClientRect(hwnd, &mut rect) != 0, "GetClientRect failed");
+
+ let mut origin = POINT::default();
+ anyhow::ensure!(ClientToScreen(hwnd, &mut origin) != 0, "ClientToScreen failed");
+
+ rect.left += origin.x;
+ rect.right += origin.x;
+ rect.top += origin.y;
+ rect.bottom += origin.y;
+ }
- rect.left += origin.x;
- rect.right += origin.x;
- rect.top += origin.y;
- rect.bottom += origin.y;
+ anyhow::ensure!(
+ ClipCursor(if capture { &rect } else { std::ptr::null() }) != 0,
+ "ClipCursor failed"
+ );
}
- anyhow::ensure!(
- ClipCursor(if capture { &rect } else { std::ptr::null() }) != 0,
- "ClipCursor failed"
- );
+ Ok(())
}
-
- Ok(())
}
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
-fn confine(_capture_state: &mut MouseCapture, _window: &dyn Window, _capture: bool) -> anyhow::Result<()> {
- anyhow::bail!("mouse confinement is unsupported on this window system")
+impl MouseCapture {
+ fn confine(&mut self, _window: &dyn Window, _capture: bool) -> anyhow::Result<()> {
+ anyhow::bail!("mouse confinement is unsupported on this window system")
+ }
}
#[cfg(target_os = "windows")]
@@ -210,18 +216,16 @@ mod wayland {
}
pub fn set(&mut self, capture: bool) -> anyhow::Result<()> {
- match capture {
- true if self.confined.is_none() => {
- let qh = self.queue.handle();
- let pointer = self.seat.get_pointer(&qh, ());
- let confined =
- self.constraints
- .confine_pointer(&self.surface, &pointer, None, Lifetime::Persistent, &qh, ());
-
- self.confined = Some((confined, pointer));
- }
- false => self::release(&mut self.confined),
- true => {}
+ if !capture {
+ self::release(&mut self.confined);
+ } else if self.confined.is_none() {
+ let qh = self.queue.handle();
+ let pointer = self.seat.get_pointer(&qh, ());
+ let confined =
+ self.constraints
+ .confine_pointer(&self.surface, &pointer, None, Lifetime::Persistent, &qh, ());
+
+ self.confined = Some((confined, pointer));
}
self.connection.flush()?;
diff --git a/crates/app/src/player/widget.rs b/crates/app/src/player/widget.rs
index c967056..75285de 100644
--- a/crates/app/src/player/widget.rs
+++ b/crates/app/src/player/widget.rs
@@ -100,32 +100,31 @@ impl Program<Message> for PlayerProgram {
self.state.clear_ir_pointer();
Some(shader::Action::request_redraw())
}
- iced::mouse::Event::ButtonPressed(button) => {
- if cursor.is_over(bounds) {
- self.state.handle_mouse_button(*button, true);
- if !self.captured {
- return Some(shader::Action::publish(Message::PlayerCaptureMouse(self.window, true)));
- }
+ iced::mouse::Event::ButtonPressed(button) if cursor.is_over(bounds) => {
+ self.state.handle_mouse_button(*button, true);
+
+ match self.captured {
+ true => Some(shader::Action::request_redraw()),
+ false => Some(shader::Action::publish(Message::PlayerCaptureMouse(self.window, true))),
}
- Some(shader::Action::request_redraw())
}
+ iced::mouse::Event::ButtonPressed(_) => Some(shader::Action::request_redraw()),
iced::mouse::Event::ButtonReleased(button) => {
self.state.handle_mouse_button(*button, false);
Some(shader::Action::request_redraw())
}
_ => None,
},
- iced::Event::Window(window::Event::Moved(_) | window::Event::Resized(_))
- if self.captured && MouseCapture::RECLIP_ON_MOVE =>
- {
- Some(shader::Action::publish(Message::PlayerCaptureMouse(self.window, true)))
- }
- iced::Event::Window(window::Event::Focused) => {
- Some(shader::Action::publish(Message::PlayerFocused(self.window, true)))
- }
- iced::Event::Window(window::Event::Unfocused) => {
- Some(shader::Action::publish(Message::PlayerFocused(self.window, false)))
- }
+ iced::Event::Window(event) => match event {
+ window::Event::Moved(_) | window::Event::Resized(_)
+ if self.captured && MouseCapture::RECLIP_ON_MOVE =>
+ {
+ Some(shader::Action::publish(Message::PlayerCaptureMouse(self.window, true)))
+ }
+ window::Event::Focused => Some(shader::Action::publish(Message::PlayerFocused(self.window, true))),
+ window::Event::Unfocused => Some(shader::Action::publish(Message::PlayerFocused(self.window, false))),
+ _ => None,
+ },
_ => None,
}
}
diff --git a/submodules/beanwii b/submodules/beanwii
index 901c414..fa5df78 160000
--- a/submodules/beanwii
+++ b/submodules/beanwii
@@ -1 +1 @@
-Subproject commit 901c414e8355401582eb3f01abf71666b9cfbb73
+Subproject commit fa5df78c84c1701ba165232ac4fd6c26b01b8b49