Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


hello all monks - i come to you after seeking google endlessly

i'm writing an app for linux (mandrake9.1 using KDE) i want the app's main frame to be topmost\always-on-top

is there anyway to do so?

till now i found only windows snippets but no linux
(don't mind changing perl versions if it makes a difference... i don't even mind too much changing window manager)
  • Comment on perlTK always-on-top \ topmost in linux

Replies are listed 'Best First'.
Re: perlTK always-on-top \ topmost in linux
by PodMaster (Abbot) on Aug 22, 2004 at 02:41 UTC
Re: perlTK always-on-top \ topmost in linux
by zentara (Cardinal) on Aug 22, 2004 at 12:00 UTC
    I think the "Stay on top" property is dependent on the Window Manager. I don't use KDE, I use fvwm2. The overrideredirect option works pretty well, but it can be intrusive since it stays on all virtual desktops. Also, you mentioned searching google, but you should be checking groups.google.com to get the tk usenet newsgroup archives.

    Maybe I'm misinterpreting what you want to do, maybe you just want to call $toplevel->raise if it isn't on top? You can test for window visibility, and raise it if it isn't visible.

    #!/usr/bin/perl use Tk; $mw = tkinit; $t = $mw->Toplevel; $t->withdraw; $t->Label(-text => "Testing...")->pack; $t->Button( -text => "Withdraw", -command => sub {$t->withdraw}, )->pack; $t ->overrideredirect(1); #to top on all virtual desktops $mw->Button( -text => 'Test', -command => sub { $_->deiconify, $_->raise for $t; }, )->pack; MainLoop;

    Also you might want to check out the Tk::Wm perldoc. The following dosn't work on fvwm2, but is reported to work on KDE.

    #from comp.lang.perl.tk #The following works, at least with KDE 2. I would be glad to #here su +ccess reports for KDE 3. #Regards, Slaven Rezic use Tk; $top = new MainWindow; keep_on_top($top); MainLoop; sub keep_on_top { my $w = shift; my($wrapper) = $w->toplevel->wrapper; $w->property('set', '_NET_WM_STATE', "ATOM", 32, ["_NET_WM_STATE_STAYS_ON_TOP"], $wrapper); } __END__

    I'm not really a human, but I play one on earth. flash japh
      Here's a modified version which first checks whether the window manager supports the _NET_WM_STATE_STAYS_ON_TOP atom.
      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; } }
      The code could be expanded to use the <Visibility> or overrideredirect hacks on other window managers.