Added new x11-toggle-primary-gpu script & config

This commit is contained in:
GaspardCulis 2023-11-10 14:05:42 +01:00
parent 07e7c02813
commit 7272b213f7
5 changed files with 115 additions and 5 deletions

81
bin/x11-toggle-primary-gpu Executable file
View file

@ -0,0 +1,81 @@
#!/bin/bash
SHARED_DIR='/home/gaspard/.local/share/x11-toggle-gpu'
XORG_DIR='/etc/X11/xorg.conf.d'
AMD_CONF_FILE='20-amdgpu.conf'
NVIDIA_CONF_FILE='10-nvidia-drm-outputclass.conf'
get-mode () {
if [ -f "$XORG_DIR/$NVIDIA_CONF_FILE" ]; then
echo 'NVIDIA'
else
echo 'AMD'
fi
}
check-config () {
if [ ! -d "$SHARED_DIR" ]; then
echo "[ERROR] Shared dir could not be found."
exit 1
fi
if [ ! -d "$XORG_DIR" ]; then
echo "[ERROR] X11 config dir could not be found."
exit 2
fi
if [ -f "$XORG_DIR/$AMD_CONF_FILE" ] && [ -f "$XORG_DIR/$NVIDIA_CONF_FILE" ]; then
echo "[ERROR] Corrupted configuration folder."
exit 3
fi
CONF_FILE="$AMD_CONF_FILE"
if [ "$(get-mode)" == "NVIDIA" ]; then
CONF_FILE="$NVIDIA_CONF_FILE"
fi
if ! cmp --silent $SHARED_DIR/$CONF_FILE $XORG_DIR/$CONF_FILE ; then
echo "[ERROR] Corrupted configuration file."
exit 4
fi
}
gpu-toggle () {
MODE="$(get-mode)"
if [ "$MODE" == "AMD" ]; then
rm "$XORG_DIR/$AMD_CONF_FILE"
cp "$SHARED_DIR/$NVIDIA_CONF_FILE" "$XORG_DIR/$NVIDIA_CONF_FILE"
elif [ "$MODE" == "NVIDIA" ]; then
rm "$XORG_DIR/$NVIDIA_CONF_FILE"
cp "$SHARED_DIR/$AMD_CONF_FILE" "$XORG_DIR/$AMD_CONF_FILE"
fi
echo "[INFO] Primary GPU configuration toggled to $(get-mode)."
}
check-config
if [ "$1" == "get" ]; then
echo "$(get-mode)"
exit 0
fi
if [ "$1" == "toggle" ]; then
# ROOT NEEDED
if [ "$EUID" -ne 0 ]
then echo "[ERROR] Please run as root"
exit
fi
gpu-toggle
exit 0
fi
echo "Usage: $0 {get, toggle}"
exit 1

View file

@ -29,11 +29,18 @@ if [ -f "$usermodmap" ]; then
xmodmap "$usermodmap" xmodmap "$usermodmap"
fi fi
if [ -d /etc/X11/xinit/xinitrc.d ] ; then # if [ -d /etc/X11/xinit/xinitrc.d ] ; then
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do # for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
[ -x "$f" ] && . "$f" # [ -x "$f" ] && . "$f"
done # done
unset f # unset f
# fi
if type "x11-toggle-primary-gpu" > /dev/null; then
if [ "$(x11-toggle-primary-gpu get)" == "NVIDIA" ]; then
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
fi
fi fi
setxkbmap fr setxkbmap fr

View file

@ -0,0 +1,15 @@
Section "OutputClass"
Identifier "AMD Graphics"
MatchDriver "amdgpu"
Driver "modesetting"
EndSection
Section "OutputClass"
Identifier "nvidia"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "PrimaryGPU" "yes"
ModulePath "/usr/lib/nvidia/xorg"
ModulePath "/usr/lib/xorg/modules"
EndSection

View file

@ -0,0 +1,5 @@
Section "Device"
Identifier "AMD Graphics"
Driver "amdgpu"
Option "TearFree" "true"
EndSection

2
sync
View file

@ -26,6 +26,7 @@ synced_files = [
('home/xinitrc', '~/.xinitrc'), ('home/xinitrc', '~/.xinitrc'),
('misc/picom/', '~/.config/picom/'), ('misc/picom/', '~/.config/picom/'),
('misc/runst/', '~/.config/runst/'), ('misc/runst/', '~/.config/runst/'),
('misc/x11-toggle-gpu/', '~/.local/share/x11-toggle-gpu/'),
('bin/swaylock-hyprland', '~/.local/bin/swaylock-hyprland'), ('bin/swaylock-hyprland', '~/.local/bin/swaylock-hyprland'),
('bin/Hyprland', '~/.local/bin/Hyprland'), ('bin/Hyprland', '~/.local/bin/Hyprland'),
@ -34,6 +35,7 @@ synced_files = [
('bin/wtoggle-touchpad', '~/.local/bin/wtoggle-touchpad'), ('bin/wtoggle-touchpad', '~/.local/bin/wtoggle-touchpad'),
('bin/togglescreen', '~/.local/bin/togglescreen'), ('bin/togglescreen', '~/.local/bin/togglescreen'),
('bin/mc-key-fix', '~/.local/bin/mc-key-fix'), ('bin/mc-key-fix', '~/.local/bin/mc-key-fix'),
('bin/x11-toggle-primary-gpu', '~/.local/bin/x11-toggle-primary-gpu'),
] ]
def save(): def save():