Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check config file if ~/.xinitrc doesn't exist !!! #12

Open
pwnwriter opened this issue Jan 23, 2023 · 1 comment
Open

Check config file if ~/.xinitrc doesn't exist !!! #12

pwnwriter opened this issue Jan 23, 2023 · 1 comment

Comments

@pwnwriter
Copy link

Hi, Most of the people these days add xinitrc in .config, tried to make it work with the following changes. If it works for you too, let me know; will create a PR anyways.

use std::env;
use std::fs;

use crate::error::Error;

pub fn de() -> Result<String, Error> {
    Ok(env::var("XDG_DESKTOP_SESSION")
        .or_else(|_| env::var("XDG_CURRENT_DESKTOP"))
        .or_else(|_| env::var("DESKTOP_SESSION"))
        .unwrap_or_else(|_| "N/A".to_string()))
}

pub fn wm() -> Result<String, Error> {
    let home_dir = env::var("HOME").unwrap();
    let path = format!("{}/.xinitrc", home_dir);
    let file = match fs::File::open(&path) {
        Ok(file) => file,
        Err(_) => {
            let config_path = format!("{}/.config/x11/xinitrc", home_dir);
            match fs::File::open(config_path) {
                Ok(file) => file,
                Err(_) => return Err(Error::new("File not found")),
            }
        }
    };

    let contents = crate::shared_functions::read(file)?;
    let line = contents.lines().last().unwrap();
    Ok(line.split(' ').last().unwrap().to_string())
}
@MathGeniusJodie
Copy link

I've found that just looking at the running processes for known wms is much more reliable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants