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 017848200eb04fea7950000b33e8735b635e7195
parent ab792c6be17ac48d7bf89615c79c848b11409bb2
Author: deurzen <max@deurzen.net>
Date:   Wed,  1 Jun 2022 03:13:25 +0200

enables focus-follows-mouse context toggle

Diffstat:
Minclude/kranewl/context.hh | 17++++++++++++++++-
Minclude/kranewl/input/key-bindings.hh | 3+++
Minclude/kranewl/model.hh | 2+-
Msrc/kranewl/model.cc | 33+++++++++++++++++++++++++--------
4 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/include/kranewl/context.hh b/include/kranewl/context.hh @@ -17,7 +17,8 @@ public: mp_output(nullptr), mp_active(nullptr), mp_prev_active(nullptr), - m_workspaces({}, true) + m_workspaces({}, true), + m_focus_follows_cursor(false) {} Index @@ -120,6 +121,18 @@ public: return m_sticky_clients; } + bool + focus_follows_cursor() const + { + return m_focus_follows_cursor; + } + + void + set_focus_follows_cursor(bool focus_follows_cursor) + { + m_focus_follows_cursor = focus_follows_cursor; + } + std::deque<Workspace_ptr>::iterator begin() { @@ -180,4 +193,6 @@ private: Cycle<Workspace_ptr> m_workspaces; std::unordered_set<Client_ptr> m_sticky_clients; + bool m_focus_follows_cursor; + }* Context_ptr; diff --git a/include/kranewl/input/key-bindings.hh b/include/kranewl/input/key-bindings.hh @@ -161,6 +161,9 @@ static const KeyBindings key_bindings = { { { XKB_KEY_M, MODKEY | WLR_MODIFIER_SHIFT }, CALL(set_focus_follows_cursor(Toggle::Reverse, model.mp_workspace)) }, +{ { XKB_KEY_M, MODKEY | WLR_MODIFIER_CTRL | WLR_MODIFIER_SHIFT }, + CALL(set_focus_follows_cursor(Toggle::Reverse, model.mp_context)) +}, // workspace layout modifiers { { XKB_KEY_F, MODKEY | WLR_MODIFIER_SHIFT }, diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -185,8 +185,8 @@ public: void pop_deiconify(); void deiconify_all(); - void set_focus_follows_cursor(Toggle, Index); void set_focus_follows_cursor(Toggle, Workspace_ptr); + void set_focus_follows_cursor(Toggle, Context_ptr); bool is_free(View_ptr) const; diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -1830,25 +1830,42 @@ Model::deiconify_all() } void -Model::set_focus_follows_cursor(Toggle toggle, Index index) +Model::set_focus_follows_cursor(Toggle toggle, Workspace_ptr workspace) { - if (index < m_workspaces.size()) - set_focus_follows_cursor(toggle, m_workspaces[index]); + bool focus_follows_cursor; + + switch (toggle) { + case Toggle::On: focus_follows_cursor = true; break; + case Toggle::Off: focus_follows_cursor = false; break; + case Toggle::Reverse: focus_follows_cursor = !workspace->focus_follows_cursor(); break; + default: return; + } + + workspace->set_focus_follows_cursor(focus_follows_cursor); } void -Model::set_focus_follows_cursor(Toggle toggle, Workspace_ptr workspace) +Model::set_focus_follows_cursor(Toggle toggle, Context_ptr context) { bool focus_follows_cursor; switch (toggle) { - case Toggle::On: focus_follows_cursor = true; break; - case Toggle::Off: focus_follows_cursor = false; break; - case Toggle::Reverse: focus_follows_cursor = !workspace->focus_follows_cursor(); break; + case Toggle::On: focus_follows_cursor = true; break; + case Toggle::Off: focus_follows_cursor = false; break; + case Toggle::Reverse: focus_follows_cursor = !context->focus_follows_cursor(); break; default: return; } - workspace->set_focus_follows_cursor(focus_follows_cursor); + for (Workspace_ptr workspace : *context) + set_focus_follows_cursor( + focus_follows_cursor + ? Toggle::On + : Toggle::Off, + workspace + ); + + context->set_focus_follows_cursor(focus_follows_cursor); +} } XDGView_ptr