#! /usr/bin/perl =for comment This is a script to add rotational behavior to the disper nvidia display changing utility. Repeated invocations of this script will do this: laptop display only -> external only external only -> both displays both displays -> laptop display only etc.. =cut use strict; use warnings; # Args that are always needed for disper my $disperArgs = '--scaling native '; # Use nvidia-settings to get the AssociatedDisplays and TwinView status my $nvsetQueryOutput = `nvidia-settings --query=AssociatedDisplays --query=TwinView`; my ($nvsetTwinView) = $nvsetQueryOutput =~ /Attribute 'TwinView' \(.*\): (\d)\./; my ($nvsetAssociatedDisplays) = $nvsetQueryOutput =~ /Attribute 'AssociatedDisplays' \(.*\): 0x\d{7}(\d)\./; # Configure args for disper SWITCH: { # Laptop display only now, switch to external only if ($nvsetTwinView == 0 && $nvsetAssociatedDisplays == 0) { $disperArgs .= '--secondary'; last SWITCH; } # External monitor only now, switch to both if ($nvsetTwinView == 0 && $nvsetAssociatedDisplays == 1) { $disperArgs .= '--extend'; last SWITCH; } # Both monitors now, switch to laptop only if ($nvsetTwinView == 1 && $nvsetAssociatedDisplays == 1) { $disperArgs .= '--single'; last SWITCH; } } # Perform the switch system "disper $disperArgs"; # Extra fun stuff # Screen metrics have possibly (probably?) changed, root window # background probably borken now. # Reinstate my beloved root window image. I use feh for this, so: my $rootImgSetter = "$ENV{HOME}/.fehbg"; system "eval `cat $rootImgSetter`" if -e $rootImgSetter;