#!/usr/bin/perl

# (C) Till Kamppeter - Code under GPL (www.gnu.org).
# Modifications by Dmitry Vukolov <dav@altlinux.ru>, 2003

# Easy starting of xojpanel with auto-detection of available devices.

# Get the list of configured devices. Check whether they have a display and
# start "xojpanel" for the devices with display. Show a message if no device
# found.

my $successnum = 0;

foreach my $ptaldevice (`ptal-device`) {
    chomp $ptaldevice;
    # Has the device a display? Check it by trying to read it with
    # the command line tool
    open LCD, ("ptal-hp $ptaldevice display 2>&1 |") or next;
    my $lcdcontent = join('', <LCD>);
    close LCD;
    next if ($lcdcontent =~ /^(\s*\(unavailable\)\s*$)|(ptal-hp:\s*Unable to)/m);
    # Start xojpanel for this device
    system("xojpanel $ptaldevice >/dev/null 2>&1 &");
    $successnum += 1;
}

system("xmessage -center -default okay 'No device found'") unless $successnum;
