Skip to content

Commit 7895d41

Browse files
committedApr 24, 2018
xrandr, grub sections and others fixes v0.9.11
1 parent 93dbf4a commit 7895d41

8 files changed

+159
-64
lines changed
 

‎CHANGELOG.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
### Change Log
2-
*( 22/04/13 ) v0.9.10*
2+
*( 2018/04/24 ) v0.9.11*
3+
- Add a options config file editable by nvidia-prime-ui because some users seems to have big trouble with grub config. Options file default sample is send with comment.
4+
- options are :
5+
- delay: allow to add a user's session delay before launching xrandr command (default 5).
6+
- intel_nodelay: start intel user's session without the configured delay (intel usually doesn't need it).
7+
- cfg_grub: enable/disable check and config (default 1).
8+
- cfg_modeset: enable/disable modeset config (if cfg_grub is set to 1) (default 1).
9+
- nv_modeset: set nvidia modeset (grub section) to set (1) or unset (0) (default 1).
10+
- font_style: nvidia-prime-ui brighness (dark/bright background.) (default 0)
11+
- Rewrote grub config section to be more intuitive. It separatly add modeset and 'nouveau' blacklist. Modeset could be change to 0 or 1 thruough options config file (default is 1).
12+
- Review xrandr auto config section to add offline displays at session manager start when nvidia option is set.
13+
- Add a report.sample in markdown to fill in issue reports.
14+
15+
16+
*( 2018/04/22 ) v0.9.10*
317
- Nvidia-prime-select was untested on multi display. It appeared that actual xrandr detection and sets failed, also display.prime was needed more delay before lauching because of xramdr monitors.xml file sets conflict.
418
- Above is fixed (hopefully), there's still a strange wallpaper behaviour diplayed in double on my laptop desktop. Please, report if you have the same issue.
519
- Just realize, I forgot to update /etc/modprobe.d to blacklist nouveau driver. Fixed (thanks to Tim).
6-
- Note: laptop is not my default machine, and I can't figure out all possible issues by my self, or wait, like it actually the case, my PC's mother board to die to disover them.
20+
- Note: laptop is not my default machine, and I can't figure out all possible issues by my self, or wait, like it actually the case, my PC's mother board to die to discover them.
721

8-
*( 18/04/13 ) v0.9.9*
22+
*( 2018/04/13 ) v0.9.9*
923
- Importante change done. Look's more like a complete rewrite.
1024
- NEW USER: nothing special, just type as superuser or admin : (sudo) make install.
1125
- OLD USER:

‎Makefile

+5-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ install:
1313
install -Dm644 -t $(INSTALL_DIR)/ xorg.nvidia.conf
1414
install -Dm644 -t $(INSTALL_DIR)/ xorg.intel.conf
1515
install -Dm644 -t $(INSTALL_DIR)/ library.conf
16+
install -Dm644 -t $(INSTALL_DIR)/ options.conf
17+
install -Dm644 -t $(INSTALL_DIR)/ report.sample
1618
install -Dm644 -t $(INSTALL_DIR)/ nvidia-prime.desktop
1719
install -Dm644 -t $(INSTALL_DIR)/ nvidia-session.desktop
1820
install -Dm644 -t /usr/share/pixmaps/ nvidia-prime.png
@@ -27,6 +29,8 @@ update:
2729
install -C -Dm755 -t /usr/sbin/ nvidia-prime-select
2830
install -C -Dm644 -t $(INSTALL_DIR)/ xorg.nvidia.conf
2931
install -C -Dm644 -t $(INSTALL_DIR)/ xorg.intel.conf
32+
install -Dm644 -t $(INSTALL_DIR)/ options.conf
33+
install -Dm644 -t $(INSTALL_DIR)/ report.sample
3034
install -C -Dm644 -t $(INSTALL_DIR)/ nvidia-prime.desktop
3135
install -C -Dm644 -t $(INSTALL_DIR)/ nvidia-session.desktop
3236
install -Dm644 -t /usr/share/pixmaps/ nvidia-prime.png
@@ -36,21 +40,10 @@ update:
3640
sh ./changelog.sh
3741

