eekboard: react to key events by default.

This commit is contained in:
Daiki Ueno
2010-08-11 17:36:33 +09:00
parent 3d5160455a
commit 8bc7b754bc
4 changed files with 114 additions and 93 deletions

View File

@ -492,9 +492,9 @@ on_button_event (GtkWidget *widget,
GdkEventButton *event, GdkEventButton *event,
gpointer user_data) gpointer user_data)
{ {
EekGtkKeyboard *keyboard = EEK_GTK_KEYBOARD(user_data), *key; EekGtkKeyboard *keyboard = EEK_GTK_KEYBOARD(user_data);
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard); EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
EekBounds bounds; EekKey *key;
gdouble x, y; gdouble x, y;
x = (gdouble)event->x / priv->scale; x = (gdouble)event->x / priv->scale;
@ -503,7 +503,7 @@ on_button_event (GtkWidget *widget,
if (key) if (key)
switch (event->type) { switch (event->type) {
case GDK_BUTTON_PRESS: case GDK_BUTTON_PRESS:
press_key (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(key)); press_key (EEK_GTK_KEYBOARD(keyboard), key);
return TRUE; return TRUE;
case GDK_BUTTON_RELEASE: case GDK_BUTTON_RELEASE:
release_key (EEK_GTK_KEYBOARD(keyboard)); release_key (EEK_GTK_KEYBOARD(keyboard));

View File

@ -514,13 +514,15 @@ eek_keyboard_find_section_by_position (EekKeyboard *keyboard,
{ {
EekBounds bounds; EekBounds bounds;
EekPoint point; EekPoint point;
EekElement *element;
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds); eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
point.x = x - bounds.x; point.x = x - bounds.x;
point.y = y - bounds.y; point.y = y - bounds.y;
return eek_container_find (EEK_CONTAINER(keyboard), element = eek_container_find (EEK_CONTAINER(keyboard),
compare_section_by_position, compare_section_by_position,
&point); &point);
return EEK_SECTION(element);
} }
EekKey * EekKey *

View File

@ -85,7 +85,6 @@ eek_point_get_type (void)
void void
eek_point_rotate (EekPoint *point, gint angle) eek_point_rotate (EekPoint *point, gint angle)
{ {
EekPoint *p;
gdouble r, phi; gdouble r, phi;
phi = atan2 (point->y, point->x); phi = atan2 (point->y, point->x);

View File

@ -97,6 +97,7 @@ struct _Eekboard {
XklEngine *engine; XklEngine *engine;
XklConfigRegistry *registry; XklConfigRegistry *registry;
GtkUIManager *ui_manager; GtkUIManager *ui_manager;
gulong on_key_pressed_id, on_key_released_id;
guint countries_merge_id; guint countries_merge_id;
GtkActionGroup *countries_action_group; GtkActionGroup *countries_action_group;
@ -152,9 +153,6 @@ static void on_about (GtkAction *action,
GtkWidget *window); GtkWidget *window);
static void on_quit (GtkAction * action, static void on_quit (GtkAction * action,
GtkWidget *window); GtkWidget *window);
static void on_monitor_key_event_toggled
(GtkToggleAction *action,
GtkWidget *window);
static void eekboard_free (Eekboard *eekboard); static void eekboard_free (Eekboard *eekboard);
static GtkWidget *create_widget (Eekboard *eekboard, static GtkWidget *create_widget (Eekboard *eekboard,
gint initial_width, gint initial_width,
@ -174,7 +172,6 @@ static const char ui_description[] =
" <menuitem action='Quit'/>" " <menuitem action='Quit'/>"
" </menu>" " </menu>"
" <menu action='KeyboardMenu'>" " <menu action='KeyboardMenu'>"
" <menuitem action='MonitorKeyEvent'/>"
" <menu action='Country'>" " <menu action='Country'>"
" <placeholder name='CountriesPH'/>" " <placeholder name='CountriesPH'/>"
" </menu>" " </menu>"
@ -222,11 +219,6 @@ static const GtkActionEntry action_entry[] = {
{"About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK (on_about)} {"About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK (on_about)}
}; };
static const GtkToggleActionEntry toggle_action_entry[] = {
{"MonitorKeyEvent", NULL, N_("Monitor Key Typing"), NULL, NULL,
G_CALLBACK(on_monitor_key_event_toggled), FALSE}
};
static gchar *opt_model = NULL; static gchar *opt_model = NULL;
static gchar *opt_layouts = NULL; static gchar *opt_layouts = NULL;
static gchar *opt_options = NULL; static gchar *opt_options = NULL;
@ -349,6 +341,8 @@ a11y_focus_listener (const AccessibleEvent *event,
gtk_widget_hide (eekboard->window); gtk_widget_hide (eekboard->window);
eekboard->acc = NULL; eekboard->acc = NULL;
} }
default:
;
} }
} }
@ -361,47 +355,48 @@ a11y_keystroke_listener (const AccessibleKeystroke *stroke,
{ {
Eekboard *eekboard = user_data; Eekboard *eekboard = user_data;
EekKey *key; EekKey *key;
guint keysym;
//g_return_val_if_fail (stroke->modifiers == SPI_KEYMASK_UNMODIFIED, FALSE); guint ignored_keysyms[] = {XK_Shift_L,
XK_Shift_R,
XK_Control_L,
XK_Control_R,
XK_Alt_L,
XK_Alt_R};
gint i;
key = eek_keyboard_find_key_by_keycode (eekboard->keyboard, key = eek_keyboard_find_key_by_keycode (eekboard->keyboard,
stroke->keycode); stroke->keycode);
if (!key) if (!key)
return FALSE; return FALSE;
if (stroke->type == SPI_KEY_PRESSED)
/* XXX: Ignore modifier keys since there is no way to receive
SPI_KEY_RELEASED event for them. */
keysym = eek_key_get_keysym (key);
for (i = 0; i < G_N_ELEMENTS(ignored_keysyms) &&
keysym != ignored_keysyms[i]; i++)
;
if (i != G_N_ELEMENTS(ignored_keysyms))
return FALSE;
if (stroke->type == SPI_KEY_PRESSED) {
g_signal_handler_block (eekboard->keyboard,
eekboard->on_key_pressed_id);
g_signal_emit_by_name (key, "pressed"); g_signal_emit_by_name (key, "pressed");
else g_signal_handler_unblock (eekboard->keyboard,
eekboard->on_key_pressed_id);
} else {
g_signal_handler_block (eekboard->keyboard,
eekboard->on_key_released_id);
g_signal_emit_by_name (key, "released"); g_signal_emit_by_name (key, "released");
g_signal_handler_unblock (eekboard->keyboard,
eekboard->on_key_released_id);
}
return TRUE; return TRUE;
} }
static AccessibleEventListener* focusListener; static AccessibleEventListener* focusListener;
static AccessibleEventListener* keystrokeListener; static AccessibleEventListener* keystrokeListener;
static void
on_monitor_key_event_toggled (GtkToggleAction *action,
GtkWidget *window)
{
Eekboard *eekboard = g_object_get_data (G_OBJECT(window), "eekboard");
if (!keystrokeListener) {
keystrokeListener =
SPI_createAccessibleKeystrokeListener (a11y_keystroke_listener,
eekboard);
}
if (gtk_toggle_action_get_active (action)) {
if (!SPI_registerAccessibleKeystrokeListener (keystrokeListener,
SPI_KEYSET_ALL_KEYS,
0,
SPI_KEY_PRESSED |
SPI_KEY_RELEASED,
SPI_KEYLISTENER_NOSYNC))
g_warning ("failed to register keystroke listener");
} else
if (!SPI_deregisterAccessibleKeystrokeListener (keystrokeListener, 0))
g_warning ("failed to deregister keystroke listener");
}
static void static void
on_key_pressed (EekKeyboard *keyboard, on_key_pressed (EekKeyboard *keyboard,
EekKey *key, EekKey *key,
@ -957,9 +952,6 @@ create_menus (Eekboard *eekboard,
gtk_action_group_add_actions (action_group, action_entry, gtk_action_group_add_actions (action_group, action_entry,
G_N_ELEMENTS (action_entry), window); G_N_ELEMENTS (action_entry), window);
gtk_action_group_add_toggle_actions (action_group, toggle_action_entry,
G_N_ELEMENTS (toggle_action_entry),
window);
gtk_ui_manager_insert_action_group (eekboard->ui_manager, action_group, 0); gtk_ui_manager_insert_action_group (eekboard->ui_manager, action_group, 0);
gtk_ui_manager_add_ui_from_string (eekboard->ui_manager, ui_description, -1, NULL); gtk_ui_manager_add_ui_from_string (eekboard->ui_manager, ui_description, -1, NULL);
@ -1004,10 +996,12 @@ create_widget_gtk (Eekboard *eekboard,
eekboard->keyboard = eek_gtk_keyboard_new (); eekboard->keyboard = eek_gtk_keyboard_new ();
eek_keyboard_set_layout (eekboard->keyboard, eekboard->layout); eek_keyboard_set_layout (eekboard->keyboard, eekboard->layout);
eek_element_set_bounds (EEK_ELEMENT(eekboard->keyboard), &bounds); eek_element_set_bounds (EEK_ELEMENT(eekboard->keyboard), &bounds);
g_signal_connect (eekboard->keyboard, "key-pressed", eekboard->on_key_pressed_id =
G_CALLBACK(on_key_pressed), eekboard); g_signal_connect (eekboard->keyboard, "key-pressed",
g_signal_connect (eekboard->keyboard, "key-released", G_CALLBACK(on_key_pressed), eekboard);
G_CALLBACK(on_key_released), eekboard); eekboard->on_key_released_id =
g_signal_connect (eekboard->keyboard, "key-released",
G_CALLBACK(on_key_released), eekboard);
eekboard->widget = eekboard->widget =
eek_gtk_keyboard_get_widget (EEK_GTK_KEYBOARD (eekboard->keyboard)); eek_gtk_keyboard_get_widget (EEK_GTK_KEYBOARD (eekboard->keyboard));
@ -1054,10 +1048,12 @@ create_widget_clutter (Eekboard *eekboard,
eekboard->keyboard = eek_clutter_keyboard_new (); eekboard->keyboard = eek_clutter_keyboard_new ();
eek_keyboard_set_layout (eekboard->keyboard, eekboard->layout); eek_keyboard_set_layout (eekboard->keyboard, eekboard->layout);
eek_element_set_bounds (EEK_ELEMENT(eekboard->keyboard), &bounds); eek_element_set_bounds (EEK_ELEMENT(eekboard->keyboard), &bounds);
g_signal_connect (eekboard->keyboard, "key-pressed", eekboard->on_key_pressed_id =
G_CALLBACK(on_key_pressed), eekboard); g_signal_connect (eekboard->keyboard, "key-pressed",
g_signal_connect (eekboard->keyboard, "key-released", G_CALLBACK(on_key_pressed), eekboard);
G_CALLBACK(on_key_released), eekboard); eekboard->on_key_released_id =
g_signal_connect (eekboard->keyboard, "key-released",
G_CALLBACK(on_key_released), eekboard);
eekboard->widget = gtk_clutter_embed_new (); eekboard->widget = gtk_clutter_embed_new ();
#if NEED_SWAP_EVENT_WORKAROUND #if NEED_SWAP_EVENT_WORKAROUND
@ -1274,24 +1270,28 @@ on_layout_changed (GtkComboBox *combo,
if (config_base->model) if (config_base->model)
config->model = g_strdup (config_base->model); config->model = g_strdup (config_base->model);
else else
config->model = eek_xkl_layout_get_model (eekboard->layout); config->model =
eek_xkl_layout_get_model (EEK_XKL_LAYOUT(eekboard->layout));
if (config_base->layouts) if (config_base->layouts)
config->layouts = g_strdupv (config_base->layouts); config->layouts = g_strdupv (config_base->layouts);
else else
config->layouts = eek_xkl_layout_get_layouts (eekboard->layout); config->layouts =
eek_xkl_layout_get_layouts (EEK_XKL_LAYOUT(eekboard->layout));
if (config_base->variants) if (config_base->variants)
config->variants = g_strdupv (config_base->variants); config->variants = g_strdupv (config_base->variants);
else else
config->variants = eek_xkl_layout_get_variants (eekboard->layout); config->variants =
eek_xkl_layout_get_variants (EEK_XKL_LAYOUT(eekboard->layout));
if (config_base->options) if (config_base->options)
config->options = g_strdupv (config_base->options); config->options = g_strdupv (config_base->options);
else else
config->options = eek_xkl_layout_get_options (eekboard->layout); config->options =
eek_xkl_layout_get_options (EEK_XKL_LAYOUT(eekboard->layout));
eek_xkl_layout_set_config (eekboard->layout, config); eek_xkl_layout_set_config (EEK_XKL_LAYOUT(eekboard->layout), config);
g_object_unref (config); g_object_unref (config);
eekboard->active_config = active; eekboard->active_config = active;
@ -1505,7 +1505,8 @@ main (int argc, char *argv[])
gssize len; gssize len;
error = NULL; error = NULL;
len = g_input_stream_read (stream, buf, sizeof buf, NULL, len = g_input_stream_read (G_INPUT_STREAM(stream),
buf, sizeof buf, NULL,
&error); &error);
if (len <= 0) if (len <= 0)
break; break;
@ -1585,46 +1586,65 @@ main (int argc, char *argv[])
notify_init ("eekboard"); notify_init ("eekboard");
eekboard->window = window; eekboard->window = window;
eekboard->gconfc = gconfc; eekboard->gconfc = gconfc;
if (!opt_standalone && eekboard->accessibility_enabled) { if (eekboard->accessibility_enabled) {
NotifyNotification *notification; if (!opt_standalone) {
NotifyNotification *notification;
error = NULL;
if (!gconf_client_get_bool (eekboard->gconfc,
"/apps/eekboard/inhibit-startup-notify",
&error)) {
notification = notify_notification_new
("eekboard started in background",
"As GNOME accessibility support enabled, "
"eekboard is starting without a window.\n"
"To make eekboard show up, click on some window with "
"an editable widget.",
"keyboard",
NULL);
notify_notification_add_action
(notification,
"dont-ask",
"Don't show up",
NOTIFY_ACTION_CALLBACK(on_notify_never_show),
eekboard,
NULL);
error = NULL; error = NULL;
notify_notification_show (notification, &error); if (!gconf_client_get_bool (eekboard->gconfc,
} "/apps/eekboard/inhibit-startup-notify",
&error)) {
notification = notify_notification_new
("eekboard started in background",
"As GNOME accessibility support enabled, "
"eekboard is starting without a window.\n"
"To make eekboard show up, click on some window with "
"an editable widget.",
"keyboard",
NULL);
notify_notification_add_action
(notification,
"dont-ask",
"Don't show up",
NOTIFY_ACTION_CALLBACK(on_notify_never_show),
eekboard,
NULL);
error = NULL;
notify_notification_show (notification, &error);
}
gtk_widget_hide (window); gtk_widget_hide (window);
focusListener = SPI_createAccessibleEventListener (a11y_focus_listener, focusListener =
eekboard); SPI_createAccessibleEventListener (a11y_focus_listener,
SPI_registerGlobalEventListener (focusListener, eekboard);
"object:state-changed:focused"); SPI_registerGlobalEventListener (focusListener,
SPI_registerGlobalEventListener (focusListener, "object:state-changed:focused");
"focus:"); SPI_registerGlobalEventListener (focusListener,
"focus:");
}
/* monitor key events */
if (!keystrokeListener) {
keystrokeListener =
SPI_createAccessibleKeystrokeListener (a11y_keystroke_listener,
eekboard);
}
if (!SPI_registerAccessibleKeystrokeListener
(keystrokeListener,
SPI_KEYSET_ALL_KEYS,
0,
SPI_KEY_PRESSED |
SPI_KEY_RELEASED,
SPI_KEYLISTENER_NOSYNC))
g_warning ("failed to register keystroke listener");
} }
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
if (combo) if (combo)
gtk_combo_box_set_active (combo, 0); gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0);
gtk_main (); gtk_main ();