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

Dear monks

I need to create a top window without WM. For this I usually do:

my $dialog = $mw->Toplevel; $dialog->overrideredirect(1);

I also need the $dialog to be always visible on top. For this I usually do:

if ($dialog->parent->toplevel->viewable){$dialog->transient($dialog->p +arent);}

The problem arises if I combine the two. In this case, I disable the WM, but my $dialog does not stay on top if my MainWindow gets the focus.

Any idea?

Replies are listed 'Best First'.
Re: Tk overrideredirect topwindow on top
by jcb (Parson) on Oct 07, 2019 at 22:58 UTC

    Your program will have to detect when the dialog becomes obscured and re-raise it. Marking the dialog as a transient window is a request that the WM keep it above its "parent" but you are using override-redirect to exclude the dialog from the WM's management entirely.

      If the dialog is being shown, meaning it should be on top of parent, simply have a Tk::after that keeps raising it, untils the dialog is withdrawn

        You might also be able to bind a handler for <Visibility> events and raise the window again if it becomes obscured, which avoids continuous graphics traffic (until two programs both try to do this and end up fighting over "on top" status).

        Is this a long-lived window or only a short-lived dialog box? Is this supposed to be a modal dialog? If so, grabbing the server may be appropriate.

        Thank you for the suggestion. For the moment I went adding

        $dialog->repeat(10, sub { $dialog->raise; });

        which makes the GUI respond as intended