|
|
|
@ -4,10 +4,26 @@ use crossbeam::{
|
|
|
|
|
};
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
use statig::prelude::*;
|
|
|
|
|
use std::sync::{mpsc::Receiver as MpscReceiver, Mutex};
|
|
|
|
|
use std::{
|
|
|
|
|
sync::{mpsc::Receiver as MpscReceiver, Mutex},
|
|
|
|
|
time::Duration,
|
|
|
|
|
};
|
|
|
|
|
use tauri::{Manager, PhysicalPosition, PhysicalSize, Window};
|
|
|
|
|
use underlayer::{Bounds, UnderlayEvent};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<State> for Event {
|
|
|
|
|
fn from(value: State) -> Self {
|
|
|
|
|
Self::State(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<&State> for Event {
|
|
|
|
|
fn from(value: &State) -> Self {
|
|
|
|
|
Self::State(value.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum Event {
|
|
|
|
|
State(State),
|
|
|
|
@ -22,10 +38,10 @@ pub struct Overlay {
|
|
|
|
|
previous: State,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct OverlaySettings {
|
|
|
|
|
pub struct OverlayData {
|
|
|
|
|
pub auto_hide: bool,
|
|
|
|
|
}
|
|
|
|
|
pub type LockedOverlaySettings = Mutex<OverlaySettings>;
|
|
|
|
|
pub type LockedOverlayData = Mutex<OverlayData>;
|
|
|
|
|
|
|
|
|
|
fn wrap_underlay_rx(rx: MpscReceiver<UnderlayEvent>) -> Receiver<UnderlayEvent> {
|
|
|
|
|
let (cb_underlay_tx, cb_underlay_rx) = crossbeam::channel::unbounded();
|
|
|
|
@ -45,7 +61,9 @@ impl Overlay {
|
|
|
|
|
previous: State::hidden(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.manage(Mutex::new(OverlaySettings { auto_hide: true }));
|
|
|
|
|
window.manage(Mutex::new(OverlayData {
|
|
|
|
|
auto_hide: true
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
let mut fsm = Overlay::uninitialized_state_machine(overlay).init();
|
|
|
|
|
|
|
|
|
@ -90,12 +108,15 @@ impl Overlay {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_overlay_focused(fsm: &mut InitializedStateMachine<Overlay>, focus: bool) {
|
|
|
|
|
if let State::Visible {} = fsm.state() {
|
|
|
|
|
match fsm.state() {
|
|
|
|
|
State::Visible {} => {
|
|
|
|
|
if focus {
|
|
|
|
|
fsm.window.set_ignore_cursor_events(true).ok();
|
|
|
|
|
underlayer::focus_target();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_underlay_event(fsm: &mut InitializedStateMachine<Overlay>, event: UnderlayEvent) {
|
|
|
|
@ -108,17 +129,21 @@ impl Overlay {
|
|
|
|
|
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::Detach => fsm.handle(&State::hidden().into()),
|
|
|
|
|
UnderlayEvent::Focus => {
|
|
|
|
|
if let State::Hidden {} = fsm.state() {
|
|
|
|
|
fsm.handle(&State::Visible { }.into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UnderlayEvent::Blur => {
|
|
|
|
|
if !fsm.window.is_focused().unwrap()
|
|
|
|
|
&& fsm
|
|
|
|
|
.window
|
|
|
|
|
.state::<LockedOverlaySettings>()
|
|
|
|
|
.state::<LockedOverlayData>()
|
|
|
|
|
.lock()
|
|
|
|
|
.is_ok_and(|s| s.auto_hide)
|
|
|
|
|
{
|
|
|
|
|
fsm.handle(&Event::State(State::Hidden {}))
|
|
|
|
|
fsm.handle(&State::Hidden {}.into())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UnderlayEvent::X11FullscreenEvent { is_fullscreen: _ } => {}
|
|
|
|
@ -150,31 +175,31 @@ impl Overlay {
|
|
|
|
|
.set_size(PhysicalSize::new(self.bounds.width, self.bounds.height))
|
|
|
|
|
.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log::trace!("on_enter_visible");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[action]
|
|
|
|
|
fn on_enter_interactable(&mut self) {
|
|
|
|
|
log::trace!("on_enter_interactable");
|
|
|
|
|
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().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).ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[state(superstate = "super_visible")]
|
|
|
|
|
#[action]
|
|
|
|
|
fn on_explicitly_visible(&mut self) {
|
|
|
|
|
underlayer::focus_target();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[state(superstate = "super_visible", entry_action = "on_explicitly_visible")]
|
|
|
|
|
fn visible(&mut self, event: &Event) -> Response<State> {
|
|
|
|
|
match event {
|
|
|
|
|
Event::State(underlying) => match underlying {
|
|
|
|
@ -217,13 +242,11 @@ impl Overlay {
|
|
|
|
|
#[superstate(superstate = "common", entry_action = "on_enter_visible")]
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
fn super_visible(&mut self, event: &Event) -> Response<State> {
|
|
|
|
|
log::trace!("in super_visible");
|
|
|
|
|
Super
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[superstate]
|
|
|
|
|
fn common(&mut self, event: &Event) -> Response<State> {
|
|
|
|
|
log::trace!("in common");
|
|
|
|
|
match event {
|
|
|
|
|
Event::Bounds(bounds) => {
|
|
|
|
|
self.bounds = *bounds;
|
|
|
|
@ -246,7 +269,6 @@ impl Overlay {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_transition(&mut self, src: &State, dest: &State) {
|
|
|
|
|
log::trace!("from {src:?} to {dest:?}");
|
|
|
|
|
if src != dest {
|
|
|
|
|
self.previous = src.clone();
|
|
|
|
|
}
|
|
|
|
|