Implement the window::urgent event

The window::urgent event is emitted when a container becomes urgent or
loses its urgent status.
next
Tony Crisci 2014-06-20 08:33:02 -04:00 committed by Michael Stapelberg
parent a9c094b731
commit 682fb0a291
4 changed files with 84 additions and 8 deletions

View File

@ -723,6 +723,7 @@ This event consists of a single serialized map containing a property
* +fullscreen_mode+ - the window has entered or exited fullscreen mode
* +move+ - the window has changed its position in the tree
* +floating+ - the window has transitioned to or from floating
* +urgent+ - the window has become urgent or lost its urgent status
Additionally a +container (object)+ field will be present, which consists
of the window's parent container. Be aware that for the "new" event, the

View File

@ -231,6 +231,7 @@ void con_focus(Con *con) {
con->urgent = false;
con_update_parents_urgency(con);
workspace_update_urgent_flag(con_get_workspace(con));
ipc_send_window_event("urgent", con);
}
}
@ -1599,14 +1600,16 @@ void con_set_urgency(Con *con, bool urgent) {
con_update_parents_urgency(con);
if (con->urgent == urgent)
LOG("Urgency flag changed to %d\n", con->urgent);
Con *ws;
/* Set the urgency flag on the workspace, if a workspace could be found
* (for dock clients, that is not the case). */
if ((ws = con_get_workspace(con)) != NULL)
workspace_update_urgent_flag(ws);
if (con->urgent == urgent) {
LOG("Urgency flag changed to %d\n", con->urgent);
ipc_send_window_event("urgent", con);
}
}
/*

View File

@ -320,11 +320,14 @@ static void workspace_reassign_sticky(Con *con) {
static void workspace_defer_update_urgent_hint_cb(EV_P_ ev_timer *w, int revents) {
Con *con = w->data;
DLOG("Resetting urgency flag of con %p by timer\n", con);
con->urgent = false;
con_update_parents_urgency(con);
workspace_update_urgent_flag(con_get_workspace(con));
tree_render();
if (con->urgent) {
DLOG("Resetting urgency flag of con %p by timer\n", con);
con->urgent = false;
con_update_parents_urgency(con);
workspace_update_urgent_flag(con_get_workspace(con));
ipc_send_window_event("urgent", con);
tree_render();
}
ev_timer_stop(main_loop, con->urgency_timer);
FREE(con->urgency_timer);
@ -380,6 +383,7 @@ static void _workspace_show(Con *workspace) {
* focus and thereby immediately destroy it */
if (next->urgent && (int)(config.workspace_urgency_timer * 1000) > 0) {
/* focus for now… */
next->urgent = false;
con_focus(next);
/* … but immediately reset urgency flags; they will be set to false by

View File

@ -0,0 +1,68 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • http://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • http://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • http://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
# (unless you are already familiar with Perl)
#
# Test that the window::urgent event works correctly. The window::urgent event
# should be emitted when a window becomes urgent or loses its urgent status.
#
use i3test;
my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
force_display_urgency_hint 0ms
EOT
my $i3 = i3(get_socket_path());
$i3->connect()->recv;
my $cv;
$i3->subscribe({
window => sub {
my ($event) = @_;
$cv->send($event) if $event->{change} eq 'urgent';
}
})->recv;
my $t;
$t = AnyEvent->timer(
after => 0.5,
cb => sub {
$cv->send(0);
}
);
$cv = AnyEvent->condvar;
fresh_workspace;
my $win = open_window;
my $dummy_win = open_window;
$win->add_hint('urgency');
my $event = $cv->recv;
isnt($event, 0, 'an urgent con should emit the window::urgent event');
is($event->{container}->{window}, $win->{id}, 'the event should contain information about the window');
is($event->{container}->{urgent}, 1, 'the container should be urgent');
$cv = AnyEvent->condvar;
$win->delete_hint('urgency');
my $event = $cv->recv;
isnt($event, 0, 'an urgent con should emit the window::urgent event');
is($event->{container}->{window}, $win->{id}, 'the event should contain information about the window');
is($event->{container}->{urgent}, 0, 'the container should not be urgent');
done_testing;