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

Dynamically update the greeter text #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mjkloeckner
Copy link

@mjkloeckner mjkloeckner commented May 20, 2023

Closes #234

Description

Adds new flag: --greeter-cmd, which accepts a command name to execute and set the output as the greeter text.

This new flag conflicts with --greeter-text because the output from the command overrides the variable containing the greeter text passed with --greeter-text, so they can't be used together.

If the indicator is idle, the greeter gets updated every second, if the user is typing, the greeter gets updated at every key press, this could lead to performance issues?

Alternative

The function that updates the greeter text executes the expression passed by --greeter-cmd this can lead to erratic behavior if the user isn't careful enough, for example if the user passes the i3lock invocation script as the argument it can lead to a fork bomb.

void update_greeter_text() {
    FILE *fp;
    static char file_text[128];

    memset(file_text,0,sizeof(file_text));

    DEBUG("greeter_cmd is: [%s]\n", greeter_cmd);
    if((fp = popen(greeter_cmd, "r")) == NULL)
        return;

    fread(file_text, sizeof(char), sizeof(file_text), fp);
    pclose(fp);

    greeter_text = file_text;
}

An alternative implementation of this function would be using a temporary file for example /tmp/i3lock-greeter-text and updating the greeter text based on the contents of this file. Maybe this would be a better solution?

Screenshots/screencaps

In this example I plug the power cord and the battery icon updates:

dynamic-greeter

In the screencap I invoke i3lock with these flags:

$ i3lock -c 00000000 --wrong-text="" --lock-text="" --lockfailed-text="" \
        --verif-text="" --verif-text="" --noinput-text="" \
        -i $HOME/.cache/wall_dimblur.png \
        -M --pointer default -k \
        --time-str="%H:%M" --time-size=110 \
        --time-font="Segoe UI Variable Static Display:style=Semibold" \
        --time-pos="ix:iy - 142" --time-color="FFFFFFCC" \
        --date-str="%A, %B %d" --date-size=26 \
        --date-font="Segoe UI Variable Static Display:style=Semibold" \
        --date-pos="tx:ty + 35 + 1" --date-color="FFFFFFCC" \
        --bar-indicator --bar-direction 2 --bar-color 00000000 --bar-pos "h" \
        --bar-step 6 --bar-max-height 6 --bar-periodic-step 6 \
        --keyhl-color="736654CC" -e -n \
        --greeter-pos="tx:ty + 70" \
        --greeter-color="FFFFFFCC" --greeter-font="CaskaydiaCove Nerd Font" \
        --greeter-size=20 --greeter-cmd="lockscreen-greeter"

Being lockscreen-greeter a script which contains:

#!/bin/sh

battery=$(battery-percentage-nerd-font)
kbmap=$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')

printf "%s 󰇙 󰌌 %s" "$battery" "$kbmap"

Release notes

Notes: no-notes.

Adds new flag: `--greeter-cmd`, which accepts a command name to execute
and sets the output to the greeter text. If the screen is idle, the
command gets executed every second, if the user is typing the command
gets executed in every keypress.

This new flag conflicts with `--greeter-text` because when the output
from the command gets captured it overrides the variable containing the
greeter text passed with `--greeter-text`, so they can't be used
together.
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

Successfully merging this pull request may close these issues.

Support displaying custom dynamic text
1 participant