28 05 | 2014

GNU/Linux graphic sessions: allowing computer suspend and disabling a monitor

Written by Tanguy

Classified in : Homepage, Debian, Command line, To remember

Allowing computer suspend

Major desktop environments such as Xfce or KDE have a built-in computer suspend feature, but when you use a lighter alternative, things are a bit more complicated, because basically: only root can suspend the computer. Possible solutions include:

  • using sudo to allow members of a given group to run a suspend command, e.g. pm-suspend as root;
  • using a D-Bus UPower thingy, which communicates with a running daemon upowerd:
    $ dbus-send --system --print-reply \
                --dest='org.freedesktop.UPower' \
                /org/freedesktop/UPower org.freedesktop.UPower.Suspend
            

With recent updates of the related Debian packages — no idea of which one exactly — the latter solution may not work any more, in which case it will only return the following error:

Error org.freedesktop.UPower.GeneralError: not authorized

It appears that this error is linked to ConsoleKit, a part of all this modern *Kit gizmo pile. If you are in this case, try prefixing your session launcher with the undocumented dark magic call ck-launch-session. For instance, this is what I have in my .xsession to launch my window manager i3:

exec ck-launch-session i3

Note: I do not know what ck-launch-session does exactly, why it is needed, and I do not want to know. To me, all that WhatsitKit pile is just some opaque, under-documented — as in: no man page — crap, that no one but their author really understand, designed to solve theoretical problems no one really cares about — like: how to allow locally connected users to use the sound card while forbidding it to remote users — while creating new issues such as this one. This stuff is too complex and under-documented for me to dive into it, so if it does not work out of the box, it is just some crap that gets in my way to using my computer as I wish.

Disabling a monitor

In some configurations, you have two monitors and want to disable one. For instance, in addition to my LCD monitor, I have a projector which I only use for movies. According to xorg.conf's man page, it can be disabled this way:

Section "Device"
    Identifier  "Internal graphic card"
    Option      "Monitor-DVI"   "LCD Monitor"
    Option      "Monitor-VGA"   "Projector"
EndSection

Section "Monitor"
    Identifier  "LCD Monitor"
EndSection

Section "Monitor"
    Identifier  "Projector"
    Option      "Enable"    "false"
EndSection

Except that does not work, because contrary to what the man page says the real option to use is not Enable but Disable! So here is the correct configuration to disable that monitor at start-up:

Section "Device"
    Identifier  "Internal graphic card"
    Option      "Monitor-DVI"   "LCD Monitor"
    Option      "Monitor-VGA"   "Projector"
EndSection

Section "Monitor"
    Identifier  "LCD Monitor"
EndSection

Section "Monitor"
    Identifier  "Projector"
    Option      "Disable"   "true"
EndSection

Note: yes, I will send a bug report with a patch against xorg.conf's man page.

7 comments

wednesday 28 may 2014 à 14:04 hugo said : #1

ConsoleKit is not longer maintained and many people consider it deprecated. It is (or will be) replaced by logind, at least on systems using systemd.

wednesday 28 may 2014 à 14:15 Tanguy said : #2

@hugo : Great, one piece of complex crap replaced by another one. systemd being persona non-grata on systems I manage, I guess I will turn to using sudo, which has the advantage of being understandable (although it has a really lousy man page).

wednesday 28 may 2014 à 16:16 hugo said : #3

Create /etc/polkit-1/rules.d/suspend.rules with content

polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.upower.suspend")
return polkit.Result.YES;
});


Then every user can suspend the system with the dbus-call you mentioned. The polkit-manpage http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html contains more information on how to write these rules (e.g. to restrict it to certain users or groups). If you don't want a login manager like ConsoleKit or logind, that's probably the best way to go.

wednesday 28 may 2014 à 16:26 Tanguy said : #4

@hugo : Thanks! It would be more appropriate to allow it only to users members of the powerdev group though, so I would have to add this I guess:

polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.upower.suspend"
&& subject.isInGroup("powerdev"))
return polkit.Result.YES;
});

friday 30 may 2014 à 01:44 ManuelPG said : #5

Thanks for the info on consolekit! I recently ran into an issue with that, and couldn't find out by myself that on can explicitly invoke ck-launch-session to solve it. I certainly agree that this kind of things are painfully underdocumented.

monday 02 june 2014 à 17:56 noname said : #6

You can turn off monitor with xrandr, I put in ~/.xsession

$ xrandr --output VGA1 --off

check your projector name with xrandr, mine is VGA1

monday 02 june 2014 à 18:09 Tanguy said : #7

@noname : But that way, with a command instead of real configuration, is not as satisfying. Also, it is for a single user, and I prefer all my static configuration to be done globally, and it will not apply to a desktop manager but only to the user session.

Write a comment

What is the last letter of the word havqzz? : 

Archives