Chinaunix首页 | 论坛 | 博客
  • 博客访问: 261977
  • 博文数量: 39
  • 博客积分: 1126
  • 博客等级: 准尉
  • 技术积分: 502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-28 11:34
文章分类

全部博文(39)

文章存档

2012年(7)

2011年(20)

2010年(12)

分类: LINUX

2011-10-17 14:27:46

针对于老Intel显卡和老SIS显卡配置相对应的xorg.conf文件,用来支持双屏的操作
不说多了直接上程序
 
 
#######################这里定义的是全局变量############################################
#确定显示模式,
#dispmode=800x600 ,这个分辨率只是用来设置副屏的,主屏分辨率需要修改代码的其他部分
dispmode=clone
#X的配置文件路径
File=/etc/X11/xorg.conf
#######################这里定义的函数都是对于Intel显卡的###############################
#获取当前使用的显示设备标号,LVDS,VGA,TV
get_intel_monitor_type ()
{
export DISPLAY=:0.0
X &>/dev/null &
sleep 1
if lspci | grep VGA | grep -q Intel; then
   export    LVDS_DEVICE=$(xrandr | grep -w 'connected' | awk '{print $1}' | grep 'LVDS' )
   export    VGA_DEVICE=$(xrandr | grep -w 'connected' | awk '{print $1}' | grep 'VGA' )
   export    TV_DEVICE=$(xrandr | grep -w 'connected' | awk '{print $1}' | grep 'TV' )
 
   killall X
fi 
}
#intel显卡,往xorg.conf中添加监视器配置的程序
append_intel_Monitor ()
{
#如果没有接其他显示器就不写minotor1的配置文件
if [ -z "$VGA_DEVICE" -a -z "$TV_DEVICE" -a "$1" = "1" ]; then
    return 0
fi
local identifier=$1
local modeline_60=$(cvt $2 $3 60 | sed -n '2p')
local modeline_70=$(cvt $2 $3 70 | sed -n '2p')
local modeline_72=$(cvt $2 $3 72 | sed -n '2p')
local modeline_75=$(cvt $2 $3 75 | sed -n '2p')
if [ "$dispmode" = "clone" ]; then
    extern_cmd=""
elif [ "$1" = "1" ]; then
    extern_cmd='Option "RightOf"   "Monitor0"'
fi
cat >>$File<Section "Monitor"
  Identifier   "Monitor$1"
 VendorName   "Monitor Vendor"
 ModelName    "Monitor Model"
 HorizSync 30.0-60
 VertRefresh 50-85
 $modeline_60
 $modeline_70
 $modeline_72
 $modeline_75
 Option "preferredMode"  "$2x$3"
 $extern_cmd
EndSection
EOF
}
#intel显卡,往xorg.conf中添加显卡驱动配置的程序
append_intel_Device ()
{
local busid=$(lspci | grep VGA | awk '{print $1}' | tr '.' ':')
local other_monitor=
if [ -n "$VGA_DEVICE" ]; then
    other_monitor="Option \"monitor-${VGA_DEVICE}\"  \"Monitor1\""
elif [ -n "$TV_DEVICE" ]; then
    other_monitor="Option \"monitor-${TV_DEVICE}\"  \"Monitor1\""
else
    other_monitor=""
fi
cat >>$File<Section "Device"
 Identifier  "Card0"
 Driver      "intel"
 BusID       "PCI:${busid}"
        Option "monitor-${LVDS_DEVICE}" "Monitor0"
        ${other_monitor}
EndSection
EOF
}
#intel显卡,往xorg.conf中添加显示器配置的程序
append_intel_Screen ()
{
cat >>$File<Section "Screen"
 Identifier "Screen0"
 Device     "Card0"
        DefaultDepth 24
 SubSection "Display"
  Viewport   0 0
  Depth     24
 EndSubSection
EndSection
EOF
}
#######################对于Intel显卡的函数定义完成###############################
#######################这里定义的函数都是对于SIS显卡的###############################
#sis显卡,往xorg.conf中添加监视器配置的程序
append_sis_Monitor ()
{
cat >>$File<Section "Monitor"
  Identifier   "Monitor$1"
 VendorName   "Monitor Vendor"
 ModelName    "Monitor Model"
 HorizSync 31.0-60
 VertRefresh 40-60
        Option "DPMS"
EndSection
EOF
}
#sis显卡,往xorg.conf中添加显卡驱动配置的程序
append_sis_Device ()
{
local busid=$(lspci | grep VGA | awk '{print $1}' | tr '.' ':')
cat >>$File<Section "Device"
 Identifier  "Card$1"
 Driver      "sis"
 BusID       "PCI:${busid}"
 Screen     $1
EndSection
EOF
}
#sis显卡,往xorg.conf中添加显示器配置的程序
append_sis_Screen ()
{
local device_num=
if [ "$1" = "0" ]; then
    device_num=0
elif [ "$dispmode" = "clone" -a "$1" = "1" ]; then
    device_num=0
else
    device_num=1
fi
cat >>$File<Section "Screen"
 Identifier "Screen$1"
 Device     "Card${device_num}"
        Monitor    "Monitor$1"
        DefaultDepth 24
 SubSection "Display"
  Depth 24
                Modes "$2"
 EndSubSection
EndSection
EOF
}
append_sis_ServerLayout()
{
v=$(cat <Section "ServerLayout"
 Identifier     "X.org Configured"
 Screen      0  "Screen0" 0 0
 Screen      1  "Screen1" RightOf "Screen0"
 InputDevice    "Mouse0" "CorePointer"
 InputDevice    "Keyboard0" "CoreKeyboard"
 Option  "Xinerama" "on"
 Option  "Clone" "on"
EndSection
EOF
cat $File)
echo "$v" >$File
}
#######################对于SIS显卡的函数定义完成###############################

