-
Notifications
You must be signed in to change notification settings - Fork 15
/
nvidia-prime-ui
executable file
·179 lines (173 loc) · 6.36 KB
/
nvidia-prime-ui
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#! /bin/bash
# License:
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
## You can redistribute it as you wish : GPL v3
## author : wildtruc@noneltd.net
## TODO
# XXX reconfigurer le xml xrandr
# XXX créer un UI pour les fichiers de config.
# XXX indiquer le dir source des librairies detectées pour l'UI de config de la source des ficheirs. (use 'find)')
# indiquer la précédence de monitor.xml généré par l'ui de xrandr.
vn='<span weight=\"normal\">'
vb='<span weight=\"bold\">'
if [[ -s /etc/nvidia-prime/options.conf ]]; then
. /etc/nvidia-prime/options.conf
if [ $font_style -gt 0 ]; then
## clear background
vn='<span color=\"#00A400\" weight=\"normal\">'
vb='<span color=\"#00A400\" weight=\"bold\">'
else
## dark background
vn='<span color=\"#005400\" weight=\"normal\">'
vb='<span color=\"#005400\" weight=\"bold\">'
fi
fi
end='</span>'
j='<span color=\"#FF6800\">'
rBB='<span color=\"#FF3300\" font=\"20\">'
## prime_setup
# first ui msg.
prime_msg_01="Select the Prime setup you would like to use:"
prime_msg_02="Default is currently set to $j%s$end."
menu_prime_01="Set Prime to Intel device"
menu_prime_02="Set Prime to Nvidia device"
menu_prime_03="Edit Libraries config file"
menu_prime_04="Edit current Xorg config file"
menu_prime_05="Edit options config file"
# ref
m_prime_01="intel"
m_prime_02="nvidia"
# last wrn msg
wrn_prime_01="Prime will be set to $j%s$end."
wrn_prime_02="\nYou may now restart the user session to take effect."
# nvidia-prime-select path and files
xorg_prime=/etc/nvidia-prime
lib_conf=/etc/nvidia-prime/library.conf
opt_conf=/etc/nvidia-prime/options.conf
## su cmd is currently manages by polkit
## setup color, grub, user's xrandr options.
edit_options(){
edit_options_conf=$(zenity --width=500 --height=400 --title="options conf editor" --icon-name=nvidia-prime \
--text-info --editable --filename="$opt_conf" --checkbox="Confirm to overwrite" \
--text="$vb\\Edit nvidia-prime-select and GUI options.$end")
if [ $? = 0 ]; then
pkexec bash -c "echo -e \"$edit_options_conf\" > $opt_conf"
notify-send -t 5000 -u low "Options data saved."
fi
bash -c nvidia-prime-ui
exit 0
}
edit_conf(){
edit_lib_conf=$(zenity --width=500 --height=400 --title="libraries conf editor" --icon-name=nvidia-prime \
--text-info --editable --filename="$lib_conf" --checkbox="Confirm to overwrite" \
--text="$vb\\Edit libraries path to fit your system install.$end")
if [ $? = 0 ]; then
if [ $(printf "$edit_lib_conf"| sed -En "s/^(.*)='(.*)'$/\2/g;p"| grep -c .) -gt 0 ]; then
pkexec bash -c "echo -e \"$edit_lib_conf\" > $lib_conf"
notify-send -t 5000 -u low "libraries data saved."
fi
fi
bash -c nvidia-prime-ui
exit 0
}
edit_xorg(){
if [ $(file /etc/X11/xorg.conf | grep -c "$xorg_prime.*$current_set") -eq 0 ]; then
xorg_file=$xorg_prime/$(file /etc/X11/xorg.conf | sed -n "s/^.*\///p")
else
xorg_file=$xorg_prime/xorg.$current_set.conf
fi
edit_xorg_conf=$(zenity --width=500 --height=400 --title="Xorg $current_set conf editor" \
--icon-name=nvidia-prime --text-info --editable \
--filename="$xorg_file" --checkbox="Confirm to overwrite" \
--text="$vb\\Edit current xorg conf as appropriate to fit your needs.$end")
if [ $? = 0 ]; then
_xorg_conf=$(echo -e "$edit_xorg_conf"| sed -En 's|\"|\\"|g;p')
pkexec bash -c "echo -e \"$_xorg_conf\" > $xorg_file"
notify-send -t 5000 -u low "Xorg conf file saved."
fi
bash -c nvidia-prime-ui
exit 0
}
setup_prime(){
if [[ -s $HOME/.config/monitors.xml ]]; then
prev_conf="\n\nNotice$vn: Display looks already configured by$j xrandr$end session tool UI.\nUI settings take precedence over$j nvidia-prime-select$end auto set.\nBe aware it could create conflicts at session restart (blank screen).$end"
fi
xrandr_msg="$vb\n\nCheck your display settings before restart.$end"
zenity --height=100 --title="nvidia-prime-select setup" --question --no-wrap \
--icon-name=nvidia-prime --text="$vb$(printf "$wrn_prime_01$wrn_prime_02" "$_prime")$prev_conf$xrandr_msg$end" \
--cancel-label='Cancel' --ok-label='Setup'
if [ $? = 0 ]; then
pkexec /usr/sbin/nvidia-prime-select $_pset
notif_msg=$(printf "Session will restart with %s hardware.\nPlease restart your session." "$_pset")
else
bash -c nvidia-prime-ui
exit 0
fi
}
#root_id
unset setup_list setup_option _pset
#setup_option=(
#"$menu_prime_01;$m_prime_01;/etc/X11/xorg.conf"
#"$menu_prime_02;$m_prime_02;/etc/X11/xorg.conf"
#"$menu_prime_03;;"
#"$menu_prime_04;;"
#"$menu_prime_05;;"
#)
setup_option=(
"$menu_prime_01;$m_prime_01"
"$menu_prime_02;$m_prime_02"
"$menu_prime_03;"
"$menu_prime_04;"
"$menu_prime_05;"
)
n=1
for p_set in "${setup_option[@]}"; do
pc_set=$(printf "$p_set"|cut -d';' -f1)
pc_msg=$(printf "$p_set"|cut -d';' -f2)
# pc_file=$(printf "$p_set"|cut -d';' -f3)
setup_list+=("false" "$n" "$pc_set")
if [[ $pc_msg != '' ]]; then
if [ $(file -p /etc/X11/xorg.conf| grep -c "xorg.$pc_msg.conf") -gt 0 ]; then
current_set=$pc_msg
fi
else
current_set=$(cat /etc/X11/xorg.conf| grep -v '#'| sed -En "s/^.*Screen.*0.*\"(.*)_screen\".*$/\1/p")
fi
((n++))
done
if [[ "$current_set" ]]; then
prime_msg="$prime_msg_01\n$(printf "$prime_msg_02" "$current_set")"
else
prime_msg="$prime_msg_01\nNo device is currently set."
fi
menu_prime=$(zenity --width=340 --list --radiolist --hide-header \
--title="nvidia-prime-select" --text "$vb$prime_msg$end" \
--column "1" --column "2" --column "3" --separator=";" --hide-column=2 \
"${setup_list[@]}" --ok-label='Select' --cancel-label='Exit')
if [ $? = 1 ]; then exit 0; fi
case $menu_prime in
"1") _pset="intel"; _prime="$m_prime_01" ;;
"2") _pset="nvidia"; _prime="$m_prime_02" ;;
"3") edit_conf ;;
"4") edit_xorg ;;
"5") edit_options ;;
esac
setup_prime
if [[ $notif_msg != '' ]]; then
notify-send -t 5000 -u low --icon=nvidia-prime "Nvidia-prime setup applied." "$notif_msg."
fi
exit 0