Commit 6bbbe27c authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Add eekboard-client.

parent 5cb5e057
......@@ -17,7 +17,7 @@
# 02110-1301 USA
if ENABLE_EEKBOARD
bin_PROGRAMS = eekboard-system-client eekboard-server
bin_PROGRAMS = eekboard-system-client eekboard-client eekboard-server
noinst_LIBRARIES = libeekboard.a
libeekboard_a_headers = proxy.h
......@@ -73,8 +73,20 @@ eekboard_server_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
eekboard_server_LDADD += $(CLUTTER_LIBS) $(top_builddir)/eek/libeek-clutter.la $(CLUTTER_GTK_LIBS)
endif
eekboard_client_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS)
eekboard_client_LDADD = \
libeekboard.a \
$(top_builddir)/eek/libeek.la \
$(GIO2_LIBS)
eekboard_client_SOURCES = client-main.c
noinst_HEADERS = \
$(libeekboard_a_headers) \
$(eekboard_system_client_headers) \
$(eekboard_client_headers) \
$(eekboard_server_headers)
endif
/*
* 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 "proxy.h"
static gchar *opt_set_keyboard = NULL;
static gboolean opt_show = FALSE;
static gboolean opt_hide = FALSE;
static gboolean opt_listen = FALSE;
static const GOptionEntry options[] = {
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
"Set keyboard from an XML file"},
{"show", '\0', 0, G_OPTION_ARG_NONE, &opt_show,
"Show keyboard"},
{"hide", '\0', 0, G_OPTION_ARG_NONE, &opt_hide,
"Hide keyboard"},
{"listen", '\0', 0, G_OPTION_ARG_NONE, &opt_listen,
"Listen events"},
{NULL}
};
static void
on_key_pressed (guint keycode, gpointer user_data)
{
g_print ("KeyPressed %u\n", keycode);
}
static void
on_key_released (guint keycode, gpointer user_data)
{
g_print ("KeyReleased %u\n", keycode);
}
int
main (int argc, char **argv)
{
EekboardProxy *proxy = NULL;
GDBusConnection *connection = NULL;
GError *error;
GOptionContext *context;
GMainLoop *loop = NULL;
gint retval = 0;
g_type_init ();
context = g_option_context_new ("eekboard-client");
g_option_context_add_main_entries (context, options, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (error) {
g_printerr ("%s\n", error->message);
retval = 1;
goto out;
}
error = NULL;
proxy = eekboard_proxy_new ("/com/redhat/eekboard/Keyboard",
connection,
NULL,
&error);
if (error) {
g_printerr ("%s\n", error->message);
retval = 1;
goto out;
}
if (opt_set_keyboard) {
GFile *file;
GFileInputStream *input;
EekLayout *layout;
EekKeyboard *keyboard;
GError *error;
file = g_file_new_for_path (opt_set_keyboard);
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);
retval = 1;
goto out;
}
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
g_object_unref (input);
keyboard = eek_keyboard_new (layout, 640, 480);
g_object_unref (layout);
eekboard_proxy_set_keyboard (proxy, keyboard);
g_object_unref (keyboard);
}
if (opt_show) {
eekboard_proxy_show (proxy);
}
if (opt_hide) {
eekboard_proxy_hide (proxy);
}
if (opt_listen) {
g_signal_connect (proxy, "key-pressed",
G_CALLBACK(on_key_pressed), NULL);
g_signal_connect (proxy, "key-released",
G_CALLBACK(on_key_released), NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
}
out:
if (proxy)
g_object_unref (proxy);
if (connection)
g_object_unref (connection);
if (loop)
g_main_loop_unref (loop);
return retval;
}
......@@ -50,7 +50,6 @@ eekboard_proxy_real_g_signal (GDBusProxy *self,
EekboardProxy *proxy = EEKBOARD_PROXY (self);
guint *keycode;
g_debug ("%s %s", sender_name, signal_name);
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
g_variant_get (parameters, "(u)", &keycode);
......
......@@ -48,18 +48,18 @@ main (int argc, char **argv)
server = eekboard_server_new (connection);
loop = g_main_loop_new(NULL, FALSE);
if (!eekboard_server_start (server)) {
g_printerr ("Can't start server\n");
exit (1);
}
g_main_loop_run(loop);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
eekboard_server_stop (server);
g_object_unref(server);
g_object_unref(connection);
g_main_loop_unref(loop);
g_object_unref (server);
g_object_unref (connection);
g_main_loop_unref (loop);
return 0;
}
......@@ -236,7 +236,7 @@ handle_method_call (GDBusConnection *connection,
{
EekboardServer *server = user_data;
g_debug ("%s", method_name);
// g_debug ("%s", method_name);
if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
GVariant *variant;
gchar *data;
......@@ -269,31 +269,50 @@ handle_method_call (GDBusConnection *connection,
update_widget (server);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "SetGroup") == 0) {
return;
}
if (g_strcmp0 (method_name, "SetGroup") == 0) {
gint group;
if (!server->keyboard)
if (!server->keyboard) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"keyboard is not set");
return;
}
g_variant_get (parameters, "(i)", &group);
eek_keyboard_set_group (server->keyboard, group);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "Show") == 0) {
if (!server->keyboard)
return;
}
if (g_strcmp0 (method_name, "Show") == 0) {
if (!server->keyboard) {
g_dbus_method_invocation_return_error (invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"keyboard is not set");
return;
}
if (server->window)
gtk_widget_show_all (server->window);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "Hide") == 0) {
return;
}
if (g_strcmp0 (method_name, "Hide") == 0) {
if (server->window)
gtk_widget_hide (server->window);
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
g_return_if_reached ();
}
static const GDBusInterfaceVTable interface_vtable =
......@@ -308,7 +327,7 @@ on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
//g_debug ("name acquired %s", name);
// g_debug ("name acquired %s", name);
}
static void
......@@ -316,7 +335,7 @@ on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
//g_debug ("name lost %s", name);
// g_debug ("name lost %s", name);
}
EekboardServer *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment