From: hwangcc23 Date: Fri, 6 Apr 2018 16:00:38 +0000 (+0800) Subject: Make "scratchpad show" return correct info X-Git-Tag: 4.16~91^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F3230%2Fhead;p=i3%2Fi3 Make "scratchpad show" return correct info Fix the issue #3227(https://github.com/i3/i3/issues/3227). 1).Make cmd_scratchpad_show() use the information coming from scratchpad_show(). 2).Add a test case 298-scratchpad-show.t. --- diff --git a/include/scratchpad.h b/include/scratchpad.h index 241653c0..b24ffc08 100644 --- a/include/scratchpad.h +++ b/include/scratchpad.h @@ -29,7 +29,7 @@ void scratchpad_move(Con *con); * can press the same key to quickly look something up). * */ -void scratchpad_show(Con *con); +bool scratchpad_show(Con *con); /** * When starting i3 initially (and after each change to the connected outputs), diff --git a/src/commands.c b/src/commands.c index d6733a30..4c03ba32 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1825,19 +1825,20 @@ void cmd_move_scratchpad(I3_CMD) { void cmd_scratchpad_show(I3_CMD) { DLOG("should show scratchpad window\n"); owindow *current; + bool result = false; if (match_is_empty(current_match)) { - scratchpad_show(NULL); + result = scratchpad_show(NULL); } else { TAILQ_FOREACH(current, &owindows, owindows) { DLOG("matching: %p / %s\n", current->con, current->con->name); - scratchpad_show(current->con); + result |= scratchpad_show(current->con); } } cmd_output->needs_tree_render = true; - // XXX: default reply for now, make this a better reply - ysuccess(true); + + ysuccess(result); } /* diff --git a/src/scratchpad.c b/src/scratchpad.c index 95154014..2774396f 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -84,7 +84,7 @@ void scratchpad_move(Con *con) { * can press the same key to quickly look something up). * */ -void scratchpad_show(Con *con) { +bool scratchpad_show(Con *con) { DLOG("should show scratchpad window %p\n", con); Con *__i3_scratch = workspace_get("__i3_scratch", NULL); Con *floating; @@ -97,7 +97,7 @@ void scratchpad_show(Con *con) { floating->scratchpad_state != SCRATCHPAD_NONE) { DLOG("Focused window is a scratchpad window, hiding it.\n"); scratchpad_move(focused); - return; + return true; } /* If the current con or any of its parents are in fullscreen mode, we @@ -124,7 +124,7 @@ void scratchpad_show(Con *con) { * window inside this scratch container in order to * keep the focus the same within this container */ con_activate(con_descend_tiling_focused(walk_con)); - return; + return true; } } @@ -141,7 +141,7 @@ void scratchpad_show(Con *con) { DLOG("Found a visible scratchpad window on another workspace,\n"); DLOG("moving it to this workspace: con = %p\n", walk_con); con_move_to_workspace(walk_con, focused_ws, true, false, false); - return; + return true; } } @@ -149,7 +149,7 @@ void scratchpad_show(Con *con) { * is actually in the scratchpad */ if (con && con->parent->scratchpad_state == SCRATCHPAD_NONE) { DLOG("Window is not in the scratchpad, doing nothing.\n"); - return; + return false; } /* If this was 'scratchpad show' with criteria, we check if it matches a @@ -165,7 +165,7 @@ void scratchpad_show(Con *con) { if (current == active) { DLOG("Window is a scratchpad window, hiding it.\n"); scratchpad_move(con); - return; + return true; } } @@ -178,7 +178,7 @@ void scratchpad_show(Con *con) { if (!con) { LOG("You don't have any scratchpad windows yet.\n"); LOG("Use 'move scratchpad' to move a window to the scratchpad.\n"); - return; + return false; } } else { /* We used a criterion, so we need to do what follows (moving, @@ -206,6 +206,8 @@ void scratchpad_show(Con *con) { } con_activate(con_descend_focused(con)); + + return true; } /* diff --git a/testcases/t/185-scratchpad.t b/testcases/t/185-scratchpad.t index 147890e1..efb5d002 100644 --- a/testcases/t/185-scratchpad.t +++ b/testcases/t/185-scratchpad.t @@ -471,4 +471,50 @@ is(scalar @$nodes, 0, 'no window on current ws anymore'); is($scratch_nodes[0]->{scratchpad_state}, 'changed', 'scratchpad_state changed'); +################################################################################ +# 15: Verify that 'scratchpad show' returns correct info. +################################################################################ + +kill_all_windows; + +my $result = cmd 'scratchpad show'; +is($result->[0]->{success}, 0, 'no scratchpad window and call to scratchpad failed'); + +open_window; +cmd 'move scratchpad'; +$result = cmd 'scratchpad show'; +is($result->[0]->{success}, 1, 'call to scratchpad succeeded'); +$result = cmd 'scratchpad show'; +is($result->[0]->{success}, 1, 'call to scratchpad succeeded'); + +kill_all_windows; +$result = cmd 'scratchpad show'; +is($result->[0]->{success}, 0, 'call to scratchpad failed'); + +################################################################################ +# 16: Verify that 'scratchpad show' with the criteria returns correct info. +################################################################################ + +open_window(name => "scratch-match"); +cmd 'move scratchpad'; + +$result = cmd '[title="scratch-match"] scratchpad show'; +is($result->[0]->{success}, 1, 'call to scratchpad with the criteria succeeded'); + +$result = cmd '[title="nomatch"] scratchpad show'; +is($result->[0]->{success}, 0, 'call to scratchpad with non-matching criteria failed'); + +################################################################################ +# 17: Open a scratchpad window on a workspace, switch to another workspace and +# call 'scratchpad show' again. Verify that it returns correct info. +################################################################################ + +fresh_workspace; +open_window; +cmd 'move scratchpad'; + +fresh_workspace; +$result = cmd 'scratchpad show'; +is($result->[0]->{success}, 1, 'call to scratchpad in another workspace succeeded'); + done_testing;