• Stars
    star
    382
  • Rank 112,241 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitLab: https://gitlab.com/jD91mZM2/xidlehook

xidlehook

Because xautolock is annoying to work with.

xidlehook is a general-purpose replacement for xautolock. It executes a command when the computer has been idle for a specified amount of time.

Improvements over xautolock:

  • Allows "cancellers" which can undo a timer action when new user activity is detected.
  • Unlimited amount of timers (provided necessary resources).
  • Not specific to locking.
  • Multiple instances can run at the same time.
  • Optionally only run through chain once.
  • Optionally prevent locking when an application is fullscreen.
  • Optionally prevent locking when any application plays audio.

Missing features:

  • Magic corners
  • All the instance related stuff (you should use unix sockets with โ€“socket).

Example

Here's a lock using i3lock, with screen dim support:

#!/usr/bin/env bash

# Only exported variables can be used within the timer's command.
export PRIMARY_DISPLAY="$(xrandr | awk '/ primary/{print $1}')"

# Run xidlehook
xidlehook \
  `# Don't lock when there's a fullscreen application` \
  --not-when-fullscreen \
  `# Don't lock when there's audio playing` \
  --not-when-audio \
  `# Dim the screen after 60 seconds, undim if user becomes active` \
  --timer 60 \
    'xrandr --output "$PRIMARY_DISPLAY" --brightness .1' \
    'xrandr --output "$PRIMARY_DISPLAY" --brightness 1' \
  `# Undim & lock after 10 more seconds` \
  --timer 10 \
    'xrandr --output "$PRIMARY_DISPLAY" --brightness 1; i3lock' \
    '' \
  `# Finally, suspend an hour after it locks` \
  --timer 3600 \
    'systemctl suspend' \
    ''

Note: Every command is passed through sh -c, so you should be able to mostly use normal syntax.

Installation

As of currently, you will need to use the Rust 1.39.0 higher when building xidlehook.

Recommended installation is through the Nix package manager, which will get you a sane default configuration of xidlehook as well as all required libraries.

nix-env -iA nixpkgs.xidlehook

will install xidlehook regardless of whether you have rust installed, regardless of whether you have libxcb and friends installed, whatever. Nix just works.

If you instead would like to use the latest master, you can install it using the following.

nix-env -if https://gitlab.com/jD91mZM2/xidlehook/-/archive/master.tar.gz

Other installation methods

While I do definitely encourage you to try Nix if you haven't already, there are other ways to install xidlehook, of course. But it will involve some system-specific trouble I can't really help you with.

Arch Linux users can avoid that, however, thanks to an unofficial AUR package!

Xidlehook with the default settings requires libxcb, libXScrnSaver (or libxss) and libpulseaudio. On debian/ubuntu, don't forget to install the -dev versions of all the mentioned dependencies, also.

Which feature flag? Native dependency
Always libxcb, libXScrnSaver (aka libxss)
When using โ€“features pulse (default) libpulseaudio

After getting these native libraries, one way of installing is with cargo, the official rust package manager that works almost everywhere with rust installed.

cargo install xidlehook --bins

Or if you want to clone it manually:

git clone https://gitlab.com/jD91mZM2/xidlehook
cd xidlehook
cargo build --release --bins

Socket API

The socket API can be communicated with over JSON. The full data and types for these structures can be seen in all the struct definitions of xidlehook/src/socket/models.rs.

