1

OS: Ubuntu 22.10
graphic card: nvidia
monitor: philips

Issue: how to change default gamma after X11 startup.

The gamma command I wish to invoke is either:

xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5

or

xrandr --output DP-0 --gamma 0.6:0.5:0.5

I want to set the gamma to default per above, when my user session starts.

I have attempted:

  1. To invoke a .sh file at startup by adding an entry to the "Startup Applications". This is unsuccessful: the .sh will not invoke. Adding a 10 second delay does nothing.
  2. Editing the file, xinitrc, to add the xgamma or xrandr commands. Also unsuccessful.
  3. Creating a .conf file in user/share/X11/xorg.conf.d Also unsuccessful. This caused my pc not to boot, requiring a recovery session as root, to remove the .conf file.
  4. Creating an .sh file on desktop, and invoking after user session starts. Successful, partly. But this is not default, and the system will over-ride the .sh command upon sleep and invoking other applications. Not the solution I am hoping to achieve.

Any help is sincerely appreciated. Thank you.

Update #1:

As suggested in the comments, I ran this command as a startup application:

sh -c '{ echo "started"; xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5; echo "$?"; echo "ended"; } > /home/user/startupapp.log 2>&1'

Here are the contents of the logs from cat ~/startupapp.log... for the xgamma command:

started
-> Red 1.000, Green 1.000, Blue 1.000 
<- Red 0.600, Green 0.500, Blue 0.500 
0 
ended

And for the xrandr command:

started
0
ended

After invoking the xgamma command, though the log shows the change in gamma, the monitor remains at gamma values 1.00.

Raffa
  • 24,905
  • 3
  • 35
  • 79
rob grune
  • 989
  • 1
  • 8
  • 17
  • I think you should create a desktop file, and in that file let the Exec line point to your shellscript. Put that file into the 'autostart' directory and logout+login or reboot. The following links might help you: [Autostart system where part runs with elevated permissons](https://askubuntu.com/questions/1353879/lubuntu-20-04-run-a-script-at-login-which-executes-in-a-terminal-window/1354182#1354182) and [Rotating the desktop](https://askubuntu.com/questions/1251814/xrandr-command-in-startup-script-has-no-effect-but-script-does-run-and-command/1251882#1251882). – sudodus Feb 11 '23 at 10:24
  • 1
    A startup application runs after X is started and a user session is also started ... So if your script runs in your DE environment, it should run in a startup application as well ... Please paste this in the command field of a new startup application `sh -c '{ echo "started"; xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5; echo "$?"; echo "ended"; } > /home/user/startupapp.log 2>&1'` after changing `user` to your username then logout and back in and show us the output of `cat ~/startupapp.log` ... Do the same for the `xrandr` command as well. – Raffa Feb 11 '23 at 14:38
  • @Raffa. Many thanks for reply. Excuse my delay. – rob grune Feb 15 '23 at 00:51
  • @Raffa. Here are the contents of the logs... for the xgamma command.. started -> Red 1.000, Green 1.000, Blue 1.000 <- Red 0.600, Green 0.500, Blue 0.500 0 ended for the xrandr command... started 0 ended .... after invoking the xgamma command, though the log shows the change in gamma, the monitor remains at gamma values 1.00 – rob grune Feb 15 '23 at 00:53
  • @ Raffa.. as you see, I am unable to format my reply. any tips? – rob grune Feb 15 '23 at 00:58
  • It appears both commands are successfully run ... I suggest you start investigating the monitor side ... e.g. builtin color profile or settings ... Probably adding a delay before the command e.g. `sh -c 'sleep 20; echo ...'` might help. – Raffa Feb 15 '23 at 07:31
  • @ Raffa. thanks for reply. Agree. Something in my system is over-riding the xgamma command. The trouble is, I don't know what. Might you know... Has Linux some means to log everything at boot to startup to the moment the desktop screen appears? If so, where could I find this? – rob grune Feb 15 '23 at 13:56
  • You could try searching the systemd journal e.g. `journalctl | grep -i "xgamma"` and `journalctl -b` for boot logs. – Raffa Feb 16 '23 at 17:04
  • @ Raffa. Many thanks again for your reply. Very helpful as a tutorial. I discovered the logs are messy, and the issue seems to be with Nvidia (as far as I can tell currently). At startup, I removed the xgamma script, and replaced it with a command to invoke the Nvidia-settings (after editing the settings) with a 3 second delay. This works on startup, but when the system awakes from a sleep, the system defaults back to the gamma 1.0 values. I don't know if this is a bug with Nvidia or my system. When I had the idea to alter gamma, I had no inklings this would be so complicated to accomplish. – rob grune Feb 19 '23 at 01:05

0 Answers0