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 */ /* redraw locked key */
list = priv->keyboard->locked_buttons; list = priv->keyboard->locked_keys;
for (const GList *head = list; head; head = g_list_next (head)) { for (const GList *head = list; head; head = g_list_next (head)) {
struct button_place place = squeek_view_find_key( struct button_place place = squeek_view_find_key(
view, squeek_button_get_key( view, ((EekModifierKey *)head->data)->key
((EekModifierKey *)head->data)->button
)
); );
if (place.button) if (place.button)
render_locked_button (self, &place); render_locked_button (self, &place);

View File

@ -50,14 +50,14 @@ eek_modifier_key_free (EekModifierKey *modkey)
} }
void void
eek_keyboard_set_button_locked (LevelKeyboard *keyboard, eek_keyboard_set_key_locked (LevelKeyboard *keyboard,
struct squeek_button *button) struct squeek_key *key)
{ {
EekModifierKey *modifier_key = g_slice_new (EekModifierKey); EekModifierKey *modifier_key = g_slice_new (EekModifierKey);
modifier_key->modifiers = 0; modifier_key->modifiers = 0;
modifier_key->button = button; modifier_key->key = key;
keyboard->locked_buttons = keyboard->locked_keys =
g_list_prepend (keyboard->locked_buttons, modifier_key); g_list_prepend (keyboard->locked_keys, modifier_key);
} }
/// Unlock all locked keys. /// Unlock all locked keys.
@ -67,14 +67,14 @@ eek_keyboard_set_button_locked (LevelKeyboard *keyboard,
/// before pressing an "emitting" key /// before pressing an "emitting" key
static int unlock_keys(LevelKeyboard *keyboard) { static int unlock_keys(LevelKeyboard *keyboard) {
int handled = 0; int handled = 0;
for (GList *head = keyboard->locked_buttons; head; ) { for (GList *head = keyboard->locked_keys; head; ) {
EekModifierKey *modifier_key = head->data; EekModifierKey *modifier_key = head->data;
GList *next = g_list_next (head); GList *next = g_list_next (head);
keyboard->locked_buttons = keyboard->locked_keys =
g_list_remove_link (keyboard->locked_buttons, head); g_list_remove_link (keyboard->locked_keys, head);
//squeek_key_set_locked(squeek_button_get_key(modifier_key->button), false); //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); g_list_free1 (head);
head = next; head = next;
handled++; handled++;
@ -83,12 +83,12 @@ static int unlock_keys(LevelKeyboard *keyboard) {
} }
static void 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, // If the currently locked key was already handled in the unlock phase,
// then skip // then skip
if (unlock_keys(keyboard) == 0) { 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 // "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); emit_key_activated(keyboard->manager, keyboard, keycode, FALSE, timestamp);
} }

View File

@ -36,7 +36,7 @@ G_BEGIN_DECLS
struct _EekModifierKey { struct _EekModifierKey {
/*< public >*/ /*< public >*/
EekModifierType modifiers; EekModifierType modifiers;
struct squeek_button *button; struct squeek_key *key;
}; };
typedef struct _EekModifierKey EekModifierKey; typedef struct _EekModifierKey EekModifierKey;
@ -48,7 +48,7 @@ struct _LevelKeyboard {
size_t keymap_len; // length of the data inside keymap_fd size_t keymap_len; // length of the data inside keymap_fd
GList *pressed_buttons; // struct squeek_button* 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 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 void
squeek_layout_place_contents(struct squeek_layout*); squeek_layout_place_contents(struct squeek_layout*);
struct squeek_view *squeek_layout_get_current_view(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); struct squeek_layout *squeek_load_layout(const char *type);

View File

@ -262,9 +262,9 @@ pub mod c {
angle: i32 angle: i32
) -> u32; ) -> u32;
pub fn eek_keyboard_set_button_locked( pub fn eek_keyboard_set_key_locked(
keyboard: *mut LevelKeyboard, keyboard: *mut LevelKeyboard,
button: *const Button key: ::keyboard::c::CKeyState,
); );
} }
@ -273,32 +273,32 @@ pub mod c {
fn squeek_layout_set_state_from_press( fn squeek_layout_set_state_from_press(
layout: *mut Layout, layout: *mut Layout,
keyboard: *mut LevelKeyboard, keyboard: *mut LevelKeyboard,
button_ptr: *const Button, key: ::keyboard::c::CKeyState,
) { ) {
let layout = unsafe { &mut *layout }; 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) => { ::symbol::Action::SetLevel(name) => {
Some(name.clone()) Some(name.clone())
}, },
::symbol::Action::LockLevel { lock, unlock } => { ::symbol::Action::LockLevel { lock, unlock } => {
let mut current_state = button.state.borrow_mut(); let locked = {
current_state.locked ^= true; let key = key.clone_ref();
if current_state.locked { let mut key = key.borrow_mut();
key.locked ^= true;
key.locked
};
if locked {
unsafe { unsafe {
eek_keyboard_set_button_locked( eek_keyboard_set_key_locked(
keyboard, keyboard,
button_ptr key
) )
}; }
} }
Some(if state.locked { unlock } else { lock }.clone())
Some(if locked { lock } else { unlock }.clone())
}, },
_ => None, _ => None,
}; };