From 7a61abddb9a45ee0c237e0fb6e1ba16d9dc879b5 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 24 Apr 2023 01:49:43 -0700 Subject: [PATCH] Extract shift / layout comparisons to functions --- src/Hy3Layout.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 1118d2f..faaa283 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -979,8 +979,16 @@ bool shiftIsForward(ShiftDirection direction) { return direction == ShiftDirection::Right || direction == ShiftDirection::Down; } -Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) { +bool shiftIsVertical(ShiftDirection direction) { + return direction == ShiftDirection::Up || direction == ShiftDirection::Down; +} +bool shiftMatchesLayout(Hy3GroupLayout layout, ShiftDirection direction) { + return (layout == Hy3GroupLayout::SplitV && shiftIsVertical(direction)) + || (layout != Hy3GroupLayout::SplitV && !shiftIsVertical(direction)); +} + +Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) { auto* break_origin = &node; auto* break_parent = break_origin->parent; @@ -990,11 +998,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo auto& group = break_parent->data.as_group; // must be a group in order to be a parent - if (((group.layout == Hy3GroupLayout::SplitH || group.layout == Hy3GroupLayout::Tabbed) - && (direction == ShiftDirection::Left || direction == ShiftDirection::Right)) - || (group.layout == Hy3GroupLayout::SplitV - && (direction == ShiftDirection::Up || direction == ShiftDirection::Down))) - { + if (shiftMatchesLayout(group.layout, direction)) { // group has the correct orientation // if this movement would break out of the group, continue the break loop (do not enter this if) @@ -1049,11 +1053,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, boo bool shift_after = false; - if (((group_data.layout == Hy3GroupLayout::SplitH || group_data.layout == Hy3GroupLayout::Tabbed) - && (direction == ShiftDirection::Left || direction == ShiftDirection::Right)) - || (group_data.layout == Hy3GroupLayout::SplitV - && (direction == ShiftDirection::Up || direction == ShiftDirection::Down))) - { + if (shiftMatchesLayout(group_data.layout, direction)) { // if the group has the same orientation as movement pick the last/first child based // on movement direction if (shiftIsForward(direction)) iter = group_data.children.begin();