Check if the server is active.
This commit is contained in:
@ -37,6 +37,7 @@ enum {
|
|||||||
DISABLED,
|
DISABLED,
|
||||||
KEY_PRESSED,
|
KEY_PRESSED,
|
||||||
KEY_RELEASED,
|
KEY_RELEASED,
|
||||||
|
DESTROYED,
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -146,6 +147,12 @@ eekboard_context_real_key_released (EekboardContext *self,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
eekboard_context_real_destroyed (EekboardContext *self)
|
||||||
|
{
|
||||||
|
// g_debug ("eekboard_context_real_destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
eekboard_context_get_property (GObject *object,
|
eekboard_context_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
@ -195,6 +202,7 @@ eekboard_context_class_init (EekboardContextClass *klass)
|
|||||||
klass->disabled = eekboard_context_real_disabled;
|
klass->disabled = eekboard_context_real_disabled;
|
||||||
klass->key_pressed = eekboard_context_real_key_pressed;
|
klass->key_pressed = eekboard_context_real_key_pressed;
|
||||||
klass->key_released = eekboard_context_real_key_released;
|
klass->key_released = eekboard_context_real_key_released;
|
||||||
|
klass->destroyed = eekboard_context_real_destroyed;
|
||||||
|
|
||||||
proxy_class->g_signal = eekboard_context_real_g_signal;
|
proxy_class->g_signal = eekboard_context_real_g_signal;
|
||||||
|
|
||||||
@ -288,6 +296,24 @@ eekboard_context_class_init (EekboardContextClass *klass)
|
|||||||
G_TYPE_NONE,
|
G_TYPE_NONE,
|
||||||
1,
|
1,
|
||||||
G_TYPE_UINT);
|
G_TYPE_UINT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EekboardContext::destroyed:
|
||||||
|
* @context: an #EekboardContext
|
||||||
|
*
|
||||||
|
* The ::destroyed signal is emitted each time the name of remote
|
||||||
|
* end is vanished.
|
||||||
|
*/
|
||||||
|
signals[DESTROYED] =
|
||||||
|
g_signal_new (I_("destroyed"),
|
||||||
|
G_TYPE_FROM_CLASS(gobject_class),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET(EekboardContextClass, destroyed),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -306,6 +332,15 @@ eekboard_context_init (EekboardContext *self)
|
|||||||
(GDestroyNotify)g_object_unref);
|
(GDestroyNotify)g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
context_name_vanished_callback (GDBusConnection *connection,
|
||||||
|
const gchar *name,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
EekboardContext *context = user_data;
|
||||||
|
g_signal_emit_by_name (context, "destroyed", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eekboard_context_new:
|
* eekboard_context_new:
|
||||||
* @connection: a #GDBusConnection
|
* @connection: a #GDBusConnection
|
||||||
@ -337,8 +372,24 @@ eekboard_context_new (GDBusConnection *connection,
|
|||||||
"g-interface-name", "com.redhat.Eekboard.Context",
|
"g-interface-name", "com.redhat.Eekboard.Context",
|
||||||
"g-object-path", object_path,
|
"g-object-path", object_path,
|
||||||
NULL);
|
NULL);
|
||||||
if (initable != NULL)
|
if (initable != NULL) {
|
||||||
return EEKBOARD_CONTEXT (initable);
|
EekboardContext *context = EEKBOARD_CONTEXT (initable);
|
||||||
|
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(context));
|
||||||
|
|
||||||
|
if (name_owner == NULL) {
|
||||||
|
g_object_unref (context);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_bus_watch_name_on_connection (connection,
|
||||||
|
name_owner,
|
||||||
|
G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||||
|
NULL,
|
||||||
|
context_name_vanished_callback,
|
||||||
|
context,
|
||||||
|
NULL);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,10 +66,11 @@ struct _EekboardContextClass {
|
|||||||
guint keycode);
|
guint keycode);
|
||||||
void (*key_released) (EekboardContext *self,
|
void (*key_released) (EekboardContext *self,
|
||||||
guint keycode);
|
guint keycode);
|
||||||
|
void (*destroyed) (EekboardContext *self);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
/* padding */
|
/* padding */
|
||||||
gpointer pdummy[24];
|
gpointer pdummy[23];
|
||||||
};
|
};
|
||||||
|
|
||||||
GType eekboard_context_get_type (void) G_GNUC_CONST;
|
GType eekboard_context_get_type (void) G_GNUC_CONST;
|
||||||
|
|||||||
@ -29,6 +29,13 @@
|
|||||||
|
|
||||||
#include "eekboard/eekboard-eekboard.h"
|
#include "eekboard/eekboard-eekboard.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DESTROYED,
|
||||||
|
LAST_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[LAST_SIGNAL] = { 0, };
|
||||||
|
|
||||||
G_DEFINE_TYPE (EekboardEekboard, eekboard_eekboard, G_TYPE_DBUS_PROXY);
|
G_DEFINE_TYPE (EekboardEekboard, eekboard_eekboard, G_TYPE_DBUS_PROXY);
|
||||||
|
|
||||||
#define EEKBOARD_EEKBOARD_GET_PRIVATE(obj) \
|
#define EEKBOARD_EEKBOARD_GET_PRIVATE(obj) \
|
||||||
@ -39,6 +46,15 @@ struct _EekboardEekboardPrivate
|
|||||||
GHashTable *context_hash;
|
GHashTable *context_hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
eekboard_eekboard_real_destroyed (EekboardEekboard *self)
|
||||||
|
{
|
||||||
|
EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(self);
|
||||||
|
|
||||||
|
// g_debug ("eekboard_eekboard_real_destroyed");
|
||||||
|
g_hash_table_remove_all (priv->context_hash);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
eekboard_eekboard_dispose (GObject *object)
|
eekboard_eekboard_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
@ -60,7 +76,27 @@ eekboard_eekboard_class_init (EekboardEekboardClass *klass)
|
|||||||
g_type_class_add_private (gobject_class,
|
g_type_class_add_private (gobject_class,
|
||||||
sizeof (EekboardEekboardPrivate));
|
sizeof (EekboardEekboardPrivate));
|
||||||
|
|
||||||
|
klass->destroyed = eekboard_eekboard_real_destroyed;
|
||||||
|
|
||||||
gobject_class->dispose = eekboard_eekboard_dispose;
|
gobject_class->dispose = eekboard_eekboard_dispose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EekboardEekboard::destroyed:
|
||||||
|
* @eekboard: an #EekboardEekboard
|
||||||
|
*
|
||||||
|
* The ::destroyed signal is emitted each time the name of remote
|
||||||
|
* end is vanished.
|
||||||
|
*/
|
||||||
|
signals[DESTROYED] =
|
||||||
|
g_signal_new (I_("destroyed"),
|
||||||
|
G_TYPE_FROM_CLASS(gobject_class),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET(EekboardEekboardClass, destroyed),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -76,6 +112,15 @@ eekboard_eekboard_init (EekboardEekboard *self)
|
|||||||
(GDestroyNotify)g_object_unref);
|
(GDestroyNotify)g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
eekboard_name_vanished_callback (GDBusConnection *connection,
|
||||||
|
const gchar *name,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
EekboardEekboard *eekboard = user_data;
|
||||||
|
g_signal_emit_by_name (eekboard, "destroyed", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eekboard_eekboard_new:
|
* eekboard_eekboard_new:
|
||||||
* @connection: a #GDBusConnection
|
* @connection: a #GDBusConnection
|
||||||
@ -102,9 +147,36 @@ eekboard_eekboard_new (GDBusConnection *connection,
|
|||||||
"g-interface-name", "com.redhat.Eekboard.Server",
|
"g-interface-name", "com.redhat.Eekboard.Server",
|
||||||
"g-object-path", "/com/redhat/Eekboard/Server",
|
"g-object-path", "/com/redhat/Eekboard/Server",
|
||||||
NULL);
|
NULL);
|
||||||
if (initable != NULL)
|
if (initable != NULL) {
|
||||||
return EEKBOARD_EEKBOARD (initable);
|
EekboardEekboard *eekboard = EEKBOARD_EEKBOARD (initable);
|
||||||
|
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(eekboard));
|
||||||
|
if (name_owner == NULL) {
|
||||||
|
g_object_unref (eekboard);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_bus_watch_name_on_connection (connection,
|
||||||
|
name_owner,
|
||||||
|
G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||||
|
NULL,
|
||||||
|
eekboard_name_vanished_callback,
|
||||||
|
eekboard,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return eekboard;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_context_destroyed (EekboardContext *context,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
EekboardEekboard *eekboard = user_data;
|
||||||
|
EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
|
||||||
|
|
||||||
|
g_hash_table_remove (priv->context_hash,
|
||||||
|
g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,6 +225,8 @@ eekboard_eekboard_create_context (EekboardEekboard *eekboard,
|
|||||||
g_hash_table_insert (priv->context_hash,
|
g_hash_table_insert (priv->context_hash,
|
||||||
g_strdup (object_path),
|
g_strdup (object_path),
|
||||||
g_object_ref (context));
|
g_object_ref (context));
|
||||||
|
g_signal_connect (context, "destroyed",
|
||||||
|
G_CALLBACK(on_context_destroyed), eekboard);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,9 +45,12 @@ struct _EekboardEekboardClass {
|
|||||||
/*< private >*/
|
/*< private >*/
|
||||||
GDBusProxyClass parent_class;
|
GDBusProxyClass parent_class;
|
||||||
|
|
||||||
|
/* signals */
|
||||||
|
void (* destroyed) (EekboardEekboard *self);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
/* padding */
|
/* padding */
|
||||||
gpointer pdummy[24];
|
gpointer pdummy[23];
|
||||||
};
|
};
|
||||||
|
|
||||||
GType eekboard_eekboard_get_type (void) G_GNUC_CONST;
|
GType eekboard_eekboard_get_type (void) G_GNUC_CONST;
|
||||||
|
|||||||
@ -77,10 +77,29 @@ on_notify_keyboard_visible (GObject *object,
|
|||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_context_destroyed (EekboardContext *context,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GMainLoop *loop = user_data;
|
||||||
|
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_destroyed (EekboardEekboard *eekboard,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GMainLoop *loop = user_data;
|
||||||
|
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
EekboardDesktopClient *client;
|
EekboardDesktopClient *client;
|
||||||
|
EekboardEekboard *eekboard;
|
||||||
EekboardContext *context;
|
EekboardContext *context;
|
||||||
GBusType bus_type;
|
GBusType bus_type;
|
||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
@ -136,6 +155,10 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
client = eekboard_desktop_client_new (connection);
|
client = eekboard_desktop_client_new (connection);
|
||||||
|
if (client == NULL) {
|
||||||
|
g_printerr ("Can't create a client\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
gconfc = gconf_client_get_default ();
|
gconfc = gconf_client_get_default ();
|
||||||
|
|
||||||
@ -196,9 +219,15 @@ main (int argc, char **argv)
|
|||||||
g_object_get (client, "context", &context, NULL);
|
g_object_get (client, "context", &context, NULL);
|
||||||
g_signal_connect (context, "notify::keyboard-visible",
|
g_signal_connect (context, "notify::keyboard-visible",
|
||||||
G_CALLBACK(on_notify_keyboard_visible), loop);
|
G_CALLBACK(on_notify_keyboard_visible), loop);
|
||||||
|
g_signal_connect (context, "destroyed",
|
||||||
|
G_CALLBACK(on_context_destroyed), loop);
|
||||||
g_object_unref (context);
|
g_object_unref (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_object_get (client, "eekboard", &eekboard, NULL);
|
||||||
|
g_signal_connect (eekboard, "destroyed",
|
||||||
|
G_CALLBACK(on_destroyed), loop);
|
||||||
|
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
g_main_loop_unref (loop);
|
g_main_loop_unref (loop);
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,7 @@
|
|||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_CONNECTION,
|
PROP_CONNECTION,
|
||||||
|
PROP_EEKBOARD,
|
||||||
PROP_CONTEXT,
|
PROP_CONTEXT,
|
||||||
PROP_LAST
|
PROP_LAST
|
||||||
};
|
};
|
||||||
@ -124,15 +125,19 @@ eekboard_desktop_client_set_property (GObject *object,
|
|||||||
connection = g_value_get_object (value);
|
connection = g_value_get_object (value);
|
||||||
|
|
||||||
client->eekboard = eekboard_eekboard_new (connection, NULL);
|
client->eekboard = eekboard_eekboard_new (connection, NULL);
|
||||||
g_assert (client->eekboard);
|
if (client->eekboard != NULL) {
|
||||||
|
|
||||||
client->context =
|
client->context =
|
||||||
eekboard_eekboard_create_context (client->eekboard,
|
eekboard_eekboard_create_context (client->eekboard,
|
||||||
"eekboard-desktop-client",
|
"eekboard-desktop-client",
|
||||||
NULL);
|
NULL);
|
||||||
g_assert (client->context);
|
if (client->context == NULL) {
|
||||||
|
g_object_unref (client->eekboard);
|
||||||
eekboard_eekboard_push_context (client->eekboard, client->context, NULL);
|
client->eekboard = NULL;
|
||||||
|
} else
|
||||||
|
eekboard_eekboard_push_context (client->eekboard,
|
||||||
|
client->context,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_object_set_property (object,
|
g_object_set_property (object,
|
||||||
@ -151,6 +156,9 @@ eekboard_desktop_client_get_property (GObject *object,
|
|||||||
EekboardDesktopClient *client = EEKBOARD_DESKTOP_CLIENT(object);
|
EekboardDesktopClient *client = EEKBOARD_DESKTOP_CLIENT(object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
|
case PROP_EEKBOARD:
|
||||||
|
g_value_set_object (value, client->eekboard);
|
||||||
|
break;
|
||||||
case PROP_CONTEXT:
|
case PROP_CONTEXT:
|
||||||
g_value_set_object (value, client->context);
|
g_value_set_object (value, client->context);
|
||||||
break;
|
break;
|
||||||
@ -230,6 +238,15 @@ eekboard_desktop_client_class_init (EekboardDesktopClientClass *klass)
|
|||||||
PROP_CONNECTION,
|
PROP_CONNECTION,
|
||||||
pspec);
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_object ("eekboard",
|
||||||
|
"Eekboard",
|
||||||
|
"Eekboard",
|
||||||
|
EEKBOARD_TYPE_EEKBOARD,
|
||||||
|
G_PARAM_READABLE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_EEKBOARD,
|
||||||
|
pspec);
|
||||||
|
|
||||||
pspec = g_param_spec_object ("context",
|
pspec = g_param_spec_object ("context",
|
||||||
"Context",
|
"Context",
|
||||||
"Context",
|
"Context",
|
||||||
@ -460,9 +477,12 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
|
|||||||
EekboardDesktopClient *
|
EekboardDesktopClient *
|
||||||
eekboard_desktop_client_new (GDBusConnection *connection)
|
eekboard_desktop_client_new (GDBusConnection *connection)
|
||||||
{
|
{
|
||||||
return g_object_new (EEKBOARD_TYPE_DESKTOP_CLIENT,
|
EekboardDesktopClient *client = g_object_new (EEKBOARD_TYPE_DESKTOP_CLIENT,
|
||||||
"connection", connection,
|
"connection", connection,
|
||||||
NULL);
|
NULL);
|
||||||
|
if (client->context)
|
||||||
|
return client;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkFilterReturn
|
static GdkFilterReturn
|
||||||
|
|||||||
Reference in New Issue
Block a user