|
|
|
@ -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<UnderlayEvent>) -> Receiver<UnderlayEvent>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Overlay {
|
|
|
|
|
pub fn new(window: Window, target_title: &str) -> Sender<Event> {
|
|
|
|
|
log::warn!("New overlay object");
|
|
|
|
|
let mut overlay = Self {
|
|
|
|
|
pub fn initialize(window: Window, target_title: &str) -> Sender<Event> {
|
|
|
|
|
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<Overlay>, 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<Overlay>, event: UnderlayEvent) {
|
|
|
|
|
let settings = fsm.window.state::<LockedOverlaySettings>();
|
|
|
|
|
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<State> {
|
|
|
|
|
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<State> {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|