kranewm

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in C++
git clone git clone git://git.deurzen.net/kranewm.git
Log | Files | Refs | LICENSE

commit fafe89e19305a85447c54b21b4b43a70de719d59
parent 65884acf6a9b2b290cfaa1725a426adec260c8d6
Author: deurzen <m.deurzen@tum.de>
Date:   Wed, 29 Sep 2021 01:17:13 +0200

adds initial partition awareness

Diffstat:
Msrc/core/context.hh | 35+++++++++++++++++++++++++++++++++++
Msrc/core/model.cc | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/core/model.hh | 3+++
Msrc/core/partition.hh | 2+-
Msrc/core/workspace.hh | 12++++++++++++
5 files changed, 114 insertions(+), 25 deletions(-)

diff --git a/src/core/context.hh b/src/core/context.hh @@ -19,6 +19,7 @@ public: m_name(name), mp_partition(nullptr), mp_active(nullptr), + mp_prev_active(nullptr), m_workspaces({}, true) {} @@ -46,6 +47,18 @@ public: return mp_active; } + Workspace_ptr + prev_workspace() const + { + return mp_prev_active; + } + + Partition_ptr + partition() const + { + return mp_partition; + } + bool is_partitioned() const { @@ -67,15 +80,23 @@ public: void activate_workspace(Index index) { + Workspace_ptr prev_active = mp_active; m_workspaces.activate_at_index(index); mp_active = *m_workspaces.active_element(); + + if (prev_active != mp_active) + mp_prev_active = prev_active; } void activate_workspace(Workspace_ptr workspace) { + Workspace_ptr prev_active = mp_active; m_workspaces.activate_element(workspace); mp_active = workspace; + + if (prev_active != mp_active) + mp_prev_active = prev_active; } Cycle<Workspace_ptr> const& @@ -138,6 +159,18 @@ public: return m_workspaces.cend(); } + Workspace_ptr + operator[](std::size_t i) + { + return m_workspaces[i]; + } + + Workspace_ptr + operator[](std::size_t i) const + { + return m_workspaces[i]; + } + private: Index m_index; std::string m_name; @@ -145,6 +178,8 @@ private: Partition_ptr mp_partition; Workspace_ptr mp_active; + Workspace_ptr mp_prev_active; + Cycle<Workspace_ptr> m_workspaces; std::unordered_set<Client_ptr> m_sticky_clients; diff --git a/src/core/model.cc b/src/core/model.cc @@ -419,43 +419,43 @@ Model::Model(Connection& conn) // workspace activators { { Key::Escape, { Main } }, - CALL(toggle_workspace()) + CALL(toggle_workspace_current_context()) }, { { Key::RightBracket, { Main } }, - CALL(activate_next_workspace(Direction::Forward)) + CALL(activate_next_workspace_current_context(Direction::Forward)) }, { { Key::LeftBracket, { Main } }, - CALL(activate_next_workspace(Direction::Backward)) + CALL(activate_next_workspace_current_context(Direction::Backward)) }, { { Key::One, { Main } }, - CALL(activate_workspace(Util::Change<Index>{ 0 })) + CALL(activate_workspace_current_context(Util::Change<Index>{ 0 })) }, { { Key::Two, { Main } }, - CALL(activate_workspace(1)) + CALL(activate_workspace_current_context(1)) }, { { Key::Three, { Main } }, - CALL(activate_workspace(2)) + CALL(activate_workspace_current_context(2)) }, { { Key::Four, { Main } }, - CALL(activate_workspace(3)) + CALL(activate_workspace_current_context(3)) }, { { Key::Five, { Main } }, - CALL(activate_workspace(4)) + CALL(activate_workspace_current_context(4)) }, { { Key::Six, { Main } }, - CALL(activate_workspace(5)) + CALL(activate_workspace_current_context(5)) }, { { Key::Seven, { Main } }, - CALL(activate_workspace(6)) + CALL(activate_workspace_current_context(6)) }, { { Key::Eight, { Main } }, - CALL(activate_workspace(7)) + CALL(activate_workspace_current_context(7)) }, { { Key::Nine, { Main } }, - CALL(activate_workspace(8)) + CALL(activate_workspace_current_context(8)) }, { { Key::Zero, { Main } }, - CALL(activate_workspace(9)) + CALL(activate_workspace_current_context(9)) }, // workspace client movers @@ -1304,7 +1304,7 @@ Model::toggle_partition() void Model::activate_next_partition(winsys::Direction direction) { - activate_partition(m_partitions.next_index(direction));; + activate_partition(m_partitions.next_index(direction)); } void @@ -1328,6 +1328,8 @@ Model::activate_partition(Partition_ptr next_partition) m_partitions.activate_element(next_partition); mp_partition = next_partition; + + activate_context(next_partition->context()); } @@ -1341,7 +1343,7 @@ Model::toggle_context() void Model::activate_next_context(winsys::Direction direction) { - activate_context(m_contexts.next_index(direction));; + activate_context(m_contexts.next_index(direction)); } void @@ -1362,8 +1364,16 @@ Model::activate_context(Context_ptr next_context) stop_moving(); stop_resizing(); + Context_ptr prev_context = mp_context; + mp_prev_context = prev_context; + + Partition_ptr next_partition = next_context->partition(); + Partition_ptr prev_partition = prev_context->partition(); + m_contexts.activate_element(next_context); mp_context = next_context; + + activate_workspace(next_context->workspace()); } @@ -1375,12 +1385,27 @@ Model::toggle_workspace() } void +Model::toggle_workspace_current_context() +{ + Workspace_ptr prev_workspace = mp_context->prev_workspace(); + + if (prev_workspace) + activate_workspace(prev_workspace); +} + +void Model::activate_next_workspace(Direction direction) { activate_workspace(m_workspaces.next_index(direction)); } void +Model::activate_next_workspace_current_context(Direction direction) +{ + activate_workspace(mp_context->workspaces().next_index(direction)); +} + +void Model::activate_workspace(Util::Change<Index> index) { if (index >= m_workspaces.size()) @@ -1390,6 +1415,15 @@ Model::activate_workspace(Util::Change<Index> index) } void +Model::activate_workspace_current_context(Util::Change<Index> index) +{ + if (index >= mp_context->size()) + return; + + activate_workspace((*mp_context)[index]); +} + +void Model::activate_workspace(Workspace_ptr next_workspace) { if (next_workspace == mp_workspace) @@ -1398,22 +1432,27 @@ Model::activate_workspace(Workspace_ptr next_workspace) stop_moving(); stop_resizing(); - m_conn.set_current_desktop(next_workspace->index()); - 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(); + + m_conn.set_current_desktop(next_workspace->index()); + for (Client_ptr client : *next_workspace) - if (!client->mapped) - map_client(client); + map_client(client); - for (Client_ptr client : *mp_workspace) - if (client->mapped && !client->sticky) - unmap_client(client); + if (next_context == prev_context) { + for (Client_ptr client : *mp_workspace) + if (!client->sticky) + unmap_client(client); - for (Client_ptr client : m_sticky_clients) - client->workspace = next_workspace; + for (Client_ptr client : m_sticky_clients) + client->workspace = next_workspace; + } + next_context->activate_workspace(next_workspace); m_workspaces.activate_element(next_workspace); mp_workspace = next_workspace; diff --git a/src/core/model.hh b/src/core/model.hh @@ -107,8 +107,11 @@ private: void activate_context(Context_ptr); void toggle_workspace(); + void toggle_workspace_current_context(); void activate_next_workspace(winsys::Direction); + void activate_next_workspace_current_context(winsys::Direction); void activate_workspace(Util::Change<Index>); + void activate_workspace_current_context(Util::Change<Index>); void activate_workspace(Workspace_ptr); void render_decoration(Client_ptr); diff --git a/src/core/partition.hh b/src/core/partition.hh @@ -46,7 +46,7 @@ public: } Context_ptr - context() + context() const { return mp_context; } diff --git a/src/core/workspace.hh b/src/core/workspace.hh @@ -242,6 +242,18 @@ public: return m_clients.cend(); } + Client_ptr + operator[](std::size_t i) + { + return m_clients[i]; + } + + Client_ptr + operator[](std::size_t i) const + { + return m_clients[i]; + } + private: std::size_t m_index; std::string m_name;