From 2aedbced667e13e80cc028a4552e294128fb6460 Mon Sep 17 00:00:00 2001 From: redxef Date: Mon, 15 Apr 2024 17:47:15 +0200 Subject: [PATCH] Automatically detect loaded module. --- .gitignore | 4 ++++ PKGBUILD | 2 +- README.md | 11 +++-------- sway-dynamic | 13 ++++++++++++- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3d2f77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +pkg/ +src/ +sway-dynamic-*/ +sway-dynamic-*.pkg.tar.zst diff --git a/PKGBUILD b/PKGBUILD index a2a1387..f54dd56 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer redxef pkgname=sway-dynamic -pkgver=1.0.0 +pkgver=1.0.1 pkgrel=1 pkgdesc="Helper files to dynamically launch sway for NVIDIA comaptibility or not" arch=('any') diff --git a/README.md b/README.md index dc01ec0..4c63746 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,6 @@ Dynamically switch between sway and sway-nvidia based on active gpu. ## Usage -When booting a GPU set the environment variable `GPUMODE=` with something -like `systemd.setenv=GPUMODE=`. The script will decide how to -launch sway depending on this variable. Possible values: - -- `nvidia` -- `nouveau` - - +Blacklist the module which should not be loaded on boot, the script +detects if the `nvidia` or `nouveau` driver is loaded and either calls +`sway-nvidia` or `sway`. diff --git a/sway-dynamic b/sway-dynamic index 5b850cb..eba3809 100755 --- a/sway-dynamic +++ b/sway-dynamic @@ -1,6 +1,17 @@ #!/bin/sh -if [ "$GPUMODE" = 'nvidia' ]; then +active_module() { + if [ -n "$(lsmod | grep "nvidia")" ]; then + echo "nvidia" + elif [ -n "$(lsmod | grep "nouveau")" ]; then + echo nouveau + else + # no nvidia modules loaded + echo "" + fi +} + +if [ "$(active_module)" = 'nvidia' ]; then exec sway-nvidia else exec sway