###############################主程序############################################
#删除原来的配置文件
rm -rf $File &>/dev/null
#关闭已打开的X程序
killall X &>/dev/null
#判断如果是sis的显卡
if lspci | grep VGA | grep -q Silicon; then
    #产生一个新的原始X的配置文件
    X -configure &>/dev/null
    sleep 1
    mv /root/xorg.conf.new $File
   
    #去掉原始文件中ServerLayout,Screen,Monitor,Device这几节的内容,这几节需要重写
    #去掉Screen1的配置,处理这句是由于有的机器自动配置是会产生Screen1的配置语句
    #使产生的配置文件不能正常工作
    sed -i '/#/d' $File
    sed -i -n '1h;1!H;${g;s#Section "ServerLayout"[^\E]*EndSection##g;p}'  $File
    sed -i -n '1h;1!H;${g;s#Section "Monitor"[^\E]*EndSection##g;p}'  $File
    sed -i -n '1h;1!H;${g;s#Section "Device"[^\E]*EndSection##g;p}'  $File
    sed -i -n '1h;1!H;${g;s#Section "Screen".*EndSection##g;p}'  $File
   
    #添加操作;添加Monitor0,Device,Screen的配置
    append_sis_Monitor 0
    append_sis_Monitor 1 
    append_sis_Device  0
    append_sis_Device  1
    append_sis_Screen  0  800x600
    append_sis_Screen  1  $dispmode
    append_sis_ServerLayout
 
fi
#判断如果是Intel的显卡
if lspci | grep VGA | grep -q Intel; then
    #获得显示器的标识号
    get_intel_monitor_type
    sleep 1
 #产生一个新的原始X的配置文件
    X -configure &>/dev/null
    sleep 1
    mv /root/xorg.conf.new $File
   
    #去掉原始文件中Screen,Monitor,Device这几节的内容,这几节需要重写
    #去掉Screen1的配置,处理这句是由于有的机器自动配置是会产生Screen1的配置语句
    #使产生的配置文件不能正常工作
    sed -i '/Screen1/d' $File
    sed -i '/#/d' $File
    sed -i -n '1h;1!H;${g;s#Section "Monitor"[^\E]*EndSection##g;p}'  $File
    sed -i -n '1h;1!H;${g;s#Section "Device"[^\E]*EndSection##g;p}'  $File
    sed -i -n '1h;1!H;${g;s#Section "Screen".*EndSection##g;p}'  $File
   
    #添加操作;添加Monitor0,Device,Screen的配置
    append_intel_Monitor 0 800 600
 
    #添加操作:根据显示模式的不同,配置监视器1
    case $dispmode in
    clone )
        append_intel_Monitor 1 800 600
       ;;
    *x*)
        append_intel_Monitor 1 ${dispmode%x*} ${dispmode#*x}
    ;;
     *)
      echo "Error: the value dispmode error"
      exit 1
    ;;
    esac
    append_intel_Device
    append_intel_Screen
fi
 
 
阅读(2745) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~