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 92616a9846e246332b776788fe8f94d277777a90
parent 1f19950f4da437cf9746e9e109e5c37f7f82bc6c
Author: deurzen <max@deurzen.net>
Date:   Wed,  1 Jun 2022 10:23:16 +0200

builds in idle inhibit protocol support

Diffstat:
Minclude/kranewl/input/seat.hh | 14++++++++------
Msrc/kranewl/input/cursor.cc | 26+++++++++++++++++++-------
Msrc/kranewl/input/seat.cc | 40+++++++++++++++++++++++++++++++---------
Msrc/kranewl/tree/xdg-view.cc | 7+++++++
4 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/include/kranewl/input/seat.hh b/include/kranewl/input/seat.hh @@ -40,9 +40,10 @@ public: static void handle_destroy(struct wl_listener*, void*); static void handle_request_set_selection(struct wl_listener*, void*); static void handle_request_set_primary_selection(struct wl_listener*, void*); - static void handle_inhibit_manager_new_inhibitor(struct wl_listener*, void*); - static void handle_inhibit_manager_inhibit_activate(struct wl_listener*, void*); - static void handle_inhibit_manager_inhibit_deactivate(struct wl_listener*, void*); + static void handle_idle_new_inhibitor(struct wl_listener*, void*); + static void handle_idle_destroy_inhibitor(struct wl_listener*, void*); + static void handle_input_inhibit_activate(struct wl_listener*, void*); + static void handle_input_inhibit_deactivate(struct wl_listener*, void*); public: Server_ptr mp_server; @@ -61,8 +62,9 @@ public: struct wl_listener ml_destroy; struct wl_listener ml_request_set_selection; struct wl_listener ml_request_set_primary_selection; - struct wl_listener ml_inhibit_manager_new_inhibitor; - struct wl_listener ml_inhibit_manager_inhibit_activate; - struct wl_listener ml_inhibit_manager_inhibit_deactivate; + struct wl_listener ml_idle_new_inhibitor; + struct wl_listener ml_idle_destroy_inhibitor; + struct wl_listener ml_input_inhibit_activate; + struct wl_listener ml_input_inhibit_deactivate; }* Seat_ptr; diff --git a/src/kranewl/input/cursor.cc b/src/kranewl/input/cursor.cc @@ -367,8 +367,19 @@ cursor_motion_to_client( { static View_ptr prev_view = nullptr; - if (time && view && view != prev_view && view->mp_workspace->focus_follows_cursor() && view->managed()) - cursor->mp_seat->mp_model->focus_view(view); + if (time) { + wlr_idle_notify_activity( + cursor->mp_seat->mp_idle, + cursor->mp_seat->mp_wlr_seat + ); + + if (view && view != prev_view + && view->mp_workspace->focus_follows_cursor() && view->managed()) + { + cursor->mp_seat->mp_model->focus_view(view); + prev_view = view; + } + } if (!surface) { wlr_seat_pointer_notify_clear_focus(cursor->mp_seat->mp_wlr_seat); @@ -383,8 +394,6 @@ cursor_motion_to_client( wlr_seat_pointer_notify_enter(cursor->mp_seat->mp_wlr_seat, surface, sx, sy); wlr_seat_pointer_notify_motion(cursor->mp_seat->mp_wlr_seat, time, sx, sy); - - prev_view = view; } void @@ -571,11 +580,12 @@ Cursor::handle_cursor_axis(struct wl_listener* listener, void* data) TRACE(); Cursor_ptr cursor = wl_container_of(listener, cursor, ml_cursor_axis); + Seat_ptr seat = cursor->mp_seat; struct wlr_event_pointer_axis* event = reinterpret_cast<struct wlr_event_pointer_axis*>(data); struct wlr_keyboard* keyboard - = wlr_seat_get_keyboard(cursor->mp_seat->mp_wlr_seat); + = wlr_seat_get_keyboard(seat->mp_wlr_seat); uint32_t button = 0; uint32_t modifiers = keyboard @@ -599,15 +609,17 @@ Cursor::handle_cursor_axis(struct wl_listener* listener, void* data) default: break; } - if (!process_cursorbinding(cursor, button, modifiers)) + if (!process_cursorbinding(cursor, button, modifiers)) { + wlr_idle_notify_activity(seat->mp_idle, seat->mp_wlr_seat); wlr_seat_pointer_notify_axis( - cursor->mp_seat->mp_wlr_seat, + seat->mp_wlr_seat, event->time_msec, event->orientation, event->delta, event->delta_discrete, event->source ); + } } void diff --git a/src/kranewl/input/seat.cc b/src/kranewl/input/seat.cc @@ -8,6 +8,7 @@ extern "C" { #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle_inhibit_v1.h> #include <wlr/types/wlr_input_inhibitor.h> #include <wlr/types/wlr_primary_selection.h> @@ -51,18 +52,19 @@ Seat::Seat( ml_destroy({ .notify = Seat::handle_destroy }), ml_request_set_selection({ .notify = Seat::handle_request_set_selection }), ml_request_set_primary_selection({ .notify = Seat::handle_request_set_primary_selection }), - ml_inhibit_manager_new_inhibitor({ .notify = Seat::handle_inhibit_manager_new_inhibitor }), - ml_inhibit_manager_inhibit_activate({ .notify = Seat::handle_inhibit_manager_inhibit_activate }), - ml_inhibit_manager_inhibit_deactivate({ .notify = Seat::handle_inhibit_manager_inhibit_deactivate }) + ml_idle_new_inhibitor({ .notify = Seat::handle_idle_new_inhibitor }), + ml_idle_destroy_inhibitor({ .notify = Seat::handle_idle_destroy_inhibitor }), + ml_input_inhibit_activate({ .notify = Seat::handle_input_inhibit_activate }), + ml_input_inhibit_deactivate({ .notify = Seat::handle_input_inhibit_deactivate }) { TRACE(); wl_signal_add(&seat->events.destroy, &ml_destroy); wl_signal_add(&seat->events.request_set_selection, &ml_request_set_selection); wl_signal_add(&seat->events.request_set_primary_selection, &ml_request_set_primary_selection); - wl_signal_add(&mp_idle_inhibit_manager->events.new_inhibitor, &ml_inhibit_manager_new_inhibitor); - wl_signal_add(&mp_input_inhibit_manager->events.activate, &ml_inhibit_manager_inhibit_activate); - wl_signal_add(&mp_input_inhibit_manager->events.deactivate, &ml_inhibit_manager_inhibit_deactivate); + wl_signal_add(&mp_idle_inhibit_manager->events.new_inhibitor, &ml_idle_new_inhibitor); + wl_signal_add(&mp_input_inhibit_manager->events.activate, &ml_input_inhibit_activate); + wl_signal_add(&mp_input_inhibit_manager->events.deactivate, &ml_input_inhibit_deactivate); } Seat::~Seat() @@ -136,21 +138,41 @@ Seat::handle_request_set_primary_selection(struct wl_listener* listener, void* d } void -Seat::handle_inhibit_manager_new_inhibitor(struct wl_listener*, void*) +Seat::handle_idle_new_inhibitor(struct wl_listener* listener, void* data) { TRACE(); + Seat_ptr seat = wl_container_of(listener, seat, ml_idle_new_inhibitor); + struct wlr_idle_inhibitor_v1* idle_inhibitor + = reinterpret_cast<struct wlr_idle_inhibitor_v1*>(data); + + wl_signal_add(&idle_inhibitor->events.destroy, &seat->ml_idle_destroy_inhibitor); + wlr_idle_set_enabled(seat->mp_idle, seat->mp_wlr_seat, false); +} + +void +Seat::handle_idle_destroy_inhibitor(struct wl_listener* listener, void*) +{ + TRACE(); + + Seat_ptr seat = wl_container_of(listener, seat, ml_idle_destroy_inhibitor); + + wlr_idle_set_enabled( + seat->mp_idle, + seat->mp_wlr_seat, + wl_list_length(&seat->mp_idle_inhibit_manager->inhibitors) <= 1 + ); } void -Seat::handle_inhibit_manager_inhibit_activate(struct wl_listener*, void*) +Seat::handle_input_inhibit_activate(struct wl_listener*, void*) { TRACE(); } void -Seat::handle_inhibit_manager_inhibit_deactivate(struct wl_listener*, void*) +Seat::handle_input_inhibit_deactivate(struct wl_listener*, void*) { TRACE(); diff --git a/src/kranewl/tree/xdg-view.cc b/src/kranewl/tree/xdg-view.cc @@ -105,6 +105,13 @@ XDGView::focus(Toggle toggle) activate(toggle); render_decoration(); raise(); + + wlr_idle_set_enabled( + mp_server->m_seat.mp_idle, + mp_server->m_seat.mp_wlr_seat, + wl_list_empty(&mp_server->m_seat.mp_idle_inhibit_manager->inhibitors) + ); + break; } case Toggle::Off: