diff --git a/wayvr-ipc/src/client.rs b/wayvr-ipc/src/client.rs index 3ca1106c..9625130e 100644 --- a/wayvr-ipc/src/client.rs +++ b/wayvr-ipc/src/client.rs @@ -460,6 +460,11 @@ impl WayVRClient { Ok(()) } + pub async fn fn_wvr_input_capture(client: WayVRClientMutex, grab: bool) -> anyhow::Result<()> { + send_only!(client, &PacketClient::WvrInputCapture(grab)); + Ok(()) + } + pub async fn fn_wlx_modify_panel( client: WayVRClientMutex, params: packet_client::WlxModifyPanelParams, diff --git a/wayvr-ipc/src/packet_client.rs b/wayvr-ipc/src/packet_client.rs index 9226e779..16f0fff0 100644 --- a/wayvr-ipc/src/packet_client.rs +++ b/wayvr-ipc/src/packet_client.rs @@ -90,6 +90,7 @@ pub enum PacketClient { WvrProcessLaunch(Serial, WvrProcessLaunchParams), WvrProcessList(Serial), WvrProcessTerminate(packet_server::WvrProcessHandle), + WvrInputCapture(bool), WlxInputState(Serial), WlxModifyPanel(WlxModifyPanelParams), WlxDeviceHaptics(usize, WlxHapticsParams), diff --git a/wayvr/src/backend/wayvr/mod.rs b/wayvr/src/backend/wayvr/mod.rs index cc57497d..01e55fab 100644 --- a/wayvr/src/backend/wayvr/mod.rs +++ b/wayvr/src/backend/wayvr/mod.rs @@ -803,7 +803,7 @@ impl WvrServerState { self.close_window(window_handle); } } - input_capture::KeyCombo::AltTab => self.alt_tab(), + input_capture::KeyCombo::AltTab => self.alt_tab(pressed), _ => {} }, } @@ -852,7 +852,7 @@ impl WvrServerState { } } - fn alt_tab(&mut self) { + fn alt_tab(&mut self, pressed: bool) { let mut windows: Vec<_> = self.wm.windows.iter().collect(); if windows.is_empty() { return; diff --git a/wayvr/src/ipc/ipc_server.rs b/wayvr/src/ipc/ipc_server.rs index 7f1cf4c9..dffe43f0 100644 --- a/wayvr/src/ipc/ipc_server.rs +++ b/wayvr/src/ipc/ipc_server.rs @@ -334,6 +334,10 @@ impl Connection { Ok(()) } + fn handle_wvr_input_capture(params: &mut TickParams, grab: bool) { + params.wvr_server.set_input_focus(grab); + } + fn handle_wlx_device_haptics( params: &mut TickParams, device: usize, @@ -426,6 +430,9 @@ impl Connection { PacketClient::WvrProcessTerminate(process_handle) => { Self::handle_wvr_process_terminate(params, process_handle); } + PacketClient::WvrInputCapture(grab) => { + Self::handle_wvr_input_capture(params, grab); + } PacketClient::WlxDeviceHaptics(device, haptics_params) => { Self::handle_wlx_device_haptics(params, device, haptics_params); } diff --git a/wayvrctl/src/helper.rs b/wayvrctl/src/helper.rs index 05d70dac..6193a192 100644 --- a/wayvrctl/src/helper.rs +++ b/wayvrctl/src/helper.rs @@ -135,6 +135,14 @@ pub async fn wvr_process_launch( ) } +pub async fn wlr_input_capture(state: &mut WayVRClientState, grab: bool) { + handle_empty_result( + WayVRClient::fn_wvr_input_capture(state.wayvr_client.clone(), grab) + .await + .context("failed to change input capture"), + ) +} + pub async fn wlx_device_haptics( state: &mut WayVRClientState, device: usize, diff --git a/wayvrctl/src/main.rs b/wayvrctl/src/main.rs index ed3e7994..e67cdab4 100644 --- a/wayvrctl/src/main.rs +++ b/wayvrctl/src/main.rs @@ -14,9 +14,9 @@ use wayvr_ipc::{ }; use crate::helper::{ - WayVRClientState, wlx_device_haptics, wlx_handsfree, wlx_input_state, wlx_panel_modify, - wlx_show_hide, wlx_switch_set, wvr_process_get, wvr_process_launch, wvr_process_list, - wvr_process_terminate, wvr_window_list, wvr_window_set_visible, + WayVRClientState, wlr_input_capture, wlx_device_haptics, wlx_handsfree, wlx_input_state, + wlx_panel_modify, wlx_show_hide, wlx_switch_set, wvr_process_get, wvr_process_launch, + wvr_process_list, wvr_process_terminate, wvr_window_list, wvr_window_set_visible, }; mod helper; @@ -200,6 +200,9 @@ async fn run_once(state: &mut WayVRClientState, args: Args) -> anyhow::Result<() Subcommands::Handsfree { command } => { wlx_handsfree(state, command.into()).await; } + Subcommands::InputCapture { command } => { + wlr_input_capture(state, matches!(command, GrabRelease::Grab)).await; + } } Ok(()) } @@ -301,6 +304,15 @@ enum Subcommands { #[command(subcommand)] command: SubcommandHandsfree, }, + InputCapture { + command: GrabRelease, + }, +} + +#[derive(Debug, Clone, Copy, clap::ValueEnum)] +enum GrabRelease { + Grab, + Release, } #[derive(Debug, Clone, Copy, clap::ValueEnum)]