generics + DashInterface impl (#334)

This commit is contained in:
galister
2025-12-28 18:44:58 +00:00
committed by GitHub
parent ee39e22472
commit 9425db9ae4
17 changed files with 348 additions and 156 deletions

View File

@@ -38,12 +38,12 @@ pub struct FrontendWidgets {
pub type FrontendTasks = Tasks<FrontendTask>; pub type FrontendTasks = Tasks<FrontendTask>;
pub struct Frontend { pub struct Frontend<T> {
pub layout: Layout, pub layout: Layout,
globals: WguiGlobals, globals: WguiGlobals,
pub settings: Box<dyn settings::SettingsIO>, pub settings: Box<dyn settings::SettingsIO>,
pub interface: BoxDashInterface, pub interface: BoxDashInterface<T>,
// async runtime executor // async runtime executor
pub executor: AsyncExecutor, pub executor: AsyncExecutor,
@@ -51,7 +51,7 @@ pub struct Frontend {
#[allow(dead_code)] #[allow(dead_code)]
state: ParserState, state: ParserState,
current_tab: Option<Box<dyn Tab>>, current_tab: Option<Box<dyn Tab<T>>>,
pub tasks: FrontendTasks, pub tasks: FrontendTasks,
@@ -68,9 +68,9 @@ pub struct Frontend {
pub(crate) desktop_finder: DesktopFinder, pub(crate) desktop_finder: DesktopFinder,
} }
pub struct InitParams { pub struct InitParams<T> {
pub settings: Box<dyn settings::SettingsIO>, pub settings: Box<dyn settings::SettingsIO>,
pub interface: BoxDashInterface, pub interface: BoxDashInterface<T>,
} }
#[derive(Clone)] #[derive(Clone)]
@@ -86,8 +86,8 @@ pub enum FrontendTask {
PushToast(Translation), PushToast(Translation),
} }
impl Frontend { impl<T: 'static> Frontend<T> {
pub fn new(params: InitParams) -> anyhow::Result<Frontend> { pub fn new(params: InitParams<T>) -> anyhow::Result<Frontend<T>> {
let mut assets = Box::new(assets::Asset {}); let mut assets = Box::new(assets::Asset {});
let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?; let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?;
@@ -164,15 +164,15 @@ impl Frontend {
Ok(frontend) Ok(frontend)
} }
pub fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> { pub fn update(&mut self, data: &mut T, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
let mut tasks = self.tasks.drain(); let mut tasks = self.tasks.drain();
while let Some(task) = tasks.pop_front() { while let Some(task) = tasks.pop_front() {
self.process_task(task)?; self.process_task(data, task)?;
} }
if let Some(mut tab) = self.current_tab.take() { if let Some(mut tab) = self.current_tab.take() {
tab.update(self)?; tab.update(self, data)?;
self.current_tab = Some(tab); self.current_tab = Some(tab);
} }
@@ -237,7 +237,6 @@ impl Frontend {
self.globals.clone(), self.globals.clone(),
self.settings.as_ref(), self.settings.as_ref(),
&mut self.layout, &mut self.layout,
&mut self.interface,
self.tasks.clone(), self.tasks.clone(),
params, params,
)?; )?;
@@ -273,7 +272,7 @@ impl Frontend {
Ok(()) Ok(())
} }
fn process_task(&mut self, task: FrontendTask) -> anyhow::Result<()> { fn process_task(&mut self, data: &mut T, task: FrontendTask) -> anyhow::Result<()> {
match task { match task {
FrontendTask::SetTab(tab_type) => self.set_tab(tab_type)?, FrontendTask::SetTab(tab_type) => self.set_tab(tab_type)?,
FrontendTask::RefreshClock => self.update_time()?, FrontendTask::RefreshClock => self.update_time()?,
@@ -282,7 +281,7 @@ impl Frontend {
FrontendTask::RefreshPopupManager => self.refresh_popup_manager()?, FrontendTask::RefreshPopupManager => self.refresh_popup_manager()?,
FrontendTask::ShowAudioSettings => self.action_show_audio_settings()?, FrontendTask::ShowAudioSettings => self.action_show_audio_settings()?,
FrontendTask::UpdateAudioSettingsView => self.action_update_audio_settings()?, FrontendTask::UpdateAudioSettingsView => self.action_update_audio_settings()?,
FrontendTask::RecenterPlayspace => self.action_recenter_playspace()?, FrontendTask::RecenterPlayspace => self.action_recenter_playspace(data)?,
FrontendTask::PushToast(content) => self.toast_manager.push(content), FrontendTask::PushToast(content) => self.toast_manager.push(content),
}; };
Ok(()) Ok(())
@@ -293,7 +292,7 @@ impl Frontend {
let widget_content = self.state.fetch_widget(&self.layout.state, "content")?; let widget_content = self.state.fetch_widget(&self.layout.state, "content")?;
self.layout.remove_children(widget_content.id); self.layout.remove_children(widget_content.id);
let tab: Box<dyn Tab> = match tab_type { let tab: Box<dyn Tab<T>> = match tab_type {
TabType::Home => Box::new(TabHome::new(self, widget_content.id)?), TabType::Home => Box::new(TabHome::new(self, widget_content.id)?),
TabType::Apps => Box::new(TabApps::new(self, widget_content.id)?), TabType::Apps => Box::new(TabApps::new(self, widget_content.id)?),
TabType::Games => Box::new(TabGames::new(self, widget_content.id)?), TabType::Games => Box::new(TabGames::new(self, widget_content.id)?),
@@ -407,8 +406,8 @@ impl Frontend {
Ok(()) Ok(())
} }
fn action_recenter_playspace(&mut self) -> anyhow::Result<()> { fn action_recenter_playspace(&mut self, data: &mut T) -> anyhow::Result<()> {
self.interface.recenter_playspace()?; self.interface.recenter_playspace(data)?;
Ok(()) Ok(())
} }
} }

View File

@@ -1,4 +1,4 @@
use std::{cell::RefCell, collections::HashMap, rc::Rc}; use std::{cell::RefCell, collections::HashMap, marker::PhantomData, rc::Rc};
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
@@ -28,7 +28,7 @@ struct State {
view_launcher: Option<(PopupHandle, views::app_launcher::View)>, view_launcher: Option<(PopupHandle, views::app_launcher::View)>,
} }
pub struct TabApps { pub struct TabApps<T> {
#[allow(dead_code)] #[allow(dead_code)]
parser_state: ParserState, parser_state: ParserState,
@@ -36,14 +36,15 @@ pub struct TabApps {
entries: Vec<DesktopEntry>, entries: Vec<DesktopEntry>,
app_list: AppList, app_list: AppList,
tasks: Tasks<Task>, tasks: Tasks<Task>,
marker: PhantomData<T>,
} }
impl Tab for TabApps { impl<T> Tab<T> for TabApps<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Apps TabType::Apps
} }
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
for task in self.tasks.drain() { for task in self.tasks.drain() {
@@ -53,7 +54,7 @@ impl Tab for TabApps {
} }
if let Some((_, launcher)) = &mut state.view_launcher { if let Some((_, launcher)) = &mut state.view_launcher {
launcher.update(&mut frontend.layout, &mut frontend.interface)?; launcher.update(&mut frontend.layout, &mut frontend.interface, data)?;
} }
Ok(()) Ok(())
} }
@@ -108,8 +109,8 @@ fn on_app_click(
}) })
} }
impl TabApps { impl<T> TabApps<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams { let doc_params = &ParseDocumentParams {
globals: frontend.layout.state.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/apps.xml"), path: AssetPath::BuiltIn("gui/tab/apps.xml"),
@@ -151,14 +152,15 @@ impl TabApps {
entries, entries,
state, state,
tasks, tasks,
marker: PhantomData,
}) })
} }
} }
impl AppList { impl AppList {
fn mount_entry( fn mount_entry<T>(
&mut self, &mut self,
frontend: &mut Frontend, frontend: &mut Frontend<T>,
parser_state: &mut ParserState, parser_state: &mut ParserState,
doc_params: &ParseDocumentParams, doc_params: &ParseDocumentParams,
list_parent: &WidgetPair, list_parent: &WidgetPair,
@@ -197,9 +199,9 @@ impl AppList {
data.fetch_component_as::<ComponentButton>("button") data.fetch_component_as::<ComponentButton>("button")
} }
fn mount_entries( fn mount_entries<T>(
&mut self, &mut self,
frontend: &mut Frontend, frontend: &mut Frontend<T>,
entries: &[DesktopEntry], entries: &[DesktopEntry],
parser_state: &mut ParserState, parser_state: &mut ParserState,
doc_params: &ParseDocumentParams, doc_params: &ParseDocumentParams,

View File

@@ -1,3 +1,5 @@
use std::marker::PhantomData;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID, layout::WidgetID,
@@ -10,26 +12,27 @@ use crate::{
views::game_list, views::game_list,
}; };
pub struct TabGames { pub struct TabGames<T> {
#[allow(dead_code)] #[allow(dead_code)]
pub state: ParserState, pub state: ParserState,
view_game_list: game_list::View, view_game_list: game_list::View,
marker: PhantomData<T>,
} }
impl Tab for TabGames { impl<T> Tab<T> for TabGames<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Games TabType::Games
} }
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
self.view_game_list.update(&mut frontend.layout, &frontend.executor)?; self.view_game_list.update(&mut frontend.layout, &frontend.executor)?;
Ok(()) Ok(())
} }
} }
impl TabGames { impl<T> TabGames<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: frontend.layout.state.globals.clone(), globals: frontend.layout.state.globals.clone(),
@@ -50,6 +53,10 @@ impl TabGames {
parent_id: game_list_parent, parent_id: game_list_parent,
})?; })?;
Ok(Self { state, view_game_list }) Ok(Self {
state,
view_game_list,
marker: PhantomData,
})
} }
} }

