Commit 39900bd9 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Allow non-keysym symbols in XML.

parent 5c091475
......@@ -554,7 +554,7 @@
<bounds>3.121951,162.341463,56.195122,37.463415</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65507">Control_L</keysym>
<symbol label="⌨">cycle-keyboard</symbol>
</symbols>
</key>
<key id="keycode133" name="keycode133" column="1" row="4">
......
......@@ -554,7 +554,7 @@
<bounds>3.121951,162.341463,56.195122,37.463415</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65507">Control_L</keysym>
<symbol label="⌨">cycle-keyboard</symbol>
</symbols>
</key>
<key id="keycode133" name="keycode133" column="1" row="4">
......
......@@ -240,7 +240,7 @@ eek_symbol_init (EekSymbol *self)
EekSymbol *
eek_symbol_new (const gchar *name)
{
return g_object_new (EEK_TYPE_SYMBOL, "name", name);
return g_object_new (EEK_TYPE_SYMBOL, "name", name, NULL);
}
/**
......
......@@ -94,9 +94,7 @@ static const gchar *valid_path_list[] = {
"groups/symbols/key/section/keyboard",
"levels/symbols/key/section/keyboard",
"keysym/symbols/key/section/keyboard",
"custom/symbols/key/section/keyboard",
"text/symbols/key/section/keyboard",
"icon/symbols/key/section/keyboard",
"symbol/symbols/key/section/keyboard",
"invalid/symbols/key/section/keyboard",
"index/key/section/keyboard",
"point/outline/keyboard",
......@@ -229,10 +227,12 @@ start_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "keysym") == 0) {
if (g_strcmp0 (element_name, "symbol") == 0 ||
g_strcmp0 (element_name, "keysym") == 0) {
data->label = g_strdup (label);
data->icon = g_strdup (icon);
data->keyval = keyval;
if (g_strcmp0 (element_name, "keysym") == 0)
data->keyval = keyval;
}
if (g_strcmp0 (element_name, "outline") == 0) {
......@@ -410,23 +410,32 @@ end_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "keysym") == 0) {
EekKeysym *keysym;
if (g_strcmp0 (element_name, "symbol") == 0 ||
g_strcmp0 (element_name, "keysym") == 0) {
EekSymbol *symbol;
if (g_strcmp0 (element_name, "keysym") == 0) {
EekKeysym *keysym;
if (data->keyval != EEK_INVALID_KEYSYM)
keysym = eek_keysym_new (data->keyval);
else
keysym = eek_keysym_new_from_name (text);
symbol = EEK_SYMBOL(keysym);
} else {
symbol = eek_symbol_new (text);
eek_symbol_set_category (symbol, EEK_SYMBOL_CATEGORY_KEYNAME);
}
if (data->keyval != EEK_INVALID_KEYSYM) {
keysym = eek_keysym_new (data->keyval);
//g_debug ("%u %s", data->keyval, eek_symbol_get_label (EEK_SYMBOL(keysym)));
} else
keysym = eek_keysym_new_from_name (text);
if (data->label) {
eek_symbol_set_label (EEK_SYMBOL(keysym), data->label);
eek_symbol_set_label (symbol, data->label);
g_free (data->label);
}
if (data->icon) {
eek_symbol_set_icon_name (EEK_SYMBOL(keysym), data->icon);
eek_symbol_set_icon_name (symbol, data->icon);
g_free (data->icon);
}
data->symbols = g_slist_prepend (data->symbols, keysym);
data->symbols = g_slist_prepend (data->symbols, symbol);
goto out;
}
......
......@@ -30,9 +30,9 @@
0xFF9E "Ins" EEK_SYMBOL_CATEGORY_FUNCTION
0xFF9F "Del" EEK_SYMBOL_CATEGORY_FUNCTION
# aliases
0xFE03 "AltGr" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE04 "AltGr" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE05 "AltGr" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE03 "" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE04 "" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE05 "" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE08 "Next" EEK_SYMBOL_CATEGORY_KEYNAME
0xFE0A "Prev" EEK_SYMBOL_CATEGORY_KEYNAME
0xFF08 "←" EEK_SYMBOL_CATEGORY_KEYNAME
......
......@@ -82,19 +82,20 @@ eekboard_context_real_g_signal (GDBusProxy *self,
}
if (g_strcmp0 (signal_name, "KeyPressed") == 0) {
guint keycode = 0;
const gchar *keyname;
GVariant *variant = NULL;
guint modifiers = 0;
EekSerializable *serializable;
g_variant_get (parameters, "(uvu)", &keycode, &variant, &modifiers);
g_variant_get (parameters, "(&svu)", &keyname, &variant, &modifiers);
g_return_if_fail (variant != NULL);
serializable = eek_serializable_deserialize (variant);
g_return_if_fail (EEK_IS_SYMBOL(serializable));
g_signal_emit_by_name (context, "key-pressed",
keycode, EEK_SYMBOL(serializable), modifiers);
keyname, EEK_SYMBOL(serializable), modifiers);
return;
}
......@@ -139,7 +140,7 @@ eekboard_context_real_disabled (EekboardContext *self)
static void
eekboard_context_real_key_pressed (EekboardContext *self,
guint keycode,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers)
{
......@@ -253,10 +254,10 @@ eekboard_context_class_init (EekboardContextClass *klass)
G_STRUCT_OFFSET(EekboardContextClass, key_pressed),
NULL,
NULL,
_eekboard_marshal_VOID__UINT_OBJECT_UINT,
_eekboard_marshal_VOID__STRING_OBJECT_UINT,
G_TYPE_NONE,
3,
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_OBJECT,
G_TYPE_UINT);
......
......@@ -67,7 +67,7 @@ struct _EekboardContextClass {
void (*enabled) (EekboardContext *self);
void (*disabled) (EekboardContext *self);
void (*key_pressed) (EekboardContext *self,
guint keycode,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers);
void (*destroyed) (EekboardContext *self);
......
VOID:UINT,OBJECT,UINT
VOID:STRING,OBJECT,UINT
......@@ -64,7 +64,7 @@ struct _EekboardClient {
EekboardEekboard *eekboard;
EekboardContext *context;
EekKeyboard *keyboard;
GSList *keyboards;
XklEngine *xkl_engine;
XklConfigRegistry *xkl_config_registry;
......@@ -288,7 +288,6 @@ eekboard_client_set_keyboard (EekboardClient *client,
const gchar *keyboard)
{
gboolean retval;
retval = set_keyboard (client, keyboard);
if (retval && IS_KEYBOARD_VISIBLE (client))
eekboard_context_show_keyboard (client->context, NULL);
......@@ -695,17 +694,37 @@ on_xkl_config_changed (XklEngine *xklengine,
static gboolean
set_keyboard (EekboardClient *client,
const gchar *keyboard)
const gchar *keyboard)
{
guint keyboard_id;
GSList *keyboards = NULL;
gchar **strv, **p;
keyboard_id = eekboard_context_add_keyboard (client->context,
keyboard,
NULL);
if (keyboard_id == 0)
return FALSE;
if (client->keyboards)
g_slist_free (client->keyboards);
eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
strv = g_strsplit (keyboard, ",", -1);
for (p = strv; *p != NULL; p++) {
guint keyboard_id;
keyboard_id = eekboard_context_add_keyboard (client->context,
*p,
NULL);
if (keyboard_id == 0)
return FALSE;
keyboards = g_slist_prepend (keyboards,
GUINT_TO_POINTER(keyboard_id));
}
g_strfreev (strv);
/* make a cycle */
keyboards = g_slist_reverse (keyboards);
g_slist_last (keyboards)->next = keyboards;
client->keyboards = keyboards;
/* select the first keyboard */
eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(keyboards->data),
NULL);
return TRUE;
}
......@@ -714,7 +733,7 @@ set_keyboard_from_xkl (EekboardClient *client)
{
XklConfigRec *rec;
gchar *layout, *keyboard;
gboolean retval;
guint keyboard_id;
rec = xkl_config_rec_new ();
xkl_config_rec_get_from_server (rec, client->xkl_engine);
......@@ -723,10 +742,16 @@ set_keyboard_from_xkl (EekboardClient *client)
keyboard = g_strdup_printf ("xkb:%s", layout);
g_free (layout);
retval = set_keyboard (client, keyboard);
keyboard_id = eekboard_context_add_keyboard (client->context,
keyboard,
NULL);
g_free (keyboard);
if (keyboard_id == 0)
return FALSE;
eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
return retval;
return TRUE;
}
static void
......@@ -909,12 +934,20 @@ send_fake_key_event (EekboardClient *client,
static void
on_key_pressed (EekboardContext *context,
guint keycode,
const gchar *keyname,
EekSymbol *symbol,
guint modifiers,
gpointer user_data)
{
EekboardClient *client = user_data;
if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) {
client->keyboards = g_slist_next (client->keyboards);
eekboard_context_set_keyboard (client->context,
GPOINTER_TO_UINT(client->keyboards->data),
NULL);
}
send_fake_key_event (client, symbol, modifiers, TRUE);
send_fake_key_event (client, symbol, modifiers, FALSE);
}
......
......@@ -80,7 +80,7 @@ static const gchar introspection_xml[] =
" <signal name='Enabled'/>"
" <signal name='Disabled'/>"
" <signal name='KeyPressed'>"
" <arg type='u' name='keycode'/>"
" <arg type='s' name='keyname'/>"
" <arg type='v' name='symbol'/>"
" <arg type='u' name='modifiers'/>"
" </signal>"
......@@ -593,7 +593,7 @@ static void
emit_key_pressed_dbus_signal (ServerContext *context, EekKey *key)
{
if (context->connection && context->enabled) {
guint keycode = eek_key_get_keycode (key);
const gchar *keyname = eek_element_get_name (EEK_ELEMENT(key));
EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
guint modifiers = eek_keyboard_get_modifiers (context->keyboard);
GVariant *variant;
......@@ -607,8 +607,8 @@ emit_key_pressed_dbus_signal (ServerContext *context, EekKey *key)
context->object_path,
SERVER_CONTEXT_INTERFACE,
"KeyPressed",
g_variant_new ("(uvu)",
keycode,
g_variant_new ("(svu)",
keyname,
variant,
modifiers),
&error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment