Przeglądaj źródła

app: when screen is off stop ticking to preserve battery

darkfi 2 tygodni temu
rodzic
commit
7f0b0c8077
3 zmienionych plików z 28 dodań i 4 usunięć
  1. 1 1
      bin/app/Cargo.lock
  2. 1 1
      bin/app/Cargo.toml
  3. 26 2
      bin/app/src/gfx/mod.rs

+ 1 - 1
bin/app/Cargo.lock

@@ -4858,7 +4858,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
 [[package]]
 name = "miniquad"
 version = "0.4.11"
-source = "git+https://github.com/not-fl3/miniquad#39fdef68b5ccb0d243875764745788e394c9378d"
+source = "git+https://github.com/narodnik/miniquad#d50fcecf5903964ce904db7759bfb6a83a72c49d"
 dependencies = [
  "libc",
  "ndk-sys 0.2.2",

+ 1 - 1
bin/app/Cargo.toml

@@ -9,7 +9,7 @@ homepage = "https://dark.fi"
 repository = "https://git.dark.fi/darkrenaissance/darkfi"
 
 [dependencies]
-miniquad = { git = "https://github.com/not-fl3/miniquad" }
+miniquad = { git = "https://github.com/narodnik/miniquad" }
 
 image = "0.25.9"
 qoi = "0.4.1"

+ 26 - 2
bin/app/src/gfx/mod.rs

@@ -1318,8 +1318,33 @@ impl EventHandler for Stage {
         let god = GOD.get().unwrap();
         god.stop_app();
     }
+
+    fn window_minimized_event(&mut self) {
+        debug!(target: "gfx", "window minimized");
+        #[cfg(target_os = "android")]
+        {
+            miniquad::window::set_sleep_interval(None);
+
+            // Drive the screen-off transition here instead of waiting for the
+            // next update() tick: with the event loop paused there may be no
+            // ticks until the screen comes back on.
+            self.screen_state = ScreenState::SwitchOff;
+            self.event_pub.notify_screen_changed(false);
+            self.pruner.drain(&self.method_recv);
+        }
+    }
+
+    fn window_restored_event(&mut self) {
+        debug!(target: "gfx", "window restored");
+        #[cfg(target_os = "android")]
+        miniquad::window::set_sleep_interval(Some(SLEEP_INTERVAL_MS));
+    }
 }
 
+/// Android: periodic wakeup interval for the blocking event loop.
+/// Used in the `Conf` and restored in `window_restored_event`.
+const SLEEP_INTERVAL_MS: u32 = 40;
+
 pub fn run_gui(linux_backend: miniquad::conf::LinuxBackend) {
     let mut window_width = 1024;
     let mut window_height = 768;
@@ -1339,8 +1364,7 @@ pub fn run_gui(linux_backend: miniquad::conf::LinuxBackend) {
             linux_backend,
             #[cfg(target_os = "android")]
             blocking_event_loop: true,
-            #[cfg(target_os = "android")]
-            sleep_interval_ms: Some(40),
+            sleep_interval_ms: Some(SLEEP_INTERVAL_MS),
             android_panic_hook: false,
             ..Default::default()
         },