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

Implement strip_workspace_name. #3083

Merged
merged 1 commit into from
Nov 19, 2018

Conversation

cedws
Copy link
Contributor

@cedws cedws commented Nov 6, 2018

#3082.
For some reason, the strip_workspace_name is deemed invalid in the config file. Still trying to find out why.

@cedws
Copy link
Contributor Author

cedws commented Nov 6, 2018

I'm almost certain that I have put a strip_workspace_name everywhere necessary, but it's still invalid when the config loads.

2018-11-06 20:18:29 - [sway/config.c:655] Read line 212:     strip_workspace_numbers yes
2018-11-06 20:18:29 - [sway/commands.c:374] handling config command 'bar strip_workspace_numbers yes'
2018-11-06 20:18:29 - [sway/commands.c:156] find_handler(strip_workspace_numbers)
2018-11-06 20:18:29 - [sway/commands.c:409] Subcommand: strip_workspace_numbers yes
2018-11-06 20:18:29 - [sway/commands.c:156] find_handler(strip_workspace_numbers)
2018-11-06 20:18:29 - [sway/commands/bar/strip_workspace_numbers.c:23] Stripping workspace numbers on bar: bar-0
2018-11-06 20:18:29 - [sway/config.c:655] Read line 213:     strip_workspace_name yes
2018-11-06 20:18:29 - [sway/commands.c:374] handling config command 'bar strip_workspace_name yes'
2018-11-06 20:18:29 - [sway/commands.c:156] find_handler(strip_workspace_name)
2018-11-06 20:18:29 - [sway/commands.c:409] Subcommand: strip_workspace_name yes
2018-11-06 20:18:29 - [sway/commands.c:156] find_handler(strip_workspace_name)
2018-11-06 20:18:29 - [sway/config.c:708] Error on line 213 'strip_workspace_name yes': Unknown/invalid command (/home/cedwards/.config/sway/config)

It fails to find the handler, even though I've defined it:

...
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
{ "strip_workspace_name", bar_cmd_strip_workspace_name },
...

I've also tried an rm -rf build since I had to add a file to meson.build. No luck.

@RedSoxFan
Copy link
Member

...
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
{ "strip_workspace_name", bar_cmd_strip_workspace_name },
...

The handlers need to be in alphabetical order. Just reverse the two lines and it should work.

@cedws
Copy link
Contributor Author

cedws commented Nov 6, 2018

Can't believe I missed that, thanks a lot.

swaybar/render.c Outdated Show resolved Hide resolved
@cedws cedws changed the title [WIP] Implement strip_workspace_name. Implement strip_workspace_name. Nov 7, 2018
sway/commands/bar/strip_workspace_name.c Outdated Show resolved Hide resolved
sway/commands/bar/strip_workspace_name.c Show resolved Hide resolved
sway/commands/bar/strip_workspace_numbers.c Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
swaybar/render.c Outdated Show resolved Hide resolved
swaybar/render.c Outdated Show resolved Hide resolved
@cedws
Copy link
Contributor Author

cedws commented Nov 8, 2018

I have committed another solution. I'm not sure how picky i3 is about the [n]:[NAME] formatting, currently the code will just split by the : character and use the substrings.

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.

Since strtok alters the original string, strip_workspace_name is forced when strip_workspace_numbers is set to no. Additionally, anything else that uses ws->name will have just the number (regardless of the settings), instead of the full name.

Also, when strip_workspace_numbers is set to yes and the workspace is not of the form n:name, then (null) is displayed.

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.

Just needs documentation. Aside from that LGTM.

@cedws
Copy link
Contributor Author

cedws commented Nov 8, 2018

Let me know before you merge and I will do a squash.

RedSoxFan
RedSoxFan previously approved these changes Nov 8, 2018
swaybar/ipc.c Outdated Show resolved Hide resolved
@RedSoxFan RedSoxFan dismissed their stale review November 9, 2018 00:50

missed edge cases

@cedws
Copy link
Contributor Author

cedws commented Nov 9, 2018

This commit fixes all the edge cases I'm aware of. I noticed some unrelated behaviour with custom workspace names - if you rename a workspace so that the num becomes 2 (swaymsg rename workspace "1" to "2"), using $mod+2 won't switch to that workspace. Is this intended?

