Commits

Xu Xiaodong committed ebd5d38

minor update

Comments (0)

Files changed (1)

 use strict;
 use warnings;
 
-my $cmd  = 'xrandr';        # 设置命令
-my $mode = '1280x768';      # 要设置的分辨率大小
-my $out  = get_out($cmd);
+use Tie::File;
+
+my $cmd  = 'xrandr';         # 设置命令
+my $mode = '1280x768';       # 要设置的分辨率大小
+my $out  = get_out($cmd);    # 已连接的显示器
 
 set_res( $cmd, $out, $mode );
 
   my $addmode = qq{$cmd --addmode $out $mode};
   my $setmode = qq{$cmd --output $out --mode $mode};
 
-  open my $out_fh, '>', "$ENV{HOME}/.xprofile"
-    or die "Can't write .xprofile: $!\n";
+  my $file = "$ENV{HOME}/.xprofile";
 
-  print $out_fh $newmode, "\n";
+  tie my @lines, 'Tie::File', $file
+    or die "Can't read '$file': $!\n";
+
+  push @lines, $newmode . "\n";
+  push @lines, $addmode . "\n";
+  push @lines, $setmode . "\n";
+
+  untie @lines;
+
   system $newmode;
-  print $out_fh $addmode, "\n";
   system $addmode;
-  print $out_fh $setmode, "\n";
   system $setmode;
-
-  close $out_fh;
 }
 
 #