Allow the server to have multiple input contexts.

This commit is contained in:
Daiki Ueno
2011-02-22 17:22:36 +09:00
parent 12cc310e38
commit d25114b370
18 changed files with 1997 additions and 1051 deletions

View File

@ -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)

417
eekboard/eekboard-context.c Normal file
View File

@ -0,0 +1,417 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eekboard/eekboard-context.h"
enum {
ENABLED,
DISABLED,
KEY_PRESSED,
KEY_RELEASED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
#define EEKBOARD_CONTEXT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CONTEXT, EekboardContextPrivate))
struct _EekboardContextPrivate
{
EekKeyboard *keyboard;
gboolean keyboard_visible;
gboolean enabled;
};
static void
eekboard_context_real_g_signal (GDBusProxy *self,
const gchar *sender_name,
const gchar *signal_name,
GVariant *parameters)
{
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 (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);
return;
}
if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) {
g_variant_get (parameters, "(b)", &priv->keyboard_visible);
return;
}
g_return_if_reached ();
}
static void
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)
{
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_dispose (GObject *self)
{
EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE (self);
if (priv->keyboard) {
g_object_unref (priv->keyboard);
priv->keyboard = NULL;
}
}
static void
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 (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;
proxy_class->g_signal = eekboard_context_real_g_signal;
gobject_class->dispose = eekboard_context_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(EekboardContextClass, key_pressed),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE,
1,
G_TYPE_UINT);
signals[KEY_RELEASED] =
g_signal_new ("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,
G_TYPE_NONE,
1,
G_TYPE_UINT);
}
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;
}
EekboardContext *
eekboard_context_new (GDBusConnection *connection,
const gchar *object_path,
GCancellable *cancellable)
{
GInitable *initable;
GError *error;
g_assert (object_path != NULL);
g_assert (G_IS_DBUS_CONNECTION(connection));
error = NULL;
initable =
g_initable_new (EEKBOARD_TYPE_CONTEXT,
cancellable,
&error,
"g-name", "com.redhat.Eekboard.Server",
"g-connection", connection,
"g-interface-name", "com.redhat.Eekboard.Context",
"g-object-path", object_path,
NULL);
if (initable != NULL)
return EEKBOARD_CONTEXT (initable);
return NULL;
}
static void
context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result)
g_variant_unref (result);
}
void
eekboard_context_set_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
GVariant *variant;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
g_return_if_fail (EEK_IS_KEYBOARD(keyboard));
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(priv->keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetKeyboard",
g_variant_new ("(v)", variant),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
context_async_ready_callback,
NULL);
g_variant_unref (variant);
}
void
eekboard_context_set_group (EekboardContext *context,
gint group,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
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,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_context_show_keyboard (EekboardContext *context,
GCancellable *cancellable)
{
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,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_context_hide_keyboard (EekboardContext *context,
GCancellable *cancellable)
{
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,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_context_press_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable)
{
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,
cancellable,
context_async_ready_callback,
NULL);
}
void
eekboard_context_release_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable)
{
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,
cancellable,
context_async_ready_callback,
NULL);
}
gboolean
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)
{
EekboardContextPrivate *priv;
g_assert (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
priv->enabled = enabled;
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* 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_CONTEXT_H
#define EEKBOARD_CONTEXT_H 1
#include <gio/gio.h>
#include "eek/eek.h"
G_BEGIN_DECLS
#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 _EekboardContext EekboardContext;
typedef struct _EekboardContextClass EekboardContextClass;
typedef struct _EekboardContextPrivate EekboardContextPrivate;
struct _EekboardContext {
GDBusProxy parent;
EekboardContextPrivate *priv;
};
struct _EekboardContextClass {
GDBusProxyClass parent_class;
void (*enabled) (EekboardContext *self);
void (*disabled) (EekboardContext *self);
void (*key_pressed) (EekboardContext *self,
guint keycode);
void (*key_released) (EekboardContext *self,
guint keycode);
};
GType eekboard_context_get_type (void) G_GNUC_CONST;
EekboardContext *eekboard_context_new (GDBusConnection *connection,
const gchar *object_path,
GCancellable *cancellable);
void eekboard_context_set_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
GCancellable *cancellable);
void eekboard_context_show_keyboard (EekboardContext *context,
GCancellable *cancellable);
void eekboard_context_hide_keyboard (EekboardContext *context,
GCancellable *cancellable);
void eekboard_context_set_group (EekboardContext *context,
gint group,
GCancellable *cancellable);
void eekboard_context_press_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable);
void eekboard_context_release_key (EekboardContext *context,
guint keycode,
GCancellable *cancellable);
gboolean eekboard_context_is_keyboard_visible
(EekboardContext *context);
void eekboard_context_set_enabled (EekboardContext *context,
gboolean enabled);
G_END_DECLS
#endif /* EEKBOARD_CONTEXT_H */

