No announcement yet.

HOWTO: Convenient monitor switching with ATI's fglrx

  • Filter
  • Time
  • Show
Clear All
new posts

  • HOWTO: Convenient monitor switching with ATI's fglrx


    Being a mobile user who uses linux(currently 2.6.18-1.2849.fc6) and fglrx(8.31.5) I had a nasty problem of switching between being mobile and using the internal monitor and being at my desk and using an external one. I don't know how it works in other distros/drivers but in my setup the Function F8 key didn't do anything once everything was loaded.

    Using ati's new dynamic display management I devised a more convient API that mimicks Windows. It is only tested in the "clone mode" setup.

    Goals: It cycles through modes(LCD only, CRT Only, LCD + CRT).

    1.) Create a file called ".0.switch" in your home directory. There should be one in each user's home directory that switches between mobile and desktop use, btw it should be owned by each of the respective users.

    2.) Below is the code for a file called:
    if   cat $HOME/.0.switch  ; then
    rm -f $HOME/.0.switch
    touch $HOME/.1.switch
    #We then run what each switch number entails: 
    #1: CRT On, LCD Off
    #2: LCD + CRT On
    #3: LCD On, CRT Off reset switches to 1
    if  cat $HOME/.1.switch ; then
    aticonfig --enable-monitor=crt1
    rm -f $HOME/.1.switch
    touch $HOME/.2.switch;
    elif  cat $HOME/.2.switch ; then
    aticonfig --enable-monitor=lvds,crt1
    rm -f $HOME/.2.switch
    touch $HOME/.3.switch;
    elif  cat $HOME/.3.switch ; then
    aticonfig --enable-monitor=lvds
    rm -f $HOME/.3.switch
    touch $HOME/.0.switch;
    Place this in the directory /usr/bin and chmod it to 755.

    Now do a quick test and type: "sh", with any luck it should switch to a CRT-only mode. Run the comand again and you'll get CRT+LCD mode, and again to get LCD-only mode.

    3.) Lastly you can/should map a custom command to run when you press certain keys. Rather then repeat the tutorial here I will supply a link: Gnome Custom key shortcuts.

    Note: The command you want to run is sh (or monitorSwitch if you follow the extra step below)
    Note #2: You can map it to "Func-F8" if you are fancy enough to map that keycode into your keymap... rather then go through that hoopla I'd reccomend making it "<CTRL><SHIFT>F8".
    Note #3: KDE users you are on your own on mapping the keyboard shortcut.

    Optional Step
    If you are like me and want a clean "monitorSwitch" command to switch monitors you can compile and place the resulting exectuable in your /usr/bin directory.
    #include <cstdlib>
    using namespace std;
    int main()
    	return system("sh /usr/bin/ >> /dev/null");
    Compile it with the command: "g++ monitorSwitch.cpp -o monitorSwitch".
    Move the resulting exectuable(monitorSwitch) to /usr/bin and make sure it is chmoded to 755. Now executing "monitorSwitch" instead of "sh" will switch monitors.
    Note: You still need in the /usr/bin directory! All the exectuable does is run the sh command on that script.

    Hopefully this is useful to people. I wrote it for my system and it seems to work so far.

    At some point I'd like to address some of the drawbacks of this solution. Now it just uses that file so it cycles between modes indeterminent of what mode you are in or what monitors are connected(like a TV in an S-Video port for instance). The script should determine the connected monitors and be "smart" to will determine what to cycle. Also it would be nice to automatically adjust the screen resolution from mode to mode(in the ***-only modes). At some point I may add that functionality in or if someone else does please amend the thread.
    Last edited by koolmanoncampus; 28 December 2006, 08:48 PM. Reason: Fixing a few spelling mistakes.

  • #2
    Nice how-to. If you didn't know, the ATI events daemon (atieventsd) supports hotkey display switching, but at present it is limited to Lenovo laptops.
    Michael Larabel


    • #3
      Cool. Didn't know that. Maybe some day it will support all laptops. (That and it'd be nice if their driver supported AIGLX)


      • #4
        Wonderfull !!


        Please could you fix your script for it removes alone some uneeded backup of xorg please?

        atlas:~$ ls /etc/X11
        fs/ xorg.conf xorg.conf.fglrx-3 xorg.conf.fglrx-9
        rstart/ xorg.conf~ xorg.conf.fglrx-4 xorg.conf.original-0
        sessions/ xorg.conf.fglrx-0 xorg.conf.fglrx-5 xorg.conf.original-1
        twm/ xorg.conf.fglrx-1 xorg.conf.fglrx-6 xorg.conf.original-2
        xdm/ xorg.conf.fglrx-10 xorg.conf.fglrx-7 xorg.conf.original-3
        xinit/ xorg.conf.fglrx-2 xorg.conf.fglrx-8 xsm/
        And add in your how :

        make "touch $HOME/.0.switch"

        Best Regards


        • #5
          Well, maybe you want to have a look on what I use for switching:

          CONNECTED=`aticonfig --query-monitor |grep Connected |sed -e 's/.*: //;s/,//'`
          ENABLED=`aticonfig --query-monitor |grep Enabled |sed -e 's/.*: //;s/,//'`
          if [ "$CONNECTED" = "lvds" ]; then
                  # We have only the internal display, don't do anything
                  exit 0
          elif [ "$CONNECTED" = "crt1 lvds" ]; then
                  # We have the internal and external display, let's swicth
                  # LVDS -> CRT1,LVDS -> CRT1
                  if [ "$ENABLED" = "lvds" ]; then
                  elif [ "$ENABLED" = "crt1 lvds" ]; then
                  echo "Enabling $SWITCH"
                  /usr/bin/aticonfig --effective=now --enable-monitor=$SWITCH
          1. does not need any state-files in $HOME
          2. does not create any xorg.conf backups

          And by the way - why do you need a binary around all this? just call the script "monitorSwitch" instead of "", place it somewhere in your $PATH, make it executable (chmod +x path/to/monitorSwitch) and be happy.
          Last edited by Zhenech; 14 May 2007, 03:30 PM.


          • #6
            Problem at the line 22 man :s

            atlas:~$ sudo
            /usr/bin/ line 22: syntax error: unexpected end of file

            could you help me?
            thx yet!

            i have add fi at the end ! it's working ! thanks a lot !!!!
            Last edited by atlas95; 14 May 2007, 02:54 PM.


            • #7
              Originally posted by atlas95 View Post
              Problem at the line 22 man :s

              atlas:~$ sudo
              /usr/bin/ line 22: syntax error: unexpected end of file

              could you help me?
              thx yet!

              i have add fi at the end ! it's working ! thanks a lot !!!!
              Ups. yeah. forgot teh last line while pasting.

              Btw, you don't need sudo, this should work as $USER (does for me).


              • #8
                Hey man

                I'm back,
                Could you add in your script some popup notify under gnome that say in which mode they are or just something like that ...

                Thanks you

                edit: with libnotify maybe for exemple?

                Best regards



                • #9
                  Well, I don't have Gnome, but I think this hack could help:
                  just replace

                  echo "Enabling $SWITCH"


                  echo "Enabling $SWITCH" |osd_cat -p top -f "-*-helvetica-*-r-*-*-*-240-*-*-*-*-*-*" -c green -O 1 -o -100

                  and install xosd-bin (on Debian... don't ask how the package containing osd_cat is called on $YOUR_DISTRO)
                  Last edited by Zhenech; 22 May 2007, 04:38 PM.


                  • #10
                    Ok Thanks I will try this !