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 15d439e256ded28b510a235b2082a33ee8918d89
parent f33e62e3d0d27d6c7b2f466ede69c6e9fa102074
Author: deurzen <max@deurzen.net>
Date:   Sun, 29 May 2022 22:53:05 +0200

adds context switching actions

Diffstat:
Minclude/kranewl/model.hh | 1+
Msrc/kranewl/model.cc | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
2 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -48,6 +48,7 @@ public: Output_ptr create_output(struct wlr_output*, struct wlr_scene_output*, Region const&&); void register_output(Output_ptr); void unregister_output(Output_ptr); + void output_reserve_context(Output_ptr); XDGView_ptr create_xdg_shell_view(struct wlr_xdg_surface*, Seat_ptr); #ifdef XWAYLAND diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -182,26 +182,7 @@ Model::create_output( std::forward<Region const&&>(output_region) ); - std::optional<Context_ptr> context - = m_contexts.first_element_with_condition([](Context_ptr context) { - return !context->output(); - }); - - if (context) { - output->set_context(*context); - (*context)->set_output(output); - - spdlog::info("Assigned context {} to output {}", - (*context)->index(), - output->mp_wlr_output->name - ); - } else - // TODO: dynamically generate new context - spdlog::error("Depleted allocatable contexts," - " output {} will not house any workspaces", - output->mp_wlr_output->name - ); - + output_reserve_context(output); register_output(output); return output; @@ -230,6 +211,32 @@ Model::unregister_output(Output_ptr output) } void +Model::output_reserve_context(Output_ptr output) +{ + TRACE(); + + std::optional<Context_ptr> context + = m_contexts.first_element_with_condition([](Context_ptr context) { + return !context->output(); + }); + + if (context) { + output->set_context(*context); + (*context)->set_output(output); + + spdlog::info("Assigned context {} to output {}", + (*context)->index(), + output->mp_wlr_output->name + ); + } else + // TODO: dynamically generate new context + spdlog::error("Depleted allocatable contexts," + " output {} will not house any workspaces", + output->mp_wlr_output->name + ); +} + +void Model::focus_view(View_ptr view) { TRACE(); @@ -713,27 +720,50 @@ Model::toggle_context() { TRACE(); + if (mp_prev_context) + activate_context(mp_prev_context); } void -Model::activate_next_context(Direction) +Model::activate_next_context(Direction direction) { TRACE(); - + activate_context(m_contexts.next_index(direction)); } void -Model::activate_context(Index) +Model::activate_context(Index index) { TRACE(); + if (index < m_contexts.size()) + activate_context(context(index)); } void -Model::activate_context(Context_ptr) +Model::activate_context(Context_ptr next_context) { TRACE(); + if (next_context == mp_context) + return; + + abort_cursor_interactive(); + + Context_ptr prev_context = mp_output->context(); + mp_prev_context = prev_context; + + Output_ptr next_output = mp_output; + Output_ptr prev_output = next_context->output(); + + if (next_output != prev_output) + prev_output->set_context(prev_context); + + next_output->set_context(next_context); + m_contexts.activate_element(next_context); + mp_context = next_context; + + activate_workspace(next_context->workspace()); } void