#!/usr/bin/env perl

=pod

=head1 NAME

fsproj - Crazy Fullscreen Detector & Screensaver Disabler

=head1 AUTHOR

Igor Gritsenko <xenomorph@mail.univ.kiev.ua>

=cut

use warnings;
use strict;
use threads ('stack_size' => 64*4096);
use threads::shared;

my %sethash : shared;
my $settings : shared = \%sethash;
my $selfpath =
  ( eval { require Cwd; &Cwd::abs_path($0); } ) =~ s/(.*)\/.*\/.*/$1/gr;
push @INC, $selfpath . "/lib";

my $app;

if (@ARGV) {
    require FSProj::Config;
    FSProj::Config::Init($selfpath);
    &FSProj::Config::ARGVparse( \$settings );
}
else {
    require Pod::Usage;
    &Pod::Usage::pod2usage(
        -verbose  => 99,
        -sections => "NAME|SYNOPSIS"
    );
    exit;
}
require FSProj::Utils;

&FSProj::Utils::daemonize;
if ( $settings->{gui} ) {
    @ARGV=(\$settings);
    require FSProj::GUI;
    $main::app = FSProj::GUI::App->new;
    $main::app->MainLoop;
}
else {
    require FSProj::Logic;
    threads->create( \&FSProj::Logic::XWinID )->detach;
    threads->create( \&FSProj::Logic::ProjLoop, \$settings )->join;
}
&FSProj::Utils::ActionHandle( 'KILL', $$ );
__END__

=pod

=head1 SYNOPSIS

fsproj [options] <action>

Actions:

B<start stop restart status>

Options:

B<[--help|-h] [--no-gui|-nog] [--gui|-g] [--fullscreen|-f] [--no-fullscreen|-nof] [--timeout|-t seconds] [--process-list|-p] [--add-proc|-a process1 process2 process3 ...] [--rm-proc|-r process1 process2 process3 ...] [--afdd-proc|-af process ...] [--rfm-proc|-rf process ...] [--version|-v]>

Use --help for more information.

=head1 OPTIONS

=over 8

=item B<--help>

Verbose description of command line options.

=back

=over 8

=item B<--version>

Shows current version.

=back

=over 8

=item B<--no-gui>

Do not use the GUI (Default).

=back

=over 8

=item B<--gui>

Enable WxWidgets GUI. They are working currently almost perfect.

=back

=over 8

=item B<--no-fullscreen>

Script works with both fullscreen and non-fullscreen applications. 

=back

=over 8

=item B<--fullscreen>

Script works only with fullscreen applications.

=back

=over 8

=item B<--timeout seconds>

Set timeout in seconds.

=back

=over 8

=item B<--process-list>

Show current tracking process list.

=back

=over 8

=item B<--add-proc process>

Add process for tracking. There could be more than one process.

=back

=over 8

=item B<--rm-proc process>

Delete process from tracking. There could be more than one process.

=back

=over 8

=item B<--afdd-proc process>

Add process for fullscreen tracking only. There could be more than one process.

=back

=over 8

=item B<--rfm-proc process>

Delete process from fullscreen only tracking. There could be more than one process.

=back

=head1 ARGUMENTS

=over 8

=item B<start> 

Starts the script and  sets the specified options.

=back

=over 8

=item B<stop>  

Stops the script. All options will be ignored.

=back 

=over 8

=item B<status>  

Shows current status of the script.

=back 

=over 8

=item B<restart>  

Restarts the script.

=back 

Any other arguments will be ignored. 

=head1 DESCRIPTION

I<FullScreenProj.pl> a.k.a I<fsproj> is a small utility that detects various videoplayers in fullscreen mode and allows users to disable screensaver and/or screen power off via DPMS. Users can control its behaviour via command line.

Default timeout is set to 5 seconds, default process list includes vlc, mplayer, and flash plugin. 
Settings that were changed via command line, are saved in config file, thus they could be used for further usage. See L</EXAMPLES> for more info.

=head1 EXAMPLES

=over 8

=item C<fsproj>

Runs brief help and exit.

=back

=over 8

=item C<fsproj start>

Starts the utility with previous configuration.

=back

=over 8

=item C<fsproj stop>

Stops the utility.

=back

=over 8

=item C<fsproj --timeout 10 start>

Starts the utility with changed timeout and saves this timeout to config.

=back

=over 8

=item C<fsproj --add-proc totem --rm-proc mplayer vlc restart>

Restarts the utility, removing mplayer and vlc from tracking list and adding totem to it. All changes are saved to config. 

=back

=over 8

=item C<fsproj --gui start>

Add WxWidgets GUI for easy use by novice users. It consist of tray icon and settings dialog box.

=back

=over 8

=item C<fsproj --process-list>

Shows info about currently tracked processes and exits. 

=back

=head1 COPYRIGHT

Copyright (c) 2012 Igor Gritsenko <xenomorph@mail.univ.kiev.ua>

This program is free software; you can redistribute it and/or
                modify it under the same terms as Perl itself.

=cut
