Active screen?

Martin <ratpoison-devel-UA2YTn/[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
I've finally entered the 21:th century & have gotten myself a dual-head setup.
This has complicated my use of ratpoison to some degree, when I found that I
needed to know which monitor that is currently the active one, but found no
easy way to have ratpoison tell it to me.

This is the script I wrote.

Has anyone else wanted to find the currently active monitor? Did you solve it
more elegantly than this? Is there perhaps a way to have ratpoison tell it
right away?

Comments?

#!/usr/bin/perl
#
# This script exists to show which screen is currently active, since I could
# not find any way to extract that information from ratpoison by any simpler
# means.
#
# It finds the active screen by taking the output of the ratpoison commands
# fdump and sfdump and comparing them.
#
# fdump will provide something like this:
#(frame :number 1 :x 0 :y 0 :width 1200 :height 1920 :screenw 1200 :screenh 1920 :window 190840842 :last-access 173 :dedicated 0),
#
# sfdump will provide something like this:
#(frame :number 0 :x 0 :y 0 :width 768 :height 1024 :screenw 768 :screenh 1024 :window 16777217 :last-access 172 :dedicated 0) 0,
#(frame :number 1 :x 0 :y 0 :width 1200 :height 1920 :screenw 1200 :screenh 1920 :window 190840842 :last-access 173 :dedicated 0) 1,
#
# By search for the existance of the fdump output inside the sfdump output, it
# is possible to know which physical screen is active.

use strict;
use warnings;

my $sfdump=`$ENV{'RATPOISON'} --command "sfdump"`;
my $fdump=`$ENV{'RATPOISON'} --command "fdump"`;

$/ = ",\n";
chomp ($fdump);

my @screens = split (/([(][^(]*,)([(][^(]*,)/, $sfdump);

foreach ( @screens ) {
	next unless m/^[(]/;
	my ( $screen ) = m/.* ([0-9]*)[,]/;
	print $screen;
	if (grep (/$fdump/, $_)) {
		print "*";
	} else {
		print "-";
	}
	print $_, "\n";
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.