Commit 4a346211 authored by Daiki Ueno's avatar Daiki Ueno

Show tooltips.

parent 4df2ecc8
......@@ -248,10 +248,10 @@
<keysym keyval="65506">Shift_R</keysym>
</key>
<key keycode="149" name="I149">
<symbol label="⌨" icon="input-keyboard-symbolic">cycle-keyboard</symbol>
<symbol label="⌨" icon="input-keyboard-symbolic" tooltip="Change keyboard">cycle-keyboard</symbol>
</key>
<key keycode="150" name="I150">
<symbol label="☺" icon="preferences-system-symbolic">preferences</symbol>
<symbol label="☺" icon="preferences-system-symbolic" tooltip="Setup">preferences</symbol>
</key>
<key keycode="37" name="LCTL">
<keysym keyval="65507">Control_L</keysym>
......
......@@ -232,6 +232,9 @@ eek_gtk_keyboard_real_motion_notify_event (GtkWidget *self,
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
EekKey *key;
if (event->state == 0)
return FALSE;
key = eek_renderer_find_key_by_position (priv->renderer,
(gdouble)event->x,
(gdouble)event->y);
......@@ -275,6 +278,30 @@ eek_gtk_keyboard_real_unmap (GtkWidget *self)
GTK_WIDGET_CLASS (eek_gtk_keyboard_parent_class)->unmap (self);
}
static gboolean
eek_gtk_keyboard_real_query_tooltip (GtkWidget *widget,
gint x,
gint y,
gboolean keyboard_tooltip,
GtkTooltip *tooltip)
{
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(widget);
EekKey *key;
key = eek_renderer_find_key_by_position (priv->renderer,
(gdouble)x,
(gdouble)y);
if (key) {
EekSymbol *symbol = eek_key_get_symbol (key);
const gchar *text = eek_symbol_get_tooltip (symbol);
if (text) {
gtk_tooltip_set_text (tooltip, text);
return TRUE;
}
}
return FALSE;
}
static void
eek_gtk_keyboard_set_keyboard (EekGtkKeyboard *self,
EekKeyboard *keyboard)
......@@ -397,6 +424,8 @@ eek_gtk_keyboard_class_init (EekGtkKeyboardClass *klass)
eek_gtk_keyboard_real_button_release_event;
widget_class->motion_notify_event =
eek_gtk_keyboard_real_motion_notify_event;
widget_class->query_tooltip =
eek_gtk_keyboard_real_query_tooltip;
gobject_class->set_property = eek_gtk_keyboard_set_property;
gobject_class->dispose = eek_gtk_keyboard_dispose;
......
......@@ -40,6 +40,7 @@ enum {
PROP_CATEGORY,
PROP_MODIFIER_MASK,
PROP_ICON_NAME,
PROP_TOOLTIP,
PROP_LAST
};
......@@ -49,6 +50,7 @@ struct _EekSymbolPrivate {
EekSymbolCategory category;
EekModifierType modifier_mask;
gchar *icon_name;
gchar *tooltip;
};
static void eek_serializable_iface_init (EekSerializableIface *iface);
......@@ -71,6 +73,7 @@ eek_symbol_real_serialize (EekSerializable *self,
g_variant_builder_add (builder, "u", priv->category);
g_variant_builder_add (builder, "u", priv->modifier_mask);
g_variant_builder_add (builder, "s", NOTNULL(priv->icon_name));
g_variant_builder_add (builder, "s", NOTNULL(priv->tooltip));
#undef NOTNULL
}
......@@ -86,6 +89,7 @@ eek_symbol_real_deserialize (EekSerializable *self,
g_variant_get_child (variant, index++, "u", &priv->category);
g_variant_get_child (variant, index++, "u", &priv->modifier_mask);
g_variant_get_child (variant, index++, "s", &priv->icon_name);
g_variant_get_child (variant, index++, "s", &priv->tooltip);
return index;
}
......@@ -121,6 +125,10 @@ eek_symbol_set_property (GObject *object,
eek_symbol_set_icon_name (EEK_SYMBOL(object),
g_value_get_string (value));
break;
case PROP_TOOLTIP:
eek_symbol_set_tooltip (EEK_SYMBOL(object),
g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -151,6 +159,10 @@ eek_symbol_get_property (GObject *object,
g_value_set_string (value,
eek_symbol_get_icon_name (EEK_SYMBOL(object)));
break;
case PROP_TOOLTIP:
g_value_set_string (value,
eek_symbol_get_tooltip (EEK_SYMBOL(object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -165,6 +177,7 @@ eek_symbol_finalize (GObject *object)
g_free (priv->name);
g_free (priv->label);
g_free (priv->icon_name);
g_free (priv->tooltip);
G_OBJECT_CLASS (eek_symbol_parent_class)->finalize (object);
}
......@@ -216,6 +229,13 @@ eek_symbol_class_init (EekSymbolClass *klass)
NULL,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ICON_NAME, pspec);
pspec = g_param_spec_string ("tooltip",
"Tooltip",
"Tooltip text",
NULL,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TOOLTIP, pspec);
}
static void
......@@ -441,6 +461,45 @@ eek_symbol_get_icon_name (EekSymbol *symbol)
return priv->icon_name;
}
/**
* eek_symbol_set_tooltip:
* @symbol: an #EekSymbol
* @tooltip: icon name of @symbol
*
* Set the tooltip text of @symbol to @tooltip.
*/
void
eek_symbol_set_tooltip (EekSymbol *symbol,
const gchar *tooltip)
{
EekSymbolPrivate *priv;
g_return_if_fail (EEK_IS_SYMBOL(symbol));
priv = EEK_SYMBOL_GET_PRIVATE(symbol);
g_free (priv->tooltip);
priv->tooltip = g_strdup (tooltip);
}
/**
* eek_symbol_get_tooltip:
* @symbol: an #EekSymbol
*
* Get the tooltip text of @symbol.
*/
G_CONST_RETURN gchar *
eek_symbol_get_tooltip (EekSymbol *symbol)
{
EekSymbolPrivate *priv;
g_return_val_if_fail (EEK_IS_SYMBOL(symbol), NULL);
priv = EEK_SYMBOL_GET_PRIVATE(symbol);
if (priv->tooltip == NULL || *priv->tooltip == '\0')
return NULL;
return priv->tooltip;
}
static const struct {
EekSymbolCategory category;
gchar *name;
......
......@@ -89,32 +89,31 @@ struct _EekSymbolClass {
GObjectClass parent_class;
};
GType eek_symbol_get_type (void) G_GNUC_CONST;
GType eek_symbol_get_type (void) G_GNUC_CONST;
EekSymbol *eek_symbol_new (const gchar *name);
void eek_symbol_set_name (EekSymbol *symbol,
const gchar *name);
G_CONST_RETURN gchar *eek_symbol_get_name (EekSymbol *symbol);
void eek_symbol_set_label (EekSymbol *symbol,
const gchar *label);
G_CONST_RETURN gchar *eek_symbol_get_label (EekSymbol *symbol);
void eek_symbol_set_category (EekSymbol *symbol,
EekSymbolCategory category);
EekSymbolCategory eek_symbol_get_category (EekSymbol *symbol);
EekModifierType eek_symbol_get_modifier_mask
(EekSymbol *symbol);
void eek_symbol_set_modifier_mask
(EekSymbol *symbol,
EekModifierType mask);
gboolean eek_symbol_is_modifier (EekSymbol *symbol);
void eek_symbol_set_icon_name (EekSymbol *symbol,
const gchar *icon_name);
G_CONST_RETURN gchar *eek_symbol_get_icon_name (EekSymbol *symbol);
EekSymbol *eek_symbol_new (const gchar *name);
void eek_symbol_set_name (EekSymbol *symbol,
const gchar *name);
const gchar *eek_symbol_get_name (EekSymbol *symbol);
void eek_symbol_set_label (EekSymbol *symbol,
const gchar *label);
const gchar *eek_symbol_get_label (EekSymbol *symbol);
void eek_symbol_set_category (EekSymbol *symbol,
EekSymbolCategory category);
EekSymbolCategory eek_symbol_get_category (EekSymbol *symbol);
EekModifierType eek_symbol_get_modifier_mask (EekSymbol *symbol);
void eek_symbol_set_modifier_mask (EekSymbol *symbol,
EekModifierType mask);
gboolean eek_symbol_is_modifier (EekSymbol *symbol);
void eek_symbol_set_icon_name (EekSymbol *symbol,
const gchar *icon_name);
const gchar *eek_symbol_get_icon_name (EekSymbol *symbol);
void eek_symbol_set_tooltip (EekSymbol *symbol,
const gchar *tooltip);
const gchar * eek_symbol_get_tooltip (EekSymbol *symbol);
G_CONST_RETURN gchar *eek_symbol_category_get_name
(EekSymbolCategory category);
EekSymbolCategory eek_symbol_category_from_name
(const gchar *name);
const gchar *eek_symbol_category_get_name (EekSymbolCategory category);
EekSymbolCategory eek_symbol_category_from_name (const gchar *name);
G_END_DECLS
......
......@@ -571,6 +571,7 @@ struct _SymbolsParseData {
GSList *symbols;
gchar *label;
gchar *icon;
gchar *tooltip;
EekSymbolCategory category;
guint keyval;
gint groups;
......@@ -683,6 +684,11 @@ symbols_start_element_callback (GMarkupParseContext *pcontext,
if (attribute != NULL)
data->icon = g_strdup (attribute);
attribute = get_attribute (attribute_names, attribute_values,
"tooltip");
if (attribute != NULL)
data->tooltip = g_strdup (attribute);
attribute = get_attribute (attribute_names, attribute_values,
"category");
if (attribute != NULL)
......@@ -766,6 +772,11 @@ symbols_end_element_callback (GMarkupParseContext *pcontext,
g_free (data->icon);
data->icon = NULL;
}
if (data->tooltip) {
eek_symbol_set_tooltip (symbol, data->tooltip);
g_free (data->tooltip);
data->tooltip = NULL;
}
data->symbols = g_slist_prepend (data->symbols, symbol);
goto out;
......
......@@ -301,6 +301,8 @@ update_widget (ServerContextService *context)
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget), theme);
g_object_unref (theme);
gtk_widget_set_has_tooltip (context->widget, TRUE);
if (!context->window) {
context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (context->window, "destroy",
......
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