Commit 91ed49b6 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Make server responsible for loading keyboard files.

parent 84f61452
keyboarddir = $(pkgdatadir)/keyboards
dist_keyboard_DATA = us-qwerty.xml
dist_keyboard_DATA = us.xml
......@@ -84,11 +84,6 @@ eek_xkl_layout_dispose (GObject *object)
priv->config = NULL;
}
if (priv->engine) {
g_object_unref (priv->engine);
priv->engine = NULL;
}
G_OBJECT_CLASS (eek_xkl_layout_parent_class)->dispose (object);
}
......
......@@ -21,12 +21,24 @@ lib_LTLIBRARIES = libeekboard.la
libeekboard_headers = \
eekboard.h \
eekboard-eekboard.h \
eekboard-context.h
eekboard-context.h
libeekboard_private_headers = \
eekboard-marshalers.h
libeekboard_sources = \
eekboard-eekboard.c \
eekboard-context.c
libeekboard_la_SOURCES = $(libeekboard_sources)
libeekboard_marshalers_sources = \
eekboard-marshalers.c \
eekboard-marshalers.h
BUILT_SOURCES = \
$(libeekboard_marshalers_sources)
libeekboard_la_SOURCES = \
$(libeekboard_sources) \
eekboard-marshalers.c
libeekboard_la_CFLAGS = -DEEKBOARD_COMPILATION=1 -I$(top_srcdir) $(GIO2_CFLAGS)
libeekboard_la_LIBADD = $(top_builddir)/eek/libeek.la $(GIO2_LIBS)
......@@ -37,10 +49,23 @@ pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
eekboard-$(EEK_API_VERSION).pc
DISTCLEANFILES = \
$(BUILT_SOURCES) \
$(pkgconfig_DATA)
CLEANFILES =
EXTRA_DIST = eekboard-marshalers.list
# gen marshal
eekboard-marshalers.h: eekboard-marshalers.list
$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_eekboard_marshal $(srcdir)/eekboard-marshalers.list --header --internal > $@.tmp && \
mv $@.tmp $@
eekboard-marshalers.c: eekboard-marshalers.list eekboard-marshalers.h
$(AM_V_GEN) (echo "#include \"eekboard-marshalers.h\""; \
$(GLIB_GENMARSHAL) --prefix=_eekboard_marshal $(srcdir)/eekboard-marshalers.list --body --internal) > $@.tmp && \
mv $@.tmp $@
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_GIRS =
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(builddir) --add-include-path=$(top_builddir)/eek
......
......@@ -29,6 +29,7 @@
#endif /* HAVE_CONFIG_H */
#include "eekboard/eekboard-context.h"
#include "eekboard/eekboard-marshalers.h"
#define I_(string) g_intern_static_string (string)
......@@ -36,7 +37,6 @@ enum {
ENABLED,
DISABLED,
KEY_PRESSED,
KEY_RELEASED,
DESTROYED,
LAST_SIGNAL
};
......@@ -56,11 +56,10 @@ G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
struct _EekboardContextPrivate
{
EekKeyboard *keyboard;
GHashTable *keyboard_hash;
gboolean keyboard_visible;
gboolean enabled;
gboolean fullscreen;
gint group;
};
static void
......@@ -83,21 +82,24 @@ eekboard_context_real_g_signal (GDBusProxy *self,
}
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
guint keycode;
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (context, "key-pressed", keycode);
return;
}
if (g_strcmp0 (signal_name, "KeyReleased") == 0) {
guint keycode;
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (context, "key-released", keycode);
guint keycode = 0;
GVariant *variant = NULL;
guint modifiers = 0;
EekSerializable *serializable;
g_variant_get (parameters, "(uvu)", &keycode, &variant, &modifiers);
g_return_if_fail (variant != NULL);
serializable = eek_serializable_deserialize (variant);
g_return_if_fail (EEK_IS_SYMBOL(serializable));
g_signal_emit_by_name (context, "key-pressed",
keycode, EEK_SYMBOL(serializable), modifiers);
return;
}
if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) {
gboolean keyboard_visible;
gboolean keyboard_visible = FALSE;
g_variant_get (parameters, "(b)", &keyboard_visible);
if (keyboard_visible != priv->keyboard_visible) {
......@@ -107,6 +109,17 @@ eekboard_context_real_g_signal (GDBusProxy *self,
return;
}
if (g_strcmp0 (signal_name, "GroupChanged") == 0) {
gint group = 0;
g_variant_get (parameters, "(i)", &group);
if (group != priv->group) {
priv->group = group;
//g_object_notify (G_OBJECT(context), "group");
}
return;
}
g_return_if_reached ();
}
......@@ -126,32 +139,15 @@ eekboard_context_real_disabled (EekboardContext *self)
static void
eekboard_context_real_key_pressed (EekboardContext *self,
guint keycode)
guint keycode,
EekSymbol *symbol,
guint modifiers)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
if (priv->keyboard) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->keyboard,
keycode);
g_signal_emit_by_name (key, "pressed");
}
}
static void
eekboard_context_real_key_released (EekboardContext *self,
guint keycode)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
if (priv->keyboard) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->keyboard,
keycode);
g_signal_emit_by_name (key, "released");
}
}
static void
eekboard_context_real_destroyed (EekboardContext *self)
{
// g_debug ("eekboard_context_real_destroyed");
}
static void
......@@ -173,22 +169,6 @@ eekboard_context_get_property (GObject *object,
}
}
static void
eekboard_context_dispose (GObject *self)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE (self);
if (priv->keyboard) {
g_object_unref (priv->keyboard);
priv->keyboard = NULL;
}
if (priv->keyboard_hash) {
g_hash_table_destroy (priv->keyboard_hash);
priv->keyboard_hash = NULL;
}
}
static void
eekboard_context_class_init (EekboardContextClass *klass)
{
......@@ -202,13 +182,11 @@ eekboard_context_class_init (EekboardContextClass *klass)
klass->enabled = eekboard_context_real_enabled;
klass->disabled = eekboard_context_real_disabled;
klass->key_pressed = eekboard_context_real_key_pressed;
klass->key_released = eekboard_context_real_key_released;
klass->destroyed = eekboard_context_real_destroyed;
proxy_class->g_signal = eekboard_context_real_g_signal;
gobject_class->get_property = eekboard_context_get_property;
gobject_class->dispose = eekboard_context_dispose;
/**
* EekboardContext:keyboard-visible:
......@@ -262,6 +240,8 @@ eekboard_context_class_init (EekboardContextClass *klass)
* EekboardContext::key-pressed:
* @context: an #EekboardContext
* @keycode: keycode
* @symbol: an #EekSymbol
* @modifiers: modifiers
*
* The ::key-pressed signal is emitted each time a key is pressed
* in @context.
......@@ -273,29 +253,11 @@ eekboard_context_class_init (EekboardContextClass *klass)
G_STRUCT_OFFSET(EekboardContextClass, key_pressed),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE,
1,
G_TYPE_UINT);
/**
* EekboardContext::key-released:
* @context: an #EekboardContext
* @keycode: keycode
*
* The ::key-released signal is emitted each time a key is released
* in @context.
*/
signals[KEY_RELEASED] =
g_signal_new (I_("key-released"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardContextClass, key_released),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
_eekboard_marshal_VOID__UINT_OBJECT_UINT,
G_TYPE_NONE,
1,
3,
G_TYPE_UINT,
G_TYPE_OBJECT,
G_TYPE_UINT);
/**
......@@ -320,17 +282,7 @@ eekboard_context_class_init (EekboardContextClass *klass)
static void
eekboard_context_init (EekboardContext *self)
{
EekboardContextPrivate *priv;
priv = self->priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
priv->keyboard = NULL;
priv->keyboard_visible = FALSE;
priv->enabled = FALSE;
priv->keyboard_hash =
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)g_object_unref);
self->priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
}
static void
......@@ -415,38 +367,29 @@ context_async_ready_callback (GObject *source_object,
/**
* eekboard_context_add_keyboard:
* @context: an #EekboardContext
* @keyboard: an #EekKeyboard
* @keyboard: a string representing keyboard
* @cancellable: a #GCancellable
*
* Register @keyboard in @context.
*/
guint
eekboard_context_add_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
const gchar *keyboard,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
GVariant *variant, *result;
GVariant *result;
GError *error;
g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), 0);
g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0);
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
variant = eek_serializable_serialize (EEK_SERIALIZABLE(keyboard));
if (g_variant_is_floating (variant))
g_variant_ref_sink (variant);
error = NULL;
result = g_dbus_proxy_call_sync (G_DBUS_PROXY(context),
"AddKeyboard",
g_variant_new ("(v)", variant),
g_variant_new ("(s)", keyboard),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
&error);
g_variant_unref (variant);
if (result) {
guint keyboard_id;
......@@ -454,11 +397,6 @@ eekboard_context_add_keyboard (EekboardContext *context,
g_variant_get (result, "(u)", &keyboard_id);
g_variant_unref (result);
if (keyboard_id != 0) {
g_hash_table_insert (priv->keyboard_hash,
GUINT_TO_POINTER(keyboard_id),
g_object_ref (keyboard));
}
return keyboard_id;
}
return 0;
......@@ -477,20 +415,8 @@ eekboard_context_remove_keyboard (EekboardContext *context,
guint keyboard_id,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
EekKeyboard *keyboard;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
keyboard = g_hash_table_lookup (priv->keyboard_hash,
GUINT_TO_POINTER(keyboard_id));
if (keyboard == priv->keyboard)
priv->keyboard = NULL;
g_hash_table_remove (priv->keyboard_hash, GUINT_TO_POINTER(keyboard_id));
g_dbus_proxy_call (G_DBUS_PROXY(context),
"RemoveKeyboard",
g_variant_new ("(u)", keyboard_id),
......@@ -514,20 +440,8 @@ eekboard_context_set_keyboard (EekboardContext *context,
guint keyboard_id,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
EekKeyboard *keyboard;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
keyboard = g_hash_table_lookup (priv->keyboard_hash,
GUINT_TO_POINTER(keyboard_id));
if (!keyboard || keyboard == priv->keyboard)
return;
priv->keyboard = keyboard;
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetKeyboard",
g_variant_new ("(u)", keyboard_id),
......@@ -557,10 +471,7 @@ eekboard_context_set_group (EekboardContext *context,
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
g_return_if_fail (priv->keyboard);
if (eek_element_get_group (EEK_ELEMENT(priv->keyboard)) != group) {
eek_element_set_group (EEK_ELEMENT(priv->keyboard), group);
if (priv->group != group) {
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetGroup",
g_variant_new ("(i)", group),
......@@ -572,6 +483,25 @@ eekboard_context_set_group (EekboardContext *context,
}
}
/**
* eekboard_context_get_group:
* @context: an #EekboardContext
* @cancellable: a #GCancellable
*
* Get the keyboard group of @context.
*/
gint
eekboard_context_get_group (EekboardContext *context,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), 0);
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
return priv->group;
}
/**
* eekboard_context_show_keyboard:
* @context: an #EekboardContext
......
......@@ -57,7 +57,6 @@ struct _EekboardContext {
* @enabled: class handler for #EekboardContext::enabled signal
* @disabled: class handler for #EekboardContext::disabled signal
* @key_pressed: class handler for #EekboardContext::key-pressed signal
* @key_released: class handler for #EekboardContext::key-released signal
*/
struct _EekboardContextClass {
/*< private >*/
......@@ -68,14 +67,14 @@ struct _EekboardContextClass {
void (*enabled) (EekboardContext *self);
void (*disabled) (EekboardContext *self);
void (*key_pressed) (EekboardContext *self,
guint keycode);
void (*key_released) (EekboardContext *self,
guint keycode);
guint keycode,
EekSymbol *symbol,
guint modifiers);
void (*destroyed) (EekboardContext *self);
/*< private >*/
/* padding */
gpointer pdummy[23];
gpointer pdummy[24];
};
GType eekboard_context_get_type (void) G_GNUC_CONST;
......@@ -84,7 +83,7 @@ EekboardContext *eekboard_context_new (GDBusConnection *connection,
const gchar *object_path,
GCancellable *cancellable);
guint eekboard_context_add_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
const gchar *keyboard,
GCancellable *cancellable);
void eekboard_context_remove_keyboard (EekboardContext *context,
guint keyboard_id,
......
......@@ -69,14 +69,19 @@ eekboard_server_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS) \
$(GTK_CFLAGS) \
-DTHEMEDIR=\"$(pkgdatadir)/themes\"
$(LIBXKLAVIER_CFLAGS) \
-DTHEMEDIR=\"$(pkgdatadir)/themes\" \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"
eekboard_server_LDADD = \
$(builddir)/libxklutil.la \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-gtk.la \
$(top_builddir)/eek/libeek-xkl.la \
$(GIO2_LIBS) \
$(GTK_LIBS)
$(GTK_LIBS) \
$(LIBXKLAVIER_LIBS)
if ENABLE_CLUTTER_GTK
eekboard_server_CFLAGS += $(CLUTTER_GTK_CFLAGS)
......
......@@ -32,7 +32,7 @@
#include "eekboard/eekboard.h"
#include "client.h"
#define DEFAULT_LAYOUT "us-qwerty"
#define DEFAULT_KEYBOARD "us"
static gboolean opt_system = FALSE;
static gboolean opt_session = FALSE;
......@@ -44,10 +44,6 @@ static gboolean opt_keystroke = FALSE;
static gchar *opt_keyboard = NULL;
static gchar *opt_model = NULL;
static gchar *opt_layouts = NULL;
static gchar *opt_options = NULL;
static gboolean opt_fullscreen = FALSE;
static const GOptionEntry options[] = {
......@@ -69,12 +65,6 @@ static const GOptionEntry options[] = {
#endif /* HAVE_ATSPI */
{"keyboard", 'k', 0, G_OPTION_ARG_STRING, &opt_keyboard,
N_("Specify keyboard")},
{"model", '\0', 0, G_OPTION_ARG_STRING, &opt_model,
N_("Specify model")},
{"layouts", '\0', 0, G_OPTION_ARG_STRING, &opt_layouts,
N_("Specify layouts")},
{"options", '\0', 0, G_OPTION_ARG_STRING, &opt_options,
N_("Specify options")},
{"fullscreen", 'F', 0, G_OPTION_ARG_NONE, &opt_fullscreen,
N_("Create window in fullscreen mode")},
{NULL}
......@@ -138,6 +128,13 @@ main (int argc, char **argv)
exit (1);
}
/* preload Eek* types for EekKeyboard deserialization */
g_type_class_ref (EEK_TYPE_KEYBOARD);
g_type_class_ref (EEK_TYPE_SECTION);
g_type_class_ref (EEK_TYPE_KEY);
g_type_class_ref (EEK_TYPE_SYMBOL);
g_type_class_ref (EEK_TYPE_KEYSYM);
option_context = g_option_context_new ("eekboard-desktop-client");
g_option_context_add_main_entries (option_context, options, NULL);
g_option_context_parse (option_context, &argc, &argv, NULL);
......@@ -254,7 +251,7 @@ main (int argc, char **argv)
}
#endif /* HAVE_IBUS */
if (opt_use_system_layout && (opt_keyboard || opt_model || opt_layouts || opt_options)) {
if (opt_use_system_layout && opt_keyboard) {
g_printerr ("Can't use --use-system-layout option with keyboard options\n");
g_object_unref (client);
exit (1);
......@@ -266,35 +263,6 @@ main (int argc, char **argv)
exit (1);
}
if (opt_use_system_layout || opt_model || opt_layouts || opt_options) {
if (!eekboard_client_load_keyboard_from_xkl (client,
opt_model,
opt_layouts,
opt_options)) {
g_printerr ("Can't load keyboard from xklavier config\n");
g_object_unref (client);
exit (1);
}
} else {
gchar *file;
gboolean success;
if (!opt_keyboard)
opt_keyboard = DEFAULT_LAYOUT;
if (g_str_has_suffix (opt_keyboard, ".xml"))
file = g_strdup (opt_keyboard);
else
file = g_strdup_printf ("%s/%s.xml", KEYBOARDDIR, opt_keyboard);
success = eekboard_client_load_keyboard_from_file (client, file);
g_free (file);
if (!success) {
g_printerr ("Can't load keyboard file %s\n", file);
g_object_unref (client);
exit (1);
}
}
#ifdef HAVE_XTEST
if (!eekboard_client_enable_xtest (client)) {
g_printerr ("Can't init xtest\n");
......@@ -303,6 +271,8 @@ main (int argc, char **argv)
}
#endif /* HAVE_XTEST */
eekboard_client_set_keyboard (client, opt_keyboard ? opt_keyboard : DEFAULT_KEYBOARD);
loop = g_main_loop_new (NULL, FALSE);
if (!opt_focus) {
g_object_get (client, "context", &context, NULL);
......
......@@ -68,7 +68,6 @@ struct _EekboardClient {
XklEngine *xkl_engine;
XklConfigRegistry *xkl_config_registry;
gboolean use_xkl_layout;
gint group;
gulong xkl_config_changed_handler;
gulong xkl_state_changed_handler;
......@@ -123,13 +122,7 @@ static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke,
void *user_data);
#endif /* HAVE_ATSPI */
static gboolean set_keyboard (EekboardClient *client,
gboolean show,
EekLayout *layout);
static gboolean set_keyboard_from_xkl (EekboardClient *client,
gboolean show,
const gchar *model,
const gchar *layouts,
const gchar *options);
const gchar *keyboard);
#ifdef HAVE_XTEST
static void update_modifier_keycodes
(EekboardClient *client);
......@@ -232,11 +225,6 @@ eekboard_client_dispose (GObject *object)
client->eekboard = NULL;
}
if (client->keyboard) {
g_object_unref (client->keyboard);
client->keyboard = NULL;
}
if (client->settings) {
g_object_unref (client->settings);
client->settings = NULL;
......@@ -286,50 +274,25 @@ eekboard_client_class_init (EekboardClientClass *klass)
static void
eekboard_client_init (EekboardClient *client)
{
client->eekboard = NULL;
client->context = NULL;
client->xkl_engine = NULL;
client->xkl_config_registry = NULL;
client->keyboard = NULL;
client->key_pressed_handler = 0;
client->key_released_handler = 0;
client->xkl_config_changed_handler = 0;
client->xkl_state_changed_handler = 0;
#if ENABLE_FOCUS_LISTENER
client->follows_focus = FALSE;
client->hide_keyboard_timeout_id = 0;
#endif /* ENABLE_FOCUS_LISTENER */
#ifdef HAVE_ATSPI
client->keystroke_listener = NULL;
#endif /* HAVE_ATSPI */
#ifdef HAVE_IBUS
client