diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2024-11-17 12:38:32 +0100 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2024-11-17 12:38:32 +0100 |
| commit | a357835607f30981ad2c8e591cda7af43b7ace3e (patch) | |
| tree | 0987a5276b432f80f39b3713f65459fa7ba9dcf6 | |
| parent | 37e6179e605ecc98f43e6da8b3bb73f8dd68d4c4 (diff) | |
ipc-server: Force modeset if needed after executing commands
IPC clients generally expect executed commands to have taken effect when
the command completes, while delayed modeset means that it can take
several milliseconds more before e.g. an output is enabled.
However, modesetting on every output command in the IPC call could on
systems with already slow modesetting behavior lead to an unresponsive
system for a not insignificant period of time.
To strike a balance, force modeset once all the commands of this IPC
call have executed if a modeset is pending.
| -rw-r--r-- | include/sway/config.h | 1 | ||||
| -rw-r--r-- | sway/desktop/output.c | 4 | ||||
| -rw-r--r-- | sway/ipc-server.c | 6 |
3 files changed, 11 insertions, 0 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 013853c8..bb770c6f 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -706,6 +706,7 @@ void free_output_config(struct output_config *oc); void request_modeset(void); void force_modeset(void); +bool modeset_is_pending(void); bool spawn_swaybg(void); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 5c2332ce..c7ad8f93 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -408,6 +408,10 @@ void request_modeset(void) { } } +bool modeset_is_pending(void) { + return server.delayed_modeset != NULL; +} + void force_modeset(void) { if (server.delayed_modeset != NULL) { wl_event_source_remove(server.delayed_modeset); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 7f353c0e..b934bb56 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -648,6 +648,12 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt } list_t *res_list = execute_command(buf, NULL, NULL); + if (modeset_is_pending()) { + // IPC expects commands to have taken immediate effect, so we need + // to force a modeset after output commands. We do a single modeset + // here to avoid modesetting for every output command in sequence. + force_modeset(); + } transaction_commit_dirty(); char *json = cmd_results_to_json(res_list); int length = strlen(json); |
