Revamp server-client API.

This commit is contained in:
Daiki Ueno
2011-08-20 09:43:20 +09:00
parent dd085be73d
commit bb85885e5d
28 changed files with 2233 additions and 1651 deletions

View File

@ -21,8 +21,6 @@ bin_PROGRAMS = \
eekboard-server \
eekboard-xml
noinst_LTLIBRARIES = libxklutil.la
eekboard_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS) \
@ -32,7 +30,6 @@ eekboard_CFLAGS = \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"
eekboard_LDADD = \
$(builddir)/libxklutil.la \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-xkl.la \
@ -74,7 +71,6 @@ eekboard_server_CFLAGS = \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"
eekboard_server_LDADD = \
$(builddir)/libxklutil.la \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-gtk.la \
@ -93,8 +89,8 @@ eekboard_server_CFLAGS += $(XDOCK_CFLAGS)
eekboard_server_LDADD += $(XDOCK_LIBS)
endif
eekboard_server_headers = server-server.h server-context.h
eekboard_server_SOURCES = server-server.c server-context.c server-main.c
eekboard_server_headers = server-service.h server-context-service.h
eekboard_server_SOURCES = server-service.c server-context-service.c server-main.c
eekboard_xml_CFLAGS = \
-I$(top_srcdir) \
@ -103,7 +99,7 @@ eekboard_xml_CFLAGS = \
$(LIBXKLAVIER_CFLAGS)
eekboard_xml_LDADD = \
$(builddir)/libxklutil.la \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-xkl.la \
$(top_builddir)/eek/libeek-gtk.la \
@ -118,11 +114,6 @@ endif
eekboard_xml_SOURCES = xml-main.c
libxklutil_la_headers = xklutil.h
libxklutil_la_SOURCES = xklutil.c
libxklutil_la_CFLAGS = $(LIBXKLAVIER_CFLAGS)
libxklutil_la_LIBADD = $(LIBXKLAVIER_LIBS)
eekboarddir = $(includedir)/eekboard-$(EEK_API_VERSION)/eekboard
eekboard_HEADERS = \
$(libeekboard_headers)
@ -130,5 +121,4 @@ eekboard_HEADERS = \
noinst_HEADERS = \
$(eekboard_headers) \
$(eekboard_server_headers) \
$(eekboard_xml_headers) \
$(libxklutil_la_headers)
$(eekboard_xml_headers)

View File

