Subject: | focus steal from other apps |
Date: | Sat, 09 Feb 2013 10:09:54 +1100 |
To: | bug-Prima [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
Under X and fvwm in click-to-focus mode, if a prima program is badly
lagged it can steal the keyboard focus from another application. With
the program foo.pl below,
run foo.pl
click "Sleep" # it prints "sleeping"
click "Dummy" # while it's sleeping
click to focus on a different app
=>
when the sleep ends prima steals the focus back to itself
Nosing around the code it seems Widget_focused() calls
apc_widget_set_focused() with guts.currentFocusTime == 0,
ie. CurrentTime, thus taking the focus no matter what subsequent user
action has done.
The fix might be as simple as putting the mouse click time into
guts.currentFocusTime. Or maybe use guts.last_time whenever
currentFocusTime is 0 -- which might be always except for responding to
WM_TAKE_FOCUS.
I struck this in a slow drawing program. When it catches up from its
lag it tended to steal the focus from where I'd switched away.
use strict;
use Prima;
use Prima::Buttons;
use Prima 'Application';
my $main = Prima::MainWindow->new (size => [100,100]);
$main->insert ('Button',
text => 'Sleep',
pack => { side => 'top' },
onClick => sub {
my ($button) = @_;
print "sleeping\n";
sleep 3;
print "awake again\n";
});
$main->insert ('Button',
text => 'Dummy',
pack => { side => 'top' },
onClick => sub {
my ($button) = @_;
print "dummy button\n";
});
Prima->run;
exit 0;