aboutsummaryrefslogtreecommitdiff
path: root/scripts/controller-autostart-steam
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/controller-autostart-steam')
-rwxr-xr-xscripts/controller-autostart-steam/,controller-add14
-rwxr-xr-xscripts/controller-autostart-steam/,start-steam13
-rw-r--r--scripts/controller-autostart-steam/99-controller-autostart-steam.rules2
-rw-r--r--scripts/controller-autostart-steam/README.md53
-rw-r--r--scripts/controller-autostart-steam/controller-autostart-steam.env6
-rw-r--r--scripts/controller-autostart-steam/controller-steam.service9
6 files changed, 97 insertions, 0 deletions
diff --git a/scripts/controller-autostart-steam/,controller-add b/scripts/controller-autostart-steam/,controller-add
new file mode 100755
index 0000000..d52d8b8
--- /dev/null
+++ b/scripts/controller-autostart-steam/,controller-add
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+env_file="$HOME/.config/controller-autostart-steam.env"
+
+. $env_file
+
+if [[ -f "$lockfile" ]]; then
+ echo "lockfile present"
+ exit 0
+fi
+
+touch "$lockfile"
+
+XDG_RUNTIME_DIR=/run/user/$(id -u $USER) systemctl --user start controller-steam.service
diff --git a/scripts/controller-autostart-steam/,start-steam b/scripts/controller-autostart-steam/,start-steam
new file mode 100755
index 0000000..7f81f00
--- /dev/null
+++ b/scripts/controller-autostart-steam/,start-steam
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+env_file="$HOME/.config/controller-autostart-steam.env"
+
+. $env_file
+
+powerprofilesctl set "$perf_inside"
+
+steam
+
+powerprofilesctl set "$perf_outside"
+
+rm "$lockfile" || echo "cannot delete $lockfile"
diff --git a/scripts/controller-autostart-steam/99-controller-autostart-steam.rules b/scripts/controller-autostart-steam/99-controller-autostart-steam.rules
new file mode 100644
index 0000000..862c8a7
--- /dev/null
+++ b/scripts/controller-autostart-steam/99-controller-autostart-steam.rules
@@ -0,0 +1,2 @@
+# my Xbox 360 controller
+ATTR{idVendor}=="0e6f", ATTR{idProduct}=="0413", ACTION=="add", RUN+="/usr/bin/sudo -u anhgelus /home/anhgelus/.local/bin/,controller-add"
diff --git a/scripts/controller-autostart-steam/README.md b/scripts/controller-autostart-steam/README.md
new file mode 100644
index 0000000..f604b15
--- /dev/null
+++ b/scripts/controller-autostart-steam/README.md
@@ -0,0 +1,53 @@
+# Controller autostart Steam
+
+Autostart Steam when my controller is plugged.
+
+Set power profile to `performance` and go back to `power-saving` when Steam is closed.
+
+## Installing
+
+Copy `,controller-add` and `,start-steam` in `$HOME/.local/bin`.
+
+Copy `99-controller-autostart-steam.rules` in `/etc/udev/rules.d/` and change:
+- `anhgelus` by your UNIX username
+- `0e6f` by the vendor ID of your controller (displayed by `lsusb`)
+- `0413` by the product ID of your controller (displayed by `lsusb`)
+
+See below if you don't know how to get these IDs.
+
+Copy `controller-steam.service` in `$HOME/.config/systemd/user/` and change:
+- `anhgelus` by your UNIX username
+
+Copy `controller-autostart-steam.env` in `$HOME/.config`.
+
+Reload udev rules:
+```bash
+sudo udevadm control --reload-rules && sudo udevadm trigger
+```
+
+Reload systemd:
+```bash
+systemctl --user daemon-reload
+```
+
+You can modify the location of the lockfile by editing `lockfile` variable in
+`$HOME/.config/controller-autostart-steam.env`.
+
+You can modify the power profile by editing in the same file:
+- `perf_inside` variable when Steam is launched
+- `perf_outside` variable when Steam is closed
+
+### How to get required IDs of your controller?
+
+Plug your controller and run:
+```bash
+lsusb
+```
+It will list hardwares connected to your computer via a USB port.
+
+My controller is this one:
+```
+Bus 003 Device 011: ID 0e6f:0413 Logic3 Afterglow AX.1 Gamepad for Xbox 360
+```
+
+Its identifier is `0e6f:0413`, where `0e6f` is its vendor ID and `0413` is its product ID.
diff --git a/scripts/controller-autostart-steam/controller-autostart-steam.env b/scripts/controller-autostart-steam/controller-autostart-steam.env
new file mode 100644
index 0000000..7422e5f
--- /dev/null
+++ b/scripts/controller-autostart-steam/controller-autostart-steam.env
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+lockfile="$HOME/.controller-add.lock"
+
+perf_inside="performance"
+perf_outside="power-saver"
diff --git a/scripts/controller-autostart-steam/controller-steam.service b/scripts/controller-autostart-steam/controller-steam.service
new file mode 100644
index 0000000..308e0f4
--- /dev/null
+++ b/scripts/controller-autostart-steam/controller-steam.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Autostart Steam when a controller is plugged
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/bash /home/anhgelus/.local/bin/,steam-controller
+
+[Install]
+WantedBy=default.target