mirror of
https://github.com/swaywm/sway.git
synced 2024-12-01 02:49:26 +00:00
Implement modifiers
array in swaybar click events
This commit is contained in:
parent
eaeb173a4b
commit
7a93906626
|
@ -5,6 +5,13 @@
|
|||
|
||||
#define SWAY_KEYBOARD_PRESSED_KEYS_CAP 32
|
||||
|
||||
struct modifier_key {
|
||||
char *name;
|
||||
uint32_t mod;
|
||||
};
|
||||
|
||||
extern struct modifier_key modifiers[10];
|
||||
|
||||
/**
|
||||
* Get modifier mask from modifier name.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _SWAYBAR_IPC_H
|
||||
#define _SWAYBAR_IPC_H
|
||||
#include <stdbool.h>
|
||||
#include <json.h>
|
||||
#include "swaybar/bar.h"
|
||||
|
||||
bool ipc_initialize(struct swaybar *bar);
|
||||
|
@ -8,5 +9,6 @@ bool handle_ipc_readable(struct swaybar *bar);
|
|||
bool ipc_get_workspaces(struct swaybar *bar);
|
||||
void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
|
||||
void ipc_execute_binding(struct swaybar *bar, struct swaybar_binding *bind);
|
||||
json_object *ipc_get_keyboard_modifiers(struct status_line *status);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
#include "sway/ipc-server.h"
|
||||
#include "log.h"
|
||||
|
||||
static struct modifier_key {
|
||||
char *name;
|
||||
uint32_t mod;
|
||||
} modifiers[] = {
|
||||
struct modifier_key modifiers[] = {
|
||||
{ XKB_MOD_NAME_SHIFT, WLR_MODIFIER_SHIFT },
|
||||
{ XKB_MOD_NAME_CAPS, WLR_MODIFIER_CAPS },
|
||||
{ XKB_MOD_NAME_CTRL, WLR_MODIFIER_CTRL },
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include "sway/input/keyboard.h"
|
||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||
#include "sway/desktop/idle_inhibit_v1.h"
|
||||
|
||||
|
@ -1000,6 +1001,20 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
|
|||
layout ? json_object_new_string(layout) : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
json_object *modifiers_json = json_object_new_array();
|
||||
uint32_t keyboard_modifiers = wlr_keyboard_get_modifiers(keyboard);
|
||||
for (int i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); i++) {
|
||||
if (keyboard_modifiers & modifiers[i].mod) {
|
||||
json_object_array_add(modifiers_json,
|
||||
json_object_new_string(modifiers[i].name));
|
||||
}
|
||||
}
|
||||
if (json_object_array_length(modifiers_json) > 0) {
|
||||
json_object_object_add(object, "xkb_modifiers", modifiers_json);
|
||||
} else {
|
||||
json_object_put(modifiers_json);
|
||||
}
|
||||
}
|
||||
|
||||
if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -606,3 +606,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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue