Skip to content

Commit a2c73c9

Browse files
kennylevinsenemersion
authored andcommitted
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.
1 parent 6111297 commit a2c73c9

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

include/sway/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ void free_output_config(struct output_config *oc);
706706

707707
void request_modeset(void);
708708
void force_modeset(void);
709+
bool modeset_is_pending(void);
709710

710711
bool spawn_swaybg(void);
711712

sway/desktop/output.c

+4
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ void request_modeset(void) {
408408
}
409409
}
410410

411+
bool modeset_is_pending(void) {
412+
return server.delayed_modeset != NULL;
413+
}
414+
411415
void force_modeset(void) {
412416
if (server.delayed_modeset != NULL) {
413417
wl_event_source_remove(server.delayed_modeset);

sway/ipc-server.c

+6
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,12 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
648648
}
649649

650650
list_t *res_list = execute_command(buf, NULL, NULL);
651+
if (modeset_is_pending()) {
652+
// IPC expects commands to have taken immediate effect, so we need
653+
// to force a modeset after output commands. We do a single modeset
654+
// here to avoid modesetting for every output command in sequence.
655+
force_modeset();
656+
}
651657
transaction_commit_dirty();
652658
char *json = cmd_results_to_json(res_list);
653659
int length = strlen(json);

0 commit comments

Comments
 (0)