├── systemd
├── system
│ └── suspend.service
└── logind.conf.d
│ └── 70-close_lid.conf
├── configure
├── .gitignore
├── Makefile
└── README.md
/systemd/system/suspend.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=Lock screen before suspend
3 | Before=sleep.target
4 |
5 | [Service]
6 | User=REPLACE_ME
7 | Type=forking
8 | Environment=DISPLAY=:0
9 | ExecStart=/usr/local/bin/xlock -b
10 | ExecStartPost=/bin/sleep 2
11 |
12 | [Install]
13 | WantedBy=sleep.target
14 |
--------------------------------------------------------------------------------
/configure:
--------------------------------------------------------------------------------
1 | #!/bin/sh -eu
2 |
3 | CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
4 |
5 | if [ "$(id -u)" = "0" ]; then
6 | echo "This script must be run as normal user." >&2
7 | exit 1
8 | fi
9 |
10 | mkdir -p "${CWD}/build"
11 | cp "${CWD}/systemd/logind.conf.d/70-close_lid.conf" "${CWD}/build/"
12 | cp "${CWD}/systemd/system/suspend.service" "${CWD}/build/"
13 | sed -i'' "s/REPLACE_ME/$(whoami)/" "${CWD}/build/suspend.service"
14 |
--------------------------------------------------------------------------------
/systemd/logind.conf.d/70-close_lid.conf:
--------------------------------------------------------------------------------
1 | [Login]
2 |
3 | # Go into suspend
4 | HandleLidSwitch=suspend
5 |
6 | # If dock/power or more than 1 monitor is connected
7 | # do not do anything.
8 | HandleLidSwitchDocked=ignore
9 |
10 | # Disable systemd's behavior if a low-level inhibitor lock by
11 | # a graphical desktop environment is set.
12 | # They usually take care about it themselves via their own
13 | # power management settings.
14 | LidSwitchIgnoreInhibited=no
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Note:
2 | # To effectively apply the changes you will have
3 | # to re-index the git index (if there are already
4 | # commited files)
5 | #
6 | # $ git rm -r --cached .
7 | # $ git add .
8 | # $ git commit -m ".gitignore index rebuild"
9 | #
10 |
11 |
12 | ######################################
13 | # CUSTOM
14 | ######################################
15 |
16 | # Keep folders
17 | !.keepme
18 | build/
19 |
20 | ######################################
21 | # GENERIC
22 | ######################################
23 |
24 | ###### std ######
25 | .lock
26 | *.log
27 |
28 | ###### patches/diffs ######
29 | *.patch
30 | *.diff
31 | *.orig
32 | *.rej
33 |
34 | ######################################
35 | # Operating Systems
36 | ######################################
37 |
38 | ###### OSX ######
39 | ._*
40 | .DS*
41 | .Spotlight-V100
42 | .Trashes
43 |
44 | ###### Windows ######
45 | Thumbs.db
46 | ehthumbs.db
47 | Desktop.ini
48 | $RECYCLE.BIN/
49 | *.lnk
50 | *.shortcut
51 |
52 | ######################################
53 | # Editors
54 | ######################################
55 |
56 | ###### Sublime ######
57 | *.sublime-workspace
58 | *.sublime-project
59 |
60 | ###### Eclipse ######
61 | .classpath
62 | .buildpath
63 | .project
64 | .settings/
65 |
66 | ###### Netbeans ######
67 | /nbproject/
68 |
69 | ###### Intellij IDE ######
70 | .idea/
71 | .idea_modules/
72 |
73 | ###### vim ######
74 | *.swp
75 | *.swo
76 | *.swn
77 | *.swm
78 | *~
79 |
80 | ###### TextMate ######
81 | .tm_properties
82 | *.tmproj
83 |
84 | ###### BBEdit ######
85 | *.bbprojectd
86 | *.bbproject
87 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Configuration
2 | SHELL = /bin/sh
3 | MKDIR_P = mkdir -p
4 | SYSTEMCTL = systemctl
5 |
6 | # Check if './configure' has been run
7 | CONFIGURED = 0
8 | ifneq ("$(wildcard build/70-close_lid.conf)","")
9 | ifneq ("$(wildcard build/suspend.service)","")
10 | CONFIGURED = 1
11 | endif
12 | endif
13 |
14 | all:
15 | @echo "Type 'make install' or 'make uninstall'"
16 | @echo
17 | @echo "make install"
18 | @echo " Will copy files to /var/lib/systemd"
19 | @echo " enable services and reload systemd."
20 | @echo ""
21 | @echo "make uninstall"
22 | @echo " Will remove files from /var/lib/systemd"
23 | @echo " disable services and reload systemd."
24 |
25 | install:
26 | ifeq ($(CONFIGURED),0)
27 | $(error Not configured, run ./configure)
28 | endif
29 | @# root check
30 | @[ `id -u` = 0 ] || { echo "Must be run as root or with sudo"; exit 1; }
31 |
32 | @# Create dir
33 | ${MKDIR_P} /usr/lib/systemd/system
34 | ${MKDIR_P} /usr/lib/systemd/logind.conf.d/
35 | @# Copy files
36 | install -m 0644 build/suspend.service /usr/lib/systemd/system/suspend.service
37 | install -m 0644 build/70-close_lid.conf /usr/lib/systemd/logind.conf.d/70-close_lid.conf
38 |
39 | ${SYSTEMCTL} enable suspend.service
40 | ${SYSTEMCTL} daemon-reload
41 |
42 | uninstall:
43 | @# root check
44 | @[ `id -u` = 0 ] || { echo "Must be run as root or with sudo"; exit 1; }
45 |
46 | @# Remove files
47 | ${SYSTEMCTL} disable suspend.service 2>/dev/null || true
48 | rm -f /usr/lib/systemd/system/suspend.service
49 | rm -f /usr/lib/systemd/logind.conf.d/70-close_lid.conf
50 | ${SYSTEMCTL} daemon-reload
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # i3-utils-systemd
2 |
3 | Systemd utilities for a minimalistic [i3](https://github.com/i3/i3) setup.
4 |
5 | 1. Lock screen before suspend
6 | 2. Suspend on lid close
7 |
8 | ---
9 |
10 | **This repository is part of the [i3-utils](https://github.com/cytopia/i3-utils).** (See also [i3-utils-bin](https://github.com/cytopia/i3-utils-bin))
11 |
12 | ---
13 |
14 | ## Systemd
15 |
16 | | Tool | Target | Description |
17 | |------|--------|-------------|
18 | | [70-close_lid.conf](systemd/logind.conf.d/70-close_lid.conf) | `/usr/lib/systemd/logind.conf.d/` | Systemd login configuration to handle notebook lid close. Will put the computer to sleep when the lid closes.
Only going to sleep when: