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

Rename EekboardDevice to EekboardKeyboard.

parent 22a51a28
......@@ -18,8 +18,8 @@
lib_LTLIBRARIES = libeekboard.la
libeekboard_headers = eekboard.h eekboard-device.h
libeekboard_sources = eekboard-device.c
libeekboard_headers = eekboard.h eekboard-keyboard.h
libeekboard_sources = eekboard-keyboard.c
libeekboard_la_SOURCES = $(libeekboard_sources)
libeekboard_la_CFLAGS = -I$(top_srcdir) $(GIO2_CFLAGS)
......
/*
* 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_DEVICE_H
#define EEKBOARD_DEVICE_H 1
#include <gio/gio.h>
#include "eek/eek.h"
G_BEGIN_DECLS
#define EEKBOARD_TYPE_DEVICE (eekboard_device_get_type())
#define EEKBOARD_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_DEVICE, EekboardDevice))
#define EEKBOARD_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_DEVICE, EekboardDeviceClass))
#define EEKBOARD_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_DEVICE))
#define EEKBOARD_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_DEVICE))
#define EEKBOARD_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_DEVICE, EekboardDeviceClass))
typedef struct _EekboardDevice EekboardDevice;
typedef struct _EekboardDeviceClass EekboardDeviceClass;
EekboardDevice *eekboard_device_new (const gchar *path,
GDBusConnection *connection,
GCancellable *cancellable,
GError **error);
void eekboard_device_set_keyboard (EekboardDevice *device,
EekKeyboard *keyboard);
void eekboard_device_set_group (EekboardDevice *device,
gint group);
void eekboard_device_show (EekboardDevice *device);
void eekboard_device_hide (EekboardDevice *device);
void eekboard_device_press_key (EekboardDevice *device,
guint keycode);
void eekboard_device_release_key (EekboardDevice *device,
guint keycode);
G_END_DECLS
#endif /* EEKBOARD_DEVICE_H */
......@@ -19,7 +19,7 @@
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eekboard-device.h"
#include "eekboard-keyboard.h"
enum {
KEY_PRESSED,
......@@ -29,35 +29,35 @@ enum {
static guint signals[LAST_SIGNAL] = { 0, };
struct _EekboardDevice {
struct _EekboardKeyboard {
GDBusProxy parent;
};
struct _EekboardDeviceClass {
struct _EekboardKeyboardClass {
GDBusProxyClass parent_class;
};
G_DEFINE_TYPE (EekboardDevice, eekboard_device, G_TYPE_DBUS_PROXY);
G_DEFINE_TYPE (EekboardKeyboard, eekboard_keyboard, G_TYPE_DBUS_PROXY);
static void
eekboard_device_real_g_signal (GDBusProxy *self,
eekboard_keyboard_real_g_signal (GDBusProxy *self,
const gchar *sender_name,
const gchar *signal_name,
GVariant *parameters)
{
EekboardDevice *device = EEKBOARD_DEVICE (self);
EekboardKeyboard *keyboard = EEKBOARD_KEYBOARD (self);
guint *keycode;
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (device, "key-pressed", keycode);
g_signal_emit_by_name (keyboard, "key-pressed", keycode);
return;
}
if (g_strcmp0 (signal_name, "KeyReleased") == 0) {
g_variant_get (parameters, "(u)", &keycode);
g_signal_emit_by_name (device, "key-released", keycode);
g_signal_emit_by_name (keyboard, "key-released", keycode);
return;
}
......@@ -65,12 +65,12 @@ eekboard_device_real_g_signal (GDBusProxy *self,
}
static void
eekboard_device_class_init (EekboardDeviceClass *klass)
eekboard_keyboard_class_init (EekboardKeyboardClass *klass)
{
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
proxy_class->g_signal = eekboard_device_real_g_signal;
proxy_class->g_signal = eekboard_keyboard_real_g_signal;
signals[KEY_PRESSED] =
g_signal_new ("key-pressed",
......@@ -98,15 +98,15 @@ eekboard_device_class_init (EekboardDeviceClass *klass)
}
static void
eekboard_device_init (EekboardDevice *device)
eekboard_keyboard_init (EekboardKeyboard *keyboard)
{
}
EekboardDevice *
eekboard_device_new (const gchar *path,
GDBusConnection *connection,
GCancellable *cancellable,
GError **error)
EekboardKeyboard *
eekboard_keyboard_new (const gchar *path,
GDBusConnection *connection,
GCancellable *cancellable,
GError **error)
{
GInitable *initable;
......@@ -114,18 +114,18 @@ eekboard_device_new (const gchar *path,
g_assert (G_IS_DBUS_CONNECTION(connection));
initable =
g_initable_new (EEKBOARD_TYPE_DEVICE,
g_initable_new (EEKBOARD_TYPE_KEYBOARD,
cancellable,
error,
"g-connection", connection,
"g-name", "com.redhat.eekboard.Device",
"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.Device",
"g-interface-name", "com.redhat.eekboard.Keyboard",
"g-object-path", path,
NULL);
if (initable != NULL)
return EEKBOARD_DEVICE (initable);
return EEKBOARD_KEYBOARD (initable);
return NULL;
}
......@@ -146,13 +146,14 @@ proxy_call_async_ready_cb (GObject *source_object,
}
void
eekboard_device_set_keyboard (EekboardDevice *device, EekKeyboard *keyboard)
eekboard_keyboard_set_description (EekboardKeyboard *keyboard,
EekKeyboard *description)
{
GVariant *variant;
variant = eek_serializable_serialize (EEK_SERIALIZABLE(keyboard));
g_dbus_proxy_call (G_DBUS_PROXY(device),
"SetKeyboard",
variant = eek_serializable_serialize (description);
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"SetDescription",
g_variant_new ("(v)", variant),
G_DBUS_CALL_FLAGS_NONE,
-1,
......@@ -163,10 +164,10 @@ eekboard_device_set_keyboard (EekboardDevice *device, EekKeyboard *keyboard)
}
void
eekboard_device_set_group (EekboardDevice *device,
gint group)
eekboard_keyboard_set_group (EekboardKeyboard *keyboard,
gint group)
{
g_dbus_proxy_call (G_DBUS_PROXY(device),
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"SetGroup",
g_variant_new ("(i)", group),
G_DBUS_CALL_FLAGS_NONE,
......@@ -177,9 +178,9 @@ eekboard_device_set_group (EekboardDevice *device,
}
void
eekboard_device_show (EekboardDevice *device)
eekboard_keyboard_show (EekboardKeyboard *keyboard)
{
g_dbus_proxy_call (G_DBUS_PROXY(device),
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Show",
NULL,
G_DBUS_CALL_FLAGS_NONE,
......@@ -190,9 +191,9 @@ eekboard_device_show (EekboardDevice *device)
}
void
eekboard_device_hide (EekboardDevice *device)
eekboard_keyboard_hide (EekboardKeyboard *keyboard)
{
g_dbus_proxy_call (G_DBUS_PROXY(device),
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"Hide",
NULL,
G_DBUS_CALL_FLAGS_NONE,
......@@ -203,10 +204,10 @@ eekboard_device_hide (EekboardDevice *device)
}
void
eekboard_device_press_key (EekboardDevice *device,
guint keycode)
eekboard_keyboard_press_key (EekboardKeyboard *keyboard,
guint keycode)
{
g_dbus_proxy_call (G_DBUS_PROXY(device),
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"PressKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
......@@ -217,10 +218,10 @@ eekboard_device_press_key (EekboardDevice *device,
}
void
eekboard_device_release_key (EekboardDevice *device,
guint keycode)
eekboard_keyboard_release_key (EekboardKeyboard *keyboard,
guint keycode)
{
g_dbus_proxy_call (G_DBUS_PROXY(device),
g_dbus_proxy_call (G_DBUS_PROXY(keyboard),
"ReleaseKey",
g_variant_new ("(u)", keycode),
G_DBUS_CALL_FLAGS_NONE,
......
/*
* 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;
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);
G_END_DECLS
#endif /* EEKBOARD_KEYBOARD_H */
......@@ -18,6 +18,6 @@
#ifndef EEKBOARD_H
#define EEKBOARD_H 1
#include "eekboard/eekboard-device.h"
#include "eekboard/eekboard-keyboard.h"
#endif /* EEKBOARD_H */
......@@ -21,7 +21,7 @@
#include "eekboard/eekboard.h"
static gchar *opt_set_keyboard = NULL;
static gchar *opt_set_description = NULL;
static gint opt_set_group = -1;
static gboolean opt_show = FALSE;
static gboolean opt_hide = FALSE;
......@@ -30,7 +30,7 @@ static gint opt_release_key = -1;
static gboolean opt_listen = FALSE;
static const GOptionEntry options[] = {
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_description,
"Set keyboard from an XML file"},
{"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
"Set group of the keyboard"},
......@@ -62,7 +62,7 @@ on_key_released (guint keycode, gpointer user_data)
int
main (int argc, char **argv)
{
EekboardDevice *device = NULL;
EekboardKeyboard *keyboard = NULL;
GDBusConnection *connection = NULL;
GError *error;
GOptionContext *context;
......@@ -86,7 +86,7 @@ main (int argc, char **argv)
}
error = NULL;
device = eekboard_device_new ("/com/redhat/eekboard/Device",
keyboard = eekboard_keyboard_new ("/com/redhat/eekboard/Keyboard",
connection,
NULL,
&error);
......@@ -96,64 +96,64 @@ main (int argc, char **argv)
goto out;
}
if (opt_set_keyboard) {
if (opt_set_description) {
GFile *file;
GFileInputStream *input;
EekLayout *layout;
EekKeyboard *keyboard;
EekKeyboard *description;
GError *error;
file = g_file_new_for_path (opt_set_keyboard);
file = g_file_new_for_path (opt_set_description);
error = NULL;
input = g_file_read (file, NULL, &error);
if (error) {
g_printerr ("Can't read file %s: %s\n",
opt_set_keyboard, error->message);
opt_set_description, error->message);
retval = 1;
goto out;
}
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
g_object_unref (input);
keyboard = eek_keyboard_new (layout, 640, 480);
description = eek_keyboard_new (layout, 640, 480);
g_object_unref (layout);
eekboard_device_set_keyboard (device, keyboard);
g_object_unref (keyboard);
eekboard_keyboard_set_description (keyboard, description);
g_object_unref (description);
}
if (opt_set_group >= 0) {
eekboard_device_set_group (device, opt_set_group);
eekboard_keyboard_set_group (keyboard, opt_set_group);
}
if (opt_show) {
eekboard_device_show (device);
eekboard_keyboard_show (keyboard);
}
if (opt_hide) {
eekboard_device_hide (device);
eekboard_keyboard_hide (keyboard);
}
if (opt_press_key >= 0) {
eekboard_device_press_key (device, opt_press_key);
eekboard_keyboard_press_key (keyboard, opt_press_key);
}
if (opt_release_key >= 0) {
eekboard_device_release_key (device, opt_release_key);
eekboard_keyboard_release_key (keyboard, opt_release_key);
}
if (opt_listen) {
g_signal_connect (device, "key-pressed",
g_signal_connect (keyboard, "key-pressed",
G_CALLBACK(on_key_pressed), NULL);
g_signal_connect (device, "key-released",
g_signal_connect (keyboard, "key-released",
G_CALLBACK(on_key_released), NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
}
out:
if (device)
g_object_unref (device);
if (keyboard)
g_object_unref (keyboard);
if (connection)
g_object_unref (connection);
if (loop)
......
......@@ -43,9 +43,9 @@ enum {
static const gchar introspection_xml[] =
"<node>"
" <interface name='com.redhat.eekboard.Device'>"
" <method name='SetKeyboard'>"
" <arg type='v' name='keyboard'/>"
" <interface name='com.redhat.eekboard.Keyboard'>"
" <method name='SetDescription'>"
" <arg type='v' name='description'/>"
" </method>"
" <method name='SetGroup'>"
" <arg type='i' name='group'/>"
......@@ -253,9 +253,9 @@ on_key_pressed (EekKeyboard *keyboard,
error = NULL;
g_dbus_connection_emit_signal (server->connection,
"com.redhat.eekboard.Device",
"/com/redhat/eekboard/Device",
"com.redhat.eekboard.Device",
"com.redhat.eekboard.Keyboard",
"/com/redhat/eekboard/Keyboard",
"com.redhat.eekboard.Keyboard",
"KeyPressed",
g_variant_new ("(u)",
eek_key_get_keycode (key)),
......@@ -273,9 +273,9 @@ on_key_released (EekKeyboard *keyboard,
error = NULL;
g_dbus_connection_emit_signal (server->connection,
"com.redhat.eekboard.Device",
"/com/redhat/eekboard/Device",
"com.redhat.eekboard.Device",
"com.redhat.eekboard.Keyboard",
"/com/redhat/eekboard/Keyboard",
"com.redhat.eekboard.Keyboard",
"KeyReleased",
g_variant_new ("(u)",
eek_key_get_keycode (key)),
......@@ -309,7 +309,7 @@ handle_method_call (GDBusConnection *connection,
EekboardServer *server = user_data;
// g_debug ("%s", method_name);
if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
if (g_strcmp0 (method_name, "SetDescription") == 0) {
EekSerializable *serializable;
GVariant *variant;
gchar *data;
......@@ -481,7 +481,7 @@ eekboard_server_start (EekboardServer *server)
error = NULL;
registration_id = g_dbus_connection_register_object
(server->connection,
"/com/redhat/eekboard/Device",
"/com/redhat/eekboard/Keyboard",
server->introspection_data->interfaces[0],
&interface_vtable,
server,
......@@ -493,7 +493,7 @@ eekboard_server_start (EekboardServer *server)
server->owner_id =
g_bus_own_name_on_connection (server->connection,
"com.redhat.eekboard.Device",
"com.redhat.eekboard.Keyboard",
G_BUS_NAME_OWNER_FLAGS_NONE,
on_name_acquired,
on_name_lost,
......
......@@ -50,9 +50,9 @@ typedef struct _EekboardSystemClientClass EekboardSystemClientClass;
struct _EekboardSystemClient {
GObject parent;
EekboardDevice *device;
EekboardKeyboard *keyboard;
EekKeyboard *keyboard;
EekKeyboard *description;
GdkDisplay *display;
XklEngine *xkl_engine;
XklConfigRegistry *xkl_config_registry;
......@@ -101,7 +101,7 @@ static SPIBoolean keystroke_listener_cb
(const AccessibleKeystroke *stroke,
void *user_data);
#endif /* HAVE_CSPI */
static void set_keyboard (EekboardSystemClient *client);
static void set_description (EekboardSystemClient *client);
static void
eekboard_system_client_set_property (GObject *object,
......@@ -117,7 +117,7 @@ eekboard_system_client_set_property (GObject *object,
case PROP_CONNECTION:
connection = g_value_get_object (value);
error = NULL;
client->device = eekboard_device_new ("/com/redhat/eekboard/Device",
client->keyboard = eekboard_keyboard_new ("/com/redhat/eekboard/Keyboard",
connection,
NULL,
&error);
......@@ -146,9 +146,14 @@ eekboard_system_client_dispose (GObject *object)
eekboard_system_client_disable_fakekey (client);
#endif /* HAVE_FAKEKEY */
if (client->device) {
g_object_unref (client->device);
client->device = NULL;
if (client->keyboard) {
g_object_unref (client->keyboard);
client->keyboard = NULL;
}
if (client->description) {
g_object_unref (client->description);
client->description = NULL;
}
#ifdef HAVE_FAKEKEY
......@@ -191,7 +196,7 @@ eekboard_system_client_init (EekboardSystemClient *client)
client->display = NULL;
client->xkl_engine = NULL;
client->xkl_config_registry = NULL;
client->device = NULL;
client->description = NULL;
client->key_pressed_handler = 0;
client->key_released_handler = 0;
client->xkl_config_changed_handler = 0;
......@@ -241,7 +246,7 @@ eekboard_system_client_enable_xkl (EekboardSystemClient *client)
xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
set_keyboard (client);
set_description (client);
return TRUE;
}
......@@ -337,12 +342,12 @@ focus_listener_cb (const AccessibleEvent *event,
case SPI_ROLE_TERMINAL:
case SPI_ROLE_ENTRY:
if (g_strcmp0 (event->type, "focus") == 0 || event->detail1 == 1)
eekboard_device_show (client->device);
eekboard_keyboard_show (client->keyboard);
default:
;
}
} else
eekboard_device_hide (client->device);
eekboard_keyboard_hide (client->keyboard);
return FALSE;
}
......@@ -356,7 +361,8 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
/* Ignore modifiers since the keystroke listener does not called
when a modifier key is released. */
key = eek_keyboard_find_key_by_keycode (client->keyboard, stroke->keycode);
key = eek_keyboard_find_key_by_keycode (client->description,
stroke->keycode);
if (key) {
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (symbol && eek_symbol_is_modifier (symbol))
......@@ -364,9 +370,9 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
}
if (stroke->type == SPI_KEY_PRESSED)
eekboard_device_press_key (client->device, stroke->keycode);
eekboard_keyboard_press_key (client->keyboard, stroke->keycode);
else
eekboard_device_release_key (client->device, stroke->keycode);
eekboard_keyboard_release_key (client->keyboard, stroke->keycode);
return TRUE;
}
#endif /* HAVE_CSPI */
......@@ -397,7 +403,7 @@ on_xkl_config_changed (XklEngine *xklengine,
{
EekboardSystemClient *client = user_data;
set_keyboard (client);
set_description (client);
#ifdef HAVE_FAKEKEY
if (client->fakekey)
......@@ -406,23 +412,23 @@ on_xkl_config_changed (XklEngine *xklengine,
}
static void
set_keyboard (EekboardSystemClient *client)
set_description (EekboardSystemClient *client)
{
EekLayout *layout;
gchar *keyboard_name;
static gint keyboard_serial = 0;
if (client->keyboard)
g_object_unref (client->keyboard);
if (client->description)
g_object_unref (client->description);
layout = eek_xkl_layout_new ();
client->keyboard = eek_keyboard_new (layout, CSW, CSH);
eek_keyboard_set_modifier_behavior (client->keyboard,
client->description = eek_keyboard_new (layout, CSW, CSH);
eek_keyboard_set_modifier_behavior (client->description,
EEK_MODIFIER_BEHAVIOR_LATCH);