EDIT - I've squashed the commits together, but the relevant changes are in ipc.c.

RyanDwyer
RyanDwyer previously approved these changes Nov 9, 2018
Copy link
Member

@RyanDwyer RyanDwyer left a comment

Choose a reason for hiding this comment

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

Code LGTM but I haven't tested it.

BTW, my original intention was for the swaybar_workspace struct to have something like name and label rather than name, stripped_name and stripped_number. You could then make render_workspace_button use the label field without having to check the stripping config. But I'm not fussed about this.

Copy link
Contributor

@ianyfan ianyfan left a comment

Choose a reason for hiding this comment

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

The variable names stripped_name and stripped_number keep confusing me because I keep forgetting which way round they are. But that might just be me.

swaybar/ipc.c Outdated Show resolved Hide resolved
@cedws
Copy link
Contributor Author

cedws commented Nov 10, 2018

@RyanDwyer I think this commit should do it the way you suggested.

swaybar/ipc.c Outdated Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
@cedws
Copy link
Contributor Author

cedws commented Nov 13, 2018

I have managed to get strip_workspace_numbers to work with/without a semicolon according to i3's behaviour, but having issues with strip_workspace_name.

There's some kind of memory bug I can't figure out. I'm allocating 2 bytes, one for the first character and one for the null terminator, and then calling strncat to copy the first character, but something is going wrong here.

swaybar/ipc.c Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
@cedws
Copy link
Contributor Author

cedws commented Nov 14, 2018

Ready for review again, it has the same behaviour as i3 AFAIK from testing.

swaybar/ipc.c Outdated Show resolved Hide resolved
@cedws cedws force-pushed the feature/StripWorkspaceName branch 2 times, most recently from e0e8919 to 7090cd9 Compare November 15, 2018 12:33
@cedws
Copy link
Contributor Author

cedws commented Nov 15, 2018

I have done some testing and these cases now work:

  • strip_workspace_name 1234: names the workspace 1234
  • strip_workspace_numbers :abcd names the workspace abcd :abcd
  • strip_workspace_name 1234:abcd names the workspace 1234
  • strip_workspace_numbers 1234:abcd names the workspace abcd
  • strip_workspace_name 1234abcd names the workspace 1234
  • strip_workspace_numbers 1234abcd names the workspace abcd

@ianyfan
Copy link
Contributor

ianyfan commented Nov 15, 2018

strip_workspace_numbers :abcd should name the workspace :abcd

@RyanDwyer RyanDwyer dismissed their stale review November 15, 2018 14:02

Dismissing my review. There's been heaps of changes since I last looked at this.

@cedws
Copy link
Contributor Author

cedws commented Nov 15, 2018

@ddevault It looks like something has gone wrong with the CI.

swaybar/ipc.c Show resolved Hide resolved
Copy link
Contributor

@ianyfan ianyfan left a comment

Choose a reason for hiding this comment

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

Implementation all works now, just (mostly) style fixes.

common/util.c Outdated Show resolved Hide resolved
sway/commands/bar/strip_workspace_name.c Outdated Show resolved Hide resolved
sway/commands/bar/strip_workspace_name.c Outdated Show resolved Hide resolved
sway/commands/bar/strip_workspace_numbers.c Outdated Show resolved Hide resolved
sway/commands/bar/strip_workspace_numbers.c Outdated Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
swaybar/ipc.c Outdated Show resolved Hide resolved
if (bar->config->strip_workspace_name) {
free(ws->label);
ws->label = malloc(len_offset + 1 * sizeof(char));
ws->label[len_offset] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realised you should be able to remove the three other lines in this block and this will still work, since it'll terminate the string in the correct place, even if there's leftover characters after it.

} else if (bar->config->strip_workspace_numbers) {
len_offset += ws->label[len_offset] == ':';
if (strlen(ws->name) > len_offset) {
free(ws->label);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could remove this line and use strcpy below, though it's less of a fun solution as the one above.

swaybar/ipc.c Outdated Show resolved Hide resolved
@emersion emersion merged commit bf7af9c into swaywm:master Nov 19, 2018
@emersion
Copy link
Member

Thanks!

@cedws cedws deleted the feature/StripWorkspaceName branch January 16, 2019 02:40
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.

None yet

6 participants