2021-12-26 23:29:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2021-12-21 22:25:59 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
2023-11-14 18:57:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2021-12-21 22:25:59 +00:00
|
|
|
#include <string.h>
|
2023-11-14 18:57:22 +00:00
|
|
|
#include <wlr/util/log.h>
|
2024-10-07 09:15:34 +09:00
|
|
|
#include "common/set.h"
|
2023-09-03 17:39:48 +02:00
|
|
|
#include "input/key-state.h"
|
2021-12-21 22:25:59 +00:00
|
|
|
|
2024-12-23 00:05:22 +09:00
|
|
|
static struct lab_set pressed, bound, pressed_sent;
|
2021-12-21 22:25:59 +00:00
|
|
|
|
2023-11-14 18:57:22 +00:00
|
|
|
static void
|
2024-10-07 09:15:34 +09:00
|
|
|
report(struct lab_set *key_set, const char *msg)
|
2023-11-14 18:57:22 +00:00
|
|
|
{
|
|
|
|
|
static char *should_print;
|
|
|
|
|
static bool has_run;
|
|
|
|
|
|
|
|
|
|
if (!has_run) {
|
|
|
|
|
should_print = getenv("LABWC_DEBUG_KEY_STATE");
|
|
|
|
|
has_run = true;
|
|
|
|
|
}
|
|
|
|
|
if (!should_print) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("%s", msg);
|
2024-10-07 09:15:34 +09:00
|
|
|
for (int i = 0; i < key_set->size; ++i) {
|
|
|
|
|
printf("%d,", key_set->values[i]);
|
2023-11-14 18:57:22 +00:00
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 20:46:39 +01:00
|
|
|
uint32_t *
|
|
|
|
|
key_state_pressed_sent_keycodes(void)
|
|
|
|
|
{
|
2023-11-14 18:57:22 +00:00
|
|
|
report(&pressed, "before - pressed:");
|
|
|
|
|
report(&bound, "before - bound:");
|
|
|
|
|
|
2022-09-20 20:46:39 +01:00
|
|
|
/* pressed_sent = pressed - bound */
|
2023-11-10 23:44:41 -05:00
|
|
|
pressed_sent = pressed;
|
2024-10-07 09:15:34 +09:00
|
|
|
for (int i = 0; i < bound.size; ++i) {
|
|
|
|
|
lab_set_remove(&pressed_sent, bound.values[i]);
|
2022-09-20 20:46:39 +01:00
|
|
|
}
|
2023-11-14 18:57:22 +00:00
|
|
|
|
|
|
|
|
report(&pressed_sent, "after - pressed_sent:");
|
|
|
|
|
|
2024-10-07 09:15:34 +09:00
|
|
|
return pressed_sent.values;
|
2022-09-20 20:46:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
key_state_nr_pressed_sent_keycodes(void)
|
|
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
return pressed_sent.size;
|
2022-09-20 20:46:39 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-21 22:25:59 +00:00
|
|
|
void
|
2024-12-23 00:05:22 +09:00
|
|
|
key_state_set_pressed(uint32_t keycode, bool is_pressed)
|
2021-12-21 22:25:59 +00:00
|
|
|
{
|
2023-11-10 23:43:46 -05:00
|
|
|
if (is_pressed) {
|
2024-10-07 09:15:34 +09:00
|
|
|
lab_set_add(&pressed, keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
} else {
|
2024-10-07 09:15:34 +09:00
|
|
|
lab_set_remove(&pressed, keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-11-04 01:23:43 -04:00
|
|
|
key_state_store_pressed_key_as_bound(uint32_t keycode)
|
2021-12-21 22:25:59 +00:00
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
lab_set_add(&bound, keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
key_state_corresponding_press_event_was_bound(uint32_t keycode)
|
|
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
return lab_set_contains(&bound, keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 17:05:08 +01:00
|
|
|
void
|
2021-12-21 22:25:59 +00:00
|
|
|
key_state_bound_key_remove(uint32_t keycode)
|
|
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
lab_set_remove(&bound, keycode);
|
2021-12-21 22:25:59 +00:00
|
|
|
}
|
2022-08-30 15:47:00 +01:00
|
|
|
|
|
|
|
|
int
|
2023-09-30 09:19:59 +01:00
|
|
|
key_state_nr_bound_keys(void)
|
2022-08-30 15:47:00 +01:00
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
return bound.size;
|
2022-08-30 15:47:00 +01:00
|
|
|
}
|
2023-09-26 17:51:54 +01:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
key_state_nr_pressed_keys(void)
|
|
|
|
|
{
|
2024-10-07 09:15:34 +09:00
|
|
|
return pressed.size;
|
2023-09-26 17:51:54 +01:00
|
|
|
}
|