How to force a virtual monitor to be always secondary?











up vote
2
down vote

favorite












Created a virtual display so VNC can work when there is no physical display:



/usr/share/X11/xorg.conf.d/20-intel.conf:



Section "Device"
Identifier "intelgpu0"
Driver "intel"
Option "VirtualHeads" "2"
EndSection


Startup script:





#!/bin/bash

/usr/bin/xrandr -d :0 --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
/usr/bin/xrandr -d :0 --addmode VIRTUAL1 "1600x900_60.00"
/usr/bin/xrandr -d :0
killall -3 gnome-shell


As in https://askubuntu.com/a/1062890/391744



But when plugging in the real monitors they are appearing as secondaries. They show the uninteresting part with no graphical programs visible and no panels/docks.



How to configure it that any non-virtual monitor would automatically become a primary?



For the moment I've only come up with this addition to the script to poll the connected monitors with xrandr:



(
while [ 1 ]; do
xrandr_out="$(LANG=C /usr/bin/xrandr -d :0)"
# If VIRTUAL is primary.
if egrep -q '^VIRTUAL[0-9]+[[:space:]]+connected[[:space:]]+primary' < <(printf '%sn' "$xrandr_out"); then
# Find non-virtual that is connected.
non_virt="$(sed -nre 's/^([^[:space:]]+)[[:space:]]+connected.*/1/p' < <(printf '%sn' "$xrandr_out" | grep -v ^VIRTUAL) | head -n1)"
if [ -n "$non_virt" ]; then
xrandr -d :0 --output "$non_virt" --primary --pos 0x0
fi
fi
sleep 10
done
) & disown









share|improve this question




























    up vote
    2
    down vote

    favorite












    Created a virtual display so VNC can work when there is no physical display:



    /usr/share/X11/xorg.conf.d/20-intel.conf:



    Section "Device"
    Identifier "intelgpu0"
    Driver "intel"
    Option "VirtualHeads" "2"
    EndSection


    Startup script:





    #!/bin/bash

    /usr/bin/xrandr -d :0 --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
    /usr/bin/xrandr -d :0 --addmode VIRTUAL1 "1600x900_60.00"
    /usr/bin/xrandr -d :0
    killall -3 gnome-shell


    As in https://askubuntu.com/a/1062890/391744



    But when plugging in the real monitors they are appearing as secondaries. They show the uninteresting part with no graphical programs visible and no panels/docks.



    How to configure it that any non-virtual monitor would automatically become a primary?



    For the moment I've only come up with this addition to the script to poll the connected monitors with xrandr:



    (
    while [ 1 ]; do
    xrandr_out="$(LANG=C /usr/bin/xrandr -d :0)"
    # If VIRTUAL is primary.
    if egrep -q '^VIRTUAL[0-9]+[[:space:]]+connected[[:space:]]+primary' < <(printf '%sn' "$xrandr_out"); then
    # Find non-virtual that is connected.
    non_virt="$(sed -nre 's/^([^[:space:]]+)[[:space:]]+connected.*/1/p' < <(printf '%sn' "$xrandr_out" | grep -v ^VIRTUAL) | head -n1)"
    if [ -n "$non_virt" ]; then
    xrandr -d :0 --output "$non_virt" --primary --pos 0x0
    fi
    fi
    sleep 10
    done
    ) & disown









    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Created a virtual display so VNC can work when there is no physical display:



      /usr/share/X11/xorg.conf.d/20-intel.conf:



      Section "Device"
      Identifier "intelgpu0"
      Driver "intel"
      Option "VirtualHeads" "2"
      EndSection


      Startup script:





      #!/bin/bash

      /usr/bin/xrandr -d :0 --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
      /usr/bin/xrandr -d :0 --addmode VIRTUAL1 "1600x900_60.00"
      /usr/bin/xrandr -d :0
      killall -3 gnome-shell


      As in https://askubuntu.com/a/1062890/391744



      But when plugging in the real monitors they are appearing as secondaries. They show the uninteresting part with no graphical programs visible and no panels/docks.



      How to configure it that any non-virtual monitor would automatically become a primary?



      For the moment I've only come up with this addition to the script to poll the connected monitors with xrandr:



      (
      while [ 1 ]; do
      xrandr_out="$(LANG=C /usr/bin/xrandr -d :0)"
      # If VIRTUAL is primary.
      if egrep -q '^VIRTUAL[0-9]+[[:space:]]+connected[[:space:]]+primary' < <(printf '%sn' "$xrandr_out"); then
      # Find non-virtual that is connected.
      non_virt="$(sed -nre 's/^([^[:space:]]+)[[:space:]]+connected.*/1/p' < <(printf '%sn' "$xrandr_out" | grep -v ^VIRTUAL) | head -n1)"
      if [ -n "$non_virt" ]; then
      xrandr -d :0 --output "$non_virt" --primary --pos 0x0
      fi
      fi
      sleep 10
      done
      ) & disown









      share|improve this question















      Created a virtual display so VNC can work when there is no physical display:



      /usr/share/X11/xorg.conf.d/20-intel.conf:



      Section "Device"
      Identifier "intelgpu0"
      Driver "intel"
      Option "VirtualHeads" "2"
      EndSection


      Startup script:





      #!/bin/bash

      /usr/bin/xrandr -d :0 --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
      /usr/bin/xrandr -d :0 --addmode VIRTUAL1 "1600x900_60.00"
      /usr/bin/xrandr -d :0
      killall -3 gnome-shell


      As in https://askubuntu.com/a/1062890/391744



      But when plugging in the real monitors they are appearing as secondaries. They show the uninteresting part with no graphical programs visible and no panels/docks.



      How to configure it that any non-virtual monitor would automatically become a primary?



      For the moment I've only come up with this addition to the script to poll the connected monitors with xrandr:



      (
      while [ 1 ]; do
      xrandr_out="$(LANG=C /usr/bin/xrandr -d :0)"
      # If VIRTUAL is primary.
      if egrep -q '^VIRTUAL[0-9]+[[:space:]]+connected[[:space:]]+primary' < <(printf '%sn' "$xrandr_out"); then
      # Find non-virtual that is connected.
      non_virt="$(sed -nre 's/^([^[:space:]]+)[[:space:]]+connected.*/1/p' < <(printf '%sn' "$xrandr_out" | grep -v ^VIRTUAL) | head -n1)"
      if [ -n "$non_virt" ]; then
      xrandr -d :0 --output "$non_virt" --primary --pos 0x0
      fi
      fi
      sleep 10
      done
      ) & disown






      command-line multiple-monitors display vnc xrandr






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 at 10:53









      pa4080

      13.2k52461




      13.2k52461










      asked Nov 27 at 8:06









      Velkan

      2,2051825




      2,2051825



























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096405%2fhow-to-force-a-virtual-monitor-to-be-always-secondary%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1096405%2fhow-to-force-a-virtual-monitor-to-be-always-secondary%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?