Skip to content

Commit

Permalink
ipc-server: Force modeset if needed after executing commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennylevinsen authored and emersion committed Nov 17, 2024
1 parent 6111297 commit a2c73c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions sway/ipc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a2c73c9

Please sign in to comment.