The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
2

How do i suspend,lockscreen and logout?

asked 2012-07-11 07:32:59 +0000

jcharnley gravatar image

updated 2012-07-12 17:01:51 +0000

joepd gravatar image

How do i manage shortcuts?

eg i logged in but couldnt lock my screen at my office (you have too, or you will get lemonparty everywhere), suspend or even logout.

(i did some fair amount of googleing before coming here :) )

// first-day-with-i3-user

edit retag flag offensive close merge delete

10 answers

Sort by ยป oldest newest most voted
2

answered 2012-07-11 07:42:15 +0000

Michael gravatar image

To lock your screen, you can use any screen locker, such as i3lock.

To logout, press Mod+shift+e (like exit).

To suspend, use pm-suspend or the more direct (but maybe not 100% working on your hardware) sudo sh -c "echo mem > /sys/power/state"

edit flag offensive delete link more

Comments

in addittion to that you can use in debian pm-is-supported for test wheter suspend or hibernate is supported if it gives you "0" you support hibernate or suspend if it gives you "1" not avalaible,you might be use this : pm-is-supported --suspend,pm is as a root user...sudo or something like that.

c1b3rh4ck gravatar imagec1b3rh4ck ( 2012-08-12 18:55:06 +0000 )edit

This works but the screen is not locked so anyone can just wake up the computer. Is it possible to also lock using pm-suspend?

simao gravatar imagesimao ( 2013-07-02 09:14:05 +0000 )edit

for lock+suspend i do use: bindsym $mod+Shift+e exec --no-startup-id "sh -c 'qslock && sleep 0.5 && sudo /usr/sbin/pm-suspend'" while qslock is just my wrapper around vlock||i3lock based on [ -z $DISPLAY ] (https://github.com/queria/scripts/blob/master/qslock)

queria gravatar imagequeria ( 2015-02-24 22:13:35 +0000 )edit
3

answered 2013-05-30 09:03:36 +0000

V0id gravatar image

I personally use a i3 "mode" to handle system shutdown, reboot, etc.

e.g to suspend: Mod+Pause then s.

The shortcuts are written in the mode name as a reminder.

set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
    bindsym l exec --no-startup-id i3exit lock, mode "default"
    bindsym e exec --no-startup-id i3exit logout, mode "default"
    bindsym s exec --no-startup-id i3exit suspend, mode "default"
    bindsym h exec --no-startup-id i3exit hibernate, mode "default"
    bindsym r exec --no-startup-id i3exit reboot, mode "default"
    bindsym Shift+s exec --no-startup-id i3exit shutdown, mode "default"

    # back to normal: Enter or Escape
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Pause mode "$mode_system"

the i3exit is a simple script like that (for a distro with systemd):

#!/bin/sh
lock() {
    i3lock
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        lock && systemctl suspend
        ;;
    hibernate)
        lock && systemctl hibernate
        ;;
    reboot)
        systemctl reboot
        ;;
    shutdown)
        systemctl poweroff
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0
edit flag offensive delete link more

Comments

Handy script, thanks

flylo gravatar imageflylo ( 2013-10-12 03:45:25 +0000 )edit
3

answered 2012-07-30 17:30:13 +0000

jonyamo gravatar image

updated 2013-06-23 03:35:03 +0000

My current favorite distro is CrunchBang, and the developer has created some cool scripts that come along with it. One of those scripts is called cb-exit and it provides a nice dialog window to handle logout, suspend, reboot, and shutdown. The problem is it is designed around Openbox, so I tweaked it to work with i3 (admittedly I didn't need to do much). Just be aware it does require Python, but that is just for creating the dialog window, you can just rip out the dbus commands and use them any way you want.

I have aptly renamed it to i3-exit and you can download it here. Just add the script to your path and then create a keybind to call it, such as:

bindsym Mod4+x exec i3-exit

Also, be aware that I prefer to lock my screen when I suspend my computer, so in the suspend function I have a call to i3-lock, which is just a wrapper I created to call my locker of choice.

As far as locking your screen just create a keybind for your favorite locker (e.g., i3lock), like so:

bindsym Mod4+l exec i3lock
edit flag offensive delete link more

Comments

+1 for cb-exit mod :)