View File

@@ -1,3 +1,5 @@
use std::marker::PhantomData;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
components::button::ComponentButton, components::button::ComponentButton,
@@ -15,12 +17,13 @@ use crate::{
various, various,
}; };
pub struct TabHome { pub struct TabHome<T> {
#[allow(dead_code)] #[allow(dead_code)]
pub state: ParserState, pub state: ParserState,
marker: PhantomData<T>,
} }
impl Tab for TabHome { impl<T> Tab<T> for TabHome<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Home TabType::Home
} }
@@ -44,8 +47,8 @@ fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, s
label_hello.set_text(common, Translation::from_raw_text(&translated)); label_hello.set_text(common, Translation::from_raw_text(&translated));
} }
impl TabHome { impl<T> TabHome<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: frontend.layout.state.globals.clone(), globals: frontend.layout.state.globals.clone(),
@@ -73,6 +76,9 @@ impl TabHome {
tasks.handle_button(&btn_processes, FrontendTask::SetTab(TabType::Processes)); tasks.handle_button(&btn_processes, FrontendTask::SetTab(TabType::Processes));
tasks.handle_button(&btn_settings, FrontendTask::SetTab(TabType::Settings)); tasks.handle_button(&btn_settings, FrontendTask::SetTab(TabType::Settings));
Ok(Self { state }) Ok(Self {
state,
marker: PhantomData,
})
} }
} }

View File

