diff options
author | 2024-03-28 00:34:30 +0100 | |
---|---|---|
committer | 2024-07-03 10:06:22 -0400 | |
commit | b04f4136bc6163246d7e24454b84a950c8137ffc (patch) | |
tree | 09214a5d78ebe61eedfe907534140ce490b11a25 | |
parent | input/keyboard: don't set layout for virtual keyboard device (diff) | |
download | sway-b04f4136bc6163246d7e24454b84a950c8137ffc.tar.gz sway-b04f4136bc6163246d7e24454b84a950c8137ffc.tar.zst sway-b04f4136bc6163246d7e24454b84a950c8137ffc.zip |
desktop/output: Debounce modesets
Output changes often happen in rapid succession. Instead of doing the
modesets one by one, set a 10 millisecond debounce timer.
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | sway/desktop/output.c | 32 |
2 files changed, 25 insertions, 9 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index 3a63df34..abf1b6b4 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -135,6 +135,8 @@ struct sway_server { | |||
135 | // Stores the nodes that have been marked as "dirty" and will be put into | 135 | // Stores the nodes that have been marked as "dirty" and will be put into |
136 | // the pending transaction. | 136 | // the pending transaction. |
137 | list_t *dirty_nodes; | 137 | list_t *dirty_nodes; |
138 | |||
139 | struct wl_event_source *delayed_modeset; | ||
138 | }; | 140 | }; |
139 | 141 | ||
140 | extern struct sway_server server; | 142 | extern struct sway_server server; |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 4c9d0b63..f936b2a8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -365,6 +365,26 @@ static void update_output_manager_config(struct sway_server *server) { | |||
365 | ipc_event_output(); | 365 | ipc_event_output(); |
366 | } | 366 | } |
367 | 367 | ||
368 | static int timer_modeset_handle(void *data) { | ||
369 | struct sway_server *server = data; | ||
370 | wl_event_source_remove(server->delayed_modeset); | ||
371 | server->delayed_modeset = NULL; | ||
372 | |||
373 | apply_all_output_configs(); | ||
374 | transaction_commit_dirty(); | ||
375 | update_output_manager_config(server); | ||
376 | |||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static void request_modeset(struct sway_server *server) { | ||
381 | if (server->delayed_modeset == NULL) { | ||
382 | server->delayed_modeset = wl_event_loop_add_timer(server->wl_event_loop, | ||
383 | timer_modeset_handle, server); | ||
384 | wl_event_source_timer_update(server->delayed_modeset, 10); | ||
385 | } | ||
386 | } | ||
387 | |||
368 | static void begin_destroy(struct sway_output *output) { | 388 | static void begin_destroy(struct sway_output *output) { |
369 | struct sway_server *server = output->server; | 389 | struct sway_server *server = output->server; |
370 | 390 | ||
@@ -388,9 +408,7 @@ static void begin_destroy(struct sway_output *output) { | |||
388 | output->wlr_output->data = NULL; | 408 | output->wlr_output->data = NULL; |
389 | output->wlr_output = NULL; | 409 | output->wlr_output = NULL; |
390 | 410 | ||
391 | transaction_commit_dirty(); | 411 | request_modeset(server); |
392 | |||
393 | update_output_manager_config(server); | ||
394 | } | 412 | } |
395 | 413 | ||
396 | static void handle_destroy(struct wl_listener *listener, void *data) { | 414 | static void handle_destroy(struct wl_listener *listener, void *data) { |
@@ -524,11 +542,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { | |||
524 | sway_session_lock_add_output(server->session_lock.lock, output); | 542 | sway_session_lock_add_output(server->session_lock.lock, output); |
525 | } | 543 | } |
526 | 544 | ||
527 | apply_all_output_configs(); | 545 | request_modeset(server); |
528 | |||
529 | transaction_commit_dirty(); | ||
530 | |||
531 | update_output_manager_config(server); | ||
532 | } | 546 | } |
533 | 547 | ||
534 | void handle_output_layout_change(struct wl_listener *listener, | 548 | void handle_output_layout_change(struct wl_listener *listener, |
@@ -680,5 +694,5 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener, | |||
680 | break; | 694 | break; |
681 | } | 695 | } |
682 | store_output_config(oc); | 696 | store_output_config(oc); |
683 | apply_all_output_configs(); | 697 | request_modeset(output->server); |
684 | } | 698 | } |