get rid of wayvr refcell
This commit is contained in:
@@ -74,6 +74,7 @@ impl compositor::CompositorHandler for Application {
|
||||
&client.get_data::<ClientState>().unwrap().compositor_state
|
||||
}
|
||||
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn commit(&mut self, surface: &WlSurface) {
|
||||
smithay::wayland::compositor::with_states(surface, |states| {
|
||||
let mut guard = states.cached_state.get::<SurfaceAttributes>();
|
||||
@@ -88,7 +89,7 @@ impl compositor::CompositorHandler for Application {
|
||||
.image_importer
|
||||
.get_or_import_dmabuf(dmabuf.clone())
|
||||
.inspect_err(|e| {
|
||||
log::warn!("wayland_server failed to import DMA-buf: {e:?}")
|
||||
log::warn!("wayland_server failed to import DMA-buf: {e:?}");
|
||||
})
|
||||
{
|
||||
let sbwi = SurfaceBufWithImage {
|
||||
@@ -108,7 +109,7 @@ impl compositor::CompositorHandler for Application {
|
||||
.image_importer
|
||||
.import_shm(data, size, buf)
|
||||
.inspect_err(|e| {
|
||||
log::warn!("wayland_server failed to import SHM: {e:?}")
|
||||
log::warn!("wayland_server failed to import SHM: {e:?}");
|
||||
})
|
||||
{
|
||||
let sbwi = SurfaceBufWithImage {
|
||||
@@ -127,7 +128,7 @@ impl compositor::CompositorHandler for Application {
|
||||
let spb = get_single_pixel_buffer(&buffer).unwrap(); // always Ok
|
||||
if let Ok(image) =
|
||||
self.image_importer.import_spb(spb).inspect_err(|e| {
|
||||
log::warn!("wayland_server failed to import SPB: {e:?}")
|
||||
log::warn!("wayland_server failed to import SPB: {e:?}");
|
||||
})
|
||||
{
|
||||
let sbwi = SurfaceBufWithImage {
|
||||
@@ -147,8 +148,7 @@ impl compositor::CompositorHandler for Application {
|
||||
}
|
||||
buffer.release();
|
||||
}
|
||||
Some(BufferAssignment::Removed) => {}
|
||||
None => {}
|
||||
Some(BufferAssignment::Removed) | None => {}
|
||||
}
|
||||
|
||||
let t = time::get_millis() as u32;
|
||||
@@ -299,7 +299,7 @@ delegate_seat!(Application);
|
||||
delegate_data_device!(Application);
|
||||
delegate_output!(Application);
|
||||
|
||||
fn wl_transform_to_frame_transform(
|
||||
const fn wl_transform_to_frame_transform(
|
||||
transform: wl_output::Transform,
|
||||
) -> wlx_capture::frame::Transform {
|
||||
match transform {
|
||||
|
||||
@@ -25,6 +25,7 @@ use smithay::{
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{HashMap, HashSet},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
@@ -106,7 +107,7 @@ pub struct Config {
|
||||
pub blit_method: BlitMethod,
|
||||
}
|
||||
|
||||
pub struct WayVRState {
|
||||
pub struct WvrServerState {
|
||||
time_start: u64,
|
||||
pub manager: client::WayVRCompositor,
|
||||
pub wm: window::WindowManager,
|
||||
@@ -131,8 +132,7 @@ pub enum TickTask {
|
||||
NewExternalProcess(ExternalProcessRequest), // Call WayVRCompositor::add_client after receiving this message
|
||||
}
|
||||
|
||||
impl WayVRState {
|
||||
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
|
||||
impl WvrServerState {
|
||||
pub fn new(
|
||||
gfx: Arc<WGfx>,
|
||||
gfx_extras: &WGfxExtras,
|
||||
@@ -180,8 +180,8 @@ impl WayVRState {
|
||||
// this will throw a compile-time error if smithay's drm-fourcc is out of sync with wlx-capture's
|
||||
let mut formats: Vec<smithay::backend::allocator::Format> = vec![];
|
||||
|
||||
for f in gfx_extras.drm_formats.iter() {
|
||||
formats.push(f.clone());
|
||||
for f in &gfx_extras.drm_formats {
|
||||
formats.push(*f);
|
||||
}
|
||||
|
||||
let dmabuf_state = DmabufFeedbackBuilder::new(main_device, formats.clone())
|
||||
@@ -230,7 +230,7 @@ impl WayVRState {
|
||||
|
||||
let time_start = get_millis();
|
||||
|
||||
Ok(WayVRState {
|
||||
Ok(Self {
|
||||
time_start,
|
||||
manager: client::WayVRCompositor::new(state, display, seat_keyboard, seat_pointer)?,
|
||||
processes: ProcessVec::new(),
|
||||
@@ -246,12 +246,16 @@ impl WayVRState {
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
|
||||
pub fn tick_events(&mut self, app: &mut AppState) -> anyhow::Result<Vec<TickTask>> {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn tick_events(app: &mut AppState) -> anyhow::Result<Vec<TickTask>> {
|
||||
let mut tasks: Vec<TickTask> = Vec::new();
|
||||
|
||||
let Some(wvr_server) = app.wvr_server.as_mut() else {
|
||||
return Ok(tasks);
|
||||
};
|
||||
|
||||
app.ipc_server.tick(&mut ipc_server::TickParams {
|
||||
wayland_state: self,
|
||||
wvr_server,
|
||||
input_state: &app.input_state,
|
||||
tasks: &mut tasks,
|
||||
signals: &app.wayvr_signals,
|
||||
@@ -260,14 +264,14 @@ impl WayVRState {
|
||||
// Tick all child processes
|
||||
let mut to_remove: SmallVec<[process::ProcessHandle; 2]> = SmallVec::new();
|
||||
|
||||
for (handle, process) in self.processes.iter_mut() {
|
||||
for (handle, process) in wvr_server.processes.iter_mut() {
|
||||
if !process.is_running() {
|
||||
to_remove.push(handle);
|
||||
}
|
||||
}
|
||||
|
||||
for p_handle in &to_remove {
|
||||
self.processes.remove(p_handle);
|
||||
wvr_server.processes.remove(p_handle);
|
||||
}
|
||||
|
||||
if !to_remove.is_empty() {
|
||||
@@ -276,20 +280,22 @@ impl WayVRState {
|
||||
));
|
||||
}
|
||||
|
||||
while let Some(task) = self.tasks.read() {
|
||||
while let Some(task) = wvr_server.tasks.read() {
|
||||
match task {
|
||||
WayVRTask::NewExternalProcess(req) => {
|
||||
tasks.push(TickTask::NewExternalProcess(req));
|
||||
}
|
||||
WayVRTask::NewToplevel(client_id, toplevel) => {
|
||||
let toplevel = Rc::new(toplevel);
|
||||
|
||||
// Attach newly created toplevel surfaces to displays
|
||||
for client in &self.manager.clients {
|
||||
for client in &wvr_server.manager.clients {
|
||||
if client.client.id() != client_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(process_handle) =
|
||||
process::find_by_pid(&self.processes, client.pid)
|
||||
process::find_by_pid(&wvr_server.processes, client.pid)
|
||||
else {
|
||||
log::error!(
|
||||
"WayVR window creation failed: Unexpected process ID {}. It wasn't registered before.",
|
||||
@@ -298,32 +304,26 @@ impl WayVRState {
|
||||
continue;
|
||||
};
|
||||
|
||||
let window_handle = self.wm.create_window(&toplevel, process_handle);
|
||||
let window_handle = wvr_server
|
||||
.wm
|
||||
.create_window(toplevel.clone(), process_handle);
|
||||
|
||||
let title: Arc<str> = with_states(toplevel.wl_surface(), |states| {
|
||||
states
|
||||
.data_map
|
||||
.get::<XdgToplevelSurfaceData>()
|
||||
.and_then(|t| t.lock().unwrap().title.clone())
|
||||
.map(|t| t.into())
|
||||
.unwrap_or_else(|| format!("P{}", client.pid).into())
|
||||
.map_or_else(|| format!("P{}", client.pid).into(), String::into)
|
||||
});
|
||||
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Create(
|
||||
OverlaySelector::Nothing,
|
||||
Box::new(move |app: &mut AppState| {
|
||||
Some(
|
||||
create_wl_window_overlay(
|
||||
title,
|
||||
app.xr_backend,
|
||||
app.wayvr_server.as_ref().unwrap().clone(),
|
||||
window_handle,
|
||||
)
|
||||
.inspect_err(|e| {
|
||||
log::error!("Could not add wayland client overlay: {e:?}")
|
||||
})
|
||||
.ok()?,
|
||||
)
|
||||
Some(create_wl_window_overlay(
|
||||
title,
|
||||
app.xr_backend,
|
||||
window_handle,
|
||||
))
|
||||
}),
|
||||
)));
|
||||
|
||||
@@ -333,28 +333,29 @@ impl WayVRState {
|
||||
}
|
||||
}
|
||||
WayVRTask::DropToplevel(client_id, toplevel) => {
|
||||
for client in &self.manager.clients {
|
||||
for client in &wvr_server.manager.clients {
|
||||
if client.client.id() != client_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
let Some(window_handle) = self.wm.find_window_handle(&toplevel) else {
|
||||
let Some(window_handle) = wvr_server.wm.find_window_handle(&toplevel)
|
||||
else {
|
||||
log::warn!("DropToplevel: Couldn't find matching window handle");
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(oid) = self.window_to_overlay.remove(&window_handle) {
|
||||
if let Some(oid) = wvr_server.window_to_overlay.remove(&window_handle) {
|
||||
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Drop(
|
||||
OverlaySelector::Id(oid),
|
||||
)));
|
||||
self.overlay_to_window.remove(oid);
|
||||
wvr_server.overlay_to_window.remove(oid);
|
||||
}
|
||||
|
||||
self.wm.remove_window(window_handle);
|
||||
wvr_server.wm.remove_window(window_handle);
|
||||
}
|
||||
}
|
||||
WayVRTask::ProcessTerminationRequest(process_handle) => {
|
||||
if let Some(process) = self.processes.get_mut(&process_handle) {
|
||||
if let Some(process) = wvr_server.processes.get_mut(&process_handle) {
|
||||
process.terminate();
|
||||
}
|
||||
|
||||
@@ -363,14 +364,14 @@ impl WayVRState {
|
||||
}
|
||||
}
|
||||
|
||||
self.manager.tick_wayland(&mut self.processes)?;
|
||||
wvr_server.manager.tick_wayland(&mut wvr_server.processes)?;
|
||||
|
||||
if self.ticks.is_multiple_of(200) {
|
||||
self.manager.cleanup_clients();
|
||||
self.manager.cleanup_handles();
|
||||
if wvr_server.ticks.is_multiple_of(200) {
|
||||
wvr_server.manager.cleanup_clients();
|
||||
wvr_server.manager.cleanup_handles();
|
||||
}
|
||||
|
||||
self.ticks += 1;
|
||||
wvr_server.ticks += 1;
|
||||
|
||||
Ok(tasks)
|
||||
}
|
||||
@@ -396,7 +397,7 @@ impl WayVRState {
|
||||
}
|
||||
self.mouse_freeze = Instant::now() + Duration::from_millis(1); // prevent other pointer from moving the mouse on the same frame
|
||||
self.wm.mouse = Some(window::MouseState {
|
||||
hover_window: handle.clone(),
|
||||
hover_window: handle,
|
||||
x,
|
||||
y,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use smithay::{
|
||||
input,
|
||||
utils::{Logical, Point},
|
||||
@@ -16,17 +18,17 @@ pub struct Window {
|
||||
pub size_x: u32,
|
||||
pub size_y: u32,
|
||||
pub visible: bool,
|
||||
pub toplevel: ToplevelSurface,
|
||||
pub toplevel: Rc<ToplevelSurface>,
|
||||
pub process: process::ProcessHandle,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
fn new(toplevel: &ToplevelSurface, process: process::ProcessHandle) -> Self {
|
||||
const fn new(toplevel: Rc<ToplevelSurface>, process: process::ProcessHandle) -> Self {
|
||||
Self {
|
||||
size_x: 0,
|
||||
size_y: 0,
|
||||
visible: true,
|
||||
toplevel: toplevel.clone(),
|
||||
toplevel,
|
||||
process,
|
||||
}
|
||||
}
|
||||
@@ -152,7 +154,7 @@ impl WindowManager {
|
||||
for (idx, cell) in self.windows.vec.iter().enumerate() {
|
||||
if let Some(cell) = cell {
|
||||
let window = &cell.obj;
|
||||
if window.toplevel == *toplevel {
|
||||
if *window.toplevel == *toplevel {
|
||||
return Some(WindowVec::get_handle(cell, idx));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +164,7 @@ impl WindowManager {
|
||||
|
||||
pub fn create_window(
|
||||
&mut self,
|
||||
toplevel: &ToplevelSurface,
|
||||
toplevel: Rc<ToplevelSurface>,
|
||||
process: process::ProcessHandle,
|
||||
) -> WindowHandle {
|
||||
self.windows.add(Window::new(toplevel, process))
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
compile_error!("WayVR feature is not enabled");
|
||||
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{BTreeMap, HashMap},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -16,7 +14,7 @@ use wlx_common::{common::LeftRight, config::GeneralConfig, windowing::Positionin
|
||||
use crate::{
|
||||
backend::{
|
||||
task::TaskContainer,
|
||||
wayvr::{self, WayVRState},
|
||||
wayvr::{self, WvrServerState},
|
||||
},
|
||||
config::load_config_with_conf_d,
|
||||
config_io,
|
||||
@@ -203,9 +201,9 @@ impl WayVRConfig {
|
||||
gfx: Arc<WGfx>,
|
||||
gfx_extras: &WGfxExtras,
|
||||
config: &GeneralConfig,
|
||||
tasks: &mut TaskContainer,
|
||||
_tasks: &mut TaskContainer,
|
||||
signals: SyncEventQueue<WayVRSignal>,
|
||||
) -> anyhow::Result<Rc<RefCell<WayVRState>>> {
|
||||
) -> anyhow::Result<WvrServerState> {
|
||||
let primary_count = self
|
||||
.displays
|
||||
.iter()
|
||||
@@ -216,7 +214,7 @@ impl WayVRConfig {
|
||||
anyhow::bail!("Number of primary displays is more than 1")
|
||||
}
|
||||
|
||||
for (catalog_name, catalog) in &self.catalogs {
|
||||
for (_catalog_name, catalog) in &self.catalogs {
|
||||
for app in &catalog.apps {
|
||||
if let Some(b) = app.shown_at_start
|
||||
&& b
|
||||
@@ -226,12 +224,12 @@ impl WayVRConfig {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Rc::new(RefCell::new(WayVRState::new(
|
||||
WvrServerState::new(
|
||||
gfx,
|
||||
gfx_extras,
|
||||
Self::get_wayvr_config(config, self)?,
|
||||
signals,
|
||||
)?)))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -347,7 +347,8 @@ pub(super) fn setup_custom_button<S: 'static>(
|
||||
return Ok(EventResult::Pass);
|
||||
}
|
||||
|
||||
app.hid_provider.send_key_routed(key, down);
|
||||
app.hid_provider
|
||||
.send_key_routed(app.wvr_server.as_mut(), key, down);
|
||||
Ok(EventResult::Consumed)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use wayvr_ipc::packet_server;
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
use crate::backend::wayvr::{self, WayVRState};
|
||||
use crate::backend::wayvr::{self, WvrServerState};
|
||||
|
||||
use crate::{
|
||||
backend::{
|
||||
@@ -18,18 +16,14 @@ use crate::{
|
||||
#[cfg(feature = "wayvr")]
|
||||
fn process_tick_tasks(
|
||||
tick_tasks: Vec<backend::wayvr::TickTask>,
|
||||
r_wayvr: &Rc<RefCell<WayVRState>>,
|
||||
server_state: &mut WvrServerState,
|
||||
) -> anyhow::Result<()> {
|
||||
for tick_task in tick_tasks {
|
||||
match tick_task {
|
||||
backend::wayvr::TickTask::NewExternalProcess(request) => {
|
||||
let mut wayvr = r_wayvr.borrow_mut();
|
||||
|
||||
log::info!("Registering external process with PID {}", request.pid);
|
||||
|
||||
wayvr.add_external_process(request.pid);
|
||||
|
||||
wayvr.manager.add_client(wayvr::client::WayVRClient {
|
||||
server_state.add_external_process(request.pid);
|
||||
server_state.manager.add_client(wayvr::client::WayVRClient {
|
||||
client: request.client,
|
||||
pid: request.pid,
|
||||
});
|
||||
@@ -47,9 +41,6 @@ pub fn tick_events<O>(
|
||||
where
|
||||
O: Default,
|
||||
{
|
||||
#[cfg(feature = "wayvr")]
|
||||
let wayvr_server = app.wayvr_server.clone();
|
||||
|
||||
while let Some(signal) = app.wayvr_signals.read() {
|
||||
match signal {
|
||||
#[cfg(feature = "wayvr")]
|
||||
@@ -76,9 +67,9 @@ where
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
{
|
||||
if let Some(wayvr_server) = wayvr_server {
|
||||
let tick_tasks = wayvr_server.borrow_mut().tick_events(app)?;
|
||||
process_tick_tasks(tick_tasks, &wayvr_server)?;
|
||||
let tick_tasks = WvrServerState::tick_events(app)?;
|
||||
if let Some(wayvr_server) = app.wvr_server.as_mut() {
|
||||
process_tick_tasks(tick_tasks, wayvr_server)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "wayvr")]
|
||||
use crate::backend::wayvr::{self, WayVRState};
|
||||
use crate::backend::wayvr::{self, WvrServerState};
|
||||
|
||||
use crate::{
|
||||
backend::input::InputState,
|
||||
@@ -76,7 +76,7 @@ fn read_payload(conn: &mut local_socket::Stream, size: u32) -> Option<Payload> {
|
||||
|
||||
pub struct TickParams<'a> {
|
||||
#[cfg(feature = "wayvr")]
|
||||
pub wayland_state: &'a mut WayVRState,
|
||||
pub wvr_server: &'a mut WvrServerState,
|
||||
#[cfg(feature = "wayvr")]
|
||||
pub tasks: &'a mut Vec<wayvr::TickTask>,
|
||||
pub signals: &'a SyncEventQueue<WayVRSignal>,
|
||||
@@ -197,7 +197,7 @@ impl Connection {
|
||||
|
||||
send(Some(packet_server::WvrWindowList {
|
||||
list: params
|
||||
.wayland_state
|
||||
.wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.iter()
|
||||
@@ -219,7 +219,7 @@ impl Connection {
|
||||
visible: bool,
|
||||
) {
|
||||
if let Some(window) = params
|
||||
.wayland_state
|
||||
.wvr_server
|
||||
.wm
|
||||
.windows
|
||||
.get_mut(&wayvr::window::WindowHandle::from_packet(handle))
|
||||
@@ -238,7 +238,7 @@ impl Connection {
|
||||
let args_vec = gen_args_vec(&packet_params.args);
|
||||
let env_vec = gen_env_vec(&packet_params.env);
|
||||
|
||||
let res = params.wayland_state.spawn_process(
|
||||
let res = params.wvr_server.spawn_process(
|
||||
&packet_params.exec,
|
||||
&args_vec,
|
||||
&env_vec,
|
||||
@@ -263,7 +263,7 @@ impl Connection {
|
||||
serial: ipc::Serial,
|
||||
) -> anyhow::Result<()> {
|
||||
let list: Vec<packet_server::WvrProcess> = params
|
||||
.wayland_state
|
||||
.wvr_server
|
||||
.processes
|
||||
.vec
|
||||
.iter()
|
||||
@@ -298,7 +298,7 @@ impl Connection {
|
||||
process_handle: packet_server::WvrProcessHandle,
|
||||
) {
|
||||
let native_handle = &wayvr::process::ProcessHandle::from_packet(process_handle);
|
||||
let process = params.wayland_state.processes.get_mut(native_handle);
|
||||
let process = params.wvr_server.processes.get_mut(native_handle);
|
||||
|
||||
let Some(process) = process else {
|
||||
return;
|
||||
@@ -316,7 +316,7 @@ impl Connection {
|
||||
) -> anyhow::Result<()> {
|
||||
let native_handle = &wayvr::process::ProcessHandle::from_packet(process_handle);
|
||||
let process = params
|
||||
.wayland_state
|
||||
.wvr_server
|
||||
.processes
|
||||
.get(native_handle)
|
||||
.map(|process| process.to_packet(*native_handle));
|
||||
|
||||
@@ -85,7 +85,8 @@ pub fn create_keyboard(app: &mut AppState, wayland: bool) -> anyhow::Result<Over
|
||||
.ok();
|
||||
|
||||
if let Some(keymap) = maybe_keymap.as_ref() {
|
||||
app.hid_provider.keymap_changed(keymap);
|
||||
app.hid_provider
|
||||
.keymap_changed(app.wvr_server.as_mut(), keymap);
|
||||
}
|
||||
|
||||
if !auto_labels {
|
||||
@@ -218,7 +219,8 @@ impl KeyboardBackend {
|
||||
|
||||
fn auto_switch_keymap(&mut self, app: &mut AppState) -> anyhow::Result<bool> {
|
||||
let keymap = self.get_effective_keymap(app)?;
|
||||
app.hid_provider.keymap_changed(&keymap);
|
||||
app.hid_provider
|
||||
.keymap_changed(app.wvr_server.as_mut(), &keymap);
|
||||
self.switch_keymap(&keymap, app)
|
||||
}
|
||||
|
||||
@@ -258,7 +260,8 @@ impl OverlayBackend for KeyboardBackend {
|
||||
}
|
||||
fn pause(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||
self.panel().state.modifiers = 0;
|
||||
app.hid_provider.set_modifiers_routed(0);
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), 0);
|
||||
self.panel().pause(app)
|
||||
}
|
||||
fn resume(&mut self, app: &mut AppState) -> anyhow::Result<()> {
|
||||
@@ -371,20 +374,24 @@ fn handle_press(
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
app.hid_provider.set_modifiers_routed(keyboard.modifiers);
|
||||
app.hid_provider.send_key_routed(*vk, true);
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), keyboard.modifiers);
|
||||
app.hid_provider
|
||||
.send_key_routed(app.wvr_server.as_mut(), *vk, true);
|
||||
pressed.set(true);
|
||||
play_key_click(app);
|
||||
}
|
||||
KeyButtonData::Modifier { modifier, sticky } => {
|
||||
sticky.set(keyboard.modifiers & *modifier == 0);
|
||||
keyboard.modifiers |= *modifier;
|
||||
app.hid_provider.set_modifiers_routed(keyboard.modifiers);
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), keyboard.modifiers);
|
||||
play_key_click(app);
|
||||
}
|
||||
KeyButtonData::Macro { verbs } => {
|
||||
for (vk, press) in verbs {
|
||||
app.hid_provider.send_key_routed(*vk, *press);
|
||||
app.hid_provider
|
||||
.send_key_routed(app.wvr_server.as_mut(), *vk, *press);
|
||||
}
|
||||
play_key_click(app);
|
||||
}
|
||||
@@ -412,8 +419,10 @@ fn handle_release(app: &mut AppState, key: &KeyState, keyboard: &mut KeyboardSta
|
||||
keyboard.modifiers &= !*m;
|
||||
}
|
||||
}
|
||||
app.hid_provider.send_key_routed(*vk, false);
|
||||
app.hid_provider.set_modifiers_routed(keyboard.modifiers);
|
||||
app.hid_provider
|
||||
.send_key_routed(app.wvr_server.as_mut(), *vk, false);
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), keyboard.modifiers);
|
||||
true
|
||||
}
|
||||
KeyButtonData::Modifier { modifier, sticky } => {
|
||||
@@ -421,7 +430,8 @@ fn handle_release(app: &mut AppState, key: &KeyState, keyboard: &mut KeyboardSta
|
||||
false
|
||||
} else {
|
||||
keyboard.modifiers &= !*modifier;
|
||||
app.hid_provider.set_modifiers_routed(keyboard.modifiers);
|
||||
app.hid_provider
|
||||
.set_modifiers_routed(app.wvr_server.as_mut(), keyboard.modifiers);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use glam::{Affine2, Affine3A, Quat, Vec3, vec3};
|
||||
use smithay::wayland::compositor::with_states;
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
use vulkano::image::view::ImageView;
|
||||
use wlx_capture::frame::MouseMeta;
|
||||
use wlx_common::{
|
||||
@@ -12,7 +12,7 @@ use crate::{
|
||||
backend::{
|
||||
XrBackend,
|
||||
input::{self, HoverResult},
|
||||
wayvr::{self, SurfaceBufWithImage, WayVRState},
|
||||
wayvr::{self, SurfaceBufWithImage},
|
||||
},
|
||||
graphics::ExtentExt,
|
||||
overlays::screen::capture::ScreenPipeline,
|
||||
@@ -30,10 +30,9 @@ use crate::{
|
||||
pub fn create_wl_window_overlay(
|
||||
name: Arc<str>,
|
||||
xr_backend: XrBackend,
|
||||
wayvr: Rc<RefCell<WayVRState>>,
|
||||
window: wayvr::window::WindowHandle,
|
||||
) -> anyhow::Result<OverlayWindowConfig> {
|
||||
Ok(OverlayWindowConfig {
|
||||
) -> OverlayWindowConfig {
|
||||
OverlayWindowConfig {
|
||||
name: name.clone(),
|
||||
default_state: OverlayWindowState {
|
||||
grabbable: true,
|
||||
@@ -50,35 +49,32 @@ pub fn create_wl_window_overlay(
|
||||
keyboard_focus: Some(KeyboardFocus::WayVR),
|
||||
category: OverlayCategory::WayVR,
|
||||
show_on_spawn: true,
|
||||
..OverlayWindowConfig::from_backend(Box::new(WayVRBackend::new(
|
||||
name, xr_backend, wayvr, window,
|
||||
)?))
|
||||
})
|
||||
..OverlayWindowConfig::from_backend(Box::new(WvrWindowBackend::new(
|
||||
name, xr_backend, window,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WayVRBackend {
|
||||
pub struct WvrWindowBackend {
|
||||
name: Arc<str>,
|
||||
pipeline: Option<ScreenPipeline>,
|
||||
interaction_transform: Option<Affine2>,
|
||||
window: wayvr::window::WindowHandle,
|
||||
wayvr: Rc<RefCell<WayVRState>>,
|
||||
just_resumed: bool,
|
||||
meta: Option<FrameMeta>,
|
||||
stereo: Option<StereoMode>,
|
||||
cur_image: Option<Arc<ImageView>>,
|
||||
}
|
||||
|
||||
impl WayVRBackend {
|
||||
fn new(
|
||||
impl WvrWindowBackend {
|
||||
const fn new(
|
||||
name: Arc<str>,
|
||||
xr_backend: XrBackend,
|
||||
wayvr: Rc<RefCell<WayVRState>>,
|
||||
window: wayvr::window::WindowHandle,
|
||||
) -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
) -> Self {
|
||||
Self {
|
||||
name,
|
||||
pipeline: None,
|
||||
wayvr,
|
||||
window,
|
||||
interaction_transform: None,
|
||||
just_resumed: false,
|
||||
@@ -89,11 +85,11 @@ impl WayVRBackend {
|
||||
None
|
||||
},
|
||||
cur_image: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OverlayBackend for WayVRBackend {
|
||||
impl OverlayBackend for WvrWindowBackend {
|
||||
fn init(&mut self, _app: &mut state::AppState) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
@@ -108,8 +104,12 @@ impl OverlayBackend for WayVRBackend {
|
||||
}
|
||||
|
||||
fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
|
||||
let wayvr = &self.wayvr.borrow();
|
||||
let Some(window) = wayvr.wm.windows.get(&self.window) else {
|
||||
let Some(toplevel) = app
|
||||
.wvr_server
|
||||
.as_ref()
|
||||
.and_then(|sv| sv.wm.windows.get(&self.window))
|
||||
.map(|win| win.toplevel.clone())
|
||||
else {
|
||||
log::debug!(
|
||||
"{:?}: WayVR overlay without matching window entry",
|
||||
self.name
|
||||
@@ -117,7 +117,7 @@ impl OverlayBackend for WayVRBackend {
|
||||
return Ok(ShouldRender::Unable);
|
||||
};
|
||||
|
||||
with_states(window.toplevel.wl_surface(), |states| {
|
||||
with_states(toplevel.wl_surface(), |states| {
|
||||
if let Some(surf) = SurfaceBufWithImage::get_from_surface(states) {
|
||||
let mut meta = FrameMeta {
|
||||
extent: surf.image.image().extent(),
|
||||
@@ -174,8 +174,8 @@ impl OverlayBackend for WayVRBackend {
|
||||
) -> anyhow::Result<()> {
|
||||
let image = self.cur_image.as_ref().unwrap().clone();
|
||||
|
||||
let wayvr = &self.wayvr.borrow();
|
||||
let mouse = wayvr
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
let mouse = wvr_server
|
||||
.wm
|
||||
.mouse
|
||||
.as_ref()
|
||||
@@ -202,23 +202,23 @@ impl OverlayBackend for WayVRBackend {
|
||||
|
||||
fn notify(
|
||||
&mut self,
|
||||
_app: &mut state::AppState,
|
||||
app: &mut state::AppState,
|
||||
event_data: OverlayEventData,
|
||||
) -> anyhow::Result<()> {
|
||||
if let OverlayEventData::IdAssigned(oid) = event_data {
|
||||
let wayvr = &mut self.wayvr.borrow_mut();
|
||||
wayvr.overlay_added(oid, self.window.clone());
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
wvr_server.overlay_added(oid, self.window.clone());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_hover(&mut self, _app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult {
|
||||
let wayvr = &mut self.wayvr.borrow_mut();
|
||||
|
||||
fn on_hover(&mut self, app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult {
|
||||
if let Some(meta) = self.meta.as_ref() {
|
||||
let x = ((hit.uv.x * (meta.extent[0] as f32)) as u32).max(0);
|
||||
let y = ((hit.uv.y * (meta.extent[1] as f32)) as u32).max(0);
|
||||
wayvr.send_mouse_move(self.window, x, y);
|
||||
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
wvr_server.send_mouse_move(self.window, x, y);
|
||||
}
|
||||
|
||||
HoverResult {
|
||||
@@ -231,7 +231,7 @@ impl OverlayBackend for WayVRBackend {
|
||||
// Ignore event
|
||||
}
|
||||
|
||||
fn on_pointer(&mut self, _app: &mut state::AppState, hit: &input::PointerHit, pressed: bool) {
|
||||
fn on_pointer(&mut self, app: &mut state::AppState, hit: &input::PointerHit, pressed: bool) {
|
||||
if let Some(index) = match hit.mode {
|
||||
input::PointerMode::Left => Some(wayvr::MouseIndex::Left),
|
||||
input::PointerMode::Middle => Some(wayvr::MouseIndex::Center),
|
||||
@@ -241,22 +241,23 @@ impl OverlayBackend for WayVRBackend {
|
||||
None
|
||||
}
|
||||
} {
|
||||
let wayvr = &mut self.wayvr.borrow_mut();
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
if pressed {
|
||||
wayvr.send_mouse_down(self.window, index);
|
||||
wvr_server.send_mouse_down(self.window, index);
|
||||
} else {
|
||||
wayvr.send_mouse_up(index);
|
||||
wvr_server.send_mouse_up(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_scroll(
|
||||
&mut self,
|
||||
_app: &mut state::AppState,
|
||||
app: &mut state::AppState,
|
||||
_hit: &input::PointerHit,
|
||||
delta: WheelDelta,
|
||||
) {
|
||||
self.wayvr.borrow_mut().send_mouse_scroll(delta);
|
||||
let wvr_server = app.wvr_server.as_mut().unwrap(); //never None
|
||||
wvr_server.send_mouse_scroll(delta);
|
||||
}
|
||||
|
||||
fn get_interaction_transform(&mut self) -> Option<Affine2> {
|
||||
|
||||
@@ -12,13 +12,10 @@ use wlx_common::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
use {
|
||||
crate::config_wayvr::{self, WayVRConfig},
|
||||
std::{cell::RefCell, rc::Rc},
|
||||
};
|
||||
use crate::config_wayvr::{self, WayVRConfig};
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
use crate::backend::wayvr::WayVRState;
|
||||
use crate::backend::wayvr::WvrServerState;
|
||||
#[cfg(feature = "osc")]
|
||||
use crate::subsystem::osc::OscSender;
|
||||
|
||||
@@ -62,7 +59,7 @@ pub struct AppState {
|
||||
pub osc_sender: Option<OscSender>,
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
pub wayvr_server: Option<Rc<RefCell<WayVRState>>>,
|
||||
pub wvr_server: Option<WvrServerState>,
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
@@ -93,11 +90,6 @@ impl AppState {
|
||||
|
||||
let mut hid_provider = HidWrapper::new();
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
if let Some(wayland_server) = wayvr_server.as_ref() {
|
||||
hid_provider.set_wayvr(wayland_server.clone());
|
||||
}
|
||||
|
||||
#[cfg(feature = "osc")]
|
||||
let osc_sender = crate::subsystem::osc::OscSender::new(session.config.osc_out_port).ok();
|
||||
|
||||
@@ -158,7 +150,7 @@ impl AppState {
|
||||
osc_sender,
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
wayvr_server,
|
||||
wvr_server: wayvr_server,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
use super::hid::{self, HidProvider, VirtualKey};
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
use crate::backend::wayvr::WayVRState;
|
||||
use crate::subsystem::hid::XkbKeymap;
|
||||
#[cfg(feature = "wayvr")]
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use crate::{backend::wayvr::WvrServerState, subsystem::hid::XkbKeymap};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum KeyboardFocus {
|
||||
PhysicalScreen,
|
||||
|
||||
#[allow(dead_code)] // Not available if "wayvr" feature is disabled
|
||||
WayVR, // (for now without wayland window id data, it's handled internally),
|
||||
WayVR, // (wayland window id data is handled internally),
|
||||
}
|
||||
|
||||
pub struct HidWrapper {
|
||||
pub keyboard_focus: KeyboardFocus,
|
||||
pub inner: Box<dyn HidProvider>,
|
||||
pub keymap: Option<XkbKeymap>,
|
||||
#[cfg(feature = "wayvr")]
|
||||
pub wayvr: Option<Rc<RefCell<WayVRState>>>, // Dynamically created if requested
|
||||
}
|
||||
|
||||
impl HidWrapper {
|
||||
@@ -27,41 +21,32 @@ impl HidWrapper {
|
||||
Self {
|
||||
keyboard_focus: KeyboardFocus::PhysicalScreen,
|
||||
inner: hid::initialize(),
|
||||
#[cfg(feature = "wayvr")]
|
||||
wayvr: None,
|
||||
keymap: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
pub fn set_wayvr(&mut self, wayvr: Rc<RefCell<WayVRState>>) {
|
||||
if let Some(keymap) = self.keymap.take() {
|
||||
let _ = wayvr
|
||||
.borrow_mut()
|
||||
.set_keymap(&keymap.inner)
|
||||
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
|
||||
}
|
||||
self.wayvr = Some(wayvr);
|
||||
}
|
||||
|
||||
pub fn send_key_routed(&self, key: VirtualKey, down: bool) {
|
||||
pub fn send_key_routed(
|
||||
&self,
|
||||
wvr_server: Option<&mut WvrServerState>,
|
||||
key: VirtualKey,
|
||||
down: bool,
|
||||
) {
|
||||
match self.keyboard_focus {
|
||||
KeyboardFocus::PhysicalScreen => self.inner.send_key(key, down),
|
||||
KeyboardFocus::WayVR =>
|
||||
{
|
||||
#[cfg(feature = "wayvr")]
|
||||
if let Some(wayvr) = &self.wayvr {
|
||||
wayvr.borrow_mut().send_key(key as u32, down);
|
||||
if let Some(wvr_server) = wvr_server {
|
||||
wvr_server.send_key(key as u32, down);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keymap_changed(&mut self, keymap: &XkbKeymap) {
|
||||
pub fn keymap_changed(&mut self, wvr_server: Option<&mut WvrServerState>, keymap: &XkbKeymap) {
|
||||
#[cfg(feature = "wayvr")]
|
||||
if let Some(wayvr) = &self.wayvr {
|
||||
let _ = wayvr
|
||||
.borrow_mut()
|
||||
if let Some(wvr_server) = wvr_server {
|
||||
let _ = wvr_server
|
||||
.set_keymap(&keymap.inner)
|
||||
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
|
||||
} else {
|
||||
@@ -74,14 +59,14 @@ impl HidWrapper {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_modifiers_routed(&mut self, mods: u8) {
|
||||
pub fn set_modifiers_routed(&mut self, wvr_server: Option<&mut WvrServerState>, mods: u8) {
|
||||
match self.keyboard_focus {
|
||||
KeyboardFocus::PhysicalScreen => self.inner.set_modifiers(mods),
|
||||
KeyboardFocus::WayVR =>
|
||||
{
|
||||
#[cfg(feature = "wayvr")]
|
||||
if let Some(wayvr) = &self.wayvr {
|
||||
wayvr.borrow_mut().set_modifiers(mods);
|
||||
if let Some(wvr_server) = wvr_server {
|
||||
wvr_server.set_modifiers(mods);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user