@@ -17,11 +17,11 @@ pub enum TabType {
Settings, Settings,
} }
pub trait Tab { pub trait Tab<T> {
#[allow(dead_code)] #[allow(dead_code)]
fn get_type(&self) -> TabType; fn get_type(&self) -> TabType;
fn update(&mut self, _: &mut Frontend) -> anyhow::Result<()> { fn update(&mut self, _: &mut Frontend<T>, _: &mut T) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
} }

View File

@@ -1,3 +1,5 @@
use std::marker::PhantomData;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID, layout::WidgetID,
@@ -9,19 +11,20 @@ use crate::{
tab::{Tab, TabType}, tab::{Tab, TabType},
}; };
pub struct TabMonado { pub struct TabMonado<T> {
#[allow(dead_code)] #[allow(dead_code)]
pub state: ParserState, pub state: ParserState,
marker: PhantomData<T>,
} }
impl Tab for TabMonado { impl<T> Tab<T> for TabMonado<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Games TabType::Games
} }
} }
impl TabMonado { impl<T> TabMonado<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: frontend.layout.state.globals.clone(), globals: frontend.layout.state.globals.clone(),
@@ -32,6 +35,9 @@ impl TabMonado {
parent_id, parent_id,
)?; )?;
Ok(Self { state }) Ok(Self {
state,
marker: PhantomData,
})
} }
} }

View File

@@ -1,3 +1,5 @@
use std::marker::PhantomData;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID, layout::WidgetID,
@@ -10,32 +12,33 @@ use crate::{
views::{process_list, window_list}, views::{process_list, window_list},
}; };
pub struct TabProcesses { pub struct TabProcesses<T> {
#[allow(dead_code)] #[allow(dead_code)]
pub state: ParserState, pub state: ParserState,
view_window_list: window_list::View, view_window_list: window_list::View,
view_process_list: process_list::View, view_process_list: process_list::View,
marker: PhantomData<T>,
} }
impl Tab for TabProcesses { impl<T> Tab<T> for TabProcesses<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Games TabType::Games
} }
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
self self
.view_window_list .view_window_list
.update(&mut frontend.layout, &mut frontend.interface)?; .update(&mut frontend.layout, &mut frontend.interface, data)?;
self self
.view_process_list .view_process_list
.update(&mut frontend.layout, &mut frontend.interface)?; .update(&mut frontend.layout, &mut frontend.interface, data)?;
Ok(()) Ok(())
} }
} }
impl TabProcesses { impl<T> TabProcesses<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let globals = frontend.layout.state.globals.clone(); let globals = frontend.layout.state.globals.clone();
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
@@ -61,6 +64,7 @@ impl TabProcesses {
globals, globals,
})?, })?,
state, state,
marker: PhantomData,
}) })
} }
} }

View File

@@ -1,4 +1,4 @@
use std::rc::Rc; use std::{marker::PhantomData, rc::Rc};
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
@@ -18,19 +18,20 @@ enum Task {
ToggleSetting(SettingType, bool), ToggleSetting(SettingType, bool),
} }
pub struct TabSettings { pub struct TabSettings<T> {
#[allow(dead_code)] #[allow(dead_code)]
pub state: ParserState, pub state: ParserState,
tasks: Tasks<Task>, tasks: Tasks<Task>,
marker: PhantomData<T>,
} }
impl Tab for TabSettings { impl<T> Tab<T> for TabSettings<T> {
fn get_type(&self) -> TabType { fn get_type(&self) -> TabType {
TabType::Settings TabType::Settings
} }
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
for task in self.tasks.drain() { for task in self.tasks.drain() {
match task { match task {
Task::ToggleSetting(setting, n) => self.toggle_setting(frontend, setting, n), Task::ToggleSetting(setting, n) => self.toggle_setting(frontend, setting, n),
@@ -60,8 +61,8 @@ impl SettingType {
} }
} }
fn init_setting_checkbox( fn init_setting_checkbox<T>(
frontend: &mut Frontend, frontend: &mut Frontend<T>,
tasks: &Tasks<Task>, tasks: &Tasks<Task>,
checkbox: Rc<ComponentCheckbox>, checkbox: Rc<ComponentCheckbox>,
setting: SettingType, setting: SettingType,
@@ -86,8 +87,8 @@ fn init_setting_checkbox(
Ok(()) Ok(())
} }
impl TabSettings { impl<T> TabSettings<T> {
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: frontend.layout.state.globals.clone(), globals: frontend.layout.state.globals.clone(),
@@ -136,10 +137,14 @@ impl TabSettings {
None, None,
)?; )?;
Ok(Self { state, tasks }) Ok(Self {
state,
tasks,
marker: PhantomData,
})
} }
fn toggle_setting(&mut self, frontend: &mut Frontend, setting: SettingType, state: bool) { fn toggle_setting(&mut self, frontend: &mut Frontend<T>, setting: SettingType, state: bool) {
*setting.get_bool(frontend.settings.get_mut()) = state; *setting.get_bool(frontend.settings.get_mut()) = state;
} }
} }

View File

@@ -14,7 +14,6 @@ use wgui::{
taffy::Display, taffy::Display,
widget::label::WidgetLabel, widget::label::WidgetLabel,
}; };
use wlx_common::dash_interface::BoxDashInterface;
use crate::{ use crate::{
frontend::{FrontendTask, FrontendTasks}, frontend::{FrontendTask, FrontendTasks},
@@ -61,7 +60,6 @@ pub struct PopupContentFuncData<'a> {
pub layout: &'a mut Layout, pub layout: &'a mut Layout,
pub settings: &'a dyn SettingsIO, pub settings: &'a dyn SettingsIO,
pub handle: PopupHandle, pub handle: PopupHandle,
pub interface: &'a mut BoxDashInterface,
pub id_content: WidgetID, pub id_content: WidgetID,
} }
@@ -127,7 +125,6 @@ impl PopupManager {
globals: WguiGlobals, globals: WguiGlobals,
settings: &dyn SettingsIO, settings: &dyn SettingsIO,
layout: &mut Layout, layout: &mut Layout,
interface: &mut BoxDashInterface,
frontend_tasks: FrontendTasks, frontend_tasks: FrontendTasks,
params: MountPopupParams, params: MountPopupParams,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@@ -184,7 +181,6 @@ impl PopupManager {
handle: popup_handle.clone(), handle: popup_handle.clone(),
id_content, id_content,
settings, settings,
interface,
})?; })?;
Ok(()) Ok(())

