-
Notifications
You must be signed in to change notification settings - Fork 777
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
Conversation
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 |
Sorry. Misunderstood the problem. |
There was a problem hiding this 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 :-)
include/scratchpad.h
Outdated
@@ -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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be true
.
I am having trouble on implementing the test code for IPC. 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; |
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); |
There was a problem hiding this comment.
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).
Up |
testcases/t/298-scratchpad-show.t
Outdated
# vim:ts=4:sw=4:expandtab | ||
# | ||
# Please read the following documents before working on tests: | ||
# �~@� https://build.i3wm.org/docs/testsuite.html |
There was a problem hiding this comment.
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.
testcases/t/298-scratchpad-show.t
Outdated
# 2: Verify that 'scratchpad show' with the criteria returns correct info. | ||
################################################################################ | ||
my $ws = fresh_workspace; | ||
cmd 'workspace $ws'; |
There was a problem hiding this comment.
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.
testcases/t/298-scratchpad-show.t
Outdated
################################################################################ | ||
kill_all_windows; | ||
|
||
cmd "workspace foo-1"; |
There was a problem hiding this comment.
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
testcases/t/298-scratchpad-show.t
Outdated
open_window; | ||
cmd 'move scratchpad'; | ||
|
||
cmd "workspace foo-2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@orestisf1993 Thanks for the review. Up. |
testcases/t/185-scratchpad.t
Outdated
################################################################################ | ||
# 15: Verify that 'scratchpad show' returns correct info. | ||
################################################################################ | ||
kill_all_windows; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Requested changes are all done. |
Thanks. I'd merge it but I'll let @Airblader have a final look. |
Thanks! |
Fix the issue #3227(#3227).