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.
Hello,
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).
Directions:
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:
monitorSwitch.sh
Place this in the directory /usr/bin and chmod it to 755.Code:#!/bin/bash if cat $HOME/.0.switch ; then rm -f $HOME/.0.switch touch $HOME/.1.switch fi #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; fi
Now do a quick test and type: "sh monitorSwitch.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 monitorSwitch.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.
Compile it with the command: "g++ monitorSwitch.cpp -o monitorSwitch".Code:#include <cstdlib> using namespace std; int main() { return system("sh /usr/bin/monitorSwitch.sh >> /dev/null"); }
Move the resulting exectuable(monitorSwitch) to /usr/bin and make sure it is chmoded to 755. Now executing "monitorSwitch" instead of "sh monitorSwitch.sh" will switch monitors.
Note: You still need monitorSwitch.sh 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; 12-28-2006 at 06:48 PM. Reason: Fixing a few spelling mistakes.
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.
Cool. Didn't know that. Maybe some day it will support all laptops. (That and it'd be nice if their driver supported AIGLX)
Wonderfull !!
BUT
Please could you fix your script for it removes alone some uneeded backup of xorg please?
And add in your how :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/
make "touch $HOME/.0.switch"
Best Regards
Well, maybe you want to have a look on what I use for switching:
1. does not need any state-files in $HOMECode:#!/bin/sh 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 SWITCH="lvds,crt1" elif [ "$ENABLED" = "crt1 lvds" ]; then SWITCH="crt1" else SWITCH="lvds" fi echo "Enabling $SWITCH" /usr/bin/aticonfig --effective=now --enable-monitor=$SWITCH fi
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 "monitorSwitch.sh", place it somewhere in your $PATH, make it executable (chmod +x path/to/monitorSwitch) and be happy.
Last edited by Zhenech; 05-14-2007 at 02:30 PM.
Problem at the line 22 man :s
atlas:~$ sudo monitorSwitch.sh
/usr/bin/monitorSwitch.sh: line 22: syntax error: unexpected end of file
could you help me?
thx yet!
edit:
i have add fi at the end ! it's working ! thanks a lot !!!!
Last edited by atlas95; 05-14-2007 at 01:54 PM.
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
Atlas
Well, I don't have Gnome, but I think this hack could help:
just replace
echo "Enabling $SWITCH"
with
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; 05-22-2007 at 03:38 PM.
Ok Thanks I will try this !
![]()