[PATCH kanshi] Add config pre_exec statement for execute before applying profile.
Export this patch
---
include/config.h | 1 +
main.c | 15 +++++++++++++++
parser.c | 9 +++++++++
3 files changed, 25 insertions(+)
diff --git a/include/config.h b/include/config.h
index 8e80bf0..a27bae0 100644
--- a/include/config.h
+++ b/include/config.h
@@ -40,6 +40,7 @@ struct kanshi_profile {
// Wildcard outputs are stored at the end of the list
struct wl_list outputs;
struct wl_list commands;
+ struct wl_list pre_commands;
};
struct kanshi_config {
diff --git a/main.c b/main.c
index a3d813f..044d100 100644
--- a/main.c
+++ b/main.c
@@ -140,6 +140,14 @@ static void execute_profile_commands(struct kanshi_profile *profile) {
}
}
+static void execute_pre_profile_commands(struct kanshi_profile *profile) {
+ struct kanshi_profile_command *command;
+ wl_list_for_each(command, &profile->pre_commands, link) {
+ fprintf(stderr, "Running preprofile command '%s'\n", command->command);
+ exec_command(command->command);
+ }
+}
+
static void config_handle_succeeded(void *data,
struct zwlr_output_configuration_v1 *config) {
struct kanshi_pending_profile *pending = data;
@@ -228,6 +236,7 @@ static void apply_profile(struct kanshi_state *state,
}
fprintf(stderr, "applying profile '%s'\n", profile->name);
+ execute_pre_profile_commands(profile);
struct kanshi_pending_profile *pending = calloc(1, sizeof(*pending));
pending->serial = state->serial;
@@ -577,6 +586,12 @@ static void destroy_config(struct kanshi_config *config) {
wl_list_remove(&command->link);
free(command);
}
+ wl_list_for_each_safe(command, tmp_command, &profile->pre_commands, link) {
+ free(command->command);
+ wl_list_remove(&command->link);
+ free(command);
+ }
+
wl_list_remove(&profile->link);
free(profile);
}
diff --git a/parser.c b/parser.c
index 5b774d9..1e6ca7f 100644
--- a/parser.c
+++ b/parser.c
@@ -398,6 +398,7 @@ static struct kanshi_profile_command *parse_profile_command(
static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
struct kanshi_profile *profile = calloc(1, sizeof(*profile));
wl_list_init(&profile->outputs);
+ wl_list_init(&profile->pre_commands);
wl_list_init(&profile->commands);
if (!parser_next_token(parser)) {
@@ -462,6 +463,14 @@ static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
}
// Insert commands at the end to preserve order
wl_list_insert(profile->commands.prev, &command->link);
+ } else if (strcmp(directive, "pre_exec") == 0) {
+ struct kanshi_profile_command *pre_command =
+ parse_profile_command(parser);
+ if (pre_command == NULL) {
+ return NULL;
+ }
+ // Insert commands at the end to preserve order
+ wl_list_insert(profile->pre_commands.prev, &pre_command->link);
} else {
fprintf(stderr, "unknown directive '%s' in profile '%s'\n",
directive, profile->name);
--
2.36.1
kanshi/patches/.build.yml: FAILED in 22s
[Add config pre_exec statement for execute before applying profile.][0] from [shinanca][1]
[0]: https://lists.sr.ht/~emersion/public-inbox/patches/34729
[1]: mailto:max_rain@chooseme.ru
✗ #825147 FAILED kanshi/patches/.build.yml https://builds.sr.ht/~emersion/job/825147