From: Simon Elsbrock Date: Thu, 27 Sep 2012 22:38:02 +0000 (+0200) Subject: fix crash: send non-floating window with floating parent to scratchpad (thanks pkordy) X-Git-Tag: 4.4~101 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=da2b47c1e5d145c5029421129264dfaa986d94f5;p=i3%2Fi3 fix crash: send non-floating window with floating parent to scratchpad (thanks pkordy) Fix a crash that occured when moving a window to the scratchpad that is seemingly floating to the user, but actually a descendant of a floating parent con (and itself non-floating). If that is the case, move the floating parent container to scratchpad instead of the window. fixes #740 --- diff --git a/src/scratchpad.c b/src/scratchpad.c index 16e26cee..7b309095 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -39,11 +39,17 @@ void scratchpad_move(Con *con) { return; } - /* 1: Ensure the window is floating. From now on, we deal with the - * CT_FLOATING_CON. We use automatic == false because the user made the - * choice that this window should be a scratchpad (and floating). */ - floating_enable(con, false); - con = con->parent; + /* 1: Ensure the window or any parent is floating. From now on, we deal + * with the CT_FLOATING_CON. We use automatic == false because the user + * made the choice that this window should be a scratchpad (and floating). + */ + Con *maybe_floating_con = con_inside_floating(con); + if (maybe_floating_con == NULL) { + floating_enable(con, false); + con = con->parent; + } else { + con = maybe_floating_con; + } /* 2: Send the window to the __i3_scratch workspace, mainting its * coordinates and not warping the pointer. */ diff --git a/testcases/t/185-scratchpad.t b/testcases/t/185-scratchpad.t index 87bda529..dafe51e0 100644 --- a/testcases/t/185-scratchpad.t +++ b/testcases/t/185-scratchpad.t @@ -323,39 +323,51 @@ does_i3_live; # 11: focus a workspace and move all of its children to the scratchpad area ################################################################################ -$tmp = fresh_workspace; +sub verify_scratchpad_move_multiple_win { + my $floating = shift; -my $first = open_window; -my $second = open_window; + my $first = open_window; + my $second = open_window; -cmd 'focus parent'; -cmd 'move scratchpad'; + if ($floating) { + cmd 'floating toggle'; + cmd 'focus tiling'; + } -does_i3_live; + cmd 'focus parent'; + cmd 'move scratchpad'; -$ws = get_ws($tmp); -is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); -is(scalar @{$ws->{floating_nodes}}, 0, 'no floating windows on ws'); + does_i3_live; -# show the first window. -cmd 'scratchpad show'; + $ws = get_ws($tmp); + is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); + is(scalar @{$ws->{floating_nodes}}, 0, 'no floating windows on ws'); -$ws = get_ws($tmp); -is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); -is(scalar @{$ws->{floating_nodes}}, 1, 'one floating windows on ws'); + # show the first window. + cmd 'scratchpad show'; -$old_focus = get_focused($tmp); + $ws = get_ws($tmp); + is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); + is(scalar @{$ws->{floating_nodes}}, 1, 'one floating windows on ws'); -cmd 'scratchpad show'; + $old_focus = get_focused($tmp); -# show the second window. -cmd 'scratchpad show'; + cmd 'scratchpad show'; -$ws = get_ws($tmp); -is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); -is(scalar @{$ws->{floating_nodes}}, 1, 'one floating windows on ws'); + # show the second window. + cmd 'scratchpad show'; -isnt(get_focused($tmp), $old_focus, 'focus changed'); + $ws = get_ws($tmp); + is(scalar @{$ws->{nodes}}, 0, 'no windows on ws'); + is(scalar @{$ws->{floating_nodes}}, 1, 'one floating windows on ws'); + + isnt(get_focused($tmp), $old_focus, 'focus changed'); +} + +$tmp = fresh_workspace; +verify_scratchpad_move_multiple_win(0); +$tmp = fresh_workspace; +verify_scratchpad_move_multiple_win(1); # TODO: make i3bar display *something* when a window on the scratchpad has the urgency hint