services: Split out layout management from EekboardContextService

Layout management was pointlessly bound with the EekboardContextService with inheritance. Splitting it out will make it easier to further break apart layout state management, settings, and input method in the future.
This commit is contained in:
Dorota Czaplejewicz
2020-01-09 20:49:27 +00:00
parent 58b087e35a
commit 92c9572ac2
10 changed files with 116 additions and 68 deletions

View File

@ -69,6 +69,10 @@ struct _EekboardContextServicePrivate {
GSettings *settings; // Owned reference
uint32_t hint;
uint32_t purpose;
// Maybe TODO: it's used only for fetching layout type.
// Maybe let UI push the type to this structure?
ServerContextService *ui; // unowned reference
};
G_DEFINE_TYPE_WITH_PRIVATE (EekboardContextService, eekboard_context_service, G_TYPE_OBJECT);
@ -218,13 +222,13 @@ eekboard_context_service_update_layout(EekboardContextService *context, enum squ
LevelKeyboard *previous_keyboard = context->priv->keyboard;
context->priv->keyboard = keyboard;
g_object_notify (G_OBJECT(context), "keyboard");
// The keymap will get set even if the window is hidden.
// It's not perfect,
// but simpler than adding a check in the window showing procedure
eekboard_context_service_set_keymap(context, keyboard);
g_object_notify (G_OBJECT(context), "keyboard");
// replacing the keyboard above will cause the previous keyboard to get destroyed from the UI side (eek_gtk_keyboard_dispose)
if (previous_keyboard) {
level_keyboard_free(previous_keyboard);
@ -232,7 +236,12 @@ eekboard_context_service_update_layout(EekboardContextService *context, enum squ
}
static void update_layout_and_type(EekboardContextService *context) {
eekboard_context_service_update_layout(context, server_context_service_get_layout_type(context));
EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
enum squeek_arrangement_kind layout_kind = ARRANGEMENT_KIND_BASE;
if (priv->ui) {
layout_kind = server_context_service_get_layout_type(priv->ui);
}
eekboard_context_service_update_layout(context, layout_kind);
}
static gboolean
@ -384,3 +393,8 @@ const char*
eekboard_context_service_get_overlay(EekboardContextService *context) {
return context->priv->overlay;
}
EekboardContextService *eekboard_context_service_new()
{
return g_object_new (EEKBOARD_TYPE_CONTEXT_SERVICE, NULL);
}

View File

@ -77,8 +77,6 @@ struct _EekboardContextServiceClass {
const gchar *keyboard_type);
/* signals */
void (*enabled) (EekboardContextService *self);
void (*disabled) (EekboardContextService *self);
void (*destroyed) (EekboardContextService *self);
/*< private >*/
@ -86,8 +84,10 @@ struct _EekboardContextServiceClass {
gpointer pdummy[24];
};
EekboardContextService *eekboard_context_service_new();
GType eekboard_context_service_get_type
(void) G_GNUC_CONST;
EekboardContextService *eekboard_context_service_new(void);
void eekboard_context_service_destroy (EekboardContextService *context);
LevelKeyboard *eekboard_context_service_get_keyboard(EekboardContextService *context);