apognu / tuigreet

Graphical console greeter for greetd
GNU General Public License v3.0
911 stars 41 forks source link

[Feature Request] Autologin #118

Open DarkDefender opened 9 months ago

DarkDefender commented 9 months ago

The issue is as follows: Greetd does already provide "initial_session" support, but it is very limited. For example it only supports hard coding in a username a command to run. This means that what ever the last user or login command was from tuigreet is not taken into account.

Previously I solved this is a hacky way by patching greetd to be able to read files. So the "initial_session" section would look something like this:

[initial_session]
user_file = /var/cache/tuigreet/lastuser
command_file = /var/cache/tuigreet/lastsession

However this doesn't work anymore as tuigreet has moved on to a better system of storing the last session data. (So that when using .desktop files to login, the command is now always up to date)

So I was thinking, perhaps a better way of doing it would be to either:

  1. Introduce a new API in greetd that could query the login client for the last user and what command to execute to login. In addition to that, it could also perhaps query if it should auto login in the first place (perhaps the user has unticked the "autologin" in the greeter interface).

  2. Make the initial_session section be able to execute commands to query the user/commands to use:

    [initial_session]
    user = 'cat /var/cache/tuigreet/lastuser'
    command = 'tuigreet --print-last-session-command`

I realize that this is more of a greetd, topic. But I wanted to start here as I think asking the developer of the greeter that I use might be a good start.

Note that I personally think that there probably needs to be some sort of hand off between greetd and the greeter as the current initial_session functionality is not that great as it skips setting environmental variables that for example tuigreet sets when logging in with Xorg/Wayland sessions.

DarkDefender commented 9 months ago

I've implemented a proof of concept where I added a new IPC command that can be used for autologin. https://github.com/DarkDefender/greetd/tree/autologin https://github.com/DarkDefender/tuigreet/tree/autologin

I'll add an option to disable this on the greetd side of things so if it is configured to not allow autologins, then it will return an error if you call this command. I will also hook up some logic so that we can only autologin once. (So we won't get logged in when you try to logout).

Does this seem like it is going in the right direction?

DarkDefender commented 9 months ago

I've updated my fork to now only allow using the autologin once per boot and the feature is now disabled per default. To me, it is now feature complete.

DarkDefender commented 8 months ago

@apognu do you have any thoughts about the code changes?

bb010g commented 4 months ago

This feature would be useful for feature parity with non-greetd display managers in NixOS (see the services.displayManager.autoLogin option and services.displayManager.sessionData.autologinSession config value).