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 11630440d7ad3cd72f857b671e533caa285c5466
parent 8e12cd943949ab8378b3e3421ccad55bcf03a316
Author: deurzen <m.deurzen@tum.de>
Date:   Mon, 27 Sep 2021 03:19:00 +0200

improves desktop (context + workspace) generation

Diffstat:
Msrc/core/context.hh | 6++++++
Msrc/core/model.cc | 47+++++++++++++++++++++++++++++++++++++----------
Msrc/core/workspace.cc | 25++++++++++++++++++++++++-
Msrc/core/workspace.hh | 8+++++++-
Msrc/winsys/util.hh | 1+
5 files changed, 75 insertions(+), 12 deletions(-)

diff --git a/src/core/context.hh b/src/core/context.hh @@ -34,6 +34,12 @@ public: return m_name; } + std::size_t + size() const + { + return m_workspaces.size(); + } + bool is_partitioned() const { diff --git a/src/core/model.cc b/src/core/model.cc @@ -715,20 +715,44 @@ Model::Model(Connection& conn) }; static const std::vector<std::string> workspace_names{ - "1:main", "2:web", "3:term", "4", "5", "6", "7", "8", "9", "10" + "main", "web", "term", {}, {}, {}, {}, {}, {}, {} }; - for (std::size_t i = 0; i < context_names.size(); ++i) - m_contexts.insert_at_back(new Context(i, context_names[i])); + for (std::size_t i = 0; i < context_names.size(); ++i) { + Context_ptr context = new Context(i, context_names[i]); + m_contexts.insert_at_back(context); - for (std::size_t i = 0; i < workspace_names.size(); ++i) - m_workspaces.insert_at_back(new Workspace(i, workspace_names[i])); + for (std::size_t j = 0; j < workspace_names.size(); ++j) { + Workspace_ptr workspace = new Workspace( + workspace_names.size() * i + j, + workspace_names[j], + context + ); + + m_workspaces.insert_at_back(workspace); + context->register_workspace(workspace); + } + + context->activate_workspace(Index{0}); + } if constexpr (Config::ipc_enabled) m_conn.init_wm_ipc(); acquire_partitions(); - m_conn.init_for_wm(workspace_names); + + std::vector<std::string> desktop_names; + desktop_names.reserve(m_workspaces.size()); + std::transform( + m_workspaces.begin(), + m_workspaces.end(), + std::back_inserter(desktop_names), + [](Workspace_ptr workspace) -> std::string { + return workspace->identifier(); + } + ); + + m_conn.init_for_wm(desktop_names); m_contexts.activate_at_index(0); m_workspaces.activate_at_index(0); @@ -738,20 +762,23 @@ Model::Model(Connection& conn) m_conn.set_current_desktop(0); - std::vector<KeyInput> key_inputs(m_key_bindings.size()); - std::vector<MouseInput> mouse_inputs(m_mouse_bindings.size()); + std::vector<KeyInput> key_inputs; + std::vector<MouseInput> mouse_inputs; + + key_inputs.reserve(m_key_bindings.size()); + mouse_inputs.reserve(m_mouse_bindings.size()); std::transform( m_key_bindings.begin(), m_key_bindings.end(), - key_inputs.begin(), + std::back_inserter(key_inputs), [](auto kv) -> KeyInput { return kv.first; } ); std::transform( m_mouse_bindings.begin(), m_mouse_bindings.end(), - mouse_inputs.begin(), + std::back_inserter(mouse_inputs), [](auto kv) -> MouseInput { return kv.first; } ); diff --git a/src/core/workspace.cc b/src/core/workspace.cc @@ -1,6 +1,7 @@ #include "../winsys/util.hh" -#include "workspace.hh" +#include "context.hh" #include "cycle.t.hh" +#include "workspace.hh" #include <algorithm> #include <optional> @@ -131,6 +132,13 @@ Workspace::length() const } +Context_ptr +Workspace::context() const +{ + return mp_context; +} + + Index Workspace::index() const { @@ -143,6 +151,21 @@ Workspace::name() const return m_name; } +std::string +Workspace::identifier() const +{ + if (!m_name.empty()) + return mp_context->name() + + ":" + + std::to_string(m_index) + + ":" + + m_name; + + return mp_context->name() + + ":" + + std::to_string(m_index); +} + Client_ptr Workspace::active() const { diff --git a/src/core/workspace.hh b/src/core/workspace.hh @@ -126,10 +126,11 @@ public: }; - Workspace(std::size_t index, std::string name) + Workspace(std::size_t index, std::string name, Context_ptr context) : m_index(index), m_name(name), m_layout_handler({}), + mp_context(context), mp_active(nullptr), m_clients({}, true), m_icons({}, true), @@ -149,8 +150,11 @@ public: std::size_t size() const; std::size_t length() const; + Context_ptr context() const; + Index index() const; std::string const& name() const; + std::string identifier() const; Client_ptr active() const; std::deque<Client_ptr> const& clients() const; @@ -244,6 +248,8 @@ private: LayoutHandler m_layout_handler; + Context_ptr mp_context; + Client_ptr mp_active; Cycle<Client_ptr> m_clients; Cycle<Client_ptr> m_icons; diff --git a/src/winsys/util.hh b/src/winsys/util.hh @@ -7,6 +7,7 @@ #include <string> #include <type_traits> #include <unordered_map> +#include <vector> namespace Util {