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 f33e62e3d0d27d6c7b2f466ede69c6e9fa102074
parent a7b49052b31ce3a03b4bbeabce1bac513fe8a60d
Author: deurzen <max@deurzen.net>
Date:   Sun, 29 May 2022 22:25:06 +0200

adds workspace switching actions

Diffstat:
Minclude/kranewl/model.hh | 11+++++++++++
Minclude/kranewl/tree/view.hh | 4++--
Msrc/kranewl/input/cursor.cc | 8++++----
Msrc/kranewl/model.cc | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/kranewl/tree/view.cc | 8++++----
5 files changed, 143 insertions(+), 12 deletions(-)

diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -38,6 +38,9 @@ public: void exit(); View_ptr focused_view() const; + Workspace_ptr workspace(Index) const; + Context_ptr context(Index) const; + Output_ptr output(Index) const; KeyBindings const& key_bindings() const; CursorBindings const& cursor_bindings() const; @@ -76,10 +79,18 @@ public: void move_view_to_output(View_ptr, Output_ptr); void move_view_to_focused_output(View_ptr); + void toggle_workspace(); + void toggle_workspace_current_context(); + void activate_next_workspace(Direction); + void activate_next_workspace_current_context(Direction); void activate_workspace(Index); + void activate_workspace_current_context(Index); void activate_workspace(Workspace_ptr); + void toggle_context(); + void activate_next_context(Direction); void activate_context(Index); void activate_context(Context_ptr); + void toggle_output(); void activate_output(Index); void activate_output(Output_ptr); diff --git a/include/kranewl/tree/view.hh b/include/kranewl/tree/view.hh @@ -129,7 +129,7 @@ typedef struct View { Pos const& free_pos() const { return m_free_region.pos; } Region const& tile_region() const { return m_tile_region; } Region const& active_region() const { return m_active_region; } - Region const& previous_region() const { return m_previous_region; } + Region const& prev_region() const { return m_prev_region; } void set_free_region(Region const&); void set_free_pos(Pos const&); void set_tile_region(Region const&); @@ -204,7 +204,7 @@ private: Region m_free_region; Region m_tile_region; Region m_active_region; - Region m_previous_region; + Region m_prev_region; Region m_inner_region; bool m_activated; diff --git a/src/kranewl/input/cursor.cc b/src/kranewl/input/cursor.cc @@ -248,7 +248,7 @@ process_cursor_resize(Cursor_ptr cursor, uint32_t time) region.pos.x = grab_region.pos.x + (grab_region.dim.w - region.dim.w); - if (region == view->previous_region()) + if (region == view->prev_region()) return; view->set_free_region(region); @@ -268,9 +268,9 @@ cursor_motion_to_client( uint32_t time ) { - static View_ptr previous_view = nullptr; + static View_ptr prev_view = nullptr; - if (true /* TODO: focus_follows_cursor */ && time && view && view != previous_view && view->managed()) + if (true /* TODO: focus_follows_cursor */ && time && view && view != prev_view && view->managed()) cursor->mp_seat->mp_model->focus_view(view); if (!surface) { @@ -287,7 +287,7 @@ cursor_motion_to_client( wlr_seat_pointer_notify_enter(cursor->mp_seat->mp_wlr_seat, surface, sx, sy); wlr_seat_pointer_notify_motion(cursor->mp_seat->mp_wlr_seat, time, sx, sy); - previous_view = view; + prev_view = view; } static inline void diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -126,6 +126,33 @@ Model::focused_view() const return mp_focus; } +Workspace_ptr +Model::workspace(Index index) const +{ + if (index < m_workspaces.size()) + return m_workspaces[index]; + + return nullptr; +} + +Context_ptr +Model::context(Index index) const +{ + if (index < m_contexts.size()) + return m_contexts[index]; + + return nullptr; +} + +Output_ptr +Model::output(Index index) const +{ + if (index < m_outputs.size()) + return m_outputs[index]; + + return nullptr; +} + KeyBindings const& Model::key_bindings() const { @@ -596,14 +623,100 @@ Model::move_view_to_focused_output(View_ptr view) } void -Model::activate_workspace(Index) +Model::toggle_workspace() +{ + TRACE(); + + if (mp_prev_workspace) + activate_workspace(mp_prev_workspace); +} + +void +Model::toggle_workspace_current_context() +{ + TRACE(); + + Workspace_ptr prev_workspace = mp_context->prev_workspace(); + + if (prev_workspace) + activate_workspace(prev_workspace); +} + +void +Model::activate_next_workspace(Direction direction) +{ + TRACE(); + activate_workspace(m_workspaces.next_index(direction)); +} + +void +Model::activate_next_workspace_current_context(Direction direction) +{ + TRACE(); + activate_workspace(*mp_context->workspaces().next_element(direction)); +} + +void +Model::activate_workspace(Index index) +{ + TRACE(); + + if (index < m_workspaces.size()) + activate_workspace(workspace(index)); +} + +void +Model::activate_workspace_current_context(Index index) { TRACE(); + if (index < mp_context->size()) + activate_workspace((*mp_context)[index]); } void -Model::activate_workspace(Workspace_ptr) +Model::activate_workspace(Workspace_ptr next_workspace) +{ + TRACE(); + + if (next_workspace == mp_workspace) + return; + + abort_cursor_interactive(); + + Workspace_ptr prev_workspace = mp_workspace; + mp_prev_workspace = prev_workspace; + + Context_ptr next_context = next_workspace->context(); + Context_ptr prev_context = prev_workspace->context(); + + if (next_context == prev_context) { + for (View_ptr view : *mp_workspace) + if (!view->sticky()) + view->unmap(); + + for (View_ptr view : m_sticky_views) + view->mp_workspace = next_workspace; + } + + next_context->activate_workspace(next_workspace); + m_workspaces.activate_element(next_workspace); + mp_workspace = next_workspace; + + apply_layout(next_workspace); + mp_output->focus_at_cursor(); + sync_focus(); +} + +void +Model::toggle_context() +{ + TRACE(); + +} + +void +Model::activate_next_context(Direction) { TRACE(); @@ -624,6 +737,13 @@ Model::activate_context(Context_ptr) } void +Model::toggle_output() +{ + TRACE(); + +} + +void Model::activate_output(Index) { TRACE(); diff --git a/src/kranewl/tree/view.cc b/src/kranewl/tree/view.cc @@ -54,7 +54,7 @@ View::View( m_free_region({}), m_tile_region({}), m_active_region({}), - m_previous_region({}), + m_prev_region({}), m_inner_region({}), m_activated(false), m_focused(false), @@ -107,7 +107,7 @@ View::View( m_free_region({}), m_tile_region({}), m_active_region({}), - m_previous_region({}), + m_prev_region({}), m_inner_region({}), m_focused(false), m_mapped(false), @@ -513,7 +513,7 @@ View::outside_state() const void View::set_active_region(Region const& region) { - m_previous_region = m_active_region; + m_prev_region = m_active_region; set_inner_region(region); m_active_region = region; } @@ -521,7 +521,7 @@ View::set_active_region(Region const& region) void View::set_active_pos(Pos const& pos) { - m_previous_region = m_active_region; + m_prev_region = m_active_region; m_active_region.pos = pos; }