This commit is contained in:
Florian Franzen 2022-10-03 22:08:45 +05:30 committed by GitHub
commit 3074bf0c97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 437 additions and 0 deletions

View file

@ -140,6 +140,30 @@ static bool ipc_parse_config(
}
}
json_object *gestures = json_object_object_get(bar_config, "gestures");
while (config->gestures->length) {
struct swaybar_gesture *binding = config->gestures->items[0];
list_del(config->gestures, 0);
free_gesture(binding);
}
if (gestures) {
int length = json_object_array_length(gestures);
for (int i = 0; i < length; ++i) {
json_object *bindobj = json_object_array_get_idx(gestures, i);
struct swaybar_gesture *binding =
calloc(1, sizeof(struct swaybar_gesture));
binding->gesture.type = json_object_get_int(
json_object_object_get(bindobj, "type"));
binding->gesture.fingers = json_object_get_int(
json_object_object_get(bindobj, "fingers"));
binding->gesture.directions = json_object_get_int(
json_object_object_get(bindobj, "directions"));
binding->command = strdup(json_object_get_string(
json_object_object_get(bindobj, "command")));
list_add(config->gestures, binding);
}
}
json_object *colors = json_object_object_get(bar_config, "colors");
if (colors) {
ipc_parse_colors(config, colors);
@ -416,6 +440,16 @@ void ipc_execute_binding(struct swaybar *bar, struct swaybar_binding *bind) {
IPC_COMMAND, bind->command, &len));
}
void ipc_execute_gesture(struct swaybar *bar, struct swaybar_gesture *bind) {
char *description = gesture_to_string(&bind->gesture);
sway_log(SWAY_DEBUG, "Executing binding for gesture %s: `%s`",
description, bind->command);
free(description);
uint32_t len = strlen(bind->command);
free(ipc_single_command(bar->ipc_socketfd,
IPC_COMMAND, bind->command, &len));
}
bool ipc_initialize(struct swaybar *bar) {
uint32_t len = strlen(bar->id);
char *res = ipc_single_command(bar->ipc_socketfd,