You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.4 KiB
78 lines
1.4 KiB
package Win32Tray; |
|
|
|
return 1 unless $^O =~ /win32/i; |
|
|
|
use strict; |
|
use warnings; |
|
|
|
use Milkbone; |
|
eval 'use Win32::GUI'; |
|
use Tk; |
|
|
|
my $icon = new Win32::GUI::Icon(path("images/mbone.ico")) or die "Couldn't load icon."; |
|
my ($i); |
|
our ($parent, $tray, $menu); |
|
|
|
register_hook("signed_in", sub { |
|
return unless option("TrayIcon") == 1; |
|
$parent = Win32::GUI::Window->new(-name => 'Main', -text => 'Perl', |
|
-width => 200, -height => 200) or die $!; |
|
$parent->Hide(); |
|
$tray = $parent->AddNotifyIcon(-icon => $icon, -name => 'NI', -id => 1, -tip => data("me") . " - milkbone"); |
|
|
|
$menu = Win32::GUI::MakeMenu( |
|
"POPUP" => "POPUP_MENU", |
|
" >Show/Hide All" => "Tray_Toggle", |
|
" >Exit" => "Tray_Exit" |
|
); |
|
|
|
hook("tk_getmain")->repeat(500, [sub { |
|
Win32::GUI::DoEvents(); |
|
}, $parent]); |
|
|
|
register_hook("post_mainloop", sub { |
|
$ARGS{-parent}->NI->Delete(-id => 1); |
|
}, {-parent => $parent}); |
|
}); |
|
|
|
END |
|
{ |
|
hook("post_mainloop"); |
|
} |
|
|
|
package main; |
|
|
|
my $hidden = 0; |
|
|
|
sub NI_RightClick |
|
{ |
|
my($x, $y) = Win32::GUI::GetCursorPos(); |
|
$Win32Tray::parent->TrackPopupMenu($Win32Tray::menu->{POPUP_MENU},$x, $y); |
|
} |
|
|
|
sub Tray_Exit_Click |
|
{ |
|
abort; |
|
} |
|
|
|
sub Tray_Head |
|
{ |
|
} |
|
|
|
sub Tray_Toggle_Click |
|
{ |
|
my $mw = hook("tk_getmain"); |
|
|
|
if($hidden) |
|
{ |
|
$_->deiconify and $_->focus for $mw->children; |
|
$hidden = 0; |
|
} |
|
else |
|
{ |
|
$_->withdraw for $mw->children; |
|
$hidden = 1; |
|
} |
|
} |
|
|
|
1;
|
|
|