main: fix kiosk command with command line options

We were just running whatever was given on the command line as the
kiosk command, which meant that if --no-xwayland was given, we'd try
execing --no-xwayland.  Preserve the processed command line from the
option parser, and run only what's left over as the kiosk command to
fix this.
This commit is contained in:
Alyssa Ross 2026-07-10 19:44:16 +02:00 committed by Victoria Brekenfeld
parent 2b360a8dd7
commit 9feaa865ab
2 changed files with 14 additions and 7 deletions

View file

@ -81,11 +81,8 @@ impl State {
warn!(?err, "Failed to setup cosmic-session communication"); warn!(?err, "Failed to setup cosmic-session communication");
} }
let mut args = env::args().skip(1); self.common.kiosk_child = if let Some(mut command) = self.kiosk_command.take() {
self.common.kiosk_child = if let Some(exec) = args.next() {
// Run command in kiosk mode // Run command in kiosk mode
let mut command = process::Command::new(&exec);
command.args(args);
command.envs( command.envs(
session::get_env(&self.common).expect("WAYLAND_DISPLAY should be valid UTF-8"), session::get_env(&self.common).expect("WAYLAND_DISPLAY should be valid UTF-8"),
); );
@ -96,7 +93,7 @@ impl State {
}) })
}; };
info!("Running {:?}", exec); info!("Running {:?}", command.get_program());
command command
.spawn() .spawn()
.map_err(|err| { .map_err(|err| {
@ -115,8 +112,10 @@ impl State {
pub fn run(hooks: crate::hooks::Hooks) -> Result<(), Box<dyn Error>> { pub fn run(hooks: crate::hooks::Hooks) -> Result<(), Box<dyn Error>> {
let raw_args = RawArgs::from_args(); let raw_args = RawArgs::from_args();
let mut cursor = raw_args.cursor(); let mut cursor = raw_args.cursor();
raw_args.next_os(&mut cursor);
let git_hash = option_env!("GIT_HASH").unwrap_or("unknown"); let git_hash = option_env!("GIT_HASH").unwrap_or("unknown");
let mut kiosk_command = None;
let mut with_xwayland = true; let mut with_xwayland = true;
// Parse the arguments // Parse the arguments
while let Some(arg) = raw_args.next_os(&mut cursor) { while let Some(arg) = raw_args.next_os(&mut cursor) {
@ -137,7 +136,11 @@ pub fn run(hooks: crate::hooks::Hooks) -> Result<(), Box<dyn Error>> {
); );
return Ok(()); return Ok(());
} }
_ => {} _ => {
let mut cmd = process::Command::new(arg);
cmd.args(raw_args.remaining(&mut cursor));
kiosk_command = Some(cmd);
}
} }
} }
@ -171,6 +174,7 @@ pub fn run(hooks: crate::hooks::Hooks) -> Result<(), Box<dyn Error>> {
event_loop.handle(), event_loop.handle(),
event_loop.get_signal(), event_loop.get_signal(),
with_xwayland, with_xwayland,
kiosk_command,
); );
// init backend // init backend
backend::init_backend_auto(&display, &mut event_loop, &mut state)?; backend::init_backend_auto(&display, &mut event_loop, &mut state)?;

View file

@ -127,7 +127,7 @@ use std::{
cmp::min, cmp::min,
collections::HashSet, collections::HashSet,
ffi::OsString, ffi::OsString,
process::Child, process::{Child, Command},
sync::{Arc, LazyLock, Once, atomic::AtomicBool}, sync::{Arc, LazyLock, Once, atomic::AtomicBool},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -225,6 +225,7 @@ pub struct State {
pub common: Common, pub common: Common,
pub ready: Once, pub ready: Once,
pub last_refresh: LastRefresh, pub last_refresh: LastRefresh,
pub kiosk_command: Option<Command>,
} }
smithay::delegate_dispatch2!(State); smithay::delegate_dispatch2!(State);
@ -633,6 +634,7 @@ impl State {
handle: LoopHandle<'static, State>, handle: LoopHandle<'static, State>,
signal: LoopSignal, signal: LoopSignal,
with_xwayland: bool, with_xwayland: bool,
kiosk_command: Option<Command>,
) -> State { ) -> State {
let requested_languages = DesktopLanguageRequester::requested_languages(); let requested_languages = DesktopLanguageRequester::requested_languages();
i18n_embed::select(&*LANG_LOADER, &Localizations, &requested_languages) i18n_embed::select(&*LANG_LOADER, &Localizations, &requested_languages)
@ -810,6 +812,7 @@ impl State {
backend: BackendData::Unset, backend: BackendData::Unset,
ready: Once::new(), ready: Once::new(),
last_refresh: LastRefresh::None, last_refresh: LastRefresh::None,
kiosk_command,
} }
} }