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

Prepare arrange code for type safe arguments #2511

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

RyanDwyer
Copy link
Member

This commit changes the arrange code in a way that will support type safe arguments.

The arrange_output et al functions are now public, however I opted not to use them directly yet. I've kept the generic arrange_windows there for convenience until type safety is fully implemented. This means this patch has much less risk of breaking things as it would otherwise.

To be type safe, arrange_children_of cannot exist in its previous form because the thing passed to it could be either a workspace or a container. So it's now renamed to arrange_children and accepts a list_t, as well as the parent layout and parent's box.

There was some code which checked the grandparent's layout to see if it was tabbed or stacked and adjusted the Y offset of the grandchild accordingly. Accessing the grandparent layout isn't easy when using type safe arguments, and it seemed odd to even need to do this. I determined that this was needed because a child of a tabbed container would have a swayc Y matching the top of the tab bar. I've changed this so a child of a tabbed container will have a swayc Y matching the bottom of the tab bar, which means we don't need to access the grandparent layout. Some tweaks to the rendering and autoconfigure code have been made to implement this, and the container_at code appears to work without needing any changes.

arrange_children_of (now arrange_children) would check if the parent had gaps and would copy them to the child, effectively making the workspace's gaps recurse into all children. We can't do this any more without passing has_gaps, gaps_inner and gaps_outer as arguments to arrange_children, so I've changed the add_gaps function to retrieve it from the workspace directly.

apply_tabbed_or_stacked_layout has been split into two functions, as it had different logic depending on the layout.

Lastly, arrange.h had an unnecessary include of transaction.h. I've removed it, which means I've had to add it to several other files.

@RyanDwyer RyanDwyer force-pushed the refactor-arrange branch 3 times, most recently from 0d5dc48 to a1f34d9 Compare August 26, 2018 00:17
@RedSoxFan
Copy link
Member

arrange_children_of (now arrange_children) would check if the parent had gaps and would copy them to the child, effectively making the workspace's gaps recurse into all children. We can't do this any more without passing has_gaps, gaps_inner and gaps_outer as arguments to arrange_children, so I've changed the add_gaps function to retrieve it from the workspace directly.

I don't personally use gaps so I could be misunderstanding something, but this doesn't sound right to me. The gaps appear to only be copied from the parent to the child if the child does not have gaps and the parent does. Since it looks like it is possible to override gaps on a per container/view basis, wouldn't it be possible that the gaps at the workspace-level are not the correct gaps to apply?

@RyanDwyer
Copy link
Member Author

Hmm. That's true. Looking at the i3-gaps readme, it looks like current is supposed to apply them to the workspace anyway, meaning you shouldn't be able to apply them per-container. This looks like a bug to me, unless sway has intentionally deviated from upstream behaviour in a backwards-incompatible way.

@RedSoxFan
Copy link
Member

Looking at the i3-gaps readme, it looks like current is supposed to apply them to the workspace anyway, meaning you shouldn't be able to apply them per-container. This looks like a bug to me, unless sway has intentionally deviated from upstream behaviour in a backwards-incompatible way.

Based on the changes to sway/commands/gaps.c in the open PR #2131, it looks like you are correct and this is actually a bug and not intentional.

I'm fine with removing the ability to change gaps at the container/view level for now. I think that if it is re-implemented in the future, it should be done as an extension (rather than a deviation) and use an unused scope (ex container)

@ddevault
Copy link
Contributor

We once had @Airblader explain how our gaps were supposed to be and confirmed that we got it right at some point.

#307

@Airblader
Copy link

Yes, I can confirm again that current applies to the current workspace, not the current container. We don't have container level gaps in i3-gaps.

@RyanDwyer
Copy link
Member Author

Found a bug in this - please hold off on merging.

@RyanDwyer RyanDwyer changed the title Prepare arrange code for type safe arguments [WIP] Prepare arrange code for type safe arguments Aug 28, 2018
This commit changes the arrange code in a way that will support type
safe arguments.

The arrange_output et al functions are now public, however I opted not
to use them directly yet. I've kept the generic arrange_windows there
for convenience until type safety is fully implemented. This means this
patch has much less risk of breaking things as it would otherwise.

To be type safe, arrange_children_of cannot exist in its previous form
because the thing passed to it could be either a workspace or a
container. So it's now renamed to arrange_children and accepts a list_t,
as well as the parent layout and parent's box.

There was some code which checked the grandparent's layout to see if it
was tabbed or stacked and adjusted the Y offset of the grandchild
accordingly. Accessing the grandparent layout isn't easy when using type
safe arguments, and it seemed odd to even need to do this. I determined
that this was needed because a child of a tabbed container would have a
swayc Y matching the top of the tab bar. I've changed this so a child of
a tabbed container will have a swayc Y matching the bottom of the tab
bar, which means we don't need to access the grandparent layout.  Some
tweaks to the rendering and autoconfigure code have been made to
implement this, and the container_at code appears to work without
needing any changes.

arrange_children_of (now arrange_children) would check if the parent had
gaps and would copy them to the child, effectively making the
workspace's gaps recurse into all children. We can't do this any more
without passing has_gaps, gaps_inner and gaps_outer as arguments to
arrange_children, so I've changed the add_gaps function to retrieve it
from the workspace directly.

apply_tabbed_or_stacked_layout has been split into two functions, as it
had different logic depending on the layout.

Lastly, arrange.h had an unnecessary include of transaction.h. I've
removed it, which means I've had to add it to several other files.
* In layout command, arrange parent of parent - not sure why this is
needed but it is
* Remove gap adjustment when rendering
* Workspace should use outer gaps, not inner
* Add exceptions for tabbed and stacked containers
* Don't mess with gap state when splitting a container
@RyanDwyer RyanDwyer changed the title [WIP] Prepare arrange code for type safe arguments Prepare arrange code for type safe arguments Aug 28, 2018
@RyanDwyer
Copy link
Member Author

All good now.

The bug was a rendering issue when using tabbed containers with inner gaps. The tab bar was misaligned.

@ddevault ddevault merged commit 8323043 into swaywm:master Aug 28, 2018
@ddevault
Copy link
Contributor

Thanks!

@RyanDwyer RyanDwyer deleted the refactor-arrange branch August 28, 2018 21:45
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.

4 participants