Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk - Invoke WM protocol

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
I've been doing some research on Tk and WM protocols, namely the "WM_URGENT" protocol.

I've been curious to find out how to make a Tk window "flash" on the task bar, like IM programs do when you receive a message on a window that doesn't have the focus. When looking around in the preferences on Gaim, they referred to this "flashing" as "Set window manager "URGENT" hint." under Notifications.

I'm a little bit familiar with Window Manager protocols, such as in Tk, to set a handler for WM_DELETE_WINDOW to be able to pop up a message box to allow the user to change their mind about closing the window, for example a "Do you want to save your document first?"

So I googled WM_URGENT and found that this is the name of a Window Manager protocol. The question is, how do you invoke a WM protocol in Tk?

I wrote this test script:
Code:
#!/usr/bin/perl -w

use Tk;
use Tk::Mwm;
use Data::Dumper;

our $mw = MainWindow->new;

our $child = $mw->Toplevel (
	-title => 'Child',
);
$child->geometry('320x240');

print "Protocol\n";
print $mw->mwmProtocol;

print "Attributes\n" . Dumper($mw->attributes);
print "\nClient\n" . Dumper($mw->client);

$mw->positionfrom('program');

print Dumper($mw->command);

print "child: $child\n";

print Dumper($child->command);

$mw->Button (
	-text => 'Send Urgent',
	-command => sub {
		print "toplevel: $child\n";
		#$child->protocol ('Tk-urgent');
		$child->command ('Tk-urgent');
		$child->deiconify;
		print Dumper($child->command);
		#$child->iconify;
	},
)->pack;

MainLoop;

What I want the script to do is... the MainWindow has a button that should send the URGENT hint for the child window, which doesn't have the focus (if it did, the URGENT hint wouldn't do anything). But, it doesn't seem to work as it is.

The output:
Code:
[casey@cuvou Tests]$ perl Tk-urgent.pl
Protocol
Attributes

Client
$VAR1 = 'Tk-urgent';
child: Tk::Toplevel=HASH(0x9552f8c)
[casey@cuvou Tests]$

The call to $mw->mwmProtocol returns nothing. The manpage for Tk::Mwm says it should return all the supported protocols. The calls to $mw->attributes and $mw->client also returns nothing.

A curiosity is... the call to $mw->command returns an array containing the word 'Tk-urgent' by default. Only the MainWindow's command() method returned Tk-urgent; the Toplevel didn't. I'm assuming that somewhere in Tk's code, a MainWindow gets this command (perhaps if my program were to open another MainWindow while I had the focus on a separate application entirely, the new window would "flash"?)

So as you can see in my code, I tried calling command() on the Toplevel to add Tk-urgent to it. Doing so didn't do anything except for add 'Tk-urgent' to the list of return values from the command() method later on.

The protocol() method only sets a handler for a protocol, but doesn't invoke the protocol. Looking at the docs, command() seems to be to add a command to the list of ones that the window supports, but doesn't invoke the command either.

Has anybody had any experience with Tk and WM_URGENT?

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top