Thursday 14 May 2015

i3 with Gnome underpinnings on Debian 8.0 (Jessie)

I've been running i3 as my window manager on Debian 7.0 (Wheezy) for a while. I meant to get round to writing a blog posting about how I set it up to work somewhat sanely with Gnome, GDM and gnome-session but never got round to it. The upgrade to Jessie brought some new problems as Gnome rolls more core functionality into gnome-shell. So, here's what I've done to create a Gnome+i3 session in GDM.

Create /usr/share/xsessions/i3-gnome.desktop containing:

[Desktop Entry]
Encoding=UTF-8
Name=i3 Gnome
Comment=improved dynamic tiling window manager with Gnome
TryExec=/usr/local/bin/gnome-session-i3
Exec=gnome-session-i3
Type=Application
Create /usr/local/bin/gnome-session-i3 containing:
#!/bin/sh
exec gnome-session --session=i3-gnome --debug "$@"
and ensure it is executable with:
chmod +x /usr/local/bin/gnome-session-i3
Create /usr/share/gnome-session/sessions/i3-gnome.session containing:
[GNOME Session]
Name=i3 Gnome session
RequiredComponents=gnome-settings-daemon;gnome-screensaver;nm-applet;i3-gnome
Create /usr/share/applications/i3-gnome.desktop containing:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=i3-gnome
Comment=improved dynamic tiling window manager with Gnome underpinnings
Exec=i3-gnome
NoDisplay=true
X-GNOME-WMName=i3 Gnome
X-GNOME-Autostart-Phase=WindowManager
X-GNOME-Provides=windowmanager
StartupWMClass=i3
Create /usr/local/bin/i3-gnome containing:
#!/bin/sh
if [ -n "$DESKTOP_AUTOSTART_ID" ]; then
   dbus-send --session --print-reply --dest=org.gnome.SessionManager "/org/gnome/SessionManager" org.gnome.SessionManager.RegisterClient "string:i3-gnome" "string:$DESKTOP_AUTOSTART_ID"
fi
exec i3
and ensure it is executable with:
chmod +x /usr/local/bin/i3-gnome
That should give you enough to have an "i3 Gnome" entry in your GDM menu. But, if you launch it you'll find there are a few problems that need solving: To make the mouse cursor appear (credit):
dconf write /org/gnome/settings-daemon/plugins/cursor/active false
In order to log out you need to tell the session manager to finish the session. I do that with a script that provides the behaviour that gnome-session-quit used to in earlier Gnome versions:
#!/bin/sh

# gnome-session-quit talks DBus to gnome-session which now tries to
# talk to gnome-shell in order to bring up a dialog box to confirm
# whether we should quit. Since we're not running gnome-shell this
# doesn't work. So, let's bring up our own box and then tell
# gnome-session to quit without prompting.

case "$1" in
    --logout)
 text="Do you wish to log out?"
 ;;
    --power-off)
 text="Do you wish to power off?"
 ;;
    --reboot)
 text="Do you wish to reboot?"
 ;;
    *)
 echo "Unknown option: $1" 1>&2
 exit 1
esac

if zenity --question --text="${text}"; then
    exec gnome-session-quit --no-prompt "$@"
fi

and then bind it in ~/.i3/config:

bindsym $mod+Shift+E exec /home/mac/bin/scripts/gnome-session-quit-ask --logout
In order to lock the session using gnome-screensaver you can add a binding like this to your .i3/config:
bindsym Ctrl+Mod1+L exec --no-startup-id dbus-send --print-reply --session --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
Fast user switching works with this but when switching back to i3 you'll unfortunately need to enter your password twice. I use udisks-glue to automatically mount storage devices.

1 comment:

Anonymous said...

This setting is working for almost everything except that I failed to logout on my Debian unstable. I created this exit menu to logout properly. It might be improved since I just begin to play with dbus...

# create Log out, Reboot, Poweroff bindings
mode "Exit (L)ogout, (R)eboot, (P)oweroff" {
bindsym $mod+l exec dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
bindsym $mod+r exec systemctl reboot
bindsym $mod+p exec systemctl poweroff

# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}

bindsym $mod+Shift+e mode "Exit (L)ogout, (R)eboot, (P)oweroff"