managers: Move visible flag to UI manager

This commit is contained in:
Dorota Czaplejewicz
2020-01-09 14:14:48 +00:00
parent 7e72722a47
commit 9f59279307
10 changed files with 98 additions and 116 deletions

View File

@ -2,9 +2,6 @@
#include <glib.h>
#include "eekboard/eekboard-context-service.h"
static const struct zwp_input_method_v2_listener input_method_listener = {
.activate = imservice_handle_input_method_activate,
.deactivate = imservice_handle_input_method_deactivate,
@ -15,7 +12,7 @@ static const struct zwp_input_method_v2_listener input_method_listener = {
.unavailable = imservice_handle_unavailable,
};
struct imservice* get_imservice(EekboardContextService *context,
struct imservice* get_imservice(ServerContextService *context,
struct zwp_input_method_manager_v2 *manager,
struct wl_seat *seat) {
struct zwp_input_method_v2 *im = zwp_input_method_manager_v2_get_input_method(manager, seat);
@ -28,14 +25,6 @@ struct imservice* get_imservice(EekboardContextService *context,
return imservice;
}
void imservice_make_visible(EekboardContextService *context) {
eekboard_context_service_show_keyboard (context);
}
void imservice_try_hide(EekboardContextService *context) {
eekboard_context_service_hide_keyboard (context);
}
/// Declared explicitly because _destroy is inline,
/// making it unavailable in Rust
void imservice_destroy_im(struct zwp_input_method_v2 *im) {

View File

@ -3,16 +3,17 @@
#include "input-method-unstable-v2-client-protocol.h"
#include "eek/eek-types.h"
#include "src/server-context-service.h"
struct imservice;
struct imservice* get_imservice(EekboardContextService *context,
struct imservice* get_imservice(ServerContextService *context,
struct zwp_input_method_manager_v2 *manager,
struct wl_seat *seat);
// Defined in Rust
struct imservice* imservice_new(struct zwp_input_method_v2 *im,
EekboardContextService *context);
ServerContextService *context);
void imservice_handle_input_method_activate(void *data, struct zwp_input_method_v2 *input_method);
void imservice_handle_input_method_deactivate(void *data, struct zwp_input_method_v2 *input_method);
void imservice_handle_surrounding_text(void *data, struct zwp_input_method_v2 *input_method,

View File

@ -29,8 +29,8 @@ pub mod c {
extern "C" {
fn imservice_destroy_im(im: *mut c::InputMethod);
fn eekboard_context_service_set_hint_purpose(imservice: *const UIManager, hint: u32, purpose: u32);
fn eekboard_context_service_show_keyboard(imservice: *const UIManager);
fn eekboard_context_service_hide_keyboard(imservice: *const UIManager);
fn server_context_service_show_keyboard(imservice: *const UIManager);
fn server_context_service_hide_keyboard(imservice: *const UIManager);
}
// The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
@ -150,13 +150,13 @@ pub mod c {
};
if active_changed {
if imservice.current.active {
eekboard_context_service_show_keyboard(imservice.ui_manager);
server_context_service_show_keyboard(imservice.ui_manager);
eekboard_context_service_set_hint_purpose(
imservice.ui_manager,
imservice.current.content_hint.bits(),
imservice.current.content_purpose.clone() as u32);
} else {
eekboard_context_service_hide_keyboard(imservice.ui_manager);
server_context_service_hide_keyboard(imservice.ui_manager);
}
}
}
@ -173,7 +173,7 @@ pub mod c {
// the keyboard is already decommissioned
imservice.current.active = false;
eekboard_context_service_hide_keyboard(imservice.ui_manager);
server_context_service_hide_keyboard(imservice.ui_manager);
}
// FIXME: destroy and deallocate

View File

@ -23,14 +23,15 @@
#include "eek/eek.h"
#include "eek/eek-gtk-keyboard.h"
#include "eek/layersurface.h"
#include "wayland.h"
#include "eekboard/eekboard-context-service.h"
#include "wayland.h"
#include "server-context-service.h"
enum {
PROP_0,
PROP_SIZE_CONSTRAINT_LANDSCAPE,
PROP_SIZE_CONSTRAINT_PORTRAIT,
PROP_VISIBLE,
PROP_LAST
};
@ -39,6 +40,7 @@ typedef struct _ServerContextServiceClass ServerContextServiceClass;
struct _ServerContextService {
EekboardContextService parent;
gboolean visible;
PhoshLayerSurface *window;
GtkWidget *widget;
guint hiding;
@ -95,8 +97,8 @@ on_notify_keyboard (GObject *object,
g_object_get (context, "visible", &visible, NULL);
if (visible) {
eekboard_context_service_hide_keyboard(EEKBOARD_CONTEXT_SERVICE(context));
eekboard_context_service_show_keyboard(EEKBOARD_CONTEXT_SERVICE(context));
server_context_service_hide_keyboard(context);
server_context_service_show_keyboard(context);
}
}
@ -238,11 +240,18 @@ make_widget (ServerContextService *context)
gtk_widget_show (context->widget);
}
void
server_context_service_real_show_keyboard (EekboardContextService *_context)
static gboolean
on_hide (ServerContextService *context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
gtk_widget_hide (GTK_WIDGET(context->window));
context->hiding = 0;
return G_SOURCE_REMOVE;
}
static void
server_context_service_real_show_keyboard (ServerContextService *context)
{
if (context->hiding) {
g_source_remove (context->hiding);
context->hiding = 0;
@ -253,28 +262,37 @@ server_context_service_real_show_keyboard (EekboardContextService *_context)
if (!context->widget)
make_widget (context);
eekboard_context_service_real_show_keyboard (_context);
context->visible = TRUE;
gtk_widget_show (GTK_WIDGET(context->window));
}
static gboolean
on_hide (ServerContextService *context)
static void
server_context_service_real_hide_keyboard (ServerContextService *context)
{
gtk_widget_hide (GTK_WIDGET(context->window));
context->hiding = 0;
if (!context->hiding)
context->hiding = g_timeout_add (200, (GSourceFunc) on_hide, context);
return G_SOURCE_REMOVE;
context->visible = FALSE;
}
void
server_context_service_real_hide_keyboard (EekboardContextService *_context)
server_context_service_show_keyboard (ServerContextService *context)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(_context);
g_return_if_fail (SERVER_IS_CONTEXT_SERVICE(context));
if (!context->hiding)
context->hiding = g_timeout_add (200, (GSourceFunc) on_hide, context);
if (!context->visible) {
server_context_service_real_show_keyboard (context);
}
}
eekboard_context_service_real_hide_keyboard (_context);
void
server_context_service_hide_keyboard (ServerContextService *context)
{
g_return_if_fail (SERVER_IS_CONTEXT_SERVICE(context));
if (context->visible) {
server_context_service_real_hide_keyboard (context);
}
}
static void
@ -304,6 +322,9 @@ server_context_service_set_property (GObject *object,
&context->size_constraint_portrait[0],
&context->size_constraint_portrait[1]);
break;
case PROP_VISIBLE:
context->visible = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -311,6 +332,23 @@ server_context_service_set_property (GObject *object,
}
}
static void
server_context_service_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ServerContextService *context = SERVER_CONTEXT_SERVICE(object);
switch (prop_id) {
case PROP_VISIBLE:
g_value_set_boolean (value, context->visible);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
server_context_service_dispose (GObject *object)
{
@ -332,6 +370,7 @@ server_context_service_class_init (ServerContextServiceClass *klass)
context_class->destroyed = server_context_service_real_destroyed;
gobject_class->set_property = server_context_service_set_property;
gobject_class->get_property = server_context_service_get_property;
gobject_class->dispose = server_context_service_dispose;
pspec = g_param_spec_variant ("size-constraint-landscape",
@ -353,6 +392,18 @@ server_context_service_class_init (ServerContextServiceClass *klass)
g_object_class_install_property (gobject_class,
PROP_SIZE_CONSTRAINT_PORTRAIT,
pspec);
/**
* Flag to indicate if keyboard is visible or not.
*/
pspec = g_param_spec_boolean ("visible",
"Visible",
"Visible",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_VISIBLE,
pspec);
}
static void
@ -364,10 +415,10 @@ server_context_service_init (ServerContextService *context)
context);
}
EekboardContextService *
ServerContextService *
server_context_service_new ()
{
return EEKBOARD_CONTEXT_SERVICE(g_object_new (SERVER_TYPE_CONTEXT_SERVICE, NULL));
return g_object_new (SERVER_TYPE_CONTEXT_SERVICE, NULL);
}
enum squeek_arrangement_kind server_context_service_get_layout_type(EekboardContextService *service)

View File

@ -18,7 +18,6 @@
#ifndef SERVER_CONTEXT_SERVICE_H
#define SERVER_CONTEXT_SERVICE_H 1
#include "eekboard/eekboard-service.h"
#include "src/layout.h"
G_BEGIN_DECLS
@ -33,10 +32,13 @@ G_BEGIN_DECLS
/** Manages the liecycle of the window displaying layouts. */
typedef struct _ServerContextService ServerContextService;
EekboardContextService *server_context_service_new ();
GType server_context_service_get_type
(void) G_GNUC_CONST;
ServerContextService *server_context_service_new();
enum squeek_arrangement_kind server_context_service_get_layout_type(EekboardContextService*);
void server_context_service_real_show_keyboard (EekboardContextService *context);
void server_context_service_real_hide_keyboard (EekboardContextService *context);
void server_context_service_show_keyboard (ServerContextService *context);
void server_context_service_hide_keyboard (ServerContextService *context);
G_END_DECLS
#endif /* SERVER_CONTEXT_SERVICE_H */

View File

@ -27,6 +27,7 @@
#include "eekboard/eekboard-service.h"
#include "eek/eek.h"
#include "eekboard/eekboard-context-service.h"
#include "imservice.h"
#include "outputs.h"
#include "server-context-service.h"
@ -38,7 +39,7 @@
/// Global application state
struct squeekboard {
struct squeek_wayland wayland;
EekboardContextService *context;
ServerContextService *context;
struct imservice *imservice;
};
@ -80,12 +81,12 @@ on_destroyed (EekboardService *service,
g_main_loop_quit (loop);
}
static EekboardContextService *create_context() {
EekboardContextService *context = server_context_service_new ();
static ServerContextService *create_context() {
ServerContextService *context = server_context_service_new ();
g_object_set_data_full (G_OBJECT(context),
"owner", g_strdup ("sender"),
(GDestroyNotify)g_free);
eekboard_context_service_enable (context);
eekboard_context_service_enable (EEKBOARD_CONTEXT_SERVICE(context));
return context;
}