Add keyboard selection dialog to preferences.

This commit is contained in:
Daiki Ueno
2012-03-28 11:24:46 +09:00
parent 1943749cb6
commit ee0505c100
20 changed files with 951 additions and 424 deletions

View File

@ -256,7 +256,6 @@ Build options:
Build shared libs $enable_shared Build shared libs $enable_shared
Build static libs $enable_static Build static libs $enable_static
CFLAGS $CFLAGS CFLAGS $CFLAGS
GTK version $with_gtk
Build Vala binding $enable_vala Build Vala binding $enable_vala
Sound support $enable_libcanberra Sound support $enable_libcanberra
Build document $enable_gtk_doc Build document $enable_gtk_doc

View File

@ -119,7 +119,7 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self); EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
GtkAllocation allocation; GtkAllocation allocation;
EekColor background; EekColor background;
GList *head; GList *list, *head;
gtk_widget_get_allocation (self, &allocation); gtk_widget_get_allocation (self, &allocation);
@ -164,16 +164,18 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
eek_renderer_render_keyboard (priv->renderer, cr); eek_renderer_render_keyboard (priv->renderer, cr);
/* redraw pressed key */ /* redraw pressed key */
head = eek_keyboard_get_pressed_keys (priv->keyboard); list = eek_keyboard_get_pressed_keys (priv->keyboard);
for (; head; head = g_list_next (head)) { for (head = list; head; head = g_list_next (head)) {
render_pressed_key (self, head->data); render_pressed_key (self, head->data);
} }
g_list_free (list);
/* redraw locked key */ /* redraw locked key */
head = eek_keyboard_get_locked_keys (priv->keyboard); list = eek_keyboard_get_locked_keys (priv->keyboard);
for (; head; head = g_list_next (head)) { for (head = list; head; head = g_list_next (head)) {
render_locked_key (self, ((EekModifierKey *)head->data)->key); render_locked_key (self, ((EekModifierKey *)head->data)->key);
} }
g_list_free (list);
return FALSE; return FALSE;
} }
@ -213,16 +215,12 @@ eek_gtk_keyboard_real_button_release_event (GtkWidget *self,
GdkEventButton *event) GdkEventButton *event)
{ {
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self); EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
GList *head = eek_keyboard_get_pressed_keys (priv->keyboard); GList *list, *head;
/* Make a copy of HEAD before sending "released" signal on list = eek_keyboard_get_pressed_keys (priv->keyboard);
elements, so that the default handler of for (head = list; head; head = g_list_next (head))
EekKeyboard::key-released signal can remove elements from its
internal copy */
head = g_list_copy (head);
for (; head; head = g_list_next (head))
g_signal_emit_by_name (head->data, "released", priv->keyboard); g_signal_emit_by_name (head->data, "released", priv->keyboard);
g_list_free (head); g_list_free (list);
return TRUE; return TRUE;
} }
@ -238,21 +236,17 @@ eek_gtk_keyboard_real_motion_notify_event (GtkWidget *self,
(gdouble)event->x, (gdouble)event->x,
(gdouble)event->y); (gdouble)event->y);
if (key) { if (key) {
GList *head = eek_keyboard_get_pressed_keys (priv->keyboard); GList *list, *head;
gboolean found = FALSE; gboolean found = FALSE;
/* Make a copy of HEAD before sending "cancelled" signal on list = eek_keyboard_get_pressed_keys (priv->keyboard);
elements, so that the default handler of for (head = list; head; head = g_list_next (head)) {
EekKeyboard::key-cancelled signal can remove elements from its
internal copy */
head = g_list_copy (head);
for (; head; head = g_list_next (head)) {
if (head->data == key) if (head->data == key)
found = TRUE; found = TRUE;
else else
g_signal_emit_by_name (head->data, "cancelled", priv->keyboard); g_signal_emit_by_name (head->data, "cancelled", priv->keyboard);
} }
g_list_free (head); g_list_free (list);
if (!found) if (!found)
g_signal_emit_by_name (key, "pressed", priv->keyboard); g_signal_emit_by_name (key, "pressed", priv->keyboard);
@ -266,16 +260,16 @@ eek_gtk_keyboard_real_unmap (GtkWidget *self)
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self); EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
if (priv->keyboard) { if (priv->keyboard) {
GList *head = eek_keyboard_get_pressed_keys (priv->keyboard); GList *list, *head;
/* Make a copy of HEAD before sending "released" signal on /* Make a copy of HEAD before sending "released" signal on
elements, so that the default handler of elements, so that the default handler of
EekKeyboard::key-released signal can remove elements from its EekKeyboard::key-released signal can remove elements from its
internal copy */ internal copy */
head = g_list_copy (head); list = eek_keyboard_get_pressed_keys (priv->keyboard);
for (; head; head = g_list_next (head)) for (head = list; head; head = g_list_next (head))
g_signal_emit_by_name (head->data, "released", priv->keyboard); g_signal_emit_by_name (head->data, "released", priv->keyboard);
g_list_free (head); g_list_free (list);
} }
GTK_WIDGET_CLASS (eek_gtk_keyboard_parent_class)->unmap (self); GTK_WIDGET_CLASS (eek_gtk_keyboard_parent_class)->unmap (self);
@ -363,12 +357,13 @@ eek_gtk_keyboard_dispose (GObject *object)
g_signal_handler_disconnect (priv->keyboard, g_signal_handler_disconnect (priv->keyboard,
priv->symbol_index_changed_handler); priv->symbol_index_changed_handler);
GList *head; GList *list, *head;
head = eek_keyboard_get_pressed_keys (priv->keyboard); list = eek_keyboard_get_pressed_keys (priv->keyboard);
for (; head; head = g_list_next (head)) { for (head = list; head; head = g_list_next (head)) {
g_signal_emit_by_name (head->data, "released", priv->keyboard); g_signal_emit_by_name (head->data, "released", priv->keyboard);
} }
g_list_free (list);
g_object_unref (priv->keyboard); g_object_unref (priv->keyboard);
priv->keyboard = NULL; priv->keyboard = NULL;

View File

