2009-11-18 20:39:53 +01:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
2012-09-10 14:09:01 +02:00
|
|
|
#
|
|
|
|
# Please read the following documents before working on tests:
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/testsuite.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/lib-i3test.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/ipc.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
2009-11-18 20:39:53 +01:00
|
|
|
|
2012-09-22 14:19:20 +02:00
|
|
|
use i3test i3_autostart => 0;
|
2010-06-02 17:51:58 +02:00
|
|
|
use List::Util qw(first);
|
2009-11-18 20:39:53 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $_NET_WM_STATE_REMOVE = 0;
|
|
|
|
my $_NET_WM_STATE_ADD = 1;
|
|
|
|
my $_NET_WM_STATE_TOGGLE = 2;
|
|
|
|
|
|
|
|
sub set_urgency {
|
|
|
|
my ($win, $urgent_flag, $type) = @_;
|
|
|
|
if ($type == 1) {
|
2013-09-24 06:36:08 +02:00
|
|
|
# Because X11::XCB does not keep track of clearing the urgency hint
|
|
|
|
# when receiving focus, we just delete it in all cases and then re-set
|
|
|
|
# it if appropriate.
|
|
|
|
$win->delete_hint('urgency');
|
2013-02-26 01:37:35 +01:00
|
|
|
$win->add_hint('urgency') if ($urgent_flag);
|
|
|
|
} elsif ($type == 2) {
|
|
|
|
my $msg = pack "CCSLLLLLL",
|
|
|
|
X11::XCB::CLIENT_MESSAGE, # response_type
|
|
|
|
32, # format
|
|
|
|
0, # sequence
|
|
|
|
$win->id, # window
|
|
|
|
$x->atom(name => '_NET_WM_STATE')->id, # message type
|
|
|
|
($urgent_flag ? $_NET_WM_STATE_ADD : $_NET_WM_STATE_REMOVE), # data32[0]
|
|
|
|
$x->atom(name => '_NET_WM_STATE_DEMANDS_ATTENTION')->id, # data32[1]
|
|
|
|
0, # data32[2]
|
|
|
|
0, # data32[3]
|
|
|
|
0; # data32[4]
|
|
|
|
|
|
|
|
$x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-22 14:19:20 +02:00
|
|
|
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
|
|
|
|
|
2015-06-12 18:19:43 +02:00
|
|
|
my ($type, $tmp, $w1, $w2);
|
2013-02-26 01:37:35 +01:00
|
|
|
for ($type = 1; $type <= 2; $type++) {
|
|
|
|
my $pid = launch_with_config($config);
|
2015-06-12 18:19:43 +02:00
|
|
|
$tmp = fresh_workspace;
|
2009-11-18 20:39:53 +01:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Create two windows and put them in stacking mode
|
|
|
|
#####################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd 'split v';
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $top = open_window;
|
|
|
|
my $bottom = open_window;
|
2009-11-18 20:39:53 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
|
|
|
|
is(@urgent, 0, 'no window got the urgent flag');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
# cmd 'layout stacking';
|
2009-11-18 20:39:53 +01:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Add the urgency hint, switch to a different workspace and back again
|
|
|
|
#####################################################################
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my @content = @{get_ws_content($tmp)};
|
|
|
|
@urgent = grep { $_->{urgent} } @content;
|
|
|
|
my $top_info = first { $_->{window} == $top->id } @content;
|
|
|
|
my $bottom_info = first { $_->{window} == $bottom->id } @content;
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
ok($top_info->{urgent}, 'top window is marked urgent');
|
|
|
|
ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
|
|
|
|
is(@urgent, 1, 'exactly one window got the urgent flag');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[id="' . $top->id . '"] focus';
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
@urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
|
|
|
|
is(@urgent, 0, 'no window got the urgent flag after focusing');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
@urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
|
|
|
|
is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Check if the workspace urgency hint gets set/cleared correctly
|
|
|
|
#####################################################################
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $ws = get_ws($tmp);
|
|
|
|
ok(!$ws->{urgent}, 'urgent flag not set on workspace');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $otmp = fresh_workspace;
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
$ws = get_ws($tmp);
|
|
|
|
ok($ws->{urgent}, 'urgent flag set on workspace');
|
2010-06-02 17:51:58 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd "workspace $tmp";
|
2009-11-18 20:39:53 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
$ws = get_ws($tmp);
|
|
|
|
ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
|
2009-11-20 15:56:18 +01:00
|
|
|
|
2012-02-14 23:47:40 +01:00
|
|
|
################################################################################
|
|
|
|
# Use the 'urgent' criteria to switch to windows which have the urgency hint set.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Go to a new workspace, open a different window, verify focus is on it.
|
2013-02-26 01:37:35 +01:00
|
|
|
$otmp = fresh_workspace;
|
|
|
|
my $different_window = open_window;
|
|
|
|
is($x->input_focus, $different_window->id, 'new window focused');
|
2012-02-14 23:47:40 +01:00
|
|
|
|
|
|
|
# Add the urgency hint on the other window.
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
|
|
|
# Now try to switch to that window and see if focus changes.
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[urgent=latest] focus';
|
|
|
|
isnt($x->input_focus, $different_window->id, 'window no longer focused');
|
|
|
|
is($x->input_focus, $top->id, 'urgent window focused');
|
2012-02-14 23:47:40 +01:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Same thing, but with multiple windows and using the 'urgency=latest' criteria
|
|
|
|
# (verify that it works in the correct order).
|
|
|
|
################################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd "workspace $otmp";
|
|
|
|
is($x->input_focus, $different_window->id, 'new window focused again');
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($bottom, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[urgent=latest] focus';
|
|
|
|
is($x->input_focus, $bottom->id, 'latest urgent window focused');
|
|
|
|
set_urgency($bottom, 0, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[urgent=latest] focus';
|
|
|
|
is($x->input_focus, $top->id, 'second urgent window focused');
|
|
|
|
set_urgency($top, 0, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Same thing, but with multiple windows and using the 'urgency=oldest' criteria
|
|
|
|
# (verify that it works in the correct order).
|
|
|
|
################################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd "workspace $otmp";
|
|
|
|
is($x->input_focus, $different_window->id, 'new window focused again');
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($top, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($bottom, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[urgent=oldest] focus';
|
|
|
|
is($x->input_focus, $top->id, 'oldest urgent window focused');
|
|
|
|
set_urgency($top, 0, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[urgent=oldest] focus';
|
|
|
|
is($x->input_focus, $bottom->id, 'oldest urgent window focused');
|
|
|
|
set_urgency($bottom, 0, $type);
|
|
|
|
sync_with_i3;
|
2012-02-14 23:47:40 +01:00
|
|
|
|
2012-09-09 18:08:55 +02:00
|
|
|
################################################################################
|
|
|
|
# Check if urgent flag gets propagated to parent containers
|
|
|
|
################################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd 'split v';
|
2012-09-09 18:08:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
sub count_urgent {
|
|
|
|
my ($con) = @_;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my @children = (@{$con->{nodes}}, @{$con->{floating_nodes}});
|
|
|
|
my $urgent = grep { $_->{urgent} } @children;
|
|
|
|
$urgent += count_urgent($_) for @children;
|
|
|
|
return $urgent;
|
|
|
|
}
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
$tmp = fresh_workspace;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $win1 = open_window;
|
|
|
|
my $win2 = open_window;
|
|
|
|
cmd 'layout stacked';
|
|
|
|
cmd 'split vertical';
|
|
|
|
my $win3 = open_window;
|
|
|
|
my $win4 = open_window;
|
|
|
|
cmd 'split horizontal' ;
|
|
|
|
my $win5 = open_window;
|
|
|
|
my $win6 = open_window;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
sync_with_i3;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $urgent = count_urgent(get_ws($tmp));
|
|
|
|
is($urgent, 0, 'no window got the urgent flag');
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[id="' . $win2->id . '"] focus';
|
|
|
|
sync_with_i3;
|
|
|
|
set_urgency($win5, 1, $type);
|
|
|
|
set_urgency($win6, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
|
|
|
# we should have 5 urgent cons. win5, win6 and their 3 split parents.
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
$urgent = count_urgent(get_ws($tmp));
|
|
|
|
is($urgent, 5, '2 windows and 3 split containers got the urgent flag');
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[id="' . $win5->id . '"] focus';
|
|
|
|
sync_with_i3;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
|
|
|
# now win5 and still the split parents should be urgent.
|
2013-02-26 01:37:35 +01:00
|
|
|
$urgent = count_urgent(get_ws($tmp));
|
|
|
|
is($urgent, 4, '1 window and 3 split containers got the urgent flag');
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd '[id="' . $win6->id . '"] focus';
|
|
|
|
sync_with_i3;
|
2012-09-09 18:08:55 +02:00
|
|
|
|
|
|
|
# now now window should be urgent.
|
2013-02-26 01:37:35 +01:00
|
|
|
$urgent = count_urgent(get_ws($tmp));
|
|
|
|
is($urgent, 0, 'All urgent flags got cleared');
|
2012-09-09 18:08:55 +02:00
|
|
|
|
2012-09-27 12:37:38 +02:00
|
|
|
################################################################################
|
|
|
|
# Regression test: Check that urgent floating containers work properly (ticket
|
|
|
|
# #821)
|
|
|
|
################################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
$tmp = fresh_workspace;
|
|
|
|
my $floating_win = open_floating_window;
|
2012-09-27 12:37:38 +02:00
|
|
|
|
|
|
|
# switch away
|
2013-02-26 01:37:35 +01:00
|
|
|
fresh_workspace;
|
2012-09-27 12:37:38 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
set_urgency($floating_win, 1, $type);
|
|
|
|
sync_with_i3;
|
2012-09-27 12:37:38 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd "workspace $tmp";
|
2012-09-27 12:37:38 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
does_i3_live;
|
2012-09-27 12:37:38 +02:00
|
|
|
|
2013-01-25 18:32:43 +01:00
|
|
|
###############################################################################
|
|
|
|
# Check if the urgency hint is still set when the urgent window is killed
|
|
|
|
###############################################################################
|
2012-09-22 14:19:20 +02:00
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
my $ws1 = fresh_workspace;
|
|
|
|
my $ws2 = fresh_workspace;
|
|
|
|
cmd "workspace $ws1";
|
2015-06-12 18:19:43 +02:00
|
|
|
$w1 = open_window;
|
|
|
|
$w2 = open_window;
|
2013-02-26 01:37:35 +01:00
|
|
|
cmd "workspace $ws2";
|
|
|
|
sync_with_i3;
|
|
|
|
set_urgency($w1, 1, $type);
|
|
|
|
sync_with_i3;
|
|
|
|
cmd '[id="' . $w1->id . '"] kill';
|
|
|
|
sync_with_i3;
|
|
|
|
my $w = get_ws($ws1);
|
|
|
|
is($w->{urgent}, 0, 'Urgent flag no longer set after killing the window ' .
|
|
|
|
'from another workspace');
|
|
|
|
|
2013-06-12 03:40:37 +02:00
|
|
|
##############################################################################
|
|
|
|
# Check if urgent flag can be unset if we move the window out of the container
|
|
|
|
##############################################################################
|
2015-06-12 18:19:43 +02:00
|
|
|
$tmp = fresh_workspace;
|
2013-06-12 03:40:37 +02:00
|
|
|
cmd 'layout tabbed';
|
2015-06-12 18:19:43 +02:00
|
|
|
$w1 = open_window;
|
|
|
|
$w2 = open_window;
|
2013-06-12 03:40:37 +02:00
|
|
|
sync_with_i3;
|
|
|
|
cmd '[id="' . $w2->id . '"] focus';
|
|
|
|
sync_with_i3;
|
|
|
|
cmd 'split v';
|
|
|
|
cmd 'layout stacked';
|
|
|
|
my $w3 = open_window;
|
|
|
|
sync_with_i3;
|
|
|
|
cmd '[id="' . $w2->id . '"] focus';
|
|
|
|
sync_with_i3;
|
|
|
|
set_urgency($w3, 1, $type);
|
|
|
|
sync_with_i3;
|
|
|
|
cmd 'focus parent';
|
|
|
|
sync_with_i3;
|
|
|
|
cmd 'move right';
|
|
|
|
cmd '[id="' . $w3->id . '"] focus';
|
|
|
|
sync_with_i3;
|
2017-12-26 13:16:15 +01:00
|
|
|
$ws = get_ws($tmp);
|
2013-06-12 03:40:37 +02:00
|
|
|
ok(!$ws->{urgent}, 'urgent flag not set on workspace');
|
|
|
|
|
2015-03-28 19:23:59 +01:00
|
|
|
##############################################################################
|
|
|
|
# Regression test for #1187: Urgency hint moves to new workspace when moving
|
|
|
|
# a container to another workspace.
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
my $tmp_source = fresh_workspace;
|
|
|
|
my $tmp_target = fresh_workspace;
|
|
|
|
cmd 'workspace ' . $tmp_source;
|
|
|
|
sync_with_i3;
|
2015-06-12 18:19:43 +02:00
|
|
|
$w1 = open_window;
|
|
|
|
$w2 = open_window;
|
2015-03-28 19:23:59 +01:00
|
|
|
sync_with_i3;
|
|
|
|
cmd '[id="' . $w1->id . '"] focus';
|
|
|
|
sync_with_i3;
|
|
|
|
cmd 'mark urgent_con';
|
|
|
|
cmd '[id="' . $w2->id . '"] focus';
|
|
|
|
set_urgency($w1, 1, $type);
|
|
|
|
sync_with_i3;
|
|
|
|
cmd '[con_mark="urgent_con"] move container to workspace ' . $tmp_target;
|
|
|
|
sync_with_i3;
|
|
|
|
my $source_ws = get_ws($tmp_source);
|
|
|
|
my $target_ws = get_ws($tmp_target);
|
|
|
|
ok(!$source_ws->{urgent}, 'Source workspace is no longer marked urgent');
|
|
|
|
is($target_ws->{urgent}, 1, 'Target workspace is now marked urgent');
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
2013-02-26 01:37:35 +01:00
|
|
|
exit_gracefully($pid);
|
|
|
|
}
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
done_testing;
|