@ -29,7 +29,7 @@
#endif /* HAVE_IBUS */
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "eekboard/eekboard.h"
#include "eekboard/eekboard-client.h"
#include "client.h"
#define DEFAULT_KEYBOARD "us"
@ -64,14 +64,14 @@ static const GOptionEntry options[] = {
};
static void
on_notify_keyboard_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
on_notify_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
GMainLoop *loop = user_data;
gboolean visible;
g_object_get (object, "keyboard-visible", &visible, NULL);
g_object_get (object, "visible", &visible, NULL);
/* user explicitly closed the window */
if (!visible && eekboard_context_is_enabled (EEKBOARD_CONTEXT(object)))
@ -88,7 +88,7 @@ on_context_destroyed (EekboardContext *context,
}
static void
on_destroyed (EekboardEekboard *eekboard,
on_destroyed (EekboardClient *eekboard,
gpointer user_data)
{
GMainLoop *loop = user_data;
@ -96,23 +96,23 @@ on_destroyed (EekboardEekboard *eekboard,
g_main_loop_quit (loop);
}
enum {
enum FocusListenerType {
FOCUS_NONE,
FOCUS_ATSPI,
FOCUS_IBUS
};
static gboolean
set_keyboard (EekboardClient *client,
set_keyboard (Client *client,
const gchar *keyboard)
{
if (g_strcmp0 (keyboard, "system") == 0) {
if (!eekboard_client_enable_xkl (client)) {
if (!client_enable_xkl (client)) {
g_printerr ("Can't register xklavier event listeners\n");
return FALSE;
}
} else {
if (!eekboard_client_set_keyboard (client, keyboard)) {
if (!client_set_keyboard (client, keyboard)) {
g_printerr ("Can't set keyboard \"%s\"\n", keyboard);
return FALSE;
}
@ -123,8 +123,8 @@ set_keyboard (EekboardClient *client,
int
main (int argc, char **argv)
{
EekboardClient *client = NULL;
EekboardEekboard *eekboard;
Client *client = NULL;
EekboardClient *eekboard;
EekboardContext *context;
GBusType bus_type;
GDBusConnection *connection;
@ -184,7 +184,7 @@ main (int argc, char **argv)
break;
}
client = eekboard_client_new (connection);
client = client_new (connection);
g_object_unref (connection);
if (client == NULL) {
@ -197,12 +197,26 @@ main (int argc, char **argv)
if (opt_focus) {
gchar *focus_listener = g_settings_get_string (settings,
"focus-listener");
const struct {
const gchar *name;
enum FocusListenerType type;
} focus_listeners[] = {
#ifdef HAVE_ATSPI
{ "atspi", FOCUS_ATSPI },
#endif
#ifdef HAVE_IBUS
{ "ibus", FOCUS_IBUS },
#endif
{ NULL }
};
gint i;
if (g_strcmp0 (focus_listener, "atspi") == 0)
focus = FOCUS_ATSPI;
else if (g_strcmp0 (focus_listener, "ibus") == 0)
focus = FOCUS_IBUS;
else {
focus = FOCUS_NONE;
for (i = 0; focus_listeners[i].name; i++) {
if (g_strcmp0 (focus_listener, focus_listeners[i].name) == 0)
focus = focus_listeners[i].type;
}
if (focus == FOCUS_NONE) {
g_printerr ("Unknown focus listener \"%s\". "
"Try \"atspi\" or \"ibus\"\n", focus_listener);
retval = 1;
@ -215,7 +229,7 @@ main (int argc, char **argv)
GSettings *desktop_settings =
g_settings_new ("org.gnome.desktop.interface");
gboolean accessibility_enabled =
g_settings_get_boolean (settings, "toolkit-accessibility");
g_settings_get_boolean (desktop_settings, "toolkit-accessibility");
g_object_unref (desktop_settings);
if (accessibility_enabled) {
@ -226,14 +240,14 @@ main (int argc, char **argv)
}
if (focus == FOCUS_ATSPI &&
!eekboard_client_enable_atspi_focus (client)) {
!client_enable_atspi_focus (client)) {
g_printerr ("Can't register AT-SPI focus change event listeners\n");
retval = 1;
goto out;
}
if (opt_keystroke &&
!eekboard_client_enable_atspi_keystroke (client)) {
!client_enable_atspi_keystroke (client)) {
g_printerr ("Can't register AT-SPI keystroke event listeners\n");
retval = 1;
goto out;
@ -250,7 +264,7 @@ main (int argc, char **argv)
if (focus == FOCUS_IBUS) {
ibus_init ();
if (!eekboard_client_enable_ibus_focus (client)) {
if (!client_enable_ibus_focus (client)) {
g_printerr ("Can't register IBus focus change event listeners\n");
retval = 1;
goto out;
@ -259,7 +273,7 @@ main (int argc, char **argv)
#endif /* HAVE_IBUS */
#ifdef HAVE_XTEST
if (!eekboard_client_enable_xtest (client)) {
if (!client_enable_xtest (client)) {
g_printerr ("Can't init xtest\n");
g_object_unref (client);
exit (1);
@ -270,8 +284,8 @@ main (int argc, char **argv)
if (!opt_focus) {
g_object_get (client, "context", &context, NULL);
g_signal_connect (context, "notify::keyboard-visible",
G_CALLBACK(on_notify_keyboard_visible), loop);
g_signal_connect (context, "notify::visible",
G_CALLBACK(on_notify_visible), loop);
g_signal_connect (context, "destroyed",
G_CALLBACK(on_context_destroyed), loop);
g_object_unref (context);

View File

@ -39,9 +39,9 @@
#include "eek/eek.h"
#include "eek/eek-xkl.h"
#include "eekboard/eekboard.h"
#include "eekboard/eekboard-client.h"
#include "eekboard/eekboard-xklutil.h"
#include "client.h"
#include "xklutil.h"
#include <string.h>
@ -56,12 +56,12 @@ enum {
PROP_LAST
};
typedef struct _EekboardClientClass EekboardClientClass;
typedef struct _ClientClass ClientClass;
struct _EekboardClient {
struct _Client {
GObject parent;
EekboardEekboard *eekboard;
EekboardClient *eekboard;
EekboardContext *context;
GSList *keyboards;
@ -95,11 +95,11 @@ struct _EekboardClient {
GSettings *settings;
};
struct _EekboardClientClass {
struct _ClientClass {
GObjectClass parent_class;
};
G_DEFINE_TYPE (EekboardClient, eekboard_client, G_TYPE_OBJECT);
G_DEFINE_TYPE (Client, client, G_TYPE_OBJECT);
#if ENABLE_FOCUS_LISTENER
#define IS_KEYBOARD_VISIBLE(client) (!client->follows_focus)
@ -126,40 +126,40 @@ static void focus_listener_cb (const AtspiEvent *event,
static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke,
void *user_data);
#endif /* HAVE_ATSPI */
static gboolean set_keyboard (EekboardClient *client,
static gboolean set_keyboard (Client *client,
const gchar *keyboard);
static gboolean set_keyboard_from_xkl (EekboardClient *client);
static gboolean set_keyboard_from_xkl (Client *client);
#ifdef HAVE_XTEST
static void update_modifier_keycodes
(EekboardClient *client);
(Client *client);
#endif /* HAVE_XTEST */
static void
eekboard_client_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
client_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EekboardClient *client = EEKBOARD_CLIENT(object);
Client *client = CLIENT(object);
GDBusConnection *connection;
switch (prop_id) {
case PROP_CONNECTION:
connection = g_value_get_object (value);
client->eekboard = eekboard_eekboard_new (connection, NULL);
client->eekboard = eekboard_client_new (connection, NULL);
if (client->eekboard != NULL) {
client->context =
eekboard_eekboard_create_context (client->eekboard,
"eekboard",
NULL);
eekboard_client_create_context (client->eekboard,
"eekboard",
NULL);
if (client->context == NULL) {
g_object_unref (client->eekboard);
client->eekboard = NULL;
} else
eekboard_eekboard_push_context (client->eekboard,
client->context,
NULL);
eekboard_client_push_context (client->eekboard,
client->context,
NULL);
}
break;
default:
@ -171,12 +171,12 @@ eekboard_client_set_property (GObject *object,
}
static void
eekboard_client_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
client_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EekboardClient *client = EEKBOARD_CLIENT(object);
Client *client = CLIENT(object);
switch (prop_id) {
case PROP_EEKBOARD:
@ -194,19 +194,19 @@ eekboard_client_get_property (GObject *object,
}
static void
eekboard_client_dispose (GObject *object)
client_dispose (GObject *object)
{
EekboardClient *client = EEKBOARD_CLIENT(object);
Client *client = CLIENT(object);
eekboard_client_disable_xkl (client);
client_disable_xkl (client);
#ifdef HAVE_ATSPI
eekboard_client_disable_atspi_focus (client);
eekboard_client_disable_atspi_keystroke (client);
client_disable_atspi_focus (client);
client_disable_atspi_keystroke (client);
#endif /* HAVE_ATSPI */
#ifdef HAVE_IBUS
eekboard_client_disable_ibus_focus (client);
client_disable_ibus_focus (client);
if (client->ibus_bus) {
g_object_unref (client->ibus_bus);
client->ibus_bus = NULL;
@ -214,12 +214,12 @@ eekboard_client_dispose (GObject *object)
#endif /* HAVE_IBUS */
#ifdef HAVE_XTEST
eekboard_client_disable_xtest (client);
client_disable_xtest (client);
#endif /* HAVE_XTEST */
if (client->context) {
if (client->eekboard) {
eekboard_eekboard_pop_context (client->eekboard, NULL);
eekboard_client_pop_context (client->eekboard, NULL);
}
g_object_unref (client->context);
@ -236,18 +236,18 @@ eekboard_client_dispose (GObject *object)
client->settings = NULL;
}
G_OBJECT_CLASS (eekboard_client_parent_class)->dispose (object);
G_OBJECT_CLASS (client_parent_class)->dispose (object);
}
static void
eekboard_client_class_init (EekboardClientClass *klass)
client_class_init (ClientClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
gobject_class->set_property = eekboard_client_set_property;
gobject_class->get_property = eekboard_client_get_property;
gobject_class->dispose = eekboard_client_dispose;
gobject_class->set_property = client_set_property;
gobject_class->get_property = client_get_property;
gobject_class->dispose = client_dispose;
pspec = g_param_spec_object ("connection",
"Connection",
@ -261,7 +261,7 @@ eekboard_client_class_init (EekboardClientClass *klass)
pspec = g_param_spec_object ("eekboard",
"Eekboard",
"Eekboard",
EEKBOARD_TYPE_EEKBOARD,
EEKBOARD_TYPE_CLIENT,
G_PARAM_READABLE);
g_object_class_install_property (gobject_class,
PROP_EEKBOARD,
@ -278,14 +278,14 @@ eekboard_client_class_init (EekboardClientClass *klass)
}
static void
eekboard_client_init (EekboardClient *client)
client_init (Client *client)
{
client->settings = g_settings_new ("org.fedorahosted.eekboard");
}
gboolean
eekboard_client_set_keyboard (EekboardClient *client,
const gchar *keyboard)
client_set_keyboard (Client *client,
const gchar *keyboard)
{
gboolean retval;
retval = set_keyboard (client, keyboard);
@ -295,7 +295,7 @@ eekboard_client_set_keyboard (EekboardClient *client,
}
gboolean
eekboard_client_enable_xkl (EekboardClient *client)
client_enable_xkl (Client *client)
{
GdkDisplay *display = gdk_display_get_default ();
gboolean retval;
@ -338,7 +338,7 @@ eekboard_client_enable_xkl (EekboardClient *client)
}
void
eekboard_client_disable_xkl (EekboardClient *client)
client_disable_xkl (Client *client)
{
if (client->xkl_engine) {
xkl_engine_stop_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
@ -357,7 +357,7 @@ eekboard_client_disable_xkl (EekboardClient *client)
#ifdef HAVE_ATSPI
gboolean
eekboard_client_enable_atspi_focus (EekboardClient *client)
client_enable_atspi_focus (Client *client)
{
GError *error;
@ -384,7 +384,7 @@ eekboard_client_enable_atspi_focus (EekboardClient *client)
}
void
eekboard_client_disable_atspi_focus (EekboardClient *client)
client_disable_atspi_focus (Client *client)
{
GError *error;
@ -406,7 +406,7 @@ eekboard_client_disable_atspi_focus (EekboardClient *client)
}
gboolean
eekboard_client_enable_atspi_keystroke (EekboardClient *client)
client_enable_atspi_keystroke (Client *client)
{
GError *error;
@ -438,7 +438,7 @@ eekboard_client_enable_atspi_keystroke (EekboardClient *client)
}
void
eekboard_client_disable_atspi_keystroke (EekboardClient *client)
client_disable_atspi_keystroke (Client *client)
{
if (client->keystroke_listener) {
GError *error;
@ -466,7 +466,7 @@ static void
focus_listener_cb (const AtspiEvent *event,
void *user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
AtspiAccessible *accessible = event->source;
AtspiStateSet *state_set = atspi_accessible_get_state_set (accessible);
AtspiRole role;
@ -516,14 +516,14 @@ static gboolean
keystroke_listener_cb (const AtspiDeviceEvent *stroke,
void *user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
switch (stroke->type) {
case ATSPI_KEY_PRESSED:
eekboard_context_press_key (client->context, stroke->hw_code, NULL);
eekboard_context_press_keycode (client->context, stroke->hw_code, NULL);
break;
case ATSPI_KEY_RELEASED:
eekboard_context_release_key (client->context, stroke->hw_code, NULL);
eekboard_context_release_keycode (client->context, stroke->hw_code, NULL);
break;
default:
g_return_val_if_reached (FALSE);
@ -537,25 +537,25 @@ static void
add_match_rule (GDBusConnection *connection,
const gchar *match_rule)
{
GError *error;
GDBusMessage *message;
GError *error;
GDBusMessage *message;
message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
"AddMatch");
g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule));
error = NULL;
g_dbus_connection_send_message (connection,
message,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
NULL,
&error);
g_object_unref (message);
message = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* path */
"org.freedesktop.DBus", /* interface */
"AddMatch");
g_dbus_message_set_body (message, g_variant_new ("(s)", match_rule));
error = NULL;
g_dbus_connection_send_message (connection,
message,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
NULL,
&error);
g_object_unref (message);
}
static gboolean
on_hide_keyboard_timeout (EekboardClient *client)
on_hide_keyboard_timeout (Client *client)
{
eekboard_context_hide_keyboard (client->context, NULL);
client->hide_keyboard_timeout_id = 0;
@ -568,7 +568,7 @@ focus_message_filter (GDBusConnection *connection,
gboolean incoming,
gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
if (incoming &&
g_strcmp0 (g_dbus_message_get_interface (message),
@ -598,7 +598,7 @@ focus_message_filter (GDBusConnection *connection,
static void
_ibus_connect_focus_handlers (IBusBus *bus, gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
GDBusConnection *connection;
connection = ibus_bus_get_connection (bus);
@ -618,7 +618,7 @@ _ibus_connect_focus_handlers (IBusBus *bus, gpointer user_data)
}
gboolean
eekboard_client_enable_ibus_focus (EekboardClient *client)
client_enable_ibus_focus (Client *client)
{
if (!client->ibus_bus) {
client->ibus_bus = ibus_bus_new ();
@ -636,7 +636,7 @@ eekboard_client_enable_ibus_focus (EekboardClient *client)
}
void
eekboard_client_disable_ibus_focus (EekboardClient *client)
client_disable_ibus_focus (Client *client)
{
GDBusConnection *connection;
@ -654,12 +654,12 @@ eekboard_client_disable_ibus_focus (EekboardClient *client)
}
#endif /* HAVE_ATSPI */
EekboardClient *
eekboard_client_new (GDBusConnection *connection)
Client *
client_new (GDBusConnection *connection)
{
EekboardClient *client = g_object_new (EEKBOARD_TYPE_CLIENT,
"connection", connection,
NULL);
Client *client = g_object_new (TYPE_CLIENT,
"connection", connection,
NULL);
if (client->context)
return client;
return NULL;
@ -670,7 +670,7 @@ filter_xkl_event (GdkXEvent *xev,
GdkEvent *event,
gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
XEvent *xevent = (XEvent *)xev;
xkl_engine_filter_events (client->xkl_engine, xevent);
@ -681,7 +681,7 @@ static void
on_xkl_config_changed (XklEngine *xklengine,
gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
gboolean retval;
retval = set_keyboard_from_xkl (client);
@ -693,7 +693,7 @@ on_xkl_config_changed (XklEngine *xklengine,
}
static gboolean
set_keyboard (EekboardClient *client,
set_keyboard (Client *client,
const gchar *keyboard)
{
GSList *keyboards = NULL;
@ -729,7 +729,7 @@ set_keyboard (EekboardClient *client,
}
static gboolean
set_keyboard_from_xkl (EekboardClient *client)
set_keyboard_from_xkl (Client *client)
{
XklConfigRec *rec;
gchar *layout, *keyboard;
@ -761,7 +761,7 @@ on_xkl_state_changed (XklEngine *xklengine,
gboolean restore,
gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
if (type == GROUP_CHANGED)
eekboard_context_set_group (client->context, value, NULL);
@ -776,7 +776,7 @@ on_xkl_state_changed (XklEngine *xklengine,
- get_keycode_from_gdk_keymap (Caribou: best_keycode_keyval_match)
*/
static guint
get_replaced_keycode (EekboardClient *client)
get_replaced_keycode (Client *client)
{
GdkDisplay *display = gdk_display_get_default ();
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
@ -798,7 +798,7 @@ get_replaced_keycode (EekboardClient *client)
non-zero keycode), it simply changes the current map with the
specified KEYCODE and KEYSYM. */
static gboolean
replace_keycode (EekboardClient *client,
replace_keycode (Client *client,
guint *keycode,
guint *keysym)
{
@ -834,7 +834,7 @@ replace_keycode (EekboardClient *client,
}
static gboolean
get_keycode_from_gdk_keymap (EekboardClient *client,
get_keycode_from_gdk_keymap (Client *client,
guint keysym,
guint *keycode,
guint *modifiers)
@ -859,7 +859,7 @@ get_keycode_from_gdk_keymap (EekboardClient *client,
}
static void
send_fake_modifier_key_event (EekboardClient *client,
send_fake_modifier_key_event (Client *client,
EekModifierType modifiers,
gboolean is_pressed)
{
@ -881,7 +881,7 @@ send_fake_modifier_key_event (EekboardClient *client,
}
static void
send_fake_key_event (EekboardClient *client,
send_fake_key_event (Client *client,
EekSymbol *symbol,
guint keyboard_modifiers,
gboolean is_pressed)
@ -939,7 +939,7 @@ on_key_pressed (EekboardContext *context,
guint modifiers,
gpointer user_data)
{
EekboardClient *client = user_data;
Client *client = user_data;
if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) {
client->keyboards = g_slist_next (client->keyboards);
@ -953,7 +953,7 @@ on_key_pressed (EekboardContext *context,
}
static void
update_modifier_keycodes (EekboardClient *client)
update_modifier_keycodes (Client *client)
{
GdkDisplay *display = gdk_display_get_default ();
XModifierKeymap *mods;
@ -974,7 +974,7 @@ update_modifier_keycodes (EekboardClient *client)
}
gboolean
eekboard_client_enable_xtest (EekboardClient *client)
client_enable_xtest (Client *client)
{
GdkDisplay *display = gdk_display_get_default ();
int opcode, event_base, error_base, major_version, minor_version;
@ -1011,7 +1011,7 @@ eekboard_client_enable_xtest (EekboardClient *client)
}
void
eekboard_client_disable_xtest (EekboardClient *client)
client_disable_xtest (Client *client)
{
if (client->xkb) {
XkbFreeKeyboard (client->xkb, 0, TRUE); /* free_all = TRUE */

View File

@ -15,48 +15,41 @@
* 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_CLIENT_H
#define EEKBOARD_CLIENT_H 1
#ifndef CLIENT_H
#define CLIENT_H 1
#include <gio/gio.h>
G_BEGIN_DECLS
#define EEKBOARD_TYPE_CLIENT (eekboard_client_get_type())
#define EEKBOARD_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_CLIENT, EekboardClient))
#define EEKBOARD_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
#define EEKBOARD_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_CLIENT))
#define EEKBOARD_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_CLIENT))
#define EEKBOARD_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
#define TYPE_CLIENT (client_get_type())
#define CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLIENT, Client))
#define CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLIENT, ClientClass))
#define IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLIENT))
#define IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLIENT))
#define CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLIENT, ClientClass))
typedef struct _EekboardClient EekboardClient;
typedef struct _Client Client;
EekboardClient * eekboard_client_new (GDBusConnection *connection);
Client *client_new (GDBusConnection *connection);
gboolean eekboard_client_set_keyboard
(EekboardClient *client,
const gchar *keyboard);
gboolean client_set_keyboard (Client *client,
const gchar *keyboard);
gboolean eekboard_client_enable_xkl (EekboardClient *client);
void eekboard_client_disable_xkl (EekboardClient *client);
gboolean client_enable_xkl (Client *client);
void client_disable_xkl (Client *client);
gboolean eekboard_client_enable_atspi_focus
(EekboardClient *client);
void eekboard_client_disable_atspi_focus
(EekboardClient *client);
gboolean client_enable_atspi_focus (Client *client);
void client_disable_atspi_focus (Client *client);
gboolean eekboard_client_enable_atspi_keystroke
(EekboardClient *client);
void eekboard_client_disable_atspi_keystroke
(EekboardClient *client);
gboolean client_enable_atspi_keystroke (Client *client);
void client_disable_atspi_keystroke (Client *client);
gboolean eekboard_client_enable_xtest (EekboardClient *client);
void eekboard_client_disable_xtest (EekboardClient *client);
gboolean client_enable_xtest (Client *client);
void client_disable_xtest (Client *client);
gboolean eekboard_client_enable_ibus_focus
(EekboardClient *client);
void eekboard_client_disable_ibus_focus
(EekboardClient *client);
gboolean client_enable_ibus_focus (Client *client);
void client_disable_ibus_focus (Client *client);
G_END_DECLS
#endif /* EEKBOARD_CLIENT_H */
#endif /* CLIENT_H */

View File

@ -0,0 +1,473 @@
/*
* 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 <gtk/gtk.h>
#include <glib/gi18n.h>
#include <X11/Xatom.h>
#include <gdk/gdkx.h>
#if HAVE_CLUTTER_GTK
#include <clutter-gtk/clutter-gtk.h>
#include "eek/eek-clutter.h"
#endif
#include "eek/eek-gtk.h"
#include "server-context-service.h"
#define DEFAULT_THEME (THEMEDIR "/default.css")
enum {
PROP_0,
PROP_UI_TOOLKIT,
PROP_LAST
};
typedef enum {
UI_TOOLKIT_GTK,
UI_TOOLKIT_CLUTTER,
UI_TOOLKIT_DEFAULT = UI_TOOLKIT_GTK
} UIToolkitType;
typedef struct _ServerContextServiceClass ServerContextServiceClass;
struct _ServerContextService {
EekboardContextService parent;
gboolean was_visible;
GtkWidget *window;
GtkWidget *widget;
gulong notify_visible_handler;
GSettings *settings;
UIToolkitType ui_toolkit;
};
struct _ServerContextServiceClass {
EekboardContextServiceClass parent_class;
};
G_DEFINE_TYPE (ServerContextService, server_context_service, EEKBOARD_TYPE_CONTEXT_SERVICE);
static void update_widget (ServerContextService *context);
static void set_geometry (ServerContextService *context);
static void
on_monitors_changed (GdkScreen *screen,
gpointer user_data)
{
ServerContextService *context = user_data;
if (context->window)
set_geometry (context);
}
static void
on_destroy (GtkWidget *widget, gpointer user_data)
{
ServerContextService *context = user_data;
g_assert (widget == context->window);
context->window = NULL;
context->widget = NULL;
}
static void
on_notify_keyboard (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
ServerContextService *context = user_data;
const EekKeyboard *keyboard;
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
if (context->window) {
if (keyboard == NULL) {
gtk_widget_hide (context->window);
gtk_widget_destroy (context->widget);
} else {
gboolean was_visible = gtk_widget_get_visible (context->window);
/* avoid to send KeyboardVisibilityChanged */
g_signal_handler_block (context->window,
context->notify_visible_handler);
update_widget (context);
if (was_visible)
gtk_widget_show_all (context->window);
g_signal_handler_unblock (context->window,
context->notify_visible_handler);
}
}
}
static void
on_notify_fullscreen (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
ServerContextService *context = user_data;
set_geometry (context);
}
static void
on_notify_visible (GObject *object, GParamSpec *spec, gpointer user_data)
{
ServerContextService *context = user_data;
gboolean visible;
g_object_get (object, "visible", &visible, NULL);
g_object_set (context, "visible", visible, NULL);
}
static void
on_realize_set_dock (GtkWidget *widget,
gpointer user_data)
{
#ifdef HAVE_XDOCK
GdkWindow *window = gtk_widget_get_window (widget);
gint x, y, width, height, depth;
long vals[12];
/* set window type to dock */
gdk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DOCK);
/* set bottom strut */
#if GTK_CHECK_VERSION(3,0,0)
gdk_window_get_geometry (window, &x, &y, &width, &height);
#else
gdk_window_get_geometry (window, &x, &y, &width, &height, &depth);
#endif /* GTK_CHECK_VERSION(3,0,0) */
vals[0] = 0;
vals[1] = 0;
vals[2] = 0;
vals[3] = height;
vals[4] = 0;
vals[5] = 0;
vals[6] = 0;
vals[7] = 0;
vals[8] = 0;
vals[9] = 0;
vals[10] = x;
vals[11] = x + width;
XChangeProperty (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
XInternAtom (GDK_WINDOW_XDISPLAY (window),
"_NET_WM_STRUT_PARTIAL", False),
XA_CARDINAL, 32, PropModeReplace,
(guchar *)vals, 12);
#endif /* HAVE_XDOCK */
}
static void
on_realize_set_non_maximizable (GtkWidget *widget,
gpointer user_data)
{
ServerContextService *context = user_data;
g_assert (context && context->window == widget);
/* make the window not maximizable */
gdk_window_set_functions (gtk_widget_get_window (widget),
GDK_FUNC_RESIZE |
GDK_FUNC_MOVE |
GDK_FUNC_MINIMIZE |
GDK_FUNC_CLOSE);
}
static void
set_geometry (ServerContextService *context)
{
GdkScreen *screen;
GdkWindow *root;
gint monitor;
GdkRectangle rect;
const EekKeyboard *keyboard;
EekBounds bounds;
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);
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
g_signal_handlers_disconnect_by_func (context->window,
on_realize_set_dock,
context);
g_signal_handlers_disconnect_by_func (context->window,
on_realize_set_non_maximizable,
context);
if (eekboard_context_service_get_fullscreen (EEKBOARD_CONTEXT_SERVICE(context))) {
gint width = rect.width, height = rect.height / 2;
if (width * bounds.height > height * bounds.width)
width = (height / bounds.height) * bounds.width;
else
height = (width / bounds.width) * bounds.height;
gtk_widget_set_size_request (context->widget, width, height);
gtk_window_move (GTK_WINDOW(context->window),
(rect.width - width) / 2,
rect.height - height);
gtk_window_set_decorated (GTK_WINDOW(context->window), FALSE);
gtk_window_set_resizable (GTK_WINDOW(context->window), FALSE);
gtk_window_set_opacity (GTK_WINDOW(context->window), 0.8);
g_signal_connect_after (context->window, "realize",
G_CALLBACK(on_realize_set_dock),
context);
} else {
if (context->ui_toolkit == UI_TOOLKIT_CLUTTER) {
#if HAVE_CLUTTER_GTK
ClutterActor *stage =
gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
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),
NULL);
#else
g_return_if_reached ();
#endif
}
gtk_widget_set_size_request (context->widget,
bounds.width,
bounds.height);
gtk_window_move (GTK_WINDOW(context->window),
MAX(rect.width - 20 - bounds.width, 0),
MAX(rect.height - 40 - bounds.height, 0));
g_signal_connect_after (context->window, "realize",
G_CALLBACK(on_realize_set_non_maximizable),
context);
}
}
static void
update_widget (ServerContextService *context)
{
const EekKeyboard *keyboard;
const gchar *client_name;
EekBounds bounds;
EekTheme *theme;
#if HAVE_CLUTTER_GTK
ClutterActor *stage, *actor;
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
#endif
if (context->widget)
gtk_widget_destroy (context->widget);
theme = eek_theme_new (DEFAULT_THEME, NULL, NULL);
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
if (context->ui_toolkit == UI_TOOLKIT_CLUTTER) {
#if HAVE_CLUTTER_GTK
context->widget = gtk_clutter_embed_new ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
actor = eek_clutter_keyboard_new (context->keyboard);
clutter_actor_set_name (actor, "keyboard");
if (theme)
eek_clutter_keyboard_set_theme (EEK_CLUTTER_KEYBOARD(actor), theme);
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
#else
g_return_if_reached ();
#endif
} else {
context->widget = eek_gtk_keyboard_new (keyboard);
if (theme)
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget),
theme);
}
if (!context->window) {
context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (context->window, "destroy",
G_CALLBACK(on_destroy), context);
context->notify_visible_handler =
g_signal_connect (context->window, "notify::visible",
G_CALLBACK(on_notify_visible), context);
gtk_widget_set_can_focus (context->window, FALSE);
g_object_set (G_OBJECT(context->window), "accept_focus", FALSE, NULL);
client_name = eekboard_context_service_get_client_name (EEKBOARD_CONTEXT_SERVICE(context));
gtk_window_set_title (GTK_WINDOW(context->window),
client_name ? client_name : _("Keyboard"));
gtk_window_set_icon_name (GTK_WINDOW(context->window), "eekboard");
gtk_window_set_keep_above (GTK_WINDOW(context->window), TRUE);
}
gtk_container_add (GTK_CONTAINER(context->window), context->widget);
set_geometry (context);
}
static void
server_context_service_real_show_keyboard (EekboardContextService *_context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (!context->window)
update_widget (context);
g_assert (context->window);
gtk_widget_show_all (context->window);
}
static void
server_context_service_real_hide_keyboard (EekboardContextService *_context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (context->window)
gtk_widget_hide (context->window);
}
static void
server_context_service_real_enabled (EekboardContextService *_context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (context->was_visible && context->window)
gtk_widget_show_all (context->window);
}
static void
server_context_service_real_disabled (EekboardContextService *_context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (context->window) {
context->was_visible =
gtk_widget_get_visible (context->window);
gtk_widget_hide (context->window);
}
}
static void
server_context_service_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(object);
const gchar *ui_toolkit;
switch (prop_id) {
case PROP_UI_TOOLKIT:
ui_toolkit = g_value_get_string (value);
if (g_strcmp0 (ui_toolkit, "gtk") == 0)
context->ui_toolkit = UI_TOOLKIT_GTK;
#if HAVE_CLUTTER_GTK
else if (g_strcmp0 (ui_toolkit, "clutter") == 0)
context->ui_toolkit = UI_TOOLKIT_CLUTTER;
#endif /* HAVE_CLUTTER_GTK */
else
g_warning ("unknown UI toolkit %s", ui_toolkit);
break;
default:
g_object_set_property (object,
g_param_spec_get_name (pspec),
value);
break;
}
}
static void
server_context_service_dispose (GObject *object)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(object);
if (context->window) {
gtk_widget_destroy (context->window);
context->window = NULL;
}
G_OBJECT_CLASS (server_context_service_parent_class)->dispose (object);
}
static void
server_context_service_class_init (ServerContextServiceClass *klass)
{
EekboardContextServiceClass *context_class = EEKBOARD_CONTEXT_SERVICE_CLASS(klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
context_class->show_keyboard = server_context_service_real_show_keyboard;
context_class->hide_keyboard = server_context_service_real_hide_keyboard;
context_class->enabled = server_context_service_real_enabled;
context_class->disabled = server_context_service_real_disabled;
gobject_class->set_property = server_context_service_set_property;
gobject_class->dispose = server_context_service_dispose;
pspec = g_param_spec_string ("ui-toolkit",
"UI toolkit",
"UI toolkit",
NULL,
G_PARAM_WRITABLE);
g_object_class_install_property (gobject_class,
PROP_UI_TOOLKIT,
pspec);
}
static void
server_context_service_init (ServerContextService *context)
{
GdkScreen *screen;
screen = gdk_screen_get_default ();
g_signal_connect (screen,
"monitors-changed",
G_CALLBACK(on_monitors_changed),
context);
g_signal_connect (context,
"notify::keyboard",
G_CALLBACK(on_notify_keyboard),
context);
g_signal_connect (context,
"notify::fullscreen",
G_CALLBACK(on_notify_fullscreen),
context);
context->settings = g_settings_new ("org.fedorahosted.eekboard");
g_settings_bind (context->settings, "ui-toolkit",
context, "ui-toolkit",
G_SETTINGS_BIND_GET);
}
ServerContextService *
server_context_service_new (const gchar *client_name,
const gchar *object_path,
GDBusConnection *connection)
{
return g_object_new (SERVER_TYPE_CONTEXT_SERVICE,
"client-name", client_name,
"object-path", object_path,
"connection", connection,
NULL);
}

View File

@ -0,0 +1,40 @@
/*
* 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_SERVICE_H
#define SERVER_CONTEXT_SERVICE_H 1
G_BEGIN_DECLS
#include "eekboard/eekboard-service.h"
#define SERVER_TYPE_CONTEXT_SERVICE (server_context_service_get_type())
#define SERVER_CONTEXT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVER_TYPE_CONTEXT_SERVICE, ServerContextService))
#define SERVER_CONTEXT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVER_TYPE_CONTEXT_SERVICE, ServerContextServiceClass))
#define SERVER_IS_CONTEXT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVER_TYPE_CONTEXT_SERVICE))
#define SERVER_IS_CONTEXT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVER_TYPE_CONTEXT_SERVICE))
#define SERVER_CONTEXT_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVER_TYPE_CONTEXT_SERVICE, ServerContextServiceClass))
typedef struct _ServerContextService ServerContextService;
ServerContextService *server_context_service_new (const gchar *client_name,
const gchar *object_path,
GDBusConnection *connection);
G_END_DECLS
#endif /* SERVER_CONTEXT_SERVICE_H */

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@
#include <clutter-gtk/clutter-gtk.h>
#endif
#include "server-server.h"
#include "server-service.h"
#include "eek/eek.h"
static gboolean opt_system = FALSE;
@ -61,7 +61,7 @@ on_name_lost (GDBusConnection *connection,
}
static void
on_destroyed (ServerServer *server,
on_destroyed (ServerService *service,
gpointer user_data)
{
GMainLoop *loop = user_data;
@ -72,7 +72,7 @@ on_destroyed (ServerServer *server,
int
main (int argc, char **argv)
{
ServerServer *server;
ServerService *service;
GBusType bus_type;
GDBusConnection *connection;
GError *error;
@ -131,15 +131,15 @@ main (int argc, char **argv)
break;
}
server = server_server_new (SERVER_SERVER_PATH, connection);
service = server_service_new (EEKBOARD_SERVICE_PATH, connection);
if (server == NULL) {
if (service == NULL) {
g_printerr ("Can't create server\n");
exit (1);
}
owner_id = g_bus_own_name_on_connection (connection,
SERVER_SERVER_INTERFACE,
EEKBOARD_SERVICE_INTERFACE,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_name_acquired,
on_name_lost,
@ -152,12 +152,12 @@ main (int argc, char **argv)
loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (server, "destroyed", G_CALLBACK(on_destroyed), loop);
g_signal_connect (service, "destroyed", G_CALLBACK(on_destroyed), loop);
g_main_loop_run (loop);
g_bus_unown_name (owner_id);
g_object_unref (server);
g_object_unref (service);
g_object_unref (connection);
g_main_loop_unref (loop);

View File

@ -1,426 +0,0 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "server-server.h"
#include "server-context.h"
#define I_(string) g_intern_static_string (string)
enum {
PROP_0,
PROP_OBJECT_PATH,
PROP_CONNECTION,
PROP_LAST
};
enum {
DESTROYED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
static const gchar introspection_xml[] =
"<node>"
" <interface name='org.fedorahosted.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>"
" <method name='Destroy'/>"
/* 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_finalize (GObject *object)
{
ServerServer *server = SERVER_SERVER(object);
g_free (server->object_path);
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;
gobject_class->finalize = server_server_finalize;
signals[DESTROYED] =
g_signal_new (I_("destroyed"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
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;
error = NULL;
server->introspection_data =
g_dbus_node_info_new_for_xml (introspection_xml, &error);
g_assert (server->introspection_data != NULL);
server->context_hash =
g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)g_object_unref);
}
static void
remove_context_from_stack (ServerServer *server, ServerContext *context)
{
GSList *head;
head = g_slist_find (server->context_stack, context);
if (head) {
server->context_stack = g_slist_remove_link (server->context_stack,
head);
g_object_unref (head->data);
g_slist_free1 (head);
}
if (server->context_stack)
server_context_set_enabled (server->context_stack->data, TRUE);
}
static void
server_name_vanished_callback (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
ServerServer *server = user_data;
GSList *head;
GHashTableIter iter;
gpointer k, v;
g_hash_table_iter_init (&iter, server->context_hash);
while (g_hash_table_iter_next (&iter, &k, &v)) {
const gchar *client_connection =
server_context_get_client_connection (v);
if (g_strcmp0 (client_connection, name) == 0)
g_hash_table_iter_remove (&iter);
}
for (head = server->context_stack; head; ) {
const gchar *client_connection =
server_context_get_client_connection (head->data);
GSList *next = g_slist_next (head);
if (g_strcmp0 (client_connection, name) == 0) {
server->context_stack = g_slist_remove_link (server->context_stack,
head);
g_object_unref (head->data);
g_slist_free1 (head);
}
head = next;
}
if (server->context_stack)
server_context_set_enabled (server->context_stack->data, TRUE);
}
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);
server_context_set_client_connection (context, sender);
server_context_set_client_name (context, client_name);
g_hash_table_insert (server->context_hash,
object_path,
context);
/* the vanished callback is called when clients are disconnected */
g_bus_watch_name_on_connection (server->connection,
sender,
G_BUS_NAME_WATCHER_FLAGS_NONE,
NULL,
server_name_vanished_callback,
server,
NULL);
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;
if (g_strcmp0 (server_context_get_client_connection (context),
sender) != 0) {
g_dbus_method_invocation_return_error
(invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"the current context not owned by %s",
sender);
return;
}
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;
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;
}
remove_context_from_stack (server, context);
g_hash_table_remove (server->context_hash, object_path);
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
if (g_strcmp0 (method_name, "Destroy") == 0) {
g_signal_emit_by_name (server, "destroyed", NULL);
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);
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2010-2011 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SERVER_KEYBOARD_H
#define SERVER_KEYBOARD_H 1
#include <gio/gio.h>
G_BEGIN_DECLS
#define SERVER_SERVER_PATH "/org/fedorahosted/Eekboard/Server"
#define SERVER_SERVER_INTERFACE "org.fedorahosted.Eekboard.Server"
#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))
typedef struct _ServerServer ServerServer;
ServerServer *server_server_new (const gchar *object_path,
GDBusConnection *connection);
G_END_DECLS
#endif /* SERVER_SERVER_H */

71
src/server-service.c Normal file
View File

@ -0,0 +1,71 @@
/*
* 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-service.h"
#include "server-context-service.h"
typedef struct _ServerServiceClass ServerServiceClass;
struct _ServerService {
EekboardService parent;
};
struct _ServerServiceClass {
EekboardServiceClass parent_class;
};
G_DEFINE_TYPE (ServerService, server_service, EEKBOARD_TYPE_SERVICE);
static EekboardContextService *
server_service_real_create_context (EekboardService *self,
const gchar *client_name,
const gchar *object_path)
{
GDBusConnection *connection;
ServerContextService *context;
g_object_get (G_OBJECT(self), "connection", &connection, NULL);
context = server_context_service_new (client_name, object_path, connection);
g_object_unref (connection);
return EEKBOARD_CONTEXT_SERVICE(context);
}
static void
server_service_class_init (ServerServiceClass *klass)
{
EekboardServiceClass *service_class = EEKBOARD_SERVICE_CLASS(klass);
service_class->create_context = server_service_real_create_context;
}
static void
server_service_init (ServerService *self)
{
}
ServerService *server_service_new (const gchar *object_path,
GDBusConnection *connection)
{
return g_object_new (SERVER_TYPE_SERVICE,
"object-path", object_path,
"connection", connection,
NULL);
}

38
src/server-service.h Normal file
View File

@ -0,0 +1,38 @@
/*
* 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_SERVICE_H
#define SERVER_SERVICE_H 1
#include "eekboard/eekboard-service.h"
G_BEGIN_DECLS
#define SERVER_TYPE_SERVICE (server_service_get_type())
#define SERVER_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SERVER_TYPE_SERVICE, ServerService))
#define SERVER_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SERVER_TYPE_SERVICE, ServerServiceClass))
#define SERVER_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SERVER_TYPE_SERVICE))
#define SERVER_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SERVER_TYPE_SERVICE))
#define SERVER_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SERVER_TYPE_SERVICE, ServerServiceClass))
typedef struct _ServerService ServerService;
ServerService *server_service_new (const gchar *object_path,
GDBusConnection *connection);
G_END_DECLS
#endif /* SERVER_SERVICE_H */

View File

@ -1,168 +0,0 @@
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <string.h>
#include "xklutil.h"
XklConfigRec *
eekboard_xkl_config_rec_from_string (const gchar *layouts)
{
XklConfigRec *rec;
gchar **strv, **l, **v;
gint i;
strv = g_strsplit (layouts, "/", -1);
g_return_val_if_fail (g_strv_length (strv) == 3, NULL);
l = g_strsplit (strv[1], ";", -1);
v = g_strdupv (l);
for (i = 0; l[i]; i++) {
gchar *layout = l[i], *variant = v[i],
*variant_start, *variant_end;
variant_start = strchr (layout, '(');
variant_end = strrchr (layout, ')');
if (variant_start && variant_end) {
*variant_start++ = '\0';
g_strlcpy (variant, variant_start,
variant_end - variant_start + 1);
} else
*variant = '\0';
}
rec = xkl_config_rec_new ();
rec->model = g_strdup (strv[0]);
rec->layouts = l;
rec->variants = v;
rec->options = g_strsplit (strv[2], ";", -1);
g_strfreev (strv);
return rec;
}
gchar *
eekboard_xkl_config_rec_to_string (XklConfigRec *rec)
{
gchar **strv, **sp, **lp, **vp, *p;
gint n_layouts;
GString *str;
n_layouts = g_strv_length (rec->layouts);
strv = g_malloc0_n (n_layouts + 2, sizeof (gchar *));
for (sp = strv, lp = rec->layouts, vp = rec->variants; *lp; sp++, lp++) {
if (*vp != NULL && **vp != '\0')
*sp = g_strdup_printf ("%s(%s)", *lp, *vp++);
else
*sp = g_strdup_printf ("%s", *lp);
}
/* MODEL/L0(V0);L1(V1);...;Ln(Vn)/O0;O1;...;On */
str = g_string_new (rec->model);
g_string_append_c (str, '/');
p = g_strjoinv (";", strv);
g_strfreev (strv);
g_string_append (str, p);
g_free (p);
g_string_append_c (str, '/');
p = g_strjoinv (";", rec->options);
g_string_append (str, p);
g_free (p);
return g_string_free (str,FALSE);
}
static XklConfigItem *
xkl_config_item_copy (const XklConfigItem *item)
{
XklConfigItem *_item = xkl_config_item_new ();
memcpy (_item->name,
item->name,
sizeof (item->name));
memcpy (_item->short_description,
item->short_description,
sizeof (item->short_description));
memcpy (_item->description,
item->description,
sizeof (item->description));
return _item;
}
static void
prepend_item (XklConfigRegistry *registry,
const XklConfigItem *item,
gpointer data)
{
GSList **list = data;
XklConfigItem *_item = xkl_config_item_copy (item);
*list = g_slist_prepend (*list, _item);
}
static gint
compare_item_by_name (gconstpointer a, gconstpointer b)
{
const XklConfigItem *ia = a, *ib = b;
return g_strcmp0 (ia->name, ib->name);
}
GSList *
eekboard_xkl_list_models (XklConfigRegistry *registry)
{
GSList *list = NULL;
xkl_config_registry_foreach_model (registry, prepend_item, &list);
return g_slist_sort (list, compare_item_by_name);
}
GSList *
eekboard_xkl_list_layouts (XklConfigRegistry *registry)
{
GSList *list = NULL;
xkl_config_registry_foreach_layout (registry, prepend_item, &list);
return g_slist_sort (list, compare_item_by_name);
}
GSList *
eekboard_xkl_list_option_groups (XklConfigRegistry *registry)
{
GSList *list = NULL;
xkl_config_registry_foreach_option_group (registry, prepend_item, &list);
return g_slist_sort (list, compare_item_by_name);
}
GSList *
eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
const gchar *layout)
{
GSList *list = NULL;
xkl_config_registry_foreach_layout_variant (registry,
layout,
prepend_item,
&list);
return g_slist_sort (list, compare_item_by_name);
}
GSList *
eekboard_xkl_list_options (XklConfigRegistry *registry,
const gchar *group)
{
GSList *list = NULL;
xkl_config_registry_foreach_option (registry, group, prepend_item, &list);
return g_slist_sort (list, compare_item_by_name);
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef EEKBOARD_XKLUTIL_H
#define EEKBOARD_XKLUTIL_H 1
#include <libxklavier/xklavier.h>
G_BEGIN_DECLS
XklConfigRec *eekboard_xkl_config_rec_from_string (const gchar *layouts);
gchar *eekboard_xkl_config_rec_to_string (XklConfigRec *rec);
GSList *eekboard_xkl_list_models (XklConfigRegistry *registry);
GSList *eekboard_xkl_list_layouts (XklConfigRegistry *registry);
GSList *eekboard_xkl_list_option_groups (XklConfigRegistry *registry);
GSList *eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
const gchar *layout);
GSList *eekboard_xkl_list_options (XklConfigRegistry *registry,
const gchar *group);
G_END_DECLS
#endif /* EEKBOARD_XKLUTIL_H */

View File

@ -36,7 +36,7 @@
#include "eek/eek-gtk.h"
#endif /* !HAVE_CLUTTER_GTK */
#include "xklutil.h"
#include "eekboard/eekboard-xklutil.h"
#define BUFSIZE 8192