@ -74,6 +74,22 @@ struct _EekKeyboardPrivate
EekModifierType alt_gr_mask; EekModifierType alt_gr_mask;
}; };
G_DEFINE_BOXED_TYPE(EekModifierKey, eek_modifier_key,
eek_modifier_key_copy, eek_modifier_key_free);
EekModifierKey *
eek_modifier_key_copy (EekModifierKey *modkey)
{
return g_slice_dup (EekModifierKey, modkey);
}
void
eek_modifier_key_free (EekModifierKey *modkey)
{
g_object_unref (modkey->key);
g_slice_free (EekModifierKey, modkey);
}
static void static void
on_key_pressed (EekSection *section, on_key_pressed (EekSection *section,
EekKey *key, EekKey *key,
@ -240,7 +256,7 @@ set_modifiers_with_key (EekKeyboard *self,
if (priv->modifier_behavior != EEK_MODIFIER_BEHAVIOR_NONE) { if (priv->modifier_behavior != EEK_MODIFIER_BEHAVIOR_NONE) {
EekModifierKey *modifier_key = g_slice_new (EekModifierKey); EekModifierKey *modifier_key = g_slice_new (EekModifierKey);
modifier_key->modifiers = enabled; modifier_key->modifiers = enabled;
modifier_key->key = key; modifier_key->key = g_object_ref (key);
priv->locked_keys = priv->locked_keys =
g_list_prepend (priv->locked_keys, modifier_key); g_list_prepend (priv->locked_keys, modifier_key);
g_signal_emit_by_name (modifier_key->key, "locked"); g_signal_emit_by_name (modifier_key->key, "locked");
@ -356,7 +372,8 @@ eek_keyboard_finalize (GObject *object)
gint i; gint i;
g_list_free (priv->pressed_keys); g_list_free (priv->pressed_keys);
g_list_free (priv->locked_keys); g_list_free_full (priv->locked_keys,
(GDestroyNotify) eek_modifier_key_free);
for (i = 0; i < priv->outline_array->len; i++) { for (i = 0; i < priv->outline_array->len; i++) {
EekOutline *outline = &g_array_index (priv->outline_array, EekOutline *outline = &g_array_index (priv->outline_array,
@ -810,7 +827,7 @@ GList *
eek_keyboard_get_pressed_keys (EekKeyboard *keyboard) eek_keyboard_get_pressed_keys (EekKeyboard *keyboard)
{ {
g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL);
return keyboard->priv->pressed_keys; return g_list_copy (keyboard->priv->pressed_keys);
} }
/** /**
@ -825,5 +842,5 @@ GList *
eek_keyboard_get_locked_keys (EekKeyboard *keyboard) eek_keyboard_get_locked_keys (EekKeyboard *keyboard)
{ {
g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL);
return keyboard->priv->locked_keys; return g_list_copy (keyboard->priv->locked_keys);
} }

View File

@ -183,5 +183,10 @@ GList *eek_keyboard_get_pressed_keys
GList *eek_keyboard_get_locked_keys GList *eek_keyboard_get_locked_keys
(EekKeyboard *keyboard); (EekKeyboard *keyboard);
EekModifierKey *eek_modifier_key_copy
(EekModifierKey *modkey);
void eek_modifier_key_free
(EekModifierKey *modkey);
G_END_DECLS G_END_DECLS
#endif /* EEK_KEYBOARD_H */ #endif /* EEK_KEYBOARD_H */

View File

@ -56,11 +56,13 @@ struct _EekXmlLayoutPrivate
EekXmlKeyboardDesc *desc; EekXmlKeyboardDesc *desc;
}; };
G_DEFINE_BOXED_TYPE(EekXmlKeyboardDesc, eek_xml_keyboard_desc, eek_xml_keyboard_desc_copy, eek_xml_keyboard_desc_free);
#define BUFSIZE 8192 #define BUFSIZE 8192
static GSList *parse_keyboards (const gchar *path, static GList *parse_keyboards (const gchar *path,
GError **error); GError **error);
static GSList *parse_prerequisites static GList *parse_prerequisites
(const gchar *path, (const gchar *path,
GError **error); GError **error);
static gboolean parse_geometry (const gchar *path, static gboolean parse_geometry (const gchar *path,
@ -69,7 +71,7 @@ static gboolean parse_geometry (const gchar *path,
static gboolean parse_symbols_with_prerequisites static gboolean parse_symbols_with_prerequisites
(const gchar *name, (const gchar *name,
EekKeyboard *keyboard, EekKeyboard *keyboard,
GSList **loaded, GList **loaded,
GError **error); GError **error);
static gboolean parse_symbols (const gchar *path, static gboolean parse_symbols (const gchar *path,
EekKeyboard *keyboard, EekKeyboard *keyboard,
@ -107,7 +109,7 @@ keyboard_desc_free (EekXmlKeyboardDesc *desc)
struct _KeyboardsParseData { struct _KeyboardsParseData {
GSList *element_stack; GSList *element_stack;
GSList *keyboards; GList *keyboards;
}; };
typedef struct _KeyboardsParseData KeyboardsParseData; typedef struct _KeyboardsParseData KeyboardsParseData;
@ -120,7 +122,7 @@ keyboards_parse_data_new (void)
static void static void
keyboards_parse_data_free (KeyboardsParseData *data) keyboards_parse_data_free (KeyboardsParseData *data)
{ {
g_slist_free_full (data->keyboards, (GDestroyNotify) keyboard_desc_free); g_list_free_full (data->keyboards, (GDestroyNotify) keyboard_desc_free);
g_slice_free (KeyboardsParseData, data); g_slice_free (KeyboardsParseData, data);
} }
@ -150,7 +152,7 @@ keyboards_start_element_callback (GMarkupParseContext *pcontext,
EekXmlKeyboardDesc *desc = g_slice_new0 (EekXmlKeyboardDesc); EekXmlKeyboardDesc *desc = g_slice_new0 (EekXmlKeyboardDesc);
const gchar *attribute; const gchar *attribute;
data->keyboards = g_slist_prepend (data->keyboards, desc); data->keyboards = g_list_prepend (data->keyboards, desc);
attribute = get_attribute (attribute_names, attribute_values, attribute = get_attribute (attribute_names, attribute_values,
"id"); "id");
@ -821,7 +823,7 @@ struct _PrerequisitesParseData {
GSList *element_stack; GSList *element_stack;
GString *text; GString *text;
GSList *prerequisites; GList *prerequisites;
}; };
typedef struct _PrerequisitesParseData PrerequisitesParseData; typedef struct _PrerequisitesParseData PrerequisitesParseData;
@ -836,7 +838,7 @@ prerequisites_parse_data_new (void)
static void static void
prerequisites_parse_data_free (PrerequisitesParseData *data) prerequisites_parse_data_free (PrerequisitesParseData *data)
{ {
g_slist_free_full (data->prerequisites, g_free); g_list_free_full (data->prerequisites, g_free);
g_string_free (data->text, TRUE); g_string_free (data->text, TRUE);
g_slice_free (PrerequisitesParseData, data); g_slice_free (PrerequisitesParseData, data);
} }
@ -877,7 +879,7 @@ prerequisites_end_element_callback (GMarkupParseContext *pcontext,
g_slist_free1 (head); g_slist_free1 (head);
if (g_strcmp0 (element_name, "include") == 0) { if (g_strcmp0 (element_name, "include") == 0) {
data->prerequisites = g_slist_append (data->prerequisites, data->prerequisites = g_list_append (data->prerequisites,
g_strndup (data->text->str, g_strndup (data->text->str,
data->text->len)); data->text->len));
} }
@ -910,7 +912,7 @@ eek_xml_layout_real_create_keyboard (EekLayout *self,
EekXmlLayout *layout = EEK_XML_LAYOUT (self); EekXmlLayout *layout = EEK_XML_LAYOUT (self);
EekKeyboard *keyboard; EekKeyboard *keyboard;
gchar *filename, *path; gchar *filename, *path;
GSList *loaded; GList *loaded;
GError *error; GError *error;
gboolean retval; gboolean retval;
@ -935,15 +937,13 @@ eek_xml_layout_real_create_keyboard (EekLayout *self,
return NULL; return NULL;
} }
EekKey *key = eek_keyboard_find_key_by_keycode (keyboard,
149);
/* Read symbols information. */ /* Read symbols information. */
loaded = NULL; loaded = NULL;
retval = parse_symbols_with_prerequisites (layout->priv->desc->symbols, retval = parse_symbols_with_prerequisites (layout->priv->desc->symbols,
keyboard, keyboard,
&loaded, &loaded,
&error); &error);
g_slist_free_full (loaded, g_free); g_list_free_full (loaded, g_free);
if (!retval) { if (!retval) {
g_object_unref (keyboard); g_object_unref (keyboard);
g_warning ("can't parse symbols file %s: %s", g_warning ("can't parse symbols file %s: %s",
@ -1057,7 +1057,7 @@ initable_init (GInitable *initable,
GError **error) GError **error)
{ {
EekXmlLayout *layout = EEK_XML_LAYOUT (initable); EekXmlLayout *layout = EEK_XML_LAYOUT (initable);
GSList *keyboards, *p; GList *keyboards, *p;
gchar *path; gchar *path;
EekXmlKeyboardDesc *desc; EekXmlKeyboardDesc *desc;
@ -1081,10 +1081,10 @@ initable_init (GInitable *initable,
return FALSE; return FALSE;
} }
keyboards = g_slist_remove_link (keyboards, p); keyboards = g_list_remove_link (keyboards, p);
layout->priv->desc = p->data; layout->priv->desc = p->data;
g_slist_free_1 (p); g_list_free_1 (p);
g_slist_free_full (keyboards, (GDestroyNotify) keyboard_desc_free); g_list_free_full (keyboards, (GDestroyNotify) keyboard_desc_free);
return TRUE; return TRUE;
} }
@ -1095,14 +1095,34 @@ initable_iface_init (GInitableIface *initable_iface)
initable_iface->init = initable_init; initable_iface->init = initable_init;
} }
GSList * GList *
eek_xml_layout_list_keyboards (void) eek_xml_list_keyboards (void)
{ {
gchar *path; gchar *path;
GSList *keyboards; GList *keyboards;
path = g_build_filename (KEYBOARDSDIR, "keyboards.xml", NULL); path = g_build_filename (KEYBOARDSDIR, "keyboards.xml", NULL);
return parse_keyboards (path, NULL); keyboards = parse_keyboards (path, NULL);
g_free (path);
return keyboards;
}
EekXmlKeyboardDesc *
eek_xml_keyboard_desc_copy (EekXmlKeyboardDesc *desc)
{
return g_slice_dup (EekXmlKeyboardDesc, desc);
}
void
eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc)
{
g_free (desc->id);
g_free (desc->name);
g_free (desc->geometry);
g_free (desc->symbols);
g_free (desc->language);
g_free (desc->longname);
g_slice_free (EekXmlKeyboardDesc, desc);
} }
static gboolean static gboolean
@ -1164,11 +1184,11 @@ parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error)
static gboolean static gboolean
parse_symbols_with_prerequisites (const gchar *name, parse_symbols_with_prerequisites (const gchar *name,
EekKeyboard *keyboard, EekKeyboard *keyboard,
GSList **loaded, GList **loaded,
GError **error) GError **error)
{ {
gchar *filename, *path; gchar *filename, *path;
GSList *prerequisites, *p; GList *prerequisites, *p;
GError *prerequisites_error; GError *prerequisites_error;
gboolean retval; gboolean retval;
@ -1182,7 +1202,7 @@ parse_symbols_with_prerequisites (const gchar *name,
return FALSE; return FALSE;
} }
} }
*loaded = g_slist_prepend (*loaded, g_strdup (name)); *loaded = g_list_prepend (*loaded, g_strdup (name));
filename = g_strdup_printf ("%s.xml", name); filename = g_strdup_printf ("%s.xml", name);
path = g_build_filename (KEYBOARDSDIR, "symbols", filename, NULL); path = g_build_filename (KEYBOARDSDIR, "symbols", filename, NULL);
@ -1203,7 +1223,7 @@ parse_symbols_with_prerequisites (const gchar *name,
if (!retval) if (!retval)
return FALSE; return FALSE;
} }
g_slist_free_full (prerequisites, (GDestroyNotify)g_free); g_list_free_full (prerequisites, (GDestroyNotify)g_free);
retval = parse_symbols (path, keyboard, error); retval = parse_symbols (path, keyboard, error);
g_free (path); g_free (path);
@ -1243,14 +1263,14 @@ parse_symbols (const gchar *path, EekKeyboard *keyboard, GError **error)
return TRUE; return TRUE;
} }
static GSList * static GList *
parse_prerequisites (const gchar *path, GError **error) parse_prerequisites (const gchar *path, GError **error)
{ {
PrerequisitesParseData *data; PrerequisitesParseData *data;
GMarkupParseContext *pcontext; GMarkupParseContext *pcontext;
GFile *file; GFile *file;
GFileInputStream *input; GFileInputStream *input;
GSList *prerequisites; GList *prerequisites;
gboolean retval; gboolean retval;
file = g_file_new_for_path (path); file = g_file_new_for_path (path);
@ -1278,14 +1298,14 @@ parse_prerequisites (const gchar *path, GError **error)
return prerequisites; return prerequisites;
} }
static GSList * static GList *
parse_keyboards (const gchar *path, GError **error) parse_keyboards (const gchar *path, GError **error)
{ {
KeyboardsParseData *data; KeyboardsParseData *data;
GMarkupParseContext *pcontext; GMarkupParseContext *pcontext;
GFile *file; GFile *file;
GFileInputStream *input; GFileInputStream *input;
GSList *keyboards; GList *keyboards;
gboolean retval; gboolean retval;
file = g_file_new_for_path (path); file = g_file_new_for_path (path);

View File

@ -76,10 +76,13 @@ struct _EekXmlKeyboardDesc
}; };
typedef struct _EekXmlKeyboardDesc EekXmlKeyboardDesc; typedef struct _EekXmlKeyboardDesc EekXmlKeyboardDesc;
GType eek_xml_layout_get_type (void) G_GNUC_CONST; GType eek_xml_layout_get_type (void) G_GNUC_CONST;
EekLayout *eek_xml_layout_new (const gchar *id, EekLayout *eek_xml_layout_new (const gchar *id,
GError **error); GError **error);
GSList *eek_xml_layout_list_keyboards (void); GList *eek_xml_list_keyboards (void);
EekXmlKeyboardDesc *eek_xml_keyboard_desc_copy (EekXmlKeyboardDesc *desc);
void eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc);
G_END_DECLS G_END_DECLS
#endif /* EEK_XML_LAYOUT_H */ #endif /* EEK_XML_LAYOUT_H */

View File

@ -50,6 +50,7 @@ enum {
enum { enum {
ENABLED, ENABLED,
DISABLED, DISABLED,
DESTROYED,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -114,8 +115,9 @@ static const gchar introspection_xml[] =
/* signals */ /* signals */
" <signal name='Enabled'/>" " <signal name='Enabled'/>"
" <signal name='Disabled'/>" " <signal name='Disabled'/>"
" <signal name='Destroyed'/>"
" <signal name='KeyActivated'>" " <signal name='KeyActivated'>"
" <arg type='s' name='keyname'/>" " <arg type='u' name='keycode'/>"
" <arg type='v' name='symbol'/>" " <arg type='v' name='symbol'/>"
" <arg type='u' name='modifiers'/>" " <arg type='u' name='modifiers'/>"
" </signal>" " </signal>"
@ -399,6 +401,23 @@ eekboard_context_service_class_init (EekboardContextServiceClass *klass)
G_TYPE_NONE, G_TYPE_NONE,
0); 0);
/**
* EekboardContextService::destroyed:
* @context: an #EekboardContextService
*
* Emitted when @context is destroyed.
*/
signals[DESTROYED] =
g_signal_new (I_("destroyed"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardContextServiceClass, destroyed),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
/** /**
* EekboardContextService:object-path: * EekboardContextService:object-path:
* *
@ -574,7 +593,7 @@ emit_key_activated_dbus_signal (EekboardContextService *context,
EekKey *key) EekKey *key)
{ {
if (context->priv->connection && context->priv->enabled) { if (context->priv->connection && context->priv->enabled) {
const gchar *keyname = eek_element_get_name (EEK_ELEMENT(key)); guint keycode = eek_key_get_keycode (key);
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0); EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
guint modifiers = eek_keyboard_get_modifiers (context->priv->keyboard); guint modifiers = eek_keyboard_get_modifiers (context->priv->keyboard);
GVariant *variant; GVariant *variant;
@ -589,8 +608,8 @@ emit_key_activated_dbus_signal (EekboardContextService *context,
context->priv->object_path, context->priv->object_path,
EEKBOARD_CONTEXT_SERVICE_INTERFACE, EEKBOARD_CONTEXT_SERVICE_INTERFACE,
"KeyActivated", "KeyActivated",
g_variant_new ("(svu)", g_variant_new ("(uvu)",
keyname, keycode,
variant, variant,
modifiers), modifiers),
&error); &error);
@ -748,13 +767,15 @@ handle_method_call (GDBusConnection *connection,
g_variant_get (parameters, "(u)", &keyboard_id); g_variant_get (parameters, "(u)", &keyboard_id);
current_keyboard_id = if (context->priv->keyboard != NULL) {
GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(context->priv->keyboard), current_keyboard_id =
"keyboard-id")); GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(context->priv->keyboard),
if (keyboard_id == current_keyboard_id) { "keyboard-id"));
disconnect_keyboard_signals (context); if (keyboard_id == current_keyboard_id) {
context->priv->keyboard = NULL; disconnect_keyboard_signals (context);
g_object_notify (G_OBJECT(context), "keyboard"); context->priv->keyboard = NULL;
g_object_notify (G_OBJECT(context), "keyboard");
}
} }
g_hash_table_remove (context->priv->keyboard_hash, g_hash_table_remove (context->priv->keyboard_hash,
@ -978,6 +999,42 @@ eekboard_context_service_disable (EekboardContextService *context)
} }
} }
/**
* eekboard_context_service_destroy:
* @context: an #EekboardContextService
*
* Destroy @context.
*/
void
eekboard_context_service_destroy (EekboardContextService *context)
{
gboolean retval;
GError *error;
g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
g_return_if_fail (context->priv->connection);
if (context->priv->enabled) {
eekboard_context_service_disable (context);
}
error = NULL;
retval = g_dbus_connection_emit_signal (context->priv->connection,
NULL,
context->priv->object_path,
EEKBOARD_CONTEXT_SERVICE_INTERFACE,
"Destroyed",
NULL,
&error);
if (!retval) {
g_warning ("failed to emit Destroyed signal: %s",
error->message);
g_error_free (error);
g_assert_not_reached ();
}
g_signal_emit (context, signals[DESTROYED], 0);
}
/** /**
* eekboard_context_service_get_keyboard: * eekboard_context_service_get_keyboard:
* @context: an #EekboardContextService * @context: an #EekboardContextService

View File

@ -73,6 +73,7 @@ struct _EekboardContextServiceClass {
/* signals */ /* signals */
void (*enabled) (EekboardContextService *self); void (*enabled) (EekboardContextService *self);
void (*disabled) (EekboardContextService *self); void (*disabled) (EekboardContextService *self);
void (*destroyed) (EekboardContextService *self);
/*< private >*/ /*< private >*/
/* padding */ /* padding */
@ -83,6 +84,7 @@ GType eekboard_context_service_get_type
(void) G_GNUC_CONST; (void) G_GNUC_CONST;
void eekboard_context_service_enable (EekboardContextService *context); void eekboard_context_service_enable (EekboardContextService *context);
void eekboard_context_service_disable (EekboardContextService *context); void eekboard_context_service_disable (EekboardContextService *context);
void eekboard_context_service_destroy (EekboardContextService *context);
EekKeyboard *eekboard_context_service_get_keyboard EekKeyboard *eekboard_context_service_get_keyboard
(EekboardContextService *context); (EekboardContextService *context);
gboolean eekboard_context_service_get_fullscreen gboolean eekboard_context_service_get_fullscreen

View File

@ -36,8 +36,8 @@
enum { enum {
ENABLED, ENABLED,
DISABLED, DISABLED,
KEY_PRESSED,
DESTROYED, DESTROYED,
KEY_ACTIVATED,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -80,14 +80,19 @@ eekboard_context_real_g_signal (GDBusProxy *self,
return; return;
} }
if (g_strcmp0 (signal_name, "Destroyed") == 0) {
g_signal_emit (context, signals[DESTROYED], 0);
return;
}
if (g_strcmp0 (signal_name, "KeyActivated") == 0) { if (g_strcmp0 (signal_name, "KeyActivated") == 0) {
const gchar *keyname; guint keycode;
GVariant *variant = NULL; GVariant *variant = NULL;
guint modifiers = 0; guint modifiers = 0;
EekSerializable *serializable; EekSerializable *serializable;
g_variant_get (parameters, "(&svu)", g_variant_get (parameters, "(uvu)",
&keyname, &variant, &modifiers); &keycode, &variant, &modifiers);
g_return_if_fail (variant != NULL); g_return_if_fail (variant != NULL);
serializable = eek_serializable_deserialize (variant); serializable = eek_serializable_deserialize (variant);
@ -95,8 +100,8 @@ eekboard_context_real_g_signal (GDBusProxy *self,
g_return_if_fail (EEK_IS_SYMBOL(serializable)); g_return_if_fail (EEK_IS_SYMBOL(serializable));
g_signal_emit (context, signals[KEY_PRESSED], 0, g_signal_emit (context, signals[KEY_ACTIVATED], 0,
keyname, EEK_SYMBOL(serializable), modifiers); keycode, EEK_SYMBOL(serializable), modifiers);
g_object_unref (serializable); g_object_unref (serializable);
return; return;
@ -140,15 +145,15 @@ eekboard_context_real_disabled (EekboardContext *self)
} }
static void static void
eekboard_context_real_key_pressed (EekboardContext *self, eekboard_context_real_destroyed (EekboardContext *self)
const gchar *keyname,
EekSymbol *symbol,
guint modifiers)
{ {
} }
static void static void
eekboard_context_real_destroyed (EekboardContext *self) eekboard_context_real_key_activated (EekboardContext *self,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers)
{ {
} }
@ -181,8 +186,8 @@ eekboard_context_class_init (EekboardContextClass *klass)
klass->enabled = eekboard_context_real_enabled; klass->enabled = eekboard_context_real_enabled;
klass->disabled = eekboard_context_real_disabled; klass->disabled = eekboard_context_real_disabled;
klass->key_pressed = eekboard_context_real_key_pressed;
klass->destroyed = eekboard_context_real_destroyed; klass->destroyed = eekboard_context_real_destroyed;
klass->key_activated = eekboard_context_real_key_activated;
proxy_class->g_signal = eekboard_context_real_g_signal; proxy_class->g_signal = eekboard_context_real_g_signal;
@ -237,26 +242,26 @@ eekboard_context_class_init (EekboardContextClass *klass)
0); 0);
/** /**
* EekboardContext::key-pressed: * EekboardContext::key-activated:
* @context: an #EekboardContext * @context: an #EekboardContext
* @keycode: keycode * @keycode: a keycode
* @symbol: an #EekSymbol * @symbol: an #EekSymbol
* @modifiers: modifiers * @modifiers: modifiers
* *
* The ::key-pressed signal is emitted each time a key is pressed * The ::key-activated signal is emitted each time a key is
* in @context. * pressed in @context.
*/ */
signals[KEY_PRESSED] = signals[KEY_ACTIVATED] =
g_signal_new (I_("key-pressed"), g_signal_new (I_("key-activated"),
G_TYPE_FROM_CLASS(gobject_class), G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekboardContextClass, key_pressed), G_STRUCT_OFFSET(EekboardContextClass, key_activated),
NULL, NULL,
NULL, NULL,
_eekboard_marshal_VOID__STRING_OBJECT_UINT, _eekboard_marshal_VOID__UINT_OBJECT_UINT,
G_TYPE_NONE, G_TYPE_NONE,
3, 3,
G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_OBJECT, G_TYPE_OBJECT,
G_TYPE_UINT); G_TYPE_UINT);

View File

@ -66,12 +66,13 @@ struct _EekboardContextClass {
/* signals */ /* signals */
void (*enabled) (EekboardContext *self); void (*enabled) (EekboardContext *self);
void (*disabled) (EekboardContext *self); void (*disabled) (EekboardContext *self);
void (*key_pressed) (EekboardContext *self,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers);
void (*destroyed) (EekboardContext *self); void (*destroyed) (EekboardContext *self);
void (*key_activated) (EekboardContext *self,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers);
/*< private >*/ /*< private >*/
/* padding */ /* padding */
gpointer pdummy[24]; gpointer pdummy[24];

View File

@ -1 +1 @@
VOID:STRING,OBJECT,UINT VOID:UINT,OBJECT,UINT

View File

@ -70,9 +70,6 @@ static const gchar introspection_xml[] =
" <arg direction='in' type='s' name='object_path'/>" " <arg direction='in' type='s' name='object_path'/>"
" </method>" " </method>"
" <method name='PopContext'/>" " <method name='PopContext'/>"
" <method name='DestroyContext'>"
" <arg direction='in' type='s' name='object_path'/>"
" </method>"
" <method name='Destroy'/>" " <method name='Destroy'/>"
/* signals */ /* signals */
" </interface>" " </interface>"
@ -349,6 +346,18 @@ service_name_vanished_callback (GDBusConnection *connection,
eekboard_context_service_enable (service->priv->context_stack->data); eekboard_context_service_enable (service->priv->context_stack->data);
} }
static void
context_destroyed_cb (EekboardContextService *context, EekboardService *service)
{
gchar *object_path = NULL;
remove_context_from_stack (service, context);
g_object_get (G_OBJECT(context), "object-path", &object_path, NULL);
g_hash_table_remove (service->priv->context_hash, object_path);
g_free (object_path);
}
static void static void
handle_method_call (GDBusConnection *connection, handle_method_call (GDBusConnection *connection,
const gchar *sender, const gchar *sender,
@ -387,6 +396,10 @@ handle_method_call (GDBusConnection *connection,
service_name_vanished_callback, service_name_vanished_callback,
service, service,
NULL); NULL);
g_signal_connect (G_OBJECT(context), "destroyed",
G_CALLBACK(context_destroyed_cb), service);
g_dbus_method_invocation_return_value (invocation, g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", g_variant_new ("(s)",
object_path)); object_path));
@ -445,38 +458,6 @@ handle_method_call (GDBusConnection *connection,
return; return;
} }
if (g_strcmp0 (method_name, "DestroyContext") == 0) {
EekboardContextService *context;
const gchar *object_path;
const gchar *owner;
g_variant_get (parameters, "(&s)", &object_path);
context = g_hash_table_lookup (service->priv->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;
}
owner = g_object_get_data (G_OBJECT(context), "owner");
if (g_strcmp0 (owner, sender) != 0) {
g_dbus_method_invocation_return_error
(invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"the context at %s not owned by %s",
object_path, sender);
return;
}
remove_context_from_stack (service, context);
g_hash_table_remove (service->priv->context_hash, object_path);
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
if (g_strcmp0 (method_name, "Destroy") == 0) { if (g_strcmp0 (method_name, "Destroy") == 0) {
g_signal_emit (service, signals[DESTROYED], 0); g_signal_emit (service, signals[DESTROYED], 0);
g_dbus_method_invocation_return_value (invocation, NULL); g_dbus_method_invocation_return_value (invocation, NULL);

View File

@ -16,83 +16,120 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA # 02110-1301 USA
bin_PROGRAMS = \ bin_PROGRAMS = \
eekboard \ eekboard \
eekboard-server eekboard-server \
$(NULL)
eekboard_CFLAGS = \ libexec_PROGRAMS = \
-I$(top_srcdir) \ eekboard-setup \
$(GIO2_CFLAGS) \ $(NULL)
$(GTK_CFLAGS) \
$(XKB_CFLAGS) \
$(LIBXKLAVIER_CFLAGS) \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\" \
-DPKGDATADIR=\"$(pkgdatadir)\"
eekboard_LDADD = \ eekboard_CFLAGS = \
$(top_builddir)/eekboard/libeekboard.la \ -I$(top_srcdir) \
$(top_builddir)/eek/libeek.la \ $(GIO2_CFLAGS) \
$(top_builddir)/eek/libeek-xkl.la \ $(GTK_CFLAGS) \
$(GIO2_LIBS) \ $(XKB_CFLAGS) \
$(GTK_LIBS) \ $(LIBXKLAVIER_CFLAGS) \
$(XKB_LIBS) \ -DLIBEXECDIR=\"$(libexecdir)\" \
$(LIBXKLAVIER_LIBS) $(NULL)
eekboard_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-xkl.la \
$(GIO2_LIBS) \
$(GTK_LIBS) \
$(XKB_LIBS) \
$(LIBXKLAVIER_LIBS) \
$(NULL)
if ENABLE_XTEST if ENABLE_XTEST
eekboard_CFLAGS += \ eekboard_CFLAGS += $(XTEST_CFLAGS)
$(XTEST_CFLAGS) eekboard_LDADD += $(XTEST_LIBS)
eekboard_LDADD += \
$(XTEST_LIBS)
endif endif
if ENABLE_ATSPI if ENABLE_ATSPI
eekboard_CFLAGS += \ eekboard_CFLAGS += $(ATSPI2_CFLAGS)
$(ATSPI2_CFLAGS) eekboard_LDADD += $(ATSPI2_LIBS)
eekboard_LDADD += \
$(ATSPI2_LIBS)
endif endif
if ENABLE_IBUS if ENABLE_IBUS
eekboard_CFLAGS += \ eekboard_CFLAGS += $(IBUS_CFLAGS)
$(IBUS_CFLAGS) eekboard_LDADD += $(IBUS_LIBS)
eekboard_LDADD += \
$(IBUS_LIBS)
endif endif
eekboard_headers = client.h preferences-dialog.h eekboard_headers = \
eekboard_SOURCES = client.c preferences-dialog.c client-main.c client.h \
$(NULL)
eekboard_server_CFLAGS = \ eekboard_SOURCES = \
-I$(top_srcdir) \ client.c \
$(GIO2_CFLAGS) \ client-main.c \
$(GTK_CFLAGS) \ $(NULL)
$(LIBXKLAVIER_CFLAGS) \
-DTHEMEDIR=\"$(pkgdatadir)/themes\" \
-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"
eekboard_server_LDADD = \ eekboard_server_CFLAGS = \
$(top_builddir)/eekboard/libeekboard.la \ -I$(top_srcdir) \
$(top_builddir)/eek/libeek.la \ $(GIO2_CFLAGS) \
$(top_builddir)/eek/libeek-gtk.la \ $(GTK_CFLAGS) \
$(top_builddir)/eek/libeek-xkl.la \ $(LIBXKLAVIER_CFLAGS) \
$(GIO2_LIBS) \ -DTHEMESDIR=\"$(pkgdatadir)/themes\" \
$(GTK_LIBS) \ $(NULL)
$(LIBXKLAVIER_LIBS)
eekboard_server_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(top_builddir)/eek/libeek-gtk.la \
$(top_builddir)/eek/libeek-xkl.la \
$(GIO2_LIBS) \
$(GTK_LIBS) \
$(LIBXKLAVIER_LIBS) \
$(NULL)
if ENABLE_XDOCK if ENABLE_XDOCK
eekboard_server_CFLAGS += $(XDOCK_CFLAGS) eekboard_server_CFLAGS += $(XDOCK_CFLAGS)
eekboard_server_LDADD += $(XDOCK_LIBS) eekboard_server_LDADD += $(XDOCK_LIBS)
endif endif
eekboard_server_headers = server-service.h server-context-service.h eekboard_server_headers = \
eekboard_server_SOURCES = server-service.c server-context-service.c server-main.c server-service.h \
server-context-service.h \
$(NULL)
eekboarddir = $(includedir)/eekboard-$(EEK_API_VERSION)/eekboard eekboard_server_SOURCES = \
eekboard_HEADERS = \ server-service.c \
$(libeekboard_headers) server-context-service.c \
server-main.c \
$(NULL)
noinst_HEADERS = \ eekboard_setup_CFLAGS = \
$(eekboard_headers) \ -I$(top_srcdir) \
$(eekboard_server_headers) $(GIO2_CFLAGS) \
$(GTK_CFLAGS) \
$(XKB_CFLAGS) \
$(LIBXKLAVIER_CFLAGS) \
-DPKGDATADIR=\"$(pkgdatadir)\" \
$(NULL)
eekboard_setup_headers = \
preferences-dialog.h \
$(NULL)
eekboard_setup_SOURCES = \
preferences-dialog.c \
setup-main.c \
$(NULL)
eekboard_setup_LDADD = \
$(top_builddir)/eek/libeek.la \
$(GIO2_LIBS) \
$(GTK_LIBS) \
$(NULL)
dist_pkgdata_DATA = preferences-dialog.ui dist_pkgdata_DATA = preferences-dialog.ui
noinst_HEADERS = \
$(eekboard_headers) \
$(eekboard_server_headers) \
$(eekboard_setup_headers) \
$(NULL)

View File

@ -67,21 +67,6 @@ static const GOptionEntry options[] = {
{NULL} {NULL}
}; };
static void
on_notify_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
GMainLoop *loop = user_data;
gboolean visible;
g_object_get (object, "visible", &visible, NULL);
/* user explicitly closed the window */
if (!visible && eekboard_context_is_enabled (EEKBOARD_CONTEXT(object)))
g_main_loop_quit (loop);
}
static void static void
on_context_destroyed (EekboardContext *context, on_context_destroyed (EekboardContext *context,
gpointer user_data) gpointer user_data)
@ -139,7 +124,7 @@ main (int argc, char **argv)
GMainLoop *loop = NULL; GMainLoop *loop = NULL;
gint focus; gint focus;
GSettings *settings = NULL; GSettings *settings = NULL;
gchar **keyboards; gchar **keyboards = NULL;
gint retval = 0; gint retval = 0;
if (!gtk_init_check (&argc, &argv)) { if (!gtk_init_check (&argc, &argv)) {
@ -302,8 +287,6 @@ main (int argc, char **argv)
if (!opt_focus) { if (!opt_focus) {
g_object_get (client, "context", &context, NULL); g_object_get (client, "context", &context, NULL);
g_signal_connect (context, "notify::visible",
G_CALLBACK(on_notify_visible), loop);
g_signal_connect (context, "destroyed", g_signal_connect (context, "destroyed",
G_CALLBACK(on_context_destroyed), loop); G_CALLBACK(on_context_destroyed), loop);
g_object_unref (context); g_object_unref (context);
@ -321,16 +304,16 @@ main (int argc, char **argv)
G_CALLBACK(on_destroyed), loop); G_CALLBACK(on_destroyed), loop);
g_object_unref (eekboard); g_object_unref (eekboard);
if (opt_keyboards != NULL) if (opt_keyboards != NULL) {
keyboards = g_strsplit (opt_keyboards, ",", -1); keyboards = g_strsplit (opt_keyboards, ",", -1);
else
keyboards = g_settings_get_strv (settings, "keyboards"); if (!set_keyboards (client, (const gchar * const *)keyboards)) {
if (!set_keyboards (client, (const gchar * const *)keyboards)) { g_strfreev (keyboards);
retval = 1;
goto out;
}
g_strfreev (keyboards); g_strfreev (keyboards);
retval = 1;
goto out;
} }
g_strfreev (keyboards);
g_main_loop_run (loop); g_main_loop_run (loop);

View File

@ -42,7 +42,6 @@
#include "eekboard/eekboard-client.h" #include "eekboard/eekboard-client.h"
#include "eekboard/eekboard-xklutil.h" #include "eekboard/eekboard-xklutil.h"
#include "client.h" #include "client.h"
#include "preferences-dialog.h"
#include <string.h> #include <string.h>
@ -54,6 +53,7 @@ enum {
PROP_CONNECTION, PROP_CONNECTION,
PROP_EEKBOARD, PROP_EEKBOARD,
PROP_CONTEXT, PROP_CONTEXT,
PROP_KEYBOARDS,
PROP_LAST PROP_LAST
}; };
@ -66,14 +66,15 @@ struct _Client {
EekboardContext *context; EekboardContext *context;
GSList *keyboards; GSList *keyboards;
GSList *keyboards_head;
XklEngine *xkl_engine; XklEngine *xkl_engine;
XklConfigRegistry *xkl_config_registry; XklConfigRegistry *xkl_config_registry;
gulong xkl_config_changed_handler; gulong xkl_config_changed_handler;
gulong xkl_state_changed_handler; gulong xkl_state_changed_handler;
gulong key_pressed_handler; gulong key_activated_handler;
gulong key_released_handler;
gboolean follows_focus; gboolean follows_focus;
guint hide_keyboard_timeout_id; guint hide_keyboard_timeout_id;
@ -158,16 +159,21 @@ client_set_property (GObject *object,
if (client->context == NULL) { if (client->context == NULL) {
g_object_unref (client->eekboard); g_object_unref (client->eekboard);
client->eekboard = NULL; client->eekboard = NULL;
} else } else {
eekboard_client_push_context (client->eekboard, eekboard_client_push_context (client->eekboard,
client->context, client->context,
NULL); NULL);
g_settings_bind (client->settings, "keyboards",
client, "keyboards",
G_SETTINGS_BIND_GET);
}
} }
break; break;
case PROP_KEYBOARDS:
client_set_keyboards (client, g_value_get_boxed (value));
break;
default: default:
g_object_set_property (object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
g_param_spec_get_name (pspec),
value);
break; break;
} }
} }
@ -188,9 +194,7 @@ client_get_property (GObject *object,
g_value_set_object (value, client->context); g_value_set_object (value, client->context);
break; break;
default: default:
g_object_get_property (object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
g_param_spec_get_name (pspec),
value);
break; break;
} }
} }
@ -289,6 +293,15 @@ client_class_init (ClientClass *klass)
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_CONTEXT, PROP_CONTEXT,
pspec); pspec);
pspec = g_param_spec_boxed ("keyboards",
"Keyboards",
"Keyboards",
G_TYPE_STRV,
G_PARAM_WRITABLE);
g_object_class_install_property (gobject_class,
PROP_KEYBOARDS,
pspec);
} }
static void static void
@ -753,10 +766,20 @@ set_keyboards (Client *client,
{ {
guint keyboard_id; guint keyboard_id;
const gchar * const *p; const gchar * const *p;
GSList *head = NULL; GSList *head;
if (client->keyboards) g_return_val_if_fail (keyboards != NULL, FALSE);
g_return_val_if_fail (client->context, FALSE);
if (client->keyboards) {
for (head = client->keyboards; head; head = head->next) {
eekboard_context_remove_keyboard (client->context,
GPOINTER_TO_UINT(head->data),
NULL);
}
g_slist_free (client->keyboards); g_slist_free (client->keyboards);
client->keyboards = NULL;
}
for (p = keyboards; *p != NULL; p++) { for (p = keyboards; *p != NULL; p++) {
keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL); keyboard_id = eekboard_context_add_keyboard (client->context, *p, NULL);
@ -764,17 +787,16 @@ set_keyboards (Client *client,
g_slist_free (head); g_slist_free (head);
return FALSE; return FALSE;
} }
head = g_slist_prepend (head, GUINT_TO_POINTER(keyboard_id)); client->keyboards = g_slist_prepend (client->keyboards,
GUINT_TO_POINTER(keyboard_id));
} }
/* make a cycle */ client->keyboards = g_slist_reverse (client->keyboards);
head = g_slist_reverse (head); client->keyboards_head = client->keyboards;
g_slist_last (head)->next = head;
client->keyboards = head;
/* select the first keyboard */ /* select the first keyboard */
eekboard_context_set_keyboard (client->context, eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(head->data), GPOINTER_TO_UINT(client->keyboards_head->data),
NULL); NULL);
return TRUE; return TRUE;
} }
@ -1028,25 +1050,37 @@ send_fake_key_events (Client *client,
} }
static void static void
on_key_pressed (EekboardContext *context, on_key_activated (EekboardContext *context,
const gchar *keyname, guint keycode,
EekSymbol *symbol, EekSymbol *symbol,
guint modifiers, guint modifiers,
gpointer user_data) gpointer user_data)
{ {
Client *client = user_data; Client *client = user_data;
if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) { if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) {
client->keyboards = g_slist_next (client->keyboards); client->keyboards_head = g_slist_next (client->keyboards_head);
if (client->keyboards_head == NULL)
client->keyboards_head = client->keyboards;
eekboard_context_set_keyboard (client->context, eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(client->keyboards->data), GPOINTER_TO_UINT(client->keyboards_head->data),
NULL); NULL);
return; return;
} }
if (g_strcmp0 (eek_symbol_get_name (symbol), "preferences") == 0) { if (g_strcmp0 (eek_symbol_get_name (symbol), "preferences") == 0) {
PreferencesDialog *dialog = preferences_dialog_new (); gchar *argv[2];
preferences_dialog_run (dialog); GError *error;
argv[0] = g_build_filename (LIBEXECDIR, "eekboard-setup", NULL);
argv[1] = NULL;
error = NULL;
if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error)) {
g_warning ("can't spawn %s: %s", argv[0], error->message);
g_error_free (error);
}
g_free (argv[0]);
return; return;
} }
@ -1104,9 +1138,9 @@ client_enable_xtest (Client *client)
update_modifier_keycodes (client); update_modifier_keycodes (client);
client->key_pressed_handler = client->key_activated_handler =
g_signal_connect (client->context, "key-pressed", g_signal_connect (client->context, "key-activated",
G_CALLBACK(on_key_pressed), client); G_CALLBACK(on_key_activated), client);
return TRUE; return TRUE;
} }

