~cassaundra/layerizer

28271113679cfe81a7485cf060b103825ee881b2 — cassaundra 1 year, 8 months ago 366b2bd
cargo fmt with default line length
4 files changed, 12 insertions(+), 37 deletions(-)

D rustfmt.toml
M src/config.rs
M src/main.rs
M src/x11.rs
D rustfmt.toml => rustfmt.toml +0 -1
@@ 1,1 0,0 @@
max_width=80
\ No newline at end of file

M src/config.rs => src/config.rs +1 -3
@@ 51,9 51,7 @@ impl Rule {
    }
}

fn deserialize_pattern<'de, D>(
    deserializer: D,
) -> Result<Option<Pattern<String>>, D::Error>
fn deserialize_pattern<'de, D>(deserializer: D) -> Result<Option<Pattern<String>>, D::Error>
where
    D: Deserializer<'de>,
{

M src/main.rs => src/main.rs +9 -26
@@ 29,8 29,7 @@ struct App {
impl App {
    pub fn from_config(config: Config) -> anyhow::Result<Self> {
        // connect to the keyboard device via HIDAPI
        let mut hidapi =
            hidapi::HidApi::new().context("Failed to initialize HIDAPI")?;
        let mut hidapi = hidapi::HidApi::new().context("Failed to initialize HIDAPI")?;
        let device = find_device(&mut hidapi, &config.device_info)?
            .context("Failed to find specified device")?;



@@ 55,10 54,7 @@ impl App {
            let event = match self.connection.wait_for_event() {
                Ok(event) => event,
                Err(err) => {
                    eprintln!(
                        "warning: error occurred on window event: {:?}",
                        err
                    );
                    eprintln!("warning: error occurred on window event: {:?}", err);
                    continue;
                }
            };


@@ 78,10 74,7 @@ impl App {
        // check to see if this window matches a rule
        let window_info = get_window_info(&self.connection, window)?;

        fn pattern_matches(
            pat: &Option<Pattern<String>>,
            val: Option<&str>,
        ) -> bool {
        fn pattern_matches(pat: &Option<Pattern<String>>, val: Option<&str>) -> bool {
            match pat {
                Some(p) => val.map(|v| p.matches(v)).unwrap_or(false),
                _ => true,


@@ 91,17 84,10 @@ impl App {
        let mut matched_rule = false;
        for rule in &self.config.rules {
            if pattern_matches(&rule.class, Some(&window_info.class))
                && pattern_matches(
                    &rule.class_name,
                    Some(&window_info.class_name),
                )
                && pattern_matches(&rule.class_name, Some(&window_info.class_name))
                && pattern_matches(&rule.name, window_info.name.as_deref())
            {
                switch_to_layer(
                    &self.device,
                    rule.layer,
                    rule.protected_layer_mask(),
                )?;
                switch_to_layer(&self.device, rule.layer, rule.protected_layer_mask())?;
                matched_rule = true;
                break;
            }


@@ 128,9 114,7 @@ impl App {
            // try to reconnect
            match err.downcast_ref::<HidError>() {
                Some(_) => {
                    if let Some(device) =
                        find_device(&mut self.hidapi, &self.config.device_info)?
                    {
                    if let Some(device) = find_device(&mut self.hidapi, &self.config.device_info)? {
                        self.device = device;
                    }
                }


@@ 145,6 129,7 @@ impl App {
fn main() -> anyhow::Result<()> {
    let matches = clap::Command::new("layerizer")
        .setting(clap::AppSettings::ColorNever)
        .setting(clap::AppSettings::DeriveDisplayOrder)
        .arg(
            clap::Arg::new("config")
                .help("Path to a configuration file")


@@ 163,10 148,8 @@ fn main() -> anyhow::Result<()> {
                .join("config.toml"),
        };

        let raw = fs::read_to_string(config_path)
            .context("Failed to read configuration file")?;
        let parsed = toml::from_str(&raw)
            .context("Failed to parse configuration file")?;
        let raw = fs::read_to_string(config_path).context("Failed to read configuration file")?;
        let parsed = toml::from_str(&raw).context("Failed to parse configuration file")?;
        parsed
    };


M src/x11.rs => src/x11.rs +2 -7
@@ 67,19 67,14 @@ pub fn get_window_info(
}

/// Find the current input focus.
pub fn get_input_focus(
    connection: &xcb::Connection,
) -> anyhow::Result<x::Window> {
pub fn get_input_focus(connection: &xcb::Connection) -> anyhow::Result<x::Window> {
    let cookie = connection.send_request(&x::GetInputFocus {});
    let reply = connection.wait_for_reply(cookie)?;
    Ok(reply.focus())
}

/// Start listening to focus change events from a window.
pub fn listen_to_window(
    connection: &xcb::Connection,
    window: x::Window,
) -> anyhow::Result<()> {
pub fn listen_to_window(connection: &xcb::Connection, window: x::Window) -> anyhow::Result<()> {
    let cookie = connection.send_request_checked(&x::ChangeWindowAttributes {
        window,
        value_list: &WINDOW_ATTRIBUTES,