3842
uninstall:
39-
# new
40-
# rm -rf $(INSTALL_DIR)
41-
# rm -f /usr/sbin/nvidia-prime-select
42-
# rm -f /usr/bin/nvidia-prime-ui
43-
# rm -f /usr/share/pixmaps/nvidia-prime.png
44-
# rm -f /usr/share/applications/nvidia-prime-ui.desktop
45-
# rm -f /usr/share/polkit-1/actions/com.github.pkexec.nvidia-prime-*
46-
# rm -f /etc/X11/xorg.conf
47-
# old (will be remove in next upload)
48-
systemctl disable nvidia-prime.service
4943
rm -rf $(INSTALL_DIR)
5044
rm -f /usr/sbin/nvidia-prime-select
5145
rm -f /usr/bin/nvidia-prime-ui
5246
rm -f /usr/share/pixmaps/nvidia-prime.png
5347
rm -f /usr/share/applications/nvidia-prime-ui.desktop
54-
rm -f /usr/lib/systemd/system/nvidia-prime.service
5548
rm -f /usr/share/polkit-1/actions/com.github.pkexec.nvidia-prime-*
56-
rm -f /etc/X11/xinit/xinitrc.d/nvidia
49+
# rm -f /etc/X11/xorg.conf

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Big mistake in repos upload :s. Forgot to send library.conf with last upgrade. M
3737
### 2018-04-22
3838
Multi display issue, see **CHANGELOG.md**.
3939

40+
### 2018-04-24
41+
Added options config file, report.sample and some fixes to grub and xrandr sections. See **CHANGELOG.md**.
42+
4043
--------------
4144

4245
# Usage

‎nvidia-prime-select

