分类: LINUX
2010-05-18 09:32:46
I work at three primary places: home, office one, and office two.
At home, I just use my laptop. At office one I have a 22" monitor and at office two I have a 24" monitor. Obviously, the resolutions are different and when I connect to them I want my displays to be set perfectly.
My laptop is always to the right of my external monitor. Here is a picture of office one's setup:
As you can see the laptop is to the left and lower than my external monitor.
|
First a disclaimer: I am no shell script expert.
My laptop's display is called LVDS. My external monitor is DFP1. However, when using the open source ATI drivers, it is called HDMI-0. Since I've been known to switch between the proprietary and open-source drivers, this script handles both. Obviously, if your external display name is different, just change it.
The script queries XRandR for the state of both HDMI-0 and DFP1. If either are in a connected state, the associated variable is set to a value of "1". I never learned sed and awk so I use the poor man's version: grep and wc.
Since both my monitors are named the same at both offices, I rely on my ethernet connection's IP address to determine where I am. Here I query ifconfig eth0 for the currently assigned IP address. Each office uses a different subnet so I'm safe.
Checking these values, I'm able to determine where I am and what display is connected. Now the fun begins. Well, it's not really fun...
If my external output is connected $EXTERNAL_OUTPUT I run an XRandR command to set it up the way I like it.
My laptop is 1600x900 at all times. Therefore my external output offset is 1600. This is set in the --pos 1600x0 statement. I also tell XRandR that this is my primary monitor with the --primary command.
Next, my laptop is always below my external monitor's viewport. I like my virtual space to mimic reality. Therefore I set my laptop display to be 500 pixels below the top of my external monitor's viewport. This is done with the --pos 0x500 in the second half of the XRandR call.
And that is it. I named this script setDisplay.sh and placed it in my ~/.kde/Autostart directory.
If you have several users who need to share this script, place it in your /usr/local/bin directory.
The final step is to make it executable:
|
|