wayvr-ipc: bump to version 4, remove unused WayVR signal broadcast feature, fix broken `window-set-visible` command

This commit is contained in:
Aleksander 2026-07-26 11:04:00 +02:00 committed by galister
parent c92e27dcf9
commit 5dffbb9fdb
8 changed files with 39 additions and 64 deletions

View File

@ -32,8 +32,6 @@ pub struct AuthInfo {
pub runtime: String,
}
type SignalFunc = Box<dyn FnMut(&packet_server::PacketServer) -> bool + Send>;
pub struct WayVRClient {
receiver: ReceiverMutex,
sender: SenderMutex,
@ -41,7 +39,6 @@ pub struct WayVRClient {
exiting: bool,
queued_packets: DenseSlotMap<QueuedPacketHandle, QueuedPacket>,
pub auth: Option<AuthInfo>,
pub on_signal: Option<SignalFunc>,
}
pub async fn send_packet(sender: &SenderMutex, data: &[u8]) -> anyhow::Result<()> {
@ -128,10 +125,6 @@ macro_rules! send_only {
}
impl WayVRClient {
pub fn set_signal_handler(&mut self, on_signal: SignalFunc) {
self.on_signal = Some(on_signal);
}
pub async fn new(client_name: &str) -> anyhow::Result<WayVRClientMutex> {
let printname = "/tmp/wayvr_ipc.sock";
@ -156,7 +149,6 @@ impl WayVRClient {
exiting: false,
queued_packets: Default::default(),
auth: None,
on_signal: None,
}));
WayVRClient::start_runner(client.clone(), cancel_rx);
@ -251,14 +243,6 @@ impl WayVRClient {
);
}
if let PacketServer::WvrStateChanged(_) = &packet
&& let Some(on_signal) = &mut client.on_signal
&& (*on_signal)(&packet)
{
// Signal consumed
return Ok(());
}
// queue packet to read if it contains a serial response
if let Some(serial) = packet.serial() {
for (_, qpacket) in &mut client.queued_packets {

View File

@ -22,7 +22,7 @@ impl SerialGenerator {
}
}
pub const PROTOCOL_VERSION: u32 = 3;
pub const PROTOCOL_VERSION: u32 = 4;
pub const CONNECTION_MAGIC: &str = "wayvr_ipc";
pub fn data_encode<T>(data: &T) -> Vec<u8>

View File

@ -53,7 +53,7 @@ use std::{
};
use vulkano::image::view::ImageView;
use wayland_protocols::xdg::shell::server::xdg_toplevel;
use wayvr_ipc::{packet_client::PositionMode, packet_server};
use wayvr_ipc::packet_client::PositionMode;
use wgui::{gfx::WGfx, log::LogErr};
use wlx_capture::frame::Transform;
use wlx_common::{
@ -74,7 +74,7 @@ use crate::{
},
},
graphics::{ExtentExt, WGfxExtras},
ipc::{event_queue::SyncEventQueue, ipc_server, signal::WayVRSignal},
ipc::{event_queue::SyncEventQueue, ipc_server},
overlays::{
anchor::ALTTAB_HELP_NAME,
wayvr::{WvrCommand, create_wl_window_overlay},
@ -126,6 +126,7 @@ pub enum WayVRTask {
DropToplevel(ClientId, ToplevelSurface),
MinimizeRequest(ClientId, ToplevelSurface),
TitleChange(ClientId, ToplevelSurface),
VisibilityChange(window::WindowHandle, bool),
NewExternalProcess(ExternalProcessRequest),
ProcessTerminationRequest(process::ProcessHandle, KillSignal),
CloseWindowRequest(window::WindowHandle),
@ -138,7 +139,6 @@ pub struct WvrServerState {
pub tasks: SyncEventQueue<WayVRTask>,
ticks: u64,
cur_modifiers: u8,
signals: SyncEventQueue<WayVRSignal>,
mouse_freeze: Instant,
window_to_overlay: HashMap<window::WindowHandle, OverlayID>,
overlay_to_window: SecondaryMap<OverlayID, window::WindowHandle>,
@ -171,11 +171,7 @@ const KEY_REPEAT_RATE: i32 = 50;
const WAYVR_SCREEN_RES: [i32; 2] = [2560, 1440];
impl WvrServerState {
pub fn new(
gfx: Arc<WGfx>,
gfx_extras: &WGfxExtras,
signals: SyncEventQueue<WayVRSignal>,
) -> anyhow::Result<Self> {
pub fn new(gfx: Arc<WGfx>, gfx_extras: &WGfxExtras) -> anyhow::Result<Self> {
const fn filter_allow_any(_: &wayland_server::Client) -> bool {
true
}
@ -301,7 +297,6 @@ impl WvrServerState {
ticks: 0,
tasks,
cur_modifiers: 0,
signals,
mouse_freeze: Instant::now(),
window_to_overlay: HashMap::new(),
overlay_to_window: SecondaryMap::new(),
@ -343,12 +338,6 @@ impl WvrServerState {
wvr_server.process_removed(&mut app.tasks, *p_handle);
}
if !to_remove.is_empty() {
app.wayvr_signals.send(WayVRSignal::BroadcastStateChanged(
packet_server::WvrStateChanged::ProcessRemoved,
));
}
while let Some(task) = wvr_server.tasks.read() {
match task {
WayVRTask::NewExternalProcess(req) => {
@ -506,10 +495,6 @@ impl WvrServerState {
.ok()
}),
)));
app.wayvr_signals.send(WayVRSignal::BroadcastStateChanged(
packet_server::WvrStateChanged::WindowCreated,
));
}
}
WayVRTask::DropToplevel(client_id, toplevel) => {
@ -554,6 +539,19 @@ impl WvrServerState {
wvr_server.wm.remove_window(window_handle);
}
}
WayVRTask::VisibilityChange(window_handle, visible) => {
if let Some(oid) = wvr_server.window_to_overlay.get(&window_handle) {
app.tasks
.enqueue(TaskType::Overlay(OverlayTask::ToggleOverlay(
OverlaySelector::Id(*oid),
if visible {
ToggleMode::EnsureOn
} else {
ToggleMode::EnsureOff
},
)));
}
}
WayVRTask::MinimizeRequest(client_id, toplevel) => {
for client in &wvr_server.manager.clients {
if client.client.id() != client_id {
@ -1258,10 +1256,6 @@ impl WvrServerState {
pos_mode,
}));
self.signals.send(WayVRSignal::BroadcastStateChanged(
packet_server::WvrStateChanged::ProcessCreated,
));
Ok(handle)
}

View File

@ -1,9 +1,7 @@
use crate::backend::wayvr::{self, WayVRTask, WvrServerState};
use wayvr_ipc::packet_client::{HandsfreeMode, HandsfreeParams};
use wayvr_ipc::packet_server;
use wlx_common::config::HandsfreePointer;
use crate::backend::wayvr::{self, WvrServerState};
use crate::{
backend::{
self,
@ -41,9 +39,12 @@ where
{
while let Some(signal) = app.wayvr_signals.read() {
match signal {
WayVRSignal::BroadcastStateChanged(packet) => {
app.ipc_server
.broadcast(packet_server::PacketServer::WvrStateChanged(packet));
WayVRSignal::WindowVisibilityChanged(window_handle, visible) => {
if let Some(server) = &mut app.wvr_server {
server
.tasks
.send(WayVRTask::VisibilityChange(window_handle, visible));
}
}
WayVRSignal::DeviceHaptics(device, haptics) => {
app.tasks

View File

@ -223,13 +223,12 @@ impl Connection {
handle: packet_server::WvrWindowHandle,
visible: bool,
) {
if let Some(window) = params
.wvr_server
.wm
.windows
.get_mut(wayvr::window::WindowHandle::from_packet(handle))
{
let window_handle = wayvr::window::WindowHandle::from_packet(handle);
if let Some(window) = params.wvr_server.wm.windows.get_mut(window_handle) {
window.visible = visible;
params
.signals
.send(WayVRSignal::WindowVisibilityChanged(window_handle, visible))
}
}
@ -576,12 +575,4 @@ impl WayVRServer {
self.accept_connections();
self.tick_connections(params);
}
pub fn broadcast(&mut self, packet: packet_server::PacketServer) {
for connection in &mut self.connections {
if let Err(e) = send_packet(&mut connection.conn, &ipc::data_encode(&packet)) {
log::error!("failed to broadcast packet: {e:?}");
}
}
}
}

View File

@ -1,9 +1,11 @@
use crate::backend::wayvr::window;
#[derive(Clone)]
pub enum WayVRSignal {
BroadcastStateChanged(wayvr_ipc::packet_server::WvrStateChanged),
DeviceHaptics(usize, crate::backend::input::Haptics),
SwitchSet(Option<usize>),
Handsfree(wayvr_ipc::packet_client::HandsfreeParams),
ShowHide,
CustomTask(crate::backend::task::ModifyPanelTask),
WindowVisibilityChanged(window::WindowHandle, bool),
}

View File

@ -106,7 +106,7 @@ impl AppState {
let wvr_signals = SyncEventQueue::new();
let wvr_server = {
let mut maybe_wvr = WvrServerState::new(gfx.clone(), &gfx_extras, wvr_signals.clone())
let mut maybe_wvr = WvrServerState::new(gfx.clone(), &gfx_extras)
.log_err("Could not initialize WayVR Server")
.ok();
if let Some(wvr) = maybe_wvr.as_mut() {

View File

@ -11,6 +11,7 @@ use wayvr_ipc::{
client::WayVRClient,
ipc,
packet_client::{self, PositionMode},
packet_server::{WvrProcessHandle, WvrWindowHandle},
};
use crate::helper::{
@ -107,11 +108,13 @@ async fn run_once(state: &mut WayVRClientState, args: Args) -> anyhow::Result<()
handle,
visible_0_or_1,
} => {
let handle = serde_json::from_str(&handle).context("Invalid handle")?;
let handle =
serde_json::from_str::<WvrWindowHandle>(&handle).context("Invalid handle")?;
wvr_window_set_visible(state, handle, visible_0_or_1 != 0).await;
}
Subcommands::ProcessGet { handle } => {
let handle = serde_json::from_str(&handle).context("Invalid handle")?;
let handle =
serde_json::from_str::<WvrProcessHandle>(&handle).context("Invalid handle")?;
wvr_process_get(state, handle).await;
}
Subcommands::ProcessList => {