#!/usr/bin/perl # ## ## tvos-filter-xf86config ## ## This script filters an xf86config file and makes the ## following modifications ## ## 1) adds specified 640x480 modes to the display section ## ## 2) print only one glx line (bug in XFree86 -configure?) ## ## 3) add dpms option if( -e "/proc/driver/nvidia/cards/0" ){ # HACK-WORKAROUND: xosd cannot work tolerably well with nvidia driver on a TNT $cardtype = `cat /proc/driver/nvidia/cards/0 | grep "^Model:"`; chomp $cardtype; $cardtype =~ s/^Model:\s*//; if ("$cardtype" eq "RIVA TNT"){ $has_nvidia = 0; } else { $has_nvidia = 1; } } else { $has_nvidia = 0; } # init $in_section = ""; $prev_section = ""; $in_subsection = ""; $prev_subsection = ""; $glx_done = 0; # simple stream filter while () { $orig_line = $_; $entering_section = 0; $exiting_section = 0; $entering_subsection = 0; $exiting_subsection = 0; $is_glx = 0; $do_not_print_this_line = 0; # SWITCH is just an arbitrary block label, as perl # has no official switch/case SWITCH: { /^Section/ && do { s/^Section \"(\w*)\".*\n/$1/; $in_section = $1; $entering_section = 1; last SWITCH }; /^EndSection/ && do { $prev_section = $in_section; $in_section = ""; $exiting_section = 1; last SWITCH }; /^\s*SubSection/ && do { s/^\s*SubSection \"(\w*)\".*\n/$1/; $in_subsection = $1; $entering_subsection = 1; last SWITCH }; /^\s*EndSubSection/ && do { $prev_subsection = $in_subsection; $in_subsection = ""; $exiting_subsection = 1; last SWITCH }; } # print "in section: $in_section , in subsection: $in_subsection \n"; # print "$entering_section $exiting_section $entering_subsection $exiting_subsection \n"; # Add Modes "640x480" at end of each Display Subsection if(($exiting_subsection) && ($prev_subsection eq "Display")) { print " # VIROS autoconfig: TVOS is 640x480\n"; print " Modes \"640x480\"\n"; } # Add dpms option at end of Device Section if(($exiting_section) && ($prev_section eq "Device")) { print " # VIROS autoconfig: add dpms\n"; print " Option \"DPMS\" \"on\"\n"; } if($in_section eq "Module"){ # print only one glx entry (I'm too tired to care about how # ungraceful this seems...) if(/^\s*Load\s*\"glx\"\s*$/) {$is_glx = 1;} if(!$glx_done && $is_glx){ print $orig_line; $glx_done = 1; $do_not_print_this_line = 1; } elsif($glx_done && $is_glx){ $do_not_print_this_line = 1; } if($has_nvidia){ if(/^\s*Load\s*\"dri\"\s*$/) {$do_not_print_this_line = 1;} if(/^\s*Load\s*\"libglx\"\s*$/) {$do_not_print_this_line = 1;} } } if($in_section eq "Device"){ if($has_nvidia){ if(/^\s*\#Option\s*\"NoLogo\"/) { print " # VIROS: get rid of other people's egos ;)\n"; print " # if only syslinux were this easy...\n"; print " Option \"NoLogo\" \"True\"\n"; $do_not_print_this_line = 1; } } } if($in_section eq "ServerLayout"){ if(/^\s*InputDevice\s*\"Mouse0\" \"CorePointer\"/) { print " InputDevice \"PS2 Mouse\" \"CorePointer\"\n"; print " InputDevice \"USB Mouse\" \"SendCoreEvents\"\n"; print " InputDevice \"LIRC Mouse\" \"SendCoreEvents\"\n"; $do_not_print_this_line = 1; } } if(!$do_not_print_this_line) {print $orig_line;} } # here are things that tvos just appends to the end of the file print ' Section "InputDevice" Identifier "PS2 Mouse" Driver "mouse" Option "Protocol" "PS/2" Option "Device" "/dev/misc/psaux" EndSection Section "InputDevice" Identifier "USB Mouse" Driver "mouse" Option "Protocol" "IMPS/2" Option "Device" "/dev/input/mouse0" EndSection Section "InputDevice" Identifier "LIRC Mouse" Driver "mouse" Option "Protocol" "MouseSystems" Option "Device" "/dev/lircm" EndSection '