-
Notifications
You must be signed in to change notification settings - Fork 93
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
Allow resize in both direcitons on Meta+Right click #860
Open
russelltg
wants to merge
3
commits into
pop-os:master
Choose a base branch
from
russelltg:resize_2dirs_wmeta
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2463,41 +2463,74 @@ impl TilingLayout { | |
edges | ||
} | ||
|
||
// Returns (left_node_idx, up_node_idx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should just create a struct definition for the return type at this point, so we can name these fields. |
||
pub fn resize_request( | ||
&self, | ||
mut node_id: NodeId, | ||
window_node_id: NodeId, | ||
edge: ResizeEdge, | ||
) -> Option<(NodeId, usize, Orientation)> { | ||
) -> (Option<(NodeId, usize)>, Option<(NodeId, usize)>) { | ||
let tree = self.tree(); | ||
// need to find two NodeIds and associated index | ||
// that indicate the groups and then the index that needs to be resized inside each one | ||
// the one that's closer to the root is the "upper" one, and the one closer to the hovered window is the "lower" one | ||
|
||
while let Some(group_id) = tree.get(&node_id).unwrap().parent().cloned() { | ||
let orientation = tree.get(&group_id).unwrap().data().orientation(); | ||
let node_idx = tree | ||
.children_ids(&group_id) | ||
let mut try_lower_node_id = window_node_id; | ||
while let Some(try_lower_group_id) = tree.get(&try_lower_node_id).unwrap().parent().cloned() | ||
{ | ||
let orientation = tree.get(&try_lower_group_id).unwrap().data().orientation(); | ||
let lower_node_idx_in_group = tree | ||
.children_ids(&try_lower_group_id) | ||
.unwrap() | ||
.position(|id| id == &node_id) | ||
.position(|id| id == &try_lower_node_id) | ||
.unwrap(); | ||
let total = tree.children_ids(&group_id).unwrap().count(); | ||
if orientation == Orientation::Vertical { | ||
if node_idx > 0 && edge.contains(ResizeEdge::LEFT) { | ||
return Some((group_id, node_idx - 1, orientation)); | ||
} | ||
if node_idx < total - 1 && edge.contains(ResizeEdge::RIGHT) { | ||
return Some((group_id, node_idx, orientation)); | ||
} | ||
} else { | ||
if node_idx > 0 && edge.contains(ResizeEdge::TOP) { | ||
return Some((group_id, node_idx - 1, orientation)); | ||
} | ||
if node_idx < total - 1 && edge.contains(ResizeEdge::BOTTOM) { | ||
return Some((group_id, node_idx, orientation)); | ||
let lower_total = tree.children_ids(&try_lower_group_id).unwrap().count(); | ||
|
||
if let Some(left_up_idx) = | ||
resize_edge_to_left_up_idx(orientation, lower_node_idx_in_group, lower_total, edge) | ||
{ | ||
let lower_node_idx = Some((try_lower_group_id.clone(), left_up_idx)); // found a lower group id! | ||
|
||
// need to find closest parent that | ||
// 1. is the opposite orientation as the lower group we found | ||
// 2. can be resized in the direction we want | ||
let mut try_upper_node_id = try_lower_group_id; | ||
let mut parent_left_up_node_idx = None; | ||
while let Some(try_upper_group_id) = | ||
tree.get(&try_upper_node_id).unwrap().parent().cloned() | ||
{ | ||
// ensure meets condition (1) | ||
if tree.get(&try_upper_group_id).unwrap().data().orientation() != orientation { | ||
let upper_node_idx_in_group = tree | ||
.children_ids(&try_upper_group_id) | ||
.unwrap() | ||
.position(|id| id == &try_upper_node_id) | ||
.unwrap(); | ||
let upper_total = tree.children_ids(&try_upper_group_id).unwrap().count(); | ||
|
||
// ensure meets condition (2) | ||
if let Some(idx) = resize_edge_to_left_up_idx( | ||
!orientation, | ||
upper_node_idx_in_group, | ||
upper_total, | ||
edge, | ||
) { | ||
parent_left_up_node_idx = Some((try_upper_group_id.clone(), idx)); // found an upper group id! | ||
break; | ||
} | ||
} | ||
try_upper_node_id = try_upper_group_id; | ||
} | ||
|
||
return match orientation { | ||
Orientation::Horizontal => (parent_left_up_node_idx, lower_node_idx), | ||
Orientation::Vertical => (lower_node_idx, parent_left_up_node_idx), | ||
}; | ||
} | ||
|
||
node_id = group_id; | ||
try_lower_node_id = try_lower_group_id; | ||
} | ||
|
||
None | ||
(None, None) | ||
} | ||
|
||
pub fn resize( | ||
|
@@ -5413,3 +5446,28 @@ fn scale_to_center<C>( | |
) | ||
} | ||
} | ||
|
||
fn resize_edge_to_left_up_idx( | ||
orientation: Orientation, | ||
node_idx: usize, | ||
total: usize, | ||
edge: ResizeEdge, | ||
) -> Option<usize> { | ||
if orientation == Orientation::Vertical { | ||
if node_idx > 0 && edge.contains(ResizeEdge::LEFT) { | ||
return Some(node_idx - 1); | ||
} | ||
if node_idx < total - 1 && edge.contains(ResizeEdge::RIGHT) { | ||
return Some(node_idx); | ||
} | ||
} else { | ||
if node_idx > 0 && edge.contains(ResizeEdge::TOP) { | ||
return Some(node_idx - 1); | ||
} | ||
if node_idx < total - 1 && edge.contains(ResizeEdge::BOTTOM) { | ||
return Some(node_idx); | ||
} | ||
} | ||
|
||
None | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
left and right? Shouldn't this be left and up?