Implement "Monitor Key Typing" using AT-SPI C.
This commit is contained in:
@ -41,6 +41,8 @@ PKG_CHECK_MODULES([LIBXKLAVIER], [libxklavier x11], ,
|
|||||||
[AC_MSG_ERROR([Libxklavier not found])])
|
[AC_MSG_ERROR([Libxklavier not found])])
|
||||||
PKG_CHECK_MODULES([LIBFAKEKEY], [libfakekey], ,
|
PKG_CHECK_MODULES([LIBFAKEKEY], [libfakekey], ,
|
||||||
[AC_MSG_ERROR([libfakekey not found])])
|
[AC_MSG_ERROR([libfakekey not found])])
|
||||||
|
PKG_CHECK_MODULES([CSPI], [cspi-1.0], ,
|
||||||
|
[AC_MSG_ERROR([AT-SPI C not found])])
|
||||||
|
|
||||||
AC_MSG_CHECKING([whether you enable Vala language support])
|
AC_MSG_CHECKING([whether you enable Vala language support])
|
||||||
AC_ARG_ENABLE(vala,
|
AC_ARG_ENABLE(vala,
|
||||||
|
|||||||
@ -179,6 +179,9 @@ struct _DrawingContext
|
|||||||
};
|
};
|
||||||
typedef struct _DrawingContext DrawingContext;
|
typedef struct _DrawingContext DrawingContext;
|
||||||
|
|
||||||
|
static void on_key_pressed (EekKey *key, gpointer user_data);
|
||||||
|
static void on_key_released (EekKey *key, gpointer user_data);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prepare_keyboard_pixmap_key_callback (EekElement *element,
|
prepare_keyboard_pixmap_key_callback (EekElement *element,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
@ -193,6 +196,11 @@ prepare_keyboard_pixmap_key_callback (EekElement *element,
|
|||||||
|
|
||||||
eek_element_get_bounds (element, &bounds);
|
eek_element_get_bounds (element, &bounds);
|
||||||
|
|
||||||
|
g_signal_connect (key, "pressed", G_CALLBACK(on_key_pressed),
|
||||||
|
context->keyboard);
|
||||||
|
g_signal_connect (key, "released", G_CALLBACK(on_key_released),
|
||||||
|
context->keyboard);
|
||||||
|
|
||||||
outline = eek_key_get_outline (key);
|
outline = eek_key_get_outline (key);
|
||||||
texture = g_hash_table_lookup (priv->outline_textures, outline);
|
texture = g_hash_table_lookup (priv->outline_textures, outline);
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
@ -414,6 +422,71 @@ key_shrink (EekGtkKeyboard *keyboard, EekKey *key)
|
|||||||
bounds.height * SCALE * priv->scale);
|
bounds.height * SCALE * priv->scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_key_pressed (EekKey *key, gpointer user_data)
|
||||||
|
{
|
||||||
|
EekGtkKeyboard *keyboard = user_data;
|
||||||
|
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
|
||||||
|
|
||||||
|
key_enlarge (EEK_GTK_KEYBOARD(keyboard), key);
|
||||||
|
priv->key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_key_released (EekKey *key, gpointer user_data)
|
||||||
|
{
|
||||||
|
EekGtkKeyboard *keyboard = user_data;
|
||||||
|
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
|
||||||
|
|
||||||
|
if (priv->key)
|
||||||
|
key_shrink (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(priv->key));
|
||||||
|
priv->key = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
press_key (EekGtkKeyboard *keyboard, EekKey *key)
|
||||||
|
{
|
||||||
|
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
|
||||||
|
if (priv->key != key) {
|
||||||
|
if (priv->key)
|
||||||
|
g_signal_emit_by_name (priv->key, "released", keyboard);
|
||||||
|
g_signal_emit_by_name (key, "pressed", keyboard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
release_key (EekGtkKeyboard *keyboard)
|
||||||
|
{
|
||||||
|
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
|
||||||
|
|
||||||
|
if (priv->key)
|
||||||
|
g_signal_emit_by_name (priv->key, "released", keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
on_key_event (GtkWidget *widget,
|
||||||
|
GdkEventKey *event,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
EekGtkKeyboard *keyboard = user_data;
|
||||||
|
EekKey *key;
|
||||||
|
|
||||||
|
key = eek_keyboard_find_key_by_keycode (EEK_KEYBOARD(keyboard),
|
||||||
|
event->hardware_keycode);
|
||||||
|
if (!key)
|
||||||
|
return FALSE;
|
||||||
|
switch (event->type) {
|
||||||
|
case GDK_KEY_PRESS:
|
||||||
|
press_key (keyboard, key);
|
||||||
|
return TRUE;
|
||||||
|
case GDK_KEY_RELEASE:
|
||||||
|
release_key (keyboard);
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
on_button_event (GtkWidget *widget,
|
on_button_event (GtkWidget *widget,
|
||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
@ -434,25 +507,14 @@ on_button_event (GtkWidget *widget,
|
|||||||
key = eek_container_find_by_position (EEK_CONTAINER(section),
|
key = eek_container_find_by_position (EEK_CONTAINER(section),
|
||||||
x,
|
x,
|
||||||
y);
|
y);
|
||||||
if (key)
|
if (!key)
|
||||||
|
return FALSE;
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case GDK_BUTTON_PRESS:
|
case GDK_BUTTON_PRESS:
|
||||||
if (priv->key == key)
|
press_key (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(key));
|
||||||
return FALSE;
|
|
||||||
if (priv->key) {
|
|
||||||
key_shrink (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(priv->key));
|
|
||||||
g_signal_emit_by_name (keyboard, "key-released", priv->key);
|
|
||||||
}
|
|
||||||
key_enlarge (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(key));
|
|
||||||
g_signal_emit_by_name (keyboard, "key-pressed", key);
|
|
||||||
priv->key = key;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case GDK_BUTTON_RELEASE:
|
case GDK_BUTTON_RELEASE:
|
||||||
if (!priv->key)
|
release_key (EEK_GTK_KEYBOARD(keyboard));
|
||||||
return FALSE;
|
|
||||||
key_shrink (EEK_GTK_KEYBOARD(keyboard), EEK_KEY(priv->key));
|
|
||||||
g_signal_emit_by_name (keyboard, "key-released", priv->key);
|
|
||||||
priv->key = NULL;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -498,12 +560,17 @@ eek_gtk_keyboard_get_widget (EekGtkKeyboard *keyboard)
|
|||||||
gtk_widget_set_events (priv->widget,
|
gtk_widget_set_events (priv->widget,
|
||||||
GDK_EXPOSURE_MASK |
|
GDK_EXPOSURE_MASK |
|
||||||
GDK_KEY_PRESS_MASK |
|
GDK_KEY_PRESS_MASK |
|
||||||
|
GDK_KEY_RELEASE_MASK |
|
||||||
GDK_BUTTON_PRESS_MASK |
|
GDK_BUTTON_PRESS_MASK |
|
||||||
GDK_BUTTON_RELEASE_MASK);
|
GDK_BUTTON_RELEASE_MASK);
|
||||||
g_signal_connect (priv->widget, "expose_event",
|
g_signal_connect (priv->widget, "expose_event",
|
||||||
G_CALLBACK (on_expose_event), keyboard);
|
G_CALLBACK (on_expose_event), keyboard);
|
||||||
g_signal_connect (priv->widget, "size-allocate",
|
g_signal_connect (priv->widget, "size-allocate",
|
||||||
G_CALLBACK (on_size_allocate), keyboard);
|
G_CALLBACK (on_size_allocate), keyboard);
|
||||||
|
g_signal_connect (priv->widget, "key-press-event",
|
||||||
|
G_CALLBACK (on_key_event), keyboard);
|
||||||
|
g_signal_connect (priv->widget, "key-release-event",
|
||||||
|
G_CALLBACK (on_key_event), keyboard);
|
||||||
g_signal_connect (priv->widget, "button-press-event",
|
g_signal_connect (priv->widget, "button-press-event",
|
||||||
G_CALLBACK (on_button_event), keyboard);
|
G_CALLBACK (on_button_event), keyboard);
|
||||||
g_signal_connect (priv->widget, "button-release-event",
|
g_signal_connect (priv->widget, "button-release-event",
|
||||||
|
|||||||
@ -24,17 +24,19 @@ eekboard_CFLAGS = \
|
|||||||
$(GTK2_CFLAGS) \
|
$(GTK2_CFLAGS) \
|
||||||
$(XKB_CFLAGS) \
|
$(XKB_CFLAGS) \
|
||||||
$(LIBXKLAVIER_CFLAGS) \
|
$(LIBXKLAVIER_CFLAGS) \
|
||||||
$(LIBFAKEKEY_CFLAGS)
|
$(LIBFAKEKEY_CFLAGS) \
|
||||||
|
$(CSPI_CFLAGS)
|
||||||
|
|
||||||
eekboard_LDFLAGS = \
|
eekboard_LDFLAGS = \
|
||||||
$(top_builddir)/eek/libeek.la \
|
$(top_builddir)/eek/libeek.la \
|
||||||
$(top_builddir)/eek/libeek-xkl.la \
|
$(top_builddir)/eek/libeek-xkl.la \
|
||||||
$(top_builddir)/eek/libeek-gtk.la \
|
$(top_builddir)/eek/libeek-gtk.la \
|
||||||
$(GOBJECT2_LIBS) \
|
$(GOBJECT2_LIBS) \
|
||||||
$(GTK2_CFLAGS) \
|
$(GTK2_LIBS) \
|
||||||
$(XKB_LIBS) \
|
$(XKB_LIBS) \
|
||||||
$(LIBXKLAVIER_LIBS) \
|
$(LIBXKLAVIER_LIBS) \
|
||||||
$(LIBFAKEKEY_LIBS)
|
$(LIBFAKEKEY_LIBS) \
|
||||||
|
$(CSPI_LIBS)
|
||||||
|
|
||||||
if HAVE_CLUTTER
|
if HAVE_CLUTTER
|
||||||
eekboard_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
|
eekboard_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
|
||||||
|
|||||||
@ -32,9 +32,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <libxklavier/xklavier.h>
|
#include <libxklavier/xklavier.h>
|
||||||
#include <fakekey/fakekey.h>
|
#include <fakekey/fakekey.h>
|
||||||
#if 0
|
#include <cspi/spi.h>
|
||||||
#include <atk/atk.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -83,7 +81,6 @@ struct _Eekboard {
|
|||||||
FakeKey *fakekey;
|
FakeKey *fakekey;
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
guint key_event_listener;
|
|
||||||
XklEngine *engine;
|
XklEngine *engine;
|
||||||
XklConfigRegistry *registry;
|
XklConfigRegistry *registry;
|
||||||
GtkUIManager *ui_manager;
|
GtkUIManager *ui_manager;
|
||||||
@ -142,11 +139,9 @@ 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);
|
||||||
#if 0
|
|
||||||
static void on_monitor_key_event_toggled
|
static void on_monitor_key_event_toggled
|
||||||
(GtkToggleAction *action,
|
(GtkToggleAction *action,
|
||||||
GtkWidget *window);
|
GtkWidget *window);
|
||||||
#endif
|
|
||||||
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,
|
||||||
@ -166,9 +161,7 @@ static const char ui_description[] =
|
|||||||
" <menuitem action='Quit'/>"
|
" <menuitem action='Quit'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
" <menu action='KeyboardMenu'>"
|
" <menu action='KeyboardMenu'>"
|
||||||
#if 0
|
|
||||||
" <menuitem action='MonitorKeyEvent'/>"
|
" <menuitem action='MonitorKeyEvent'/>"
|
||||||
#endif
|
|
||||||
" <menu action='Country'>"
|
" <menu action='Country'>"
|
||||||
" <placeholder name='CountriesPH'/>"
|
" <placeholder name='CountriesPH'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
@ -216,12 +209,10 @@ 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)}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
static const GtkToggleActionEntry toggle_action_entry[] = {
|
static const GtkToggleActionEntry toggle_action_entry[] = {
|
||||||
{"MonitorKeyEvent", NULL, N_("Monitor Key Typing"), NULL, NULL,
|
{"MonitorKeyEvent", NULL, N_("Monitor Key Typing"), NULL, NULL,
|
||||||
G_CALLBACK(on_monitor_key_event_toggled), FALSE}
|
G_CALLBACK(on_monitor_key_event_toggled), FALSE}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
static gchar *opt_model = NULL;
|
static gchar *opt_model = NULL;
|
||||||
static gchar *opt_layouts = NULL;
|
static gchar *opt_layouts = NULL;
|
||||||
@ -280,13 +271,26 @@ on_quit (GtkAction * action, GtkWidget *window)
|
|||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
static SPIBoolean
|
||||||
static gint
|
keystroke_listener (const AccessibleKeystroke *stroke,
|
||||||
key_snoop (AtkKeyEventStruct *event, gpointer func_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
return FALSE;
|
Eekboard *eekboard = user_data;
|
||||||
|
EekKey *key;
|
||||||
|
|
||||||
|
//g_return_val_if_fail (stroke->modifiers == SPI_KEYMASK_UNMODIFIED, FALSE);
|
||||||
|
key = eek_keyboard_find_key_by_keycode (eekboard->keyboard,
|
||||||
|
stroke->keycode);
|
||||||
|
g_return_val_if_fail (key, FALSE);
|
||||||
|
if (stroke->type == SPI_KEY_PRESSED)
|
||||||
|
g_signal_emit_by_name (key, "pressed");
|
||||||
|
else
|
||||||
|
g_signal_emit_by_name (key, "released");
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AccessibleEventListener* keystrokeListener;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_monitor_key_event_toggled (GtkToggleAction *action,
|
on_monitor_key_event_toggled (GtkToggleAction *action,
|
||||||
GtkWidget *window)
|
GtkWidget *window)
|
||||||
@ -294,18 +298,23 @@ on_monitor_key_event_toggled (GtkToggleAction *action,
|
|||||||
|
|
||||||
Eekboard *eekboard = g_object_get_data (G_OBJECT(window), "eekboard");
|
Eekboard *eekboard = g_object_get_data (G_OBJECT(window), "eekboard");
|
||||||
|
|
||||||
if (gtk_toggle_action_get_active (action)) {
|
if (!keystrokeListener) {
|
||||||
if (eekboard->key_event_listener == 0)
|
keystrokeListener =
|
||||||
eekboard->key_event_listener =
|
SPI_createAccessibleKeystrokeListener (keystroke_listener,
|
||||||
atk_add_key_event_listener (key_snoop, eekboard);
|
eekboard);
|
||||||
g_warning ("failed to enable ATK key event listener");
|
|
||||||
} else
|
|
||||||
if (eekboard->key_event_listener != 0) {
|
|
||||||
atk_remove_key_event_listener (eekboard->key_event_listener);
|
|
||||||
eekboard->key_event_listener = 0;
|
|
||||||
}
|
}
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_key_pressed (EekKeyboard *keyboard,
|
on_key_pressed (EekKeyboard *keyboard,
|
||||||
@ -861,11 +870,9 @@ 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);
|
||||||
#if 0
|
|
||||||
gtk_action_group_add_toggle_actions (action_group, toggle_action_entry,
|
gtk_action_group_add_toggle_actions (action_group, toggle_action_entry,
|
||||||
G_N_ELEMENTS (toggle_action_entry),
|
G_N_ELEMENTS (toggle_action_entry),
|
||||||
window);
|
window);
|
||||||
#endif
|
|
||||||
|
|
||||||
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);
|
||||||
@ -1154,6 +1161,8 @@ main (int argc, char *argv[])
|
|||||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SPI_init ();
|
||||||
|
|
||||||
env = g_getenv ("EEKBOARD_DISABLE_CLUTTER");
|
env = g_getenv ("EEKBOARD_DISABLE_CLUTTER");
|
||||||
if (env && g_strcmp0 (env, "1") == 0)
|
if (env && g_strcmp0 (env, "1") == 0)
|
||||||
use_clutter = FALSE;
|
use_clutter = FALSE;
|
||||||
|
|||||||
Reference in New Issue
Block a user