locked: Use keys instead of buttons

This commit is contained in:
Dorota Czaplejewicz
2019-09-09 13:54:55 +00:00
parent 6523275b6a
commit 0ed66e0eab
5 changed files with 37 additions and 37 deletions

View File

@ -121,12 +121,10 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
}
/* redraw locked key */
list = priv->keyboard->locked_buttons;
list = priv->keyboard->locked_keys;
for (const GList *head = list; head; head = g_list_next (head)) {
struct button_place place = squeek_view_find_key(
view, squeek_button_get_key(
((EekModifierKey *)head->data)->button
)
view, ((EekModifierKey *)head->data)->key
);
if (place.button)
render_locked_button (self, &place);

View File

@ -50,14 +50,14 @@ eek_modifier_key_free (EekModifierKey *modkey)
}
void
eek_keyboard_set_button_locked (LevelKeyboard *keyboard,
struct squeek_button *button)
eek_keyboard_set_key_locked (LevelKeyboard *keyboard,
struct squeek_key *key)
{
EekModifierKey *modifier_key = g_slice_new (EekModifierKey);
modifier_key->modifiers = 0;
modifier_key->button = button;
keyboard->locked_buttons =
g_list_prepend (keyboard->locked_buttons, modifier_key);
modifier_key->key = key;
keyboard->locked_keys =
g_list_prepend (keyboard->locked_keys, modifier_key);
}
/// Unlock all locked keys.
@ -67,14 +67,14 @@ eek_keyboard_set_button_locked (LevelKeyboard *keyboard,
/// before pressing an "emitting" key
static int unlock_keys(LevelKeyboard *keyboard) {
int handled = 0;
for (GList *head = keyboard->locked_buttons; head; ) {
for (GList *head = keyboard->locked_keys; head; ) {
EekModifierKey *modifier_key = head->data;
GList *next = g_list_next (head);
keyboard->locked_buttons =
g_list_remove_link (keyboard->locked_buttons, head);
keyboard->locked_keys =
g_list_remove_link (keyboard->locked_keys, head);
//squeek_key_set_locked(squeek_button_get_key(modifier_key->button), false);
squeek_layout_set_state_from_press(keyboard->layout, keyboard, modifier_key->button);
squeek_layout_set_state_from_press(keyboard->layout, keyboard, modifier_key->key);
g_list_free1 (head);
head = next;
handled++;
@ -83,12 +83,12 @@ static int unlock_keys(LevelKeyboard *keyboard) {
}
static void
set_level_from_press (LevelKeyboard *keyboard, struct squeek_button *button)
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, button);
squeek_layout_set_state_from_press(keyboard->layout, keyboard, key);
}
}
@ -118,11 +118,13 @@ void eek_keyboard_release_button(LevelKeyboard *keyboard,
}
}
set_level_from_press (keyboard, button);
struct squeek_key *key = squeek_button_get_key(button);
set_level_from_press (keyboard, key);
// "Borrowed" from eek-context-service; doesn't influence the state but forwards the event
guint keycode = squeek_key_get_keycode (squeek_button_get_key(button));
guint keycode = squeek_key_get_keycode (key);
emit_key_activated(keyboard->manager, keyboard, keycode, FALSE, timestamp);
}

View File

@ -36,7 +36,7 @@ G_BEGIN_DECLS
struct _EekModifierKey {
/*< public >*/
EekModifierType modifiers;
struct squeek_button *button;
struct squeek_key *key;
};
typedef struct _EekModifierKey EekModifierKey;
@ -48,7 +48,7 @@ struct _LevelKeyboard {
size_t keymap_len; // length of the data inside keymap_fd
GList *pressed_buttons; // struct squeek_button*
GList *locked_buttons; // struct squeek_button*
GList *locked_keys; // struct squeek_button*
guint id; // as a key to layout choices

View File

@ -55,7 +55,7 @@ struct squeek_button *squeek_view_find_button_by_position(struct squeek_view *vi
void
squeek_layout_place_contents(struct squeek_layout*);
struct squeek_view *squeek_layout_get_current_view(struct squeek_layout*);
void squeek_layout_set_state_from_press(struct squeek_layout* layout, LevelKeyboard *keyboard, struct squeek_button* button);
void squeek_layout_set_state_from_press(struct squeek_layout* layout, LevelKeyboard *keyboard, struct squeek_key* key);
struct squeek_layout *squeek_load_layout(const char *type);

View File

@ -262,9 +262,9 @@ pub mod c {
angle: i32
) -> u32;
pub fn eek_keyboard_set_button_locked(
pub fn eek_keyboard_set_key_locked(
keyboard: *mut LevelKeyboard,
button: *const Button
key: ::keyboard::c::CKeyState,
);
}
@ -273,32 +273,32 @@ pub mod c {
fn squeek_layout_set_state_from_press(
layout: *mut Layout,
keyboard: *mut LevelKeyboard,
button_ptr: *const Button,
key: ::keyboard::c::CKeyState,
) {
let layout = unsafe { &mut *layout };
let button = unsafe { &*button_ptr };
// don't want to leave this borrowed in the function body
let state = {
let state = button.state.borrow();
state.clone()
};
let view_name = match state.symbol.action {
let view_name = match key.to_owned().symbol.action {
::symbol::Action::SetLevel(name) => {
Some(name.clone())
},
::symbol::Action::LockLevel { lock, unlock } => {
let mut current_state = button.state.borrow_mut();
current_state.locked ^= true;
if current_state.locked {
unsafe {
eek_keyboard_set_button_locked(
keyboard,
button_ptr
)
let locked = {
let key = key.clone_ref();
let mut key = key.borrow_mut();
key.locked ^= true;
key.locked
};
if locked {
unsafe {
eek_keyboard_set_key_locked(
keyboard,
key
)
}
Some(if state.locked { unlock } else { lock }.clone())
}
Some(if locked { lock } else { unlock }.clone())
},
_ => None,
};