diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eff8c0..217022a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] - ReleaseDate +### Fixed + +- Fix crash caused by missing `SetForeground` api function + ## [0.2.0] - 2025-10-28 ### Added @@ -46,8 +50,8 @@ - First release -[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.0...HEAD +[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.0...HEAD [0.2.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.2...v0.2.0 [0.1.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.0...v0.1.1 diff --git a/src/api.rs b/src/api.rs index 5821376..9d4cab3 100644 --- a/src/api.rs +++ b/src/api.rs @@ -13,7 +13,7 @@ use crate::{ }, rendering::PoBString, search_handle::new_search_handle, - window::{get_screen_scale, get_screen_size, set_window_title}, + window::{get_screen_scale, get_screen_size, set_foreground, set_window_title}, }, lua::ContextSocket, }; @@ -84,6 +84,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> { globals.set("GetScreenSize", lua.create_function(get_screen_size)?)?; globals.set("GetScreenScale", lua.create_function(get_screen_scale)?)?; globals.set("SetWindowTitle", lua.create_function(set_window_title)?)?; + globals.set("SetForeground", lua.create_function(set_foreground)?)?; // lua globals.set("PCall", lua.create_function(protected_call)?)?; diff --git a/src/api/window.rs b/src/api/window.rs index 6d55054..be60e7f 100644 --- a/src/api/window.rs +++ b/src/api/window.rs @@ -26,3 +26,9 @@ pub fn set_window_title(l: &Lua, title: String) -> LuaResult<()> { socket.window().set_window_title(&title); Ok(()) } + +pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> { + let socket = l.app_data_ref::<&'static ContextSocket>().unwrap(); + socket.window().focus(); + Ok(()) +} diff --git a/src/window.rs b/src/window.rs index 25d2094..470af38 100644 --- a/src/window.rs +++ b/src/window.rs @@ -42,4 +42,10 @@ impl WindowState { pub fn logical_size(&self) -> LogicalSize { self.size.to_logical(self.scale_factor) } + + pub fn focus(&self) { + if let Some(ref window) = self.window { + window.focus_window(); + } + } }