Cleanup, fixed lots of small warnings

merge-notes
isark 2 years ago
parent d4f827154c
commit 8a6e22a6d1

34
src-tauri/Cargo.lock generated

@ -2,23 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 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]] [[package]]
name = "Underlayer" name = "Underlayer"
version = "0.2.2" version = "0.2.2"
@ -2033,6 +2016,23 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" 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]] [[package]]
name = "notify-rust" name = "notify-rust"
version = "4.8.0" version = "4.8.0"

@ -1,5 +1,5 @@
[package] [package]
name = "Nothing" name = "nothing"
version = "0.0.0" version = "0.0.0"
description = "A Tauri App" description = "A Tauri App"
authors = ["you"] authors = ["you"]

@ -39,7 +39,7 @@ fn main() {
tauri::Builder::default() tauri::Builder::default()
.setup(|app| { .setup(|app| {
let tx = Overlay::new( let tx = Overlay::initialize(
app.get_window("Overlay") app.get_window("Overlay")
.expect("Could not get main overlay window"), .expect("Could not get main overlay window"),
"Untitled 1 - Mousepad", "Untitled 1 - Mousepad",

@ -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::{ use crossbeam::{
channel::{Receiver, Select, Sender}, channel::{Receiver, Sender},
select, select,
}; };
use serde::Serialize; use serde::Serialize;
// The prelude module re-exports the most common used items from statig.
use statig::prelude::*; use statig::prelude::*;
use std::sync::{mpsc::Receiver as MpscReceiver, Mutex};
use tauri::{Manager, PhysicalPosition, PhysicalSize, Window}; use tauri::{Manager, PhysicalPosition, PhysicalSize, Window};
use underlayer::{Bounds, UnderlayEvent}; use underlayer::{Bounds, UnderlayEvent};
use crate::overlay; #[derive(Debug)]
pub enum Event { pub enum Event {
State(State), State(State),
Bounds(Bounds), Bounds(Bounds),
@ -49,17 +38,14 @@ fn wrap_underlay_rx(rx: MpscReceiver<UnderlayEvent>) -> Receiver<UnderlayEvent>
} }
impl Overlay { impl Overlay {
pub fn new(window: Window, target_title: &str) -> Sender<Event> { pub fn initialize(window: Window, target_title: &str) -> Sender<Event> {
log::warn!("New overlay object"); let overlay: Overlay = Self {
let mut overlay = Self {
window: window.clone(), window: window.clone(),
bounds: Bounds::default(), bounds: Bounds::default(),
previous: State::hidden(), previous: State::hidden(),
}; };
window.manage(Mutex::new(OverlaySettings { window.manage(Mutex::new(OverlaySettings { auto_hide: true }));
auto_hide: true,
}));
let mut fsm = Overlay::uninitialized_state_machine(overlay).init(); let mut fsm = Overlay::uninitialized_state_machine(overlay).init();
@ -67,11 +53,10 @@ impl Overlay {
let (ee_tx, ee_rx) = crossbeam::channel::unbounded(); let (ee_tx, ee_rx) = crossbeam::channel::unbounded();
let (window_event_tx, window_event_rx) = crossbeam::channel::unbounded(); let (window_event_tx, window_event_rx) = crossbeam::channel::unbounded();
window.on_window_event(move |event| match event { window.on_window_event(move |event| {
tauri::WindowEvent::Focused(focus) => { if let tauri::WindowEvent::Focused(focus) = event {
window_event_tx.send(*focus).ok(); window_event_tx.send(*focus).ok();
} }
_ => {}
}); });
std::thread::spawn(move || loop { std::thread::spawn(move || loop {
@ -105,32 +90,26 @@ impl Overlay {
} }
fn handle_overlay_focused(fsm: &mut InitializedStateMachine<Overlay>, focus: bool) { fn handle_overlay_focused(fsm: &mut InitializedStateMachine<Overlay>, focus: bool) {
match fsm.state() { if let State::Visible {} = fsm.state() {
State::Visible {} => {
if focus { if focus {
fsm.window.set_ignore_cursor_events(true); fsm.window.set_ignore_cursor_events(true).ok();
underlayer::focus_target(); underlayer::focus_target();
} }
},
_ => {}
} }
} }
fn handle_underlay_event(fsm: &mut InitializedStateMachine<Overlay>, event: UnderlayEvent) { fn handle_underlay_event(fsm: &mut InitializedStateMachine<Overlay>, event: UnderlayEvent) {
let settings = fsm.window.state::<LockedOverlaySettings>();
match event { match event {
UnderlayEvent::Attach { UnderlayEvent::Attach {
bounds, bounds,
has_access, has_access: _,
is_fullscreen, is_fullscreen: _,
} => { } => {
fsm.handle(&Event::Bounds(bounds)); fsm.handle(&Event::Bounds(bounds));
} }
UnderlayEvent::MoveResize(bounds) => fsm.handle(&Event::Bounds(bounds)), UnderlayEvent::MoveResize(bounds) => fsm.handle(&Event::Bounds(bounds)),
UnderlayEvent::Detach => fsm.handle(&Event::State(State::hidden())), UnderlayEvent::Detach => fsm.handle(&Event::State(State::hidden())),
UnderlayEvent::Focus => { UnderlayEvent::Focus => fsm.handle(&Event::State(State::Visible {})),
fsm.handle(&Event::State(State::Visible {}))
}
UnderlayEvent::Blur => { UnderlayEvent::Blur => {
if !fsm.window.is_focused().unwrap() if !fsm.window.is_focused().unwrap()
&& fsm && fsm
@ -142,7 +121,7 @@ impl Overlay {
fsm.handle(&Event::State(State::Hidden {})) fsm.handle(&Event::State(State::Hidden {}))
} }
} }
UnderlayEvent::X11FullscreenEvent { is_fullscreen } => {} UnderlayEvent::X11FullscreenEvent { is_fullscreen: _ } => {}
} }
} }
@ -160,14 +139,16 @@ impl Overlay {
impl Overlay { impl Overlay {
#[action] #[action]
fn on_enter_visible(&mut self) { fn on_enter_visible(&mut self) {
self.window.set_always_on_top(true); self.window.set_always_on_top(true).ok();
self.window.show(); self.window.show().ok();
self.window.set_resizable(true); self.window.set_resizable(true).ok();
if self.bounds.width > 0 && self.bounds.height > 0 { if self.bounds.width > 0 && self.bounds.height > 0 {
self.window 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 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"); log::trace!("on_enter_visible");
@ -176,21 +157,21 @@ impl Overlay {
#[action] #[action]
fn on_enter_interactable(&mut self) { fn on_enter_interactable(&mut self) {
log::trace!("on_enter_interactable"); log::trace!("on_enter_interactable");
self.window.set_ignore_cursor_events(false); self.window.set_ignore_cursor_events(false).ok();
self.window.set_focus(); self.window.set_focus().ok();
} }
#[action] #[action]
fn on_enter_hidden(&mut self) { fn on_enter_hidden(&mut self) {
log::trace!("on_enter_hidden"); log::trace!("on_enter_hidden");
self.window.hide(); self.window.hide().ok();
self.window.set_resizable(false); self.window.set_resizable(false).ok();
} }
#[action] #[action]
fn on_exit_interactable(&mut self) { fn on_exit_interactable(&mut self) {
log::trace!("on_exit_interactable"); log::trace!("on_exit_interactable");
self.window.set_ignore_cursor_events(true); self.window.set_ignore_cursor_events(true).ok();
} }
#[state(superstate = "super_visible")] #[state(superstate = "super_visible")]
@ -205,10 +186,7 @@ impl Overlay {
} }
} }
#[state( #[state(superstate = "common", entry_action = "on_enter_hidden")]
superstate = "common",
entry_action = "on_enter_hidden"
)]
fn hidden(&mut self, event: &Event) -> Response<State> { fn hidden(&mut self, event: &Event) -> Response<State> {
match event { match event {
Event::State(underlying) => match underlying { Event::State(underlying) => match underlying {
@ -237,6 +215,7 @@ impl Overlay {
} }
#[superstate(superstate = "common", entry_action = "on_enter_visible")] #[superstate(superstate = "common", entry_action = "on_enter_visible")]
#[allow(unused_variables)]
fn super_visible(&mut self, event: &Event) -> Response<State> { fn super_visible(&mut self, event: &Event) -> Response<State> {
log::trace!("in super_visible"); log::trace!("in super_visible");
Super Super
@ -250,9 +229,11 @@ impl Overlay {
self.bounds = *bounds; self.bounds = *bounds;
if bounds.width > 0 && bounds.height > 0 { if bounds.width > 0 && bounds.height > 0 {
self.window self.window
.set_position(PhysicalPosition::new(bounds.x, bounds.y)); .set_position(PhysicalPosition::new(bounds.x, bounds.y))
.ok();
self.window self.window
.set_size(PhysicalSize::new(bounds.width, bounds.height)); .set_size(PhysicalSize::new(bounds.width, bounds.height))
.ok();
} }
Super Super
} }
@ -269,6 +250,6 @@ impl Overlay {
if src != dest { if src != dest {
self.previous = src.clone(); self.previous = src.clone();
} }
self.window.emit("OverlayStateChange", dest); self.window.emit("OverlayStateChange", dest).ok();
} }
} }

Loading…
Cancel
Save