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 378bbc4e4b832ef15a20d0da5a057eb503c71745
parent e73b155aca6afe3d710bf3841a4804ece9ce5b10
Author: deurzen <max@deurzen.net>
Date:   Sat, 28 May 2022 19:45:03 +0200

resolves view {,un}map focus-follows-mouse issue

Diffstat:
Minclude/kranewl/input/mouse.hh | 2++
Msrc/kranewl/input/mouse.cc | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/kranewl/model.cc | 14+++++++++++++-
3 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/include/kranewl/input/mouse.hh b/include/kranewl/input/mouse.hh @@ -42,6 +42,8 @@ typedef struct Mouse { ); ~Mouse(); + View_ptr view_under_cursor() const; + static void handle_cursor_motion(struct wl_listener*, void*); static void handle_cursor_motion_absolute(struct wl_listener*, void*); static void handle_cursor_button(struct wl_listener*, void*); diff --git a/src/kranewl/input/mouse.cc b/src/kranewl/input/mouse.cc @@ -67,20 +67,6 @@ Mouse::~Mouse() } -static inline void -process_cursor_move(Mouse_ptr mouse, uint32_t time) -{ - TRACE(); - -} - -static inline void -process_cursor_resize(Mouse_ptr mouse, uint32_t time) -{ - TRACE(); - -} - static inline View_ptr view_at( Server_ptr server, @@ -117,8 +103,39 @@ view_at( return nullptr; } +View_ptr +Mouse::view_under_cursor() const +{ + double sx, sy; + struct wlr_surface* surface = nullptr; + + View_ptr view = view_at( + mp_server, + mp_cursor->x, + mp_cursor->y, + &surface, + &sx, &sy + ); + + return view; +} + static inline void -cursor_set_focus( +process_cursor_move(Mouse_ptr mouse, uint32_t time) +{ + TRACE(); + +} + +static inline void +process_cursor_resize(Mouse_ptr mouse, uint32_t time) +{ + TRACE(); + +} + +static inline void +cursor_motion_to_client( Mouse_ptr mouse, View_ptr view, struct wlr_surface* surface, @@ -166,6 +183,7 @@ process_cursor_motion(Mouse_ptr mouse, uint32_t time) double sx, sy; struct wlr_surface* surface = nullptr; + View_ptr view = view_at( mouse->mp_server, mouse->mp_cursor->x, @@ -182,7 +200,7 @@ process_cursor_motion(Mouse_ptr mouse, uint32_t time) ); } - cursor_set_focus(mouse, view, surface, sx, sy, time); + cursor_motion_to_client(mouse, view, surface, sx, sy, time); } void @@ -216,6 +234,32 @@ Mouse::handle_cursor_button(struct wl_listener* listener, void* data) { TRACE(); + Mouse_ptr mouse = wl_container_of(listener, mouse, ml_cursor_button); + struct wlr_event_pointer_button* event + = reinterpret_cast<struct wlr_event_pointer_button*>(data); + + wlr_seat_pointer_notify_button( + mouse->mp_seat->mp_wlr_seat, + event->time_msec, + event->button, + event->state + ); + + double sx, sy; + struct wlr_surface* surface = nullptr; + + View_ptr view = view_at( + mouse->mp_server, + mouse->mp_cursor->x, + mouse->mp_cursor->y, + &surface, + &sx, &sy + ); + + if (event->state == WLR_BUTTON_RELEASED) + mouse->m_cursor_mode = CursorMode::Passthrough; + else if (false /* TODO: !focus_follows_mouse */) + mouse->mp_seat->mp_model->focus_view(view); } void diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -1589,6 +1589,8 @@ Model::register_view(View_ptr view, Workspace_ptr workspace) ); move_view_to_workspace(view, workspace); + + sync_focus(); } void @@ -1596,8 +1598,10 @@ Model::unregister_view(View_ptr view) { TRACE(); - if (view->mp_workspace) + if (view->mp_workspace) { view->mp_workspace->remove_view(view); + apply_layout(view->mp_workspace); + } std::stringstream uid_ss; uid_ss << std::hex << view->m_uid; @@ -1608,6 +1612,14 @@ 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); + } + sync_focus(); }