joepd gravatar imagejoepd ( 2012-09-09 18:31:30 +0000 )edit
1

Thanks for i3 exit, it's really cool ! I bind it on the power button : bindsym XF86PowerOff exec ~/.i3/i3-exit

swap38 gravatar imageswap38 ( 2012-11-28 15:16:18 +0000 )edit

The download link for this is dead and I didn't find the script in jonyamo's repositories either. How can I get it?

mschaefer gravatar imagemschaefer ( 2013-03-12 15:55:30 +0000 )edit

mschaefer: Reply in new answer.

joepd gravatar imagejoepd ( 2013-03-17 16:58:08 +0000 )edit

joepd: thanks, i will try do adapt it myself :-)

mschaefer gravatar imagemschaefer ( 2013-03-18 08:45:12 +0000 )edit
1

answered 2014-09-17 10:24:24 +0000

Sam73 gravatar image

updated 2014-09-17 10:27:28 +0000

I used answer from V0id but changed the i3exit script for dbus commands so being root is not required

#!/bin/sh
lock() {
    i3lock
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        lock && dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
        ;;
    hibernate)
        lock && dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
        ;;
    reboot)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
        ;;
    shutdown)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

exit 0
edit flag offensive delete link more

Comments

The reboot, shutdown & hibernate commands won't work in Ubuntu 14.04+, I've posted them in a new comment below.

Ruben G gravatar imageRuben G ( 2015-03-02 08:24:19 +0000 )edit
1

answered 2015-03-02 08:25:53 +0000

Ruben G gravatar image

updated 2015-03-26 07:35:01 +0000

Extending Sam73 comment, the reboot, shutdown & hibernate commands won't work in Ubuntu 14.04+, these are the new ones:

Reboot:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Reboot" boolean:true

Suspend:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Suspend" boolean:true

Hibernate:

dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Hibernate" boolean:true

Source (can't post direct links): askubuntu.com/questions/454039/what-command-is-executed-when-shutdown-from-the-graphical-menu-in-14-04

Edit 3/26-Two more interesting commands, switch user and switch to guest account without closing current session:

Switch user:

dm-tool switch-to-greeter

Switch to guest:

dm-tool switch-to-guest
edit flag offensive delete link more
0

answered 2014-01-10 21:22:44 +0000

An easy way could be

pm-suspend && i3lock

edit flag offensive delete link more

Comments

pm-suspend must be (in most cases) run as superuser

vire gravatar imagevire ( 2014-10-04 09:18:40 +0000 )edit
0

answered 2012-08-26 15:12:58 +0000

lzap gravatar image

If you want KDE/GNOME behavior for locking, then:

bindsym Control+mod1+l exec i3lock
edit flag offensive delete link more
0

answered 2012-12-19 02:14:37 +0000

If you are looking for a "10 minutes idle" type of screen saver try adding xautolock to your xsession.

In security conscious environments this is a must. I like the ideas above and plan to use both.

It's not specific to i3, but you can use it to launch any screen lock type of program (to include i3lock).

Also, for fellow i3noobs - i3lock's default mode is to make the screen white. To unlock just type your password (there's no dialog like you are used to seeing - just type it). The first time I ran i3lock I thought I hosed my session up. I like it, but it just confused me for a google or two.

edit flag offensive delete link more
0

answered 2015-05-08 12:40:14 +0000

msx gravatar image

updated 2015-05-10 21:54:23 +0000

Log out - quick and clean:

bindsym $mod+Shift+e exec "i3-msg exit"

For manually locking your screen you can set i3-lock the same way, however I'm using 'i3-lock-wrapper' (from the awesome i3 extras repo in GitHub: https://github.com/ashinkarov/i3-extras):

bindsym $mod+Ctrl+l exec --no-startup-id "~/.i3/addons/i3lock-wrapper -nbdl; xset r rate 200 40; setxkbmap -rules evdev -model evdev -layout us -variant altgr-intl; xinput --set-button-map 15 1 3 2"

