package AmphetaDesk::OS::Linux; ############################################################################### # This package handles all the GUI routines for the Linux operating system. # # It requires various modules to be compiled into the runtime wrapper script # # - these modules are assumed to be there. If not, oopsy, we got problems. # # # # LIST OF ROUTINES BELOW: # # gui_init - start the gui and display the window. # # gui_listen - listen for window events for our gui. # # gui_note - send a note to our gui window. # # open_url - open a url in the system's default browser. # # _things - various routines that control the gui and should be private. # ############################################################################### use strict; use AmphetaDesk::Settings; use AmphetaDesk::Utilities; use POSIX ":sys_wait_h"; use POSIX ":unistd_h"; require Exporter; use vars qw( @ISA @EXPORT ); @ISA = qw( Exporter ); @EXPORT = qw( gui_init gui_listen gui_note open_url ); # taken from perlipc man page sub sigchild { my $child; # If a second child dies while in the signal handler caused by the # first death, we won't get another signal. So must loop here else # we will leave the unreaped child as a zombie. And the next time # two children die we get another zombie. And so on. while (($child = waitpid(-1,WNOHANG)) > 0) {} $SIG{CHLD} = \&sigchild; } ############################################################################### # gui_init - start the gui and display the window. # ############################################################################### # USAGE: # # gui_init; # # # # NOTES: # # This routine loads specific libraries specific to the OS and attempts to # # do everything necessary to start up a GUI window and start listening for # # events. Further down in this file, you should see supplementary GUI # # routines (starting with _) that are part of the GUI happenings this # # routine inits. # # # # For Linux, this would probably load up some Tk junk. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_init { return 1; } ############################################################################### # gui_listen - listen for window events for our gui. # ############################################################################### # USAGE: # # gui_listen; # # # # NOTES: # # This routine checks the event queue and sees if there is anything that # # needs to be done. It's called from the main loop of our program. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_listen { return 1; } ############################################################################### # gui_note - send a note to our gui window. # ############################################################################### # USAGE: # # gui_note("This is a gui window line. Yup."); # # # # NOTES: # # Much like note(), only we send our message to our os specific gui window. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_note { # eventually, if we ever do Tk, this will do something meaningful. my ($message) = @_; print STDOUT $message . "\n"; return 1; } ############################################################################### # open_url - open a url in the system's default browser. # ############################################################################### # USAGE: # # open_url( ); # # # # OS SPECIFIC NOTES: # # Since it's nigh near impossible for us to figure out the default browser # # much less the path to said browser in Linux, we simply display a # # message telling the user what to do. # # # # RETURNS: # # 1; we instruct the user to open their browser if we can't. # ############################################################################### sub open_url { # construct our url. my $url = "http://127.0.0.1:" . get_setting("urls_port") . "/index.html"; # default browser my $browser; # we spit out our suggestion just to catch all instances. note("If your browser doesn't load, go to <$url>.", 1); # what browser? if ($ENV{'BROWSER'}) { $browser = $ENV{'BROWSER'}; } else { if (get_setting("user_browser_path")) { $browser = get_setting("user_browser_path"); } } if ( ($browser) && ( (-x $browser) || (-X $browser) ) ) { note("Your environment states that $browser is your default program."); $SIG{CHLD} = \&sigchild; if (fork() == 0) { my @args = ("$browser", "$url"); setsid(); close(STDIN); close(STDOUT); close(STDERR); exec(@args) == 0 or note("The browser <$browser> does not exist. Please select another."); exit 1; } } return 1; } ############################################################################### # _things - various routines that control the gui and should be private. # ############################################################################### # USAGE: # # These are internally called by the GUI and shouldn't be publically # # used. So stop poking around here. Sheesh. Flippin' nosy people. Sigh. # ############################################################################### 1;