commit 16ca98918e74b0af06f67c39b6033f79835c6feb
parent 99fbdee1ddeaa34e503162ce78700129c3b0c113
Author: deurzen <max@deurzen.net>
Date: Tue, 21 Jun 2022 10:21:47 +0200
adds cross-track focus cycling
Diffstat:
6 files changed, 61 insertions(+), 57 deletions(-)
diff --git a/include/kranewl/input/cursor-bindings.hh b/include/kranewl/input/cursor-bindings.hh
@@ -84,12 +84,24 @@ static const CursorBindings cursor_bindings = {
{ { GLOBAL, SCROLLDOWN, MODKEY },
CALL_NOFOCUS({
static_cast<void>(view);
- model.cycle_focus(Direction::Forward);
+ model.cycle_focus_track(Direction::Forward);
})
},
{ { GLOBAL, SCROLLUP, MODKEY },
CALL_NOFOCUS({
static_cast<void>(view);
+ model.cycle_focus_track(Direction::Backward);
+ })
+},
+{ { GLOBAL, SCROLLDOWN, MODKEY | SECKEY },
+ CALL_NOFOCUS({
+ static_cast<void>(view);
+ model.cycle_focus(Direction::Forward);
+ })
+},
+{ { GLOBAL, SCROLLUP, MODKEY | SECKEY },
+ CALL_NOFOCUS({
+ static_cast<void>(view);
model.cycle_focus(Direction::Backward);
})
},
diff --git a/include/kranewl/input/key-bindings.hh b/include/kranewl/input/key-bindings.hh
@@ -228,6 +228,18 @@ static const KeyBindings key_bindings = {
.repeatable = true
}
},
+{ { XKB_KEY_j, MODKEY | SECKEY },
+ {
+ .action = CALL(cycle_focus(Direction::Forward)),
+ .repeatable = true
+ }
+},
+{ { XKB_KEY_k, MODKEY | SECKEY },
+ {
+ .action = CALL(cycle_focus(Direction::Backward)),
+ .repeatable = true
+ }
+},
{ { XKB_KEY_J, MODKEY | WLR_MODIFIER_SHIFT },
{
.action = CALL(drag_focus_track(Direction::Forward)),
diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh
@@ -103,7 +103,6 @@ public:
void cycle_focus(Direction);
void cycle_focus_track(Direction);
- void drag_focus(Direction);
void drag_focus_track(Direction);
void toggle_track();
diff --git a/include/kranewl/workspace.hh b/include/kranewl/workspace.hh
@@ -106,7 +106,7 @@ public:
SceneLayer track_layer() const;
void activate_track(SceneLayer);
void toggle_track();
- void cycle_track(Direction);
+ bool cycle_track(Direction);
void add_view_to_track(View_ptr, SceneLayer);
void remove_view_from_track(View_ptr, SceneLayer);
@@ -119,9 +119,8 @@ public:
View_ptr prev_view() const;
std::optional<View_ptr> find_view(ViewSelector const&) const;
- std::pair<std::optional<View_ptr>, std::optional<View_ptr>> cycle(Direction);
+ std::pair<std::optional<View_ptr>, std::optional<View_ptr>> cycle_focus(Direction);
std::pair<std::optional<View_ptr>, std::optional<View_ptr>> cycle_focus_track(Direction);
- std::pair<std::optional<View_ptr>, std::optional<View_ptr>> drag(Direction);
std::pair<std::optional<View_ptr>, std::optional<View_ptr>> drag_focus_track(Direction);
template<typename UnaryPredicate>
diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc
@@ -599,7 +599,7 @@ Model::cycle_focus(Direction direction)
if (mp_workspace->size() <= 1)
return;
- mp_workspace->cycle(direction);
+ mp_workspace->cycle_focus(direction);
sync_focus();
}
@@ -616,19 +616,6 @@ Model::cycle_focus_track(Direction direction)
}
void
-Model::drag_focus(Direction direction)
-{
- TRACE();
-
- if (mp_workspace->size() <= 1)
- return;
-
- mp_workspace->drag(direction);
- sync_focus();
- apply_layout(mp_workspace);
-}
-
-void
Model::drag_focus_track(Direction direction)
{
TRACE();
diff --git a/src/kranewl/workspace.cc b/src/kranewl/workspace.cc
@@ -196,7 +196,7 @@ Workspace::toggle_track()
activate_track(m_prev_track_layer);
}
-void
+bool
Workspace::cycle_track(Direction direction)
{
TRACE();
@@ -220,11 +220,12 @@ Workspace::cycle_track(Direction direction)
: m_track_layer + 1
);
break;
- default: return;
+ default: return false;
}
} while (m_tracks[m_track_layer]->empty() && cycles--);
activate_track(m_track_layer);
+ return cycles >= 0;
}
void
@@ -342,30 +343,51 @@ Workspace::find_view(ViewSelector const& selector) const
}
std::pair<std::optional<View_ptr>, std::optional<View_ptr>>
-Workspace::cycle(Direction direction)
+Workspace::cycle_focus(Direction direction)
{
TRACE();
+ View_ptr prev_active = mp_active;
+
switch (direction) {
case Direction::Forward:
{
- if (!layout_wraps() && m_views.active_index() == m_views.last_index())
- return std::pair{std::nullopt, std::nullopt};
+ if (mp_track->active_index() == mp_track->last_index()) {
+ if (!cycle_track(direction))
+ return std::pair{std::nullopt, std::nullopt};
+ else
+ mp_track->activate_at_index(0);
+ } else
+ return cycle_focus_track(direction);
+
break;
}
case Direction::Backward:
{
- if (!layout_wraps() && m_views.active_index() == 0)
- return std::pair{std::nullopt, std::nullopt};
+ if (mp_track->active_index() == 0) {
+ if (!cycle_track(direction))
+ return std::pair{std::nullopt, std::nullopt};
+ else
+ mp_track->activate_at_index(mp_track->last_index());
+ } else
+ return cycle_focus_track(direction);
+
break;
}
}
- std::pair<std::optional<View_ptr>, std::optional<View_ptr>> views
- = m_views.cycle_active(direction);
- mp_active = views.second.value_or(nullptr);
+ mp_active = mp_track->active_element().value_or(nullptr);
+ if (mp_active)
+ m_views.activate_element(mp_active);
- return views;
+ return std::pair{
+ prev_active
+ ? std::optional{prev_active}
+ : std::nullopt,
+ mp_active
+ ? std::optional{mp_active}
+ : std::nullopt
+ };
}
std::pair<std::optional<View_ptr>, std::optional<View_ptr>>
@@ -399,33 +421,6 @@ Workspace::cycle_focus_track(Direction direction)
}
std::pair<std::optional<View_ptr>, std::optional<View_ptr>>
-Workspace::drag(Direction direction)
-{
- TRACE();
-
- switch (direction) {
- case Direction::Forward:
- {
- if (!layout_wraps() && m_views.active_index() == m_views.last_index())
- return std::pair{std::nullopt, std::nullopt};
- break;
- }
- case Direction::Backward:
- {
- if (!layout_wraps() && m_views.active_index() == 0)
- return std::pair{std::nullopt, std::nullopt};
- break;
- }
- }
-
- std::pair<std::optional<View_ptr>, std::optional<View_ptr>> views
- = m_views.drag_active(direction);
- mp_active = views.second.value_or(nullptr);
-
- return views;
-}
-
-std::pair<std::optional<View_ptr>, std::optional<View_ptr>>
Workspace::drag_focus_track(Direction direction)
{
TRACE();