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 ab792c6be17ac48d7bf89615c79c848b11409bb2
parent 95b3b02958e2f2c476258a2818fd5eac975e1120
Author: deurzen <max@deurzen.net>
Date:   Tue, 31 May 2022 13:45:24 +0200

enables focus-follows-mouse workspace toggle

Diffstat:
Minclude/kranewl/input/cursor.hh | 4++++
Minclude/kranewl/input/key-bindings.hh | 5+++++
Minclude/kranewl/model.hh | 3+++
Minclude/kranewl/workspace.hh | 8++++----
Msrc/kranewl/input/cursor.cc | 7+++++--
Msrc/kranewl/input/seat.cc | 1+
Msrc/kranewl/model.cc | 22++++++++++++++++++++++
Msrc/kranewl/tree/output.cc | 2+-
Msrc/kranewl/workspace.cc | 8++++----
9 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/include/kranewl/input/cursor.hh b/include/kranewl/input/cursor.hh @@ -38,6 +38,7 @@ struct CursorInput { }; typedef class Server* Server_ptr; +typedef class Model* Model_ptr; typedef class Seat* Seat_ptr; typedef struct View* View_ptr; typedef struct Node* Node_ptr; @@ -51,12 +52,14 @@ typedef struct Cursor { Cursor( Server_ptr, + Model_ptr, Seat_ptr, struct wlr_cursor*, struct wlr_pointer_constraints_v1*, struct wlr_relative_pointer_manager_v1*, struct wlr_virtual_pointer_manager_v1* ); + ~Cursor(); View_ptr view_under_cursor() const; @@ -78,6 +81,7 @@ typedef struct Cursor { static void handle_request_set_cursor(struct wl_listener*, void*); Server_ptr mp_server; + Model_ptr mp_model; Seat_ptr mp_seat; struct wlr_cursor* mp_wlr_cursor; diff --git a/include/kranewl/input/key-bindings.hh b/include/kranewl/input/key-bindings.hh @@ -157,6 +157,11 @@ static const KeyBindings key_bindings = { CALL(rotate_views(Direction::Backward)) }, + // workspace behavior modifiers +{ { XKB_KEY_M, MODKEY | WLR_MODIFIER_SHIFT }, + CALL(set_focus_follows_cursor(Toggle::Reverse, model.mp_workspace)) +}, + // workspace layout modifiers { { XKB_KEY_F, MODKEY | WLR_MODIFIER_SHIFT }, CALL(set_layout(LayoutHandler::LayoutKind::Float)) diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -185,6 +185,9 @@ public: void pop_deiconify(); void deiconify_all(); + void set_focus_follows_cursor(Toggle, Index); + void set_focus_follows_cursor(Toggle, Workspace_ptr); + bool is_free(View_ptr) const; void spawn_external(std::string&&) const; diff --git a/include/kranewl/workspace.hh b/include/kranewl/workspace.hh @@ -21,14 +21,14 @@ public: m_free_views({}, true), m_iconified_views({}, true), m_disowned_views({}, true), - m_focus_follows_mouse(false) + m_focus_follows_cursor(false) {} bool empty() const; bool contains(View_ptr) const; - bool focus_follows_mouse() const; - void set_focus_follows_mouse(bool); + bool focus_follows_cursor() const; + void set_focus_follows_cursor(bool); bool layout_is_free() const; bool layout_has_margin() const; @@ -160,6 +160,6 @@ private: Cycle<View_ptr> m_iconified_views; Cycle<View_ptr> m_disowned_views; - bool m_focus_follows_mouse; + bool m_focus_follows_cursor; }* Workspace_ptr; diff --git a/src/kranewl/input/cursor.cc b/src/kranewl/input/cursor.cc @@ -8,6 +8,7 @@ #include <kranewl/server.hh> #include <kranewl/tree/view.hh> #include <kranewl/util.hh> +#include <kranewl/workspace.hh> // https://github.com/swaywm/wlroots/issues/682 #include <pthread.h> @@ -30,6 +31,7 @@ extern "C" { Cursor::Cursor( Server_ptr server, + Model_ptr model, Seat_ptr seat, struct wlr_cursor* cursor, struct wlr_pointer_constraints_v1* pointer_constraints, @@ -37,6 +39,7 @@ Cursor::Cursor( struct wlr_virtual_pointer_manager_v1* virtual_pointer_manager ) : mp_server(server), + mp_model(model), mp_seat(seat), mp_wlr_cursor(cursor), mp_cursor_manager(wlr_xcursor_manager_create(nullptr, 24)), @@ -363,7 +366,7 @@ cursor_motion_to_client( { static View_ptr prev_view = nullptr; - if (true /* TODO: focus_follows_cursor */ && time && view && view != prev_view && view->managed()) + if (time && view && view != prev_view && view->mp_workspace->focus_follows_cursor() && view->managed()) cursor->mp_seat->mp_model->focus_view(view); if (!surface) { @@ -527,7 +530,7 @@ Cursor::handle_cursor_button(struct wl_listener* listener, void* data) if (process_cursorbinding(cursor, button, modifiers)) return; - if (false /* TODO: !focus_follows_cursor */) { + if (!cursor->mp_model->mp_workspace->focus_follows_cursor()) { View_ptr view = cursor->view_under_cursor(); if (view && !view->focused() && view->managed()) diff --git a/src/kranewl/input/seat.cc b/src/kranewl/input/seat.cc @@ -37,6 +37,7 @@ Seat::Seat( mp_keyboard_shortcuts_inhibit_manager(keyboard_shortcuts_inhibit_manager), mp_cursor(new Cursor( server, + model, this, cursor, pointer_constraints, diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -1829,6 +1829,28 @@ Model::deiconify_all() pop_deiconify(); } +void +Model::set_focus_follows_cursor(Toggle toggle, Index index) +{ + if (index < m_workspaces.size()) + set_focus_follows_cursor(toggle, m_workspaces[index]); +} + +void +Model::set_focus_follows_cursor(Toggle toggle, Workspace_ptr workspace) +{ + 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); +} + XDGView_ptr Model::create_xdg_shell_view( struct wlr_xdg_surface* wlr_xdg_surface, diff --git a/src/kranewl/tree/output.cc b/src/kranewl/tree/output.cc @@ -98,7 +98,7 @@ Output::handle_present(struct wl_listener* listener, void*) 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 */) { + if (output->context()->workspace()->focus_follows_cursor()) { View_ptr view_under_cursor = output->mp_seat->mp_cursor->view_under_cursor(); diff --git a/src/kranewl/workspace.cc b/src/kranewl/workspace.cc @@ -23,15 +23,15 @@ Workspace::contains(View_ptr view) const } bool -Workspace::focus_follows_mouse() const +Workspace::focus_follows_cursor() const { - return m_focus_follows_mouse; + return m_focus_follows_cursor; } void -Workspace::set_focus_follows_mouse(bool focus_follows_mouse) +Workspace::set_focus_follows_cursor(bool focus_follows_cursor) { - m_focus_follows_mouse = focus_follows_mouse; + m_focus_follows_cursor = focus_follows_cursor; } bool