diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-12-11 11:00:39 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-12 10:37:30 -0500 |
commit | 2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6 (patch) | |
tree | 69d3367cf7dbd7f756d45d89cd37e6016503a88d /sway/input | |
parent | f645f8efd688104cdeac01cd940b32a8ff978571 (diff) |
Add seat <seat> idle_{inhibit,wake} <sources...>
This adds seat configuration options which can be used to configure what
events affect the idle behavior of sway.
An example use-case is mobile devices: you would remove touch from the
list of idle_wake events. This allows the phone to stay on while you're
actively using it, but doesn't wake from idle on touch events while it's
sleeping in your pocket.
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 16 | ||||
-rw-r--r-- | sway/input/keyboard.c | 2 | ||||
-rw-r--r-- | sway/input/seat.c | 31 | ||||
-rw-r--r-- | sway/input/switch.c | 4 |
4 files changed, 42 insertions, 11 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 83b5212d..680fe39e 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -206,7 +206,7 @@ void cursor_handle_activity(struct sway_cursor *cursor) { wl_event_source_timer_update( cursor->hide_source, cursor_get_timeout(cursor)); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_POINTER); if (cursor->hidden) { cursor_unhide(cursor); } @@ -341,7 +341,7 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) { static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH); struct wlr_event_touch_down *event = data; struct sway_seat *seat = cursor->seat; @@ -372,7 +372,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH); struct wlr_event_touch_up *event = data; struct wlr_seat *seat = cursor->seat->wlr_seat; // TODO: fall back to cursor simulation if client has not bound to touch @@ -382,7 +382,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { static void handle_touch_motion(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_motion); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH); struct wlr_event_touch_motion *event = data; struct sway_seat *seat = cursor->seat; @@ -492,7 +492,7 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor, static void handle_tool_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_axis *event = data; struct sway_tablet_tool *sway_tool = event->tool->data; @@ -548,7 +548,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { static void handle_tool_tip(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_tip *event = data; struct sway_tablet_tool *sway_tool = event->tool->data; struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; @@ -589,7 +589,7 @@ static struct sway_tablet *get_tablet_for_device(struct sway_cursor *cursor, static void handle_tool_proximity(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_proximity *event = data; struct wlr_tablet_tool *tool = event->tool; @@ -619,7 +619,7 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { static void handle_tool_button(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); - wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); + seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_button *event = data; struct sway_tablet_tool *sway_tool = event->tool->data; struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index c4ce8246..1d55c165 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -326,7 +326,7 @@ static void handle_key_event(struct sway_keyboard *keyboard, keyboard->seat_device->input_device->wlr_device; char *device_identifier = input_device_get_identifier(wlr_device); bool exact_identifier = wlr_device->keyboard->group != NULL; - wlr_idle_notify_activity(server.idle, wlr_seat); + seat_idle_notify_activity(seat, IDLE_SOURCE_KEYBOARD); bool input_inhibited = seat->exclusive_client != NULL; // Identify new keycode, raw keysym(s), and translated keysym(s) diff --git a/sway/input/seat.c b/sway/input/seat.c index bc72ff0c..371de56e 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -6,6 +6,7 @@ #include <time.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_tablet_v2.h> @@ -71,6 +72,25 @@ static void seat_node_destroy(struct sway_seat_node *seat_node) { free(seat_node); } +void seat_idle_notify_activity(struct sway_seat *seat, + enum sway_input_idle_source source) { + uint32_t mask = seat->idle_inhibit_sources; + struct wlr_idle_timeout *timeout; + int ntimers = 0, nidle = 0; + wl_list_for_each(timeout, &server.idle->idle_timers, link) { + ++ntimers; + if (timeout->idle_state) { + ++nidle; + } + } + if (nidle == ntimers) { + mask = seat->idle_wake_sources; + } + if ((source & mask) > 0) { + wlr_idle_notify_activity(server.idle, seat->wlr_seat); + } +} + /** * Activate all views within this container recursively. */ @@ -491,6 +511,14 @@ struct sway_seat *seat_create(const char *seat_name) { return NULL; } + seat->idle_inhibit_sources = seat->idle_wake_sources = + IDLE_SOURCE_KEYBOARD | + IDLE_SOURCE_POINTER | + IDLE_SOURCE_TOUCH | + IDLE_SOURCE_TABLET_PAD | + IDLE_SOURCE_TABLET_TOOL | + IDLE_SOURCE_SWITCH; + // init the focus stack wl_list_init(&seat->focus_stack); @@ -1325,6 +1353,9 @@ void seat_apply_config(struct sway_seat *seat, return; } + seat->idle_inhibit_sources = seat_config->idle_inhibit_sources; + seat->idle_wake_sources = seat_config->idle_wake_sources; + wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); } diff --git a/sway/input/switch.c b/sway/input/switch.c index 72d1245f..b7c28df1 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c @@ -70,8 +70,8 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { struct sway_switch *sway_switch = wl_container_of(listener, sway_switch, switch_toggle); struct wlr_event_switch_toggle *event = data; - struct wlr_seat* wlr_seat = sway_switch->seat_device->sway_seat->wlr_seat; - wlr_idle_notify_activity(server.idle, wlr_seat); + struct sway_seat *seat = sway_switch->seat_device->sway_seat; + seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH); struct wlr_input_device *wlr_device = sway_switch->seat_device->input_device->wlr_device; |