HOWTO switch between internal and external monitor (Fn-F5)

Discussion in 'Linux' started by Nudnik_de, Mar 12, 2009.

  1. Nudnik_de

    Nudnik_de

    Joined:
    Aug 7, 2008
    Messages:
    57
    Likes Received:
    0
    Hi,

    I was looking for a solution to switch between monitor modes (internal/external) with the Fn F5 key. I finally found an approach with the help of Thinkwiki.

    First I tested
    Code:
    xrandr --auto 
    it turns on the external VGA Monitor. Unfortunately with limited resolution. According to to Ubuntuhelp/grandr this is due to wrong framebuffer settings during startup. They are limited to the AspieOne resolution of 1024x600. So I added the SubSection "Display" in my ect/X11/xorg.conf

    Code:
    Section "Screen"
    	Identifier	"Default Screen"
    	Monitor		"Configured Monitor"
    	Device		"Configured Video Device"
    	SubSection "Display"
    		Virtual 1280 1024
    	EndSubSection
    EndSection
    Now the VGA will switch into the 1280x1024.

    I rewrote a script from Thinkwiki allowing to switch between different monitor modes: internal, internal+external, external with one command. and saved it in my homedirectory as /home/username/xrandr-switch.sh

    Code:
    #!/bin/bash
    # Switch between video output modes on external VGA port
    # thinkwiki.org
     
     
    # Figure out current state
    INTERNAL_STATE=$($SU xrandr | grep ^'''LVDS''' | grep con | sed "s/.*connected //" | sed "s/(.*//")
    EXTERNAL_STATE=$($SU xrandr | grep ^'''VGA''' | grep con | sed "s/.*connected //" | sed "s/(.*//")
     
    if [ -z "$INTERNAL_STATE" ]; then
           STATE="external"
    elif [ -z "$EXTERNAL_STATE" ]; then
           STATE="internal"
    else
           INTERNAL_STATE=$(echo $INTERNAL_STATE | sed "s/[0-9]*x[0-9]*//")
           EXTERNAL_STATE=$(echo $EXTERNAL_STATE | sed "s/[0-9]*x[0-9]*//")
           if [ "$INTERNAL_STATE" = "$EXTERNAL_STATE" ]; then
                   STATE="mirror"
           else
                   STATE="both"
           fi
    fi
     
    case "$STATE" in
          internal)
    		# start mirror mode
           		xrandr --output LVDS --mode 1024x600
           		xrandr --output VGA --mode 1024x768
          ;;
          mirror)
           		# start external mode
           		xrandr --output LVDS --off
           		xrandr --output VGA --auto
          ;;
          external)
    		# start internal mode
            	xrandr --output VGA --off
            	xrandr --output LVDS --auto
          ;;
          *)
          		# screen_internal
            	xrandr --output VGA --off
            	xrandr --output LVDS --auto
          ;;
    esac
    
    You can check if its working with invoking the script with
    Code:
    sh /home/username/xrandr-switch.sh
    starting it several times should allow to switch from one mode to the next

    Next step is to define Fn-F5 to execute this shell script.
    In my Xubuntu (XFCE) install I open Settings -> Keyboard -> Application Shortcuts
    adding a new shortcut, enter the code sh /home/username/xrandr-switch.sh, click OK, press Fn-F5 and confirm finally. Thats it.
    Monitor switching should now work.
     
    Nudnik_de, Mar 12, 2009
    #1
  2. Nudnik_de

    geekyhawkes

    Joined:
    Oct 22, 2008
    Messages:
    30
    Likes Received:
    0
    Does this fix the issue of having to start the netbook up with an external monitor already connected? This is the main issue i have at the moment as it is a real pain having to restart the machine every time you want to use an external monitor.

    (Nice clear guide by the way).
     
    geekyhawkes, Mar 15, 2009
    #2
  3. Nudnik_de

    Nudnik_de

    Joined:
    Aug 7, 2008
    Messages:
    57
    Likes Received:
    0
    The good news is that the external monitor doesn't have to be attached during startup. As long as you set the max resolution you want to use as a virtual resolution within your Xorg.conf then it works fine.
     
    Nudnik_de, Mar 16, 2009
    #3
  4. Nudnik_de

    rurik

    Joined:
    Nov 13, 2008
    Messages:
    4
    Likes Received:
    0
    Nudnik_de
    thank you very much for the script and for explaining. But I have a problem with xubuntu 9.04 - it doesn't recognize Fn+F5 at all !! can you help me?
     
    rurik, Mar 22, 2009
    #4
  5. Nudnik_de

    Nudnik_de

    Joined:
    Aug 7, 2008
    Messages:
    57
    Likes Received:
    0
    I'm using xubuntu 8.10 and using XEV in terminal gives also no result for Fn-F5. But when I open the application shortcut dialogue from main-menu it works. Just try the following:

    Open Main Menue -> Settings -> Keyboard -> Application Shortcuts

    Do you allready have an entry called XF86Display? The XF86Display is the system name for the Fn-F5 Shortcut. If you have it you just can change it accordingly.

    If you don't have it try add one it the same way I described it in my initial post

    If it's not working you have two options:

    1) use another shortcut like Shift-F5

    2) try to enter the XF86Display code manually, If it's not possible to do that in the dialogue then you could enter the code into the configuration script of the keyboard settings manager. I don't know where it is but Google should know it... ;-)
     
    Nudnik_de, Mar 22, 2009
    #5
  6. Nudnik_de

    c-m

    Joined:
    Jan 28, 2009
    Messages:
    72
    Likes Received:
    0
    I have got a 16080x1050 22" monitor that I want to connect to my netbook to show video.

    How should your code be adapted? When i added that resolution to the xrandr-switch.sh file in replace of the 1024x768 I get the following error:

    Code:
    carl@carl-laptop:~$ sh /home/carl/xrandr-switch.sh
    xrandr: cannot find mode 1680x1050
    carl@carl-laptop:~$
     
    c-m, Apr 22, 2009
    #6
  7. Nudnik_de

    mzc

    Joined:
    Sep 10, 2008
    Messages:
    106
    Likes Received:
    0
    very interesting...I've been using ubuntu 9.04 netbook remix RC.. the only opportunity I see is the available resolution / mirroring / cloning of screens as most projectors does not accept 1024x600. Hence, when cloned, the AAO changes to 800x600 same as the projector. Furthermore, I do not have to plug the projector at start-up, It has been hot-pluggable since I started using it.
     
    mzc, Apr 23, 2009
    #7
  8. Nudnik_de

    Nudnik_de

    Joined:
    Aug 7, 2008
    Messages:
    57
    Likes Received:
    0
    @ C-M, try the following:

    Code:
    xrandr --output VGA --auto
    Which resolution does the external monitor show? Try also to reboot with the monitor attched.

    If it works properly when the monitor is attached during booting then you should modify your virtual screen size in your xorg.conf as described in my initial post.

    Hope this helps
     
    Nudnik_de, Apr 24, 2009
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.