Skip to content

Commit

Permalink
#147 retry cancellations
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Jan 15, 2024
1 parent 921aa79 commit aab2050
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ TST_E = $(patsubst tst/%.c,%,$(wildcard tst/tst-*.c))
TST_T = $(patsubst tst%,test%,$(TST_E))

all: way-displays
ssh duke -C "rm /home/alex/bin/way-displays" || true
scp way-displays duke:/home/alex/bin

$(SRC_O): $(INC_H) $(PRO_H) config.mk GNUmakefile
$(PRO_O): $(PRO_H) config.mk GNUmakefile
Expand Down
4 changes: 4 additions & 0 deletions inc/displ.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stdint.h>

#define MAX_SEQUENTIAL_CANCELLATIONS 3

enum ConfigState {
IDLE = 0,
SUCCEEDED,
Expand All @@ -24,6 +26,8 @@ struct Displ {
uint32_t output_manager_version;

enum ConfigState config_state;

uint32_t sequential_cancellations;
};

void displ_init(void);
Expand Down
13 changes: 11 additions & 2 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ void handle_failure(void) {
}
}

void handle_cancelled(void) {
if (displ->sequential_cancellations >= MAX_SEQUENTIAL_CANCELLATIONS) {
log_error("\nChanges cancelled %d times, exiting", MAX_SEQUENTIAL_CANCELLATIONS);
wd_exit_message(EXIT_FAILURE);
} else {
log_warn("\nChanges cancelled, retrying");
}
}

void layout(void) {

print_heads(INFO, ARRIVED, heads_arrived);
Expand All @@ -402,9 +411,9 @@ void layout(void) {
break;

case CANCELLED:
log_warn("\nChanges cancelled, retrying");
handle_cancelled();
displ->config_state = IDLE;
return;
break;

case IDLE:
default:
Expand Down
10 changes: 9 additions & 1 deletion src/listener_output_configuration.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <stddef.h>
#include <stdlib.h>

#include "listeners.h"

#include "displ.h"
#include "process.h"
#include "slist.h"
#include "head.h"
#include "wlr-output-management-unstable-v1.h"
Expand All @@ -23,12 +25,18 @@ void cleanup(struct Displ *displ,

zwlr_output_configuration_v1_destroy(zwlr_output_configuration_v1);

if (config_state == CANCELLED) {
displ->sequential_cancellations++;
} else {
displ->sequential_cancellations = 0;
}

displ->config_state = config_state;
}

static void succeeded(void *data,
struct zwlr_output_configuration_v1 *zwlr_output_configuration_v1) {
cleanup(data, zwlr_output_configuration_v1, SUCCEEDED);
cleanup(data, zwlr_output_configuration_v1, CANCELLED);
}

static void failed(void *data,
Expand Down

0 comments on commit aab2050

Please sign in to comment.