presses: Move press handling to Rust
This fixes some rendering things which would happen with multiple state-sharing buttons. It also removes some interfaces exposing rows, views, layouts, and buttons, bringing the code closer to removing them from the FFI entirely.
This commit is contained in:
@ -38,65 +38,6 @@
|
||||
|
||||
#include "eek-keyboard.h"
|
||||
|
||||
void
|
||||
eek_keyboard_set_key_locked (LevelKeyboard *keyboard,
|
||||
struct squeek_key *key)
|
||||
{
|
||||
keyboard->locked_keys =
|
||||
g_list_prepend (keyboard->locked_keys, key);
|
||||
}
|
||||
|
||||
/// Unlock all locked keys.
|
||||
/// All locked keys will unlock at the next keypress (should be called "stuck")
|
||||
/// Returns the number of handled keys
|
||||
/// TODO: may need to check key type in order to chain locks
|
||||
/// before pressing an "emitting" key
|
||||
static int unlock_keys(LevelKeyboard *keyboard) {
|
||||
int handled = 0;
|
||||
for (GList *head = keyboard->locked_keys; head; ) {
|
||||
struct squeek_key *key = head->data;
|
||||
GList *next = g_list_next (head);
|
||||
keyboard->locked_keys =
|
||||
g_list_remove_link (keyboard->locked_keys, head);
|
||||
|
||||
squeek_layout_set_state_from_press(keyboard->layout, keyboard, key);
|
||||
g_list_free1 (head);
|
||||
head = next;
|
||||
handled++;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
static void
|
||||
set_level_from_press (LevelKeyboard *keyboard, struct squeek_key *key)
|
||||
{
|
||||
// If the currently locked key was already handled in the unlock phase,
|
||||
// then skip
|
||||
if (unlock_keys(keyboard) == 0) {
|
||||
squeek_layout_set_state_from_press(keyboard->layout, keyboard, key);
|
||||
}
|
||||
}
|
||||
|
||||
void eek_keyboard_press_key(LevelKeyboard *keyboard, struct squeek_key *key, guint32 timestamp) {
|
||||
keyboard->pressed_keys = g_list_prepend (keyboard->pressed_keys, key);
|
||||
squeek_key_press(key, keyboard->manager->virtual_keyboard, KEY_PRESS, timestamp);
|
||||
}
|
||||
|
||||
void eek_keyboard_release_key(LevelKeyboard *keyboard,
|
||||
struct squeek_key *key,
|
||||
guint32 timestamp) {
|
||||
for (GList *head = keyboard->pressed_keys; head; head = g_list_next (head)) {
|
||||
if (squeek_key_equal(head->data, key)) {
|
||||
keyboard->pressed_keys = g_list_remove_link (keyboard->pressed_keys, head);
|
||||
g_list_free1 (head);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_level_from_press (keyboard, key);
|
||||
squeek_key_press(key, keyboard->manager->virtual_keyboard, KEY_RELEASE, timestamp);
|
||||
}
|
||||
|
||||
void level_keyboard_deinit(LevelKeyboard *self) {
|
||||
squeek_layout_free(self->layout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user