+56-37
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,55 @@ nv_drv_32='/usr/lib/nvidia'
3838
nv_drv_64='/usr/lib64/nvidia'
3939
nv_xorg_path='/usr/lib64/nvidia/xorg'
4040
## check any custom dirs for nvidia librairies linking
41-
if [ -s $install_dir/library.conf ]; then
41+
if [[ -s $install_dir/library.conf ]]; then
4242
## TODO Here special distro library config could take place.
4343
## test library conf content before loading.
4444
if [ $(cat $install_dir/library.conf| sed -En "s/^(.*)='(.*)'$/\2/g;p"| grep -c .) -gt 0 ]; then
4545
. $install_dir/library.conf
4646
fi
4747
fi
48-
## FIXME
48+
## default options (have to be manual set/reset in options.conf of by nvidia-prime-ui)
49+
delay=5
50+
intel_nodelay=1
51+
cfg_grub=1
52+
cfg_modeset=1
53+
nv_modeset=0
54+
55+
if [[ -s $install_dir/options.conf ]]; then
56+
. $install_dir/options.conf
57+
fi
58+
current_display=$(xrandr --current| grep "connected"| grep "[0-9]\{3,4\}[x]"| sed -n "s/\ (.*$//p")
59+
connected_display=( "$(xrandr --current| grep -w "connected"| sed -En "s|^(.*)\ (\(.*)$|\1|p")" )
60+
61+
## FIXME ?
4962
## grub section have to be filtered in case of distros specifics.
5063
grub_config(){
51-
## look at /proc/version to detect distro variant.
52-
boot_key='/boot/vmlinuz-'$(uname -r)
53-
if [ $(cat /boot/grub2/grub.cfg| egrep -c "^.*$boot_key.*nvidia-drm.modeset=1.*$") -eq 0 ]; then
54-
if [ $(cat /boot/grub2/grub.cfg| egrep -c "^.*$boot_key.*blacklist=nouveau.*$") -eq 0 ]; then
55-
blacklist=' nouveau.modeset=0 rd.driver.blacklist=nouveau'
56-
fi
57-
modset='nvidia-drm.modeset=1'$blacklist
58-
## add nouveau blacklist to modeproe.d conigs list.
59-
if ! [[ -s /etc/modprobe.d/blacklist-nouveau.conf ]]; then
60-
echo "blacklist nouveau" > /etc/modprobe.d/blacklist-nouveau.conf
64+
if [ $cfg_grub -gt 0 ]; then
65+
## look at /proc/version to detect distro variant.
66+
boot_key='/boot/vmlinuz-'$(uname -r)
67+
modeset_check=$(cat /boot/grub2/grub.cfg| egrep -c "^.*$boot_key.*nvidia-drm.modeset=.*$")
68+
if [ $(cat /boot/grub2/grub.cfg| egrep -c "^.*$boot_key.*nvidia-drm.modeset=$nv_modeset.*$") -eq 0 ]; then
69+
if [ $(cat /boot/grub2/grub.cfg| egrep -c "^.*$boot_key.*blacklist=nouveau.*$") -eq 0 ]; then
70+
blacklist=' nouveau.modeset=0 rd.driver.blacklist=nouveau'
71+
fi
72+
if [ $cfg_modeset -gt 0 ]; then
73+
modset='nvidia-drm.modeset='$nv_modeset$blacklist
74+
else
75+
modset=$blacklist
76+
fi
77+
## add nouveau blacklist to modeproe.d configs list.
78+
if ! [[ -s /etc/modprobe.d/blacklist-nouveau.conf ]]; then
79+
echo "blacklist nouveau" > /etc/modprobe.d/blacklist-nouveau.conf
80+
fi
81+
if [ $modeset_check -gt 0 ]; then
82+
sed -Eni -e "s|(linux.*$boot_key.*ro) (nvidia-drm.modeset=[0-9])(.*)$|\1 $modset\3|g;p" /boot/grub2/grub.cfg
83+
else
84+
sed -Eni -e "s|(linux.*$boot_key.*ro)(.*)$|\1 $modset \2|g;p" /boot/grub2/grub.cfg
85+
fi
86+
reboot_text='Grub has been modified for Nvidia Prime modesetting.\nPLease reboot the system for changes to take effect.'
6187
fi
62-
sed -Eni -e "s|(linux.*$boot_key.*ro)(.*)$|\1 $modset \2|g;p" /boot/grub2/grub.cfg
63-
reboot_text='Grub has been modified for Nvidia Prime modesetting.\nPLease reboot the system for changes to take effect.'
6488
fi
6589
}
66-
## First of all, configure grub for modesetting and blacklist all nouveau drivers.
67-
grub_config
68-
current_display=$(xrandr --current| grep "connected"| grep "[0-9]\{3,4\}[x]"| sed -n "s/\ (.*$//p")
69-
connected_display=( "$(xrandr --current| grep -w "connected"| sed -En "s|^(.*)\ (\(.*)$|\1|p")" )
70-
7190
bus_id_query(){
7291
## detect and config pci ids.
7392
bus_vga_list=$(lspci | grep VGA| awk '{print $1" "$5}'| sed -En "s|^.([0-9])\:.([0-9])\.([0-9])\ (.*)$|bus_\L\4=\1:\2:\3|p")
@@ -88,23 +107,10 @@ clean_files() {
88107
fi
89108
done
90109
}
91-
92110
xrandr_outputs(){
93111
## xrandr have to be set as user wishes to give to script proper xrandr sets.
94112
## This is mandatory.
95113
# conf=nvidia
96-
unset scrn
97-
unset def
98-
if [[ $conf == nvidia ]]; then
99-
xrandr_source='NVIDIA-0'
100-
xrandr_sink='modesetting'
101-
fi
102-
if [[ $conf == nvidia ]]; then
103-
xrandr_init="xrandr --setprovideroutputsource $xrandr_sink $xrandr_source --auto --output VGA-0 --off"
104-
else
105-
xrandr_init=''
106-
fi
107-
echo -e "#! /bin/bash\n\n#sleep 5\n$xrandr_init" > $install_dir/xinitrc.prime
108114
ifs=$IFS
109115
IFS=$(echo -en "\n\b")
110116
for _dsp in ${connected_display[@]}; do
@@ -144,17 +150,29 @@ xrandr_outputs(){
144150
else
145151
disable_output=' --output '$connected_output' --off'
146152
_outputs+=($disable_output)
153+
_disabled+=($disable_output)
147154
fi
148155
done
149156
if [[ $conf == nvidia ]]; then
150157
if [ $(echo -e "${_outputs[*]}"| grep -c "VGA") -eq 0 ]; then
151158
disable_output='--output VGA-0 --off'
152159
_outputs+=($disable_output)
160+
_disabled+=($disable_output)
153161
fi
154162
fi
155163
IFS=$ifs
156164
xrandr_config="xrandr${_outputs[*]}"
157-
165+
if [[ $conf == nvidia ]]; then
166+
xrandr_source='NVIDIA-0'
167+
xrandr_sink='modesetting'
168+
fi
169+
if [[ $conf == nvidia ]]; then
170+
# xrandr_init="xrandr --setprovideroutputsource $xrandr_sink $xrandr_source --auto --output VGA-0 --off"
171+
xrandr_init="xrandr --setprovideroutputsource $xrandr_sink $xrandr_source --auto ${_disabled[*]}"
172+
else
173+
xrandr_init=''
174+
fi
175+
echo -e "#! /bin/bash\n\n#sleep $delay\n$xrandr_init" > $install_dir/xinitrc.prime
158176
echo -e "#! /bin/bash\n\nsleep $delay\n$xrandr_config\n" > $install_dir/display.prime
159177
if [ $(stat -c %a $install_dir/display.prime) -ne 755 ]; then
160178
chmod 755 $install_dir/display.prime
@@ -163,7 +181,6 @@ xrandr_outputs(){
163181
chmod 755 $install_dir/xinitrc.prime
164182
fi
165183
}
166-
167184
session_manager(){
168185
home=/home/$(ls -l "$(pwd)"| cut -d' ' -f3 | sed -n "2p")
169186
## configure each session manager if deteed: gdm kdm sddm lightdm
@@ -278,7 +295,7 @@ display_config(){
278295
}
279296
go_for_nvidia(){
280297
clean_files
281-
delay=5
298+
# delay=5
282299
ctrl_key=nvidia
283300
display_config
284301
abi_crtl
@@ -290,7 +307,7 @@ go_for_nvidia(){
290307
}
291308
go_for_intel(){
292309
clean_files
293-
delay=5
310+
if [ $intel_nodelay -eq 1 ]; then delay=0; else delay=5; fi
294311
ctrl_key=intel
295312
display_config
296313
}
@@ -301,6 +318,8 @@ go_default(){
301318
printf '/usr/lib' > $nvidia32_lib_file
302319
fi
303320
}
321+
## configure grub for modesetting and blacklist all nouveau drivers.
322+
grub_config
304323
bus_id_query
305324
current=$(file -p /etc/X11/xorg.conf| sed -En "s|^.*xorg.(.*).conf$|\1|p")
306325
if [[ -s /var/log/Xorg.0.log ]]; then
@@ -310,7 +329,7 @@ case $1 in
310329
default ) go_default ;;
311330
nvidia ) go_for_nvidia ;;
312331
intel ) go_for_intel ;;
313-
test) xrandr_outputs; exit 0;;
332+
# test) xrandr_outputs; exit 0;;
314333
*|help )
315334
printf "Usage:\t$(basename $0 ) intel|nvidia|default\n\n"
316335
printf "\tintel\t\tSwitch to Intel GPU.\n"

‎nvidia-prime-ui

+44-11
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@
2222
## TODO
2323
# indiquer la précédence de monitor.xml généré par l'ui de xrandr.
2424

25-
26-
# color setup TODO < color.conf
25+
vn='<span weight=\"normal\">'
26+
vb='<span weight=\"bold\">'
27+
if [[ -s /etc/nvidia-prime/options.conf ]]; then
28+
. /etc/nvidia-prime/options.conf
29+
if [ $font_style -gt 0 ]; then
30+
## clear background
31+
vn='<span color=\"#00A400\" weight=\"normal\">'
32+
vb='<span color=\"#00A400\" weight=\"bold\">'
33+
else
34+
## dark background
35+
vn='<span color=\"#005400\" weight=\"normal\">'
36+
vb='<span color=\"#005400\" weight=\"bold\">'
37+
fi
38+
fi
2739
end='</span>'
28-
vn='<span color=\"#005400\" weight=\"normal\">'
29-
vb='<span color=\"#005400\" weight=\"bold\">'
3040
j='<span color=\"#FF6800\">'
3141
rBB='<span color=\"#FF3300\" font=\"20\">'
3242
## prime_setup
@@ -37,6 +47,7 @@ menu_prime_01="Set Prime to Intel device"
3747
menu_prime_02="Set Prime to Nvidia device"
3848
menu_prime_03="Edit Libraries config file"
3949
menu_prime_04="Edit current Xorg config file"
50+
menu_prime_05="Edit options config file"
4051
# ref
4152
m_prime_01="intel"
4253
m_prime_02="nvidia"
@@ -46,7 +57,20 @@ wrn_prime_02="\nYou may now restart the user session to take effect."
4657
# nvidia-prime-select path and files
4758
xorg_path=/etc/nvidia-prime
4859
lib_conf=/etc/nvidia-prime/library.conf
60+
opt_conf=/etc/nvidia-prime/options.conf
4961
## su cmd is currently manages by polkit
62+
## setup color, grub, user's xrandr options.
63+
edit_options(){
64+
edit_options_conf=$(zenity --width=500 --height=400 --title="options conf editor" --icon-name=nvidia-prime \
65+
--text-info --editable --filename="$opt_conf" --checkbox="Confirm to overwrite" \
66+
--text="$vb\\Edit nvidia-prime-select and GUI options.$end")
67+
if [ $? = 0 ]; then
68+
pkexec sh -c "echo -e \"$edit_options_conf\" > $opt_conf"
69+
notify-send -t 5000 -u low "Options data saved."
70+
fi
71+
bash -c nvidia-prime-ui
72+
exit 0
73+
}
5074
edit_conf(){
5175
edit_lib_conf=$(zenity --width=500 --height=400 --title="libraries conf editor" --icon-name=nvidia-prime \
5276
--text-info --editable --filename="$lib_conf" --checkbox="Confirm to overwrite" \
@@ -75,15 +99,20 @@ edit_xorg(){
7599
}
76100
setup_prime(){
77101
if [[ -s $HOME/.config/monitors.xml ]]; then
78-
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.$end"
102+
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"
79103
fi
80104
xrandr_msg="$vb\n\nCheck your display settings before restart.$end"
81105
zenity --height=100 --title="nvidia-prime-select setup" --question --no-wrap \
82106
--icon-name=nvidia-prime --text="$vb$(printf "$wrn_prime_01$wrn_prime_02" "$_prime")$prev_conf$xrandr_msg$end" \
83107
--cancel-label='Cancel' --ok-label='Setup'
84-
if [ $? = 1 ]; then $0; fi
85-
pkexec /usr/sbin/nvidia-prime-select $_pset
86-
notif_msg=$(printf "Session will restart with %s hardware.\nPlease restart your session." "$_pset")
108+
if [ $? = 0 ]; then
109+
pkexec /usr/sbin/nvidia-prime-select $_pset
110+
notif_msg=$(printf "Session will restart with %s hardware.\nPlease restart your session." "$_pset")
111+
else
112+
bash -c nvidia-prime-ui
113+
exit 0
114+
fi
115+
87116
}
88117
#root_id
89118
unset setup_list setup_option _pset
@@ -92,6 +121,7 @@ setup_option=(
92121
"$menu_prime_02;$m_prime_02;/etc/X11/xorg.conf"
93122
"$menu_prime_03;;"
94123
"$menu_prime_04;;"
124+
"$menu_prime_05;;"
95125
)
96126
n=1
97127
for p_set in "${setup_option[@]}"; do
@@ -111,8 +141,8 @@ else
111141
prime_msg="$prime_msg_01\nNo device is currently set."
112142
fi
113143

114-
menu_prime=$(zenity --width=340 --list --radiolist --hide-header \
115-
--title="Zenvidia prime setup" --text "$vb$prime_msg$end" \
144+
menu_prime=$(zenity --width=340 --list --radiolist --hide-header \
145+
--title="nvidia-prime-select" --text "$vb$prime_msg$end" \
116146
--column "1" --column "2" --column "3" --separator=";" --hide-column=2 \
117147
"${setup_list[@]}" --ok-label='Select' --cancel-label='Exit')
118148
if [ $? = 1 ]; then exit 0; fi
@@ -121,7 +151,10 @@ case $menu_prime in
121151
"2") _pset="nvidia"; _prime="$m_prime_02" ;;
122152
"3") edit_conf ;;
123153
"4") edit_xorg ;;
154+
"5") edit_options ;;
124155
esac
125156
setup_prime
126-
notify-send -t 5000 -u low --icon=nvidia-prime "Nvidia-prime setup applied." "$notif_msg."
157+
if [[ $notif_msg != '' ]]; then
158+
notify-send -t 5000 -u low --icon=nvidia-prime "Nvidia-prime setup applied." "$notif_msg."
159+
fi
127160
exit 0

‎nvidia-prime-ui.desktop

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Name=nvidia-prime
55
Comment=NVIDIA Prime switcher
66
Exec=nvidia-prime-ui
77
Icon=nvidia-prime.png
8-
Categories=Application;Settings;
8+
Categories=Application;System;Settings;
99

‎options.conf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## give some delay at user's session start from 0 to ?.
2+
## (could solve conflict with session monitors.xml file).
3+
delay=5
4+
## avoid delaying for intel session display (delay>0, no delay>1).
5+
intel_nodelay=1
6+
## allow/disallow grub check and config. check>1, don't check>0.
7+
cfg_grub=1
8+
## allow/disallow modeset config in grub. config>1, not config>0.
9+
cfg_modeset=1
10+
## nvidia modeset variable. Define and set>1, define and not set>0.
11+
nv_modeset=1
12+
## set nvidia-prime-ui's display fonts style. Clear>1, Dark>0.
13+
font_style=1

‎report.sample

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### Main:
2+
**distro**: `cat /proc/version`. Help to get distro name and get a tip for possible per distro auto conf.
3+
4+
**session-manager**:
5+
6+
**grub.cfg**: default menuentry 'linux/linux16' whole line. As su or sudo -S prompt, `cat /boot/grub2/grub.cfg| grep "linux.*$(uname -r)"`.
7+
8+
**xrandr providers**: `xrandr --listproviders`, respectively under intel, then nvidia device (if can be started).
9+
- intel:
10+
- nvidia:
11+
12+
**xrandr displays**: `xrandr --query`
13+
- intel:
14+
- nvidia:
15+
16+
### Optional:
17+
**xorg log**: `cat /var/log/Xorg.0.log`
18+
19+
**lsmod**: to get intel, nvidia, bbswitch (if any) loaded modules. `lsmod | grep "nvidia\|bbswitch\|intel"`
20+

0 commit comments

Comments
 (0)
Please sign in to comment.