diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e53488f..7ab6d4a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2,23 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Nothing" -version = "0.0.0" -dependencies = [ - "Underlayer", - "crossbeam", - "log", - "raw-window-handle", - "serde", - "serde_json", - "simple_logger", - "statig", - "tauri", - "tauri-build", - "x11rb", -] - [[package]] name = "Underlayer" version = "0.2.2" @@ -2033,6 +2016,23 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nothing" +version = "0.0.0" +dependencies = [ + "Underlayer", + "crossbeam", + "log", + "raw-window-handle", + "serde", + "serde_json", + "simple_logger", + "statig", + "tauri", + "tauri-build", + "x11rb", +] + [[package]] name = "notify-rust" version = "4.8.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index bcdd8da..79dfb0e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "Nothing" +name = "nothing" version = "0.0.0" description = "A Tauri App" authors = ["you"] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2d289f6..7dad4fb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -39,7 +39,7 @@ fn main() { tauri::Builder::default() .setup(|app| { - let tx = Overlay::new( + let tx = Overlay::initialize( app.get_window("Overlay") .expect("Could not get main overlay window"), "Untitled 1 - Mousepad", diff --git a/src-tauri/src/overlay.rs b/src-tauri/src/overlay.rs index fc7234b..07a83d9 100644 --- a/src-tauri/src/overlay.rs +++ b/src-tauri/src/overlay.rs @@ -1,25 +1,14 @@ -#![allow(unused)] - -use std::{ - borrow::BorrowMut, - cell::RefCell, - ops::DerefMut, - sync::{mpsc::Receiver as MpscReceiver, Arc, Mutex}, - time::Duration, -}; - use crossbeam::{ - channel::{Receiver, Select, Sender}, + channel::{Receiver, Sender}, select, }; use serde::Serialize; -// The prelude module re-exports the most common used items from statig. use statig::prelude::*; +use std::sync::{mpsc::Receiver as MpscReceiver, Mutex}; use tauri::{Manager, PhysicalPosition, PhysicalSize, Window}; use underlayer::{Bounds, UnderlayEvent}; -use crate::overlay; - +#[derive(Debug)] pub enum Event { State(State), Bounds(Bounds), @@ -49,17 +38,14 @@ fn wrap_underlay_rx(rx: MpscReceiver) -> Receiver } impl Overlay { - pub fn new(window: Window, target_title: &str) -> Sender { - log::warn!("New overlay object"); - let mut overlay = Self { + pub fn initialize(window: Window, target_title: &str) -> Sender { + let overlay: Overlay = Self { window: window.clone(), bounds: Bounds::default(), previous: State::hidden(), }; - window.manage(Mutex::new(OverlaySettings { - auto_hide: true, - })); + window.manage(Mutex::new(OverlaySettings { auto_hide: true })); let mut fsm = Overlay::uninitialized_state_machine(overlay).init(); @@ -67,11 +53,10 @@ impl Overlay { let (ee_tx, ee_rx) = crossbeam::channel::unbounded(); let (window_event_tx, window_event_rx) = crossbeam::channel::unbounded(); - window.on_window_event(move |event| match event { - tauri::WindowEvent::Focused(focus) => { + window.on_window_event(move |event| { + if let tauri::WindowEvent::Focused(focus) = event { window_event_tx.send(*focus).ok(); } - _ => {} }); std::thread::spawn(move || loop { @@ -105,32 +90,26 @@ impl Overlay { } fn handle_overlay_focused(fsm: &mut InitializedStateMachine, focus: bool) { - match fsm.state() { - State::Visible {} => { - if focus { - fsm.window.set_ignore_cursor_events(true); - underlayer::focus_target(); - } - }, - _ => {} + if let State::Visible {} = fsm.state() { + if focus { + fsm.window.set_ignore_cursor_events(true).ok(); + underlayer::focus_target(); + } } } fn handle_underlay_event(fsm: &mut InitializedStateMachine, event: UnderlayEvent) { - let settings = fsm.window.state::(); match event { UnderlayEvent::Attach { bounds, - has_access, - is_fullscreen, + has_access: _, + is_fullscreen: _, } => { fsm.handle(&Event::Bounds(bounds)); } UnderlayEvent::MoveResize(bounds) => fsm.handle(&Event::Bounds(bounds)), UnderlayEvent::Detach => fsm.handle(&Event::State(State::hidden())), - UnderlayEvent::Focus => { - fsm.handle(&Event::State(State::Visible {})) - } + UnderlayEvent::Focus => fsm.handle(&Event::State(State::Visible {})), UnderlayEvent::Blur => { if !fsm.window.is_focused().unwrap() && fsm @@ -142,7 +121,7 @@ impl Overlay { fsm.handle(&Event::State(State::Hidden {})) } } - UnderlayEvent::X11FullscreenEvent { is_fullscreen } => {} + UnderlayEvent::X11FullscreenEvent { is_fullscreen: _ } => {} } } @@ -160,14 +139,16 @@ impl Overlay { impl Overlay { #[action] fn on_enter_visible(&mut self) { - self.window.set_always_on_top(true); - self.window.show(); - self.window.set_resizable(true); + self.window.set_always_on_top(true).ok(); + self.window.show().ok(); + self.window.set_resizable(true).ok(); if self.bounds.width > 0 && self.bounds.height > 0 { self.window - .set_position(PhysicalPosition::new(self.bounds.x, self.bounds.y)); + .set_position(PhysicalPosition::new(self.bounds.x, self.bounds.y)) + .ok(); self.window - .set_size(PhysicalSize::new(self.bounds.width, self.bounds.height)); + .set_size(PhysicalSize::new(self.bounds.width, self.bounds.height)) + .ok(); } log::trace!("on_enter_visible"); @@ -176,21 +157,21 @@ impl Overlay { #[action] fn on_enter_interactable(&mut self) { log::trace!("on_enter_interactable"); - self.window.set_ignore_cursor_events(false); - self.window.set_focus(); + self.window.set_ignore_cursor_events(false).ok(); + self.window.set_focus().ok(); } #[action] fn on_enter_hidden(&mut self) { log::trace!("on_enter_hidden"); - self.window.hide(); - self.window.set_resizable(false); + self.window.hide().ok(); + self.window.set_resizable(false).ok(); } #[action] fn on_exit_interactable(&mut self) { log::trace!("on_exit_interactable"); - self.window.set_ignore_cursor_events(true); + self.window.set_ignore_cursor_events(true).ok(); } #[state(superstate = "super_visible")] @@ -205,10 +186,7 @@ impl Overlay { } } - #[state( - superstate = "common", - entry_action = "on_enter_hidden" - )] + #[state(superstate = "common", entry_action = "on_enter_hidden")] fn hidden(&mut self, event: &Event) -> Response { match event { Event::State(underlying) => match underlying { @@ -237,6 +215,7 @@ impl Overlay { } #[superstate(superstate = "common", entry_action = "on_enter_visible")] + #[allow(unused_variables)] fn super_visible(&mut self, event: &Event) -> Response { log::trace!("in super_visible"); Super @@ -250,9 +229,11 @@ impl Overlay { self.bounds = *bounds; if bounds.width > 0 && bounds.height > 0 { self.window - .set_position(PhysicalPosition::new(bounds.x, bounds.y)); + .set_position(PhysicalPosition::new(bounds.x, bounds.y)) + .ok(); self.window - .set_size(PhysicalSize::new(bounds.width, bounds.height)); + .set_size(PhysicalSize::new(bounds.width, bounds.height)) + .ok(); } Super } @@ -269,6 +250,6 @@ impl Overlay { if src != dest { self.previous = src.clone(); } - self.window.emit("OverlayStateChange", dest); + self.window.emit("OverlayStateChange", dest).ok(); } }