Refactor layout code, rescale and reformat when changing level
This commit is contained in:
@ -262,6 +262,8 @@ set_level_from_modifiers (EekKeyboard *self, EekKey *key)
|
|||||||
|
|
||||||
priv->old_level = level;
|
priv->old_level = level;
|
||||||
eek_element_set_level (EEK_ELEMENT(self), level);
|
eek_element_set_level (EEK_ELEMENT(self), level);
|
||||||
|
|
||||||
|
eek_layout_update_layout(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -528,6 +530,7 @@ eek_keyboard_init (EekKeyboard *self)
|
|||||||
self->priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline));
|
self->priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline));
|
||||||
self->priv->keycodes = g_hash_table_new (g_direct_hash, g_direct_equal);
|
self->priv->keycodes = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
eek_element_set_symbol_index (EEK_ELEMENT(self), 0, 0);
|
eek_element_set_symbol_index (EEK_ELEMENT(self), 0, 0);
|
||||||
|
self->scale = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -62,6 +62,7 @@ struct _EekKeyboard
|
|||||||
struct xkb_keymap *keymap;
|
struct xkb_keymap *keymap;
|
||||||
int keymap_fd; // keymap formatted as XKB string
|
int keymap_fd; // keymap formatted as XKB string
|
||||||
size_t keymap_len; // length of the data inside keymap_fd
|
size_t keymap_len; // length of the data inside keymap_fd
|
||||||
|
double scale;
|
||||||
|
|
||||||
EekboardContextService *manager; // unowned reference
|
EekboardContextService *manager; // unowned reference
|
||||||
};
|
};
|
||||||
|
|||||||
@ -128,3 +128,61 @@ eek_layout_place_sections(EekKeyboard *keyboard)
|
|||||||
keyboard_bounds.height = total_height;
|
keyboard_bounds.height = total_height;
|
||||||
eek_element_set_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds);
|
eek_element_set_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void scale_bounds_callback (EekElement *element,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
static void
|
||||||
|
scale_bounds (EekElement *element,
|
||||||
|
gdouble scale)
|
||||||
|
{
|
||||||
|
EekBounds bounds;
|
||||||
|
|
||||||
|
eek_element_get_bounds (element, &bounds);
|
||||||
|
bounds.x *= scale;
|
||||||
|
bounds.y *= scale;
|
||||||
|
bounds.width *= scale;
|
||||||
|
bounds.height *= scale;
|
||||||
|
eek_element_set_bounds (element, &bounds);
|
||||||
|
|
||||||
|
if (EEK_IS_CONTAINER(element))
|
||||||
|
eek_container_foreach_child (EEK_CONTAINER(element),
|
||||||
|
scale_bounds_callback,
|
||||||
|
&scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
scale_bounds_callback (EekElement *element,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
scale_bounds (element, *(gdouble *)user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
eek_layout_scale_keyboard(EekKeyboard *keyboard, gdouble scale)
|
||||||
|
{
|
||||||
|
gsize n_outlines;
|
||||||
|
|
||||||
|
scale_bounds (EEK_ELEMENT(keyboard), scale);
|
||||||
|
|
||||||
|
n_outlines = eek_keyboard_get_n_outlines (keyboard);
|
||||||
|
for (guint i = 0; i < n_outlines; i++) {
|
||||||
|
EekOutline *outline = eek_keyboard_get_outline (keyboard, i);
|
||||||
|
gint j;
|
||||||
|
|
||||||
|
for (j = 0; j < outline->num_points; j++) {
|
||||||
|
outline->points[j].x *= scale;
|
||||||
|
outline->points[j].y *= scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard->scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
eek_layout_update_layout(EekKeyboard *keyboard)
|
||||||
|
{
|
||||||
|
eek_layout_scale_keyboard(keyboard, 1.0 / keyboard->scale);
|
||||||
|
eek_layout_place_sections(keyboard);
|
||||||
|
eek_layout_scale_keyboard(keyboard, 1.0 / keyboard->scale);
|
||||||
|
}
|
||||||
|
|||||||
@ -57,5 +57,9 @@ GType eek_layout_get_type (void) G_GNUC_CONST;
|
|||||||
|
|
||||||
void eek_layout_place_sections(EekKeyboard *keyboard);
|
void eek_layout_place_sections(EekKeyboard *keyboard);
|
||||||
|
|
||||||
|
void eek_layout_scale_keyboard(EekKeyboard *keyboard, gdouble scale);
|
||||||
|
|
||||||
|
void eek_layout_update_layout(EekKeyboard *keyboard);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
#endif /* EEK_LAYOUT_H */
|
#endif /* EEK_LAYOUT_H */
|
||||||
|
|||||||
@ -943,7 +943,9 @@ eek_xml_layout_real_create_keyboard (EekboardContextService *manager,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fit keyboard in the given width and hight. */
|
eek_layout_place_sections(keyboard);
|
||||||
|
|
||||||
|
/* Fit keyboard in the given width and height. */
|
||||||
scale_keyboard (keyboard, initial_width, initial_height);
|
scale_keyboard (keyboard, initial_width, initial_height);
|
||||||
|
|
||||||
/* Use pre-defined modifier mask here. */
|
/* Use pre-defined modifier mask here. */
|
||||||
@ -1277,9 +1279,6 @@ parse_symbols (const gchar *path, EekKeyboard *keyboard, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
symbols_parse_data_free (data);
|
symbols_parse_data_free (data);
|
||||||
|
|
||||||
eek_layout_place_sections(keyboard);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1358,43 +1357,12 @@ parse_keyboards (const gchar *path, GError **error)
|
|||||||
return keyboards;
|
return keyboards;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scale_bounds_callback (EekElement *element,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void
|
|
||||||
scale_bounds (EekElement *element,
|
|
||||||
gdouble scale)
|
|
||||||
{
|
|
||||||
EekBounds bounds;
|
|
||||||
|
|
||||||
eek_element_get_bounds (element, &bounds);
|
|
||||||
bounds.x *= scale;
|
|
||||||
bounds.y *= scale;
|
|
||||||
bounds.width *= scale;
|
|
||||||
bounds.height *= scale;
|
|
||||||
eek_element_set_bounds (element, &bounds);
|
|
||||||
|
|
||||||
if (EEK_IS_CONTAINER(element))
|
|
||||||
eek_container_foreach_child (EEK_CONTAINER(element),
|
|
||||||
scale_bounds_callback,
|
|
||||||
&scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
scale_bounds_callback (EekElement *element,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
scale_bounds (element, *(gdouble *)user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scale_keyboard (EekKeyboard *keyboard,
|
static void scale_keyboard (EekKeyboard *keyboard,
|
||||||
gdouble width,
|
gdouble width,
|
||||||
gdouble height)
|
gdouble height)
|
||||||
{
|
{
|
||||||
gdouble scale;
|
gdouble scale;
|
||||||
EekBounds bounds;
|
EekBounds bounds;
|
||||||
gsize n_outlines;
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
|
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
|
||||||
|
|
||||||
@ -1403,18 +1371,7 @@ static void scale_keyboard (EekKeyboard *keyboard,
|
|||||||
else
|
else
|
||||||
scale = height / bounds.height;
|
scale = height / bounds.height;
|
||||||
|
|
||||||
scale_bounds (EEK_ELEMENT(keyboard), scale);
|
eek_layout_scale_keyboard(keyboard, scale);
|
||||||
|
|
||||||
n_outlines = eek_keyboard_get_n_outlines (keyboard);
|
|
||||||
for (i = 0; i < n_outlines; i++) {
|
|
||||||
EekOutline *outline = eek_keyboard_get_outline (keyboard, i);
|
|
||||||
gint j;
|
|
||||||
|
|
||||||
for (j = 0; j < outline->num_points; j++) {
|
|
||||||
outline->points[j].x *= scale;
|
|
||||||
outline->points[j].y *= scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|||||||
@ -282,7 +282,8 @@ settings_get_layout(GSettings *settings, char **type, char **layout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
settings_update_layout(EekboardContextService *context) {
|
settings_update_layout(EekboardContextService *context)
|
||||||
|
{
|
||||||
g_autofree gchar *keyboard_type = NULL;
|
g_autofree gchar *keyboard_type = NULL;
|
||||||
g_autofree gchar *keyboard_layout = NULL;
|
g_autofree gchar *keyboard_layout = NULL;
|
||||||
settings_get_layout(context->priv->settings, &keyboard_type, &keyboard_layout);
|
settings_get_layout(context->priv->settings, &keyboard_type, &keyboard_layout);
|
||||||
|
|||||||
Reference in New Issue
Block a user