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 5ee13d18263275c597f44b4e23e7ffc209be9243
parent cf8ac9d10ca9745668f752825c5618555d209b84
Author: deurzen <max@deurzen.net>
Date:   Sun, 29 May 2022 08:10:14 +0200

adds proper focus-follows-mouse behavior

Diffstat:
Minclude/kranewl/tree/output.hh | 4++++
Msrc/kranewl/model.cc | 69++++++++++++++++++++++-----------------------------------------------
Msrc/kranewl/tree/output.cc | 23+++++++++++++++++++++--
3 files changed, 47 insertions(+), 49 deletions(-)

diff --git a/include/kranewl/tree/output.hh b/include/kranewl/tree/output.hh @@ -38,11 +38,15 @@ public: bool contains(Pos) const; bool contains(Region) const; + void focus_at_cursor(); + private: Context_ptr mp_context; Region m_full_region; Region m_placeable_region; + bool m_cursor_focus_on_present; + public: Server_ptr mp_server; Model_ptr mp_model; diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -871,6 +871,7 @@ Model::set_floating_view(Toggle toggle, View_ptr view) } apply_layout(view->mp_workspace); + mp_output->focus_at_cursor(); } void @@ -894,15 +895,10 @@ Model::set_fullscreen_view(Toggle toggle, View_ptr view) return; view->set_fullscreen(true); - // TODO: set fullscreen state - - Workspace_ptr workspace = view->mp_workspace; - apply_layout(workspace); - m_fullscreen_map[view] = view->free_region(); - return; + break; } case Toggle::Off: { @@ -913,15 +909,10 @@ Model::set_fullscreen_view(Toggle toggle, View_ptr view) view->set_free_region(m_fullscreen_map.at(view)); view->set_fullscreen(false); - // TODO: unset fullscreen state - - Workspace_ptr workspace = view->mp_workspace; - apply_layout(workspace); - m_fullscreen_map.erase(view); - return; + break; } case Toggle::Reverse: { @@ -936,6 +927,10 @@ Model::set_fullscreen_view(Toggle toggle, View_ptr view) } default: return; } + + Workspace_ptr workspace = view->mp_workspace; + apply_layout(workspace); + mp_output->focus_at_cursor(); } void @@ -1037,20 +1032,12 @@ Model::set_contained_view(Toggle toggle, View_ptr view) case Toggle::On: { view->set_contained(true); - - Workspace_ptr workspace = view->mp_workspace; - - apply_layout(workspace); - return; + break; } case Toggle::Off: { view->set_contained(false); - - Workspace_ptr workspace = view->mp_workspace; - - apply_layout(workspace); - return; + break; } case Toggle::Reverse: { @@ -1065,6 +1052,10 @@ Model::set_contained_view(Toggle toggle, View_ptr view) } default: return; } + + Workspace_ptr workspace = view->mp_workspace; + apply_layout(workspace); + mp_output->focus_at_cursor(); } void @@ -1139,42 +1130,29 @@ Model::set_iconify_view(Toggle toggle, View_ptr view) { TRACE(); + Workspace_ptr workspace = view->mp_workspace; + switch (toggle) { case Toggle::On: { if (view->iconified() || view->sticky()) return; - Workspace_ptr workspace = view->mp_workspace; workspace->view_to_icon(view); - // TODO: set iconify state - view->unmap(); - - apply_layout(workspace); - sync_focus(); - view->set_iconified(true); - - return; + break; } case Toggle::Off: { if (!view->iconified()) return; - Workspace_ptr workspace = view->mp_workspace; workspace->icon_to_view(view); - // TODO: unset iconify state - view->set_iconified(false); - - apply_layout(workspace); - sync_focus(); - - return; + break; } case Toggle::Reverse: { @@ -1189,6 +1167,10 @@ Model::set_iconify_view(Toggle toggle, View_ptr view) } default: return; } + + apply_layout(workspace); + mp_output->focus_at_cursor(); + sync_focus(); } void @@ -1612,14 +1594,7 @@ Model::unregister_view(View_ptr view) view->m_pid ); - if (true /* TODO: focus_follows_mouse */) { - View_ptr view_under_cursor - = mp_server->m_seat.mp_mouse->view_under_cursor(); - - if (view_under_cursor) - focus_view(view_under_cursor); - } - + mp_output->focus_at_cursor(); sync_focus(); } diff --git a/src/kranewl/tree/output.cc b/src/kranewl/tree/output.cc @@ -33,9 +33,9 @@ Output::Output( mp_server(server), mp_model(model), m_dirty(true), + m_cursor_focus_on_present(false), mp_wlr_output(wlr_output), mp_wlr_scene_output(wlr_scene_output), - m_subpixel(wlr_output->subpixel), ml_frame({ .notify = Output::handle_frame }), ml_commit({ .notify = Output::handle_commit }), ml_present({ .notify = Output::handle_present }), @@ -79,10 +79,23 @@ Output::handle_commit(struct wl_listener*, void*) } void -Output::handle_present(struct wl_listener*, void*) +Output::handle_present(struct wl_listener* listener, void*) { TRACE(); + Output_ptr output = wl_container_of(listener, output, ml_present); + + if (output->m_cursor_focus_on_present && output == output->mp_model->mp_output) { + if (true /* TODO: focus_follows_mouse */) { + View_ptr view_under_cursor + = output->mp_server->m_seat.mp_cursor->view_under_cursor(); + + if (view_under_cursor) + output->mp_model->focus_view(view_under_cursor); + } + + output->m_cursor_focus_on_present = false; + } } void @@ -156,3 +169,9 @@ Output::contains(Region region) const { return m_full_region.contains(region); } + +void +Output::focus_at_cursor() +{ + m_cursor_focus_on_present = true; +}