Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "scratchpad show" return correct info #3230

Merged
merged 1 commit into from
Apr 21, 2018
Merged

Conversation

hwangcc23
Copy link
Contributor

Fix the issue #3227(#3227).

@Airblader
Copy link
Member

I'm sorry, I don't understand the fix. We want to return whether we have successfully shown a window or not. That means we need to use the information coming from scratchpad_show.

@Airblader Airblader added the waiting Waiting for feedback/changes from the author of the issue/PR. Make sure to notify us with a comment. label Apr 6, 2018
@hwangcc23
Copy link
Contributor Author

Sorry. Misunderstood the problem.
Up.

Copy link
Member

@Airblader Airblader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! There's a couple of changes and I also think we can & should add tests for all these different cases :-)

@@ -28,8 +28,10 @@ void scratchpad_move(Con *con);
* scratchpad window, this serves as a shortcut to hide it again (so the user
* can press the same key to quickly look something up).
*
* Return true if a window is successfully showning.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo, but let's make change it to

Returns true either if con was in the scratchpad and is now shown or if con was moved back into the scratchpad due to toggling.

src/commands.c Outdated
} 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should report a failure if there was a failure for any matched window (that's how we try to do it everywhere), so this should be result &= ….

src/scratchpad.c Outdated
@@ -83,8 +83,10 @@ void scratchpad_move(Con *con) {
* scratchpad window, this serves as a shortcut to hide it again (so the user
* can press the same key to quickly look something up).
*
* Return true if a window is successfully showning.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

src/scratchpad.c Outdated
@@ -97,7 +99,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 false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return true. I think the true/false semantics should be that it's true whenever we successfully did something with con.

src/scratchpad.c Outdated
@@ -165,7 +167,7 @@ void scratchpad_show(Con *con) {
if (current == active) {
DLOG("Window is a scratchpad window, hiding it.\n");
scratchpad_move(con);
return;
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be true.

@hwangcc23
Copy link
Contributor Author

I am having trouble on implementing the test code for IPC.
Is there anyone having the suggestion or hint?
Thanks.

Here is my test code. I cannot get the returned value of 'scratchpad show' correctly in the test code.

sub scratchpad_show_subtest {
    my ($expect) = @_;
    my @events = events_for(
        sub { cmd 'scratchpad show' },
        'floating_nodes');
    my @temp = grep { $_->{scratchpad_state} eq 'change' } @events;
    is(scalar @temp, $expect, 'Success');
}
fresh_workspace;
open_window;
cmd 'move scratchpad';
subtest 'scratchpad show', \&scratchpad_show_subtest, 1;

@orestisfl
Copy link
Member

@hwangcc23

fresh_workspace;
open_window;
cmd 'move scratchpad';
my $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');

} 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should report a success if there is any matched window shown or hidden (due to toggled).
This is for passing the test with the criteria(The test case 2: Verify that 'scratchpad show' with the criteria returns correct info).

@hwangcc23
Copy link
Contributor Author

Up

# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# �~@� https://build.i3wm.org/docs/testsuite.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extend 185-scratchpad.t? Your â~@¢ character seems to be wrong here too.

# 2: Verify that 'scratchpad show' with the criteria returns correct info.
################################################################################
my $ws = fresh_workspace;
cmd 'workspace $ws';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you do here: open a new workspace with a random name, then immediately switch to a workspace named $ws (you used single quotes). You don't need a variable or the cmd so I think you can remove both.

################################################################################
kill_all_windows;

cmd "workspace foo-1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: just use fresh_workspace

open_window;
cmd 'move scratchpad';

cmd "workspace foo-2";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@hwangcc23
Copy link
Contributor Author

@orestisf1993 Thanks for the review.

Up.

################################################################################
# 15: Verify that 'scratchpad show' returns correct info.
################################################################################
kill_all_windows;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicky but can you add a newline after the comment blocks, like the rest of the file does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Will send the PR again.

src/scratchpad.c Outdated
@@ -83,8 +83,11 @@ void scratchpad_move(Con *con) {
* scratchpad window, this serves as a shortcut to hide it again (so the user
* can press the same key to quickly look something up).
*
* Returns true either if con was in the scratchpad and is now shown or if con
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly inaccurate because true is also returned if there is an unfocused scratchpad on the current workspace. We don't really need to document the return value since it's a bit obvious.

Fix the issue i3#3227(i3#3227).

1).Make cmd_scratchpad_show() use the information coming from scratchpad_show().
2).Add a test case 298-scratchpad-show.t.
@hwangcc23
Copy link
Contributor Author

Requested changes are all done.

@orestisfl
Copy link
Member

Thanks. I'd merge it but I'll let @Airblader have a final look.

@Airblader Airblader merged commit 5a0f02b into i3:next Apr 21, 2018
@Airblader
Copy link
Member

Thanks!

@hwangcc23 hwangcc23 deleted the fix-3227 branch April 23, 2018 04:01
@orestisfl orestisfl removed the waiting Waiting for feedback/changes from the author of the issue/PR. Make sure to notify us with a comment. label Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants