Showing and hiding

This commit is contained in:
Dorota Czaplejewicz
2019-04-05 18:36:25 +00:00
parent b065b16bf1
commit 862cfdb55d
2 changed files with 48 additions and 41 deletions

View File

@ -250,12 +250,12 @@ eekboard_context_service_set_property (GObject *object,
context->priv->keyboard = g_value_get_object (value); context->priv->keyboard = g_value_get_object (value);
break; break;
case PROP_VISIBLE: case PROP_VISIBLE:
if (context->priv->keyboard) { /*if (context->priv->keyboard) {
if (g_value_get_boolean (value)) if (g_value_get_boolean (value))
eekboard_context_service_show_keyboard (context); eekboard_context_service_show_keyboard (context);
else else
eekboard_context_service_hide_keyboard (context); eekboard_context_service_hide_keyboard (context);
} }*/
break; break;
case PROP_FULLSCREEN: case PROP_FULLSCREEN:
context->priv->fullscreen = g_value_get_boolean (value); context->priv->fullscreen = g_value_get_boolean (value);

View File

@ -251,8 +251,6 @@ set_geometry (ServerContextService *context)
gtk_window_set_decorated (GTK_WINDOW(context->window), FALSE); gtk_window_set_decorated (GTK_WINDOW(context->window), FALSE);
gtk_window_set_resizable (GTK_WINDOW(context->window), FALSE); gtk_window_set_resizable (GTK_WINDOW(context->window), FALSE);
gtk_window_set_opacity (GTK_WINDOW(context->window), 0.8);
g_signal_connect_after (context->window, "realize", g_signal_connect_after (context->window, "realize",
G_CALLBACK(on_realize_set_dock), G_CALLBACK(on_realize_set_dock),
context); context);
@ -273,33 +271,11 @@ set_geometry (ServerContextService *context)
} }
static void static void
update_widget (ServerContextService *context) make_window (ServerContextService *context) {
{ if (context->window) {
EekKeyboard *keyboard; g_error("Window already present");
const gchar *client_name; return;
EekBounds bounds;
gchar *theme_path;
EekTheme *theme;
if (context->widget) {
gtk_widget_destroy (context->widget);
context->widget = NULL;
} }
theme_path = g_build_filename (THEMESDIR, "default.css", NULL);
theme = eek_theme_new (theme_path, NULL, NULL);
g_free (theme_path);
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
context->widget = eek_gtk_keyboard_new (keyboard);
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_WIDGET(g_object_new ( context->window = GTK_WIDGET(g_object_new (
PHOSH_TYPE_LAYER_SURFACE, PHOSH_TYPE_LAYER_SURFACE,
"layer-shell", squeak_wayland->layer_shell, "layer-shell", squeak_wayland->layer_shell,
@ -322,12 +298,44 @@ update_widget (ServerContextService *context)
gtk_widget_set_can_focus (context->window, FALSE); gtk_widget_set_can_focus (context->window, FALSE);
g_object_set (G_OBJECT(context->window), "accept_focus", FALSE, NULL); g_object_set (G_OBJECT(context->window), "accept_focus", FALSE, NULL);
client_name = eekboard_context_service_get_client_name (EEKBOARD_CONTEXT_SERVICE(context)); const gchar *client_name = eekboard_context_service_get_client_name (EEKBOARD_CONTEXT_SERVICE(context));
gtk_window_set_title (GTK_WINDOW(context->window), gtk_window_set_title (GTK_WINDOW(context->window),
client_name ? client_name : _("Keyboard")); client_name ? client_name : _("Keyboard"));
gtk_window_set_icon_name (GTK_WINDOW(context->window), "eekboard"); gtk_window_set_icon_name (GTK_WINDOW(context->window), "eekboard");
gtk_window_set_keep_above (GTK_WINDOW(context->window), TRUE); gtk_window_set_keep_above (GTK_WINDOW(context->window), TRUE);
} }
static void
destroy_window (ServerContextService *context) {
context->window = NULL;
}
static void
update_widget (ServerContextService *context)
{
EekKeyboard *keyboard;
EekBounds bounds;
gchar *theme_path;
EekTheme *theme;
if (context->widget) {
gtk_widget_destroy (context->widget);
context->widget = NULL;
}
theme_path = g_build_filename (THEMESDIR, "default.css", NULL);
theme = eek_theme_new (theme_path, NULL, NULL);
g_free (theme_path);
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
context->widget = eek_gtk_keyboard_new (keyboard);
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget), theme);
g_object_unref (theme);
gtk_widget_set_has_tooltip (context->widget, TRUE);
gtk_container_add (GTK_CONTAINER(context->window), context->widget); gtk_container_add (GTK_CONTAINER(context->window), context->widget);
set_geometry (context); set_geometry (context);
} }
@ -337,10 +345,8 @@ server_context_service_real_show_keyboard (EekboardContextService *_context)
{ {
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context); ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (!context->window) make_window (context);
update_widget (context); update_widget (context);
g_assert (context->window);
gtk_widget_show_all (context->window);
EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)-> EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)->
show_keyboard (_context); show_keyboard (_context);
@ -351,8 +357,9 @@ server_context_service_real_hide_keyboard (EekboardContextService *_context)
{ {
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context); ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
if (context->window)
gtk_widget_hide (context->window); gtk_widget_hide (context->window);
gtk_container_remove(GTK_CONTAINER(context->window), context->widget);
destroy_window (context);
EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)-> EEKBOARD_CONTEXT_SERVICE_CLASS (server_context_service_parent_class)->
hide_keyboard (_context); hide_keyboard (_context);