(The rest of the commands just re-establish my kbd and mouse settings)

To manually suspend the system I use a little variation of the above line:

bindsym $mod+Ctrl+s exec --no-startup-id "~/.i3/addons/i3lock-wrapper -bdl; systemctl suspend;...

I yet need to configure my system to automatically lock the screen whenever I suspend but closing my laptop's lid, I think I will end up creating a new systemd service for that.

edit flag offensive delete link more
0

answered 2013-03-17 16:57:22 +0000

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

posting an answer, as a comment cannot be that long. This is the current version of cb-exit at crunchbang linux, could not find a quick link... Community wiki for if someone makes it better suited for i3 ;)

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os
import getpass

class cb_exit:
    def disable_buttons(self):
        self.cancel.set_sensitive(False)
        self.logout.set_sensitive(False)
        self.suspend.set_sensitive(False)
        self.reboot.set_sensitive(False)
        self.shutdown.set_sensitive(False)

    def cancel_action(self,btn):
        self.disable_buttons()
        gtk.main_quit()

    def logout_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Exiting Openbox, please standby...")
        os.system("openbox --exit")

    def suspend_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Suspending, please standby...")
        os.system("cb-lock")
        os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.UPower\" /org/freedesktop/UPower org.freedesktop.UPower.Suspend")
        gtk.main_quit()

    def reboot_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Rebooting, please standby...")
        os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart")

    def shutdown_action(self,btn):
        self.disable_buttons()
        self.status.set_label("Shutting down, please standby...")
        os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop")

    def create_window(self):
        self.window = gtk.Window()
        title = "Log out " + getpass.getuser() + "? Choose an option:"
        self.window.set_title(title)
        self.window.set_border_width(5)
        self.window.set_size_request(500, 80)
        self.window.set_resizable(False)
        self.window.set_keep_above(True)
        self.window.stick
        self.window.set_position(1)
        self.window.connect("delete_event", gtk.main_quit)
        windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
        self.window.set_icon(windowicon)


        #Create HBox for buttons
        self.button_box = gtk.HBox()
        self.button_box.show()

        #Cancel button
        self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
        self.cancel.set_border_width(4)
        self.cancel.connect("clicked", self.cancel_action)
        self.button_box.pack_start(self.cancel)
        self.cancel.show()

        #Logout button
        self.logout = gtk.Button("_Log out")
        self.logout.set_border_width(4)
        self.logout.connect("clicked", self.logout_action)
        self.button_box.pack_start(self.logout)
        self.logout.show()

        #Suspend button
        self.suspend = gtk.Button("_Suspend")
        self.suspend.set_border_width(4)
        self.suspend.connect("clicked", self.suspend_action)
        self.button_box.pack_start(self.suspend)
        self.suspend.show()

        #Reboot button
        self.reboot = gtk.Button("_Reboot")
        self.reboot.set_border_width(4)
        self.reboot.connect("clicked", self.reboot_action)
        self.button_box.pack_start(self.reboot)
        self.reboot.show()

        #Shutdown button
        self.shutdown = gtk.Button("_Power off")
        self.shutdown.set_border_width(4)
        self.shutdown.connect("clicked", self.shutdown_action)
        self.button_box.pack_start(self.shutdown)
        self.shutdown.show()

        #Create HBox for status label
        self.label_box = gtk.HBox()
        self.label_box.show()
        self.status = gtk.Label()
        self.status.show()
        self.label_box.pack_start(self.status)

        #Create VBox and pack the above HBox's
        self.vbox = gtk.VBox()
        self.vbox.pack_start(self.button_box)
        self.vbox.pack_start(self.label_box)
        self.vbox.show()

        self.window.add(self.vbox)
        self.window.show()

    def __init__(self):
        self.create_window()


def main():
    gtk.main()

if __name__ == "__main__":
    go = cb_exit()
    main()
edit flag offensive delete link more

Question Tools

9 followers

Stats

Asked: 2012-07-11 07:32:59 +0000

Seen: 71,769 times

Last updated: May 10