<NME> keymap_file.rs
<BEF> use crate::utils::sealed_file::SealedFile;
use slog::error;
    fs::File,
    io::{Seek, Write},
    os::unix::prelude::{AsRawFd, FromRawFd, RawFd},
    path::PathBuf,
};

use nix::{
#[derive(Debug)]
pub struct KeymapFile {
    sealed: Option<SealedFile>,
use slog::error;

#[derive(Debug)]
pub(crate) struct KeymapFile {
    #[allow(dead_code)]
    sealed: Option<SealedFile>,
    keymap: CString,
}
    {
        let logger = crate::slog_or_fallback(logger);
        let name = CString::new("smithay-keymap").unwrap();
        let keymap = keymap.get_as_string(KEYMAP_FORMAT_TEXT_V1);
        let sealed = SealedFile::new(name, CString::new(keymap.as_str()).unwrap());

        if let Err(err) = sealed.as_ref() {
            error!(logger, "Error when creating sealed keymap file: {}", err);
        }

        Self {
            sealed: sealed.ok(),
            keymap,
        }
    }

    #[cfg(feature = "wayland_frontend")]
    where
        F: FnOnce(RawFd, usize),
    {
        if let Some(file) = supports_sealed.then(|| self.sealed.as_ref()).flatten() {
            cb(file.as_raw_fd(), file.size);
            Ok(())
        if let Err(err) = sealed.as_ref() {
            error!(logger, "Error when creating sealed keymap file: {}", err);
        }

        self.sealed = sealed.ok();
        self.keymap = keymap;
    }

    #[cfg(feature = "wayland_frontend")]
    /// Run a closure with the file descriptor to ensure safety
    pub fn with_fd<F>(&self, supports_sealed: bool, cb: F) -> Result<(), std::io::Error>
    where
        F: FnOnce(RawFd, usize),
    {
        use std::{io::Write, os::unix::prelude::AsRawFd, path::PathBuf};

        if let Some(file) = supports_sealed.then(|| self.sealed.as_ref()).flatten() {
            cb(file.as_raw_fd(), file.size());
        } else {
            let dir = std::env::var_os("XDG_RUNTIME_DIR")
                .map(PathBuf::from)
                .unwrap_or_else(std::env::temp_dir);

            let mut file = tempfile::tempfile_in(dir)?;
            file.write_all(self.keymap.as_bytes())?;
            file.flush()?;

            cb(file.as_raw_fd(), self.keymap.len());
        }
        Ok(())
    }

    /// Send the keymap contained within to a WlKeyboard
    pub fn send(
        &self,
        keyboard: &wayland_server::protocol::wl_keyboard::WlKeyboard,
    ) -> Result<(), std::io::Error> {
        use wayland_server::{protocol::wl_keyboard::KeymapFormat, Resource};

        self.with_fd(keyboard.version() >= 7, |fd, size| {
            keyboard.keymap(KeymapFormat::XkbV1, fd, size as u32);
        })
    }
}

<MSG> input: Fix warnings without wayland feature

<DFF> @@ -3,7 +3,6 @@ use std::{
     fs::File,
     io::{Seek, Write},
     os::unix::prelude::{AsRawFd, FromRawFd, RawFd},
-    path::PathBuf,
 };
 
 use nix::{
@@ -13,8 +12,8 @@ use nix::{
 use slog::error;
 
 #[derive(Debug)]
+#[allow(dead_code)]
 pub(crate) struct KeymapFile {
-    #[allow(dead_code)]
     sealed: Option<SealedFile>,
     keymap: CString,
 }
@@ -38,6 +37,8 @@ impl KeymapFile {
     where
         F: FnOnce(RawFd, usize),
     {
+        use std::path::PathBuf;
+
         if let Some(file) = supports_sealed.then(|| self.sealed.as_ref()).flatten() {
             cb(file.as_raw_fd(), file.size);
             Ok(())

input: Fix warnings without wayland feature