forked from wildtruc/nvidia-prime-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvidia-prime-ui
executable file
·160 lines (154 loc) · 5.72 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
#! /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
# 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_path=/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 sh -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 sh -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(){
edit_xorg_conf=$(zenity --width=500 --height=400 --title="Xorg $current_set conf editor" \
--icon-name=nvidia-prime --text-info --editable \
--filename="$xorg_path/xorg.$current_set.conf" --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 sh -c "echo -e \"$_xorg_conf\" > $xorg_path/xorg.$current_set.conf"
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;;"
)
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 [ $(file -p /etc/X11/xorg.conf| grep -c "xorg.$pc_msg.conf") -gt 0 ]; then
current_set=$pc_msg
fi
n=$[ $n+1 ]
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