View File

@ -1,326 +0,0 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eekboard-keyboard.h"
enum {
KEY_PRESSED,
KEY_RELEASED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekboardKeyboard, eekboard_keyboard, G_TYPE_DBUS_PROXY);
#define EEKBOARD_KEYBOARD_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_KEYBOARD, EekboardKeyboardPrivate))
struct _EekboardKeyboardPrivate
{
EekKeyboard *description;
gboolean visible;
};
static void
eekboard_keyboard_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);
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
guint keycode;
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (keyboard, "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);
return;
}
if (g_strcmp0 (signal_name, "VisibilityChanged") == 0) {
g_variant_get (parameters, "(b)", &priv->visible);
return;
}
g_return_if_reached ();
}
static void
eekboard_keyboard_real_key_pressed (EekboardKeyboard *self,
guint keycode)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
if (priv->description) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->description,
keycode);
g_signal_emit_by_name (key, "pressed");
}
}
static void
eekboard_keyboard_real_key_released (EekboardKeyboard *self,
guint keycode)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
if (priv->description) {
EekKey *key = eek_keyboard_find_key_by_keycode (priv->description,
keycode);
g_signal_emit_by_name (key, "released");
}
}
static void
eekboard_keyboard_dispose (GObject *self)
{
EekboardKeyboardPrivate *priv = EEKBOARD_KEYBOARD_GET_PRIVATE (self);
if (priv->description) {
g_object_unref (priv->description);
priv->description = NULL;
}
}
static void
eekboard_keyboard_class_init (EekboardKeyboardClass *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));
klass->key_pressed = eekboard_keyboard_real_key_pressed;
klass->key_released = eekboard_keyboard_real_key_released;
proxy_class->g_signal = eekboard_keyboard_real_g_signal;
gobject_class->dispose = eekboard_keyboard_dispose;
signals[KEY_PRESSED] =
g_signal_new ("key-pressed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardKeyboardClass, key_pressed),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE,
1,
G_TYPE_UINT);
signals[KEY_RELEASED] =
g_signal_new ("key-released",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardKeyboardClass, key_released),
NULL,
NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE,
1,
G_TYPE_UINT);
}
static void
eekboard_keyboard_init (EekboardKeyboard *self)
{
EekboardKeyboardPrivate *priv;
priv = self->priv = EEKBOARD_KEYBOARD_GET_PRIVATE(self);
priv->description = NULL;
priv->visible = 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)
{
GInitable *initable;
g_assert (path != NULL);
g_assert (G_IS_DBUS_CONNECTION(connection));
initable =
g_initable_new (EEKBOARD_TYPE_KEYBOARD,
cancellable,
error,
"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,
NULL);
if (initable != NULL)
return EEKBOARD_KEYBOARD (initable);
return NULL;
}
static void
proxy_call_async_ready_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
GVariant *result;
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)
{
EekboardKeyboardPrivate *priv;
GVariant *variant;
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_return_if_fail (EEK_IS_KEYBOARD(description));
priv = EEKBOARD_KEYBOARD_GET_PRIVATE(keyboard);
if (priv->description)
g_object_unref (priv->description);
priv->description = g_object_ref (description);
variant = eek_serializable_serialize (EEK_SERIALIZABLE(description));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"SetDescription",
g_variant_new ("(v)", variant),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
g_variant_unref (variant);
}
void
eekboard_keyboard_set_group (EekboardKeyboard *keyboard,
gint group)
{
EekboardKeyboardPrivate *priv;
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
priv = EEKBOARD_KEYBOARD_GET_PRIVATE (keyboard);
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"SetGroup",
g_variant_new ("(i)", group),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
eek_keyboard_set_group (priv->description, group);
}
void
eekboard_keyboard_show (EekboardKeyboard *keyboard)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Show",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
void
eekboard_keyboard_hide (EekboardKeyboard *keyboard)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Hide",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
void
eekboard_keyboard_press_key (EekboardKeyboard *keyboard,
guint keycode)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"PressKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
void
eekboard_keyboard_release_key (EekboardKeyboard *keyboard,
guint keycode)
{
g_return_if_fail (EEKBOARD_IS_KEYBOARD(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"ReleaseKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
proxy_call_async_ready_cb,
NULL);
}
gboolean
eekboard_keyboard_get_visible (EekboardKeyboard *keyboard)
{
EekboardKeyboardPrivate *priv;
g_assert (EEKBOARD_IS_KEYBOARD(keyboard));
priv = EEKBOARD_KEYBOARD_GET_PRIVATE (keyboard);
return priv->visible;
}

View File

@ -1,71 +0,0 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* 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
#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))
typedef struct _EekboardKeyboard EekboardKeyboard;
typedef struct _EekboardKeyboardClass EekboardKeyboardClass;
typedef struct _EekboardKeyboardPrivate EekboardKeyboardPrivate;
struct _EekboardKeyboard {
GDBusProxy parent;
EekboardKeyboardPrivate *priv;
};
struct _EekboardKeyboardClass {
GDBusProxyClass parent_class;
void (*key_pressed) (EekboardKeyboard *self,
guint keycode);
void (*key_released) (EekboardKeyboard *self,
guint keycode);
};
GType eekboard_keyboard_get_type (void) G_GNUC_CONST;
EekboardKeyboard *eekboard_keyboard_new (const gchar *path,
GDBusConnection *connection,
GCancellable *cancellable,
GError **error);
void eekboard_keyboard_set_description
(EekboardKeyboard *keyboard,
EekKeyboard *description);
void eekboard_keyboard_set_group (EekboardKeyboard *keyboard,
gint group);
void eekboard_keyboard_show (EekboardKeyboard *keyboard);
void eekboard_keyboard_hide (EekboardKeyboard *keyboard);
void eekboard_keyboard_press_key (EekboardKeyboard *keyboard,
guint keycode);
void eekboard_keyboard_release_key (EekboardKeyboard *keyboard,
guint keycode);
gboolean eekboard_keyboard_get_visible (EekboardKeyboard *keyboard);
G_END_DECLS
#endif /* EEKBOARD_KEYBOARD_H */

300
eekboard/eekboard-server.c Normal file
View File

@ -0,0 +1,300 @@
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eekboard/eekboard-server.h"
G_DEFINE_TYPE (EekboardServer, eekboard_server, G_TYPE_DBUS_PROXY);
#define EEKBOARD_SERVER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_SERVER, EekboardServerPrivate))
struct _EekboardServerPrivate
{
GHashTable *context_hash;
GSList *context_stack;
/* used in eekboard_server_push_context and
eekboard_server_destroy_context as a callback data */
EekboardContext *context;
};
static void
eekboard_server_dispose (GObject *object)
{
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(object);
GSList *head;
if (priv->context_hash) {
g_hash_table_destroy (priv->context_hash);
priv->context_hash = NULL;
}
for (head = priv->context_stack; head; head = priv->context_stack) {
g_object_unref (head->data);
priv->context_stack = g_slist_next (head);
g_slist_free1 (head);
}
G_OBJECT_CLASS (eekboard_server_parent_class)->dispose (object);
}
static void
eekboard_server_class_init (EekboardServerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (gobject_class,
sizeof (EekboardServerPrivate));
gobject_class->dispose = eekboard_server_dispose;
}
static void
eekboard_server_init (EekboardServer *self)
{
EekboardServerPrivate *priv;
priv = self->priv = EEKBOARD_SERVER_GET_PRIVATE(self);
priv->context_hash =
g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)g_object_unref);
priv->context_stack = NULL;
priv->context = NULL;
}
EekboardServer *
eekboard_server_new (GDBusConnection *connection,
GCancellable *cancellable)
{
GInitable *initable;
GError *error;
g_assert (G_IS_DBUS_CONNECTION(connection));
error = NULL;
initable =
g_initable_new (EEKBOARD_TYPE_SERVER,
cancellable,
&error,
"g-connection", connection,
"g-name", "com.redhat.Eekboard.Server",
"g-interface-name", "com.redhat.Eekboard.Server",
"g-object-path", "/com/redhat/Eekboard/Server",
NULL);
if (initable != NULL)
return EEKBOARD_SERVER (initable);
return NULL;
}
EekboardContext *
eekboard_server_create_context (EekboardServer *server,
const gchar *client_name,
GCancellable *cancellable)
{
GVariant *variant;
const gchar *object_path;
EekboardContext *context;
EekboardServerPrivate *priv;
GError *error;
GDBusConnection *connection;
g_assert (EEKBOARD_IS_SERVER(server));
g_assert (client_name);
error = NULL;
variant = g_dbus_proxy_call_sync (G_DBUS_PROXY(server),
"CreateContext",
g_variant_new ("(s)", client_name),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
&error);
if (!variant)
return NULL;
g_variant_get (variant, "(&s)", &object_path);
connection = g_dbus_proxy_get_connection (G_DBUS_PROXY(server));
context = eekboard_context_new (connection, object_path, cancellable);
if (!context) {
g_variant_unref (variant);
return NULL;
}
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
g_hash_table_insert (priv->context_hash, g_strdup (object_path), context);
return context;
}
static void
push_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
g_variant_unref (result);
if (priv->context_stack)
eekboard_context_set_enabled (priv->context_stack->data, FALSE);
priv->context_stack = g_slist_prepend (priv->context_stack,
priv->context);
g_object_ref (priv->context);
eekboard_context_set_enabled (priv->context, TRUE);
}
}
void
eekboard_server_push_context (EekboardServer *server,
EekboardContext *context,
GCancellable *cancellable)
{
EekboardServerPrivate *priv;
const gchar *object_path;
g_return_if_fail (EEKBOARD_IS_SERVER(server));
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
context = g_hash_table_lookup (priv->context_hash, object_path);
if (!context)
return;
priv->context = context;
g_dbus_proxy_call (G_DBUS_PROXY(server),
"PushContext",
g_variant_new ("(s)", object_path),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
push_context_async_ready_callback,
server);
}
static void
pop_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
g_variant_unref (result);
if (priv->context_stack) {
EekboardContext *context = priv->context_stack->data;
eekboard_context_set_enabled (context, FALSE);
priv->context_stack = g_slist_next (priv->context_stack);
g_object_unref (context);
if (priv->context_stack)
eekboard_context_set_enabled (priv->context_stack->data, TRUE);
}
}
}
void
eekboard_server_pop_context (EekboardServer *server,
GCancellable *cancellable)
{
g_return_if_fail (EEKBOARD_IS_SERVER(server));
g_dbus_proxy_call (G_DBUS_PROXY(server),
"PopContext",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
pop_context_async_ready_callback,
server);
}
static void
destroy_context_async_ready_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
EekboardServer *server = user_data;
EekboardServerPrivate *priv = EEKBOARD_SERVER_GET_PRIVATE(server);
GError *error = NULL;
GVariant *result;
const gchar *object_path;
GSList *head;
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
res,
&error);
if (result) {
g_variant_unref (result);
head = g_slist_find (priv->context_stack, priv->context);
if (head) {
priv->context_stack = g_slist_remove_link (priv->context_stack,
head);
g_slist_free1 (head);
}
object_path =
g_dbus_proxy_get_object_path (G_DBUS_PROXY(priv->context));
g_hash_table_remove (priv->context_hash, object_path);
}
}
void
eekboard_server_destroy_context (EekboardServer *server,
EekboardContext *context,
GCancellable *cancellable)
{
EekboardServerPrivate *priv;
const gchar *object_path;
g_return_if_fail (EEKBOARD_IS_SERVER(server));
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
priv = EEKBOARD_SERVER_GET_PRIVATE(server);
priv->context = context;
g_dbus_proxy_call (G_DBUS_PROXY(server),
"DestroyContext",
g_variant_new ("(s)", object_path),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
destroy_context_async_ready_callback,
server);
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* 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_SERVER_H
#define EEKBOARD_SERVER_H 1
#include <gio/gio.h>
#include "eekboard/eekboard-context.h"
G_BEGIN_DECLS
#define EEKBOARD_TYPE_SERVER (eekboard_server_get_type())
#define EEKBOARD_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_SERVER, EekboardServer))
#define EEKBOARD_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_SERVER, EekboardServerClass))
#define EEKBOARD_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_SERVER))
#define EEKBOARD_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_SERVER))
#define EEKBOARD_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_SERVER, EekboardServerClass))
typedef struct _EekboardServer EekboardServer;
typedef struct _EekboardServerClass EekboardServerClass;
typedef struct _EekboardServerPrivate EekboardServerPrivate;
struct _EekboardServer {
GDBusProxy parent;
EekboardServerPrivate *priv;
};
struct _EekboardServerClass {
GDBusProxyClass parent_class;
};
GType eekboard_server_get_type (void) G_GNUC_CONST;
EekboardServer *eekboard_server_new (GDBusConnection *connection,
GCancellable *cancellable);
EekboardContext *eekboard_server_create_context (EekboardServer *server,
const gchar *client_name,
GCancellable *cancellable);
void eekboard_server_push_context (EekboardServer *server,
EekboardContext *context,
GCancellable *cancellable);
void eekboard_server_pop_context (EekboardServer *server,
GCancellable *cancellable);
void eekboard_server_destroy_context (EekboardServer *server,
EekboardContext *context,
GCancellable *cancellable);
G_END_DECLS
#endif /* EEKBOARD_SERVER_H */

View File

@ -18,6 +18,7 @@
#ifndef EEKBOARD_H
#define EEKBOARD_H 1
#include "eekboard/eekboard-keyboard.h"
#include "eekboard/eekboard-server.h"
#include "eekboard/eekboard-context.h"
#endif /* EEKBOARD_H */