Skip to content

Instantly share code, notes, and snippets.

@laserbat
Last active September 23, 2023 14:13
Show Gist options
  • Save laserbat/8387c39f3f06c1d3c4955443981aa42a to your computer and use it in GitHub Desktop.
Save laserbat/8387c39f3f06c1d3c4955443981aa42a to your computer and use it in GitHub Desktop.

To use this script

  1. Install xdotool: $ sudo apt install xdotool

  2. Install this script to /usr/local/bin: $ sudo cp path/to/file/permafocus.sh /usr/local/bin/ (path/to/file should be replaced by the actual path to the folder containing script, for example ~/Downloads/)

  3. Make the file executable: $ sudo chmod +x /usr/local/bin/permafocus.sh

  4. Follow this guide to create a custom shortcut, use any name and shortcut key you prefer. In the command field type permafocus.sh toggle

Now whenever you press that shortcut key, the window currently in focus will keep the focus even when you click on another window. Press it again to stop this behavior.

To use it with renoise, you can press your shortcut whenever you start working on a song in renoise and press it again, disabling focus grabbing, when you need to input something into your plugin or another window. But note that it should be pressed when main renoise window is in focus, not a plugin or any other window.

Please note that I can’t test this script in every environment and setup, so it might not run correctly on some systems. Feel free to contact me if this is the case and I’d be happy to try to help.

#!/bin/bash
CMD_PID=""
PIDFILE="/tmp/permafocus.pid"
if [[ -a "$PIDFILE" ]]; then
read -r OLD_PID < "$PIDFILE"
kill -0 "$OLD_PID" &&
CMD_PID="$OLD_PID" &&
RUNNING="1"
fi
start_cmd(){
if [[ "$RUNNING" ]]; then
return
fi
xdotool getactivewindow behave %1 blur windowfocus %1 &
CMD_PID="$!"
echo "$CMD_PID" > "$PIDFILE"
}
stop_cmd() {
if [[ ! "$RUNNING" ]]; then
return
fi
kill "$CMD_PID"
# Make sure that the process is killed
kill -0 "$CMD_PID" && kill -9 "$CMD_PID"
rm -f "$PIDFILE"
}
toggle() {
if [[ "$RUNNING" ]]; then
stop_cmd
else
start_cmd
fi
}
case "$1" in
stop) stop_cmd;;
start) start_cmd;;
toggle) toggle;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment