mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-19 20:45:18 -05:00
feat(pointing): Release pressed keys on disconnect (#3204)
Match the behavior for key press release on split peripheral disconnect, and track pressed input keys to release them as needed on disconnect.
This commit is contained in:
@@ -7,4 +7,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t code, int32_t value,
|
int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t code, int32_t value,
|
||||||
bool sync);
|
bool sync);
|
||||||
|
int zmk_input_split_peripheral_disconnected(uint8_t reg);
|
||||||
@@ -78,6 +78,11 @@ config ZMK_INPUT_SPLIT_INIT_PRIORITY
|
|||||||
int "Input Split initialization priority"
|
int "Input Split initialization priority"
|
||||||
default INPUT_INIT_PRIORITY
|
default INPUT_INIT_PRIORITY
|
||||||
|
|
||||||
|
|
||||||
|
config ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS
|
||||||
|
int "Input Split max tracked keys to release on peripheral disconnect"
|
||||||
|
default 5
|
||||||
|
|
||||||
endif # ZMK_INPUT_SPLIT
|
endif # ZMK_INPUT_SPLIT
|
||||||
|
|
||||||
endif # ZMK_POINTING
|
endif # ZMK_POINTING
|
||||||
|
|||||||
@@ -26,11 +26,42 @@ struct zis_entry {
|
|||||||
|
|
||||||
static const struct zis_entry proxy_inputs[] = {DT_INST_FOREACH_STATUS_OKAY(ZIS_ENTRY)};
|
static const struct zis_entry proxy_inputs[] = {DT_INST_FOREACH_STATUS_OKAY(ZIS_ENTRY)};
|
||||||
|
|
||||||
|
static uint16_t proxy_active_keys[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)]
|
||||||
|
[CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS];
|
||||||
|
|
||||||
|
static int replace_active_key(size_t input, uint16_t find, uint16_t replace) {
|
||||||
|
for (size_t k = 0; k < CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS; k++) {
|
||||||
|
if (proxy_active_keys[input][k] == find) {
|
||||||
|
proxy_active_keys[input][k] = replace;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t code, int32_t value,
|
int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t code, int32_t value,
|
||||||
bool sync) {
|
bool sync) {
|
||||||
LOG_DBG("Got peripheral event for %d!", reg);
|
LOG_DBG("Got peripheral event for %d!", reg);
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(proxy_inputs); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(proxy_inputs); i++) {
|
||||||
if (reg == proxy_inputs[i].reg) {
|
if (reg == proxy_inputs[i].reg) {
|
||||||
|
if (type == INPUT_EV_KEY) {
|
||||||
|
uint16_t find, replace;
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
find = 0;
|
||||||
|
replace = code;
|
||||||
|
} else {
|
||||||
|
find = code;
|
||||||
|
replace = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = replace_active_key(i, find, replace);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_WRN("Failed to %s key %d", value ? "track pressed" : "untrack released",
|
||||||
|
ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
return input_report(proxy_inputs[i].dev, type, code, value, sync, K_NO_WAIT);
|
return input_report(proxy_inputs[i].dev, type, code, value, sync, K_NO_WAIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,6 +69,37 @@ int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zmk_input_split_peripheral_disconnected(uint8_t reg) {
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(proxy_inputs); i++) {
|
||||||
|
if (reg == proxy_inputs[i].reg) {
|
||||||
|
uint16_t prev = 0;
|
||||||
|
for (size_t k = 0; k < CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS; k++) {
|
||||||
|
if (proxy_active_keys[i][k] != 0) {
|
||||||
|
if (prev != 0) {
|
||||||
|
int ret = input_report(proxy_inputs[i].dev, INPUT_EV_KEY, prev, 0, false,
|
||||||
|
K_NO_WAIT);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_WRN("Failed to report release event on disconnect (%d)", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = proxy_active_keys[i][k];
|
||||||
|
proxy_active_keys[i][k] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev != 0) {
|
||||||
|
int ret = input_report(proxy_inputs[i].dev, INPUT_EV_KEY, prev, 0, true, K_NO_WAIT);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_WRN("Failed to report release event on disconnect (%d)", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
#define ZIS_INST(n) \
|
#define ZIS_INST(n) \
|
||||||
DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, \
|
DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, \
|
||||||
CONFIG_ZMK_INPUT_SPLIT_INIT_PRIORITY, NULL);
|
CONFIG_ZMK_INPUT_SPLIT_INIT_PRIORITY, NULL);
|
||||||
@@ -78,4 +140,4 @@ int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(ZIS_INST)
|
DT_INST_FOREACH_STATUS_OKAY(ZIS_INST)
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ void release_peripheral_input_subs(struct bt_conn *conn) {
|
|||||||
for (size_t i = 0; i < ARRAY_SIZE(peripheral_input_slots); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(peripheral_input_slots); i++) {
|
||||||
if (peripheral_input_slots[i].conn == conn) {
|
if (peripheral_input_slots[i].conn == conn) {
|
||||||
peripheral_input_slots[i].conn = NULL;
|
peripheral_input_slots[i].conn = NULL;
|
||||||
// memset(&peripheral_input_slots[i], 0, sizeof(struct peripheral_input_slot));
|
zmk_input_split_peripheral_disconnected(peripheral_input_slots[i].reg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
|
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
|
||||||
|
s/^d_00: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}.*zmk_hid_mouse_button_/mouse button /p
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
, <INPUT_EV_REL INPUT_REL_Y 100 1>
|
, <INPUT_EV_REL INPUT_REL_Y 100 1>
|
||||||
, <INPUT_EV_REL INPUT_REL_X 40 0>
|
, <INPUT_EV_REL INPUT_REL_X 40 0>
|
||||||
, <INPUT_EV_REL INPUT_REL_Y 50 1>
|
, <INPUT_EV_REL INPUT_REL_Y 50 1>
|
||||||
|
, <INPUT_EV_KEY INPUT_BTN_1 1 1>
|
||||||
;
|
;
|
||||||
exit-after;
|
exit-after;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,3 +24,12 @@ profile 0 <dbg> ble_central: notify_func: payload
|
|||||||
profile 0 00 64 00 64 00 00 00 00 00 |.d.d.... .
|
profile 0 00 64 00 64 00 00 00 00 00 |.d.d.... .
|
||||||
profile 0 <dbg> ble_central: notify_func: payload
|
profile 0 <dbg> ble_central: notify_func: payload
|
||||||
profile 0 00 28 00 32 00 00 00 00 00 |.(.2.... .
|
profile 0 00 28 00 32 00 00 00 00 00 |.(.2.... .
|
||||||
|
mouse button press: Button 1 count 1
|
||||||
|
mouse button press: Mouse buttons set to 0x02
|
||||||
|
profile 0 <dbg> ble_central: notify_func: payload
|
||||||
|
profile 0 02 00 00 00 00 00 00 00 00 |........ .
|
||||||
|
mouse button release: Button 1 count: 0
|
||||||
|
mouse button release: Button 1 released
|
||||||
|
mouse button release: Mouse buttons set to 0x00
|
||||||
|
profile 0 <dbg> ble_central: notify_func: payload
|
||||||
|
profile 0 00 00 00 00 00 00 00 00 00 |........ .
|
||||||
|
|||||||
Reference in New Issue
Block a user