Allow the server to have multiple input contexts.
This commit is contained in:
@ -68,8 +68,8 @@ eekboard_server_LDADD = \
|
||||
$(GIO2_LIBS) \
|
||||
$(GTK_LIBS)
|
||||
|
||||
eekboard_server_headers = server.h
|
||||
eekboard_server_SOURCES = server.c server-main.c
|
||||
eekboard_server_headers = server-server.h server-context.h
|
||||
eekboard_server_SOURCES = server-server.c server-context.c server-main.c
|
||||
|
||||
if ENABLE_CLUTTER
|
||||
eekboard_server_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
|
||||
|
||||
@ -21,22 +21,22 @@
|
||||
|
||||
#include "eekboard/eekboard.h"
|
||||
|
||||
static gchar *opt_set_description = NULL;
|
||||
static gchar *opt_set_keyboard = NULL;
|
||||
static gint opt_set_group = -1;
|
||||
static gboolean opt_show = FALSE;
|
||||
static gboolean opt_hide = FALSE;
|
||||
static gboolean opt_show_keyboard = FALSE;
|
||||
static gboolean opt_hide_keyboard = FALSE;
|
||||
static gint opt_press_key = -1;
|
||||
static gint opt_release_key = -1;
|
||||
static gboolean opt_listen = FALSE;
|
||||
|
||||
static const GOptionEntry options[] = {
|
||||
{"set-description", '\0', 0, G_OPTION_ARG_STRING, &opt_set_description,
|
||||
"Set keyboard description from an XML file"},
|
||||
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
|
||||
"Set keyboard keyboard from an XML file"},
|
||||
{"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
|
||||
"Set group of the keyboard"},
|
||||
{"show", '\0', 0, G_OPTION_ARG_NONE, &opt_show,
|
||||
{"show-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_show_keyboard,
|
||||
"Show keyboard"},
|
||||
{"hide", '\0', 0, G_OPTION_ARG_NONE, &opt_hide,
|
||||
{"hide-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_hide_keyboard,
|
||||
"Hide keyboard"},
|
||||
{"press-key", '\0', 0, G_OPTION_ARG_INT, &opt_press_key,
|
||||
"Press key"},
|
||||
@ -62,20 +62,21 @@ on_key_released (guint keycode, gpointer user_data)
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
EekboardKeyboard *keyboard = NULL;
|
||||
EekboardServer *server = NULL;
|
||||
EekboardContext *context = NULL;
|
||||
GDBusConnection *connection = NULL;
|
||||
GError *error;
|
||||
GOptionContext *context;
|
||||
GOptionContext *option_context;
|
||||
GMainLoop *loop = NULL;
|
||||
gint retval = 0;
|
||||
|
||||
g_type_init ();
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
|
||||
|
||||
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);
|
||||
option_context = g_option_context_new ("eekboard-client");
|
||||
g_option_context_add_main_entries (option_context, options, NULL);
|
||||
g_option_context_parse (option_context, &argc, &argv, NULL);
|
||||
g_option_context_free (option_context);
|
||||
|
||||
error = NULL;
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
@ -85,75 +86,82 @@ main (int argc, char **argv)
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = NULL;
|
||||
keyboard = eekboard_keyboard_new ("/com/redhat/Eekboard/Keyboard",
|
||||
connection,
|
||||
NULL,
|
||||
&error);
|
||||
if (error) {
|
||||
g_printerr ("%s\n", error->message);
|
||||
server = eekboard_server_new (connection, NULL);
|
||||
if (!server) {
|
||||
g_printerr ("Can't create server\n");
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opt_set_description) {
|
||||
context = eekboard_server_create_context (server,
|
||||
"eekboard-client",
|
||||
NULL);
|
||||
if (!context) {
|
||||
g_printerr ("Can't create context\n");
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
eekboard_server_push_context (server, context, NULL);
|
||||
|
||||
if (opt_set_keyboard) {
|
||||
GFile *file;
|
||||
GFileInputStream *input;
|
||||
EekLayout *layout;
|
||||
EekKeyboard *description;
|
||||
GError *error;
|
||||
EekKeyboard *keyboard;
|
||||
|
||||
file = g_file_new_for_path (opt_set_description);
|
||||
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_description, error->message);
|
||||
opt_set_keyboard, error->message);
|
||||
retval = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
|
||||
g_object_unref (input);
|
||||
description = eek_keyboard_new (layout, 640, 480);
|
||||
keyboard = eek_keyboard_new (layout, 640, 480);
|
||||
g_object_unref (layout);
|
||||
eekboard_keyboard_set_description (keyboard, description);
|
||||
g_object_unref (description);
|
||||
|
||||
eekboard_context_set_keyboard (context, keyboard, NULL);
|
||||
g_object_unref (keyboard);
|
||||
}
|
||||
|
||||
if (opt_set_group >= 0) {
|
||||
eekboard_keyboard_set_group (keyboard, opt_set_group);
|
||||
eekboard_context_set_group (context, opt_set_group, NULL);
|
||||
}
|
||||
|
||||
if (opt_show) {
|
||||
eekboard_keyboard_show (keyboard);
|
||||
if (opt_show_keyboard) {
|
||||
eekboard_context_show_keyboard (context, NULL);
|
||||
}
|
||||
|
||||
if (opt_hide) {
|
||||
eekboard_keyboard_hide (keyboard);
|
||||
if (opt_hide_keyboard) {
|
||||
eekboard_context_hide_keyboard (context, NULL);
|
||||
}
|
||||
|
||||
if (opt_press_key >= 0) {
|
||||
eekboard_keyboard_press_key (keyboard, opt_press_key);
|
||||
eekboard_context_press_key (context, opt_press_key, NULL);
|
||||
}
|
||||
|
||||
if (opt_release_key >= 0) {
|
||||
eekboard_keyboard_release_key (keyboard, opt_release_key);
|
||||
eekboard_context_release_key (context, opt_release_key, NULL);
|
||||
}
|
||||
|
||||
if (opt_listen) {
|
||||
g_signal_connect (keyboard, "key-pressed",
|
||||
g_signal_connect (context, "key-pressed",
|
||||
G_CALLBACK(on_key_pressed), NULL);
|
||||
g_signal_connect (keyboard, "key-released",
|
||||
g_signal_connect (context, "key-released",
|
||||
G_CALLBACK(on_key_released), NULL);
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
}
|
||||
|
||||
out:
|
||||
if (keyboard)
|
||||
g_object_unref (keyboard);
|
||||
if (context)
|
||||
g_object_unref (context);
|
||||
if (connection)
|
||||
g_object_unref (connection);
|
||||
if (loop)
|
||||
|
||||
619
src/server-context.c
Normal file
619
src/server-context.c
Normal file
@ -0,0 +1,619 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include "eek/eek.h"
|
||||
|
||||
#if HAVE_CLUTTER_GTK
|
||||
#include <clutter-gtk/clutter-gtk.h>
|
||||
#include "eek/eek-clutter.h"
|
||||
#else /* HAVE_CLUTTER_GTK */
|
||||
#include "eek/eek-gtk.h"
|
||||
#endif /* !HAVE_CLUTTER_GTK */
|
||||
|
||||
#include "server-context.h"
|
||||
|
||||
#define CSW 640
|
||||
#define CSH 480
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_CONNECTION,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
static const gchar introspection_xml[] =
|
||||
"<node>"
|
||||
" <interface name='com.redhat.Eekboard.Context'>"
|
||||
" <method name='SetKeyboard'>"
|
||||
" <arg type='v' name='keyboard'/>"
|
||||
" </method>"
|
||||
" <method name='ShowKeyboard'/>"
|
||||
" <method name='HideKeyboard'/>"
|
||||
" <method name='SetGroup'>"
|
||||
" <arg type='i' name='group'/>"
|
||||
" </method>"
|
||||
" <method name='PressKey'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </method>"
|
||||
" <method name='ReleaseKey'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </method>"
|
||||
/* signals */
|
||||
" <signal name='Enabled'/>"
|
||||
" <signal name='Disabled'/>"
|
||||
" <signal name='KeyPressed'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </signal>"
|
||||
" <signal name='KeyReleased'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </signal>"
|
||||
" <signal name='KeyboardVisibilityChanged'>"
|
||||
" <arg type='b' name='visible'/>"
|
||||
" </signal>"
|
||||
" </interface>"
|
||||
"</node>";
|
||||
|
||||
typedef struct _ServerContextClass ServerContextClass;
|
||||
|
||||
struct _ServerContext {
|
||||
GObject parent;
|
||||
GDBusConnection *connection;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
guint registration_id;
|
||||
char *object_path;
|
||||
|
||||
gboolean enabled;
|
||||
|
||||
GtkWidget *window;
|
||||
GtkWidget *widget;
|
||||
EekKeyboard *keyboard;
|
||||
|
||||
gulong key_pressed_handler;
|
||||
gulong key_released_handler;
|
||||
};
|
||||
|
||||
struct _ServerContextClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ServerContext, server_context, G_TYPE_OBJECT);
|
||||
|
||||
static void disconnect_keyboard_signals (ServerContext *context);
|
||||
static void handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data);
|
||||
|
||||
static const GDBusInterfaceVTable interface_vtable =
|
||||
{
|
||||
handle_method_call,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
#if HAVE_CLUTTER_GTK
|
||||
static void
|
||||
on_allocation_changed (ClutterActor *stage,
|
||||
ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags,
|
||||
gpointer user_data)
|
||||
{
|
||||
ClutterActor *actor = user_data;
|
||||
clutter_actor_set_size (actor,
|
||||
box->x2 - box->x1,
|
||||
box->y2 - box->y1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
on_destroy (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
ServerContext *context = user_data;
|
||||
|
||||
g_assert (widget == context->window);
|
||||
context->window = NULL;
|
||||
context->widget = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
on_notify_visible (GObject *object, GParamSpec *spec, gpointer user_data)
|
||||
{
|
||||
ServerContext *context = user_data;
|
||||
gboolean visible;
|
||||
GError *error;
|
||||
|
||||
g_object_get (object, "visible", &visible, NULL);
|
||||
|
||||
if (context->connection && context->enabled) {
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (context->connection,
|
||||
NULL,
|
||||
context->object_path,
|
||||
SERVER_CONTEXT_INTERFACE,
|
||||
"KeyboardVisibilityChanged",
|
||||
g_variant_new ("(b)", visible),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_widget (ServerContext *context)
|
||||
{
|
||||
GdkScreen *screen;
|
||||
GdkWindow *root;
|
||||
gint monitor;
|
||||
GdkRectangle rect;
|
||||
EekBounds bounds;
|
||||
#if HAVE_CLUTTER_GTK
|
||||
ClutterActor *stage, *actor;
|
||||
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
|
||||
#endif
|
||||
|
||||
if (context->widget)
|
||||
gtk_widget_destroy (context->widget);
|
||||
|
||||
if (context->window)
|
||||
gtk_widget_destroy (context->window);
|
||||
|
||||
eek_element_get_bounds (EEK_ELEMENT(context->keyboard), &bounds);
|
||||
#if HAVE_CLUTTER_GTK
|
||||
context->widget = gtk_clutter_embed_new ();
|
||||
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
|
||||
actor = eek_clutter_context_new (context->keyboard);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
|
||||
|
||||
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
|
||||
clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), TRUE);
|
||||
clutter_stage_set_minimum_size (CLUTTER_STAGE(stage),
|
||||
bounds.width / 3,
|
||||
bounds.height / 3);
|
||||
g_signal_connect (stage,
|
||||
"allocation-changed",
|
||||
G_CALLBACK(on_allocation_changed),
|
||||
actor);
|
||||
#else
|
||||
context->widget = eek_gtk_keyboard_new (context->keyboard);
|
||||
#endif
|
||||
gtk_widget_set_size_request (context->widget, bounds.width, bounds.height);
|
||||
|
||||
context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect (context->window, "destroy",
|
||||
G_CALLBACK(on_destroy), context);
|
||||
g_signal_connect (context->window, "notify::visible",
|
||||
G_CALLBACK(on_notify_visible), context);
|
||||
gtk_container_add (GTK_CONTAINER(context->window), context->widget);
|
||||
|
||||
gtk_widget_set_can_focus (context->window, FALSE);
|
||||
g_object_set (G_OBJECT(context->window), "accept_focus", FALSE, NULL);
|
||||
gtk_window_set_title (GTK_WINDOW(context->window), "Context");
|
||||
gtk_window_set_keep_above (GTK_WINDOW(context->window), TRUE);
|
||||
|
||||
screen = gdk_screen_get_default ();
|
||||
root = gtk_widget_get_root_window (context->window);
|
||||
monitor = gdk_screen_get_monitor_at_window (screen, root);
|
||||
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
||||
gtk_window_move (GTK_WINDOW(context->window),
|
||||
MAX(rect.width - 20 - bounds.width, 0),
|
||||
MAX(rect.height - 40 - bounds.height, 0));
|
||||
}
|
||||
|
||||
static void
|
||||
server_context_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ServerContext *context = SERVER_CONTEXT(object);
|
||||
GDBusConnection *connection;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_OBJECT_PATH:
|
||||
if (context->object_path)
|
||||
g_free (context->object_path);
|
||||
context->object_path = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_CONNECTION:
|
||||
connection = g_value_get_object (value);
|
||||
if (context->connection)
|
||||
g_object_unref (context->connection);
|
||||
context->connection = g_object_ref (connection);
|
||||
break;
|
||||
default:
|
||||
g_object_set_property (object,
|
||||
g_param_spec_get_name (pspec),
|
||||
value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
server_context_dispose (GObject *object)
|
||||
{
|
||||
ServerContext *context = SERVER_CONTEXT(object);
|
||||
|
||||
if (context->keyboard) {
|
||||
disconnect_keyboard_signals (context);
|
||||
g_object_unref (context->keyboard);
|
||||
context->keyboard = NULL;
|
||||
}
|
||||
|
||||
if (context->window) {
|
||||
gtk_widget_destroy (context->window);
|
||||
context->window = NULL;
|
||||
}
|
||||
|
||||
if (context->connection) {
|
||||
if (context->registration_id > 0) {
|
||||
g_dbus_connection_unregister_object (context->connection,
|
||||
context->registration_id);
|
||||
context->registration_id = 0;
|
||||
}
|
||||
|
||||
g_object_unref (context->connection);
|
||||
context->connection = NULL;
|
||||
}
|
||||
|
||||
if (context->introspection_data) {
|
||||
g_dbus_node_info_unref (context->introspection_data);
|
||||
context->introspection_data = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (server_context_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
server_context_constructed (GObject *object)
|
||||
{
|
||||
ServerContext *context = SERVER_CONTEXT (object);
|
||||
if (context->connection && context->object_path) {
|
||||
GError *error = NULL;
|
||||
|
||||
context->registration_id = g_dbus_connection_register_object
|
||||
(context->connection,
|
||||
context->object_path,
|
||||
context->introspection_data->interfaces[0],
|
||||
&interface_vtable,
|
||||
context,
|
||||
NULL,
|
||||
&error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
server_context_class_init (ServerContextClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->constructed = server_context_constructed;
|
||||
gobject_class->set_property = server_context_set_property;
|
||||
gobject_class->dispose = server_context_dispose;
|
||||
|
||||
pspec = g_param_spec_string ("object-path",
|
||||
"Object-path",
|
||||
"Object-path",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
pspec);
|
||||
|
||||
pspec = g_param_spec_object ("connection",
|
||||
"Connection",
|
||||
"Connection",
|
||||
G_TYPE_DBUS_CONNECTION,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONNECTION,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
server_context_init (ServerContext *context)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
context->connection = NULL;
|
||||
error = NULL;
|
||||
context->introspection_data =
|
||||
g_dbus_node_info_new_for_xml (introspection_xml, &error);
|
||||
g_assert (context->introspection_data != NULL);
|
||||
context->registration_id = 0;
|
||||
context->object_path = NULL;
|
||||
|
||||
context->keyboard = NULL;
|
||||
context->widget = NULL;
|
||||
context->window = NULL;
|
||||
context->key_pressed_handler = 0;
|
||||
context->key_released_handler = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
on_key_pressed (EekKeyboard *keyboard,
|
||||
EekKey *key,
|
||||
gpointer user_data)
|
||||
{
|
||||
ServerContext *context = user_data;
|
||||
|
||||
if (context->connection && context->enabled) {
|
||||
guint keycode = eek_key_get_keycode (key);
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (context->connection,
|
||||
NULL,
|
||||
context->object_path,
|
||||
SERVER_CONTEXT_INTERFACE,
|
||||
"KeyPressed",
|
||||
g_variant_new ("(u)", keycode),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_key_released (EekKeyboard *keyboard,
|
||||
EekKey *key,
|
||||
gpointer user_data)
|
||||
{
|
||||
ServerContext *context = user_data;
|
||||
|
||||
if (context->connection && context->enabled) {
|
||||
guint keycode = eek_key_get_keycode (key);
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (context->connection,
|
||||
NULL,
|
||||
context->object_path,
|
||||
SERVER_CONTEXT_INTERFACE,
|
||||
"KeyReleased",
|
||||
g_variant_new ("(u)", keycode),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_keyboard_signals (ServerContext *context)
|
||||
{
|
||||
if (g_signal_handler_is_connected (context->keyboard,
|
||||
context->key_pressed_handler))
|
||||
g_signal_handler_disconnect (context->keyboard,
|
||||
context->key_pressed_handler);
|
||||
if (g_signal_handler_is_connected (context->keyboard,
|
||||
context->key_released_handler))
|
||||
g_signal_handler_disconnect (context->keyboard,
|
||||
context->key_released_handler);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
ServerContext *context = user_data;
|
||||
|
||||
if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
|
||||
EekSerializable *serializable;
|
||||
GVariant *variant;
|
||||
|
||||
if (!context->enabled) {
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get (parameters, "(v)", &variant);
|
||||
serializable = eek_serializable_deserialize (variant);
|
||||
if (!EEK_IS_KEYBOARD(serializable)) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"not a keyboard");
|
||||
return;
|
||||
}
|
||||
|
||||
context->keyboard = EEK_KEYBOARD(serializable);
|
||||
disconnect_keyboard_signals (context);
|
||||
context->key_pressed_handler =
|
||||
g_signal_connect (context->keyboard, "key-pressed",
|
||||
G_CALLBACK(on_key_pressed),
|
||||
context);
|
||||
context->key_released_handler =
|
||||
g_signal_connect (context->keyboard, "key-released",
|
||||
G_CALLBACK(on_key_released),
|
||||
context);
|
||||
eek_keyboard_set_modifier_behavior (context->keyboard,
|
||||
EEK_MODIFIER_BEHAVIOR_LATCH);
|
||||
|
||||
if (context->window) {
|
||||
gboolean was_visible = gtk_widget_get_visible (context->window);
|
||||
update_widget (context);
|
||||
if (was_visible)
|
||||
gtk_widget_show_all (context->window);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "SetGroup") == 0) {
|
||||
gint group;
|
||||
|
||||
if (!context->enabled) {
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context->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 (context->keyboard, group);
|
||||
|
||||
if (context->window) {
|
||||
gboolean was_visible = gtk_widget_get_visible (context->window);
|
||||
update_widget (context);
|
||||
if (was_visible)
|
||||
gtk_widget_show_all (context->window);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "ShowKeyboard") == 0) {
|
||||
if (!context->keyboard) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"keyboard is not set");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context->window)
|
||||
update_widget (context);
|
||||
g_assert (context->window);
|
||||
gtk_widget_show_all (context->window);
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "HideKeyboard") == 0) {
|
||||
if (context->window)
|
||||
gtk_widget_hide (context->window);
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PressKey") == 0 ||
|
||||
g_strcmp0 (method_name, "ReleaseKey") == 0) {
|
||||
EekKey *key;
|
||||
guint keycode;
|
||||
|
||||
if (!context->enabled) {
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context->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, "(u)", &keycode);
|
||||
key = eek_keyboard_find_key_by_keycode (context->keyboard, keycode);
|
||||
|
||||
if (!key) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"key for %u is not found",
|
||||
keycode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PressKey") == 0) {
|
||||
g_signal_handler_block (context->keyboard,
|
||||
context->key_pressed_handler);
|
||||
g_signal_emit_by_name (key, "pressed");
|
||||
g_signal_handler_unblock (context->keyboard,
|
||||
context->key_pressed_handler);
|
||||
} else {
|
||||
g_signal_handler_block (context->keyboard,
|
||||
context->key_released_handler);
|
||||
g_signal_emit_by_name (key, "released");
|
||||
g_signal_handler_unblock (context->keyboard,
|
||||
context->key_released_handler);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
ServerContext *
|
||||
server_context_new (const gchar *object_path,
|
||||
GDBusConnection *connection)
|
||||
{
|
||||
return g_object_new (SERVER_TYPE_CONTEXT,
|
||||
"object-path", object_path,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
server_context_set_enabled (ServerContext *context, gboolean enabled)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
g_return_if_fail (SERVER_IS_CONTEXT(context));
|
||||
g_return_if_fail (context->connection);
|
||||
|
||||
if (context->enabled == enabled)
|
||||
return;
|
||||
|
||||
if (enabled) {
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (context->connection,
|
||||
NULL,
|
||||
context->object_path,
|
||||
SERVER_CONTEXT_INTERFACE,
|
||||
"Enabled",
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
} else {
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (context->connection,
|
||||
NULL,
|
||||
context->object_path,
|
||||
SERVER_CONTEXT_INTERFACE,
|
||||
"Disabled",
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
context->enabled = enabled;
|
||||
}
|
||||
43
src/server-context.h
Normal file
43
src/server-context.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 SERVER_CONTEXT_H
|
||||
#define SERVER_CONTEXT_H 1
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SERVER_CONTEXT_PATH "/com/redhat/Eekboard/Context_%d"
|
||||
#define SERVER_CONTEXT_INTERFACE "com.redhat.Eekboard.Context"
|
||||
|
||||
#define SERVER_TYPE_CONTEXT (server_context_get_type())
|
||||
#define SERVER_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVER_TYPE_CONTEXT, ServerContext))
|
||||
#define SERVER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVER_TYPE_CONTEXT, ServerContextClass))
|
||||
#define SERVER_IS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVER_TYPE_CONTEXT))
|
||||
#define SERVER_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVER_TYPE_CONTEXT))
|
||||
#define SERVER_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVER_TYPE_CONTEXT, ServerContextClass))
|
||||
|
||||
typedef struct _ServerContext ServerContext;
|
||||
|
||||
ServerContext *server_context_new (const gchar *object_path,
|
||||
GDBusConnection *connection);
|
||||
void server_context_set_enabled (ServerContext *context,
|
||||
gboolean enabled);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* SERVER_CONTEXT_H */
|
||||
@ -27,13 +27,28 @@
|
||||
#include <clutter-gtk/clutter-gtk.h>
|
||||
#endif
|
||||
|
||||
#include "server.h"
|
||||
#include "server-server.h"
|
||||
#include "eek/eek.h"
|
||||
|
||||
static void
|
||||
on_name_acquired (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_lost (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
EekboardServer *server;
|
||||
ServerServer *server;
|
||||
GDBusConnection *connection;
|
||||
GError *error;
|
||||
GMainLoop *loop;
|
||||
@ -66,18 +81,18 @@ main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
|
||||
server = eekboard_server_new ("/com/redhat/Eekboard/Keyboard", connection);
|
||||
server = server_server_new (SERVER_SERVER_PATH, connection);
|
||||
|
||||
if (server == NULL) {
|
||||
g_printerr ("Can't start server\n");
|
||||
g_printerr ("Can't create server server\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
owner_id = g_bus_own_name_on_connection (connection,
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
SERVER_SERVER_INTERFACE,
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
NULL,
|
||||
NULL);
|
||||
if (owner_id == 0) {
|
||||
|
||||
324
src/server-server.c
Normal file
324
src/server-server.c
Normal file
@ -0,0 +1,324 @@
|
||||
/*
|
||||
* 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 "server-server.h"
|
||||
#include "server-context.h"
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_CONNECTION,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
static const gchar introspection_xml[] =
|
||||
"<node>"
|
||||
" <interface name='com.redhat.Eekboard.Server'>"
|
||||
" <method name='CreateContext'>"
|
||||
" <arg direction='in' type='s' name='client_name'/>"
|
||||
" <arg direction='out' type='s' name='object_path'/>"
|
||||
" </method>"
|
||||
" <method name='PushContext'>"
|
||||
" <arg direction='in' type='s' name='object_path'/>"
|
||||
" </method>"
|
||||
" <method name='PopContext'/>"
|
||||
" <method name='DestroyContext'>"
|
||||
" <arg direction='in' type='s' name='object_path'/>"
|
||||
" </method>"
|
||||
/* signals */
|
||||
" </interface>"
|
||||
"</node>";
|
||||
|
||||
typedef struct _ServerServerClass ServerServerClass;
|
||||
|
||||
struct _ServerServer {
|
||||
GObject parent;
|
||||
GDBusConnection *connection;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
guint registration_id;
|
||||
char *object_path;
|
||||
|
||||
GHashTable *context_hash;
|
||||
GSList *context_stack;
|
||||
};
|
||||
|
||||
struct _ServerServerClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ServerServer, server_server, G_TYPE_OBJECT);
|
||||
|
||||
static void handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data);
|
||||
|
||||
static const GDBusInterfaceVTable interface_vtable =
|
||||
{
|
||||
handle_method_call,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static void
|
||||
server_server_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
ServerServer *server = SERVER_SERVER(object);
|
||||
GDBusConnection *connection;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_OBJECT_PATH:
|
||||
if (server->object_path)
|
||||
g_free (server->object_path);
|
||||
server->object_path = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_CONNECTION:
|
||||
connection = g_value_get_object (value);
|
||||
if (server->connection)
|
||||
g_object_unref (server->connection);
|
||||
server->connection = g_object_ref (connection);
|
||||
break;
|
||||
default:
|
||||
g_object_set_property (object,
|
||||
g_param_spec_get_name (pspec),
|
||||
value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
server_server_dispose (GObject *object)
|
||||
{
|
||||
ServerServer *server = SERVER_SERVER(object);
|
||||
GSList *head;
|
||||
|
||||
if (server->context_hash) {
|
||||
g_hash_table_destroy (server->context_hash);
|
||||
server->context_hash = NULL;
|
||||
}
|
||||
|
||||
for (head = server->context_stack; head; head = server->context_stack) {
|
||||
g_object_unref (head->data);
|
||||
server->context_stack = g_slist_next (head);
|
||||
g_slist_free1 (head);
|
||||
}
|
||||
|
||||
if (server->connection) {
|
||||
if (server->registration_id > 0) {
|
||||
g_dbus_connection_unregister_object (server->connection,
|
||||
server->registration_id);
|
||||
server->registration_id = 0;
|
||||
}
|
||||
|
||||
g_object_unref (server->connection);
|
||||
server->connection = NULL;
|
||||
}
|
||||
|
||||
if (server->introspection_data) {
|
||||
g_dbus_node_info_unref (server->introspection_data);
|
||||
server->introspection_data = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (server_server_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
server_server_constructed (GObject *object)
|
||||
{
|
||||
ServerServer *server = SERVER_SERVER (object);
|
||||
if (server->connection && server->object_path) {
|
||||
GError *error = NULL;
|
||||
|
||||
server->registration_id = g_dbus_connection_register_object
|
||||
(server->connection,
|
||||
server->object_path,
|
||||
server->introspection_data->interfaces[0],
|
||||
&interface_vtable,
|
||||
server,
|
||||
NULL,
|
||||
&error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
server_server_class_init (ServerServerClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->constructed = server_server_constructed;
|
||||
gobject_class->set_property = server_server_set_property;
|
||||
gobject_class->dispose = server_server_dispose;
|
||||
|
||||
pspec = g_param_spec_string ("object-path",
|
||||
"Object-path",
|
||||
"Object-path",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
pspec);
|
||||
|
||||
pspec = g_param_spec_object ("connection",
|
||||
"Connection",
|
||||
"Connection",
|
||||
G_TYPE_DBUS_CONNECTION,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONNECTION,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
server_server_init (ServerServer *server)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
server->connection = NULL;
|
||||
error = NULL;
|
||||
server->introspection_data =
|
||||
g_dbus_node_info_new_for_xml (introspection_xml, &error);
|
||||
g_assert (server->introspection_data != NULL);
|
||||
server->registration_id = 0;
|
||||
|
||||
server->context_hash =
|
||||
g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
(GDestroyNotify)g_free,
|
||||
(GDestroyNotify)g_object_unref);
|
||||
server->context_stack = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
ServerServer *server = user_data;
|
||||
|
||||
if (g_strcmp0 (method_name, "CreateContext") == 0) {
|
||||
const gchar *client_name;
|
||||
gchar *object_path;
|
||||
static gint context_id = 0;
|
||||
ServerContext *context;
|
||||
|
||||
g_variant_get (parameters, "(&s)", &client_name);
|
||||
object_path = g_strdup_printf (SERVER_CONTEXT_PATH, context_id++);
|
||||
context = server_context_new (object_path, server->connection);
|
||||
g_hash_table_insert (server->context_hash,
|
||||
object_path,
|
||||
context);
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(s)",
|
||||
object_path));
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PushContext") == 0) {
|
||||
const gchar *object_path;
|
||||
ServerContext *context;
|
||||
|
||||
g_variant_get (parameters, "(&s)", &object_path);
|
||||
context = g_hash_table_lookup (server->context_hash, object_path);
|
||||
if (!context) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"context not found");
|
||||
return;
|
||||
}
|
||||
if (server->context_stack)
|
||||
server_context_set_enabled (server->context_stack->data, FALSE);
|
||||
server->context_stack = g_slist_prepend (server->context_stack,
|
||||
context);
|
||||
g_object_ref (context);
|
||||
server_context_set_enabled (context, TRUE);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PopContext") == 0) {
|
||||
if (server->context_stack) {
|
||||
ServerContext *context = server->context_stack->data;
|
||||
|
||||
server_context_set_enabled (context, FALSE);
|
||||
server->context_stack = g_slist_next (server->context_stack);
|
||||
g_object_unref (context);
|
||||
if (server->context_stack)
|
||||
server_context_set_enabled (server->context_stack->data, TRUE);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "DestroyContext") == 0) {
|
||||
const gchar *object_path;
|
||||
ServerContext *context;
|
||||
GSList *head;
|
||||
|
||||
g_variant_get (parameters, "(&s)", &object_path);
|
||||
context = g_hash_table_lookup (server->context_hash, object_path);
|
||||
if (!context) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"context not found");
|
||||
return;
|
||||
}
|
||||
head = g_slist_find (server->context_stack, context);
|
||||
if (head) {
|
||||
server->context_stack = g_slist_remove_link (server->context_stack,
|
||||
head);
|
||||
g_slist_free1 (head);
|
||||
}
|
||||
|
||||
g_hash_table_remove (server->context_hash, object_path);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
ServerServer *
|
||||
server_server_new (const gchar *object_path,
|
||||
GDBusConnection *connection)
|
||||
{
|
||||
return g_object_new (SERVER_TYPE_SERVER,
|
||||
"object-path", object_path,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
}
|
||||
@ -15,24 +15,27 @@
|
||||
* 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
|
||||
#ifndef SERVER_KEYBOARD_H
|
||||
#define SERVER_KEYBOARD_H 1
|
||||
|
||||
#include <gio/gio.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))
|
||||
#define SERVER_SERVER_PATH "/com/redhat/Eekboard/Server"
|
||||
#define SERVER_SERVER_INTERFACE "com.redhat.Eekboard.Server"
|
||||
|
||||
typedef struct _EekboardServer EekboardServer;
|
||||
#define SERVER_TYPE_SERVER (server_server_get_type())
|
||||
#define SERVER_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVER_TYPE_SERVER, ServerServer))
|
||||
#define SERVER_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVER_TYPE_SERVER, ServerServerClass))
|
||||
#define SERVER_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVER_TYPE_SERVER))
|
||||
#define SERVER_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVER_TYPE_SERVER))
|
||||
#define SERVER_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVER_TYPE_SERVER, ServerServerClass))
|
||||
|
||||
EekboardServer *eekboard_server_new (const gchar *object_path,
|
||||
typedef struct _ServerServer ServerServer;
|
||||
|
||||
ServerServer *server_server_new (const gchar *object_path,
|
||||
GDBusConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* EEKBOARD_SERVER_H */
|
||||
#endif /* SERVER_SERVER_H */
|
||||
545
src/server.c
545
src/server.c
@ -1,545 +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/>.
|
||||
*/
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include "eek/eek.h"
|
||||
|
||||
#if HAVE_CLUTTER_GTK
|
||||
#include <clutter-gtk/clutter-gtk.h>
|
||||
#include "eek/eek-clutter.h"
|
||||
#else /* HAVE_CLUTTER_GTK */
|
||||
#include "eek/eek-gtk.h"
|
||||
#endif /* !HAVE_CLUTTER_GTK */
|
||||
|
||||
#include "server.h"
|
||||
|
||||
#define CSW 640
|
||||
#define CSH 480
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_CONNECTION,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
static const gchar introspection_xml[] =
|
||||
"<node>"
|
||||
" <interface name='com.redhat.Eekboard.Keyboard'>"
|
||||
" <method name='SetDescription'>"
|
||||
" <arg type='v' name='description'/>"
|
||||
" </method>"
|
||||
" <method name='SetGroup'>"
|
||||
" <arg type='i' name='group'/>"
|
||||
" </method>"
|
||||
" <method name='Show'/>"
|
||||
" <method name='Hide'/>"
|
||||
" <method name='PressKey'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </method>"
|
||||
" <method name='ReleaseKey'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </method>"
|
||||
" <signal name='KeyPressed'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </signal>"
|
||||
" <signal name='KeyReleased'>"
|
||||
" <arg type='u' name='keycode'/>"
|
||||
" </signal>"
|
||||
" <signal name='VisibilityChanged'>"
|
||||
" <arg type='b' name='visible'/>"
|
||||
" </signal>"
|
||||
" </interface>"
|
||||
"</node>";
|
||||
|
||||
typedef struct _EekboardServerClass EekboardServerClass;
|
||||
|
||||
struct _EekboardServer {
|
||||
GObject parent;
|
||||
GDBusConnection *connection;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
guint registration_id;
|
||||
char *object_path;
|
||||
|
||||
GtkWidget *window;
|
||||
GtkWidget *widget;
|
||||
EekKeyboard *keyboard;
|
||||
|
||||
gulong key_pressed_handler;
|
||||
gulong key_released_handler;
|
||||
};
|
||||
|
||||
struct _EekboardServerClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (EekboardServer, eekboard_server, G_TYPE_OBJECT);
|
||||
|
||||
static void handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data);
|
||||
|
||||
static const GDBusInterfaceVTable interface_vtable =
|
||||
{
|
||||
handle_method_call,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
#if HAVE_CLUTTER_GTK
|
||||
static void
|
||||
on_allocation_changed (ClutterActor *stage,
|
||||
ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags,
|
||||
gpointer user_data)
|
||||
{
|
||||
ClutterActor *actor = user_data;
|
||||
clutter_actor_set_size (actor,
|
||||
box->x2 - box->x1,
|
||||
box->y2 - box->y1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
on_destroy (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
EekboardServer *server = user_data;
|
||||
|
||||
g_assert (widget == server->window);
|
||||
server->window = NULL;
|
||||
server->widget = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
on_notify_visible (GObject *object, GParamSpec *spec, gpointer user_data)
|
||||
{
|
||||
EekboardServer *server = user_data;
|
||||
gboolean visible;
|
||||
GError *error;
|
||||
|
||||
g_object_get (object, "visible", &visible, NULL);
|
||||
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (server->connection,
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"/com/redhat/Eekboard/Keyboard",
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"VisibilityChanged",
|
||||
g_variant_new ("(b)", visible),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
static void
|
||||
update_widget (EekboardServer *server)
|
||||
{
|
||||
GdkScreen *screen;
|
||||
GdkWindow *root;
|
||||
gint monitor;
|
||||
GdkRectangle rect;
|
||||
EekBounds bounds;
|
||||
#if HAVE_CLUTTER_GTK
|
||||
ClutterActor *stage, *actor;
|
||||
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
|
||||
#endif
|
||||
|
||||
if (server->widget)
|
||||
gtk_widget_destroy (server->widget);
|
||||
|
||||
if (server->window)
|
||||
gtk_widget_destroy (server->window);
|
||||
|
||||
eek_element_get_bounds (EEK_ELEMENT(server->keyboard), &bounds);
|
||||
#if HAVE_CLUTTER_GTK
|
||||
server->widget = gtk_clutter_embed_new ();
|
||||
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(server->widget));
|
||||
actor = eek_clutter_keyboard_new (server->keyboard);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
|
||||
|
||||
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
|
||||
clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), TRUE);
|
||||
clutter_stage_set_minimum_size (CLUTTER_STAGE(stage),
|
||||
bounds.width / 3,
|
||||
bounds.height / 3);
|
||||
g_signal_connect (stage,
|
||||
"allocation-changed",
|
||||
G_CALLBACK(on_allocation_changed),
|
||||
actor);
|
||||
#else
|
||||
server->widget = eek_gtk_keyboard_new (server->keyboard);
|
||||
#endif
|
||||
gtk_widget_set_size_request (server->widget, bounds.width, bounds.height);
|
||||
|
||||
server->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect (server->window, "destroy",
|
||||
G_CALLBACK(on_destroy), server);
|
||||
g_signal_connect (server->window, "notify::visible",
|
||||
G_CALLBACK(on_notify_visible), server);
|
||||
gtk_container_add (GTK_CONTAINER(server->window), server->widget);
|
||||
|
||||
gtk_widget_set_can_focus (server->window, FALSE);
|
||||
g_object_set (G_OBJECT(server->window), "accept_focus", FALSE, NULL);
|
||||
gtk_window_set_title (GTK_WINDOW(server->window), "Keyboard");
|
||||
gtk_window_set_keep_above (GTK_WINDOW(server->window), TRUE);
|
||||
|
||||
screen = gdk_screen_get_default ();
|
||||
root = gtk_widget_get_root_window (server->window);
|
||||
monitor = gdk_screen_get_monitor_at_window (screen, root);
|
||||
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
|
||||
gtk_window_move (GTK_WINDOW(server->window),
|
||||
MAX(rect.width - 20 - bounds.width, 0),
|
||||
MAX(rect.height - 40 - bounds.height, 0));
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_server_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekboardServer *server = EEKBOARD_SERVER(object);
|
||||
GDBusConnection *connection;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_OBJECT_PATH:
|
||||
if (server->object_path)
|
||||
g_free (server->object_path);
|
||||
server->object_path = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_CONNECTION:
|
||||
connection = g_value_get_object (value);
|
||||
if (server->connection)
|
||||
g_object_unref (server->connection);
|
||||
server->connection = g_object_ref (connection);
|
||||
break;
|
||||
default:
|
||||
g_object_set_property (object,
|
||||
g_param_spec_get_name (pspec),
|
||||
value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_server_dispose (GObject *object)
|
||||
{
|
||||
EekboardServer *server = EEKBOARD_SERVER(object);
|
||||
|
||||
if (server->connection) {
|
||||
if (server->registration_id > 0) {
|
||||
g_dbus_connection_unregister_object (server->connection,
|
||||
server->registration_id);
|
||||
server->registration_id = 0;
|
||||
}
|
||||
|
||||
g_object_unref (server->connection);
|
||||
server->connection = NULL;
|
||||
}
|
||||
|
||||
if (server->introspection_data) {
|
||||
g_dbus_node_info_unref (server->introspection_data);
|
||||
server->introspection_data = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (eekboard_server_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_server_constructed (GObject *object)
|
||||
{
|
||||
EekboardServer *server = EEKBOARD_SERVER (object);
|
||||
if (server->connection && server->object_path) {
|
||||
GError *error = NULL;
|
||||
|
||||
server->registration_id = g_dbus_connection_register_object
|
||||
(server->connection,
|
||||
server->object_path,
|
||||
server->introspection_data->interfaces[0],
|
||||
&interface_vtable,
|
||||
server,
|
||||
NULL,
|
||||
&error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_server_class_init (EekboardServerClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->constructed = eekboard_server_constructed;
|
||||
gobject_class->set_property = eekboard_server_set_property;
|
||||
gobject_class->dispose = eekboard_server_dispose;
|
||||
|
||||
pspec = g_param_spec_string ("object-path",
|
||||
"Object-path",
|
||||
"Object-path",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
pspec);
|
||||
|
||||
pspec = g_param_spec_object ("connection",
|
||||
"Connection",
|
||||
"Connection",
|
||||
G_TYPE_DBUS_CONNECTION,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONNECTION,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_server_init (EekboardServer *server)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
server->introspection_data =
|
||||
g_dbus_node_info_new_for_xml (introspection_xml, &error);
|
||||
g_assert (server->introspection_data != NULL);
|
||||
server->registration_id = 0;
|
||||
server->object_path = NULL;
|
||||
server->keyboard = NULL;
|
||||
server->widget = NULL;
|
||||
server->window = NULL;
|
||||
server->key_pressed_handler = 0;
|
||||
server->key_released_handler = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
on_key_pressed (EekKeyboard *keyboard,
|
||||
EekKey *key,
|
||||
gpointer user_data)
|
||||
{
|
||||
EekboardServer *server = user_data;
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (server->connection,
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"/com/redhat/Eekboard/Keyboard",
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"KeyPressed",
|
||||
g_variant_new ("(u)",
|
||||
eek_key_get_keycode (key)),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
static void
|
||||
on_key_released (EekKeyboard *keyboard,
|
||||
EekKey *key,
|
||||
gpointer user_data)
|
||||
{
|
||||
EekboardServer *server = user_data;
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
g_dbus_connection_emit_signal (server->connection,
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"/com/redhat/Eekboard/Keyboard",
|
||||
"com.redhat.Eekboard.Keyboard",
|
||||
"KeyReleased",
|
||||
g_variant_new ("(u)",
|
||||
eek_key_get_keycode (key)),
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_keyboard_signals (EekboardServer *server)
|
||||
{
|
||||
if (g_signal_handler_is_connected (server->keyboard,
|
||||
server->key_pressed_handler))
|
||||
g_signal_handler_disconnect (server->keyboard,
|
||||
server->key_pressed_handler);
|
||||
if (g_signal_handler_is_connected (server->keyboard,
|
||||
server->key_released_handler))
|
||||
g_signal_handler_disconnect (server->keyboard,
|
||||
server->key_released_handler);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_method_call (GDBusConnection *connection,
|
||||
const gchar *sender,
|
||||
const gchar *object_path,
|
||||
const gchar *interface_name,
|
||||
const gchar *method_name,
|
||||
GVariant *parameters,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
EekboardServer *server = user_data;
|
||||
|
||||
// g_debug ("%s", method_name);
|
||||
if (g_strcmp0 (method_name, "SetDescription") == 0) {
|
||||
EekSerializable *serializable;
|
||||
GVariant *variant;
|
||||
|
||||
g_variant_get (parameters, "(v)", &variant);
|
||||
serializable = eek_serializable_deserialize (variant);
|
||||
if (!EEK_IS_KEYBOARD(serializable)) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"not a keyboard");
|
||||
return;
|
||||
}
|
||||
|
||||
server->keyboard = EEK_KEYBOARD(serializable);
|
||||
disconnect_keyboard_signals (server);
|
||||
server->key_pressed_handler =
|
||||
g_signal_connect (server->keyboard, "key-pressed",
|
||||
G_CALLBACK(on_key_pressed),
|
||||
server);
|
||||
server->key_released_handler =
|
||||
g_signal_connect (server->keyboard, "key-released",
|
||||
G_CALLBACK(on_key_released),
|
||||
server);
|
||||
eek_keyboard_set_modifier_behavior (server->keyboard,
|
||||
EEK_MODIFIER_BEHAVIOR_LATCH);
|
||||
|
||||
if (server->window) {
|
||||
gboolean was_visible = gtk_widget_get_visible (server->window);
|
||||
update_widget (server);
|
||||
if (was_visible)
|
||||
gtk_widget_show_all (server->window);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "SetGroup") == 0) {
|
||||
gint group;
|
||||
|
||||
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);
|
||||
|
||||
if (server->window) {
|
||||
gboolean was_visible = gtk_widget_get_visible (server->window);
|
||||
update_widget (server);
|
||||
if (was_visible)
|
||||
gtk_widget_show_all (server->window);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
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)
|
||||
update_widget (server);
|
||||
g_assert (server->window);
|
||||
gtk_widget_show_all (server->window);
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
g_object_notify (G_OBJECT(server->window), "visible");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "Hide") == 0) {
|
||||
if (server->window)
|
||||
gtk_widget_hide (server->window);
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
g_object_notify (G_OBJECT(server->window), "visible");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PressKey") == 0 ||
|
||||
g_strcmp0 (method_name, "ReleaseKey") == 0) {
|
||||
EekKey *key;
|
||||
guint keycode;
|
||||
|
||||
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, "(u)", &keycode);
|
||||
key = eek_keyboard_find_key_by_keycode (server->keyboard, keycode);
|
||||
|
||||
if (!key) {
|
||||
g_dbus_method_invocation_return_error (invocation,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED_HANDLED,
|
||||
"key for %u is not found",
|
||||
keycode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (method_name, "PressKey") == 0) {
|
||||
g_signal_handler_block (server->keyboard,
|
||||
server->key_pressed_handler);
|
||||
g_signal_emit_by_name (key, "pressed");
|
||||
g_signal_handler_unblock (server->keyboard,
|
||||
server->key_pressed_handler);
|
||||
} else {
|
||||
g_signal_handler_block (server->keyboard,
|
||||
server->key_released_handler);
|
||||
g_signal_emit_by_name (key, "released");
|
||||
g_signal_handler_unblock (server->keyboard,
|
||||
server->key_released_handler);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
EekboardServer *
|
||||
eekboard_server_new (const gchar *object_path,
|
||||
GDBusConnection *connection)
|
||||
{
|
||||
return g_object_new (EEKBOARD_TYPE_SERVER,
|
||||
"object-path", object_path,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
}
|
||||
@ -50,9 +50,10 @@ typedef struct _EekboardSystemClientClass EekboardSystemClientClass;
|
||||
struct _EekboardSystemClient {
|
||||
GObject parent;
|
||||
|
||||
EekboardKeyboard *keyboard;
|
||||
EekboardServer *server;
|
||||
EekboardContext *context;
|
||||
|
||||
EekKeyboard *description;
|
||||
EekKeyboard *keyboard;
|
||||
GdkDisplay *display;
|
||||
XklEngine *xkl_engine;
|
||||
XklConfigRegistry *xkl_config_registry;
|
||||
@ -101,7 +102,7 @@ static SPIBoolean keystroke_listener_cb
|
||||
(const AccessibleKeystroke *stroke,
|
||||
void *user_data);
|
||||
#endif /* HAVE_CSPI */
|
||||
static void set_description (EekboardSystemClient *client);
|
||||
static void set_keyboard (EekboardSystemClient *client);
|
||||
|
||||
static void
|
||||
eekboard_system_client_set_property (GObject *object,
|
||||
@ -111,16 +112,21 @@ eekboard_system_client_set_property (GObject *object,
|
||||
{
|
||||
EekboardSystemClient *client = EEKBOARD_SYSTEM_CLIENT(object);
|
||||
GDBusConnection *connection;
|
||||
GError *error;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CONNECTION:
|
||||
connection = g_value_get_object (value);
|
||||
error = NULL;
|
||||
client->keyboard = eekboard_keyboard_new ("/com/redhat/Eekboard/Keyboard",
|
||||
connection,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
client->server = eekboard_server_new (connection, NULL);
|
||||
g_assert (client->server);
|
||||
|
||||
client->context =
|
||||
eekboard_server_create_context (client->server,
|
||||
"eekboard-system-client",
|
||||
NULL);
|
||||
g_assert (client->context);
|
||||
|
||||
eekboard_server_push_context (client->server, client->context, NULL);
|
||||
break;
|
||||
default:
|
||||
g_object_set_property (object,
|
||||
@ -146,16 +152,25 @@ eekboard_system_client_dispose (GObject *object)
|
||||
eekboard_system_client_disable_fakekey (client);
|
||||
#endif /* HAVE_FAKEKEY */
|
||||
|
||||
if (client->context) {
|
||||
if (client->server) {
|
||||
eekboard_server_pop_context (client->server, NULL);
|
||||
}
|
||||
|
||||
g_object_unref (client->context);
|
||||
client->context = NULL;
|
||||
}
|
||||
|
||||
if (client->server) {
|
||||
g_object_unref (client->server);
|
||||
client->server = 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
|
||||
if (client->fakekey) {
|
||||
client->fakekey = NULL;
|
||||
@ -192,11 +207,12 @@ eekboard_system_client_class_init (EekboardSystemClientClass *klass)
|
||||
static void
|
||||
eekboard_system_client_init (EekboardSystemClient *client)
|
||||
{
|
||||
client->keyboard = NULL;
|
||||
client->server = NULL;
|
||||
client->context = NULL;
|
||||
client->display = NULL;
|
||||
client->xkl_engine = NULL;
|
||||
client->xkl_config_registry = NULL;
|
||||
client->description = NULL;
|
||||
client->keyboard = NULL;
|
||||
client->key_pressed_handler = 0;
|
||||
client->key_released_handler = 0;
|
||||
client->xkl_config_changed_handler = 0;
|
||||
@ -246,7 +262,7 @@ eekboard_system_client_enable_xkl (EekboardSystemClient *client)
|
||||
|
||||
xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
|
||||
|
||||
set_description (client);
|
||||
set_keyboard (client);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -341,13 +357,15 @@ focus_listener_cb (const AccessibleEvent *event,
|
||||
case SPI_ROLE_PASSWORD_TEXT:
|
||||
case SPI_ROLE_TERMINAL:
|
||||
case SPI_ROLE_ENTRY:
|
||||
if (g_strcmp0 (event->type, "focus") == 0 || event->detail1 == 1)
|
||||
eekboard_keyboard_show (client->keyboard);
|
||||
if (g_strcmp0 (event->type, "focus") == 0 || event->detail1 == 1) {
|
||||
eekboard_context_show_keyboard (client->context, NULL);
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
} else
|
||||
eekboard_keyboard_hide (client->keyboard);
|
||||
} else {
|
||||
eekboard_context_hide_keyboard (client->context, NULL);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -361,7 +379,7 @@ 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->description,
|
||||
key = eek_keyboard_find_key_by_keycode (client->keyboard,
|
||||
stroke->keycode);
|
||||
if (key) {
|
||||
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
|
||||
@ -369,10 +387,12 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (stroke->type == SPI_KEY_PRESSED)
|
||||
eekboard_keyboard_press_key (client->keyboard, stroke->keycode);
|
||||
else
|
||||
eekboard_keyboard_release_key (client->keyboard, stroke->keycode);
|
||||
if (stroke->type == SPI_KEY_PRESSED) {
|
||||
eekboard_context_press_key (client->context, stroke->keycode, NULL);
|
||||
} else {
|
||||
eekboard_context_release_key (client->context, stroke->keycode, NULL);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* HAVE_CSPI */
|
||||
@ -403,7 +423,7 @@ on_xkl_config_changed (XklEngine *xklengine,
|
||||
{
|
||||
EekboardSystemClient *client = user_data;
|
||||
|
||||
set_description (client);
|
||||
set_keyboard (client);
|
||||
|
||||
#ifdef HAVE_FAKEKEY
|
||||
if (client->fakekey)
|
||||
@ -412,23 +432,23 @@ on_xkl_config_changed (XklEngine *xklengine,
|
||||
}
|
||||
|
||||
static void
|
||||
set_description (EekboardSystemClient *client)
|
||||
set_keyboard (EekboardSystemClient *client)
|
||||
{
|
||||
EekLayout *layout;
|
||||
gchar *keyboard_name;
|
||||
static gint keyboard_serial = 0;
|
||||
|
||||
if (client->description)
|
||||
g_object_unref (client->description);
|
||||
if (client->keyboard)
|
||||
g_object_unref (client->keyboard);
|
||||
layout = eek_xkl_layout_new ();
|
||||
client->description = eek_keyboard_new (layout, CSW, CSH);
|
||||
eek_keyboard_set_modifier_behavior (client->description,
|
||||
client->keyboard = eek_keyboard_new (layout, CSW, CSH);
|
||||
eek_keyboard_set_modifier_behavior (client->keyboard,
|
||||
EEK_MODIFIER_BEHAVIOR_LATCH);
|
||||
|
||||
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
|
||||
eek_element_set_name (EEK_ELEMENT(client->description), keyboard_name);
|
||||
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
|
||||
|
||||
eekboard_keyboard_set_description (client->keyboard, client->description);
|
||||
eekboard_context_set_keyboard (client->context, client->keyboard, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -440,11 +460,10 @@ on_xkl_state_changed (XklEngine *xklengine,
|
||||
{
|
||||
EekboardSystemClient *client = user_data;
|
||||
|
||||
if (type == GROUP_CHANGED && client->description) {
|
||||
gint group = eek_keyboard_get_group (client->description);
|
||||
if (type == GROUP_CHANGED && client->keyboard) {
|
||||
gint group = eek_keyboard_get_group (client->keyboard);
|
||||
if (group != value) {
|
||||
eek_keyboard_set_group (client->description, value);
|
||||
eekboard_keyboard_set_group (client->keyboard, value);
|
||||
eekboard_context_set_group (client->context, value, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -480,7 +499,7 @@ on_key_pressed (EekKeyboard *keyboard,
|
||||
|
||||
g_assert (client->fakekey);
|
||||
|
||||
modifiers = eek_keyboard_get_modifiers (client->description);
|
||||
modifiers = eek_keyboard_get_modifiers (client->keyboard);
|
||||
fakekey_modefiers = get_fakekey_modifiers (modifiers);
|
||||
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
|
||||
keycode = eek_key_get_keycode (key);
|
||||
@ -515,10 +534,10 @@ eekboard_system_client_enable_fakekey (EekboardSystemClient *client)
|
||||
g_assert (client->fakekey);
|
||||
|
||||
client->key_pressed_handler =
|
||||
g_signal_connect (client->description, "key-pressed",
|
||||
g_signal_connect (client->keyboard, "key-pressed",
|
||||
G_CALLBACK(on_key_pressed), client);
|
||||
client->key_released_handler =
|
||||
g_signal_connect (client->description, "key-released",
|
||||
g_signal_connect (client->keyboard, "key-released",
|
||||
G_CALLBACK(on_key_released), client);
|
||||
|
||||
return TRUE;
|
||||
|
||||
Reference in New Issue
Block a user