For convenience, there is now an xidlehook-client (see #18), which will communicate with this API for you. See

xidlehook-client --help

for details.

A common use case of xidlehook is using it to run a lockscreen. To then manually lock the screen, you could first decide what ID the timer has, either by counting the indexes yourself of the timers you inform xidlehook of (starting from 0), or by querying timer information after starting it:

# Check what timer(s) you want to trigger...
xidlehook-client --socket /path/to/xidlehook.sock query

And then bind a hotkey or bash alias to lock it:

# Trigger it/them
xidlehook-client --socket /path/to/xidlehook.sock control --action trigger --timer <my timer id>

Caffeinate

If you're looking for a more elaborate client to temporarily disable xidlehook, take a look at caffeinate which has timers and PID based monitoring.

Configuring via systemd

If you use a distribution that uses systemd for its init system, you may wish to use it to ensure that xidlehook is always started when you log in. You can do this at the level of an individual user by placing the following service file at $XDG_CONFIG_HOME/systemd/user/xidlehook.service (typically $HOME/.config/systemd/user/xidlehook.service):

[Unit]
Description=Automatic Screen Locker

[Service]
Type=simple
Environment=DISPLAY=:0
Environment=XIDLEHOOK_SOCK=%t/xidlehook.socket
ExecStart=/usr/bin/xidlehook --not-when-audio --not-when-fullscreen --socket $XIDLEHOOK_SOCK --timer 900 '/usr/bin/slock' ''

[Install]
WantedBy=multi-user.target

The above service file example locks the screen using the slock program after 15 minutes of inactivity, but you can edit it the xidlehook command to do anything you wish. We need to thread the DISPLAY environment variable down so that xidlehook knows how to open up a connection to the X server.

Troubleshooting

If you have redshift running, the brightness of your screen will be quickly overriden by redshift. You can specify the brightness of the screen via redshift instead of xrandr to fix this issue.

More Repositories

1

termplay

GitLab: https://gitlab.com/jD91mZM2/termplay
Rust
540
star
2

powerline-rs

GitLab: https://gitlab.com/jD91mZM2/powerline-rs
Nix
117
star
3

sslhash

SSL without a certificate authority
Rust
31
star
4

jrust

A Rust macro that parses Java-like syntax and runs it as a Rust program
Rust
27
star
5

dotfiles

Literally just my "dotfiles" (except most don't even have dots in front of them). Not interesting, but 'kay.
Nix
25
star
6

rot26

Pure rust implementation of the rot26 algorithm
Rust
24
star
7

Jointercept

Jointercept stands for Join Intercept and is a replacement for the buggy EventGhost to instead launch your own programs!
Go
19
star
8

rust-lci

A LOLCODE interpreter written in Rust
Rust
15
star
9

rust-import

Attempt at an importer for Rust
Rust
11
star
10

minttp

minttp is an experiment to see if I could create a simple and minimal HTTP library without any dependencies.
Rust
11
star
11

chess-minimax

A chess bot written in Rust using the minimax algorithm
Rust
7
star
12

UndertaleSandbox

Backup your Undertale save files and replace them with new ones temporarily.
Go
7
star
13

insult

"Oh... Sir! The Insult Simulator" - like insults.
Rust
5
star
14

docker-steam

Very simple steam docker image (entirely thanks to x11docker)
Shell
5
star
15

git-subcopy

Link files across repositories
Nix
4
star
16

no-std-compat

A `#![no_std]` compatibility layer that will make porting your crate to no_std *easy*.
Rust
4
star
17

TimeyWimey-Go

No more stuggle with time zones... Thanks Discord!
Go
3
star
18

Join-API-for-Java

Access the Join API simply via Java
Java
2
star
19

termwm

A floating WM of terminals inside your terminal
Rust
2
star
20

pseudoterm

Low-level library for creating PTYs and getting related properties
Rust
2
star
21

spell

Tries to find the word you are looking for and spell it correctly
Rust
2
star
22

DA-DANK-MEEMZ

IT US DANK MEEMZ ONLEIN 2 GIV U AUDIO AND JPEGZ. INVEIT 2 UR DISCORD SERVR 4 MAXIMUM DANKNEZZZ
Go
2
star
23

docker-compiler-explorer

WIP Dockerfile to run compiler explorer locally
Dockerfile
2
star
24

rowan-tools

A few helpers for writing hand-written parsers (Mirror)
Rust
2
star
25

lcs

A project aimed to teach me how to calculate diffs
Rust
1
star
26

cargo-patch

A WIP cargo subcommand for recursively patching dependencies without [patch]
Rust
1
star
27

MCWASM

Mirror from GitLab
Python
1
star
28

math-types

A simple library for a few math types, such as fractions and matrices.
Rust
1
star
29

easyfuse

A high-level idiomatic wrapper around rust-fuse
Rust
1
star
30

configfs

Crazy project that creates a virtual filesystem to translate your config files
Rust
1
star
31

nix-github

Nix Flake action for GitHub
Shell
1
star
32

remoterm

SSH-like application for remote support
Rust
1
star