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

Context - Ubuntu 18.04.2 LTS Gnome-Shell 3.28.3 Perl 5.26.1 Tk 804.034
Challenge - identifying what event/s is/are issued when a Tk TopLevel window in state 'iconic' is changed to state 'normal'. I have tried binding to Map,Unmap,Configure,Visibility,Expose,ButtonRelease-1 events and while I get the expected events from 'normal' to 'iconic' I do not get any that I can identify in the reverse direction i.e. when I left mouse click on the window's icon(I assigned via $mw->iconphoto(...)) under the Ubuntu Activities bar the window appears but so far I have not found which event/s accompanies said - I'm currently guessing none as the related action is not under Tk orchestration albeit Tk should know such an action occurred and could generate at least a 'Visibility' event.

The problem I am trying to address is a means to re-display a withdrawn 'undecorated' (overrideredirect(1)) window as such windows do not appear to allow being 'iconic' so I have a simple decorated window (initially withdrawn then iconized when 'undecorated' withdrawn) to hold the icon I want which when pressed will in essence raise the 'undecorated' one and quickly withdraw itself - hence the need to bind to whatever event will tell me its now visible!


Any help in direction greatly appreciated!

  • Comment on Identify Tk state iconic to normal events

Replies are listed 'Best First'.
Re: Identify Tk state iconic to normal events
by Anonymous Monk on Jul 20, 2019 at 08:48 UTC
      Heh
      #!/usr/bin/perl -- use strict; use warnings; use Tk; use Data::Dump qw/ dd /; my @tags = ( "<KeyPress>", "<KeyRelease>", "<ButtonPress>", "<ButtonRelease>", "<FocusIn>", "<FocusOut>", "<Expose>", "<MapRequest>", "<ConfigureRequest>", "<ResizeRequest>", "<Activate>", "<Deactivate>", "<Activate>", "<Destroy>", "<Map>", "<ButtonPress>", "<Button>", "<Enter>", "<MapRequest>", "<ButtonRelease>", "<Expose>", "<Motion>", "<Circulate>", "<FocusIn>", "<MouseWheel>", "<FocusOut>", "<Property>", "<Colormap>", "<Gravity>", "<Reparent>", "<Configure>", "<Key>", "<ResizeRequest>", "<ConfigureRequest>", "<KeyRelease>", "<Unmap>", "<Create>", "<Leave>", "<Visibility>", "<Deactivate>", ); my $mw = tkinit(); $mw->Button( qw/ -text exit -command /, sub { $Tk::widget->toplevel->destroy; } )->pack; my %seen; for my $bindtag ( @tags ) { $mw->bind( $mw, $bindtag, sub { $seen{$bindtag}++; print qq{$bindtag \$e $Tk::event \$w $Tk::widget \@_ @_\n} +; } ); } my $redirect = 0; $mw->geometry( '480x480+50+50' ); $mw->overrideredirect( $redirect = !$redirect ); $mw->withdraw; $mw->deiconify; $mw->raise; $mw->repeat( 1000, sub { $Tk::widget->overrideredirect( $redirect = !$redirect ); $Tk::widget->deiconify; $Tk::widget->raise; } ); dd \%seen; $mw->MainLoop; dd \%seen; __END__ <Visibility> $e XEvent=SCALAR(0xf45c24) $w Tk::Button=HASH(0xf56344) @ +_ Tk::Button=HASH(0xf56344) <Configure> $e XEvent=SCALAR(0xf648a4) $w MainWindow=HASH(0xf27a84) @_ + MainWindow=HASH(0xf27a84) <Expose> $e XEvent=SCALAR(0xf64864) $w MainWindow=HASH(0xf27a84) @_ Ma +inWindow=HASH(0xf27a84) <Key> $e XEvent=SCALAR(0xf28494) $w MainWindow=HASH(0xf27a84) @_ MainW +indow=HASH(0xf27a84) <FocusIn> $e XEvent=SCALAR(0xf647d4) $w Tk::Button=HASH(0xf56344) @_ T +k::Button=HASH(0xf56344) <KeyRelease> $e XEvent=SCALAR(0xf64794) $w Tk::Button=HASH(0xf56344) @ +_ Tk::Button=HASH(0xf56344) <Destroy> $e XEvent=SCALAR(0xf56514) $w Tk::Button=HASH(0xf56344) @_ T +k::Button=HASH(0xf56344) <Destroy> $e XEvent=SCALAR(0xf27b84) $w MainWindow=HASH(0xf27a84) @_ M +ainWindow=HASH(0xf27a84) { "<Button>" => 1, "<ButtonRelease>" => 1, "<Configure>" => 36, "<Destroy>" => 2, "<Enter>" => 3, "<Expose>" => 24, "<FocusIn>" => 16, "<FocusOut>" => 14, "<Key>" => 96, "<KeyRelease>" => 97, "<Leave>" => 2, "<Map>" => 25, "<Motion>" => 21, "<Visibility>" => 48, }

        Thank you. The answer it led me too, while counter intuitive, was FocusIn(A widget has gained the keyboard focus) is the 'only' event(at least in the provided tags) that is generated when a window in iconic state becomes visible. Your code helped me to find that!
        Please note it had to be modified as the logic you employed does not see an Icon appear in Ubuntu Activities Bar so no user interaction viable to restore it once withdrawn.