2

What is the best place to add a mode with xrandr?

As of now, I added

xrandr --newmode "1344x744_60.00"   80.75  1344 1408 1544 1744  744 747 757 773 -hsync +vsync
xrandr --newmode "1344x768_60.00"   84.00  1344 1416 1552 1760  768 771 781 798 -hsync +vsync
xrandr --addmode DP-2 "1344x744_60.00" 
xrandr --addmode DP-2 "1344x768_60.00" 

to my ~/.bashrc, but this is obviously not the best place, as every time I launch a bash process it tries to add modes. So far, it only throws some errors (see below tl;dr), but it is harmless, I guess.

Perhaps .gnomerc is appropriate, although I guess if I start an xrdp session the mode may not be available.

Related:

  1. How to run scripts on start up?
  2. https://unix.stackexchange.com/questions/120291/how-to-get-external-monitor-resolution-set-by-xrandr-to-persist

EDIT: It seems ~/.xprofile may be a good place for these settings. I am not sure it works well with vino-server, which I need.

EDIT 2: This suggests using ~/.xinitrc. But it may be outdated.


TL;DR: Errors I get:

  1. When connecting from a text terminal (e.g., ssh)

       Can't open display
       Can't open display
       Can't open display
       Can't open display
    
  2. When starting a graphic terminal when the modes were already added

       X Error of failed request:  BadName (named color or font does not exist)
         Major opcode of failed request:  140 (RANDR)
         Minor opcode of failed request:  16 (RRCreateMode)
         Serial number of failed request:  27
         Current serial number in output stream:  27
       X Error of failed request:  BadName (named color or font does not exist)
         Major opcode of failed request:  140 (RANDR)
         Minor opcode of failed request:  16 (RRCreateMode)
         Serial number of failed request:  27
         Current serial number in output stream:  27
    
  • Some discussion of this issue here: https://askubuntu.com/q/754231/57576 – andrew.46 Aug 22 '20 at 04:53
  • @andrew.46 - Thanks for the subtlety... I would say it is a dupe more than "Some discussion of this issue". I will wait until my next opportunity to reboot (so it doesn't interfere with my work), and if the solution works as expected I would close this one as a duplicate. Also relevant the link posted there https://wiki.ubuntu.com/X/Config/Resolution#Setting_xrandr_changes_persistently – sancho.s ReinstateMonicaCellio Aug 22 '20 at 10:06
  • @andrew.46 - Due to the pandemics I am working remotely, with vino-server and TigerVNC under Win10 as a client. I had implemented the .xprofile method. I just rebooted for the first time since this posting. At first I couldn't start a VNS session, and it turned out that vino-server did not start. So I tried renaming .xprofile, rebooting, and now vino-server started, and I could start a VNC session as usual. Then I issued the commands from a terminal. – sancho.s ReinstateMonicaCellio Aug 27 '20 at 09:43
  • @andrew.46 - I am not certain about the causality, and I cannot test now; it can take a couple of hours of tinkering. I have no time, but above all I cannot risk losing VNC connectivity. In my experience, vino-server is somewhat fragile, and I have almost no access to the console. – sancho.s ReinstateMonicaCellio Aug 27 '20 at 09:43

1 Answers1

0

If you are using X11, you can add the mode to a config file in /etc/X11/xorg.conf.d/. Name it something like 99-modes.conf.

Section "Modes"
   Identifier "modes"
   Modeline "1368x768"  85.86  1368 1440 1584 1800  768 769 772 795  -HSync +Vsync
EndSection

If the above doesn't work, you'll need to expand the config.

Section "Monitor"
   Identifier "monitor"
   Modeline "1368x768"  85.86  1368 1440 1584 1800  768 769 772 795  -HSync +Vsync
EndSection

Section "Device" Identifier "card" EndSection

Section "Screen" Identifier "screen" Device "card" Monitor "monitor" SubSection "Display" Modes "1368x768" EndSubSection EndSection

See also:

xiota
  • 4,849