kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

commit 99fbdee1ddeaa34e503162ce78700129c3b0c113
parent 67fc7bc8bb2b264864d6b6c1ecfd8c870311b8d4
Author: deurzen <max@deurzen.net>
Date:   Tue, 21 Jun 2022 00:39:11 +0200

adds overlapping paper layout

Diffstat:
Minclude/kranewl/input/key-bindings.hh | 6++++++
Minclude/kranewl/layout.hh | 2++
Msrc/kranewl/layout.cc | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/include/kranewl/input/key-bindings.hh b/include/kranewl/input/key-bindings.hh @@ -358,6 +358,12 @@ static const KeyBindings key_bindings = { .repeatable = false } }, +{ { XKB_KEY_P, MODKEY | WLR_MODIFIER_SHIFT }, + { + .action = CALL(set_layout(LayoutHandler::LayoutKind::OverlappingPaper)), + .repeatable = false + } +}, { { XKB_KEY_Y, MODKEY | WLR_MODIFIER_SHIFT }, { .action = CALL(set_layout(LayoutHandler::LayoutKind::HorizontalStack)), diff --git a/include/kranewl/layout.hh b/include/kranewl/layout.hh @@ -31,6 +31,7 @@ public: // non-overlapping tiled layouts Paper, CompactPaper, + OverlappingPaper, DoubleStack, CompactDoubleStack, HorizontalStack, @@ -157,6 +158,7 @@ private: void arrange_stack_deck(Region, placement_vector, view_iter, view_iter) const; void arrange_double_deck(Region, placement_vector, view_iter, view_iter) const; void arrange_paper(Region, placement_vector, view_iter, view_iter) const; + void arrange_overlapping_paper(Region, placement_vector, view_iter, view_iter) const; void arrange_compact_paper(Region, placement_vector, view_iter, view_iter) const; void arrange_double_stack(Region, placement_vector, view_iter, view_iter) const; void arrange_compact_double_stack(Region, placement_vector, view_iter, view_iter) const; diff --git a/src/kranewl/layout.cc b/src/kranewl/layout.cc @@ -47,6 +47,7 @@ LayoutHandler::LayoutHandler() NEW_LAYOUT(LayoutKind::DoubleDeck), NEW_LAYOUT(LayoutKind::Paper), NEW_LAYOUT(LayoutKind::CompactPaper), + NEW_LAYOUT(LayoutKind::OverlappingPaper), NEW_LAYOUT(LayoutKind::DoubleStack), NEW_LAYOUT(LayoutKind::CompactDoubleStack), NEW_LAYOUT(LayoutKind::HorizontalStack), @@ -142,6 +143,11 @@ LayoutHandler::arrange( arrange_compact_paper(screen_region, placements, begin, end); break; } + case LayoutKind::OverlappingPaper: + { + arrange_overlapping_paper(screen_region, placements, begin, end); + break; + } case LayoutKind::DoubleStack: { arrange_double_stack(screen_region, placements, begin, end); @@ -1041,6 +1047,108 @@ LayoutHandler::arrange_compact_paper( } void +LayoutHandler::arrange_overlapping_paper( + Region screen_region, + placement_vector placements, + view_iter begin, + view_iter end +) const +{ + TRACE(); + + static const float MIN_W_RATIO = 0.5; + + const Layout::LayoutData_ptr data = *mp_layout->data.active_element(); + int n = static_cast<int>(end - begin); + + if (n == 1) { + placements.emplace_back(Placement{ + mp_layout->config.method, + *begin, + NO_DECORATION, + screen_region + }); + + return; + } + + int cw; + if (data->main_factor > MIN_W_RATIO) { + cw = static_cast<int>(static_cast<float>(screen_region.dim.w) * data->main_factor); + } else { + cw = static_cast<int>(static_cast<float>(screen_region.dim.w) * MIN_W_RATIO); + } + + int w = static_cast<int>(static_cast<float>(screen_region.dim.w - cw) + / static_cast<float>(n - 1)); + + bool contains_active = false; + const auto last_active = std::max_element( + begin, + end, + [&contains_active](const View_ptr lhs, const View_ptr rhs) { + if (lhs->focused()) { + contains_active = true; + return false; + } else if (rhs->focused()) { + contains_active = true; + return true; + } + + return lhs->last_focused() < rhs->last_focused(); + } + ); + + bool after_active = false; + int i = 0; + + std::transform( + begin, + end, + std::back_inserter(placements), + [=,this,&after_active,&i](View_ptr view) -> Placement{ + int x = screen_region.pos.x + static_cast<int>(i++ * w); + + if ((!contains_active && *last_active == view) || view->focused()) { + after_active = true; + + return Placement{ + mp_layout->config.method, + view, + mp_layout->config.decoration, + Region{ + Pos{ + x, + screen_region.pos.y + }, + Dim{ + cw, + screen_region.dim.h + } + } + }; + } else { + return Placement{ + mp_layout->config.method, + view, + mp_layout->config.decoration, + Region{ + Pos{ + x, + screen_region.pos.y + }, + Dim{ + cw, + screen_region.dim.h + } + } + }; + } + } + ); +} + +void LayoutHandler::arrange_double_stack( Region screen_region, placement_vector placements, @@ -1432,6 +1540,23 @@ LayoutHandler::Layout::kind_to_config(LayoutKind kind) false }; } + case LayoutKind::OverlappingPaper: + { + return LayoutConfig{ + Placement::PlacementMethod::Tile, + Decoration{ + Frame{ + Extents{1, 1, 0, 0} + }, + DEFAULT_COLOR_SCHEME + }, + true, + true, + true, + false, + false + }; + } case LayoutKind::DoubleStack: { return LayoutConfig{ @@ -1567,6 +1692,7 @@ LayoutHandler::Layout::kind_to_default_data(LayoutKind kind) case LayoutKind::DoubleDeck: // fallthrough case LayoutKind::Paper: // fallthrough case LayoutKind::CompactPaper: // fallthrough + case LayoutKind::OverlappingPaper: // fallthrough case LayoutKind::DoubleStack: // fallthrough case LayoutKind::CompactDoubleStack: // fallthrough case LayoutKind::HorizontalStack: // fallthrough