diff --git a/dash-frontend/src/tab/settings/mod.rs b/dash-frontend/src/tab/settings/mod.rs index 772a5795..aeeaad4e 100644 --- a/dash-frontend/src/tab/settings/mod.rs +++ b/dash-frontend/src/tab/settings/mod.rs @@ -270,13 +270,7 @@ impl Tab for TabSettings { if let Some(tab) = self.current_tab.as_mut() { let config = frontend.interface.general_config(data); let mut change_kind: Option = None; - tab.push_task_string( - &action, - config, - &mut change_kind, - &mut frontend.layout, - &mut self.state, - )?; + tab.push_task_string(&action, config, &mut change_kind, &mut frontend.layout, &mut self.state)?; if let Some(change_kind) = change_kind { frontend.interface.config_changed(data, change_kind); } diff --git a/dash-frontend/src/tab/settings/tab_features.rs b/dash-frontend/src/tab/settings/tab_features.rs index 03d0f3f6..e6848e5d 100644 --- a/dash-frontend/src/tab/settings/tab_features.rs +++ b/dash-frontend/src/tab/settings/tab_features.rs @@ -17,21 +17,17 @@ use wgui::{ }; use wlx_common::{async_executor::AsyncExecutor, config::GeneralConfig, dash_interface::ConfigChangeKind}; +use crate::util::downloadable_file::DownloadableFile; use crate::{ frontend::FrontendTasks, tab::settings::{ SettingType, SettingsMountParams, SettingsTab, TabNameEnum, Task as ParentTask, horiz_cell, + macros::{MacroParams, options_category, options_checkbox, options_range_f32}, mount_requires_restart, - macros::{ - MacroParams, options_category, options_checkbox, options_range_f32, - }, }, util::{ popup_manager::PopupHolder, - swipe_type::{ - SWIPE_TYPE_MODEL, swwipe_type_model_downloaded, - swipe_type_delete_all_models, swipe_type_model_path, - }, + swipe_type::{SWIPE_TYPE_MODEL, swipe_type_delete_all_models, swipe_type_model_path, swwipe_type_model_downloaded}, whisper::{ WHISPER_MODELS, whisper_any_models_downloaded, whisper_delete_all_models, whisper_model_from_name, whisper_model_path, @@ -39,7 +35,6 @@ use crate::{ }, views::{self, ViewUpdateParams}, }; -use crate::util::downloadable_file::DownloadableFile; #[derive(Clone)] enum Task { @@ -89,7 +84,13 @@ impl SettingsTab for State { } Task::WhisperDownload(model) => { self.pending_whisper_download = Some(model); - self.show_download_dialogue(model, par.executor.clone(), whisper_model_path(model.file_name), Task::WhisperDownloadClosed, Task::WhisperDownloadDone); + self.show_download_dialogue( + model, + par.executor.clone(), + whisper_model_path(model.file_name), + Task::WhisperDownloadClosed, + Task::WhisperDownloadDone, + ); } Task::WhisperDownloadDone => { if let Some(model) = self.pending_whisper_download.take() { @@ -114,7 +115,13 @@ impl SettingsTab for State { } Task::SwipeTypeDownloadAll => { self.pending_swipe_download = Some(&SWIPE_TYPE_MODEL); - self.show_download_dialogue(&SWIPE_TYPE_MODEL, par.executor.clone(), swipe_type_model_path(SWIPE_TYPE_MODEL.file_name), Task::SwipeTypeDownloadClosed, Task::SwipeTypeDownloadDone); + self.show_download_dialogue( + &SWIPE_TYPE_MODEL, + par.executor.clone(), + swipe_type_model_path(SWIPE_TYPE_MODEL.file_name), + Task::SwipeTypeDownloadClosed, + Task::SwipeTypeDownloadDone, + ); } Task::SwipeTypeDownloadDone => { if let Some(_) = self.pending_swipe_download.take() { @@ -247,7 +254,14 @@ impl State { }) } - fn show_download_dialogue(&mut self, file: &DownloadableFile, executor: AsyncExecutor, target_path: PathBuf, on_closed: Task, on_downloaded: Task) { + fn show_download_dialogue( + &mut self, + file: &DownloadableFile, + executor: AsyncExecutor, + target_path: PathBuf, + on_closed: Task, + on_downloaded: Task, + ) { views::download_file::mount_popup( self.popup_download.clone(), self.frontend_tasks.clone(), @@ -556,4 +570,4 @@ fn swipe_type_enabled_checkbox(mp: &mut MacroParams, parent: WidgetID) -> anyhow })); Ok(()) -} \ No newline at end of file +} diff --git a/dash-frontend/src/util/downloadable_file.rs b/dash-frontend/src/util/downloadable_file.rs index a23a4dd9..818cb59b 100644 --- a/dash-frontend/src/util/downloadable_file.rs +++ b/dash-frontend/src/util/downloadable_file.rs @@ -1,5 +1,5 @@ pub struct DownloadableFile { - pub file_name: &'static str, - pub display_name: &'static str, - pub url: &'static str, -} \ No newline at end of file + pub file_name: &'static str, + pub display_name: &'static str, + pub url: &'static str, +} diff --git a/dash-frontend/src/util/mod.rs b/dash-frontend/src/util/mod.rs index a3e6f408..06f7e3af 100644 --- a/dash-frontend/src/util/mod.rs +++ b/dash-frontend/src/util/mod.rs @@ -1,11 +1,11 @@ pub mod cached_fetcher; +pub mod downloadable_file; pub mod networking; pub mod openxr_bindings; pub mod pactl_wrapper; pub mod popup_manager; pub mod steam_utils; +pub mod swipe_type; pub mod toast_manager; pub mod wgui_simple; pub mod whisper; -pub mod swipe_type; -pub mod downloadable_file; diff --git a/dash-frontend/src/util/swipe_type.rs b/dash-frontend/src/util/swipe_type.rs index faef0db7..70928e8e 100644 --- a/dash-frontend/src/util/swipe_type.rs +++ b/dash-frontend/src/util/swipe_type.rs @@ -1,7 +1,7 @@ use std::{fs, io, path::PathBuf}; -use wlx_common::data_dir; use crate::util::downloadable_file::DownloadableFile; +use wlx_common::data_dir; pub const SWIPE_TYPE_MODEL: DownloadableFile = DownloadableFile { file_name: "en.tar", @@ -44,4 +44,4 @@ pub fn swipe_type_delete_all_models() -> io::Result<()> { } Ok(()) -} \ No newline at end of file +} diff --git a/dash-frontend/src/util/whisper.rs b/dash-frontend/src/util/whisper.rs index ef29fce9..8464ac9e 100644 --- a/dash-frontend/src/util/whisper.rs +++ b/dash-frontend/src/util/whisper.rs @@ -1,7 +1,7 @@ use std::{fs, io, path::PathBuf}; -use wlx_common::data_dir; use crate::util::downloadable_file::DownloadableFile; +use wlx_common::data_dir; pub const WHISPER_MODELS: &[DownloadableFile] = &[ DownloadableFile { diff --git a/wayvr/src/backend/wayvr/client.rs b/wayvr/src/backend/wayvr/client.rs index 5bf70a97..ddde3502 100644 --- a/wayvr/src/backend/wayvr/client.rs +++ b/wayvr/src/backend/wayvr/client.rs @@ -9,6 +9,7 @@ use std::{ use anyhow::Context; use glam::{DVec2, Vec2}; use slotmap::DenseSlotMap; +use smithay::wayland::selection::data_device::set_data_device_selection; use smithay::{ backend::input::{Axis, AxisSource, ButtonState, Keycode}, input::{ @@ -18,17 +19,16 @@ use smithay::{ reexports::wayland_server::{self, protocol::wl_surface::WlSurface}, utils::{Logical, Point, SerialCounter}, }; -use smithay::wayland::selection::data_device::set_data_device_selection; use wgui::log::LogErr; use xkbcommon::xkb; -use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask}; -use crate::backend::wayvr::comp::Application; use super::{ ProcessWayVREnv, comp::{self, ClientState}, process, }; +use crate::backend::wayvr::comp::Application; +use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask}; pub struct WayVRClient { pub client: wayland_server::Client, @@ -264,7 +264,10 @@ impl WayVRCompositor { set_data_device_selection::( &self.state.display_handle, &self.state.seat, - vec!["text/plain;charset=utf-8".to_string(), "text/plain".to_string()], + vec![ + "text/plain;charset=utf-8".to_string(), + "text/plain".to_string(), + ], text.as_bytes().into(), ); } diff --git a/wayvr/src/overlays/keyboard/builder.rs b/wayvr/src/overlays/keyboard/builder.rs index 29b968b1..715c64ab 100644 --- a/wayvr/src/overlays/keyboard/builder.rs +++ b/wayvr/src/overlays/keyboard/builder.rs @@ -1,5 +1,11 @@ use std::{rc::Rc, time::Duration}; +#[cfg(feature = "swipe-to-type")] +use super::init_swipe_type_manager; +use super::{ + KeyButtonData, KeyState, KeyboardState, handle_mouse_motion, handle_press, handle_release, + layout::{self, KeyCapType}, +}; use crate::{ app_misc, gui::{ @@ -32,9 +38,6 @@ use wgui::{ }; #[cfg(feature = "swipe-to-type")] use wlx_common::data_dir; -use super::{KeyButtonData, KeyState, KeyboardState, handle_press, handle_release, layout::{self, KeyCapType}, handle_mouse_motion}; -#[cfg(feature = "swipe-to-type")] -use super::init_swipe_type_manager; const PIXELS_PER_UNIT: f32 = 60.; @@ -236,9 +239,20 @@ pub(super) fn create_keyboard_panel( let CallbackMetadata::MouseButton(button) = data.metadata else { panic!("CallbackMetadata should contain MouseButton!"); }; - let within_key_pos = data.metadata.get_mouse_pos_normalized(&common.alterables.transform_stack); + let within_key_pos = data + .metadata + .get_mouse_pos_normalized(&common.alterables.transform_stack); - handle_press(app, &k, &k_label, &k_cap_type, &within_key_pos, state, button, button.device); + handle_press( + app, + &k, + &k_label, + &k_cap_type, + &within_key_pos, + state, + button, + button.device, + ); on_press_anim(k.clone(), common, data); Ok(EventResult::Pass) } @@ -252,12 +266,21 @@ pub(super) fn create_keyboard_panel( let k_label = key_label.clone(); let k_cap_type = key_cap_type.clone(); move |common, data, _app, state| { - let within_key_pos = data.metadata.get_mouse_pos_normalized(&common.alterables.transform_stack); + let within_key_pos = data + .metadata + .get_mouse_pos_normalized(&common.alterables.transform_stack); let CallbackMetadata::MousePosition(position) = data.metadata else { panic!("CallbackMetadata should contain MousePosition!"); }; - handle_mouse_motion(&k, &k_label, &k_cap_type, state, &within_key_pos, position.device); + handle_mouse_motion( + &k, + &k_label, + &k_cap_type, + state, + &within_key_pos, + position.device, + ); Ok(EventResult::Pass) } }), @@ -348,9 +371,14 @@ pub(super) fn create_keyboard_panel( super::prediction_bar::set_visible(panel, false); } - if app.session.config.keyboard_swipe_to_type_enabled && panel.state.swipe_typing_manager.is_none() { + if app.session.config.keyboard_swipe_to_type_enabled + && panel.state.swipe_typing_manager.is_none() + { #[cfg(feature = "swipe-to-type")] - init_swipe_type_manager(&mut panel.state, data_dir::get_path("swipe_type").join("en.tar")); + init_swipe_type_manager( + &mut panel.state, + data_dir::get_path("swipe_type").join("en.tar"), + ); super::prediction_bar::set_visible(panel, true); } diff --git a/wayvr/src/overlays/keyboard/mod.rs b/wayvr/src/overlays/keyboard/mod.rs index b791065d..3de46499 100644 --- a/wayvr/src/overlays/keyboard/mod.rs +++ b/wayvr/src/overlays/keyboard/mod.rs @@ -5,6 +5,8 @@ use std::{ sync::{Arc, atomic::Ordering}, }; +use crate::overlays::keyboard::layout::KeyCapType; +use crate::overlays::keyboard::swipe_type::{PredictionSlot, SwipeTypingManager}; use crate::overlays::toast::Toast; use crate::{ KEYMAP_CHANGE, @@ -29,26 +31,24 @@ use crate::{ }, }; use anyhow::Context; -use glam::{Affine3A, Quat, Vec3, vec3, Vec2}; +use glam::{Affine3A, Quat, Vec2, Vec3, vec3}; use regex::Regex; use slotmap::{SlotMap, new_key_type}; use smallvec::SmallVec; +use wgui::event::DeviceBitmask; use wgui::{ color::WguiColor, event::{InternalStateChangeEvent, MouseButtonEvent, MouseButtonIndex}, i18n::Translation, layout::WidgetID, }; -use wgui::event::DeviceBitmask; +#[cfg(feature = "swipe-to-type")] +use wlx_common::data_dir; use wlx_common::windowing::{OverlayWindowState, Positioning}; use wlx_common::{ config::AltModifier, overlays::{BackendAttrib, BackendAttribValue, ToastTopic}, }; -#[cfg(feature = "swipe-to-type")] -use wlx_common::data_dir; -use crate::overlays::keyboard::layout::KeyCapType; -use crate::overlays::keyboard::swipe_type::{PredictionSlot, SwipeTypingManager}; pub mod builder; mod layout; @@ -59,8 +59,8 @@ mod swipe_type; #[cfg(not(feature = "swipe-to-type"))] mod swipe_type { - use wgui::event::{DeviceBitmask, MouseButtonIndex}; use glam::Vec2; + use wgui::event::{DeviceBitmask, MouseButtonIndex}; pub struct SwipeTypingManager; @@ -83,17 +83,66 @@ mod swipe_type { pub fn new(_model_folder: std::path::PathBuf) -> anyhow::Result<(Self, PredictionSlot)> { Ok((Self, PredictionSlot)) } - pub fn add_swipe(&mut self, _within_key_pos_normalized: &Vec2, _key_label: char, _device: DeviceBitmask, _index: Option) {} - pub fn predict(&mut self) -> anyhow::Result<()> { Ok(()) } + pub fn add_swipe( + &mut self, + _within_key_pos_normalized: &Vec2, + _key_label: char, + _device: DeviceBitmask, + _index: Option, + ) { + } + pub fn predict(&mut self) -> anyhow::Result<()> { + Ok(()) + } pub fn reset(&mut self) {} - pub fn did_swipe_leave_first_key(&self) -> bool { false } - pub fn is_current_swipe_empty(&self) -> bool { true } - pub fn current_swipe_mouse_button_index(&self) -> Option { None } - pub fn handle_key_press(&mut self, _key_cap_type: &super::layout::KeyCapType, _within_key_pos: &Option, _key_label: &[String], _device: DeviceBitmask, _index: MouseButtonIndex) -> super::KeyPressOutcome { super::KeyPressOutcome::Dispatch } - pub fn handle_key_motion(&mut self, _key_cap_type: &super::layout::KeyCapType, _within_key_pos: &Option, _key_label: &[String], _device: DeviceBitmask) {} - pub fn handle_key_release(&mut self, _key_cap_type: &super::layout::KeyCapType, _alt_modifier: crate::subsystem::hid::KeyModifier) -> super::KeyReleaseOutcome { super::KeyReleaseOutcome::Normal } - pub fn select_word(&mut self, _word: &String, _app: &mut crate::state::AppState, _original_keyboard_mods: crate::subsystem::hid::KeyModifier) {} - pub fn select_alternate_prediction(&mut self, _word: &String, _app: &mut crate::state::AppState, _original_keyboard_mods: crate::subsystem::hid::KeyModifier) {} + pub fn did_swipe_leave_first_key(&self) -> bool { + false + } + pub fn is_current_swipe_empty(&self) -> bool { + true + } + pub fn current_swipe_mouse_button_index(&self) -> Option { + None + } + pub fn handle_key_press( + &mut self, + _key_cap_type: &super::layout::KeyCapType, + _within_key_pos: &Option, + _key_label: &[String], + _device: DeviceBitmask, + _index: MouseButtonIndex, + ) -> super::KeyPressOutcome { + super::KeyPressOutcome::Dispatch + } + pub fn handle_key_motion( + &mut self, + _key_cap_type: &super::layout::KeyCapType, + _within_key_pos: &Option, + _key_label: &[String], + _device: DeviceBitmask, + ) { + } + pub fn handle_key_release( + &mut self, + _key_cap_type: &super::layout::KeyCapType, + _alt_modifier: crate::subsystem::hid::KeyModifier, + ) -> super::KeyReleaseOutcome { + super::KeyReleaseOutcome::Normal + } + pub fn select_word( + &mut self, + _word: &String, + _app: &mut crate::state::AppState, + _original_keyboard_mods: crate::subsystem::hid::KeyModifier, + ) { + } + pub fn select_alternate_prediction( + &mut self, + _word: &String, + _app: &mut crate::state::AppState, + _original_keyboard_mods: crate::subsystem::hid::KeyModifier, + ) { + } } } @@ -191,7 +240,7 @@ pub(self) fn init_swipe_type_manager(state: &mut KeyboardState, model_path: std: Ok((engine, slot)) => { state.swipe_typing_manager = Some(engine); state.swipe_candidate_slot = Some(slot); - }, + } Err(e) => { log::error!("Error occurred while trying to load swipe engine: {}", e); } @@ -237,8 +286,7 @@ impl KeyboardBackend { log::info!("swipe engine created"); } - let mut panel = - create_keyboard_panel(app, keymap, state, &self.wlx_layout)?; + let mut panel = create_keyboard_panel(app, keymap, state, &self.wlx_layout)?; if !app.session.config.keyboard_swipe_to_type_enabled { prediction_bar::set_visible(&mut panel, false); @@ -289,7 +337,10 @@ impl KeyboardBackend { if app.session.config.keyboard_swipe_to_type_enabled { #[cfg(feature = "swipe-to-type")] - init_swipe_type_manager(&mut state_from, data_dir::get_path("swipe_type").join("en.tar")); + init_swipe_type_manager( + &mut state_from, + data_dir::get_path("swipe_type").join("en.tar"), + ); } self.active_layout = new_key; @@ -301,9 +352,7 @@ impl KeyboardBackend { if !app.session.config.keyboard_swipe_to_type_enabled { prediction_bar::set_visible( - self.layout_panels - .get_mut(self.active_layout) - .unwrap(), + self.layout_panels.get_mut(self.active_layout).unwrap(), false, ); } @@ -516,7 +565,7 @@ struct KeyboardState { keymap_switch_index: usize, keymap_switch_pending: bool, swipe_typing_manager: Option, - swipe_candidate_slot: Option + swipe_candidate_slot: Option, } macro_rules! take_and_leave_default { @@ -597,7 +646,7 @@ fn handle_mouse_motion( key_cap_type: &KeyCapType, keyboard: &mut KeyboardState, within_key_pos: &Option, - device: DeviceBitmask + device: DeviceBitmask, ) { if let KeyButtonData::Key { .. } = &key.button_state && let Some(swipe_manager) = keyboard.swipe_typing_manager.as_mut() @@ -613,14 +662,18 @@ fn handle_press( within_key_pos: &Option, keyboard: &mut KeyboardState, button: MouseButtonEvent, - device: DeviceBitmask + device: DeviceBitmask, ) { match &key.button_state { KeyButtonData::Key { vk, pressed } => { let outcome = match keyboard.swipe_typing_manager.as_mut() { - Some(swipe_manager) => { - swipe_manager.handle_key_press(key_cap_type, within_key_pos, key_label, device, button.index) - } + Some(swipe_manager) => swipe_manager.handle_key_press( + key_cap_type, + within_key_pos, + key_label, + device, + button.index, + ), None => KeyPressOutcome::Dispatch, }; @@ -683,7 +736,12 @@ fn handle_press( } } -fn handle_release(app: &mut AppState, key: &KeyState, k_cap_type: &KeyCapType, keyboard: &mut KeyboardState) -> bool { +fn handle_release( + app: &mut AppState, + key: &KeyState, + k_cap_type: &KeyCapType, + keyboard: &mut KeyboardState, +) -> bool { match &key.button_state { KeyButtonData::Key { vk, pressed } => { let outcome = match keyboard.swipe_typing_manager.as_mut() { diff --git a/wayvr/src/overlays/keyboard/prediction_bar.rs b/wayvr/src/overlays/keyboard/prediction_bar.rs index 4f853ed6..0cf024e8 100644 --- a/wayvr/src/overlays/keyboard/prediction_bar.rs +++ b/wayvr/src/overlays/keyboard/prediction_bar.rs @@ -1,17 +1,13 @@ use std::{collections::HashMap, rc::Rc}; -use crate::{ - gui::panel::GuiPanel, - state::AppState, -}; -use anyhow::bail; -use slotmap::Key; use super::{ KeyButtonData, KeyState, KeyboardState, - builder::{ - new_doc_params, on_enter_anim, on_leave_anim, on_press_anim, on_release_anim, - }, + builder::{new_doc_params, on_enter_anim, on_leave_anim, on_press_anim, on_release_anim}, }; +use crate::{gui::panel::GuiPanel, state::AppState}; +use anyhow::bail; +use slotmap::Key; +use wgui::event::StyleSetRequest; use wgui::{ event::EventListenerKind, layout::LayoutTask, @@ -19,7 +15,6 @@ use wgui::{ taffy::Display, widget::{EventResult, rectangle::WidgetRectangle}, }; -use wgui::event::StyleSetRequest; /// Root widget that hosts the swipe-to-type prediction candidates. pub(super) const ROOT: &str = "swipe_predictions_root"; @@ -36,10 +31,7 @@ pub(super) fn update( if let Some(slot) = panel.state.swipe_candidate_slot.as_mut() && let Some(candidates) = slot.take() { - let predictions_root = panel - .parser_state - .get_widget_id(ROOT) - .unwrap_or_default(); + let predictions_root = panel.parser_state.get_widget_id(ROOT).unwrap_or_default(); if predictions_root.is_null() { return Ok(elements_changed); @@ -155,10 +147,7 @@ pub(super) fn update( /// Show or hide the prediction candidate bar. pub(super) fn set_visible(panel: &mut GuiPanel, visible: bool) { - let predictions_root = panel - .parser_state - .get_widget_id(ROOT) - .unwrap_or_default(); + let predictions_root = panel.parser_state.get_widget_id(ROOT).unwrap_or_default(); if predictions_root.is_null() { return; } @@ -169,6 +158,10 @@ pub(super) fn set_visible(panel: &mut GuiPanel, visible: bool) { panel.layout.tasks.push(LayoutTask::SetWidgetStyle( predictions_root, - StyleSetRequest::Display(if visible { Display::Flex } else { Display::None }), + StyleSetRequest::Display(if visible { + Display::Flex + } else { + Display::None + }), )); -} \ No newline at end of file +} diff --git a/wayvr/src/overlays/keyboard/swipe_type.rs b/wayvr/src/overlays/keyboard/swipe_type.rs index b4190f30..dc986f85 100644 --- a/wayvr/src/overlays/keyboard/swipe_type.rs +++ b/wayvr/src/overlays/keyboard/swipe_type.rs @@ -1,23 +1,23 @@ +use super::layout::KeyCapType; use crate::state::AppState; -use crate::subsystem::hid::{KeyModifier, VirtualKey, CTRL, SHIFT}; -use anyhow::{bail}; +use crate::subsystem::clipboard; +use crate::subsystem::clipboard::ClipboardProvider; +use crate::subsystem::hid::{CTRL, KeyModifier, SHIFT, VirtualKey}; +use crate::subsystem::input::InputFocus; +use anyhow::bail; use glam::Vec2; use std::mem; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::mpsc::{Sender, channel}; use std::sync::{Arc, Mutex}; -use std::sync::mpsc::{channel, Sender}; use std::thread::{self, JoinHandle}; use std::time::Instant; +use super_swipe_type::SwipePoint; use super_swipe_type::keyboard_manager::QwertyKeyboardGrid; use super_swipe_type::swipe_orchestrator::SwipeOrchestrator; -use super_swipe_type::{SwipePoint}; use wgui::event::{DeviceBitmask, MouseButtonIndex}; use wgui::log::LogErr; -use crate::subsystem::clipboard; -use crate::subsystem::clipboard::ClipboardProvider; -use crate::subsystem::input::InputFocus; -use super::layout::KeyCapType; const PREDICTION_SUGGESTION_COUNT: usize = 5; @@ -83,30 +83,39 @@ pub struct SwipeTypingManager { } impl SwipeTypingManager { - pub fn select_alternate_prediction(&mut self, word: &String, app: &mut AppState, original_keyboard_mods: KeyModifier) { + pub fn select_alternate_prediction( + &mut self, + word: &String, + app: &mut AppState, + original_keyboard_mods: KeyModifier, + ) { Self::undo(app, original_keyboard_mods); self.select_word(word, app, original_keyboard_mods); } - pub fn select_word(&mut self, word: &String, app: &mut AppState, original_keyboard_mods: KeyModifier) { + pub fn select_word( + &mut self, + word: &String, + app: &mut AppState, + original_keyboard_mods: KeyModifier, + ) { self.last_swiped_word = Some(word.clone()); let text_to_paste = format!("{word} "); match app.hid_provider.get_input_focus() { - InputFocus::PhysicalScreen => { + InputFocus::PhysicalScreen => { if let Some(clipboard) = self.clipboard.as_mut() { clipboard.set_clipboard_utf8(&text_to_paste); Self::paste(app, original_keyboard_mods); } - }, + } InputFocus::WayVR => { if let Some(wvr_server) = app.wvr_server.as_mut() { wvr_server.set_clipboard_text(text_to_paste); Self::paste(app, original_keyboard_mods); } - }, + } } - } fn undo(app: &mut AppState, original_keyboard_mods: KeyModifier) { @@ -214,11 +223,10 @@ impl SwipeTypingManager { let last_word = self.last_swiped_word.clone(); self.reset_swipe(); - self.prediction_task_sender - .send(PredictionTask::Predict { - swipe: current_swipe, - last_word, - })?; + self.prediction_task_sender.send(PredictionTask::Predict { + swipe: current_swipe, + last_word, + })?; Ok(()) } @@ -238,7 +246,12 @@ impl SwipeTypingManager { self.current_swipe_mouse_button_index = None; } - fn start_swipe(&mut self, key_label: char, device: DeviceBitmask, index: Option) -> Instant { + fn start_swipe( + &mut self, + key_label: char, + device: DeviceBitmask, + index: Option, + ) -> Instant { let now = Instant::now(); self.swipe_start_time = Some(now); self.first_swipe_char = key_label.to_ascii_lowercase(); @@ -254,7 +267,7 @@ impl SwipeTypingManager { pub const fn is_current_swipe_empty(&self) -> bool { self.current_swipe.is_empty() } - + pub const fn current_swipe_mouse_button_index(&self) -> Option { self.current_swipe_mouse_button_index } @@ -276,7 +289,12 @@ impl SwipeTypingManager { if let Some(pos) = within_key_pos && let Some(label) = key_label.first() { - self.add_swipe(pos, label.chars().next().unwrap_or_default(), device, Some(index)); + self.add_swipe( + pos, + label.chars().next().unwrap_or_default(), + device, + Some(index), + ); } super::KeyPressOutcome::Consumed @@ -332,13 +350,24 @@ impl SwipeTypingManager { super::KeyReleaseOutcome::TapKey { modifier } } - pub fn add_swipe(&mut self, within_key_pos_normalized: &Vec2, key_label: char, device: DeviceBitmask, index: Option) { - if let Some(pos) = self.keyboard_gird.key_positions.get(&key_label.to_ascii_lowercase()) { - if let Some(current_device) = self.current_swipe_device && current_device != device { + pub fn add_swipe( + &mut self, + within_key_pos_normalized: &Vec2, + key_label: char, + device: DeviceBitmask, + index: Option, + ) { + if let Some(pos) = self + .keyboard_gird + .key_positions + .get(&key_label.to_ascii_lowercase()) + { + if let Some(current_device) = self.current_swipe_device + && current_device != device + { return; } - if self.first_swipe_char != char::default() && self.first_swipe_char != key_label.to_ascii_lowercase() { diff --git a/wayvr/src/state.rs b/wayvr/src/state.rs index cf9d8373..f2ac99ba 100644 --- a/wayvr/src/state.rs +++ b/wayvr/src/state.rs @@ -192,7 +192,8 @@ impl AppState { { feats.whisper = true; } - #[cfg(feature = "swipe-to-type")] { + #[cfg(feature = "swipe-to-type")] + { feats.swipe_to_type = true; } diff --git a/wayvr/src/subsystem/clipboard/mod.rs b/wayvr/src/subsystem/clipboard/mod.rs index 05d31ed1..a19b9e22 100644 --- a/wayvr/src/subsystem/clipboard/mod.rs +++ b/wayvr/src/subsystem/clipboard/mod.rs @@ -6,4 +6,3 @@ pub mod x11; pub trait ClipboardProvider { fn set_clipboard_utf8(&mut self, content: &str); } - diff --git a/wgui/src/components/checkbox.rs b/wgui/src/components/checkbox.rs index 20ee4fed..465d12d0 100644 --- a/wgui/src/components/checkbox.rs +++ b/wgui/src/components/checkbox.rs @@ -214,12 +214,19 @@ impl ComponentCheckbox { set_box_checked(&common.state.widgets, &self.data, checked, hovered, disabled); - common.state.widgets.call(self.data.id_outer_box, |rect: &mut WidgetRectangle| { - rect.params.border_color = box_border_color(hovered, down, disabled); - }); + common + .state + .widgets + .call(self.data.id_outer_box, |rect: &mut WidgetRectangle| { + rect.params.border_color = box_border_color(hovered, down, disabled); + }); if let Some(mut label) = common.state.widgets.get_as::(self.data.id_label) { - let color = if disabled { disabled_color() } else { WguiColorName::OnBackground.into() }; + let color = if disabled { + disabled_color() + } else { + WguiColorName::OnBackground.into() + }; label.set_color(common, color, true); } @@ -296,9 +303,7 @@ fn register_event_mouse_enter( if !disabled { common.alterables.trigger_haptics(); - common - .alterables - .animate(anim_hover_in(&state, &data, anim_mult)); + common.alterables.animate(anim_hover_in(&state, &data, anim_mult)); if checked { common @@ -338,9 +343,7 @@ fn register_event_mouse_leave( if !disabled { common.alterables.trigger_haptics(); - common - .alterables - .animate(anim_hover_out(&state, &data, anim_mult)); + common.alterables.animate(anim_hover_out(&state, &data, anim_mult)); if checked { common @@ -442,7 +445,13 @@ fn register_event_mouse_release( }); } - set_box_checked(&common.state.widgets, &data, state.checked, state.hovered, state.disabled); + set_box_checked( + &common.state.widgets, + &data, + state.checked, + state.hovered, + state.disabled, + ); if state.hovered && let Some(on_toggle) = &state.on_toggle { diff --git a/wgui/src/event.rs b/wgui/src/event.rs index 6dd5daa2..3add97aa 100644 --- a/wgui/src/event.rs +++ b/wgui/src/event.rs @@ -255,7 +255,7 @@ impl CallbackMetadata { } pub fn get_mouse_pos_normalized(&self, transform_stack: &TransformStack) -> Option { let pos_relative = self.get_mouse_pos_relative(transform_stack)?; - Some(pos_relative/transform_stack.parent().raw_dim) + Some(pos_relative / transform_stack.parent().raw_dim) } }