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

Fix commands: criteria, layout, move, workspace #2392

Merged
merged 11 commits into from
Aug 6, 2018

Conversation

ianyfan
Copy link
Contributor

@ianyfan ianyfan commented Jul 31, 2018

Ref #2336

Fixes #1518

Criteria:

  • urgent
  • con_id=__focused__

Commands:

  • layout
  • document <criteria> focus
  • move
    • documentation
    • move position center
    • move to mark
    • move to workspace back_and_forth
    • --no-auto-back-and-forth
    • make "to" optional
  • workspace
    • --no-auto-back-and-forth
    • back_and_forth

Also prevents renaming workspace to "back_and_forth", as well as making it clear that they cannot be named to "special" workspace names.

Copy link
Contributor

@minus7 minus7 left a comment

Choose a reason for hiding this comment

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

Ah, didn't see this was still WIP

sway/criteria.c Outdated
return NULL;
}
size_t id = view->swayc->id;
int len = snprintf(NULL, 0, "%zu", id) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the standard way to compute the string's length?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. It's not a length (as in number of chars), it's a size (as in number of bytes that will get malloc'ed) so it probably makes more sense to name it id_size. Also it should be a size_t, not an int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Also it should be a size_t, not an int.

*printf returns an int and so it makes sense to leave it as it is. It really is splitting hairs, though.

Copy link
Member

Choose a reason for hiding this comment

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

fwiw I found that function after using snprintf like that myself, but for integer string length conversion we have this in common/util.c (declared in include/util.h):

int numlen(int n) {
        if (n == 0) {
                return 1;
        }
        return log10(n) + 1;
}

(It doesn't handle negative integers nor the full range of size_t, but both are fixable by just changing the prototype of the function. We only have one user though, it's a shame but it might be just as well to remove that function...)

sway/sway.5.scd Outdated

*move* left|right|up|down [<px>]
*layout* toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...
Copy link
Contributor

Choose a reason for hiding this comment

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

Your code doesn't seem to handle split here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, thanks.

@ddevault
Copy link
Contributor

ddevault commented Aug 2, 2018

Can we work on this a few commands at a time? I'd rather not do a mega-PR which attempts to close #2336 all in one go.

@ianyfan
Copy link
Contributor Author

ianyfan commented Aug 2, 2018

Got it, I'll add a checklist in the description

@ianyfan ianyfan changed the title [WIP] Add missing i3 commands [WIP] Fix commands: criteria, layout, move Aug 4, 2018
@ianyfan ianyfan force-pushed the commands branch 2 times, most recently from 3272167 to 750f38c Compare August 4, 2018 23:16
@ianyfan ianyfan changed the title [WIP] Fix commands: criteria, layout, move [WIP] Fix commands: criteria, layout, move, workspace Aug 4, 2018
@ianyfan ianyfan changed the title [WIP] Fix commands: criteria, layout, move, workspace Fix commands: criteria, layout, move, workspace Aug 4, 2018
@ianyfan
Copy link
Contributor Author

ianyfan commented Aug 4, 2018

Ready for review, though not sure if I've missed any edge cases in testing.

Copy link
Member

@RedSoxFan RedSoxFan left a comment

Choose a reason for hiding this comment

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

Style: split lines so they don't go past column 80.

return current_workspace;

char *name_cpy = strdup(name);
char *first_word = strtok(name_cpy, " ");
Copy link
Member

Choose a reason for hiding this comment

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

What's the reasoning for getting and checking against the first word in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it to consolidate logic, treating commands '[move container to] workspace next thing' as just the next workspace without having to check for each case again in their respective functions. However, thinking about it, I guess it overcorrects if the name is quoted: 'workspace "next thing"' also gets treated as the next workspace. So I'm not opposed to changing it.

ws = current_workspace;
} else if (strcasecmp(first_word, "back_and_forth") == 0) {
if (prev_workspace_name) {
ws = container_find(&root_container, _workspace_by_name,
Copy link
Member

Choose a reason for hiding this comment

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

Should this recreate the workspace if it doesn't exist anymore?

Copy link
Contributor Author

@ianyfan ianyfan Aug 5, 2018

Choose a reason for hiding this comment

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

It's recreated in the commands that call it, but I wasn't sure whether it should be recreated in all cases (there's a few other functions that call it), so I didn't.

@RedSoxFan
Copy link
Member

Just needs the long lines split and then it will LGTM.

@ianyfan
Copy link
Contributor Author

ianyfan commented Aug 6, 2018

The logic is all done now, I think; I'll have a look at splitting the long lines later, and maybe squash some commits together.

@ddevault ddevault dismissed RedSoxFan’s stale review August 6, 2018 15:30

long lines are addressed

@ddevault ddevault merged commit 1a8bee6 into swaywm:master Aug 6, 2018
@ddevault
Copy link
Contributor

ddevault commented Aug 6, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants