This commit is contained in:
Wsevolod 2022-10-31 02:48:29 +09:00 committed by GitHub
commit 9a024bd3db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 4 deletions

View file

@ -9,6 +9,7 @@
#include "swaybar/bar.h"
#include "swaybar/config.h"
#include "swaybar/i3bar.h"
#include "swaybar/ipc.h"
#include "swaybar/input.h"
#include "swaybar/status_line.h"
@ -286,6 +287,10 @@ enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
json_object_object_add(event_json, "button",
json_object_new_int(event_to_x11_button(button)));
json_object_object_add(event_json, "event", json_object_new_int(button));
json_object *modifiers_json = ipc_get_keyboard_modifiers(status);
if (modifiers_json) {
json_object_object_add(event_json, "modifiers", modifiers_json);
}
if (status->float_event_coords) {
json_object_object_add(event_json, "x", json_object_new_double(x));
json_object_object_add(event_json, "y", json_object_new_double(y));

View file

@ -607,3 +607,23 @@ bool handle_ipc_readable(struct swaybar *bar) {
free_ipc_response(resp);
return bar_is_dirty;
}
json_object *ipc_get_keyboard_modifiers(struct status_line *status) {
uint32_t len = 0;
char *buf = ipc_single_command(status->bar->ipc_socketfd,
IPC_GET_INPUTS, NULL, &len);
json_object *inputs_json = json_tokener_parse(buf);
free(buf);
if (!inputs_json) {
return NULL;
}
for (size_t i = 0; i < json_object_array_length(inputs_json); i++) {
json_object *input_json = json_object_array_get_idx(inputs_json, i);
json_object *modifiers_json = NULL;
json_object_object_get_ex(input_json, "xkb_modifiers", &modifiers_json);
if (modifiers_json) {
return modifiers_json;
}
}
return NULL;
}