7

I want to use logind for power management. After 30 minutes of inactivity, I would like the computer to suspend.

Problem is, right now, it suspends after 30 minutes, even when I am active with mouse and keyboard. My logind.conf:

[Login]
HandlePowerKey=suspend
IdleAction=suspend
IdleActionSec=30min

My Ubuntu 15.04 setup is very minimal, and I would like to keep it that way. I login at the console (I don't want a session manager) and then type startx, which launches my ~/.xinitrc that executes i3, my preferred window manager. I do not want to use a desktop environment.

I want the computer to suspend and lock after a given amount of time.

So, my ~/.config/i3/config file includes:

exec "xss-lock -- i3lock -c 000000"

The screen locker works fine, and integrates fine. So no problems there.

In case it is of interest:

loginctl show-seat -p IdleHint

Yields:

IdleHint=yes

Seems like that should be "no" if I am active, right?

And if I do this:

gdbus call --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1/session/c1 --method org.freedesktop.login1.Session.SetIdleHint false

or this:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1/session/c1 "org.freedesktop.login1.Session.SetIdleHint" boolean:false

Reading IdleHint still outputs "IdleHint=yes"!

So what am I missing? How do I keep systemd-logind from suspending while I am active, without using a session manager or desktop environment?

I know that I could use lxqt-powermanagement, for instance, but I think I am correct in assuming this is unnecessary. Of course I can change my personal preferences regarding desktop environment, and will if necessary. This problem seems solvable, though.

5

Sadly, the lack of answers may mean that there isn't one. Happy to be wrong, though!

For those who may be researching the same thing, I finally caved in and am using a session manager. Specifically, sddm. Everything seems to be working fine, now, and the session manager really isn't too bloated and pretty much stays out of the way.

1

When I do

dbus-send --system --print-reply \
  --dest=org.freedesktop.login1 /org/freedesktop/login1/session/self \
  "org.freedesktop.login1.Session.SetIdleHint" boolean:false

I get

Error org.freedesktop.DBus.Error.NotSupported: Idle hint control is not supported on non-graphical sessions.

which suggests that the problem is logind thinking the session isn't graphical. Indeed:

$ loginctl show-session --property=Type self
Type=tty

This is why using sddm helps: it sets the session type.

But can we set the session type manually?

org.freedesktop.login1(5) says:

SetType() allows the type of the session to be changed dynamically. It can only be called by session's current controller. If TakeControl() has not been called, this method will fail. In addition, the session type will be reset to its original value once control is released, either by calling ReleaseControl() or closing the D-Bus connection. This should help prevent a session from entering an inconsistent state, for example if the controller crashes. The only argument type is the new session type.

Xorg server becomes the session controller but doesn't set the type, so it's probably not possible to just set it elsewhere (xinitrc, xsession or something like that) as only the session controller can do it.

But there is a somewhat hack-ish way to do it, by setting $XDG_SESSION_TYPE for pam_systemd(8). I tried putting this into /etc/systemd/system/getty@tty10.service.d/override.conf:

[Service]
Environment=XDG_SESSION_TYPE=x11

Now when I log into vt10 and exec startx /etc/X11/Xsession, IdleHint can be updated and is indeed being updated by xss-lock.

To make this a little more robust, my .bash_profile checks $XDG_SESSION_TYPE as well as whether the session is primary (only one session should push its environment variables to the user systemd instance) and starts X, turning vt10 into a very simple desktop manager. :-)

#!bash

if [[ ! $DISPLAY && $XDG_SESSION_TYPE == "x11" ]]; then
        [[ "$(loginctl show-user --property=Display "$USER")" == "Display=$XDG_SESSION_ID" ]] && primary=: || primary=
        journal=(/usr/bin/systemd-cat --priority=info --stderr-priority=warning --level-prefix=false)
        [[ $primary ]] && session=(/etc/X11/xinit/xinitrc) || session=(~/.xsession)

        exec startx "${journal[@]}" "${session[@]}"
        exit 1
fi

. ~/.bashrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.