Commit d25114b3 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Allow the server to have multiple input contexts.

parent 12cc310e
......@@ -172,24 +172,14 @@ eek_container_dispose (GObject *object)
EekContainerPrivate *priv = EEK_CONTAINER_GET_PRIVATE(object);
GSList *head;
for (head = priv->children; head; head = g_slist_next (head)) {
if (head->data) {
g_object_unref (head->data);
head->data = NULL;
}
for (head = priv->children; head; head = priv->children) {
g_object_unref (head->data);
priv->children = g_slist_next (head);
g_slist_free1 (head);
}
G_OBJECT_CLASS(eek_container_parent_class)->dispose (object);
}
static void
eek_container_finalize (GObject *object)
{
EekContainerPrivate *priv = EEK_CONTAINER_GET_PRIVATE(object);
g_slist_free (priv->children);
G_OBJECT_CLASS(eek_container_parent_class)->finalize (object);
}
static void
eek_container_class_init (EekContainerClass *klass)
{
......@@ -207,7 +197,6 @@ eek_container_class_init (EekContainerClass *klass)
klass->child_added = NULL;
klass->child_removed = NULL;
gobject_class->finalize = eek_container_finalize;
gobject_class->dispose = eek_container_dispose;
/**
......
......@@ -18,8 +18,13 @@
lib_LTLIBRARIES = libeekboard.la
libeekboard_headers = eekboard.h eekboard-keyboard.h
libeekboard_sources = eekboard-keyboard.c
libeekboard_headers = \
eekboard.h \
eekboard-server.h \
eekboard-context.h
libeekboard_sources = \
eekboard-server.c \
eekboard-context.c
libeekboard_la_SOURCES = $(libeekboard_sources)
libeekboard_la_CFLAGS = -I$(top_srcdir) $(GIO2_CFLAGS)
......
......@@ -19,9 +19,11 @@
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eekboard-keyboard.h"
#include "eekboard/eekboard-context.h"
enum {
ENABLED,
DISABLED,
KEY_PRESSED,
KEY_RELEASED,
LAST_SIGNAL
......@@ -29,42 +31,53 @@ enum {
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekboardKeyboard, eekboard_keyboard, G_TYPE_DBUS_PROXY);
G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
#define EEKBOARD_KEYBOARD_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_KEYBOARD, EekboardKeyboardPrivate))
#define EEKBOARD_CONTEXT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CONTEXT, EekboardContextPrivate))
struct _EekboardKeyboardPrivate
struct _EekboardContextPrivate
{
EekKeyboard *description;
gboolean visible;
EekKeyboard *keyboard;
gboolean keyboard_visible;
gboolean enabled;
};
static void
eekboard_keyboard_real_g_signal (GDBusProxy *self,
const gchar *sender_name,
const gchar *signal_name,
GVariant *parameters)
eekboard_context_real_g_signal (GDBusProxy *self,
const gchar *sender_name,
const gchar *signal_name,
GVariant *parameters)
{
EekboardKeyboard *keyboard = EEKBOARD_KEYBOARD (self);
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE (keyboard);
EekboardContext *context = EEKBOARD_CONTEXT (self);
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (g_strcmp0 (signal_name, "Enabled") == 0) {
g_signal_emit_by_name (context, "enabled");
return;
}
if (g_strcmp0 (signal_name, "Disabled") == 0) {
g_signal_emit_by_name (context, "disabled");
return;
}
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
guint keycode;
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (keyboard, "key-pressed", 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 (keyboard, "key-released", keycode);
g_signal_emit_by_name (context, "key-released", keycode);
return;
}
if (g_strcmp0 (signal_name, "VisibilityChanged") == 0) {
g_variant_get (parameters, "(b)", &priv->visible);
if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) {
g_variant_get (parameters, "(b)", &priv->keyboard_visible);
return;
}
......@@ -72,61 +85,99 @@ eekboard_keyboard_real_g_signal (GDBusProxy *self,
}
static void
eekboard_keyboard_real_key_pressed (EekboardKeyboard *self,
guint keycode)
eekboard_context_real_enabled (EekboardContext *self)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
priv->enabled = TRUE;
}
static void
eekboard_context_real_disabled (EekboardContext *self)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
priv->enabled = FALSE;
}
static void
eekboard_context_real_key_pressed (EekboardContext *self,
guint keycode)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
if (priv->description) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->description,
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_keyboard_real_key_released (EekboardKeyboard *self,
guint keycode)
eekboard_context_real_key_released (EekboardContext *self,
guint keycode)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
if (priv->description) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->description,
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_keyboard_dispose (GObject *self)
eekboard_context_dispose (GObject *self)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE (self);
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE (self);
if (priv->description) {
g_object_unref (priv->description);
priv->description = NULL;
if (priv->keyboard) {
g_object_unref (priv->keyboard);
priv->keyboard = NULL;
}
}
static void
eekboard_keyboard_class_init (EekboardKeyboardClass *klass)
eekboard_context_class_init (EekboardContextClass *klass)
{
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (gobject_class,
sizeof (EekboardKeyboardPrivate));
sizeof (EekboardContextPrivate));
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->key_pressed = eekboard_keyboard_real_key_pressed;
klass->key_released = eekboard_keyboard_real_key_released;
proxy_class->g_signal = eekboard_context_real_g_signal;
proxy_class->g_signal = eekboard_keyboard_real_g_signal;
gobject_class->dispose = eekboard_context_dispose;
gobject_class->dispose = eekboard_keyboard_dispose;
signals[ENABLED] =
g_signal_new ("enabled",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardContextClass, enabled),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals[DISABLED] =
g_signal_new ("disabled",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardContextClass, disabled),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals[KEY_PRESSED] =
g_signal_new ("key-pressed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardKeyboardClass, key_pressed),
G_STRUCT_OFFSET(EekboardContextClass, key_pressed),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
......@@ -138,7 +189,7 @@ eekboard_keyboard_class_init (EekboardKeyboardClass *klass)
g_signal_new ("key-released",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardKeyboardClass, key_released),
G_STRUCT_OFFSET(EekboardContextClass, key_released),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
......@@ -148,55 +199,46 @@ eekboard_keyboard_class_init (EekboardKeyboardClass *klass)
}
static void
eekboard_keyboard_init (EekboardKeyboard *self)
eekboard_context_init (EekboardContext *self)
{
EekboardKeyboardPrivate *priv;
EekboardContextPrivate *priv;
priv = self->priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
priv->description = NULL;
priv->visible = FALSE;
priv = self->priv = EEKBOARD_CONTEXT_GET_PRIVATE(self);
priv->keyboard = NULL;
priv->keyboard_visible = FALSE;
priv->enabled = FALSE;
}
/**
* eekboard_keyboard_new:
* @path: object path in DBus
* @connection: #GDBusConnection
* @cancellable: #GCancellable
* @error: a pointer of #GError
*
* Create a new #EekboardKeyboard.
*/
EekboardKeyboard *
eekboard_keyboard_new (const gchar *path,
GDBusConnection *connection,
GCancellable *cancellable,
GError **error)
EekboardContext *
eekboard_context_new (GDBusConnection *connection,
const gchar *object_path,
GCancellable *cancellable)
{
GInitable *initable;
GError *error;
g_assert (path != NULL);
g_assert (object_path != NULL);
g_assert (G_IS_DBUS_CONNECTION(connection));
error = NULL;
initable =
g_initable_new (EEKBOARD_TYPE_KEYBOARD,
g_initable_new (EEKBOARD_TYPE_CONTEXT,
cancellable,
error,
&error,
"g-name", "com.redhat.Eekboard.Server",
"g-connection", connection,
"g-name", "com.redhat.Eekboard.Keyboard",
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
"g-interface-name", "com.redhat.Eekboard.Keyboard",
"g-object-path", path,
"g-interface-name", "com.redhat.Eekboard.Context",
"g-object-path", object_path,
NULL);
if (initable != NULL)
return EEKBOARD_KEYBOARD (initable);
return EEKBOARD_CONTEXT (initable);
return NULL;
}
static void
proxy_call_async_ready_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GVariant *result;
......@@ -204,123 +246,172 @@ proxy_call_async_ready_cb (GObject *source_object,
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
// g_assert_no_error (error);
if (result)
g_variant_unref (result);
}
void
eekboard_keyboard_set_description (EekboardKeyboard *keyboard,
EekKeyboard *description)
eekboard_context_set_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
GCancellable *cancellable)
{
EekboardKeyboardPrivate *priv;
EekboardContextPrivate *priv;
GVariant *variant;
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_return_if_fail (EEK_IS_KEYBOARD(description));
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
g_return_if_fail (EEK_IS_KEYBOARD(keyboard));
priv = EEKBOARD_KEYBOARD_GET_PRIVATE(keyboard);
if (priv->description)
g_object_unref (priv->description);
priv->description = g_object_ref (description);
priv = EEKBOARD_CONTEXT_GET_PRIVATE(context);
if (priv->keyboard)
g_object_unref (priv->keyboard);
priv->keyboard = g_object_ref (keyboard);
variant = eek_serializable_serialize (EEK_SERIALIZABLE(description));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"SetDescription",
variant = eek_serializable_serialize (EEK_SERIALIZABLE(priv->keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetKeyboard",
g_variant_new ("(v)", variant),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
g_variant_unref (variant);
}
void
eekboard_keyboard_set_group (EekboardKeyboard *keyboard,
gint group)
eekboard_context_set_group (EekboardContext *context,
gint group,
GCancellable *cancellable)
{
EekboardKeyboardPrivate *priv;
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
priv = EEKBOARD_KEYBOARD_GET_PRIVATE (keyboard);
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
g_return_if_fail (priv->keyboard);
g_return_if_fail (group >= 0);
eek_keyboard_set_group (priv->keyboard, group);
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetGroup",
g_variant_new ("(i)", group),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
eek_keyboard_set_group (priv->description, group);
}
void
eekboard_keyboard_show (EekboardKeyboard *keyboard)
eekboard_context_show_keyboard (EekboardContext *context,
GCancellable *cancellable)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Show",
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (!priv->enabled)
return;
g_dbus_proxy_call (G_DBUS_PROXY(context),
"ShowKeyboard",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_keyboard_hide (EekboardKeyboard *keyboard)
eekboard_context_hide_keyboard (EekboardContext *context,
GCancellable *cancellable)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Hide",
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (!priv->enabled)
return;
g_dbus_proxy_call (G_DBUS_PROXY(context),
"HideKeyboard",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_keyboard_press_key (EekboardKeyboard *keyboard,
guint keycode)
eekboard_context_press_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (!priv->enabled)
return;
g_dbus_proxy_call (G_DBUS_PROXY(context),
"PressKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_keyboard_release_key (EekboardKeyboard *keyboard,
guint keycode)
eekboard_context_release_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (!priv->enabled)
return;
g_dbus_proxy_call (G_DBUS_PROXY(context),
"ReleaseKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
cancellable,
context_async_ready_callback,
NULL);
}
gboolean
eekboard_keyboard_get_visible (EekboardKeyboard *keyboard)
eekboard_context_is_keyboard_visible (EekboardContext *context)
{
EekboardContextPrivate *priv;
g_assert (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
return priv->enabled && priv->keyboard_visible;
}
void
eekboard_context_set_enabled (EekboardContext *context,
gboolean enabled)
{
EekboardKeyboardPrivate *priv;
EekboardContextPrivate *priv;
g_assert (EEKBOARD_IS_KEYBOARD(keyboard));
g_assert (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_KEYBOARD_GET_PRIVATE (keyboard);
return priv->visible;
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
priv->enabled = enabled;
}
......@@ -15,57 +15,67 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EEKBOARD_KEYBOARD_H
#define EEKBOARD_KEYBOARD_H 1
#ifndef EEKBOARD_CONTEXT_H
#define EEKBOARD_CONTEXT_H 1
#include <gio/gio.h>
#include "eek/eek.h"
G_BEGIN_DECLS
#define EEKBOARD_TYPE_KEYBOARD (eekboard_keyboard_get_type())
#define EEKBOARD_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_KEYBOARD, EekboardKeyboard))
#define EEKBOARD_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_KEYBOARD, EekboardKeyboardClass))
#define EEKBOARD_IS_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_KEYBOARD))
#define EEKBOARD_IS_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_KEYBOARD))
#define EEKBOARD_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_KEYBOARD, EekboardKeyboardClass))
#define EEKBOARD_TYPE_CONTEXT (eekboard_context_get_type())
#define EEKBOARD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_CONTEXT, EekboardContext))
#define EEKBOARD_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_CONTEXT, EekboardContextClass))
#define EEKBOARD_IS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_CONTEXT))
#define EEKBOARD_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_CONTEXT))
#define EEKBOARD_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_CONTEXT, EekboardContextClass))
typedef struct _EekboardKeyboard EekboardKeyboard;
typedef struct _EekboardKeyboardClass EekboardKeyboardClass;
typedef struct _EekboardKeyboardPrivate EekboardKeyboardPrivate;
typedef struct _EekboardContext EekboardContext;
typedef struct _EekboardContextClass EekboardContextClass;
typedef struct _EekboardContextPrivate EekboardContextPrivate;
struct _EekboardKeyboard {
struct _EekboardContext {
GDBusProxy parent;
EekboardKeyboardPrivate *priv;
EekboardContextPrivate *priv;
};
struct _EekboardKeyboardClass {
struct _EekboardContextClass {
GDBusProxyClass parent_class;