Skip to content

Commit

Permalink
Merge pull request #132 from olekolek1000/wayvr_dashboard_ipc
Browse files Browse the repository at this point in the history
WayVR: IPC: Fix process launcher calling create_display two times
  • Loading branch information
olekolek1000 authored Jan 12, 2025
2 parents eb3087f + de6c5b8 commit ff15010
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/backend/wayvr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn generate_auth_key() -> String {
uuid.to_string()
}

#[derive(Debug)]
pub struct DisplayWindow {
pub window_handle: window::WindowHandle,
pub toplevel: ToplevelSurface,
Expand All @@ -42,12 +43,14 @@ pub struct SpawnProcessResult {
pub child: std::process::Child,
}

#[derive(Debug)]
pub enum DisplayTask {
ProcessCleanup(process::ProcessHandle),
}

const MAX_DISPLAY_SIZE: u16 = 8192;

#[derive(Debug)]
pub struct Display {
// Display info stuff
pub width: u16,
Expand Down
5 changes: 3 additions & 2 deletions src/backend/wayvr/egl_data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::egl_ex;
use anyhow::anyhow;

#[derive(Debug)]
pub struct EGLData {
pub egl: khronos_egl::Instance<khronos_egl::Static>,
pub display: khronos_egl::Display,
Expand All @@ -15,13 +16,13 @@ macro_rules! bind_egl_function {
};
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct DMAbufModifierInfo {
pub modifiers: Vec<u64>,
pub fourcc: u32,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct DMAbufData {
pub fd: i32,
pub stride: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/backend/wayvr/event_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use std::{cell::RefCell, collections::VecDeque, rc::Rc};

#[derive(Debug)]
struct Data<DataType> {
queue: VecDeque<DataType>,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct SyncEventQueue<DataType> {
data: Rc<RefCell<Data<DataType>>>,
}
Expand Down
4 changes: 3 additions & 1 deletion src/backend/wayvr/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ macro_rules! gen_id {
$cell_name:ident,
$handle_name:ident) => {
//ThingCell
#[derive(Debug)]
pub struct $cell_name {
pub obj: $instance_name,
pub generation: u64,
}

//ThingVec
#[derive(Debug)]
pub struct $container_name {
// Vec<Option<ThingCell>>
pub vec: Vec<Option<$cell_name>>,
Expand All @@ -20,7 +22,7 @@ macro_rules! gen_id {
}

//ThingHandle
#[derive(Default, Clone, Copy, PartialEq, Hash, Eq)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Eq)]
pub struct $handle_name {
idx: u32,
generation: u64,
Expand Down
7 changes: 5 additions & 2 deletions src/backend/wayvr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use wayvr_ipc::packet_client;
const STR_INVALID_HANDLE_DISP: &str = "Invalid display handle";
const STR_INVALID_HANDLE_PROCESS: &str = "Invalid process handle";

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct WaylandEnv {
pub display_num: u32,
}
Expand Down Expand Up @@ -106,7 +106,10 @@ pub enum MouseIndex {

pub enum TickTask {
NewExternalProcess(ExternalProcessRequest), // Call WayVRCompositor::add_client after receiving this message
NewDisplay(packet_client::WvrDisplayCreateParams),
NewDisplay(
packet_client::WvrDisplayCreateParams,
Option<display::DisplayHandle>, /* existing handle? */
),
}

impl WayVR {
Expand Down
3 changes: 3 additions & 0 deletions src/backend/wayvr/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::gen_id;

use super::display;

#[derive(Debug)]
pub struct WayVRProcess {
pub auth_key: String,
pub child: std::process::Child,
Expand All @@ -14,11 +15,13 @@ pub struct WayVRProcess {
pub env: Vec<(String, String)>,
}

#[derive(Debug)]
pub struct ExternalProcess {
pub pid: u32,
pub display_handle: display::DisplayHandle,
}

#[derive(Debug)]
pub enum Process {
Managed(WayVRProcess), // Process spawned by WayVR
External(ExternalProcess), // External process not directly controlled by us
Expand Down
7 changes: 4 additions & 3 deletions src/backend/wayvr/server_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ impl Connection {
false,
)?;

params
.tasks
.push(TickTask::NewDisplay(packet_params.clone()));
params.tasks.push(TickTask::NewDisplay(
packet_params.clone(),
Some(display_handle),
));

send_packet(
&mut self.conn,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/wayvr/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use smithay::wayland::shell::xdg::ToplevelSurface;

use crate::gen_id;

#[derive(Debug)]
pub struct Window {
pub pos_x: i32,
pub pos_y: i32,
Expand Down Expand Up @@ -38,6 +39,7 @@ impl Window {
}
}

#[derive(Debug)]
pub struct WindowManager {
pub windows: WindowVec,
}
Expand Down
17 changes: 10 additions & 7 deletions src/overlays/wayvr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,22 @@ where
});
}
}
wayvr::TickTask::NewDisplay(cpar) => {
wayvr::TickTask::NewDisplay(cpar, disp_handle) => {
log::info!("Creating new display with name \"{}\"", cpar.name);

let mut wayvr = r_wayvr.borrow_mut();

let unique_name = wayvr.get_unique_display_name(cpar.name);

let disp_handle = wayvr.data.state.create_display(
cpar.width,
cpar.height,
&unique_name,
false,
)?;
let disp_handle = match disp_handle {
Some(d) => d,
None => wayvr.data.state.create_display(
cpar.width,
cpar.height,
&unique_name,
false,
)?,
};

wayvr.overlays_to_create.push(OverlayToCreate {
disp_handle,
Expand Down

0 comments on commit ff15010

Please sign in to comment.