~kennylevinsen/greetd-devel

greetd: greetd: add terminal switch flag configuration option v4 APPLIED

muradm: 1
 greetd: add terminal switch flag configuration option

 4 files changed, 58 insertions(+), 11 deletions(-)
#567967 alpine.yml success
#567968 archlinux.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/24441/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH greetd v4] greetd: add terminal switch flag configuration option Export this patch

This adds "switch" true/false flag in "terminal" section of
configuration file.

Flags controls wether terminal under control should be switched to
when greetd starts. If "switch" set to true, greetd behaves as it
was before, on start vt_setactivate will be called. If "switch" set
to false, and terminal under control for greetd is not currently
active VT, greetd will wait for terminal to become active with
vt_waitactive, which translates to VT_WAITACTIVE ioctl call.

* greetd/src/config/mod.rs: add "switch" flag
* greetd/src/server.rs: add using "switch" flag and waiting for active
* greetd/src/terminal/mod.rs: add vt_waitactive method
* man/greetd-5.scd: mention "switch" configuration option
---
 greetd/src/config/mod.rs   | 32 +++++++++++++++++++++++---------
 greetd/src/server.rs       | 19 +++++++++++++++++--
 greetd/src/terminal/mod.rs |  8 ++++++++
 man/greetd-5.scd           | 10 ++++++++++
 4 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/greetd/src/config/mod.rs b/greetd/src/config/mod.rs
index 5f2d537..6c59c93 100644
--- a/greetd/src/config/mod.rs
+++ b/greetd/src/config/mod.rs
@@ -35,6 +35,7 @@ pub struct ConfigInternal {
#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigTerminal {
    pub vt: VtSelection,
    pub switch: bool,
}

#[derive(Debug, Eq, PartialEq)]
@@ -104,7 +105,7 @@ fn parse_old_config(config: &HashMap<&str, HashMap<&str, &str>>) -> Result<Confi
    };

    Ok(ConfigFile {
        terminal: ConfigTerminal { vt },
        terminal: ConfigTerminal { vt, switch: true },
        default_session: ConfigSession {
            user: greeter_user,
            command: greeter,
@@ -165,6 +166,11 @@ fn parse_new_config(config: &HashMap<&str, HashMap<&str, &str>>) -> Result<Confi
                        .map_err(|e| format!("could not parse vt number: {}", e))?,
                ),
            },
            switch: section
                .get("switch")
                .unwrap_or(&"true")
                .parse()
                .map_err(|e| format!("could not parse switch: {}", e))?,
        }),
        None => Err("no terminal specified"),
    }?;
@@ -300,7 +306,8 @@ greeter_user = \"greeter\"
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Specific(1)
                    vt: VtSelection::Specific(1),
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -322,7 +329,8 @@ greeter = \"agreety\"
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Next
                    vt: VtSelection::Next,
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -349,7 +357,8 @@ command = \"agreety\"
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Specific(1)
                    vt: VtSelection::Specific(1),
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -376,7 +385,8 @@ user = \"john\"
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Specific(1)
                    vt: VtSelection::Specific(1),
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -406,7 +416,8 @@ runfile = \"/path/to/greetd.state\"
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Specific(1)
                    vt: VtSelection::Specific(1),
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -447,7 +458,8 @@ vt = 1
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Specific(1)
                    vt: VtSelection::Specific(1),
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -469,7 +481,8 @@ vt = next
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Next
                    vt: VtSelection::Next,
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
@@ -491,7 +504,8 @@ vt = current
            config,
            ConfigFile {
                terminal: ConfigTerminal {
                    vt: VtSelection::Current
                    vt: VtSelection::Current,
                    switch: true,
                },
                default_session: ConfigSession {
                    command: "agreety".to_string(),
diff --git a/greetd/src/server.rs b/greetd/src/server.rs
index 0a1994b..9dab635 100644
--- a/greetd/src/server.rs
+++ b/greetd/src/server.rs
@@ -31,6 +31,17 @@ fn reset_vt(term_mode: &TerminalMode) -> Result<(), Error> {
    Ok(())
}

fn wait_vt(term_mode: &TerminalMode) -> Result<(), Error> {
    match term_mode {
        TerminalMode::Terminal { path, vt, .. } => {
            let term = Terminal::open(path)?;
            term.vt_waitactive(*vt)?;
        }
        TerminalMode::Stdin => (),
    }
    Ok(())
}

fn wrap_result<T>(res: Result<T, Error>) -> Response {
    match res {
        Ok(_) => Response::Success,
@@ -145,14 +156,14 @@ fn get_tty(config: &Config) -> Result<TerminalMode, Error> {
            TerminalMode::Terminal {
                path: format!("/dev/tty{}", vt),
                vt,
                switch: true,
                switch: config.file.terminal.switch,
            }
        }
        VtSelection::None => TerminalMode::Stdin,
        VtSelection::Specific(vt) => TerminalMode::Terminal {
            path: format!("/dev/tty{}", vt),
            vt,
            switch: true,
            switch: config.file.terminal.switch,
        },
    };
    return Ok(term);
@@ -215,6 +226,10 @@ pub async fn main(config: Config) -> Result<(), Error> {

    let term_mode = get_tty(&config)?;

    if !config.file.terminal.switch {
        wait_vt(&term_mode).map_err(|e| format!("unable to wait VT: {}", e))?;
    }

    let ctx = Rc::new(Context::new(
        config.file.default_session.command,
        config.file.default_session.user,
diff --git a/greetd/src/terminal/mod.rs b/greetd/src/terminal/mod.rs
index 1da4904..987f6cc 100644
--- a/greetd/src/terminal/mod.rs
+++ b/greetd/src/terminal/mod.rs
@@ -111,6 +111,14 @@ impl Terminal {
        Ok(())
    }

    /// Waits for specified VT to become active.
    pub fn vt_waitactive(&self, target_vt: usize) -> Result<(), Error> {
        if let Err(v) = unsafe { ioctl::vt_waitactive(self.fd, target_vt as i32) } {
            return Err(format!("terminal: unable to wait for activation: {}", v).into());
        }
        Ok(())
    }

    /// Set the VT mode to VT_AUTO with everything cleared.
    fn vt_mode_clean(&self) -> Result<(), Error> {
        let mode = ioctl::vt_mode {
diff --git a/man/greetd-5.scd b/man/greetd-5.scd
index eaf5c8d..6971842 100644
--- a/man/greetd-5.scd
+++ b/man/greetd-5.scd
@@ -37,6 +37,16 @@ This section contains terminal configuration.

	Use of a specific VT with appropriate conflict avoidance is recommended.

*switch* = true|false
	Whether or not to switch to *vt*.

	If set to false and *vt* is not currently active VT, greetd will wait for
	*vt* to become active, before doing anything including starting greeter.

	If set to true, greetd will switch current VT to *vt*,

	Default is true.

## general

This section contains general configuration that does not fit in other sections
-- 
2.32.0