mirror of https://github.com/wayvr-org/wayvr.git
optionally use wayvr compositor clipboard when pasting
This commit is contained in:
parent
47a3c65ca0
commit
1c272fc655
|
|
@ -7,10 +7,12 @@ use smithay::{
|
|||
reexports::wayland_server,
|
||||
utils::SerialCounter,
|
||||
};
|
||||
use smithay::input::Seat;
|
||||
use smithay::wayland::selection::data_device::set_data_device_selection;
|
||||
use xkbcommon::xkb;
|
||||
|
||||
use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask};
|
||||
|
||||
use crate::backend::wayvr::comp::Application;
|
||||
use super::{
|
||||
ProcessWayVREnv,
|
||||
comp::{self, ClientState},
|
||||
|
|
@ -26,6 +28,7 @@ pub struct WayVRCompositor {
|
|||
pub state: comp::Application,
|
||||
pub seat_keyboard: KeyboardHandle<comp::Application>,
|
||||
pub seat_pointer: PointerHandle<comp::Application>,
|
||||
pub seat: Seat<comp::Application>,
|
||||
pub serial_counter: SerialCounter,
|
||||
pub wayland_env: super::WaylandEnv,
|
||||
|
||||
|
|
@ -68,6 +71,7 @@ impl WayVRCompositor {
|
|||
display: wayland_server::Display<comp::Application>,
|
||||
seat_keyboard: KeyboardHandle<comp::Application>,
|
||||
seat_pointer: PointerHandle<comp::Application>,
|
||||
seat: Seat<comp::Application>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let (wayland_env, listener) = create_wayland_listener()?;
|
||||
|
||||
|
|
@ -81,6 +85,7 @@ impl WayVRCompositor {
|
|||
serial_counter: SerialCounter::new(),
|
||||
clients: Vec::new(),
|
||||
toplevel_surf_count: 0,
|
||||
seat,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -200,6 +205,14 @@ impl WayVRCompositor {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn set_clipboard_text(&mut self, text: String) {
|
||||
set_data_device_selection::<Application>(
|
||||
&self.state.display_handle,
|
||||
&self.seat,
|
||||
vec!["text/plain;charset=utf-8".to_string(), "text/plain".to_string()],
|
||||
text.as_bytes().into(),
|
||||
);
|
||||
}
|
||||
pub fn set_keymap(&mut self, keymap: &xkb::Keymap) -> anyhow::Result<()> {
|
||||
// Smithay only accepts keymaps in a string form due to thread safety concerns
|
||||
self.seat_keyboard
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ impl WvrServerState {
|
|||
|
||||
Ok(Self {
|
||||
time_start,
|
||||
manager: client::WayVRCompositor::new(state, display, seat_keyboard, seat_pointer)?,
|
||||
manager: client::WayVRCompositor::new(state, display, seat_keyboard, seat_pointer, seat)?,
|
||||
processes: ProcessVec::new(),
|
||||
wm: window::WindowManager::new(),
|
||||
ticks: 0,
|
||||
|
|
@ -635,6 +635,9 @@ impl WvrServerState {
|
|||
pub fn send_key(&mut self, virtual_key: u32, down: bool) {
|
||||
self.manager.send_key(virtual_key, down);
|
||||
}
|
||||
pub fn set_clipboard_text(&mut self, text: String) {
|
||||
self.manager.set_clipboard_text(text);
|
||||
}
|
||||
|
||||
pub fn set_keymap(&mut self, keymap: &xkb::Keymap) -> anyhow::Result<()> {
|
||||
self.manager.set_keymap(keymap)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::state::AppState;
|
||||
use crate::subsystem::hid::{KeyModifier, VirtualKey, CTRL};
|
||||
use anyhow::{anyhow, bail};
|
||||
use anyhow::{bail};
|
||||
use arboard::Clipboard;
|
||||
use glam::Vec2;
|
||||
use std::mem;
|
||||
|
|
@ -9,7 +9,8 @@ use std::thread::{self, JoinHandle};
|
|||
use std::time::Instant;
|
||||
use super_swipe_type::keyboard_manager::QwertyKeyboardGrid;
|
||||
use super_swipe_type::swipe_orchestrator::SwipeOrchestrator;
|
||||
use super_swipe_type::{SwipeCandidate, SwipePoint};
|
||||
use super_swipe_type::{SwipePoint};
|
||||
use crate::subsystem::input::KeyboardFocus;
|
||||
|
||||
const PREDICTION_SUGGESTION_COUNT: usize = 5;
|
||||
|
||||
|
|
@ -37,18 +38,31 @@ pub struct SwipeTypingManager {
|
|||
|
||||
impl SwipeTypingManager {
|
||||
pub fn select_alternate_prediction(&mut self, word: &String, app: &mut AppState, original_keyboard_mods: KeyModifier) {
|
||||
Self::undo_paste(app, original_keyboard_mods);
|
||||
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) {
|
||||
self.last_swiped_word = Some(word.clone());
|
||||
if let Ok(_) = self.copy_text_to_clipboard(word.as_ref()) {
|
||||
Self::paste(app, original_keyboard_mods);
|
||||
let text_to_paste = format!("{word} ");
|
||||
|
||||
match app.hid_provider.keyboard_focus {
|
||||
KeyboardFocus::PhysicalScreen => {
|
||||
if let Ok(_) = self.clipboard.set_text(text_to_paste) {
|
||||
Self::paste(app, original_keyboard_mods);
|
||||
}
|
||||
},
|
||||
KeyboardFocus::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_paste(app: &mut AppState, original_keyboard_mods: KeyModifier) {
|
||||
fn undo(app: &mut AppState, original_keyboard_mods: KeyModifier) {
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), CTRL);
|
||||
app.hid_provider
|
||||
|
|
@ -69,11 +83,6 @@ impl SwipeTypingManager {
|
|||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), original_keyboard_mods);
|
||||
}
|
||||
|
||||
fn copy_text_to_clipboard(&mut self, text: &str) -> Result<(), arboard::Error> {
|
||||
self.clipboard.set_text(format!("{text} "))
|
||||
}
|
||||
|
||||
pub fn new() -> anyhow::Result<(SwipeTypingManager, Receiver<Option<Vec<String>>>)> {
|
||||
let (candidate_sender, candidate_receiver) = sync_channel(1);
|
||||
let (task_sender, task_receiver) = channel::<PredictionTask>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue