diff --git a/Cargo.lock b/Cargo.lock index 775eacbe..2876c74a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,21 +76,21 @@ dependencies = [ [[package]] name = "android-activity" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee91c0c2905bae44f84bfa4e044536541df26b7703fd0888deeb9060fcc44289" +checksum = "ef6978589202a00cd7e118380c448a08b6ed394c3a8df3a430d0898e3a42d046" dependencies = [ "android-properties", - "bitflags 2.4.2", + "bitflags 2.5.0", "cc", "cesu8", "jni 0.21.1", "jni-sys", "libc", "log", - "ndk 0.8.0", + "ndk 0.9.0", "ndk-context", - "ndk-sys 0.5.0+25.2.9519653", + "ndk-sys 0.6.0+11769913", "num_enum 0.7.2", "thiserror", ] @@ -381,7 +381,7 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cexpr", "clang-sys", "itertools", @@ -424,9 +424,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" dependencies = [ "serde", ] @@ -446,22 +446,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae85a0696e7ea3b835a453750bf002770776609115e6d25c6d2ff28a8200f7e7" -dependencies = [ - "objc-sys", -] - [[package]] name = "block2" -version = "0.3.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" dependencies = [ - "block-sys", "objc2", ] @@ -531,7 +521,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "log", "polling", "rustix", @@ -908,7 +898,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e3d747f100290a1ca24b752186f61f6637e1deffe3bf6320de6fcb29510a307" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libloading 0.8.1", "winapi", ] @@ -967,13 +957,19 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "dpi" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" + [[package]] name = "drm" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0f8a69e60d75ae7dab4ef26a59ca99f2a89d4c142089b537775ae0c198bdcde" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "drm-ffi", "drm-fourcc", @@ -1525,7 +1521,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "gpu-alloc-types", ] @@ -1535,7 +1531,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", ] [[package]] @@ -1557,7 +1553,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc11df1ace8e7e564511f53af41f3e42ddc95b56fd07b3f4445d2a6048bc682c" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "gpu-descriptor-types", "hashbrown", ] @@ -1568,7 +1564,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bf0b36e6f090b7e1d8a4b49c0cb81c1f8376f72198c65dd3ad9ff3556b8b78c" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", ] [[package]] @@ -1607,7 +1603,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "com", "libc", "libloading 0.8.1", @@ -1646,7 +1642,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55f9226618af7e8155fc8a233e4d84dc1ec44438705f972e35d5d50e62f937df" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "glam", "log", "num-traits", @@ -1654,7 +1650,7 @@ dependencies = [ "raw-window-handle 0.6.0", "smol_str", "thiserror", - "web-time", + "web-time 0.2.4", "xxhash-rust", ] @@ -1677,7 +1673,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0660df444c64a13f72999c55a324f6d3ea020167bb1af8ef43fe2bff168d8c27" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "cosmic-text", "half", @@ -1753,7 +1749,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa5d3ce370c7044ddc9535c8f87057f1008434a495be6b9f46b2666c3e9638f7" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "futures", "glam", @@ -1779,17 +1775,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "icrate" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" -dependencies = [ - "block2", - "dispatch", - "objc2", -] - [[package]] name = "idna" version = "0.5.0" @@ -2026,7 +2011,7 @@ version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "redox_syscall 0.4.1", ] @@ -2125,7 +2110,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43f73953f8cbe511f021b58f18c3ce1c3d1ae13fe953293e13345bf83217f25" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "block", "core-graphics-types", "foreign-types", @@ -2211,7 +2196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8878eb410fc90853da3908aebfe61d73d26d4437ef850b70050461f939509899" dependencies = [ "bit-set", - "bitflags 2.4.2", + "bitflags 2.5.0", "codespan-reporting", "hexf-parse", "indexmap", @@ -2240,14 +2225,14 @@ dependencies = [ [[package]] name = "ndk" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "jni-sys", "log", - "ndk-sys 0.5.0+25.2.9519653", + "ndk-sys 0.6.0+11769913", "num_enum 0.7.2", "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", @@ -2271,9 +2256,9 @@ dependencies = [ [[package]] name = "ndk-sys" -version = "0.5.0+25.2.9519653" +version = "0.6.0+11769913" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" dependencies = [ "jni-sys", ] @@ -2367,7 +2352,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg-if", "libc", "memoffset", @@ -2489,25 +2474,103 @@ dependencies = [ [[package]] name = "objc-sys" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7c71324e4180d0899963fc83d9d241ac39e699609fc1025a850aadac8257459" +checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" [[package]] name = "objc2" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" +checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" dependencies = [ "objc-sys", "objc2-encode", ] +[[package]] +name = "objc2-app-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" +dependencies = [ + "bitflags 2.5.0", + "block2", + "libc", + "objc2", + "objc2-core-data", + "objc2-core-image", + "objc2-foundation", + "objc2-quartz-core", +] + +[[package]] +name = "objc2-core-data" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" +dependencies = [ + "bitflags 2.5.0", + "block2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-image" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" +dependencies = [ + "block2", + "objc2", + "objc2-foundation", + "objc2-metal", +] + [[package]] name = "objc2-encode" -version = "3.0.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" +checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" + +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.5.0", + "block2", + "dispatch", + "libc", + "objc2", +] + +[[package]] +name = "objc2-metal" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" +dependencies = [ + "bitflags 2.5.0", + "block2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" +dependencies = [ + "bitflags 2.5.0", + "block2", + "objc2", + "objc2-foundation", + "objc2-metal", +] [[package]] name = "objc_exception" @@ -2590,7 +2653,7 @@ version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ac4177ce94a34c3bcfa9e39f8338c8170918faa560d00dd923d984331a749e4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "byte-slice-cast", "byteorder", "generational-arena", @@ -2743,6 +2806,26 @@ dependencies = [ name = "piano-math" version = "0.1.0" +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -2970,15 +3053,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -3059,7 +3133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ "base64", - "bitflags 2.4.2", + "bitflags 2.5.0", "serde", "serde_derive", ] @@ -3091,7 +3165,7 @@ version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys 0.4.13", @@ -3138,9 +3212,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sctk-adwaita" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b2eaf3a5b264a521b988b2e73042e742df700c4f962cde845d1541adb46550" +checksum = "7de61fa7334ee8ee1f5c3c58dcc414fb9361e7e8f5bff9d45f4d69eeb89a7169" dependencies = [ "ab_glyph", "log", @@ -3269,7 +3343,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60e3d9941fa3bacf7c2bf4b065304faa14164151254cd16ce1b1bc8fc381600f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "calloop", "calloop-wayland-source", "cursor-icon", @@ -3352,7 +3426,7 @@ version = "0.3.0+sdk-1.3.268.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", ] [[package]] @@ -3872,7 +3946,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "rustix", "wayland-backend", "wayland-scanner", @@ -3884,7 +3958,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "cursor-icon", "wayland-backend", ] @@ -3906,7 +3980,7 @@ version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-scanner", @@ -3918,7 +3992,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-protocols", @@ -3931,7 +4005,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "wayland-backend", "wayland-client", "wayland-protocols", @@ -3981,6 +4055,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "weezl" version = "0.1.8" @@ -4020,7 +4104,7 @@ checksum = "6b15e451d4060ada0d99a64df44e4d590213496da7c4f245572d51071e8e30ed" dependencies = [ "arrayvec", "bit-vec", - "bitflags 2.4.2", + "bitflags 2.5.0", "cfg_aliases 0.1.1", "codespan-reporting", "indexmap", @@ -4048,7 +4132,7 @@ dependencies = [ "arrayvec", "ash", "bit-set", - "bitflags 2.4.2", + "bitflags 2.5.0", "block", "cfg_aliases 0.1.1", "core-graphics-types", @@ -4098,7 +4182,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "895fcbeb772bfb049eb80b2d6e47f6c9af235284e9703c96fc0218a42ffd5af2" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "js-sys", "web-sys", ] @@ -4383,38 +4467,40 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winit" -version = "0.29.10" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c824f11941eeae66ec71111cc2674373c772f482b58939bb4066b642aa2ffcf" +checksum = "ea9e6d5d66cbf702e0dd820302144f51b69a95acdc495dd98ca280ff206562b1" dependencies = [ "ahash", "android-activity", "atomic-waker", - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "calloop", - "cfg_aliases 0.1.1", + "cfg_aliases 0.2.0", + "concurrent-queue", "core-foundation", "core-graphics", "cursor-icon", - "icrate", + "dpi", "js-sys", "libc", - "log", "memmap2 0.9.4", - "ndk 0.8.0", - "ndk-sys 0.5.0+25.2.9519653", + "ndk 0.9.0", "objc2", - "once_cell", + "objc2-app-kit", + "objc2-foundation", "orbclient", "percent-encoding", + "pin-project", "raw-window-handle 0.5.2", "raw-window-handle 0.6.0", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "rustix", "sctk-adwaita", "smithay-client-toolkit", "smol_str", + "tracing", "unicode-segmentation", "wasm-bindgen", "wasm-bindgen-futures", @@ -4423,8 +4509,8 @@ dependencies = [ "wayland-protocols", "wayland-protocols-plasma", "web-sys", - "web-time", - "windows-sys 0.48.0", + "web-time 1.1.0", + "windows-sys 0.52.0", "x11-dl", "x11rb", "xkbcommon-dl", @@ -4499,11 +4585,11 @@ dependencies = [ [[package]] name = "xkbcommon-dl" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" +checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "dlib", "log", "once_cell", diff --git a/neothesia/Cargo.toml b/neothesia/Cargo.toml index b1e413b6..0b3637b8 100644 --- a/neothesia/Cargo.toml +++ b/neothesia/Cargo.toml @@ -32,7 +32,7 @@ iced_wgpu.workspace = true iced_widget.workspace = true fps_ticker = "1" -winit = { version = "0.29", features = ["rwh_05"] } +winit = { version = "0.30", features = ["rwh_05"] } rfd = "0.14" async-thread = "0.1" diff --git a/neothesia/src/main.rs b/neothesia/src/main.rs index 8e6376df..7cca6b93 100644 --- a/neothesia/src/main.rs +++ b/neothesia/src/main.rs @@ -20,10 +20,9 @@ use midi_file::midly::MidiMessage; use neothesia_core::{config, render}; use wgpu_jumpstart::Surface; use wgpu_jumpstart::{Gpu, TransformUniform}; -use winit::{ - event::WindowEvent, - event_loop::{EventLoop, EventLoopBuilder}, -}; +use winit::application::ApplicationHandler; +use winit::event_loop::EventLoopProxy; +use winit::{event::WindowEvent, event_loop::EventLoop}; #[derive(Debug)] pub enum NeothesiaEvent { @@ -70,10 +69,11 @@ impl Neothesia { fn window_event( &mut self, - event: &WindowEvent, - event_loop: &winit::event_loop::EventLoopWindowTarget, + event_loop: &winit::event_loop::ActiveEventLoop, + _window_id: winit::window::WindowId, + event: WindowEvent, ) { - self.context.window_state.window_event(event); + self.context.window_state.window_event(&event); match &event { WindowEvent::Resized(_) => { @@ -129,13 +129,13 @@ impl Neothesia { _ => {} } - self.game_scene.window_event(&mut self.context, event); + self.game_scene.window_event(&mut self.context, &event); } - fn neothesia_event( + fn user_event( &mut self, + event_loop: &winit::event_loop::ActiveEventLoop, event: NeothesiaEvent, - event_loop: &winit::event_loop::EventLoopWindowTarget, ) { match event { NeothesiaEvent::Play(song) => { @@ -158,6 +158,10 @@ impl Neothesia { } } + fn about_to_wait(&mut self, _event_loop: &winit::event_loop::ActiveEventLoop) { + self.context.window.request_redraw(); + } + fn update(&mut self, delta: Duration) { #[cfg(debug_assertions)] { @@ -238,63 +242,79 @@ impl Neothesia { } } -fn main() { - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("neothesia=info")) - .init(); +// This is so stupid, but winit holds us at gunpoint with create_window deprecation +struct NeothesiaBootstrap(Option, EventLoopProxy); + +impl ApplicationHandler for NeothesiaBootstrap { + fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { + if self.0.is_some() { + return; + } + + let attributes = winit::window::Window::default_attributes() + .with_inner_size(winit::dpi::LogicalSize { + width: 1080.0, + height: 720.0, + }) + .with_title("Neothesia") + .with_theme(Some(winit::window::Theme::Dark)); + + let window = event_loop.create_window(attributes).unwrap(); - let event_loop: EventLoop = - EventLoopBuilder::with_user_event().build().unwrap(); - - let builder = winit::window::WindowBuilder::new() - .with_inner_size(winit::dpi::LogicalSize { - width: 1080.0, - height: 720.0, - }) - .with_title("Neothesia") - .with_theme(Some(winit::window::Theme::Dark)); - - // TODO: This can be removed now - #[cfg(target_os = "windows")] - let builder = { - use winit::platform::windows::WindowBuilderExtWindows; - builder.with_drag_and_drop(false) - }; - let window = builder.build(&event_loop).unwrap(); - - if let Err(err) = set_window_icon(&window) { - log::error!("Failed to load window icon: {}", err); + if let Err(err) = set_window_icon(&window) { + log::error!("Failed to load window icon: {}", err); + } + + let window_state = WindowState::new(&window); + let size = window.inner_size(); + let window = Arc::new(window); + let (gpu, surface) = + futures::executor::block_on(Gpu::for_window(window.clone(), size.width, size.height)) + .unwrap(); + + let ctx = Context::new(window, window_state, self.1.clone(), gpu); + + let app = Neothesia::new(ctx, surface); + self.0 = Some(app); } - let window_state = WindowState::new(&window); - let size = window.inner_size(); - let window = Arc::new(window); - let (gpu, surface) = - futures::executor::block_on(Gpu::for_window(window.clone(), size.width, size.height)) - .unwrap(); + fn user_event( + &mut self, + event_loop: &winit::event_loop::ActiveEventLoop, + event: NeothesiaEvent, + ) { + if let Some(app) = self.0.as_mut() { + app.user_event(event_loop, event); + } + } - let ctx = Context::new(window, window_state, event_loop.create_proxy(), gpu); + fn window_event( + &mut self, + event_loop: &winit::event_loop::ActiveEventLoop, + window_id: winit::window::WindowId, + event: WindowEvent, + ) { + if let Some(app) = self.0.as_mut() { + app.window_event(event_loop, window_id, event) + } + } - let mut app = Neothesia::new(ctx, surface); + fn about_to_wait(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { + if let Some(app) = self.0.as_mut() { + app.about_to_wait(event_loop) + } + } +} - // Investigate: - // https://github.com/gfx-rs/wgpu-rs/pull/306 +fn main() { + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("neothesia=info")) + .init(); + + let event_loop: EventLoop = EventLoop::with_user_event().build().unwrap(); + let proxy = event_loop.create_proxy(); event_loop - .run(move |event, event_loop| { - use winit::event::Event; - match event { - Event::UserEvent(event) => { - app.neothesia_event(event, event_loop); - } - Event::WindowEvent { event, .. } => { - app.window_event(&event, event_loop); - } - Event::AboutToWait => { - app.context.window.request_redraw(); - } - _ => {} - } - }) + .run_app(&mut NeothesiaBootstrap(None, proxy)) .unwrap(); }