View File

@ -21,6 +21,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "preferences-dialog.h" #include "preferences-dialog.h"
#include <eek/eek.h>
struct _PreferencesDialog { struct _PreferencesDialog {
GtkWidget *dialog; GtkWidget *dialog;
@ -29,9 +30,16 @@ struct _PreferencesDialog {
GtkWidget *repeat_speed_scale; GtkWidget *repeat_speed_scale;
GtkWidget *auto_hide_toggle; GtkWidget *auto_hide_toggle;
GtkWidget *auto_hide_delay_scale; GtkWidget *auto_hide_delay_scale;
GtkWidget *start_fullscreen_toggle; GtkWidget *selected_keyboards_treeview;
GtkWidget *keyboard_entry; GtkWidget *up_button;
GtkWidget *down_button;
GtkWidget *add_button;
GtkWidget *remove_button;
GtkWidget *new_keyboard_dialog;
GtkWidget *available_keyboards_treeview;
GList *available_keyboards;
GSettings *settings; GSettings *settings;
}; };
@ -62,33 +70,191 @@ set_rate (const GValue *value,
return g_variant_new_uint32 (msecs); return g_variant_new_uint32 (msecs);
} }
static gboolean static void
get_strv (GValue *value, add_keyboard_to_treeview (GtkTreeView *treeview,
GVariant *variant, const gchar *id,
gpointer user_data) const gchar *longname)
{ {
const gchar **strv = g_variant_get_strv (variant, NULL); GtkTreeModel *model = gtk_tree_view_get_model (treeview);
gchar *text = g_strjoinv (", ", (gchar **)strv); GtkTreeIter iter;
g_free (strv);
g_value_set_string (value, text); if (gtk_tree_model_get_iter_first (model, &iter)) {
return TRUE; do {
gchar *_id;
gtk_tree_model_get (model, &iter, 0, &_id, -1);
if (g_strcmp0 (id, _id) == 0) {
g_free (_id);
return;
}
g_free (_id);
} while (gtk_tree_model_iter_next (model, &iter));
}
gtk_list_store_append (GTK_LIST_STORE(model),
&iter);
gtk_list_store_set (GTK_LIST_STORE(model),
&iter,
0, id,
1, longname,
-1);
} }
static GVariant * static void
set_strv (const GValue *value, add_keyboard (GtkWidget *button, PreferencesDialog *dialog)
const GVariantType *expected_type,
gpointer user_data)
{ {
const gchar *text = g_value_get_string (value); gint retval = gtk_dialog_run (GTK_DIALOG(dialog->new_keyboard_dialog));
gchar **strv = g_strsplit (text, ",", -1), **p; if (retval == GTK_RESPONSE_OK) {
GVariant *variant; GtkTreeSelection *selection;
GtkTreeModel *model;
GList *rows, *p;
for (p = strv; *p != NULL; p++) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->available_keyboards_treeview));
g_strstrip (*p); rows = gtk_tree_selection_get_selected_rows (selection, &model);
for (p = rows; p; p = p->next) {
GtkTreeIter iter;
if (gtk_tree_model_get_iter (model, &iter, p->data)) {
gchar *id, *longname;
gtk_tree_model_get (model, &iter, 0, &id, 1, &longname, -1);
add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->selected_keyboards_treeview),
id,
longname);
g_free (id);
g_free (longname);
}
}
}
gtk_widget_hide (dialog->new_keyboard_dialog);
}
variant = g_variant_new_strv ((const gchar * const *)strv, -1); static void
remove_keyboard (GtkWidget *button, PreferencesDialog *dialog)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GList *rows, *p;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview));
rows = gtk_tree_selection_get_selected_rows (selection, &model);
for (p = rows; p; p = p->next) {
GtkTreeIter iter;
if (gtk_tree_model_get_iter (model, &iter, p->data))
gtk_list_store_remove (GTK_LIST_STORE(model), &iter);
}
}
static void
up_keyboard (GtkWidget *button, PreferencesDialog *dialog)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview));
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
GtkTreeIter prev = iter;
if (gtk_tree_model_iter_previous (model, &prev))
gtk_list_store_swap (GTK_LIST_STORE(model), &iter, &prev);
}
}
static void
down_keyboard (GtkWidget *button, PreferencesDialog *dialog)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(dialog->selected_keyboards_treeview));
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
GtkTreeIter next = iter;
if (gtk_tree_model_iter_next (model, &next))
gtk_list_store_swap (GTK_LIST_STORE(model), &iter, &next);
}
}
static void
selection_changed_cb (GtkTreeSelection *selection, PreferencesDialog *dialog)
{
gint count = gtk_tree_selection_count_selected_rows (selection);
if (count > 0) {
gtk_widget_set_sensitive (dialog->remove_button, TRUE);
gtk_widget_set_sensitive (dialog->up_button, TRUE);
gtk_widget_set_sensitive (dialog->down_button, TRUE);
} else {
gtk_widget_set_sensitive (dialog->remove_button, FALSE);
gtk_widget_set_sensitive (dialog->up_button, FALSE);
gtk_widget_set_sensitive (dialog->down_button, FALSE);
}
}
static gint
compare_keyboard_id (const EekXmlKeyboardDesc *desc, const char *id)
{
return g_strcmp0 (desc->id, id);
}
static void
populate_selected_keyboards (PreferencesDialog *dialog)
{
gchar **strv, **p;
strv = g_settings_get_strv (dialog->settings, "keyboards");
for (p = strv; *p != NULL; p++) {
GList *head = g_list_find_custom (dialog->available_keyboards,
*p,
(GCompareFunc) compare_keyboard_id);
if (head == NULL) {
g_warning ("unknown keyboard %s", *p);
} else {
EekXmlKeyboardDesc *desc = head->data;
add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->selected_keyboards_treeview),
desc->id,
desc->longname);
}
}
g_strfreev (strv); g_strfreev (strv);
return variant; }
static void
populate_available_keyboards (PreferencesDialog *dialog)
{
GList *p;
for (p = dialog->available_keyboards; p; p = p->next) {
EekXmlKeyboardDesc *desc = p->data;
add_keyboard_to_treeview (GTK_TREE_VIEW(dialog->available_keyboards_treeview),
desc->id,
desc->longname);
}
}
static void
save_keyboards (PreferencesDialog *dialog)
{
GtkTreeModel *model;
GtkTreeIter iter;
GList *list = NULL, *head;
gchar **strv, **p;
model = gtk_tree_view_get_model (GTK_TREE_VIEW(dialog->selected_keyboards_treeview));
if (gtk_tree_model_get_iter_first (model, &iter)) {
do {
gchar *id;
gtk_tree_model_get (model, &iter, 0, &id, -1);
list = g_list_prepend (list, id);
} while (gtk_tree_model_iter_next (model, &iter));
}
list = g_list_reverse (list);
strv = g_new0 (gchar *, g_list_length (list) + 1);
for (head = list, p = strv; head; head = head->next, p++) {
*p = head->data;
}
g_settings_set_strv (dialog->settings,
"keyboards",
(const gchar * const *)strv);
g_strfreev (strv);
g_list_free (list);
} }
PreferencesDialog * PreferencesDialog *
@ -99,13 +265,19 @@ preferences_dialog_new (void)
GtkBuilder *builder; GtkBuilder *builder;
GObject *object; GObject *object;
GError *error; GError *error;
GtkListStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
dialog = g_slice_new0 (PreferencesDialog); dialog = g_slice_new0 (PreferencesDialog);
dialog->settings = g_settings_new ("org.fedorahosted.eekboard"); dialog->settings = g_settings_new ("org.fedorahosted.eekboard");
builder = gtk_builder_new (); builder = gtk_builder_new ();
gtk_builder_set_translation_domain (builder, "eekboard"); gtk_builder_set_translation_domain (builder, "eekboard");
ui_path = g_strdup_printf ("%s/%s", PKGDATADIR, "preferences-dialog.ui"); ui_path = g_build_filename (PKGDATADIR,
"preferences-dialog.ui",
NULL);
error = NULL; error = NULL;
if (gtk_builder_add_from_file (builder, ui_path, &error) == 0) { if (gtk_builder_add_from_file (builder, ui_path, &error) == 0) {
g_warning ("can't load %s: %s", ui_path, error->message); g_warning ("can't load %s: %s", ui_path, error->message);
@ -113,28 +285,24 @@ preferences_dialog_new (void)
} }
g_free (ui_path); g_free (ui_path);
object = object = gtk_builder_get_object (builder, "dialog");
gtk_builder_get_object (builder, "dialog");
dialog->dialog = GTK_WIDGET(object); dialog->dialog = GTK_WIDGET(object);
object = object = gtk_builder_get_object (builder, "repeat_toggle");
gtk_builder_get_object (builder, "repeat_toggle");
dialog->repeat_toggle = GTK_WIDGET(object); dialog->repeat_toggle = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "repeat", g_settings_bind (dialog->settings, "repeat",
dialog->repeat_toggle, "active", dialog->repeat_toggle, "active",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT);
object = object = gtk_builder_get_object (builder, "repeat_delay_scale");
gtk_builder_get_object (builder, "repeat_delay_scale");
dialog->repeat_delay_scale = GTK_WIDGET(object); dialog->repeat_delay_scale = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "repeat-delay", g_settings_bind (dialog->settings, "repeat-delay",
gtk_range_get_adjustment (GTK_RANGE (dialog->repeat_delay_scale)), "value", gtk_range_get_adjustment (GTK_RANGE (dialog->repeat_delay_scale)), "value",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT);
object = object = gtk_builder_get_object (builder, "repeat_speed_scale");
gtk_builder_get_object (builder, "repeat_speed_scale");
dialog->repeat_speed_scale = GTK_WIDGET(object); dialog->repeat_speed_scale = GTK_WIDGET(object);
g_settings_bind_with_mapping (dialog->settings, "repeat-interval", g_settings_bind_with_mapping (dialog->settings, "repeat-interval",
@ -142,38 +310,85 @@ preferences_dialog_new (void)
G_SETTINGS_BIND_DEFAULT, G_SETTINGS_BIND_DEFAULT,
get_rate, set_rate, NULL, NULL); get_rate, set_rate, NULL, NULL);
object = object = gtk_builder_get_object (builder, "auto_hide_toggle");
gtk_builder_get_object (builder, "auto_hide_toggle");
dialog->auto_hide_toggle = GTK_WIDGET(object); dialog->auto_hide_toggle = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "auto-hide", g_settings_bind (dialog->settings, "auto-hide",
dialog->auto_hide_toggle, "active", dialog->auto_hide_toggle, "active",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT);
object = object = gtk_builder_get_object (builder, "auto_hide_delay_scale");
gtk_builder_get_object (builder, "auto_hide_delay_scale");
dialog->auto_hide_delay_scale = GTK_WIDGET(object); dialog->auto_hide_delay_scale = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "auto-hide-delay", g_settings_bind (dialog->settings, "auto-hide-delay",
gtk_range_get_adjustment (GTK_RANGE (dialog->auto_hide_delay_scale)), "value", gtk_range_get_adjustment (GTK_RANGE (dialog->auto_hide_delay_scale)), "value",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT);
object = object = gtk_builder_get_object (builder,
gtk_builder_get_object (builder, "start_fullscreen_toggle"); "selected_keyboards_treeview");
dialog->start_fullscreen_toggle = GTK_WIDGET(object); dialog->selected_keyboards_treeview = GTK_WIDGET(object);
g_settings_bind (dialog->settings, "start-fullscreen", selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (object));
dialog->start_fullscreen_toggle, "active", g_signal_connect (G_OBJECT(selection), "changed",
G_SETTINGS_BIND_DEFAULT); G_CALLBACK(selection_changed_cb), dialog);
object = renderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new ());
gtk_builder_get_object (builder, "keyboard_entry"); column = gtk_tree_view_column_new_with_attributes ("Keyboard",
dialog->keyboard_entry = GTK_WIDGET(object); renderer,
"text",
1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (object), column);
g_settings_bind_with_mapping (dialog->settings, "keyboards", object = gtk_builder_get_object (builder, "up_button");
GTK_ENTRY(dialog->keyboard_entry), "text", dialog->up_button = GTK_WIDGET(object);
G_SETTINGS_BIND_DEFAULT, g_signal_connect (object, "clicked",
get_strv, set_strv, NULL, NULL); G_CALLBACK(up_keyboard), dialog);
object = gtk_builder_get_object (builder, "down_button");
dialog->down_button = GTK_WIDGET(object);
g_signal_connect (object, "clicked",
G_CALLBACK(down_keyboard), dialog);
object = gtk_builder_get_object (builder, "add_button");
dialog->add_button = GTK_WIDGET(object);
g_signal_connect (object, "clicked",
G_CALLBACK(add_keyboard), dialog);
object = gtk_builder_get_object (builder, "remove_button");
dialog->remove_button = GTK_WIDGET(object);
g_signal_connect (object, "clicked",
G_CALLBACK(remove_keyboard), dialog);
object = gtk_builder_get_object (builder, "new_keyboard_dialog");
dialog->new_keyboard_dialog = GTK_WIDGET(object);
object = gtk_builder_get_object (builder,
"available_keyboards_treeview");
dialog->available_keyboards_treeview = GTK_WIDGET(object);
renderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new ());
column = gtk_tree_view_column_new_with_attributes ("Keyboard",
renderer,
"text",
1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (object), column);
object = gtk_builder_get_object (builder,
"available_keyboards_liststore");
store = GTK_LIST_STORE(object);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store),
1,
GTK_SORT_ASCENDING);
dialog->available_keyboards = eek_xml_list_keyboards ();
populate_selected_keyboards (dialog);
populate_available_keyboards (dialog);
g_object_unref (builder);
return dialog; return dialog;
} }
@ -183,5 +398,18 @@ preferences_dialog_run (PreferencesDialog *dialog)
{ {
gtk_window_present (GTK_WINDOW(dialog->dialog)); gtk_window_present (GTK_WINDOW(dialog->dialog));
gtk_dialog_run (GTK_DIALOG(dialog->dialog)); gtk_dialog_run (GTK_DIALOG(dialog->dialog));
gtk_widget_destroy (dialog->dialog); save_keyboards (dialog);
}
void
preferences_dialog_free (PreferencesDialog *dialog)
{
gtk_widget_destroy (dialog->dialog);
// gtk_widget_destroy (dialog->new_keyboard_dialog);
g_object_unref (dialog->settings);
g_list_free_full (dialog->available_keyboards,
(GDestroyNotify) eek_xml_keyboard_desc_free);
g_slice_free (PreferencesDialog, dialog);
} }

