Subject: | Better StayOnTop implementation for X11 and Windows |
I have attached is a better method to get stayontop working on X11 systems. This works for "modern" window manager (e.g. the ones found in KDE or GNOME). For older window managers, a fallback to something like
{
my $stay_above_after;
$mw->bind("<Visibility>" =>
sub {
if ($stay_above_after) {
$stay_above_after->cancel;
}
$stay_above_after = $mw->after
(1000, sub {
$mw->raise;
#Tk->break;
undef $stay_above_after;
});
}
);
}
could be used. This could also be used on Windows if Win32::API is not installed. For Windows with Tk804.027 and better I would recommend to use $top->attributes(-topmost => 1) instead.
Regards,
Slaven
#!/usr/bin/perl
use Tk;
$mw = tkinit;
keep_on_top($mw);
MainLoop;
sub keep_on_top {
my $w = shift;
my($wrapper) = $w->toplevel->wrapper;
eval {
if (!grep { $_ eq '_NET_WM_STATE_STAYS_ON_TOP' } $w->property('get', '_NET_SUPPORTED', 'root')) {
die "_NET_WM_STATE_STAYS_ON_TOP not supported";
}
$w->property('set', '_NET_WM_STATE', "ATOM", 32,
["_NET_WM_STATE_STAYS_ON_TOP"], $wrapper);
};
if ($@) {
warn $@;
0;
} else {
1;
}
}