Skip to content

Commit 38ac185

Browse files
hoshinolinaslp
authored andcommitted
x11: Use muvm-x11bridge instead of x112virtgpu
Signed-off-by: Asahi Lina <[email protected]>
1 parent e474781 commit 38ac185

5 files changed

Lines changed: 21 additions & 15 deletions

File tree

crates/muvm/src/bin/muvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ fn main() -> Result<()> {
382382
);
383383
env.insert("MUVM_SERVER_COOKIE".to_owned(), cookie.to_string());
384384

385+
#[cfg(x11bridge)]
385386
if options.direct_x11 {
386387
let display =
387388
env::var("DISPLAY").context("X11 forwarding requested but DISPLAY is unset")?;

crates/muvm/src/cli_options.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ pub fn options() -> OptionParser<Options> {
111111
.help("Use direct X11 forwarding instead of sommelier + XWayland")
112112
.switch();
113113

114+
#[cfg(not(feature = "x11bridge"))]
115+
let direct_x11 = direct_x11
116+
.guard(
117+
|x| !*x,
118+
"--direct-x11 requires the `x11bridge` crate feature",
119+
)
120+
.hide();
121+
114122
let command = positional("COMMAND").help("the command you want to execute in the vm");
115123
let command_args = any::<String, _, _>("COMMAND_ARGS", |arg| {
116124
(!["--help", "-h"].contains(&&*arg)).then_some(arg)

crates/muvm/src/guest/bin/muvm-guest.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use muvm::guest::net::configure_network;
1212
use muvm::guest::socket::setup_socket_proxy;
1313
use muvm::guest::sommelier::exec_sommelier;
1414
use muvm::guest::user::setup_user;
15+
#[cfg(feature = "x11bridge")]
1516
use muvm::guest::x11::setup_x11_forwarding;
1617
use muvm::utils::env::find_in_path;
1718
use rustix::process::{getrlimit, setrlimit, Resource};
@@ -79,7 +80,12 @@ fn main() -> Result<()> {
7980
let pulse_path = pulse_path.join("native");
8081
setup_socket_proxy(pulse_path, 3333)?;
8182

82-
if !setup_x11_forwarding(run_path)? {
83+
#[cfg(feature = "x11bridge")]
84+
let direct_x11 = setup_x11_forwarding(run_path)?;
85+
#[cfg(not(feature = "x11bridge"))]
86+
let direct_x11 = false;
87+
88+
if !direct_x11 {
8389
// Will not return if successful.
8490
exec_sommelier(&options.command, &options.command_args)
8591
.context("Failed to execute sommelier")?;

crates/muvm/src/guest/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pub mod net;
55
pub mod socket;
66
pub mod sommelier;
77
pub mod user;
8+
#[cfg(feature = "x11bridge")]
89
pub mod x11;

crates/muvm/src/guest/x11.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use std::process::Command;
77
use anyhow::{anyhow, Context, Result};
88
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
99

10-
use super::socket::setup_socket_proxy;
11-
12-
use crate::utils::env::find_in_path;
10+
use crate::env::find_muvm_exec;
1311

1412
pub fn setup_x11_forwarding<P>(run_path: P) -> Result<bool>
1513
where
@@ -26,18 +24,10 @@ where
2624
}
2725
let host_display = &host_display[1..];
2826

29-
let x112virtgpu_path =
30-
find_in_path("x112virtgpu").context("Failed to check existence of `x112virtgpu`")?;
31-
32-
if x112virtgpu_path.is_some() {
33-
let mut cmd = Command::new(x112virtgpu_path.unwrap());
34-
cmd.args(["--listen-display", ":1"]);
27+
let mut cmd = Command::new(find_muvm_exec("muvm-x11bridge")?);
28+
cmd.args(["--listen-display", ":1"]);
3529

36-
cmd.spawn().context("Failed to spawn `x112virtgpu`")?;
37-
} else {
38-
log::error!("x112virtgpu not available, X11 forwarding will operate in socket forwarding mode. This is probably not what you want.");
39-
setup_socket_proxy(Path::new("/tmp/.X11-unix/X1"), 6000)?;
40-
}
30+
cmd.spawn().context("Failed to spawn `muvm-x11bridge`")?;
4131

4232
// SAFETY: Safe if and only if `muvm-guest` program is not multithreaded.
4333
// See https://doc.rust-lang.org/std/env/fn.set_var.html#safety

0 commit comments

Comments
 (0)