View File

@ -18,12 +18,15 @@
#ifndef PREFERENCES_DIALOG_H #ifndef PREFERENCES_DIALOG_H
#define PREFERENCES_DIALOG_H 1 #define PREFERENCES_DIALOG_H 1
#include <glib-object.h>
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _PreferencesDialog PreferencesDialog; typedef struct _PreferencesDialog PreferencesDialog;
PreferencesDialog *preferences_dialog_new (void); PreferencesDialog *preferences_dialog_new (void);
void preferences_dialog_run (PreferencesDialog *dialog); void preferences_dialog_run (PreferencesDialog *dialog);
void preferences_dialog_free (PreferencesDialog *dialog);
G_END_DECLS G_END_DECLS
#endif /* PREFERENCES_DIALOG_H */ #endif /* PREFERENCES_DIALOG_H */

View File

@ -1,6 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<!-- interface-requires gtk+ 3.0 --> <!-- interface-requires gtk+ 3.0 -->
<object class="GtkAction" id="action1">
<property name="stock_id">gtk-close</property>
</object>
<object class="GtkAction" id="action2">
<property name="stock_id">gtk-cancel</property>
</object>
<object class="GtkAction" id="action3">
<property name="label" translatable="yes">Select</property>
<property name="stock_id">gtk-ok</property>
</object>
<object class="GtkAdjustment" id="auto_hide_delay_adjustment">
<property name="lower">100</property>
<property name="upper">2000</property>
<property name="value">500</property>
<property name="step_increment">10</property>
<property name="page_increment">10</property>
</object>
<object class="GtkListStore" id="available_keyboards_liststore">
<columns>
<!-- column-name id -->
<column type="gchararray"/>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="dialog"> <object class="GtkDialog" id="dialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="border_width">5</property> <property name="border_width">5</property>
@ -452,116 +477,6 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Keyboard</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="appearances_vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="start_fullscreen_toggle">
<property name="label" translatable="yes">Start in fullscreen mode</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_columns">4</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Keyboard type: </property>
</object>
</child>
<child>
<object class="GtkEntry" id="keyboard_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object> </object>
</child> </child>
<child type="tab"> <child type="tab">
@ -575,10 +490,119 @@
</packing> </packing>
</child> </child>
<child> <child>
<placeholder/> <object class="GtkVBox" id="keyboards_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="spacing">18</property>
<child>
<object class="GtkTreeView" id="selected_keyboards_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">selected_keyboards_liststore</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="buttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="up_button">
<property name="label">gtk-go-up</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="down_button">
<property name="label">gtk-go-down</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="add_button">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="remove_button">
<property name="label">gtk-remove</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child> </child>
<child type="tab"> <child type="tab">
<placeholder/> <object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Keyboards</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child> </child>
<child> <child>
<placeholder/> <placeholder/>
@ -599,8 +623,86 @@
<action-widget response="0">button1</action-widget> <action-widget response="0">button1</action-widget>
</action-widgets> </action-widgets>
</object> </object>
<object class="GtkAction" id="action1"> <object class="GtkDialog" id="new_keyboard_dialog">
<property name="stock_id">gtk-close</property> <property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="default_height">430</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="transient_for">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox2">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area2">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="related_action">action2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="related_action">action3</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="available_keyboards_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">available_keyboards_liststore</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection3"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
<action-widget response="-5">button3</action-widget>
</action-widgets>
</object> </object>
<object class="GtkAdjustment" id="repeat_delay_adjustment"> <object class="GtkAdjustment" id="repeat_delay_adjustment">
<property name="lower">100</property> <property name="lower">100</property>
@ -616,11 +718,12 @@
<property name="step_increment">1</property> <property name="step_increment">1</property>
<property name="page_increment">1</property> <property name="page_increment">1</property>
</object> </object>
<object class="GtkAdjustment" id="auto_hide_delay_adjustment"> <object class="GtkListStore" id="selected_keyboards_liststore">
<property name="lower">100</property> <columns>
<property name="upper">2000</property> <!-- column-name id -->
<property name="value">500</property> <column type="gchararray"/>
<property name="step_increment">10</property> <!-- column-name gchararray1 -->
<property name="page_increment">10</property> <column type="gchararray"/>
</columns>
</object> </object>
</interface> </interface>

