Implement kiosk mode for cosmic-greeter

This commit is contained in:
Jeremy Soller 2024-02-06 09:25:48 -07:00 committed by Victoria Brekenfeld
parent 54f2d2c67e
commit ec822e421f
2 changed files with 65 additions and 20 deletions

View file

@ -59,6 +59,29 @@ unsafe fn set_cloexec(fd: RawFd) -> rustix::io::Result<()> {
rustix::io::fcntl_setfd(fd, flags | rustix::io::FdFlags::CLOEXEC)
}
pub fn get_env(state: &State) -> Result<HashMap<String, String>> {
let mut env = HashMap::new();
env.insert(
String::from("WAYLAND_DISPLAY"),
state
.common
.socket
.clone()
.into_string()
.map_err(|_| anyhow!("wayland socket is no valid utf-8 string?"))?,
);
if let Some(display) = state
.common
.shell
.xwayland_state
.as_ref()
.map(|s| s.display)
{
env.insert(String::from("DISPLAY"), format!(":{}", display));
}
Ok(env)
}
pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
if let Ok(fd_num) = std::env::var("COSMIC_SESSION_SOCK") {
if let Ok(fd) = fd_num.parse::<RawFd>() {
@ -72,25 +95,7 @@ pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
}
};
let mut env = HashMap::new();
env.insert(
String::from("WAYLAND_DISPLAY"),
state
.common
.socket
.clone()
.into_string()
.map_err(|_| anyhow!("wayland socket is no valid utf-8 string?"))?,
);
if let Some(display) = state
.common
.shell
.xwayland_state
.as_ref()
.map(|s| s.display)
{
env.insert(String::from("DISPLAY"), format!(":{}", display));
}
let env = get_env(state)?;
let message = serde_json::to_string(&Message::SetEnv { variables: env })
.with_context(|| "Failed to encode environment variables into json")?;
let bytes = message.into_bytes();