From 8d38529bcdafd331a618552399a04a30b71a57c3 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 24 Sep 2013 21:53:48 +0200 Subject: [PATCH] tests: move set_wm_class to X11::XCB::Window This code was duplicated way too often for a long time :) --- testcases/Makefile.PL | 2 +- testcases/t/119-match.t | 38 +++------------------ testcases/t/165-for_window.t | 36 +++++-------------- testcases/t/166-assign.t | 23 +------------ testcases/t/173-regress-focus-assign.t | 23 +------------ testcases/t/190-scratchpad-diff-ws.t | 33 +----------------- testcases/t/203-regress-assign-and-move.t | 21 +----------- testcases/t/204-regress-scratchpad-move.t | 32 +---------------- testcases/t/208-regress-floating-criteria.t | 22 +----------- testcases/t/211-regress-urgency-assign.t | 23 +------------ 10 files changed, 21 insertions(+), 232 deletions(-) diff --git a/testcases/Makefile.PL b/testcases/Makefile.PL index 28036d1f..1a9b19cf 100755 --- a/testcases/Makefile.PL +++ b/testcases/Makefile.PL @@ -9,7 +9,7 @@ WriteMakefile( PREREQ_PM => { 'AnyEvent' => 0, 'AnyEvent::I3' => '0.14', - 'X11::XCB' => '0.03', + 'X11::XCB' => '0.09', 'Inline' => 0, 'ExtUtils::PkgConfig' => 0, 'Test::More' => '0.94', diff --git a/testcases/t/119-match.t b/testcases/t/119-match.t index 7ac622c7..0aaeddd7 100644 --- a/testcases/t/119-match.t +++ b/testcases/t/119-match.t @@ -17,7 +17,6 @@ # Tests all kinds of matching methods # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE); my $tmp = fresh_workspace; @@ -61,39 +60,10 @@ is_num_children($tmp, 0, 'window killed'); $tmp = fresh_workspace; -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - -sub open_special { - my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; - - return open_window( - %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, - ); -} - -my $left = open_special(name => 'left'); +my $left = open_window(wm_class => 'special', name => 'left'); ok($left->mapped, 'left window mapped'); -my $right = open_special(name => 'right'); +my $right = open_window(wm_class => 'special', name => 'right'); ok($right->mapped, 'right window mapped'); # two windows should be here @@ -111,7 +81,7 @@ is_num_children($tmp, 1, 'one window still there'); $tmp = fresh_workspace; -$left = open_special(name => 'left', wm_class => 'special7'); +$left = open_window(name => 'left', wm_class => 'special7'); ok($left->mapped, 'left window mapped'); is_num_children($tmp, 1, 'window opened'); @@ -125,7 +95,7 @@ is_num_children($tmp, 0, 'window killed'); $tmp = fresh_workspace; -$left = open_special(name => 'ä 3', wm_class => 'special7'); +$left = open_window(name => 'ä 3', wm_class => 'special7'); ok($left->mapped, 'left window mapped'); is_num_children($tmp, 1, 'window opened'); diff --git a/testcases/t/165-for_window.t b/testcases/t/165-for_window.t index b01de91d..ada7c5c5 100644 --- a/testcases/t/165-for_window.t +++ b/testcases/t/165-for_window.t @@ -49,29 +49,9 @@ wait_for_unmap $window; cmp_ok(@content, '==', 0, 'no more nodes'); diag('content = '. Dumper(\@content)); - -# TODO: move this to X11::XCB::Window -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - $window = open_window( name => 'Borderless window', - before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') }, + wm_class => 'borderless', ); @content = @{get_ws_content($tmp)}; @@ -190,7 +170,7 @@ $tmp = fresh_workspace; $window = open_window( name => 'usethis', - before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') }, + wm_class => 'borderless', ); @content = @{get_ws_content($tmp)}; @@ -208,8 +188,7 @@ sync_with_i3; cmp_ok(@content, '==', 0, 'no nodes on this workspace now'); $window->_create; - -set_wm_class($window->id, 'borderless', 'borderless'); +$window->wm_class('borderless'); $window->name('notthis'); $window->map; wait_for_map $window; @@ -238,7 +217,8 @@ $tmp = fresh_workspace; $window = open_window( name => 'usethis', - before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, + wm_class => 'bar', + instance => 'foo', ); @content = @{get_ws_content($tmp)}; @@ -264,7 +244,8 @@ $tmp = fresh_workspace; $window = open_window( name => 'usethis', - before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, + wm_class => 'bar', + instance => 'foo', ); @content = @{get_ws_content($tmp)}; @@ -292,7 +273,8 @@ $tmp = fresh_workspace; $window = open_window( name => 'usethis', - before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, + wm_class => 'bar', + instance => 'foo', ); @content = @{get_ws_content($tmp)}; diff --git a/testcases/t/166-assign.t b/testcases/t/166-assign.t index 1cee1ebb..355058dd 100644 --- a/testcases/t/166-assign.t +++ b/testcases/t/166-assign.t @@ -17,37 +17,16 @@ # Tests if assignments work # use i3test i3_autostart => 0; -use X11::XCB qw(PROP_MODE_REPLACE); - -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} sub open_special { my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; $args{name} //= 'special window'; # We use dont_map because i3 will not map the window on the current # workspace. Thus, open_window would time out in wait_for_map (2 seconds). my $window = open_window( %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + wm_class => 'special', dont_map => 1, ); $window->map; diff --git a/testcases/t/173-regress-focus-assign.t b/testcases/t/173-regress-focus-assign.t index aff3fe3a..b010963b 100644 --- a/testcases/t/173-regress-focus-assign.t +++ b/testcases/t/173-regress-focus-assign.t @@ -18,37 +18,16 @@ # assigned to an invisible workspace # use i3test i3_autostart => 0; -use X11::XCB qw(PROP_MODE_REPLACE); - -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} sub open_special { my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; $args{name} //= 'special window'; # We use dont_map because i3 will not map the window on the current # workspace. Thus, open_window would time out in wait_for_map (2 seconds). my $window = open_window( %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + wm_class => 'special', dont_map => 1, ); $window->map; diff --git a/testcases/t/190-scratchpad-diff-ws.t b/testcases/t/190-scratchpad-diff-ws.t index 5451f482..644aafb1 100644 --- a/testcases/t/190-scratchpad-diff-ws.t +++ b/testcases/t/190-scratchpad-diff-ws.t @@ -18,44 +18,13 @@ # window is shown on another workspace. # use i3test; -use List::Util qw(first); -use X11::XCB qw(:all); my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - -sub open_special { - my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; - - return open_window( - %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, - ); -} - my $win = open_window; -my $scratch = open_special; +my $scratch = open_window(wm_class => 'special'); cmd '[class="special"] move scratchpad'; is_num_children($tmp, 1, 'one window on current ws'); diff --git a/testcases/t/203-regress-assign-and-move.t b/testcases/t/203-regress-assign-and-move.t index bf3df91e..51a1676f 100644 --- a/testcases/t/203-regress-assign-and-move.t +++ b/testcases/t/203-regress-assign-and-move.t @@ -19,7 +19,6 @@ # Ticket: #909 # Bug still in: 4.4-69-g6856b23 use i3test i3_autostart => 0; -use X11::XCB qw(:all); my $config = <atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - # We use dont_map because i3 will not map the window on the current # workspace. Thus, open_window would time out in wait_for_map (2 seconds). my $window = open_window( - before_map => sub { set_wm_class($_->id, '__i3-test-window', '__i3-test-window') }, + wm_class => '__i3-test-window', dont_map => 1, ); $window->map; diff --git a/testcases/t/204-regress-scratchpad-move.t b/testcases/t/204-regress-scratchpad-move.t index 8c307aa5..0782da38 100644 --- a/testcases/t/204-regress-scratchpad-move.t +++ b/testcases/t/204-regress-scratchpad-move.t @@ -20,41 +20,11 @@ # Ticket: #913 # Bug still in: 4.4-97-gf767ac3 use i3test; -use X11::XCB qw(:all); - -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - -sub open_special { - my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; - - return open_window( - %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, - ); -} my $tmp = fresh_workspace; # Open a new window which we can identify later on based on its WM_CLASS. -my $scratch = open_special; +my $scratch = open_window(wm_class => 'special'); my $tmp2 = fresh_workspace; diff --git a/testcases/t/208-regress-floating-criteria.t b/testcases/t/208-regress-floating-criteria.t index 09a29fd8..a13e0ad3 100644 --- a/testcases/t/208-regress-floating-criteria.t +++ b/testcases/t/208-regress-floating-criteria.t @@ -19,7 +19,6 @@ # Ticket: #1027 # Bug still in: 4.5.1-90-g6582da9 use i3test i3_autostart => 0; -use X11::XCB qw(PROP_MODE_REPLACE); my $config = <<'EOT'; # i3 config file (v4) @@ -31,28 +30,9 @@ EOT my $pid = launch_with_config($config); -# TODO: move this to X11::XCB::Window -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} - my $window = open_window( name => 'Borderless window', - before_map => sub { set_wm_class($_->id, 'special', 'special') }, + wm_class => 'special', dont_map => 1, ); $window->map; diff --git a/testcases/t/211-regress-urgency-assign.t b/testcases/t/211-regress-urgency-assign.t index a90703ee..57d8b434 100644 --- a/testcases/t/211-regress-urgency-assign.t +++ b/testcases/t/211-regress-urgency-assign.t @@ -21,37 +21,16 @@ # Ticket: #1086 # Bug still in: 4.6-62-g7098ef6 use i3test i3_autostart => 0; -use X11::XCB qw(:all); - -# TODO: move to X11::XCB -sub set_wm_class { - my ($id, $class, $instance) = @_; - - # Add a _NET_WM_STRUT_PARTIAL hint - my $atomname = $x->atom(name => 'WM_CLASS'); - my $atomtype = $x->atom(name => 'STRING'); - - $x->change_property( - PROP_MODE_REPLACE, - $id, - $atomname->id, - $atomtype->id, - 8, - length($class) + length($instance) + 2, - "$instance\x00$class\x00" - ); -} sub open_special { my %args = @_; - my $wm_class = delete($args{wm_class}) || 'special'; $args{name} //= 'special window'; # We use dont_map because i3 will not map the window on the current # workspace. Thus, open_window would time out in wait_for_map (2 seconds). my $window = open_window( %args, - before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + wm_class => 'special', dont_map => 1, ); $window->add_hint('urgency'); -- 2.39.5