Commit 82d1f256 authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz

Remove released and cancelled key events

parent e7ba2a0e
/*
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
......@@ -61,31 +61,25 @@ struct _EekGtkKeyboardPrivate
{
EekRenderer *renderer;
EekKeyboard *keyboard;
gulong key_pressed_handler;
gulong key_released_handler;
gulong key_locked_handler;
gulong key_unlocked_handler;
gulong key_cancelled_handler;
gulong symbol_index_changed_handler;
EekTheme *theme;
};
static EekColor * color_from_gdk_color (GdkColor *gdk_color);
static void on_key_pressed (EekKeyboard *keyboard,
EekKey *key, guint32 timestamp,
static void on_key_pressed (EekKey *key,
EekGtkKeyboard *self);
static void on_key_released (EekKey *key,
EekGtkKeyboard *self);
static void on_key_released (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data);
static void on_key_locked (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data);
static void on_key_unlocked (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data);
static void on_key_cancelled (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data);
static void on_key_cancelled (EekKey *key,
EekGtkKeyboard *self);
static void on_symbol_index_changed (EekKeyboard *keyboard,
gint group,
gint level,
......@@ -211,11 +205,12 @@ eek_gtk_keyboard_real_button_press_event (GtkWidget *self,
(gdouble)event->y);
if (key) {
eek_keyboard_press_key(priv->keyboard, key, event->time);
on_key_pressed(priv->keyboard, key, event->time, EEK_GTK_KEYBOARD(self));
on_key_pressed(key, EEK_GTK_KEYBOARD(self));
}
return TRUE;
}
// TODO: this belongs more in gtk_keyboard, with a way to find out which key to re-render
static gboolean
eek_gtk_keyboard_real_button_release_event (GtkWidget *self,
GdkEventButton *event)
......@@ -225,12 +220,12 @@ eek_gtk_keyboard_real_button_release_event (GtkWidget *self,
return TRUE;
}
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
GList *list, *head;
list = eek_keyboard_get_pressed_keys (priv->keyboard);
for (head = list; head; head = g_list_next (head)) {
g_log("squeek", G_LOG_LEVEL_DEBUG, "emit EekKey released");
g_signal_emit_by_name (head->data, "released", priv->keyboard);
GList *list = eek_keyboard_get_pressed_keys (priv->keyboard);
for (GList *head = list; head; head = g_list_next (head)) {
EekKey *key = EEK_KEY(head->data);
eek_keyboard_release_key(priv->keyboard, key, event->time);
on_key_released(key, EEK_GTK_KEYBOARD(self));
}
g_list_free (list);
......@@ -325,18 +320,12 @@ eek_gtk_keyboard_set_keyboard (EekGtkKeyboard *self,
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
priv->keyboard = g_object_ref (keyboard);
priv->key_released_handler =
g_signal_connect (priv->keyboard, "key-released",
G_CALLBACK(on_key_released), self);
priv->key_locked_handler =
g_signal_connect (priv->keyboard, "key-locked",
G_CALLBACK(on_key_locked), self);
priv->key_unlocked_handler =
g_signal_connect (priv->keyboard, "key-unlocked",
G_CALLBACK(on_key_unlocked), self);
priv->key_cancelled_handler =
g_signal_connect (priv->keyboard, "key-cancelled",
G_CALLBACK(on_key_cancelled), self);
priv->symbol_index_changed_handler =
g_signal_connect (priv->keyboard, "symbol-index-changed",
G_CALLBACK(on_symbol_index_changed), self);
......@@ -372,14 +361,6 @@ eek_gtk_keyboard_dispose (GObject *object)
}
if (priv->keyboard) {
if (g_signal_handler_is_connected (priv->keyboard,
priv->key_pressed_handler))
g_signal_handler_disconnect (priv->keyboard,
priv->key_pressed_handler);
if (g_signal_handler_is_connected (priv->keyboard,
priv->key_released_handler))
g_signal_handler_disconnect (priv->keyboard,
priv->key_released_handler);
if (g_signal_handler_is_connected (priv->keyboard,
priv->key_locked_handler))
g_signal_handler_disconnect (priv->keyboard,
......@@ -388,15 +369,11 @@ eek_gtk_keyboard_dispose (GObject *object)
priv->key_unlocked_handler))
g_signal_handler_disconnect (priv->keyboard,
priv->key_unlocked_handler);
if (g_signal_handler_is_connected (priv->keyboard,
priv->key_cancelled_handler))
g_signal_handler_disconnect (priv->keyboard,
priv->key_cancelled_handler);
if (g_signal_handler_is_connected (priv->keyboard,
priv->symbol_index_changed_handler))
g_signal_handler_disconnect (priv->keyboard,
priv->symbol_index_changed_handler);
GList *list, *head;
list = eek_keyboard_get_pressed_keys (priv->keyboard);
......@@ -577,13 +554,9 @@ render_released_key (GtkWidget *widget,
}
static void
on_key_pressed (EekKeyboard *keyboard,
EekKey *key,
guint32 timestamp,
on_key_pressed (EekKey *key,
EekGtkKeyboard *self)
{
(void)keyboard;
(void)timestamp;
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
/* renderer may have not been set yet if the widget is a popup */
......@@ -602,18 +575,16 @@ on_key_pressed (EekKeyboard *keyboard,
}
static void
on_key_released (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
on_key_released (EekKey *key,
EekGtkKeyboard *self)
{
GtkWidget *widget = user_data;
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(widget);
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
/* renderer may have not been set yet if the widget is a popup */
if (!priv->renderer)
return;
render_released_key (widget, key);
render_released_key (GTK_WIDGET(self), key);
#if HAVE_LIBCANBERRA
ca_gtk_play_for_widget (widget, 0,
......@@ -625,18 +596,16 @@ on_key_released (EekKeyboard *keyboard,
}
static void
on_key_cancelled (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
on_key_cancelled (EekKey *key,
EekGtkKeyboard *self)
{
GtkWidget *widget = user_data;
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(widget);
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
/* renderer may have not been set yet if the widget is a popup */
if (!priv->renderer)
return;
render_released_key (widget, key);
render_released_key (self, key);
}
static void
......
......@@ -47,7 +47,6 @@ enum {
};
enum {
RELEASED,
LOCKED,
UNLOCKED,
CANCELLED,
......@@ -73,17 +72,6 @@ struct _EekKeyPrivate
gboolean is_locked;
};
static void
eek_key_real_released (EekKey *self)
{
EekKeyPrivate *priv = EEK_KEY_GET_PRIVATE(self);
priv->is_pressed = FALSE;
#if DEBUG
g_debug ("released %X", eek_key_get_keycode (self));
#endif
}
static void
eek_key_real_locked (EekKey *self)
{
......@@ -206,7 +194,6 @@ eek_key_class_init (EekKeyClass *klass)
gobject_class->finalize = eek_key_finalize;
/* signals */
klass->released = eek_key_real_released;
klass->locked = eek_key_real_locked;
klass->unlocked = eek_key_real_unlocked;
klass->cancelled = eek_key_real_cancelled;
......@@ -271,23 +258,6 @@ eek_key_class_init (EekKeyClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_OREF, pspec);
/**
* EekKey::released:
* @key: an #EekKey
*
* The ::released signal is emitted each time @key is shifted to
* the released state.
*/
signals[RELEASED] =
g_signal_new (I_("released"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekKeyClass, released),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* EekKey::locked:
* @key: an #EekKey
......
......@@ -74,7 +74,6 @@ struct _EekKeyClass
/*< public >*/
/* signals */
void (* released) (EekKey *key);
void (* locked) (EekKey *key);
void (* unlocked) (EekKey *key);
void (* cancelled) (EekKey *key);
......
......@@ -50,7 +50,6 @@ enum {
KEY_RELEASED,
KEY_LOCKED,
KEY_UNLOCKED,
KEY_CANCELLED,
LAST_SIGNAL
};
......@@ -92,15 +91,6 @@ eek_modifier_key_free (EekModifierKey *modkey)
g_slice_free (EekModifierKey, modkey);
}
static void
on_key_released (EekSection *section,
EekKey *key,
EekKeyboard *keyboard)
{
g_log("squeek", G_LOG_LEVEL_DEBUG, "emit EekKeyboard key-released");
g_signal_emit (keyboard, signals[KEY_RELEASED], 0, key);
}
static void
on_key_locked (EekSection *section,
EekKey *key,
......@@ -117,14 +107,6 @@ on_key_unlocked (EekSection *section,
g_signal_emit (keyboard, signals[KEY_UNLOCKED], 0, key);
}
static void
on_key_cancelled (EekSection *section,
EekKey *key,
EekKeyboard *keyboard)
{
g_signal_emit (keyboard, signals[KEY_CANCELLED], 0, key);
}
static void
on_symbol_index_changed (EekSection *section,
gint group,
......@@ -278,7 +260,7 @@ void eek_keyboard_press_key(EekKeyboard *keyboard, EekKey *key, guint32 timestam
EekModifierType modifier;
eek_key_set_pressed(key, TRUE);
key = EEK_KEY(key);
priv->pressed_keys = g_list_prepend (priv->pressed_keys, key);
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
......@@ -302,53 +284,55 @@ void eek_keyboard_press_key(EekKeyboard *keyboard, EekKey *key, guint32 timestam
emit_key_activated(&ec, keycode, symbol, modifiers, &c, TRUE, timestamp);
}
static void
eek_keyboard_real_key_released (EekKeyboard *self,
EekKey *key)
{
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(self);
EekSymbol *symbol;
EekModifierType modifier;
void eek_keyboard_release_key( EekKeyboard *keyboard,
EekKey *key,
guint32 timestamp) {
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(keyboard);
EEK_KEYBOARD_GET_CLASS (self)->key_cancelled (self, key);
for (GList *head = priv->pressed_keys; head; head = g_list_next (head)) {
if (head->data == key) {
priv->pressed_keys = g_list_remove_link (priv->pressed_keys, head);
g_list_free1 (head);
break;
}
}
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
return;
EekModifierType modifier = eek_symbol_get_modifier_mask (symbol);
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
return;
modifier = eek_symbol_get_modifier_mask (symbol);
switch (priv->modifier_behavior) {
case EEK_MODIFIER_BEHAVIOR_NONE:
set_modifiers_with_key (self, key, priv->modifiers & ~modifier);
set_modifiers_with_key (keyboard, key, priv->modifiers & ~modifier);
break;
case EEK_MODIFIER_BEHAVIOR_LOCK:
priv->modifiers ^= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LATCH:
if (modifier)
set_modifiers_with_key (self, key, priv->modifiers ^ modifier);
set_modifiers_with_key (keyboard, key, priv->modifiers ^ modifier);
else
set_modifiers_with_key (self, key,
set_modifiers_with_key (keyboard, key,
(priv->modifiers ^ modifier) & modifier);
break;
}
set_level_from_modifiers (self);
}
set_level_from_modifiers (keyboard);
static void
eek_keyboard_real_key_cancelled (EekKeyboard *self,
EekKey *key)
{
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(self);
GList *head;
// "Borrowed" from eek-context-service; doesn't influence the state but forwards the event
for (head = priv->pressed_keys; head; head = g_list_next (head)) {
if (head->data == key) {
priv->pressed_keys = g_list_remove_link (priv->pressed_keys, head);
g_list_free1 (head);
break;
}
}
guint keycode = eek_key_get_keycode (key);
guint modifiers = eek_keyboard_get_modifiers (keyboard);
// Insert
EekboardContext ec = {0};
Client c = {&ec, 0, {0}};
emit_key_activated(&ec, keycode, symbol, modifiers, &c, FALSE, timestamp);
}
static void
......@@ -392,14 +376,10 @@ static void
eek_keyboard_real_child_added (EekContainer *self,
EekElement *element)
{
g_signal_connect (element, "key-released",
G_CALLBACK(on_key_released), self);
g_signal_connect (element, "key-locked",
G_CALLBACK(on_key_locked), self);
g_signal_connect (element, "key-unlocked",
G_CALLBACK(on_key_unlocked), self);
g_signal_connect (element, "key-cancelled",
G_CALLBACK(on_key_cancelled), self);
g_signal_connect (element, "symbol-index-changed",
G_CALLBACK(on_symbol_index_changed), self);
}
......@@ -408,10 +388,8 @@ static void
eek_keyboard_real_child_removed (EekContainer *self,
EekElement *element)
{
g_signal_handlers_disconnect_by_func (element, on_key_released, self);
g_signal_handlers_disconnect_by_func (element, on_key_locked, self);
g_signal_handlers_disconnect_by_func (element, on_key_unlocked, self);
g_signal_handlers_disconnect_by_func (element, on_key_cancelled, self);
}
static void
......@@ -427,9 +405,6 @@ eek_keyboard_class_init (EekKeyboardClass *klass)
klass->create_section = eek_keyboard_real_create_section;
/* signals */
klass->key_released = eek_keyboard_real_key_released;
klass->key_cancelled = eek_keyboard_real_key_cancelled;
container_class->child_added = eek_keyboard_real_child_added;
container_class->child_removed = eek_keyboard_real_child_removed;
......@@ -467,26 +442,6 @@ eek_keyboard_class_init (EekKeyboardClass *klass)
PROP_MODIFIER_BEHAVIOR,
pspec);
/**
* EekKeyboard::key-released:
* @keyboard: an #EekKeyboard
* @key: an #EekKey
*
* The ::key-released signal is emitted each time a key in @keyboard
* is shifted to the released state.
*/
signals[KEY_RELEASED] =
g_signal_new (I_("key-released"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekKeyboardClass, key_released),
NULL,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
/**
* EekKeyboard::key-locked:
* @keyboard: an #EekKeyboard
......@@ -526,26 +481,6 @@ eek_keyboard_class_init (EekKeyboardClass *klass)
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
/**
* EekKeyboard::key-cancelled:
* @keyboard: an #EekKeyboard
* @key: an #EekKey
*
* The ::key-cancelled signal is emitted each time a key in @keyboard
* is shifted to the cancelled state.
*/
signals[KEY_CANCELLED] =
g_signal_new (I_("key-cancelled"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekKeyboardClass, key_cancelled),
NULL,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
}
static void
......
......@@ -84,10 +84,6 @@ struct _EekKeyboardClass
EekKey *(* find_key_by_keycode) (EekKeyboard *self,
guint keycode);
/* signals */
void (* key_released) (EekKeyboard *self,
EekKey *key);
/*< private >*/
/* obsolete members moved to EekElement */
gpointer symbol_index_changed;
......@@ -98,8 +94,6 @@ struct _EekKeyboardClass
EekKey *key);
void (* key_unlocked) (EekKeyboard *self,
EekKey *key);
void (* key_cancelled) (EekKeyboard *self,
EekKey *key);
/*< private >*/
/* padding */
......@@ -189,6 +183,7 @@ void eek_modifier_key_free
(EekModifierKey *modkey);
void eek_keyboard_press_key(EekKeyboard *keyboard, EekKey *key, guint32 timestamp);
void eek_keyboard_release_key(EekKeyboard *keyboard, EekKey *key, guint32 timestamp);
G_END_DECLS
#endif /* EEK_KEYBOARD_H */
......@@ -45,11 +45,8 @@ enum {
};
enum {
KEY_PRESSED,
KEY_RELEASED,
KEY_LOCKED,
KEY_UNLOCKED,
KEY_CANCELLED,
LAST_SIGNAL
};
......@@ -114,14 +111,6 @@ eek_section_real_get_row (EekSection *self,
*orientation = row->orientation;
}
static void
on_released (EekKey *key,
EekSection *section)
{
g_log("squeek", G_LOG_LEVEL_DEBUG, "emit EekSection key-released");
g_signal_emit (section, signals[KEY_RELEASED], 0, key);
}
static void
on_locked (EekKey *key,
EekSection *section)
......@@ -136,13 +125,6 @@ on_unlocked (EekKey *key,
g_signal_emit (section, signals[KEY_UNLOCKED], 0, key);
}
static void
on_cancelled (EekKey *key,
EekSection *section)
{
g_signal_emit (section, signals[KEY_CANCELLED], 0, key);
}
static EekKey *
eek_section_real_create_key (EekSection *self,
guint keycode,
......@@ -290,20 +272,16 @@ static void
eek_section_real_child_added (EekContainer *self,
EekElement *element)
{
g_signal_connect (element, "released", G_CALLBACK(on_released), self);
g_signal_connect (element, "locked", G_CALLBACK(on_locked), self);
g_signal_connect (element, "unlocked", G_CALLBACK(on_unlocked), self);
g_signal_connect (element, "cancelled", G_CALLBACK(on_cancelled), self);
}
static void
eek_section_real_child_removed (EekContainer *self,
EekElement *element)
{
g_signal_handlers_disconnect_by_func (element, on_released, self);
g_signal_handlers_disconnect_by_func (element, on_locked, self);
g_signal_handlers_disconnect_by_func (element, on_unlocked, self);
g_signal_handlers_disconnect_by_func (element, on_cancelled, self);
}
static void
......@@ -345,26 +323,6 @@ eek_section_class_init (EekSectionClass *klass)
PROP_ANGLE,
pspec);
/**
* EekSection::key-released:
* @section: an #EekSection
* @key: an #EekKey
*
* The ::key-released signal is emitted each time a key in @section
* is shifted to the released state.
*/
signals[KEY_RELEASED] =
g_signal_new (I_("key-released"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekSectionClass, key_released),
NULL,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
/**
* EekSection::key-locked:
* @section: an #EekSection
......@@ -404,26 +362,6 @@ eek_section_class_init (EekSectionClass *klass)
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
/**
* EekSection::key-cancelled:
* @section: an #EekSection
* @key: an #EekKey
*
* The ::key-cancelled signal is emitted each time a key in @section
* is shifted to the cancelled state.
*/
signals[KEY_CANCELLED] =
g_signal_new (I_("key-cancelled"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekSectionClass, key_cancelled),
NULL,
NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
EEK_TYPE_KEY);
}
static void
......
......@@ -700,58 +700,9 @@ on_repeat_timeout_init (EekboardContextService *context)
return FALSE;
}
static void
on_key_activated(EekKeyboard *keyboard,
EekKey *key,
EekboardContextService *context,
gboolean pressed)
{
guint keycode = eek_key_get_keycode (key);
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
guint modifiers = eek_keyboard_get_modifiers (context->priv->keyboard);
// Insert
EekboardContext ec = {0};
Client c = {&ec, 0, {0}};
emit_key_activated(&ec, keycode, symbol, modifiers, &c, pressed, 0);
}
static void
on_key_released (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
{
EekboardContextService *context = user_data;
if (context->priv->repeat_timeout_id > 0) {
g_source_remove (context->priv->repeat_timeout_id);
context->priv->repeat_timeout_id = 0;
}
on_key_activated(keyboard, key, context, FALSE);
}
static void
on_key_cancelled (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
{
on_key_released(keyboard, key, user_data);
// TODO: special handling when composing text via text-input? text may not be committed until button released
}
static void
connect_keyboard_signals (EekboardContextService *context)
{
context->priv->key_released_handler =
g_signal_connect (context->priv->keyboard, "key-released",
G_CALLBACK(on_key_released),
context);
context->priv->key_cancelled_handler =
g_signal_connect (context->priv->keyboard, "key-cancelled",
G_CALLBACK(on_key_cancelled),
context);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment