diff options
Diffstat (limited to 'scripts/detect-resolution')
-rwxr-xr-x | scripts/detect-resolution | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/scripts/detect-resolution b/scripts/detect-resolution new file mode 100755 index 0000000..dad066e --- /dev/null +++ b/scripts/detect-resolution @@ -0,0 +1,117 @@ +#!/usr/bin/perl +# -*- Mode: cperl -*- +# Copyright (C) 2002 by Chmouel Boudjnah <chmouel@mandrakesoft.com> +# Redistribution of this file is permitted under the terms of the GNU +# Public License (GPL) +# +# Detect vga resolution we want. +# + +#use strict; +my (%main, %entry); + +my $vga = detect_from_cmdline(cat_('/proc/cmdline')); +undef $vga if $vga =~ /x/; #lilo cmdline can't convert +detect_from_loader() if not $vga; +if ($vga) { + chomp $vga; + $vga =~ s/vga=//; + $vga = convert_vgamode(); +} +print $vga, "\n" if $vga; + +sub detect_from_cmdline {return (grep /vga=\d+/, split("[ \t]", shift))[0];} +sub detect_from_loader { + my $loader = `detectloader -q`;chomp $loader; + if ($loader =~ m/lilo/i ) { + parse_lilo_conf(); + $vga = $entry{$main{default}}{vga}; + $vga = $main{vga} if not $vga; + } elsif ($loader =~ /grub/i ) { + parse_grub_conf(); + $vga = detect_from_cmdline($entry{$main{default}}{options}); + } +} +sub parse_grub_conf { + my ($title); + my $cnt = 0; + my $grub_conf = "/boot/grub/menu.lst"; + open F, $grub_conf or die "Can't open $grub_conf\n"; + + while (<F>) { + next if /^\s*#/; + $main{default} = $1 if /^default (\d+)/; + if (/^title\s+(.*)/) { + $title=$1; + $entry{$title}{title} = $title; + $entry{$title}{cnt} = $cnt; + $main{default} = $title if $entry{$title}{cnt} eq $main{default}; + $cnt++; + } + if (m/kernel\s+(\(.*\))([^\s]+)\s+(.*)/) { + $entry{$title}{partition} = $1; + $entry{$title}{kernel} = $2; + $entry{$title}{options} = $3; + } + $entry{$title}{initrd} = $1 if m/\s*initrd.*\)(.*)/; + } + close F; +} + +sub parse_lilo_conf { + my $lilo_conf="/etc/lilo.conf"; + my ($vga, $label); + open F, $lilo_conf or die "Can't open $lilo_conf\n"; + while (<F>) { + next if /^\s*#/; + $main{default} = $1 if m/^default=(.*)/; + $main{vga} = $1 if m/^vga=(.*)/; + $vga = $1 if /vga=(.*)/; + $label=$1 if /label=(.*)/; + $entry{$label}{vga} = $vga if ($label and $vga); + undef $vga if (/image=/ and $vga); + } + close F; +} + +sub convert_vgamode { + my $v; + #From drakx Xconfigurator_consts.pm + my %vgamodes = ( + '640xx8' => 769, + '640x480x8' => 769, + '800xx8' => 771, + '800x600x8' => 771, + '1024xx8' => 773, + '1024x768x8' => 773, + '1280xx8' => 775, + '1280x1024x8' => 775, + '640xx15' => 784, + '640x480x15' => 784, + '800xx15' => 787, + '800x600x15' => 787, + '1024xx15' => 790, + '1024x768x15' => 790, + '1280xx15' => 793, + '1280x1024x15' => 793, + '640xx16' => 785, + '640x480x16' => 785, + '800xx16' => 788, + '800x600x16' => 788, + '1024xx16' => 791, + '1024x768x16' => 791, + '1280xx16' => 794, + '1280x1024x16' => 794, + #- '640xx24' => 786, #- there is a problem with these resolutions since the BIOS may take 24 or 32 planes. + #- '640x480x24' => 786, + #- '800xx24' => 789, + #- '800x600x24' => 789, + #- '1024xx24' => 792, + #- '1024x768x24' => 792, + #- '1280xx24' => 795, + #- '1280x1024x24' => 795, + ); + foreach my $k (keys %vgamodes) { $v = $k if $vgamodes{$k} == $vga } + undef $vga if not $v;return $v; +} +sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l } |