View File

@@ -31,12 +31,13 @@ enum Task {
Launch, Launch,
} }
struct LaunchParams<'a> { struct LaunchParams<'a, T> {
application: &'a DesktopEntry, application: &'a DesktopEntry,
run_mode: RunMode, run_mode: RunMode,
globals: &'a WguiGlobals, globals: &'a WguiGlobals,
frontend_tasks: &'a FrontendTasks, frontend_tasks: &'a FrontendTasks,
interface: &'a mut BoxDashInterface, interface: &'a mut BoxDashInterface<T>,
data: &'a mut T,
on_launched: &'a dyn Fn(), on_launched: &'a dyn Fn(),
} }
@@ -157,7 +158,12 @@ impl View {
}) })
} }
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { pub fn update<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
loop { loop {
let tasks = self.tasks.drain(); let tasks = self.tasks.drain();
if tasks.is_empty() { if tasks.is_empty() {
@@ -166,7 +172,7 @@ impl View {
for task in tasks { for task in tasks {
match task { match task {
Task::SetRunMode(run_mode) => self.action_set_run_mode(layout, run_mode)?, Task::SetRunMode(run_mode) => self.action_set_run_mode(layout, run_mode)?,
Task::Launch => self.action_launch(interface), Task::Launch => self.action_launch(interface, data),
} }
} }
} }
@@ -188,18 +194,19 @@ impl View {
Ok(()) Ok(())
} }
fn action_launch(&mut self, interface: &mut BoxDashInterface) { fn action_launch<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
View::try_launch(LaunchParams { View::try_launch(LaunchParams {
application: &self.entry, application: &self.entry,
frontend_tasks: &self.frontend_tasks, frontend_tasks: &self.frontend_tasks,
globals: &self.globals, globals: &self.globals,
run_mode: self.run_mode.clone(), run_mode: self.run_mode.clone(),
interface, interface,
data,
on_launched: &self.on_launched, on_launched: &self.on_launched,
}); });
} }
fn try_launch(params: LaunchParams) { fn try_launch<T>(params: LaunchParams<T>) {
let globals = params.globals.clone(); let globals = params.globals.clone();
let frontend_tasks = params.frontend_tasks.clone(); let frontend_tasks = params.frontend_tasks.clone();
@@ -213,7 +220,7 @@ impl View {
)))); ))));
} }
fn launch(params: LaunchParams) -> anyhow::Result<()> { fn launch<T>(params: LaunchParams<T>) -> anyhow::Result<()> {
let mut env = Vec::<String>::new(); let mut env = Vec::<String>::new();
if params.run_mode == RunMode::Wayland { if params.run_mode == RunMode::Wayland {
@@ -238,13 +245,16 @@ impl View {
let mut userdata = HashMap::new(); let mut userdata = HashMap::new();
userdata.insert("desktop-entry".to_string(), serde_json::to_string(params.application)?); userdata.insert("desktop-entry".to_string(), serde_json::to_string(params.application)?);
params.interface.process_launch(WvrProcessLaunchParams { params.interface.process_launch(
env, params.data,
exec, WvrProcessLaunchParams {
name: params.application.app_name.to_string(), env,
args, exec,
userdata, name: params.application.app_name.to_string(),
})?; args,
userdata,
},
)?;
params params
.frontend_tasks .frontend_tasks

View File

@@ -71,7 +71,12 @@ impl View {
}) })
} }
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { pub fn update<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
loop { loop {
let tasks = self.tasks.drain(); let tasks = self.tasks.drain();
if tasks.is_empty() { if tasks.is_empty() {
@@ -79,8 +84,8 @@ impl View {
} }
for task in tasks { for task in tasks {
match task { match task {
Task::Refresh => self.refresh(layout, interface)?, Task::Refresh => self.refresh(layout, interface, data)?,
Task::TerminateProcess(process) => self.action_terminate_process(interface, process)?, Task::TerminateProcess(process) => self.action_terminate_process(interface, data, process)?,
} }
} }
} }
@@ -196,11 +201,16 @@ fn fill_process_list(
} }
impl View { impl View {
fn refresh(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { fn refresh<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
layout.remove_children(self.id_list_parent); layout.remove_children(self.id_list_parent);
let mut text: Option<Translation> = None; let mut text: Option<Translation> = None;
match interface.process_list() { match interface.process_list(data) {
Ok(list) => { Ok(list) => {
if list.is_empty() { if list.is_empty() {
text = Some(Translation::from_translation_key("PROCESS_LIST.NO_PROCESSES_FOUND")) text = Some(Translation::from_translation_key("PROCESS_LIST.NO_PROCESSES_FOUND"))
@@ -236,12 +246,13 @@ impl View {
Ok(()) Ok(())
} }
fn action_terminate_process( fn action_terminate_process<T>(
&mut self, &mut self,
interface: &mut BoxDashInterface, interface: &mut BoxDashInterface<T>,
data: &mut T,
process: packet_server::WvrProcess, process: packet_server::WvrProcess,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
interface.process_terminate(process.handle)?; interface.process_terminate(data, process.handle)?;
self.tasks.push(Task::Refresh); self.tasks.push(Task::Refresh);
Ok(()) Ok(())
} }

View File

@@ -12,8 +12,8 @@ use wgui::{
taffy::{self, prelude::length}, taffy::{self, prelude::length},
task::Tasks, task::Tasks,
widget::{ widget::{
ConstructEssentials,
label::{WidgetLabel, WidgetLabelParams}, label::{WidgetLabel, WidgetLabelParams},
ConstructEssentials,
}, },
}; };
use wlx_common::dash_interface::BoxDashInterface; use wlx_common::dash_interface::BoxDashInterface;
@@ -84,7 +84,12 @@ impl View {
}) })
} }
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { pub fn update<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
loop { loop {
let tasks = self.tasks.drain(); let tasks = self.tasks.drain();
if tasks.is_empty() { if tasks.is_empty() {
@@ -94,23 +99,24 @@ impl View {
match task { match task {
Task::WindowClicked(display) => self.action_window_clicked(display)?, Task::WindowClicked(display) => self.action_window_clicked(display)?,
Task::WindowOptionsFinish => self.action_window_options_finish(), Task::WindowOptionsFinish => self.action_window_options_finish(),
Task::Refresh => self.refresh(layout, interface)?, Task::Refresh => self.refresh(layout, interface, data)?,
} }
} }
} }
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
if let Some((_, view)) = &mut state.view_window_options { if let Some((_, view)) = &mut state.view_window_options {
view.update(layout, interface)?; view.update(layout, interface, data)?;
} }
Ok(()) Ok(())
} }
} }
pub fn construct_window_button( pub fn construct_window_button<T>(
ess: &mut ConstructEssentials, ess: &mut ConstructEssentials,
interface: &mut BoxDashInterface, interface: &mut BoxDashInterface<T>,
data: &mut T,
globals: &WguiGlobals, globals: &WguiGlobals,
window: &packet_server::WvrWindow, window: &packet_server::WvrWindow,
) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> { ) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> {
@@ -137,7 +143,7 @@ pub fn construct_window_button(
}, },
)?; )?;
let process_name = match interface.process_get(window.process_handle.clone()) { let process_name = match interface.process_get(data, window.process_handle.clone()) {
Some(process) => process.name.clone(), Some(process) => process.name.clone(),
None => String::from("Unknown"), None => String::from("Unknown"),
}; };
@@ -171,15 +177,16 @@ pub fn construct_window_button(
Ok((widget_button, button)) Ok((widget_button, button))
} }
fn fill_window_list( fn fill_window_list<T>(
globals: &WguiGlobals, globals: &WguiGlobals,
ess: &mut ConstructEssentials, ess: &mut ConstructEssentials,
interface: &mut BoxDashInterface, interface: &mut BoxDashInterface<T>,
data: &mut T,
list: Vec<packet_server::WvrWindow>, list: Vec<packet_server::WvrWindow>,
tasks: &Tasks<Task>, tasks: &Tasks<Task>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
for entry in list { for entry in list {
let (_, button) = construct_window_button(ess, interface, globals, &entry)?; let (_, button) = construct_window_button(ess, interface, data, globals, &entry)?;
button.on_click({ button.on_click({
let tasks = tasks.clone(); let tasks = tasks.clone();
@@ -199,11 +206,16 @@ impl View {
self.tasks.push(Task::Refresh); self.tasks.push(Task::Refresh);
} }
fn refresh(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { fn refresh<T>(
&mut self,
layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
layout.remove_children(self.id_list_parent); layout.remove_children(self.id_list_parent);
let mut text: Option<Translation> = None; let mut text: Option<Translation> = None;
match interface.window_list() { match interface.window_list(data) {
Ok(list) => { Ok(list) => {
if list.is_empty() { if list.is_empty() {
text = Some(Translation::from_translation_key("NO_WINDOWS_FOUND")) text = Some(Translation::from_translation_key("NO_WINDOWS_FOUND"))
@@ -215,6 +227,7 @@ impl View {
parent: self.id_list_parent, parent: self.id_list_parent,
}, },
interface, interface,
data,
list, list,
&self.tasks, &self.tasks,
)? )?
@@ -252,19 +265,20 @@ impl View {
let state = self.state.clone(); let state = self.state.clone();
let tasks = self.tasks.clone(); let tasks = self.tasks.clone();
//TODO
Rc::new(move |data| { Rc::new(move |data| {
state.borrow_mut().view_window_options = Some(( // state.borrow_mut().view_window_options = Some((
data.handle, // data.handle,
window_options::View::new(window_options::Params { // window_options::View::new(window_options::Params {
globals: globals.clone(), // globals: globals.clone(),
layout: data.layout, // layout: data.layout,
parent_id: data.id_content, // parent_id: data.id_content,
on_submit: tasks.make_callback(Task::WindowOptionsFinish), // on_submit: tasks.make_callback(Task::WindowOptionsFinish),
window: window.clone(), // window: window.clone(),
frontend_tasks: frontend_tasks.clone(), // frontend_tasks: frontend_tasks.clone(),
interface: data.interface, // })?,
})?, // ));
));
Ok(()) Ok(())
}) })
}, },

View File

@@ -34,18 +34,19 @@ pub struct View {
on_submit: Rc<dyn Fn()>, on_submit: Rc<dyn Fn()>,
} }
pub struct Params<'a> { pub struct Params<'a, T> {
pub globals: WguiGlobals, pub globals: WguiGlobals,
pub frontend_tasks: FrontendTasks, pub frontend_tasks: FrontendTasks,
pub layout: &'a mut Layout, pub layout: &'a mut Layout,
pub parent_id: WidgetID, pub parent_id: WidgetID,
pub on_submit: Rc<dyn Fn()>, pub on_submit: Rc<dyn Fn()>,
pub window: packet_server::WvrWindow, pub window: packet_server::WvrWindow,
pub interface: &'a mut BoxDashInterface, pub interface: &'a mut BoxDashInterface<T>,
pub data: &'a mut T,
} }
impl View { impl View {
pub fn new(params: Params) -> anyhow::Result<Self> { pub fn new<T>(params: Params<T>) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams { let doc_params = &ParseDocumentParams {
globals: params.globals.clone(), globals: params.globals.clone(),
path: AssetPath::BuiltIn("gui/view/window_options.xml"), path: AssetPath::BuiltIn("gui/view/window_options.xml"),
@@ -67,6 +68,7 @@ impl View {
parent: window_parent, parent: window_parent,
}, },
params.interface, params.interface,
params.data,
&params.globals, &params.globals,
&params.window, &params.window,
)?; )?;
@@ -93,12 +95,17 @@ impl View {
}) })
} }
pub fn update(&mut self, _layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> { pub fn update<T>(
&mut self,
_layout: &mut Layout,
interface: &mut BoxDashInterface<T>,
data: &mut T,
) -> anyhow::Result<()> {
for task in self.tasks.drain() { for task in self.tasks.drain() {
match task { match task {
Task::SetVisible(v) => self.action_set_visible(interface, v), Task::SetVisible(v) => self.action_set_visible(interface, data, v),
Task::Close => self.action_close(interface), Task::Close => self.action_close(interface, data),
Task::Kill => self.action_kill(interface), Task::Kill => self.action_kill(interface, data),
} }
} }
Ok(()) Ok(())
@@ -106,8 +113,8 @@ impl View {
} }
impl View { impl View {
fn action_set_visible(&mut self, interface: &mut BoxDashInterface, visible: bool) { fn action_set_visible<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T, visible: bool) {
if let Err(e) = interface.window_set_visible(self.window.handle.clone(), visible) { if let Err(e) = interface.window_set_visible(data, self.window.handle.clone(), visible) {
self self
.frontend_tasks .frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!( .push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
@@ -119,8 +126,8 @@ impl View {
(*self.on_submit)(); (*self.on_submit)();
} }
fn action_close(&mut self, interface: &mut BoxDashInterface) { fn action_close<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
if let Err(e) = interface.window_request_close(self.window.handle.clone()) { if let Err(e) = interface.window_request_close(data, self.window.handle.clone()) {
self self
.frontend_tasks .frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!( .push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
@@ -132,16 +139,16 @@ impl View {
(*self.on_submit)(); (*self.on_submit)();
} }
fn action_kill_process(&mut self, interface: &mut BoxDashInterface) -> anyhow::Result<()> { fn action_kill_process<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) -> anyhow::Result<()> {
let process = interface let process = interface
.process_get(self.window.process_handle.clone()) .process_get(data, self.window.process_handle.clone())
.context("Process not found")?; .context("Process not found")?;
interface.process_terminate(process.handle)?; interface.process_terminate(data, process.handle)?;
Ok(()) Ok(())
} }
fn action_kill(&mut self, interface: &mut BoxDashInterface) { fn action_kill<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
if let Err(e) = self.action_kill_process(interface) { if let Err(e) = self.action_kill_process(interface, data) {
self self
.frontend_tasks .frontend_tasks
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!( .push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(

View File

@@ -3,15 +3,15 @@ use wayvr_ipc::{
packet_server::{WvrProcess, WvrProcessHandle, WvrWindow, WvrWindowHandle}, packet_server::{WvrProcess, WvrProcessHandle, WvrWindow, WvrWindowHandle},
}; };
pub trait DashInterface { pub trait DashInterface<T> {
fn window_list(&mut self) -> anyhow::Result<Vec<WvrWindow>>; fn window_list(&mut self, data: &mut T) -> anyhow::Result<Vec<WvrWindow>>;
fn window_set_visible(&mut self, handle: WvrWindowHandle, visible: bool) -> anyhow::Result<()>; fn window_set_visible(&mut self, data: &mut T, handle: WvrWindowHandle, visible: bool) -> anyhow::Result<()>;
fn window_request_close(&mut self, handle: WvrWindowHandle) -> anyhow::Result<()>; fn window_request_close(&mut self, data: &mut T, handle: WvrWindowHandle) -> anyhow::Result<()>;
fn process_get(&mut self, handle: WvrProcessHandle) -> Option<WvrProcess>; fn process_get(&mut self, data: &mut T, handle: WvrProcessHandle) -> Option<WvrProcess>;
fn process_launch(&mut self, params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle>; fn process_launch(&mut self, data: &mut T, params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle>;
fn process_list(&mut self) -> anyhow::Result<Vec<WvrProcess>>; fn process_list(&mut self, data: &mut T) -> anyhow::Result<Vec<WvrProcess>>;
fn process_terminate(&mut self, handle: WvrProcessHandle) -> anyhow::Result<()>; fn process_terminate(&mut self, data: &mut T, handle: WvrProcessHandle) -> anyhow::Result<()>;
fn recenter_playspace(&mut self) -> anyhow::Result<()>; fn recenter_playspace(&mut self, data: &mut T) -> anyhow::Result<()>;
} }
pub type BoxDashInterface = Box<dyn DashInterface>; pub type BoxDashInterface<T> = Box<dyn DashInterface<T>>;

View File

@@ -79,12 +79,12 @@ impl Default for DashInterfaceEmulated {
} }
} }
impl DashInterface for DashInterfaceEmulated { impl DashInterface<()> for DashInterfaceEmulated {
fn window_list(&mut self) -> anyhow::Result<Vec<WvrWindow>> { fn window_list(&mut self, _: &mut ()) -> anyhow::Result<Vec<WvrWindow>> {
Ok(self.windows.iter().map(|(handle, w)| w.to(handle)).collect()) Ok(self.windows.iter().map(|(handle, w)| w.to(handle)).collect())
} }
fn window_request_close(&mut self, handle: WvrWindowHandle) -> anyhow::Result<()> { fn window_request_close(&mut self, _: &mut (), handle: WvrWindowHandle) -> anyhow::Result<()> {
self.windows.remove(&EmuWindowHandle { self.windows.remove(&EmuWindowHandle {
generation: handle.generation, generation: handle.generation,
idx: handle.idx, idx: handle.idx,
@@ -92,12 +92,12 @@ impl DashInterface for DashInterfaceEmulated {
Ok(()) Ok(())
} }
fn process_get(&mut self, handle: WvrProcessHandle) -> Option<WvrProcess> { fn process_get(&mut self, _: &mut (), handle: WvrProcessHandle) -> Option<WvrProcess> {
let emu_handle = EmuProcessHandle::new(handle.idx, handle.generation); let emu_handle = EmuProcessHandle::new(handle.idx, handle.generation);
self.processes.get(&emu_handle).map(|process| process.to(emu_handle)) self.processes.get(&emu_handle).map(|process| process.to(emu_handle))
} }
fn process_launch(&mut self, params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle> { fn process_launch(&mut self, _: &mut (), params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle> {
let res = self.processes.add(EmuProcess { name: params.name }); let res = self.processes.add(EmuProcess { name: params.name });
self.windows.add(EmuWindow { self.windows.add(EmuWindow {
@@ -111,7 +111,7 @@ impl DashInterface for DashInterfaceEmulated {
}) })
} }
fn process_list(&mut self) -> anyhow::Result<Vec<WvrProcess>> { fn process_list(&mut self, _: &mut ()) -> anyhow::Result<Vec<WvrProcess>> {
Ok( Ok(
self self
.processes .processes
@@ -121,7 +121,7 @@ impl DashInterface for DashInterfaceEmulated {
) )
} }
fn process_terminate(&mut self, handle: WvrProcessHandle) -> anyhow::Result<()> { fn process_terminate(&mut self, _: &mut (), handle: WvrProcessHandle) -> anyhow::Result<()> {
let mut to_remove = None; let mut to_remove = None;
for (wh, w) in self.windows.iter() { for (wh, w) in self.windows.iter() {
@@ -140,7 +140,7 @@ impl DashInterface for DashInterfaceEmulated {
Ok(()) Ok(())
} }
fn window_set_visible(&mut self, handle: WvrWindowHandle, visible: bool) -> anyhow::Result<()> { fn window_set_visible(&mut self, _: &mut (), handle: WvrWindowHandle, visible: bool) -> anyhow::Result<()> {
match self.windows.get_mut(&EmuWindowHandle { match self.windows.get_mut(&EmuWindowHandle {
generation: handle.generation, generation: handle.generation,
idx: handle.idx, idx: handle.idx,
@@ -153,7 +153,7 @@ impl DashInterface for DashInterfaceEmulated {
} }
} }
fn recenter_playspace(&mut self) -> anyhow::Result<()> { fn recenter_playspace(&mut self, _: &mut ()) -> anyhow::Result<()> {
// stub! // stub!
Ok(()) Ok(())
} }

View File

@@ -386,6 +386,10 @@ impl WvrServerState {
self.window_to_overlay.insert(window, oid); self.window_to_overlay.insert(window, oid);
} }
pub fn get_overlay_id(&self, window: window::WindowHandle) -> Option<OverlayID> {
self.window_to_overlay.get(&window).cloned()
}
pub fn send_mouse_move(&mut self, handle: window::WindowHandle, x: u32, y: u32) { pub fn send_mouse_move(&mut self, handle: window::WindowHandle, x: u32, y: u32) {
if self.mouse_freeze > Instant::now() { if self.mouse_freeze > Instant::now() {
return; return;

View File

@@ -3,6 +3,11 @@ use dash_frontend::{
settings::{self, SettingsIO}, settings::{self, SettingsIO},
}; };
use glam::{Affine2, Affine3A, Vec2, vec2, vec3}; use glam::{Affine2, Affine3A, Vec2, vec2, vec3};
use tracing::instrument::WithSubscriber;
use wayvr_ipc::{
packet_client::WvrProcessLaunchParams,
packet_server::{WvrProcess, WvrProcessHandle, WvrWindow, WvrWindowHandle},
};
use wgui::{ use wgui::{
event::{ event::{
Event as WguiEvent, MouseButtonIndex, MouseDownEvent, MouseLeaveEvent, MouseMotionEvent, Event as WguiEvent, MouseButtonIndex, MouseDownEvent, MouseLeaveEvent, MouseMotionEvent,
@@ -13,7 +18,7 @@ use wgui::{
widget::EventResult, widget::EventResult,
}; };
use wlx_common::{ use wlx_common::{
dash_interface_emulated::DashInterfaceEmulated, dash_interface::DashInterface,
overlays::{BackendAttrib, BackendAttribValue}, overlays::{BackendAttrib, BackendAttribValue},
}; };
use wlx_common::{ use wlx_common::{
@@ -22,11 +27,16 @@ use wlx_common::{
}; };
use crate::{ use crate::{
backend::input::{Haptics, HoverResult, PointerHit, PointerMode}, backend::{
input::{Haptics, HoverResult, PointerHit, PointerMode},
task::{OverlayTask, PlayspaceTask, TaskType},
wayvr::{process::ProcessHandle, window::WindowHandle},
},
ipc::ipc_server::{gen_args_vec, gen_env_vec},
state::AppState, state::AppState,
subsystem::hid::WheelDelta, subsystem::hid::WheelDelta,
windowing::{ windowing::{
Z_ORDER_DASHBOARD, OverlaySelector, Z_ORDER_DASHBOARD,
backend::{ backend::{
FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender, FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender,
ui_transform, ui_transform,
@@ -78,7 +88,7 @@ impl settings::SettingsIO for SimpleSettingsIO {
} }
pub struct DashFrontend { pub struct DashFrontend {
inner: frontend::Frontend, inner: frontend::Frontend<AppState>,
initialized: bool, initialized: bool,
interaction_transform: Option<Affine2>, interaction_transform: Option<Affine2>,
timestep: Timestep, timestep: Timestep,
@@ -91,7 +101,7 @@ const GUI_SCALE: f32 = 2.0;
impl DashFrontend { impl DashFrontend {
fn new(app: &mut AppState) -> anyhow::Result<Self> { fn new(app: &mut AppState) -> anyhow::Result<Self> {
let settings = SimpleSettingsIO::new(); let settings = SimpleSettingsIO::new();
let interface = DashInterfaceEmulated::new(); let interface = DashInterfaceLive::new();
let frontend = frontend::Frontend::new(frontend::InitParams { let frontend = frontend::Frontend::new(frontend::InitParams {
settings: Box::new(settings), settings: Box::new(settings),
@@ -108,8 +118,9 @@ impl DashFrontend {
}) })
} }
fn update(&mut self, timestep_alpha: f32) -> anyhow::Result<()> { fn update(&mut self, app: &mut AppState, timestep_alpha: f32) -> anyhow::Result<()> {
self.inner.update( self.inner.update(
app,
DASH_RES_VEC2.x / GUI_SCALE, DASH_RES_VEC2.x / GUI_SCALE,
DASH_RES_VEC2.y / GUI_SCALE, DASH_RES_VEC2.y / GUI_SCALE,
timestep_alpha, timestep_alpha,
@@ -134,7 +145,7 @@ impl OverlayBackend for DashFrontend {
self.interaction_transform = Some(ui_transform(DASH_RES_U32A)); self.interaction_transform = Some(ui_transform(DASH_RES_U32A));
if self.inner.layout.content_size.x * self.inner.layout.content_size.y != 0.0 { if self.inner.layout.content_size.x * self.inner.layout.content_size.y != 0.0 {
self.update(0.0)?; self.update(app, 0.0)?;
self.initialized = true; self.initialized = true;
} }
Ok(()) Ok(())
@@ -150,12 +161,12 @@ impl OverlayBackend for DashFrontend {
Ok(()) Ok(())
} }
fn should_render(&mut self, _app: &mut AppState) -> anyhow::Result<ShouldRender> { fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
while self.timestep.on_tick() { while self.timestep.on_tick() {
self.inner.layout.tick()?; self.inner.layout.tick()?;
} }
if let Err(e) = self.update(self.timestep.alpha) { if let Err(e) = self.update(app, self.timestep.alpha) {
log::error!("uncaught exception: {e:?}"); log::error!("uncaught exception: {e:?}");
} }
@@ -301,3 +312,113 @@ pub fn create_dash_frontend(app: &mut AppState) -> anyhow::Result<OverlayWindowC
..OverlayWindowConfig::from_backend(Box::new(DashFrontend::new(app)?)) ..OverlayWindowConfig::from_backend(Box::new(DashFrontend::new(app)?))
}) })
} }
pub struct DashInterfaceLive {}
impl DashInterfaceLive {
pub fn new() -> Self {
Self {}
}
}
impl DashInterface<AppState> for DashInterfaceLive {
fn window_list(&mut self, app: &mut AppState) -> anyhow::Result<Vec<WvrWindow>> {
let wvr_server = app.wvr_server.as_mut().unwrap();
Ok(wvr_server
.wm
.windows
.iter()
.map(|(handle, win)| WvrWindow {
handle: WindowHandle::as_packet(&handle),
process_handle: ProcessHandle::as_packet(&win.process),
size_x: win.size_x,
size_y: win.size_y,
visible: win.visible,
})
.collect())
}
fn window_request_close(
&mut self,
app: &mut AppState,
handle: WvrWindowHandle,
) -> anyhow::Result<()> {
let wvr_server = app.wvr_server.as_mut().unwrap();
wvr_server
.wm
.remove_window(WindowHandle::from_packet(handle));
Ok(())
}
fn process_get(&mut self, app: &mut AppState, handle: WvrProcessHandle) -> Option<WvrProcess> {
let wvr_server = app.wvr_server.as_mut().unwrap();
let handle = ProcessHandle::from_packet(handle);
wvr_server
.processes
.get(&handle)
.map(|x| x.to_packet(handle))
}
fn process_launch(
&mut self,
app: &mut AppState,
params: WvrProcessLaunchParams,
) -> anyhow::Result<WvrProcessHandle> {
let wvr_server = app.wvr_server.as_mut().unwrap();
let args_vec = gen_args_vec(&params.args);
let env_vec = gen_env_vec(&params.env);
wvr_server
.spawn_process(&params.exec, &args_vec, &env_vec, None, params.userdata)
.map(|x| x.as_packet())
}
fn process_list(&mut self, app: &mut AppState) -> anyhow::Result<Vec<WvrProcess>> {
let wvr_server = app.wvr_server.as_mut().unwrap();
Ok(wvr_server
.processes
.iter()
.map(|(hnd, p)| p.to_packet(hnd))
.collect())
}
fn process_terminate(
&mut self,
app: &mut AppState,
handle: WvrProcessHandle,
) -> anyhow::Result<()> {
let wvr_server = app.wvr_server.as_mut().unwrap();
wvr_server.terminate_process(ProcessHandle::from_packet(handle));
Ok(())
}
fn window_set_visible(
&mut self,
app: &mut AppState,
handle: WvrWindowHandle,
visible: bool,
) -> anyhow::Result<()> {
let wvr_server = app.wvr_server.as_mut().unwrap();
let Some(oid) = wvr_server.get_overlay_id(WindowHandle::from_packet(handle)) else {
return Ok(());
};
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Modify(
OverlaySelector::Id(oid),
Box::new(move |app, owc| {
if visible && !owc.is_active() {
owc.activate(app);
} else if !visible && owc.is_active() {
owc.deactivate();
}
}),
)));
Ok(())
}
fn recenter_playspace(&mut self, app: &mut AppState) -> anyhow::Result<()> {
app.tasks
.enqueue(TaskType::Playspace(PlayspaceTask::Recenter));
Ok(())
}
}