-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimus.sh
executable file
·124 lines (105 loc) · 2.81 KB
/
optimus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Ensure the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Use sudo to run it."
exit 1
fi
# Path to the Xorg configuration file
CONFIG_FILE="/usr/share/X11/xorg.conf.d/20-optimus.conf"
# Integrated and Hybrid configurations
INTEGRATED_CONFIG=$(cat <<EOF
# Integrated mode
Section "ServerFlags"
Option "AutoAddGPU" "false"
Option "DefaultServerLayout" "iGPU Layout"
EndSection
Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:101:0:0"
Option "PageFlip" "off"
EndSection
Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection
Section "ServerLayout"
Identifier "iGPU Layout"
Screen "iGPU"
Option "SingleCard" "true"
EndSection
EOF
)
HYBRID_CONFIG=$(cat <<EOF
# Hybrid mode
Section "Device"
Identifier "dGPU"
Driver "nvidia"
BusID "PCI:100:0:0"
Option "AllowEmptyInitialConfiguration" "true"
EndSection
Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:101:0:0"
Option "PageFlip" "off"
EndSection
Section "Screen"
Identifier "dGPU"
Device "dGPU"
EndSection
Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection
EOF
)
# Check the current mode in the config file
current_mode=$(head -n 1 "$CONFIG_FILE")
# Function to check if the config is already in the desired mode
check_mode() {
if [[ "$current_mode" == "# $1 mode" ]]; then
echo "Xorg config is already in $1 mode."
exit 0
fi
}
# Function to change the config to the specified mode
change_config() {
if [[ "$1" == "Integrated" ]]; then
echo "$INTEGRATED_CONFIG" > "$CONFIG_FILE"
elif [[ "$1" == "Hybrid" ]]; then
echo "$HYBRID_CONFIG" > "$CONFIG_FILE"
fi
echo "Xorg config changed to $1 mode."
}
# If no arguments are supplied, show the current mode
if [[ -z $1 ]]; then
if [[ "$current_mode" == "# Hybrid mode" ]]; then
echo "Xorg config is Hybrid mode."
elif [[ "$current_mode" == "# Integrated mode" ]]; then
echo "Xorg config is Integrated mode."
else
echo "Unknown mode in Xorg config."
fi
exit 0
fi
# If arguments are supplied, determine the desired mode
case "$1" in
i|integrated|Integrated)
check_mode "Integrated"
change_config "Integrated"
;;
h|hybrid|Hybrid)
check_mode "Hybrid"
change_config "Hybrid"
;;
*)
echo "Invalid argument. Use 'i', 'integrated', or 'Integrated' for Integrated mode, and 'h', 'hybrid', or 'Hybrid' for Hybrid mode."
exit 1
;;
esac
# Ask user if they want to log out to apply changes
read -p "Configuration changed. Do you want to log out to apply settings? (y/n): " response
if [[ "$response" == "y" ]]; then
systemctl restart sddm
fi