From 61a54ec64c6f7139bb544fe9ac29b48d2ab72561 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Tue, 9 Nov 2021 15:00:53 +0000 Subject: [PATCH] Laptop control, udev rules, xorg configs, README --- README.md | 17 ++++++++++++++++- bin/brightness_down | 34 ++++++++++++++++++++++++++++++++++ bin/brightness_up | 34 ++++++++++++++++++++++++++++++++++ bin/conservation_mode | 15 +++++++++++++++ bin/power_saving_mode | 28 ++++++++++++++++++++++++++++ udev/backlight.rules | 8 ++++++++ udev/touchpad_input.rules | 1 + xorg/10-monitor.conf | 6 ++++++ 8 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 bin/brightness_down create mode 100644 bin/brightness_up create mode 100644 bin/conservation_mode create mode 100644 bin/power_saving_mode create mode 100644 udev/backlight.rules create mode 100644 udev/touchpad_input.rules create mode 100644 xorg/10-monitor.conf diff --git a/README.md b/README.md index 6ccb22a..b8c2547 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ # legion-7 -Repository with various scripts/configs for Arch Linux on the Lenovo Legion 7 (2021) \ No newline at end of file +Repository with various scripts/configs for Arch Linux on the Lenovo Legion 7 (2021). + +Scripts in the `bin` folder should be placed in `/usr/local/bin` or a similar directory and given execute permissions. + +- `brightness_up` and `brightness_down`: See which GPU is connected and control brightness using ACPI +- `conservation_mode`: Toggle battery conservation mode which limits charge to 60% to preserve its health +- `power_saving_mode`: Change CPU governor, brightness, and refresh rate to extend battery life + +Files in the `udev` folder should be placed in `/etc/udev/rules.d` and owned by `root`. + +- `backlight.rules`: Gives normal users access to backlight controls +- `touchpad_input.rules`: Maps the touchpad's variable `/dev/input/event*` path to the static `/dev/input/touchpad` for VFIO passthrough + +FIles in the `xorg` folder should be placed in `/etc/X11/xorg.conf.d` and owned by `root`. + +- `10-monitor.conf`: Enables 165Hz on boot. diff --git a/bin/brightness_down b/bin/brightness_down new file mode 100644 index 0000000..a654662 --- /dev/null +++ b/bin/brightness_down @@ -0,0 +1,34 @@ +#!/bin/bash + +# Check if AMD or NVIDIA GPU is connected +BrPath= +for Dir in /sys/class/backlight/amdgpu_* +do + if [ -d "$Dir" ] + then + BrPath="$Dir" + break + fi +done + +if [ -d "$BrPath" ] +then + : + # echo "Found AMD GPU folder $BrPath" +else + BrPath=/sys/class/backlight/nvidia_0 + # echo "Didn't find AMD GPU, defaulting to $BrPath" +fi + +# Step brightness by 10% +BrCur=$(cat $BrPath/brightness) +BrMax=$(cat $BrPath/max_brightness) +BrStep=$(($BrMax/10)) + +if [ "$(($BrCur - $BrStep))" -lt "$BrStep" ] +then + echo "$BrStep" > "${BrPath}/brightness" +else + BrCur=$(($BrCur-$BrStep)) + echo "$BrCur" > "${BrPath}/brightness" +fi diff --git a/bin/brightness_up b/bin/brightness_up new file mode 100644 index 0000000..7d7a766 --- /dev/null +++ b/bin/brightness_up @@ -0,0 +1,34 @@ +#!/bin/bash + +# Check if AMD or NVIDIA GPU is connected +BrPath= +for Dir in /sys/class/backlight/amdgpu_* +do + if [ -d "$Dir" ] + then + BrPath="$Dir" + break + fi +done + +if [ -d "$BrPath" ] +then + : + #echo "Found AMD GPU folder $BrPath" +else + BrPath=/sys/class/backlight/nvidia_0 + #echo "Didn't find AMD GPU, defaulting to $BrPath" +fi + +# Step brightness by 10% +BrCur=$(cat $BrPath/brightness) +BrMax=$(cat $BrPath/max_brightness) +BrStep=$(($BrMax/10)) + +if [ "$(($BrCur + $BrStep))" -gt "$BrMax" ] +then + echo "$BrMax" > "${BrPath}/brightness" +else + BrCur=$(($BrCur+$BrStep)) + echo "$BrCur" > "${BrPath}/brightness" +fi diff --git a/bin/conservation_mode b/bin/conservation_mode new file mode 100644 index 0000000..c7f8887 --- /dev/null +++ b/bin/conservation_mode @@ -0,0 +1,15 @@ +#!/bin/bash + +# Run as sudo +[ "$UID" -eq 0 ] || exec sudo "$0" "$@" + +Mode=$(cat /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode) + +if [ "$Mode" -eq "1" ] +then + echo 0 > /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode + echo "Battery Conservation Mode is now inactive" +else + echo 1 > /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode + echo "Battery Conservation Mode is now active" +fi diff --git a/bin/power_saving_mode b/bin/power_saving_mode new file mode 100644 index 0000000..0b72ac9 --- /dev/null +++ b/bin/power_saving_mode @@ -0,0 +1,28 @@ +#!/bin/bash + +# Run as sudo +[ "$UID" -eq 0 ] || exec sudo "$0" "$@" + +if [ "$1" == "on" ] +then + for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; + do + echo "powersave" > $file; + done + xrandr --output DP-4 --mode 2560x1600 --rate 60 > /dev/null 2>&1 + xrandr --output eDP-1 --mode 2560x1600 --rate 60 > /dev/null 2>&1 + for i in {1..3}; do brightness_down; done + echo "Power Saving Mode is now active" +elif [ "$1" == "off" ] +then + for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; + do + echo "schedutil" > $file; + done + xrandr --output DP-4 --mode 2560x1600 --rate 165 > /dev/null 2>&1 + xrandr --output eDP-1 --mode 2560x1600 --rate 165 > /dev/null 2>&1 + for i in {1..3}; do brightness_up; done + echo "Power Saving Mode is now inactive" +else + echo "Usage: power_saving_mode [on/off]" +fi diff --git a/udev/backlight.rules b/udev/backlight.rules new file mode 100644 index 0000000..15afb72 --- /dev/null +++ b/udev/backlight.rules @@ -0,0 +1,8 @@ +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="nvidia_0", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="nvidia_0", RUN+="/usr/bin/chmod g+rw /sys/class/backlight/%k/brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="nvidia_0", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/max_brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="nvidia_0", RUN+="/usr/bin/chmod g+rw /sys/class/backlight/%k/max_brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="amdgpu_bl*", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="amdgpu_bl*", RUN+="/usr/bin/chmod g+rw /sys/class/backlight/%k/brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="amdgpu_bl*", RUN+="/usr/bin/chgrp video /sys/class/backlight/%k/max_brightness" +ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="amdgpu_bl*", RUN+="/usr/bin/chmod g+rw /sys/class/backlight/%k/max_brightness" diff --git a/udev/touchpad_input.rules b/udev/touchpad_input.rules new file mode 100644 index 0000000..015af90 --- /dev/null +++ b/udev/touchpad_input.rules @@ -0,0 +1 @@ +KERNEL=="event[0-9]|event[0-9][0-9]", SUBSYSTEM=="input", ATTRS{name}=="MSFT0001:00 06CB:CE44 Touchpad", ACTION=="add", SYMLINK+="input/touchpad" diff --git a/xorg/10-monitor.conf b/xorg/10-monitor.conf new file mode 100644 index 0000000..96cb34d --- /dev/null +++ b/xorg/10-monitor.conf @@ -0,0 +1,6 @@ +Section "Screen" + Identifier "Screen 0" + Subsection "Display" + Modes "2560x1600_165" + EndSubsection +EndSection