View File

@ -79,8 +79,11 @@ on_destroy (GtkWidget *widget, gpointer user_data)
ServerContextService *context = user_data; ServerContextService *context = user_data;
g_assert (widget == context->window); g_assert (widget == context->window);
context->window = NULL; context->window = NULL;
context->widget = NULL; context->widget = NULL;
eekboard_context_service_destroy (EEKBOARD_CONTEXT_SERVICE (context));
} }
static void static void
@ -96,6 +99,7 @@ on_notify_keyboard (GObject *object,
if (keyboard == NULL) { if (keyboard == NULL) {
gtk_widget_hide (context->window); gtk_widget_hide (context->window);
gtk_widget_destroy (context->widget); gtk_widget_destroy (context->widget);
context->widget = NULL;
} else { } else {
gboolean was_visible = gtk_widget_get_visible (context->window); gboolean was_visible = gtk_widget_get_visible (context->window);
/* avoid to send KeyboardVisibilityChanged */ /* avoid to send KeyboardVisibilityChanged */
@ -273,16 +277,21 @@ update_widget (ServerContextService *context)
EekKeyboard *keyboard; EekKeyboard *keyboard;
const gchar *client_name; const gchar *client_name;
EekBounds bounds; EekBounds bounds;
gchar *theme_name, *theme_path; gchar *theme_name, *theme_filename, *theme_path;
EekTheme *theme; EekTheme *theme;
if (context->widget) if (context->widget) {
gtk_widget_destroy (context->widget); gtk_widget_destroy (context->widget);
context->widget = NULL;
}
theme_name = g_settings_get_string (context->settings, "theme"); theme_name = g_settings_get_string (context->settings, "theme");
theme_path = g_strdup_printf ("%s/%s.css", THEMEDIR, theme_name); theme_filename = g_strdup_printf ("%s.css", theme_name);
g_free (theme_name); g_free (theme_name);
theme_path = g_build_filename (THEMESDIR, theme_filename, NULL);
g_free (theme_filename);
theme = eek_theme_new (theme_path, NULL, NULL); theme = eek_theme_new (theme_path, NULL, NULL);
g_free (theme_path); g_free (theme_path);
@ -353,6 +362,11 @@ server_context_service_real_disabled (EekboardContextService *_context)
} }
} }
static void
server_context_service_real_destroyed (EekboardContextService *_context)
{
}
static void static void
server_context_service_set_property (GObject *object, server_context_service_set_property (GObject *object,
guint prop_id, guint prop_id,
@ -377,9 +391,7 @@ server_context_service_set_property (GObject *object,
break; break;
default: default:
g_object_set_property (object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
g_param_spec_get_name (pspec),
value);
break; break;
} }
} }
@ -408,6 +420,7 @@ server_context_service_class_init (ServerContextServiceClass *klass)
context_class->hide_keyboard = server_context_service_real_hide_keyboard; context_class->hide_keyboard = server_context_service_real_hide_keyboard;
context_class->enabled = server_context_service_real_enabled; context_class->enabled = server_context_service_real_enabled;
context_class->disabled = server_context_service_real_disabled; context_class->disabled = server_context_service_real_disabled;
context_class->destroyed = server_context_service_real_destroyed;
gobject_class->set_property = server_context_service_set_property; gobject_class->set_property = server_context_service_set_property;
gobject_class->dispose = server_context_service_dispose; gobject_class->dispose = server_context_service_dispose;

41
src/setup-main.c Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2012 Daiki Ueno <ueno@unixuser.org>
* Copyright (C) 2012 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
#include "preferences-dialog.h"
#include <gtk/gtk.h>
#include <stdlib.h>
int
main (int argc, char **argv)
{
PreferencesDialog *dialog;
if (!gtk_init_check (&argc, &argv)) {
g_printerr ("Can't init GTK\n");
return EXIT_FAILURE;
}
dialog = preferences_dialog_new ();
preferences_dialog_run (dialog);
preferences_dialog_free (dialog);
return EXIT_SUCCESS;
}