Skip to content

Commit

Permalink
nya
Browse files Browse the repository at this point in the history
  • Loading branch information
griffi-gh committed Sep 1, 2024
1 parent 2849c11 commit 518b2c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions kubi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ winapi = { version = "0.3", features = ["wincon"] }
default = ["raw-evt-mouse"]
raw-evt-keyboard = [] # use raw input for keyboard. works on x11 and windows, breaks keyboard on android and wayland
raw-evt-mouse = [] # required for mouse input
c-ffi = [] # generate a C-ffi-compatible `kubi_main` entry point (useful if building as a shared library)
generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"]
safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"]
parallel = ["shipyard/parallel"] # causes some serious issues!
Expand Down
20 changes: 17 additions & 3 deletions kubi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,30 @@ fn attach_console() {
unsafe { AttachConsole(ATTACH_PARENT_PROCESS); }
}

#[unsafe(no_mangle)]
#[cfg(target_os = "android")]
#[unsafe(no_mangle)]
pub fn android_main(app: android_activity::AndroidApp) {
use android_activity::WindowManagerFlags;
app.set_window_flags(WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty());
kubi_main(app)
kubi_main_impl(app);
}

#[cfg(feature = "c-ffi")]
#[cfg(not(target_os = "android"))]
#[unsafe(no_mangle)]
pub fn kubi_main(
pub extern "C" fn kubi_main() {
// cant let unwinds cross the ffi boundary!
// also, hopefully this code should never panic either...
let panic = std::panic::catch_unwind(|| {
kubi_main_impl();
});
if panic.is_err() {
println!("!!! PANIC CAUGHT ON FFI BOUNDARY !!!");
};
std::mem::forget(panic); // forget the result, as dropping it will cause unwinding!
}

pub fn kubi_main_impl(
#[cfg(target_os = "android")]
app: android_activity::AndroidApp
) {
Expand Down
4 changes: 2 additions & 2 deletions kubi/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg_attr(
all(windows, not(debug_assertions)),
all(windows, not(debug_assertions)),
windows_subsystem = "windows"
)]

fn main() {
kubilib::kubi_main();
kubilib::kubi_main_impl();
}

0 comments on commit 518b2c3

Please sign in to comment.