Update smithay

This commit is contained in:
Ian Douglas Scott 2024-04-24 09:34:46 -07:00 committed by Victoria Brekenfeld
parent a9740e5040
commit 73b12194c0
19 changed files with 202 additions and 137 deletions

View file

@ -19,7 +19,7 @@ use std::{
};
use tracing::{error, warn};
use crate::state::{ClientState, State};
use crate::state::{ClientState, Common, State};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "message")]
@ -59,24 +59,23 @@ 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>> {
pub fn get_env(common: &Common) -> Result<HashMap<String, String>> {
let mut env = HashMap::new();
env.insert(
String::from("WAYLAND_DISPLAY"),
state
.common
common
.socket
.clone()
.into_string()
.map_err(|_| anyhow!("wayland socket is no valid utf-8 string?"))?,
);
if let Some(display) = state.common.xwayland_state.as_ref().map(|s| s.display) {
if let Some(display) = common.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<()> {
pub fn setup_socket(handle: LoopHandle<State>, common: &Common) -> Result<()> {
if let Ok(fd_num) = std::env::var("COSMIC_SESSION_SOCK") {
if let Ok(fd) = fd_num.parse::<RawFd>() {
let mut session_socket = match unsafe { set_cloexec(fd) } {
@ -89,7 +88,7 @@ pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
}
};
let env = get_env(state)?;
let env = get_env(common)?;
let message = serde_json::to_string(&Message::SetEnv { variables: env })
.with_context(|| "Failed to encode environment variables into json")?;
let bytes = message.into_bytes();