Run clang-format

This commit is contained in:
outfoxxed 2024-03-02 05:18:59 -08:00
parent f306ecc689
commit a726135c86
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
6 changed files with 302 additions and 264 deletions

View file

@ -1,16 +1,17 @@
#include <regex>
#include <set>
#include <functional> #include <functional>
#include <numeric> #include <numeric>
#include <regex>
#include <set>
#include <hyprland/src/Compositor.hpp> #include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp> #include <hyprland/src/plugins/PluginAPI.hpp>
#include <ranges> #include <ranges>
#include "BitFlag.hpp"
#include "Hy3Layout.hpp" #include "Hy3Layout.hpp"
#include "SelectionHook.hpp" #include "SelectionHook.hpp"
#include "globals.hpp"
#include "conversions.hpp" #include "conversions.hpp"
#include "BitFlag.hpp" #include "globals.hpp"
std::unique_ptr<HOOK_CALLBACK_FN> renderHookPtr = std::unique_ptr<HOOK_CALLBACK_FN> renderHookPtr =
std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::renderHook); std::make_unique<HOOK_CALLBACK_FN>(Hy3Layout::renderHook);
@ -346,9 +347,7 @@ void Hy3Layout::onWindowRemovedTiling(CWindow* window) {
} }
} }
void Hy3Layout::onWindowRemovedFloating(CWindow *window) { void Hy3Layout::onWindowRemovedFloating(CWindow* window) { this->m_focusIntercepts.erase(window); }
this->m_focusIntercepts.erase(window);
}
void Hy3Layout::onWindowFocusChange(CWindow* window) { void Hy3Layout::onWindowFocusChange(CWindow* window) {
auto* node = this->getNodeFromWindow(window); auto* node = this->getNodeFromWindow(window);
@ -380,7 +379,7 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) {
// todo: refactor this // todo: refactor this
auto* top_node = this->getWorkspaceRootGroup(monitor->activeWorkspace); auto* top_node = this->getWorkspaceRootGroup(monitor->activeWorkspace);
if(top_node == nullptr) { if (top_node == nullptr) {
top_node = this->getWorkspaceRootGroup(monitor->specialWorkspaceID); top_node = this->getWorkspaceRootGroup(monitor->specialWorkspaceID);
} }
@ -409,57 +408,61 @@ ShiftDirection reverse(ShiftDirection direction) {
} }
} }
void executeResizeOperation(const Vector2D& delta, eRectCorner corner, Hy3Node *node, CMonitor* monitor) { void executeResizeOperation(
const Vector2D& delta,
eRectCorner corner,
Hy3Node* node,
CMonitor* monitor
) {
if (node == nullptr) return; if (node == nullptr) return;
if (monitor == nullptr) return; if (monitor == nullptr) return;
const bool display_left = const bool display_left =
STICKS(node->position.x, monitor->vecPosition.x + monitor->vecReservedTopLeft.x); STICKS(node->position.x, monitor->vecPosition.x + monitor->vecReservedTopLeft.x);
const bool display_right = STICKS( const bool display_right = STICKS(
node->position.x + node->size.x, node->position.x + node->size.x,
monitor->vecPosition.x + monitor->vecSize.x - monitor->vecReservedBottomRight.x monitor->vecPosition.x + monitor->vecSize.x - monitor->vecReservedBottomRight.x
); );
const bool display_top = const bool display_top =
STICKS(node->position.y, monitor->vecPosition.y + monitor->vecReservedTopLeft.y); STICKS(node->position.y, monitor->vecPosition.y + monitor->vecReservedTopLeft.y);
const bool display_bottom = STICKS( const bool display_bottom = STICKS(
node->position.y + node->size.y, node->position.y + node->size.y,
monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y monitor->vecPosition.y + monitor->vecSize.y - monitor->vecReservedBottomRight.y
); );
Vector2D resize_delta = delta; Vector2D resize_delta = delta;
bool node_is_root = (node->data.type == Hy3NodeType::Group && node->parent == nullptr) bool node_is_root = (node->data.type == Hy3NodeType::Group && node->parent == nullptr)
|| (node->data.type == Hy3NodeType::Window || (node->data.type == Hy3NodeType::Window
&& (node->parent == nullptr || node->parent->parent == nullptr)); && (node->parent == nullptr || node->parent->parent == nullptr));
if (node_is_root) { if (node_is_root) {
if (display_left && display_right) resize_delta.x = 0; if (display_left && display_right) resize_delta.x = 0;
if (display_top && display_bottom) resize_delta.y = 0; if (display_top && display_bottom) resize_delta.y = 0;
}
// Don't execute the logic unless there's something to do
if (resize_delta.x != 0 || resize_delta.y != 0) {
ShiftDirection target_edge_x;
ShiftDirection target_edge_y;
// Determine the direction in which we're going to look for the neighbor node
// that will be resized
if (corner == CORNER_NONE) { // It's probably a keyboard event.
target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
// If the anchor is not at the top/left then reverse the delta
if (target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
if (target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
} else { // It's probably a mouse event
// Resize against the edges corresponding to the selected corner
target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
? ShiftDirection::Left
: ShiftDirection::Right;
target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT ? ShiftDirection::Up
: ShiftDirection::Down;
} }
// Don't execute the logic unless there's something to do
if (resize_delta.x != 0 || resize_delta.y != 0) {
ShiftDirection target_edge_x;
ShiftDirection target_edge_y;
// Determine the direction in which we're going to look for the neighbor node
// that will be resized
if (corner == CORNER_NONE) { // It's probably a keyboard event.
target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
// If the anchor is not at the top/left then reverse the delta
if (target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
if (target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
} else { // It's probably a mouse event
// Resize against the edges corresponding to the selected corner
target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
? ShiftDirection::Left
: ShiftDirection::Right;
target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT
? ShiftDirection::Up
: ShiftDirection::Down;
}
// Find the neighboring node in each axis, which will be either above or at the // Find the neighboring node in each axis, which will be either above or at the
// same level as the initiating node in the layout hierarchy. These are the nodes // same level as the initiating node in the layout hierarchy. These are the nodes
// which must get resized (rather than the initiator) because they are the // which must get resized (rather than the initiator) because they are the
@ -467,13 +470,13 @@ void executeResizeOperation(const Vector2D& delta, eRectCorner corner, Hy3Node *
auto horizontal_neighbor = node->findNeighbor(target_edge_x); auto horizontal_neighbor = node->findNeighbor(target_edge_x);
auto vertical_neighbor = node->findNeighbor(target_edge_y); auto vertical_neighbor = node->findNeighbor(target_edge_y);
static const auto animate = ConfigValue<Hyprlang::INT>("misc:animate_manual_resizes"); static const auto animate = ConfigValue<Hyprlang::INT>("misc:animate_manual_resizes");
// Note that the resize direction is reversed, because from the neighbor's perspective // Note that the resize direction is reversed, because from the neighbor's perspective
// the edge to be moved is the opposite way round. However, the delta is still the same. // the edge to be moved is the opposite way round. However, the delta is still the same.
if (horizontal_neighbor) { if (horizontal_neighbor) {
horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0); horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0);
} }
if (vertical_neighbor) { if (vertical_neighbor) {
vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0); vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0);
@ -484,17 +487,19 @@ void executeResizeOperation(const Vector2D& delta, eRectCorner corner, Hy3Node *
void Hy3Layout::resizeNode(const Vector2D& delta, eRectCorner corner, Hy3Node* node) { void Hy3Layout::resizeNode(const Vector2D& delta, eRectCorner corner, Hy3Node* node) {
// Is the intended target really a node or a floating window? // Is the intended target really a node or a floating window?
auto window = g_pCompositor->m_pLastWindow; auto window = g_pCompositor->m_pLastWindow;
if(window && window->m_bIsFloating) { if (window && window->m_bIsFloating) {
this->resizeActiveWindow(delta, corner, window); this->resizeActiveWindow(delta, corner, window);
} else if (node) { } else if (node) {
auto monitor = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(node->workspace_id)->m_iMonitorID); auto monitor = g_pCompositor->getMonitorFromID(
g_pCompositor->getWorkspaceByID(node->workspace_id)->m_iMonitorID
);
executeResizeOperation(delta, corner, node, monitor); executeResizeOperation(delta, corner, node, monitor);
} }
} }
void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CWindow* pWindow) { void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CWindow* pWindow) {
auto window = pWindow ? pWindow : g_pCompositor->m_pLastWindow; auto window = pWindow ? pWindow : g_pCompositor->m_pLastWindow;
if(window == nullptr || ! g_pCompositor->windowValidMapped(window)) return; if (window == nullptr || !g_pCompositor->windowValidMapped(window)) return;
if (window->m_bIsFloating) { if (window->m_bIsFloating) {
// Use the same logic as the `main` layout for floating windows // Use the same logic as the `main` layout for floating windows
@ -504,8 +509,13 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW
); );
window->m_vRealSize = required_size; window->m_vRealSize = required_size;
g_pXWaylandManager->setWindowSize(window, required_size); g_pXWaylandManager->setWindowSize(window, required_size);
} else if (auto* node = this->getNodeFromWindow(window);node != nullptr) { } else if (auto* node = this->getNodeFromWindow(window); node != nullptr) {
executeResizeOperation(delta, corner, &node->getExpandActor(), g_pCompositor->getMonitorFromID(window->m_iMonitorID)); executeResizeOperation(
delta,
corner,
&node->getExpandActor(),
g_pCompositor->getMonitorFromID(window->m_iMonitorID)
);
} }
} }
@ -896,50 +906,51 @@ void Hy3Layout::shiftNode(Hy3Node& node, ShiftDirection direction, bool once, bo
void shiftFloatingWindow(CWindow* window, ShiftDirection direction) { void shiftFloatingWindow(CWindow* window, ShiftDirection direction) {
static const auto kbd_shift_delta = ConfigValue<Hyprlang::INT>("plugin:hy3:kbd_shift_delta"); static const auto kbd_shift_delta = ConfigValue<Hyprlang::INT>("plugin:hy3:kbd_shift_delta");
if(!window) return; if (!window) return;
Vector2D bounds {0, 0}; Vector2D bounds {0, 0};
// BUG: Assumes horizontal monitor layout // BUG: Assumes horizontal monitor layout
// BUG: Ignores monitor reserved space // BUG: Ignores monitor reserved space
for(auto m: g_pCompositor->m_vMonitors) { for (auto m: g_pCompositor->m_vMonitors) {
bounds.x = std::max(bounds.x, m->vecPosition.x + m->vecSize.x); bounds.x = std::max(bounds.x, m->vecPosition.x + m->vecSize.x);
if(m->ID == window->m_iMonitorID) { if (m->ID == window->m_iMonitorID) {
bounds.y = m->vecPosition.y + m->vecSize.y; bounds.y = m->vecPosition.y + m->vecSize.y;
} }
} }
const int delta = getSearchDirection(direction) == SearchDirection::Forwards const int delta = getSearchDirection(direction) == SearchDirection::Forwards ? *kbd_shift_delta
? *kbd_shift_delta: -*kbd_shift_delta; : -*kbd_shift_delta;
Vector2D movement_delta = (getAxis(direction) == Axis::Horizontal) Vector2D movement_delta =
? Vector2D{ delta, 0 } : Vector2D{ 0, delta }; (getAxis(direction) == Axis::Horizontal) ? Vector2D {delta, 0} : Vector2D {0, delta};
auto window_pos = window->m_vRealPosition.vec(); auto window_pos = window->m_vRealPosition.vec();
auto window_size = window->m_vRealSize.vec(); auto window_size = window->m_vRealSize.vec();
// Keep at least `delta` pixels visible // Keep at least `delta` pixels visible
if (window_pos.x + window_size.x + delta < 0 || window_pos.x + delta > bounds.x) movement_delta.x = 0; if (window_pos.x + window_size.x + delta < 0 || window_pos.x + delta > bounds.x)
if (window_pos.y + window_size.y + delta < 0 || window_pos.y + delta > bounds.y) movement_delta.y = 0; movement_delta.x = 0;
if(movement_delta.x != 0 || movement_delta.y != 0) { if (window_pos.y + window_size.y + delta < 0 || window_pos.y + delta > bounds.y)
movement_delta.y = 0;
if (movement_delta.x != 0 || movement_delta.y != 0) {
auto new_pos = window_pos + movement_delta; auto new_pos = window_pos + movement_delta;
// Do we need to change the workspace? // Do we need to change the workspace?
const auto new_monitor = g_pCompositor->getMonitorFromVector(new_pos); const auto new_monitor = g_pCompositor->getMonitorFromVector(new_pos);
if(new_monitor && new_monitor->ID != window->m_iMonitorID) { if (new_monitor && new_monitor->ID != window->m_iMonitorID) {
// Ignore the movement request if the new workspace is special // Ignore the movement request if the new workspace is special
if(! new_monitor->specialWorkspaceID) { if (!new_monitor->specialWorkspaceID) {
const auto old_workspace = g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID); const auto old_workspace = g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID);
const auto new_workspace = g_pCompositor->getWorkspaceByID(new_monitor->activeWorkspace); const auto new_workspace = g_pCompositor->getWorkspaceByID(new_monitor->activeWorkspace);
const auto previous_monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID); const auto previous_monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID);
const auto original_new_pos = new_pos; const auto original_new_pos = new_pos;
if(new_workspace && previous_monitor) { if (new_workspace && previous_monitor) {
switch (direction) switch (direction) {
{ case ShiftDirection::Left: new_pos.x += new_monitor->vecSize.x; break;
case ShiftDirection::Left: new_pos.x += new_monitor->vecSize.x; break; case ShiftDirection::Right: new_pos.x -= previous_monitor->vecSize.x; break;
case ShiftDirection::Right: new_pos.x -= previous_monitor->vecSize.x; break; case ShiftDirection::Up: new_pos.y += new_monitor->vecSize.y; break;
case ShiftDirection::Up: new_pos.y += new_monitor->vecSize.y; break; case ShiftDirection::Down: new_pos.y -= previous_monitor->vecSize.y; break;
case ShiftDirection::Down: new_pos.y -= previous_monitor->vecSize.y; break; default: UNREACHABLE();
default: UNREACHABLE();
} }
} }
@ -947,7 +958,8 @@ void shiftFloatingWindow(CWindow* window, ShiftDirection direction) {
g_pCompositor->moveWindowToWorkspaceSafe(window, new_workspace); g_pCompositor->moveWindowToWorkspaceSafe(window, new_workspace);
g_pCompositor->setActiveMonitor(new_monitor); g_pCompositor->setActiveMonitor(new_monitor);
const static auto allow_workspace_cycles = ConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles"); const static auto allow_workspace_cycles =
ConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
if (*allow_workspace_cycles) new_workspace->rememberPrevWorkspace(old_workspace); if (*allow_workspace_cycles) new_workspace->rememberPrevWorkspace(old_workspace);
} }
} else { } else {
@ -968,16 +980,16 @@ void Hy3Layout::shiftWindow(int workspace_id, ShiftDirection direction, bool onc
} }
void Hy3Layout::focusMonitor(CMonitor* monitor) { void Hy3Layout::focusMonitor(CMonitor* monitor) {
if(monitor == nullptr) return; if (monitor == nullptr) return;
g_pCompositor->setActiveMonitor(monitor); g_pCompositor->setActiveMonitor(monitor);
const auto focusedNode = this->getWorkspaceFocusedNode(monitor->activeWorkspace); const auto focusedNode = this->getWorkspaceFocusedNode(monitor->activeWorkspace);
if(focusedNode != nullptr) { if (focusedNode != nullptr) {
focusedNode->focus(); focusedNode->focus();
} else { } else {
auto* workspace = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace); auto* workspace = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace);
CWindow* next_window = nullptr; CWindow* next_window = nullptr;
if(workspace != nullptr) { if (workspace != nullptr) {
workspace->setActive(true); workspace->setActive(true);
if (workspace->m_bHasFullscreenWindow) { if (workspace->m_bHasFullscreenWindow) {
next_window = g_pCompositor->getFullscreenWindowOnWorkspace(workspace->m_iID); next_window = g_pCompositor->getFullscreenWindowOnWorkspace(workspace->m_iID);
@ -987,8 +999,8 @@ void Hy3Layout::focusMonitor(CMonitor* monitor) {
} else { } else {
for (auto& w: g_pCompositor->m_vWindows | std::views::reverse) { for (auto& w: g_pCompositor->m_vWindows | std::views::reverse) {
if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2
&& w->m_iWorkspaceID == next_window->m_iWorkspaceID && !w->m_bX11ShouldntFocus && w->m_iWorkspaceID == next_window->m_iWorkspaceID && !w->m_bX11ShouldntFocus
&& !w->m_sAdditionalConfigData.noFocus) && !w->m_sAdditionalConfigData.noFocus)
{ {
next_window = w.get(); next_window = w.get();
break; break;
@ -999,13 +1011,13 @@ void Hy3Layout::focusMonitor(CMonitor* monitor) {
} }
} }
CWindow *getFocusedWindow(const Hy3Node *node) { CWindow* getFocusedWindow(const Hy3Node* node) {
auto search = node; auto search = node;
while(search != nullptr && search->data.type == Hy3NodeType::Group) { while (search != nullptr && search->data.type == Hy3NodeType::Group) {
search = search->data.as_group.focused_child; search = search->data.as_group.focused_child;
} }
if(search == nullptr || search->data.type != Hy3NodeType::Window) { if (search == nullptr || search->data.type != Hy3NodeType::Window) {
return nullptr; return nullptr;
} }
@ -1025,32 +1037,31 @@ bool shiftMatchesLayout(Hy3GroupLayout layout, ShiftDirection direction) {
|| (layout != Hy3GroupLayout::SplitV && !shiftIsVertical(direction)); || (layout != Hy3GroupLayout::SplitV && !shiftIsVertical(direction));
} }
bool covers(const CBox& outer, const CBox& inner) {
bool covers(const CBox &outer, const CBox &inner) { return outer.x <= inner.x && outer.y <= inner.y && outer.x + outer.w >= inner.x + inner.w
return outer.x <= inner.x && outer.y + outer.h >= inner.y + inner.h;
&& outer.y <= inner.y
&& outer.x + outer.w >= inner.x + inner.w
&& outer.y + outer.h >= inner.y + inner.h;
} }
bool isObscured (CWindow* window) { bool isObscured(CWindow* window) {
if(!window) return false; if (!window) return false;
const auto inner_box = window->getWindowMainSurfaceBox(); const auto inner_box = window->getWindowMainSurfaceBox();
bool is_obscured = false; bool is_obscured = false;
for(auto& w :g_pCompositor->m_vWindows | std::views::reverse) { for (auto& w: g_pCompositor->m_vWindows | std::views::reverse) {
if(w.get() == window) { if (w.get() == window) {
// Don't go any further if this is a floating window, because m_vWindows is sorted bottom->top per Compositor.cpp // Don't go any further if this is a floating window, because m_vWindows is sorted bottom->top
if(window->m_bIsFloating) break; else continue; // per Compositor.cpp
if (window->m_bIsFloating) break;
else continue;
} }
if(!w->m_bIsFloating) continue; if (!w->m_bIsFloating) continue;
const auto outer_box = w->getWindowMainSurfaceBox(); const auto outer_box = w->getWindowMainSurfaceBox();
is_obscured = covers(outer_box, inner_box); is_obscured = covers(outer_box, inner_box);
if(is_obscured) break; if (is_obscured) break;
}; };
return is_obscured; return is_obscured;
@ -1063,45 +1074,54 @@ bool isObscured(Hy3Node* node) {
bool isNotObscured(CWindow* window) { return !isObscured(window); } bool isNotObscured(CWindow* window) { return !isObscured(window); }
bool isNotObscured(Hy3Node* node) { return !isObscured(node); } bool isNotObscured(Hy3Node* node) { return !isObscured(node); }
CWindow* getWindowInDirection(CWindow* source, ShiftDirection direction, BitFlag<Layer> layers_same_monitor, BitFlag<Layer> layers_other_monitors) { CWindow* getWindowInDirection(
if(!source) return nullptr; CWindow* source,
if(layers_other_monitors == Layer::None && layers_same_monitor == Layer::None) return nullptr; ShiftDirection direction,
BitFlag<Layer> layers_same_monitor,
BitFlag<Layer> layers_other_monitors
) {
if (!source) return nullptr;
if (layers_other_monitors == Layer::None && layers_same_monitor == Layer::None) return nullptr;
CWindow *target_window = nullptr; CWindow* target_window = nullptr;
const auto source_middle = source->middle(); const auto source_middle = source->middle();
std::optional<Distance> target_distance; std::optional<Distance> target_distance;
const auto static focus_policy = ConfigValue<Hyprlang::INT>("plugin:hy3:focus_obscured_windows_policy"); const auto static focus_policy =
bool permit_obscured_windows = *focus_policy == 0 || (*focus_policy == 2 && layers_same_monitor.HasNot(Layer::Floating | Layer::Tiled)); ConfigValue<Hyprlang::INT>("plugin:hy3:focus_obscured_windows_policy");
bool permit_obscured_windows =
*focus_policy == 0
|| (*focus_policy == 2 && layers_same_monitor.HasNot(Layer::Floating | Layer::Tiled));
const auto source_monitor = g_pCompositor->getMonitorFromID(source->m_iMonitorID); const auto source_monitor = g_pCompositor->getMonitorFromID(source->m_iMonitorID);
const auto next_monitor = layers_other_monitors.HasAny(Layer::Floating | Layer::Tiled) const auto next_monitor =
? g_pCompositor->getMonitorInDirection(source_monitor, directionToChar(direction)) layers_other_monitors.HasAny(Layer::Floating | Layer::Tiled)
: nullptr; ? g_pCompositor->getMonitorInDirection(source_monitor, directionToChar(direction))
: nullptr;
const auto next_workspace = next_monitor const auto next_workspace = next_monitor ? next_monitor->specialWorkspaceID
? next_monitor->specialWorkspaceID ? next_monitor->specialWorkspaceID ? next_monitor->specialWorkspaceID
: next_monitor->activeWorkspace : next_monitor->activeWorkspace
: WORKSPACE_INVALID; : WORKSPACE_INVALID;
auto isCandidate = [=, mon = source->m_iMonitorID](CWindow* w) { auto isCandidate = [=, mon = source->m_iMonitorID](CWindow* w) {
const auto window_layer = w->m_bIsFloating ? Layer::Floating : Layer::Tiled; const auto window_layer = w->m_bIsFloating ? Layer::Floating : Layer::Tiled;
const auto monitor_flags = w->m_iMonitorID == mon ? layers_same_monitor : layers_other_monitors; const auto monitor_flags = w->m_iMonitorID == mon ? layers_same_monitor : layers_other_monitors;
return (monitor_flags.Has(window_layer)) return (monitor_flags.Has(window_layer)) && w->m_bIsMapped && w->m_iX11Type != 2
&& w->m_bIsMapped && !w->m_sAdditionalConfigData.noFocus && !w->isHidden() && !w->m_bX11ShouldntFocus
&& w->m_iX11Type != 2 && (w->m_bPinned || w->m_iWorkspaceID == source->m_iWorkspaceID
&& !w->m_sAdditionalConfigData.noFocus || w->m_iWorkspaceID == next_workspace);
&& !w->isHidden()
&& !w->m_bX11ShouldntFocus
&& (w->m_bPinned || w->m_iWorkspaceID == source->m_iWorkspaceID || w->m_iWorkspaceID == next_workspace);
}; };
for(auto &pw: g_pCompositor->m_vWindows) { for (auto& pw: g_pCompositor->m_vWindows) {
auto w = pw.get(); auto w = pw.get();
if(w != source && isCandidate(w)) { if (w != source && isCandidate(w)) {
auto dist = Distance { direction, source_middle, w->middle() }; auto dist = Distance {direction, source_middle, w->middle()};
if((target_distance.has_value() ? dist < target_distance.value() : dist.isInDirection(direction)) && (permit_obscured_windows || isNotObscured(w)) ) { if ((target_distance.has_value() ? dist < target_distance.value()
: dist.isInDirection(direction))
&& (permit_obscured_windows || isNotObscured(w)))
{
target_window = w; target_window = w;
target_distance = dist; target_distance = dist;
} }
@ -1111,19 +1131,32 @@ CWindow* getWindowInDirection(CWindow* source, ShiftDirection direction, BitFlag
hy3_log(LOG, "getWindowInDirection: closest window to {} is {}", source, target_window); hy3_log(LOG, "getWindowInDirection: closest window to {} is {}", source, target_window);
// If the closest window is on a different monitor and the nearest edge has the same position // If the closest window is on a different monitor and the nearest edge has the same position
// as the last focused window on that monitor's workspace then choose the last focused window instead; this // as the last focused window on that monitor's workspace then choose the last focused window
// allows seamless back-and-forth by direction keys // instead; this allows seamless back-and-forth by direction keys
if(target_window && target_window->m_iMonitorID != source->m_iMonitorID) { if (target_window && target_window->m_iMonitorID != source->m_iMonitorID) {
if (auto new_workspace = g_pCompositor->getWorkspaceByID(next_workspace)) { if (auto new_workspace = g_pCompositor->getWorkspaceByID(next_workspace)) {
if (auto last_focused = new_workspace->getLastFocusedWindow()) { if (auto last_focused = new_workspace->getLastFocusedWindow()) {
auto target_bounds = CBox(target_window->m_vRealPosition.vec(), target_window->m_vRealSize.vec()); auto target_bounds =
auto last_focused_bounds = CBox(last_focused->m_vRealPosition.vec(), last_focused->m_vRealSize.vec()); CBox(target_window->m_vRealPosition.vec(), target_window->m_vRealSize.vec());
auto last_focused_bounds =
CBox(last_focused->m_vRealPosition.vec(), last_focused->m_vRealSize.vec());
if((direction == ShiftDirection::Left && STICKS(target_bounds.x + target_bounds.w, last_focused_bounds.x + last_focused_bounds.w)) if ((direction == ShiftDirection::Left
|| (direction == ShiftDirection::Right && STICKS(target_bounds.x, last_focused_bounds.x)) && STICKS(
|| (direction == ShiftDirection::Up && STICKS(target_bounds.y + target_bounds.h, last_focused_bounds.y + last_focused_bounds.h)) target_bounds.x + target_bounds.w,
|| (direction == ShiftDirection::Down && STICKS(target_bounds.y, last_focused_bounds.y))) { last_focused_bounds.x + last_focused_bounds.w
target_window = last_focused; ))
|| (direction == ShiftDirection::Right && STICKS(target_bounds.x, last_focused_bounds.x)
)
|| (direction == ShiftDirection::Up
&& STICKS(
target_bounds.y + target_bounds.h,
last_focused_bounds.y + last_focused_bounds.h
))
|| (direction == ShiftDirection::Down && STICKS(target_bounds.y, last_focused_bounds.y)
))
{
target_window = last_focused;
} }
} }
} }
@ -1134,15 +1167,20 @@ CWindow* getWindowInDirection(CWindow* source, ShiftDirection direction, BitFlag
void Hy3Layout::shiftFocusToMonitor(ShiftDirection direction) { void Hy3Layout::shiftFocusToMonitor(ShiftDirection direction) {
auto target_monitor = g_pCompositor->getMonitorInDirection(directionToChar(direction)); auto target_monitor = g_pCompositor->getMonitorInDirection(directionToChar(direction));
if(target_monitor) this->focusMonitor(target_monitor); if (target_monitor) this->focusMonitor(target_monitor);
} }
void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible, BitFlag<Layer> eligible_layers) { void Hy3Layout::shiftFocus(
Hy3Node *candidate_node = nullptr; int workspace,
CWindow *closest_window = nullptr; ShiftDirection direction,
Hy3Node *source_node = nullptr; bool visible,
CWindow *source_window = g_pCompositor->m_pLastWindow; BitFlag<Layer> eligible_layers
CWorkspace *source_workspace = g_pCompositor->getWorkspaceByID(workspace); ) {
Hy3Node* candidate_node = nullptr;
CWindow* closest_window = nullptr;
Hy3Node* source_node = nullptr;
CWindow* source_window = g_pCompositor->m_pLastWindow;
CWorkspace* source_workspace = g_pCompositor->getWorkspaceByID(workspace);
if (source_workspace) { if (source_workspace) {
source_window = source_workspace->m_pLastFocusedWindow; source_window = source_workspace->m_pLastFocusedWindow;
@ -1155,56 +1193,66 @@ void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible
return; return;
} }
hy3_log(LOG, hy3_log(
"shiftFocus: Source: {} ({}), workspace: {}, direction: {}, visible: {}", LOG,
source_window, "shiftFocus: Source: {} ({}), workspace: {}, direction: {}, visible: {}",
source_window->m_bIsFloating ? "floating" : "tiled", source_window,
workspace, source_window->m_bIsFloating ? "floating" : "tiled",
(int)direction, workspace,
visible (int) direction,
visible
); );
// If no eligible_layers specified then choose the same layer as the source window // If no eligible_layers specified then choose the same layer as the source window
if(eligible_layers == Layer::None) eligible_layers = source_window->m_bIsFloating ? Layer::Floating : Layer::Tiled; if (eligible_layers == Layer::None)
eligible_layers = source_window->m_bIsFloating ? Layer::Floating : Layer::Tiled;
const auto static focus_policy = ConfigValue<Hyprlang::INT>("plugin:hy3:focus_obscured_windows_policy"); const auto static focus_policy =
bool skip_obscured = *focus_policy == 1 || (*focus_policy == 2 && eligible_layers.Has(Layer::Floating | Layer::Tiled)); ConfigValue<Hyprlang::INT>("plugin:hy3:focus_obscured_windows_policy");
bool skip_obscured = *focus_policy == 1
|| (*focus_policy == 2 && eligible_layers.Has(Layer::Floating | Layer::Tiled));
// Determine the starting point for looking for a tiled node - it's either the // Determine the starting point for looking for a tiled node - it's either the
// workspace's focused node or the floating window's focus entry point (which may be null) // workspace's focused node or the floating window's focus entry point (which may be null)
if (eligible_layers.Has(Layer::Tiled)) { if (eligible_layers.Has(Layer::Tiled)) {
source_node = source_window->m_bIsFloating ? getFocusOverride(source_window, direction) source_node = source_window->m_bIsFloating ? getFocusOverride(source_window, direction)
: getWorkspaceFocusedNode(workspace); : getWorkspaceFocusedNode(workspace);
if(source_node) { if (source_node) {
candidate_node = this->shiftOrGetFocus(*source_node, direction, false, false, visible); candidate_node = this->shiftOrGetFocus(*source_node, direction, false, false, visible);
while(candidate_node && skip_obscured && isObscured(candidate_node)) { while (candidate_node && skip_obscured && isObscured(candidate_node)) {
candidate_node = this->shiftOrGetFocus(*candidate_node, direction, false, false, visible); candidate_node = this->shiftOrGetFocus(*candidate_node, direction, false, false, visible);
} }
} }
} }
BitFlag<Layer> this_monitor = eligible_layers & Layer::Floating; BitFlag<Layer> this_monitor = eligible_layers & Layer::Floating;
if(source_window->m_bIsFloating && !candidate_node) this_monitor |= (eligible_layers & Layer::Tiled); if (source_window->m_bIsFloating && !candidate_node)
this_monitor |= (eligible_layers & Layer::Tiled);
BitFlag<Layer> other_monitors; BitFlag<Layer> other_monitors;
if(!candidate_node) other_monitors |= eligible_layers; if (!candidate_node) other_monitors |= eligible_layers;
// Find the closest window in the right direction. Consider other monitors // Find the closest window in the right direction. Consider other monitors
// if we don't have a tiled candidate // if we don't have a tiled candidate
closest_window = getWindowInDirection(source_window, direction, this_monitor, other_monitors); closest_window = getWindowInDirection(source_window, direction, this_monitor, other_monitors);
// If there's a window in the right direction then choose between that window and the tiled candidate. // If there's a window in the right direction then choose between that window and the tiled
// candidate.
bool focus_closest_window = false; bool focus_closest_window = false;
if(closest_window) { if (closest_window) {
if(candidate_node) { if (candidate_node) {
// If the closest window is tiled then focus the tiled node which was obtained from `shiftOrGetFocus`, // If the closest window is tiled then focus the tiled node which was obtained from
// otherwise focus whichever is closer // `shiftOrGetFocus`, otherwise focus whichever is closer
if(closest_window->m_bIsFloating) { if (closest_window->m_bIsFloating) {
Distance distanceToClosestWindow(direction, source_window->middle(), closest_window->middle()); Distance distanceToClosestWindow(
direction,
source_window->middle(),
closest_window->middle()
);
Distance distanceToTiledNode(direction, source_window->middle(), candidate_node->middle()); Distance distanceToTiledNode(direction, source_window->middle(), candidate_node->middle());
if(distanceToClosestWindow < distanceToTiledNode) { if (distanceToClosestWindow < distanceToTiledNode) {
focus_closest_window = true; focus_closest_window = true;
} }
} }
@ -1214,14 +1262,15 @@ void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible
} }
std::optional<uint64_t> new_monitor_id; std::optional<uint64_t> new_monitor_id;
if(focus_closest_window) { if (focus_closest_window) {
new_monitor_id = closest_window->m_iMonitorID; new_monitor_id = closest_window->m_iMonitorID;
setFocusOverride(closest_window, direction, source_node); setFocusOverride(closest_window, direction, source_node);
g_pCompositor->focusWindow(closest_window); g_pCompositor->focusWindow(closest_window);
} else if(candidate_node) { } else if (candidate_node) {
if(candidate_node->data.type == Hy3NodeType::Window) { if (candidate_node->data.type == Hy3NodeType::Window) {
new_monitor_id = candidate_node->data.as_window->m_iMonitorID; new_monitor_id = candidate_node->data.as_window->m_iMonitorID;
} else if(auto *workspace = g_pCompositor->getWorkspaceByID(candidate_node->getRoot()->workspace_id)) { } else if (auto* workspace = g_pCompositor->getWorkspaceByID(candidate_node->getRoot()->workspace_id))
{
new_monitor_id = workspace->m_iMonitorID; new_monitor_id = workspace->m_iMonitorID;
} }
candidate_node->focusWindow(); candidate_node->focusWindow();
@ -1230,23 +1279,27 @@ void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible
shiftFocusToMonitor(direction); shiftFocusToMonitor(direction);
} }
if(new_monitor_id && new_monitor_id.value() != source_window->m_iMonitorID) { if (new_monitor_id && new_monitor_id.value() != source_window->m_iMonitorID) {
if(auto *monitor = g_pCompositor->getMonitorFromID(new_monitor_id.value())) { if (auto* monitor = g_pCompositor->getMonitorFromID(new_monitor_id.value())) {
g_pCompositor->setActiveMonitor(monitor); g_pCompositor->setActiveMonitor(monitor);
} }
} }
} }
Hy3Node* Hy3Layout::getFocusOverride(CWindow* src, ShiftDirection direction) { Hy3Node* Hy3Layout::getFocusOverride(CWindow* src, ShiftDirection direction) {
if(auto intercept = this->m_focusIntercepts.find(src); intercept != this->m_focusIntercepts.end()) { if (auto intercept = this->m_focusIntercepts.find(src);
intercept != this->m_focusIntercepts.end())
{
Hy3Node** accessor = intercept->second.forDirection(direction); Hy3Node** accessor = intercept->second.forDirection(direction);
if(auto override = *accessor) { if (auto override = *accessor) {
// If the root isn't valid or is on a different workspsace then update the intercept data // If the root isn't valid or is on a different workspsace then update the intercept data
if(override->workspace_id != src->m_iWorkspaceID || !std::ranges::contains(this->nodes, *override)) { if (override->workspace_id != src->m_iWorkspaceID
|| !std::ranges::contains(this->nodes, *override))
{
*accessor = nullptr; *accessor = nullptr;
// If there are no remaining overrides then discard the intercept // If there are no remaining overrides then discard the intercept
if(intercept->second.isEmpty()) { if (intercept->second.isEmpty()) {
this->m_focusIntercepts.erase(intercept); this->m_focusIntercepts.erase(intercept);
} }
} }
@ -1259,16 +1312,17 @@ Hy3Node* Hy3Layout::getFocusOverride(CWindow* src, ShiftDirection direction) {
} }
void Hy3Layout::setFocusOverride(CWindow* src, ShiftDirection direction, Hy3Node* dest) { void Hy3Layout::setFocusOverride(CWindow* src, ShiftDirection direction, Hy3Node* dest) {
if(auto intercept = this->m_focusIntercepts.find(src);intercept != this->m_focusIntercepts.end()) { if (auto intercept = this->m_focusIntercepts.find(src);
intercept != this->m_focusIntercepts.end())
{
*intercept->second.forDirection(direction) = dest; *intercept->second.forDirection(direction) = dest;
} else { } else {
FocusOverride override; FocusOverride override;
*override.forDirection(direction) = dest; *override.forDirection(direction) = dest;
this->m_focusIntercepts.insert({ src, override }); this->m_focusIntercepts.insert({src, override});
} }
} }
void changeNodeWorkspaceRecursive(Hy3Node& node, CWorkspace* workspace) { void changeNodeWorkspaceRecursive(Hy3Node& node, CWorkspace* workspace) {
node.workspace_id = workspace->m_iID; node.workspace_id = workspace->m_iID;
@ -2006,7 +2060,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
} }
insert = parent_group.children.begin(); insert = parent_group.children.begin();
} else if (break_origin == parent_group.children.back() && shiftIsForward(direction)) { } else if (break_origin == parent_group.children.back() && shiftIsForward(direction)) {
if (!shift) { if (!shift) {
return nullptr; return nullptr;
} }
insert = parent_group.children.end(); insert = parent_group.children.end();
@ -2030,7 +2084,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus(
if (shiftIsForward(direction)) insert = iter; if (shiftIsForward(direction)) insert = iter;
else insert = std::next(iter); else insert = std::next(iter);
} }
} else { } else {
return (*iter)->getFocusedNode(); return (*iter)->getFocusedNode();
} }
} else { } else {

View file

@ -1,9 +1,10 @@
#pragma once #pragma once
#include <list> #include <list>
#include <map>
#include <set> #include <set>
#include <hyprland/src/layout/IHyprLayout.hpp> #include <hyprland/src/layout/IHyprLayout.hpp>
#include <map>
#include "BitFlag.hpp" #include "BitFlag.hpp"
class Hy3Layout; class Hy3Layout;
@ -21,27 +22,15 @@ enum class ShiftDirection {
Right, Right,
}; };
enum class SearchDirection { enum class SearchDirection { None, Forwards, Backwards };
None,
Forwards,
Backwards
};
enum class Axis { None, Horizontal, Vertical }; enum class Axis { None, Horizontal, Vertical };
enum class Layer { enum class Layer { None = 0, Tiled = 1 << 0, Floating = 1 << 1 };
None = 0,
Tiled = 1 << 0,
Floating = 1 << 1
};
inline Layer operator| (Layer a, Layer b) { inline Layer operator|(Layer a, Layer b) { return static_cast<Layer>((int) a | (int) b); }
return static_cast<Layer>((int)a | (int)b);
}
inline Layer operator& (Layer a, Layer b) { inline Layer operator&(Layer a, Layer b) { return static_cast<Layer>((int) a & (int) b); }
return static_cast<Layer>((int)a & (int)b);
}
#include "Hy3Node.hpp" #include "Hy3Node.hpp"
#include "TabGroup.hpp" #include "TabGroup.hpp"
@ -90,27 +79,24 @@ enum class ExpandFullscreenOption {
}; };
struct FocusOverride { struct FocusOverride {
Hy3Node *left = nullptr; Hy3Node* left = nullptr;
Hy3Node *up = nullptr; Hy3Node* up = nullptr;
Hy3Node *right = nullptr; Hy3Node* right = nullptr;
Hy3Node *down = nullptr; Hy3Node* down = nullptr;
Hy3Node **forDirection(ShiftDirection direction) { Hy3Node** forDirection(ShiftDirection direction) {
switch(direction) { switch (direction) {
case ShiftDirection::Left: return &left; case ShiftDirection::Left: return &left;
case ShiftDirection::Up: return &up; case ShiftDirection::Up: return &up;
case ShiftDirection::Right: return &right; case ShiftDirection::Right: return &right;
case ShiftDirection::Down: return &down; case ShiftDirection::Down: return &down;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
bool isEmpty() { bool isEmpty() { return !(left || right || up || down); }
return !(left || right || up || down);
}
}; };
class Hy3Layout: public IHyprLayout { class Hy3Layout: public IHyprLayout {
public: public:
virtual void onWindowCreated(CWindow*, eDirection = DIRECTION_DEFAULT); virtual void onWindowCreated(CWindow*, eDirection = DIRECTION_DEFAULT);
@ -121,7 +107,8 @@ public:
virtual bool isWindowTiled(CWindow*); virtual bool isWindowTiled(CWindow*);
virtual void recalculateMonitor(const int& monitor_id); virtual void recalculateMonitor(const int& monitor_id);
virtual void recalculateWindow(CWindow*); virtual void recalculateWindow(CWindow*);
virtual void resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CWindow* pWindow = nullptr); virtual void
resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CWindow* pWindow = nullptr);
virtual void fullscreenRequestForWindow(CWindow*, eFullscreenMode, bool enable_fullscreen); virtual void fullscreenRequestForWindow(CWindow*, eFullscreenMode, bool enable_fullscreen);
virtual std::any layoutMessage(SLayoutMessageHeader header, std::string content); virtual std::any layoutMessage(SLayoutMessageHeader header, std::string content);
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);

View file

@ -862,9 +862,7 @@ int directionToIteratorIncrement(ShiftDirection direction) {
} }
} }
Vector2D Hy3Node::middle() { Vector2D Hy3Node::middle() { return this->position + this->size / 2.f; }
return this->position + this->size / 2.f;
}
void Hy3Node::resize(ShiftDirection direction, double delta, bool no_animation) { void Hy3Node::resize(ShiftDirection direction, double delta, bool no_animation) {
auto& parent_node = this->parent; auto& parent_node = this->parent;
@ -899,7 +897,12 @@ void Hy3Node::resize(ShiftDirection direction, double delta, bool no_animation)
parent_node->recalcSizePosRecursive(no_animation); parent_node->recalcSizePosRecursive(no_animation);
} else { } else {
hy3_log(WARN, "Requested size ratio {} or {} out of bounds, ignoring", requested_size_ratio, requested_neighbor_size_ratio); hy3_log(
WARN,
"Requested size ratio {} or {} out of bounds, ignoring",
requested_size_ratio,
requested_neighbor_size_ratio
);
} }
} }
} }
@ -925,17 +928,17 @@ void Hy3Node::swapData(Hy3Node& a, Hy3Node& b) {
} }
bool Hy3Node::hasChild(Hy3Node* node) { bool Hy3Node::hasChild(Hy3Node* node) {
if(this->data.type == Hy3NodeType::Window) return false; if (this->data.type == Hy3NodeType::Window) return false;
auto n = node; auto n = node;
while(n != nullptr && n->parent != this) n = n->parent; while (n != nullptr && n->parent != this) n = n->parent;
return n != nullptr; return n != nullptr;
} }
Hy3Node* Hy3Node::getRoot() { Hy3Node* Hy3Node::getRoot() {
Hy3Node* maybeRoot = this; Hy3Node* maybeRoot = this;
while(maybeRoot->parent) maybeRoot = maybeRoot->parent; while (maybeRoot->parent) maybeRoot = maybeRoot->parent;
return maybeRoot; return maybeRoot;
} }

View file

@ -147,14 +147,18 @@ struct Distance {
secondary_axis = getAxis(direction) == Axis::Horizontal ? dist.y : dist.x; secondary_axis = getAxis(direction) == Axis::Horizontal ? dist.y : dist.x;
} }
bool operator< (Distance other) { bool operator<(Distance other) {
return signbit(primary_axis) == signbit(other.primary_axis) return signbit(primary_axis) == signbit(other.primary_axis)
&& (abs(primary_axis) < abs(other.primary_axis) || (primary_axis == other.primary_axis && abs(secondary_axis) < abs(other.secondary_axis))); && (abs(primary_axis) < abs(other.primary_axis)
|| (primary_axis == other.primary_axis
&& abs(secondary_axis) < abs(other.secondary_axis)));
} }
bool operator> (Distance other) { bool operator>(Distance other) {
return signbit(primary_axis) == signbit(other.primary_axis) return signbit(primary_axis) == signbit(other.primary_axis)
&& (abs(primary_axis) > abs(other.primary_axis) || (primary_axis == other.primary_axis && abs(secondary_axis) > abs(other.secondary_axis))); && (abs(primary_axis) > abs(other.primary_axis)
|| (primary_axis == other.primary_axis
&& abs(secondary_axis) > abs(other.secondary_axis)));
} }
bool isSameDirection(Distance other) { bool isSameDirection(Distance other) {
@ -162,6 +166,7 @@ struct Distance {
} }
bool isInDirection(ShiftDirection direction) { bool isInDirection(ShiftDirection direction) {
return std::signbit(primary_axis) == (getSearchDirection(direction) == SearchDirection::Forwards); return std::signbit(primary_axis)
== (getSearchDirection(direction) == SearchDirection::Forwards);
} }
}; };

View file

@ -1,47 +1,35 @@
#include "Hy3Node.hpp" #include "Hy3Node.hpp"
Axis getAxis(Hy3GroupLayout layout) { Axis getAxis(Hy3GroupLayout layout) {
switch (layout) switch (layout) {
{ case Hy3GroupLayout::SplitH: return Axis::Horizontal;
case Hy3GroupLayout::SplitH: case Hy3GroupLayout::SplitV: return Axis::Vertical;
return Axis::Horizontal; default: return Axis::None;
case Hy3GroupLayout::SplitV:
return Axis::Vertical;
default:
return Axis::None;
} }
} }
Axis getAxis(ShiftDirection direction) { Axis getAxis(ShiftDirection direction) {
switch (direction) switch (direction) {
{
case ShiftDirection::Left: case ShiftDirection::Left:
case ShiftDirection::Right: case ShiftDirection::Right: return Axis::Horizontal;
return Axis::Horizontal;
case ShiftDirection::Down: case ShiftDirection::Down:
case ShiftDirection::Up: case ShiftDirection::Up: return Axis::Vertical;
return Axis::Vertical; default: return Axis::None;
default:
return Axis::None;
} }
} }
SearchDirection getSearchDirection(ShiftDirection direction) { SearchDirection getSearchDirection(ShiftDirection direction) {
switch(direction) { switch (direction) {
case ShiftDirection::Left: case ShiftDirection::Left:
case ShiftDirection::Up: case ShiftDirection::Up: return SearchDirection::Backwards;
return SearchDirection::Backwards; case ShiftDirection::Right:
case ShiftDirection::Right: case ShiftDirection::Down: return SearchDirection::Forwards;
case ShiftDirection::Down: default: return SearchDirection::None;
return SearchDirection::Forwards;
default:
return SearchDirection::None;
} }
} }
char directionToChar(ShiftDirection direction) { char directionToChar(ShiftDirection direction) {
switch (direction) switch (direction) {
{
case ShiftDirection::Left: return 'l'; case ShiftDirection::Left: return 'l';
case ShiftDirection::Up: return 'u'; case ShiftDirection::Up: return 'u';
case ShiftDirection::Down: return 'd'; case ShiftDirection::Down: return 'd';

View file

@ -8,7 +8,7 @@
int workspace_for_action(bool allow_fullscreen = false) { int workspace_for_action(bool allow_fullscreen = false) {
if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return -1; if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return -1;
if(!g_pCompositor->m_pLastMonitor) return -1; if (!g_pCompositor->m_pLastMonitor) return -1;
int workspace_id = g_pCompositor->m_pLastMonitor->activeWorkspace; int workspace_id = g_pCompositor->m_pLastMonitor->activeWorkspace;
@ -128,14 +128,15 @@ void dispatch_movefocus(std::string value) {
bool visible; bool visible;
BitFlag<Layer> layers; BitFlag<Layer> layers;
for(auto arg: args) { for (auto arg: args) {
if(arg == "visible") visible = true; if (arg == "visible") visible = true;
else if ((layerArg = parseLayerArg(arg))) layers |= layerArg.value(); else if ((layerArg = parseLayerArg(arg))) layers |= layerArg.value();
} }
if(!layerArg) { if (!layerArg) {
const static auto default_movefocus_layer = ConfigValue<Hyprlang::STRING>("plugin:hy3:default_movefocus_layer"); const static auto default_movefocus_layer =
if((layerArg = parseLayerArg(*default_movefocus_layer))) layers |= layerArg.value(); ConfigValue<Hyprlang::STRING>("plugin:hy3:default_movefocus_layer");
if ((layerArg = parseLayerArg(*default_movefocus_layer))) layers |= layerArg.value();
} }
g_Hy3Layout->shiftFocus(workspace, shift.value(), visible, layers); g_Hy3Layout->shiftFocus(workspace, shift.value(), visible, layers);
@ -275,7 +276,7 @@ void dispatch_resizenode(std::string value) {
auto* node = g_Hy3Layout->getWorkspaceFocusedNode(workspace, false, true); auto* node = g_Hy3Layout->getWorkspaceFocusedNode(workspace, false, true);
const auto delta = g_pCompositor->parseWindowVectorArgsRelative(value, Vector2D(0, 0)); const auto delta = g_pCompositor->parseWindowVectorArgsRelative(value, Vector2D(0, 0));
hy3_log(LOG, "resizeNode: node: {:x}, delta: {:X}", (uintptr_t)node, delta); hy3_log(LOG, "resizeNode: node: {:x}, delta: {:X}", (uintptr_t) node, delta);
g_Hy3Layout->resizeNode(delta, CORNER_NONE, node); g_Hy3Layout->resizeNode(delta, CORNER_NONE, node);
} }