diff options
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/sway/input/switch.h | 10 | ||||
-rw-r--r-- | sway/commands/bind.c | 2 | ||||
-rw-r--r-- | sway/config.c | 12 | ||||
-rw-r--r-- | sway/input/switch.c | 57 | ||||
-rw-r--r-- | sway/sway.5.scd | 7 |
6 files changed, 63 insertions, 26 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 4adce8ab..c5558c0d 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -39,6 +39,7 @@ enum binding_flags { | |||
39 | BINDING_CONTENTS=8, // mouse only; trigger on container contents | 39 | BINDING_CONTENTS=8, // mouse only; trigger on container contents |
40 | BINDING_TITLEBAR=16, // mouse only; trigger on container titlebar | 40 | BINDING_TITLEBAR=16, // mouse only; trigger on container titlebar |
41 | BINDING_CODE=32, // keyboard only; convert keysyms into keycodes | 41 | BINDING_CODE=32, // keyboard only; convert keysyms into keycodes |
42 | BINDING_RELOAD=62, // switch only; (re)trigger binding on reload | ||
42 | }; | 43 | }; |
43 | 44 | ||
44 | /** | 45 | /** |
diff --git a/include/sway/input/switch.h b/include/sway/input/switch.h index 19bb1e77..213b471d 100644 --- a/include/sway/input/switch.h +++ b/include/sway/input/switch.h | |||
@@ -4,16 +4,20 @@ | |||
4 | #include "sway/input/seat.h" | 4 | #include "sway/input/seat.h" |
5 | 5 | ||
6 | struct sway_switch { | 6 | struct sway_switch { |
7 | struct sway_seat_device *seat_device; | 7 | struct sway_seat_device *seat_device; |
8 | enum wlr_switch_state state; | ||
9 | enum wlr_switch_type type; | ||
8 | 10 | ||
9 | struct wl_listener switch_toggle; | 11 | struct wl_listener switch_toggle; |
10 | }; | 12 | }; |
11 | 13 | ||
12 | struct sway_switch *sway_switch_create(struct sway_seat *seat, | 14 | struct sway_switch *sway_switch_create(struct sway_seat *seat, |
13 | struct sway_seat_device *device); | 15 | struct sway_seat_device *device); |
14 | 16 | ||
15 | void sway_switch_configure(struct sway_switch *sway_switch); | 17 | void sway_switch_configure(struct sway_switch *sway_switch); |
16 | 18 | ||
17 | void sway_switch_destroy(struct sway_switch *sway_switch); | 19 | void sway_switch_destroy(struct sway_switch *sway_switch); |
18 | 20 | ||
21 | void sway_switch_retrigger_bindings_for_all(void); | ||
22 | |||
19 | #endif | 23 | #endif |
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 49b511ad..767c2fee 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -478,6 +478,8 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv, | |||
478 | binding->flags |= BINDING_LOCKED; | 478 | binding->flags |= BINDING_LOCKED; |
479 | } else if (strcmp("--no-warn", argv[0]) == 0) { | 479 | } else if (strcmp("--no-warn", argv[0]) == 0) { |
480 | warn = false; | 480 | warn = false; |
481 | } else if (strcmp("--reload", argv[0]) == 0) { | ||
482 | binding->flags |= BINDING_RELOAD; | ||
481 | } else { | 483 | } else { |
482 | break; | 484 | break; |
483 | } | 485 | } |
diff --git a/sway/config.c b/sway/config.c index 70f2d706..74080898 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <wlr/types/wlr_output.h> | 17 | #include <wlr/types/wlr_output.h> |
18 | #include "sway/input/input-manager.h" | 18 | #include "sway/input/input-manager.h" |
19 | #include "sway/input/seat.h" | 19 | #include "sway/input/seat.h" |
20 | #include "sway/input/switch.h" | ||
20 | #include "sway/commands.h" | 21 | #include "sway/commands.h" |
21 | #include "sway/config.h" | 22 | #include "sway/config.h" |
22 | #include "sway/criteria.h" | 23 | #include "sway/criteria.h" |
@@ -520,6 +521,12 @@ bool load_main_config(const char *file, bool is_active, bool validating) { | |||
520 | } | 521 | } |
521 | 522 | ||
522 | if (is_active) { | 523 | if (is_active) { |
524 | input_manager_verify_fallback_seat(); | ||
525 | for (int i = 0; i < config->seat_configs->length; i++) { | ||
526 | input_manager_apply_seat_config(config->seat_configs->items[i]); | ||
527 | } | ||
528 | sway_switch_retrigger_bindings_for_all(); | ||
529 | |||
523 | reset_outputs(); | 530 | reset_outputs(); |
524 | spawn_swaybg(); | 531 | spawn_swaybg(); |
525 | 532 | ||
@@ -527,11 +534,6 @@ bool load_main_config(const char *file, bool is_active, bool validating) { | |||
527 | if (config->swaynag_config_errors.client != NULL) { | 534 | if (config->swaynag_config_errors.client != NULL) { |
528 | swaynag_show(&config->swaynag_config_errors); | 535 | swaynag_show(&config->swaynag_config_errors); |
529 | } | 536 | } |
530 | |||
531 | input_manager_verify_fallback_seat(); | ||
532 | for (int i = 0; i < config->seat_configs->length; i++) { | ||
533 | input_manager_apply_seat_config(config->seat_configs->items[i]); | ||
534 | } | ||
535 | } | 537 | } |
536 | 538 | ||
537 | if (old_config) { | 539 | if (old_config) { |
diff --git a/sway/input/switch.c b/sway/input/switch.c index d825c5c3..72d1245f 100644 --- a/sway/input/switch.c +++ b/sway/input/switch.c | |||
@@ -13,39 +13,30 @@ struct sway_switch *sway_switch_create(struct sway_seat *seat, | |||
13 | } | 13 | } |
14 | device->switch_device = switch_device; | 14 | device->switch_device = switch_device; |
15 | switch_device->seat_device = device; | 15 | switch_device->seat_device = device; |
16 | switch_device->state = WLR_SWITCH_STATE_OFF; | ||
16 | wl_list_init(&switch_device->switch_toggle.link); | 17 | wl_list_init(&switch_device->switch_toggle.link); |
17 | sway_log(SWAY_DEBUG, "Allocated switch for device"); | 18 | sway_log(SWAY_DEBUG, "Allocated switch for device"); |
18 | 19 | ||
19 | return switch_device; | 20 | return switch_device; |
20 | } | 21 | } |
21 | 22 | ||
22 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { | 23 | static void execute_binding(struct sway_switch *sway_switch) { |
23 | struct sway_switch *sway_switch = | ||
24 | wl_container_of(listener, sway_switch, switch_toggle); | ||
25 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; | 24 | struct sway_seat* seat = sway_switch->seat_device->sway_seat; |
26 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
27 | struct wlr_input_device *wlr_device = | ||
28 | sway_switch->seat_device->input_device->wlr_device; | ||
29 | |||
30 | wlr_idle_notify_activity(server.idle, wlr_seat); | ||
31 | bool input_inhibited = seat->exclusive_client != NULL; | 25 | bool input_inhibited = seat->exclusive_client != NULL; |
32 | 26 | ||
33 | char *device_identifier = input_device_get_identifier(wlr_device); | ||
34 | |||
35 | struct wlr_event_switch_toggle *event = data; | ||
36 | enum wlr_switch_type type = event->switch_type; | ||
37 | enum wlr_switch_state state = event->switch_state; | ||
38 | sway_log(SWAY_DEBUG, "%s: type %d state %d", device_identifier, type, state); | ||
39 | |||
40 | list_t *bindings = config->current_mode->switch_bindings; | 27 | list_t *bindings = config->current_mode->switch_bindings; |
41 | struct sway_switch_binding *matched_binding = NULL; | 28 | struct sway_switch_binding *matched_binding = NULL; |
42 | for (int i = 0; i < bindings->length; ++i) { | 29 | for (int i = 0; i < bindings->length; ++i) { |
43 | struct sway_switch_binding *binding = bindings->items[i]; | 30 | struct sway_switch_binding *binding = bindings->items[i]; |
44 | if (binding->type != type) { | 31 | if (binding->type != sway_switch->type) { |
45 | continue; | 32 | continue; |
46 | } | 33 | } |
47 | if (binding->state != WLR_SWITCH_STATE_TOGGLE && | 34 | if (binding->state != WLR_SWITCH_STATE_TOGGLE && |
48 | binding->state != state) { | 35 | binding->state != sway_switch->state) { |
36 | continue; | ||
37 | } | ||
38 | if (config->reloading && (binding->state == WLR_SWITCH_STATE_TOGGLE | ||
39 | || (binding->flags & BINDING_RELOAD) == 0)) { | ||
49 | continue; | 40 | continue; |
50 | } | 41 | } |
51 | bool binding_locked = binding->flags & BINDING_LOCKED; | 42 | bool binding_locked = binding->flags & BINDING_LOCKED; |
@@ -73,7 +64,25 @@ static void handle_switch_toggle(struct wl_listener *listener, void *data) { | |||
73 | 64 | ||
74 | transaction_commit_dirty(); | 65 | transaction_commit_dirty(); |
75 | 66 | ||
67 | } | ||
68 | |||
69 | static void handle_switch_toggle(struct wl_listener *listener, void *data) { | ||
70 | struct sway_switch *sway_switch = | ||
71 | wl_container_of(listener, sway_switch, switch_toggle); | ||
72 | struct wlr_event_switch_toggle *event = data; | ||
73 | struct wlr_seat* wlr_seat = sway_switch->seat_device->sway_seat->wlr_seat; | ||
74 | wlr_idle_notify_activity(server.idle, wlr_seat); | ||
75 | |||
76 | struct wlr_input_device *wlr_device = | ||
77 | sway_switch->seat_device->input_device->wlr_device; | ||
78 | char *device_identifier = input_device_get_identifier(wlr_device); | ||
79 | sway_log(SWAY_DEBUG, "%s: type %d state %d", device_identifier, | ||
80 | event->switch_type, event->switch_state); | ||
76 | free(device_identifier); | 81 | free(device_identifier); |
82 | |||
83 | sway_switch->type = event->switch_type; | ||
84 | sway_switch->state = event->switch_state; | ||
85 | execute_binding(sway_switch); | ||
77 | } | 86 | } |
78 | 87 | ||
79 | void sway_switch_configure(struct sway_switch *sway_switch) { | 88 | void sway_switch_configure(struct sway_switch *sway_switch) { |
@@ -93,3 +102,17 @@ void sway_switch_destroy(struct sway_switch *sway_switch) { | |||
93 | wl_list_remove(&sway_switch->switch_toggle.link); | 102 | wl_list_remove(&sway_switch->switch_toggle.link); |
94 | free(sway_switch); | 103 | free(sway_switch); |
95 | } | 104 | } |
105 | |||
106 | void sway_switch_retrigger_bindings_for_all(void) { | ||
107 | struct sway_seat *seat; | ||
108 | wl_list_for_each(seat, &server.input->seats, link) { | ||
109 | struct sway_seat_device *seat_device; | ||
110 | wl_list_for_each(seat_device, &seat->devices, link) { | ||
111 | struct sway_input_device *input_device = seat_device->input_device; | ||
112 | if (input_device->wlr_device->type != WLR_INPUT_DEVICE_SWITCH) { | ||
113 | continue; | ||
114 | } | ||
115 | execute_binding(seat_device->switch_device); | ||
116 | }; | ||
117 | } | ||
118 | } | ||
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 90d7fed8..ca47c1f9 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -378,7 +378,7 @@ runtime. | |||
378 | *bindcode* [--whole-window] [--border] [--exclude-titlebar] [--release] [--locked] [--input-device=<device>] [--no-warn] <code> <command> | 378 | *bindcode* [--whole-window] [--border] [--exclude-titlebar] [--release] [--locked] [--input-device=<device>] [--no-warn] <code> <command> |
379 | is also available for binding with key/button codes instead of key/button names. | 379 | is also available for binding with key/button codes instead of key/button names. |
380 | 380 | ||
381 | *bindswitch* [--locked] [--no-warn] <switch>:<state> <command> | 381 | *bindswitch* [--locked] [--no-warn] [--reload] <switch>:<state> <command> |
382 | Binds <switch> to execute the sway command _command_ on state changes. | 382 | Binds <switch> to execute the sway command _command_ on state changes. |
383 | Supported switches are _lid_ (laptop lid) and _tablet_ (tablet mode) | 383 | Supported switches are _lid_ (laptop lid) and _tablet_ (tablet mode) |
384 | switches. Valid values for _state_ are _on_, _off_ and _toggle_. These | 384 | switches. Valid values for _state_ are _on_, _off_ and _toggle_. These |
@@ -391,6 +391,11 @@ runtime. | |||
391 | and without _--locked_, the one with will be preferred when locked and the | 391 | and without _--locked_, the one with will be preferred when locked and the |
392 | one without will be preferred when unlocked. | 392 | one without will be preferred when unlocked. |
393 | 393 | ||
394 | If the _--reload_ flag is given, the binding will also be executed when | ||
395 | the config is reloaded. _toggle_ bindings will not be executed on reload. | ||
396 | The _--locked_ flag will operate as normal so if the config is reloaded | ||
397 | while locked and _--locked_ is not given, the binding will not be executed. | ||
398 | |||
394 | By default, if you overwrite a binding, swaynag will give you a warning. To | 399 | By default, if you overwrite a binding, swaynag will give you a warning. To |
395 | silence this, use the _--no-warn_ flag. | 400 | silence this, use the _--no-warn_ flag. |
396 | 401 | ||