summaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2019-12-11 11:00:39 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-12-12 10:37:30 -0500
commit2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6 (patch)
tree69d3367cf7dbd7f756d45d89cd37e6016503a88d /sway/input
parentFix lingering workspace with scratchpad show (diff)
downloadsway-2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6.tar.gz
sway-2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6.tar.zst
sway-2f3c6cccf5d6b2d6ffd3cee62e7b624dc80dc6e6.zip
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.c16
-rw-r--r--sway/input/keyboard.c2
-rw-r--r--sway/input/seat.c31
-rw-r--r--sway/input/switch.c4
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) {
206 wl_event_source_timer_update( 206 wl_event_source_timer_update(
207 cursor->hide_source, cursor_get_timeout(cursor)); 207 cursor->hide_source, cursor_get_timeout(cursor));
208 208
209 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 209 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_POINTER);
210 if (cursor->hidden) { 210 if (cursor->hidden) {
211 cursor_unhide(cursor); 211 cursor_unhide(cursor);
212 } 212 }
@@ -341,7 +341,7 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) {
341 341
342static void handle_touch_down(struct wl_listener *listener, void *data) { 342static void handle_touch_down(struct wl_listener *listener, void *data) {
343 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); 343 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
344 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 344 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH);
345 struct wlr_event_touch_down *event = data; 345 struct wlr_event_touch_down *event = data;
346 346
347 struct sway_seat *seat = cursor->seat; 347 struct sway_seat *seat = cursor->seat;
@@ -372,7 +372,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
372 372
373static void handle_touch_up(struct wl_listener *listener, void *data) { 373static void handle_touch_up(struct wl_listener *listener, void *data) {
374 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); 374 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
375 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 375 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH);
376 struct wlr_event_touch_up *event = data; 376 struct wlr_event_touch_up *event = data;
377 struct wlr_seat *seat = cursor->seat->wlr_seat; 377 struct wlr_seat *seat = cursor->seat->wlr_seat;
378 // TODO: fall back to cursor simulation if client has not bound to touch 378 // 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) {
382static void handle_touch_motion(struct wl_listener *listener, void *data) { 382static void handle_touch_motion(struct wl_listener *listener, void *data) {
383 struct sway_cursor *cursor = 383 struct sway_cursor *cursor =
384 wl_container_of(listener, cursor, touch_motion); 384 wl_container_of(listener, cursor, touch_motion);
385 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 385 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TOUCH);
386 struct wlr_event_touch_motion *event = data; 386 struct wlr_event_touch_motion *event = data;
387 387
388 struct sway_seat *seat = cursor->seat; 388 struct sway_seat *seat = cursor->seat;
@@ -492,7 +492,7 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor,
492 492
493static void handle_tool_axis(struct wl_listener *listener, void *data) { 493static void handle_tool_axis(struct wl_listener *listener, void *data) {
494 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); 494 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
495 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 495 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL);
496 struct wlr_event_tablet_tool_axis *event = data; 496 struct wlr_event_tablet_tool_axis *event = data;
497 struct sway_tablet_tool *sway_tool = event->tool->data; 497 struct sway_tablet_tool *sway_tool = event->tool->data;
498 498
@@ -548,7 +548,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
548 548
549static void handle_tool_tip(struct wl_listener *listener, void *data) { 549static void handle_tool_tip(struct wl_listener *listener, void *data) {
550 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); 550 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
551 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 551 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL);
552 struct wlr_event_tablet_tool_tip *event = data; 552 struct wlr_event_tablet_tool_tip *event = data;
553 struct sway_tablet_tool *sway_tool = event->tool->data; 553 struct sway_tablet_tool *sway_tool = event->tool->data;
554 struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; 554 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,
589 589
590static void handle_tool_proximity(struct wl_listener *listener, void *data) { 590static void handle_tool_proximity(struct wl_listener *listener, void *data) {
591 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); 591 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity);
592 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 592 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL);
593 struct wlr_event_tablet_tool_proximity *event = data; 593 struct wlr_event_tablet_tool_proximity *event = data;
594 594
595 struct wlr_tablet_tool *tool = event->tool; 595 struct wlr_tablet_tool *tool = event->tool;
@@ -619,7 +619,7 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) {
619 619
620static void handle_tool_button(struct wl_listener *listener, void *data) { 620static void handle_tool_button(struct wl_listener *listener, void *data) {
621 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); 621 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
622 wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); 622 seat_idle_notify_activity(cursor->seat, IDLE_SOURCE_TABLET_TOOL);
623 struct wlr_event_tablet_tool_button *event = data; 623 struct wlr_event_tablet_tool_button *event = data;
624 struct sway_tablet_tool *sway_tool = event->tool->data; 624 struct sway_tablet_tool *sway_tool = event->tool->data;
625 struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; 625 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,
326 keyboard->seat_device->input_device->wlr_device; 326 keyboard->seat_device->input_device->wlr_device;
327 char *device_identifier = input_device_get_identifier(wlr_device); 327 char *device_identifier = input_device_get_identifier(wlr_device);
328 bool exact_identifier = wlr_device->keyboard->group != NULL; 328 bool exact_identifier = wlr_device->keyboard->group != NULL;
329 wlr_idle_notify_activity(server.idle, wlr_seat); 329 seat_idle_notify_activity(seat, IDLE_SOURCE_KEYBOARD);
330 bool input_inhibited = seat->exclusive_client != NULL; 330 bool input_inhibited = seat->exclusive_client != NULL;
331 331
332 // Identify new keycode, raw keysym(s), and translated keysym(s) 332 // 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 @@
6#include <time.h> 6#include <time.h>
7#include <wlr/types/wlr_cursor.h> 7#include <wlr/types/wlr_cursor.h>
8#include <wlr/types/wlr_data_device.h> 8#include <wlr/types/wlr_data_device.h>
9#include <wlr/types/wlr_idle.h>
9#include <wlr/types/wlr_output_layout.h> 10#include <wlr/types/wlr_output_layout.h>
10#include <wlr/types/wlr_primary_selection.h> 11#include <wlr/types/wlr_primary_selection.h>
11#include <wlr/types/wlr_tablet_v2.h> 12#include <wlr/types/wlr_tablet_v2.h>
@@ -71,6 +72,25 @@ static void seat_node_destroy(struct sway_seat_node *seat_node) {
71 free(seat_node); 72 free(seat_node);
72} 73}
73 74
75void seat_idle_notify_activity(struct sway_seat *seat,
76 enum sway_input_idle_source source) {
77 uint32_t mask = seat->idle_inhibit_sources;
78 struct wlr_idle_timeout *timeout;
79 int ntimers = 0, nidle = 0;
80 wl_list_for_each(timeout, &server.idle->idle_timers, link) {
81 ++ntimers;
82 if (timeout->idle_state) {
83 ++nidle;
84 }
85 }
86 if (nidle == ntimers) {
87 mask = seat->idle_wake_sources;
88 }
89 if ((source & mask) > 0) {
90 wlr_idle_notify_activity(server.idle, seat->wlr_seat);
91 }
92}
93
74/** 94/**
75 * Activate all views within this container recursively. 95 * Activate all views within this container recursively.
76 */ 96 */
@@ -491,6 +511,14 @@ struct sway_seat *seat_create(const char *seat_name) {
491 return NULL; 511 return NULL;
492 } 512 }
493 513
514 seat->idle_inhibit_sources = seat->idle_wake_sources =
515 IDLE_SOURCE_KEYBOARD |
516 IDLE_SOURCE_POINTER |
517 IDLE_SOURCE_TOUCH |
518 IDLE_SOURCE_TABLET_PAD |
519 IDLE_SOURCE_TABLET_TOOL |
520 IDLE_SOURCE_SWITCH;
521
494 // init the focus stack 522 // init the focus stack
495 wl_list_init(&seat->focus_stack); 523 wl_list_init(&seat->focus_stack);
496 524
@@ -1325,6 +1353,9 @@ void seat_apply_config(struct sway_seat *seat,
1325 return; 1353 return;
1326 } 1354 }
1327 1355
1356 seat->idle_inhibit_sources = seat_config->idle_inhibit_sources;
1357 seat->idle_wake_sources = seat_config->idle_wake_sources;
1358
1328 wl_list_for_each(seat_device, &seat->devices, link) { 1359 wl_list_for_each(seat_device, &seat->devices, link) {
1329 seat_configure_device(seat, seat_device->input_device); 1360 seat_configure_device(seat, seat_device->input_device);
1330 } 1361 }
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) {
70 struct sway_switch *sway_switch = 70 struct sway_switch *sway_switch =
71 wl_container_of(listener, sway_switch, switch_toggle); 71 wl_container_of(listener, sway_switch, switch_toggle);
72 struct wlr_event_switch_toggle *event = data; 72 struct wlr_event_switch_toggle *event = data;
73 struct wlr_seat* wlr_seat = sway_switch->seat_device->sway_seat->wlr_seat; 73 struct sway_seat *seat = sway_switch->seat_device->sway_seat;
74 wlr_idle_notify_activity(server.idle, wlr_seat); 74 seat_idle_notify_activity(seat, IDLE_SOURCE_SWITCH);
75 75
76 struct wlr_input_device *wlr_device = 76 struct wlr_input_device *wlr_device =
77 sway_switch->seat_device->input_device->wlr_device; 77 sway_switch->seat_device->input_device->wlr_device;