Enable Wayland's virtual-keyboard protocol

This commit includes a little restructuring necessary for keeping wayland objects properly.
It doesn't fix broken modifier functionality yet.
This commit is contained in:
Dorota Czaplejewicz
2019-06-22 15:20:58 +00:00
parent c0fdffac28
commit 9e5629d1e0
27 changed files with 497 additions and 194 deletions

View File

@ -88,7 +88,7 @@ enum FocusListenerType {
};
static gboolean
set_keyboards (Client *client,
set_keyboards (SeatEmitter *client,
const gchar * const *keyboards)
{
if (g_strv_length ((gchar **)keyboards) == 0) {
@ -110,7 +110,7 @@ set_keyboards (Client *client,
int
main (int argc, char **argv)
{
Client *client = NULL;
SeatEmitter *client = NULL;
EekboardClient *eekboard;
EekboardContext *context;
GBusType bus_type;

View File

@ -101,7 +101,7 @@ struct _ClientClass {
GObjectClass parent_class;
};
G_DEFINE_TYPE (Client, client, G_TYPE_OBJECT);
G_DEFINE_TYPE (SeatEmitter, client, G_TYPE_OBJECT);
#if ENABLE_FOCUS_LISTENER
#define IS_KEYBOARD_VISIBLE(client) (!client->follows_focus)
@ -128,10 +128,10 @@ static void focus_listener_cb (const AtspiEvent *event,
static gboolean keystroke_listener_cb (const AtspiDeviceEvent *stroke,
void *user_data);
#endif /* HAVE_ATSPI */
static gboolean set_keyboards (Client *client,
static gboolean set_keyboards (SeatEmitter *client,
const gchar * const *keyboard);
static gboolean set_keyboards_from_xkl
(Client *client);
(SeatEmitter *client);
#ifdef HAVE_XTEST
static void update_modifier_keycodes
(Client *client);
@ -143,7 +143,7 @@ client_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
Client *client = CLIENT(object);
SeatEmitter *client = CLIENT(object);
GDBusConnection *connection;
gchar **keyboards;
@ -188,7 +188,7 @@ client_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
Client *client = CLIENT(object);
SeatEmitter *client = CLIENT(object);
switch (prop_id) {
case PROP_EEKBOARD:
@ -206,7 +206,7 @@ client_get_property (GObject *object,
static void
client_dispose (GObject *object)
{
Client *client = CLIENT(object);
SeatEmitter *client = CLIENT(object);
client_disable_xkl (client);
@ -246,7 +246,7 @@ client_dispose (GObject *object)
static void
client_finalize (GObject *object)
{
Client *client = CLIENT(object);
SeatEmitter *client = CLIENT(object);
g_slist_free (client->keyboards);
G_OBJECT_CLASS (client_parent_class)->finalize (object);
@ -301,13 +301,13 @@ client_class_init (ClientClass *klass)
}
static void
client_init (Client *client)
client_init (SeatEmitter *client)
{
client->settings = g_settings_new ("org.fedorahosted.eekboard");
}
gboolean
client_set_keyboards (Client *client,
client_set_keyboards (SeatEmitter *client,
const gchar * const *keyboards)
{
gboolean retval;
@ -318,7 +318,7 @@ client_set_keyboards (Client *client,
}
gboolean
client_enable_xkl (Client *client)
client_enable_xkl (SeatEmitter *client)
{
GdkDisplay *display = gdk_display_get_default ();
gboolean retval;
@ -361,7 +361,7 @@ client_enable_xkl (Client *client)
}
void
client_disable_xkl (Client *client)
client_disable_xkl (SeatEmitter *client)
{
if (client->xkl_engine) {
xkl_engine_stop_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
@ -618,7 +618,7 @@ add_match_rule (GDBusConnection *connection,
}
static gboolean
on_hide_keyboard_timeout (Client *client)
on_hide_keyboard_timeout (SeatEmitter *client)
{
eekboard_client_hide_keyboard (client->eekboard, NULL);
client->hide_keyboard_timeout_id = 0;
@ -631,7 +631,7 @@ focus_message_filter (GDBusConnection *connection,
gboolean incoming,
gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
if (incoming &&
g_strcmp0 (g_dbus_message_get_interface (message),
@ -661,7 +661,7 @@ focus_message_filter (GDBusConnection *connection,
static void
_ibus_connect_focus_handlers (GDBusConnection *connection, gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
add_match_rule (connection,
"type='method_call',"
@ -679,7 +679,7 @@ _ibus_connect_focus_handlers (GDBusConnection *connection, gpointer user_data)
}
gboolean
client_enable_ibus_focus (Client *client)
client_enable_ibus_focus (SeatEmitter *client)
{
if (client->ibus_connection == NULL) {
const gchar *ibus_address;
@ -711,7 +711,7 @@ client_enable_ibus_focus (Client *client)
}
void
client_disable_ibus_focus (Client *client)
client_disable_ibus_focus (SeatEmitter *client)
{
client->follows_focus = FALSE;
@ -725,10 +725,10 @@ client_disable_ibus_focus (Client *client)
}
}
Client *
SeatEmitter *
client_new (GDBusConnection *connection)
{
Client *client = g_object_new (TYPE_CLIENT,
SeatEmitter *client = g_object_new (TYPE_CLIENT,
"connection", connection,
NULL);
if (client->context)
@ -741,7 +741,7 @@ filter_xkl_event (GdkXEvent *xev,
GdkEvent *event,
gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
XEvent *xevent = (XEvent *)xev;
xkl_engine_filter_events (client->xkl_engine, xevent);
@ -752,7 +752,7 @@ static void
on_xkl_config_changed (XklEngine *xklengine,
gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
gboolean retval;
retval = set_keyboards_from_xkl (client);
@ -764,7 +764,7 @@ on_xkl_config_changed (XklEngine *xklengine,
}
static gboolean
set_keyboards (Client *client,
set_keyboards (SeatEmitter *client,
const gchar * const *keyboards)
{
guint keyboard_id;
@ -805,7 +805,7 @@ set_keyboards (Client *client,
}
static gboolean
set_keyboards_from_xkl (Client *client)
set_keyboards_from_xkl (SeatEmitter *client)
{
XklConfigRec *rec;
gchar *layout, *keyboard;
@ -837,7 +837,7 @@ on_xkl_state_changed (XklEngine *xklengine,
gboolean restore,
gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
if (type == GROUP_CHANGED)
eekboard_context_set_group (client->context, value, NULL);
@ -851,7 +851,7 @@ on_xkl_state_changed (XklEngine *xklengine,
- get_keycode_from_gdk_keymap (Caribou: best_keycode_keyval_match)
*/
static guint
get_replaced_keycode (Client *client)
get_replaced_keycode (SeatEmitter *client)
{
guint keycode;
@ -876,7 +876,7 @@ get_replaced_keycode (Client *client)
non-zero keycode), it simply changes the current map with the
specified KEYCODE and KEYSYM. */
static gboolean
replace_keycode (Client *client,
replace_keycode (SeatEmitter *client,
guint keycode,
guint *keysym)
{
@ -904,7 +904,7 @@ return TRUE; // FIXME: no xkb allocated at the moment, pretending all is fine
}
static gboolean
get_keycode_from_gdk_keymap (Client *client,
get_keycode_from_gdk_keymap (SeatEmitter *client,
guint keysym,
guint *keycode,
guint *modifiers)
@ -932,7 +932,7 @@ get_keycode_from_gdk_keymap (Client *client,
return TRUE;
}
int WaylandFakeKeyEvent(
int send_virtual_keyboard_key(
Display* dpy,
unsigned int keycode,
Bool is_press,
@ -943,7 +943,7 @@ int WaylandFakeKeyEvent(
/* never actually used? */
static void
send_fake_modifier_key_event (Client *client,
send_fake_modifier_key_event (SeatEmitter *client,
EekModifierType modifiers,
gboolean is_pressed)
{
@ -957,7 +957,7 @@ send_fake_modifier_key_event (Client *client,
printf("Trying to send a modifier %d press %d\n", i, is_pressed);
g_return_if_fail (keycode > 0);
WaylandFakeKeyEvent (xdisplay,
send_virtual_keyboard_key (xdisplay,
keycode,
is_pressed,
CurrentTime);
@ -967,7 +967,7 @@ send_fake_modifier_key_event (Client *client,
}
static void
send_fake_key_event (Client *client,
send_fake_key_event (SeatEmitter *client,
guint xkeysym,
guint keyboard_modifiers)
{
@ -1006,9 +1006,9 @@ send_fake_key_event (Client *client,
modifiers |= keyboard_modifiers;
send_fake_modifier_key_event (client, modifiers, TRUE);
WaylandFakeKeyEvent (xdisplay, keycode, TRUE, 20);
send_virtual_keyboard_key (xdisplay, keycode, TRUE, 20);
//XSync (xdisplay, False);
WaylandFakeKeyEvent (xdisplay, keycode, FALSE, 20);
send_virtual_keyboard_key (xdisplay, keycode, FALSE, 20);
// XSync (xdisplay, False);
send_fake_modifier_key_event (client, modifiers, FALSE);
@ -1017,7 +1017,7 @@ send_fake_key_event (Client *client,
}
static void
send_fake_key_events (Client *client,
send_fake_key_events (SeatEmitter *client,
EekSymbol *symbol,
guint keyboard_modifiers)
{
@ -1063,7 +1063,7 @@ on_key_activated (EekboardContext *context,
guint modifiers,
gpointer user_data)
{
Client *client = user_data;
SeatEmitter *client = user_data;
if (g_strcmp0 (eek_symbol_get_name (symbol), "cycle-keyboard") == 0) {
client->keyboards_head = g_slist_next (client->keyboards_head);
@ -1119,7 +1119,7 @@ update_modifier_keycodes (Client *client)
}
#endif
gboolean
client_enable_xtest (Client *client)
client_enable_xtest (SeatEmitter *client)
{
//GdkDisplay *display = gdk_display_get_default ();
//Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
@ -1156,7 +1156,7 @@ client_enable_xtest (Client *client)
}
void
client_disable_xtest (Client *client)
client_disable_xtest (SeatEmitter *client)
{
//if (client->xkb) {
// XkbFreeKeyboard (client->xkb, 0, TRUE); /* free_all = TRUE */

View File

@ -29,27 +29,27 @@ G_BEGIN_DECLS
#define IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLIENT))
#define CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLIENT, ClientClass))
typedef struct _Client Client;
typedef struct _Client SeatEmitter;
Client *client_new (GDBusConnection *connection);
SeatEmitter *client_new (GDBusConnection *connection);
gboolean client_set_keyboards (Client *client,
gboolean client_set_keyboards (SeatEmitter *client,
const gchar * const *keyboard);
gboolean client_enable_xkl (Client *client);
void client_disable_xkl (Client *client);
gboolean client_enable_xkl (SeatEmitter *client);
void client_disable_xkl (SeatEmitter *client);
gboolean client_enable_atspi_focus (Client *client);
void client_disable_atspi_focus (Client *client);
gboolean client_enable_atspi_focus (SeatEmitter *client);
void client_disable_atspi_focus (SeatEmitter *client);
gboolean client_enable_atspi_keystroke (Client *client);
void client_disable_atspi_keystroke (Client *client);
gboolean client_enable_atspi_keystroke (SeatEmitter *client);
void client_disable_atspi_keystroke (SeatEmitter *client);
gboolean client_enable_xtest (Client *client);
void client_disable_xtest (Client *client);
gboolean client_enable_xtest (SeatEmitter *client);
void client_disable_xtest (SeatEmitter *client);
gboolean client_enable_ibus_focus (Client *client);
void client_disable_ibus_focus (Client *client);
gboolean client_enable_ibus_focus (SeatEmitter *client);
void client_disable_ibus_focus (SeatEmitter *client);
G_END_DECLS
#endif /* CLIENT_H */

View File

@ -34,6 +34,7 @@ sources = [
enums,
keysym_entries,
marshalers,
'../eekboard/keymap.c',
'../eekboard/key-emitter.c',
'../eekboard/eekboard-context-service.c',
'../eekboard/eekboard-context.c',
@ -51,7 +52,9 @@ deps = [
dependency('gtk+-3.0', version: '>=3.0'),
dependency('libcroco-0.6'),
dependency('wayland-client', version: '>=1.14'),
dependency('xkbcommon'),
cc.find_library('m'),
cc.find_library('rt'),
# dependency('libxklavier'), # FIXME remove
]

View File

@ -95,6 +95,17 @@ on_notify_keyboard (GObject *object,
const EekKeyboard *keyboard;
keyboard = eekboard_context_service_get_keyboard (EEKBOARD_CONTEXT_SERVICE(context));
if (!keyboard) {
g_error("Programmer error: keyboard layout was unset!");
}
// 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(EEKBOARD_CONTEXT_SERVICE(context),
keyboard);
if (context->window) {
if (keyboard == NULL) {
gtk_widget_hide (context->window);
@ -106,8 +117,9 @@ on_notify_keyboard (GObject *object,
g_signal_handler_block (context->window,
context->notify_visible_handler);
update_widget (context);
if (was_visible)
if (was_visible) {
gtk_widget_show_all (context->window);
}
g_signal_handler_unblock (context->window,
context->notify_visible_handler);
}
@ -492,9 +504,9 @@ server_context_service_init (ServerContextService *context)
context);
}
ServerContextService *
EekboardContextService *
server_context_service_new ()
{
return g_object_new (SERVER_TYPE_CONTEXT_SERVICE,
NULL);
return EEKBOARD_CONTEXT_SERVICE(g_object_new (SERVER_TYPE_CONTEXT_SERVICE,
NULL));
}

View File

@ -32,7 +32,7 @@ G_BEGIN_DECLS
/** Manages the liecycle of the window displaying layouts. */
typedef struct _ServerContextService ServerContextService;
ServerContextService *server_context_service_new ();
EekboardContextService *server_context_service_new ();
G_END_DECLS
#endif /* SERVER_CONTEXT_SERVICE_H */

View File

@ -38,6 +38,14 @@
#include <gdk/gdkwayland.h>
/// Global application state
struct squeekboard {
struct squeek_wayland wayland;
EekboardContextService *context;
};
static gboolean opt_system = FALSE;
static gchar *opt_address = NULL;
@ -93,17 +101,25 @@ registry_handle_global (void *data,
const char *interface,
uint32_t version)
{
struct squeek_wayland *wayland = data;
// currently only v1 supported for most interfaces,
// so there's no reason to check for available versions.
// Even when lower version would be served, it would not be supported,
// causing a hard exit
(void)version;
struct squeekboard *instance = data;
if (!strcmp (interface, zwlr_layer_shell_v1_interface.name)) {
wayland->layer_shell = wl_registry_bind (registry, name,
instance->wayland.layer_shell = wl_registry_bind (registry, name,
&zwlr_layer_shell_v1_interface, 1);
} else if (!strcmp (interface, zwp_virtual_keyboard_manager_v1_interface.name)) {
instance->wayland.virtual_keyboard_manager = wl_registry_bind(registry, name,
&zwp_virtual_keyboard_manager_v1_interface, 1);
} else if (!strcmp (interface, "wl_output")) {
struct wl_output *output = wl_registry_bind (registry, name,
&wl_output_interface, 2);
g_ptr_array_add (wayland->outputs, output);
g_ptr_array_add (instance->wayland.outputs, output);
} else if (!strcmp(interface, "wl_seat")) {
wayland->seat = wl_registry_bind(registry, name,
instance->wayland.seat = wl_registry_bind(registry, name,
&wl_seat_interface, 1);
}
}
@ -139,17 +155,33 @@ main (int argc, char **argv)
if (display == NULL) {
g_error ("Failed to get display: %m\n");
exit(1);
}
struct squeek_wayland wayland = {0};
squeek_wayland_init (&wayland);
struct wl_registry *registry = wl_display_get_registry (display);
wl_registry_add_listener (registry, &registry_listener, &wayland);
squeek_wayland_set_global(&wayland);
EekboardContextService *context = create_context();
struct squeekboard instance = {0};
squeek_wayland_init (&instance.wayland);
struct wl_registry *registry = wl_display_get_registry (display);
wl_registry_add_listener (registry, &registry_listener, &instance);
wl_display_roundtrip(display); // wait until the registry is actually populated
squeek_wayland_set_global(&instance.wayland);
if (!instance.wayland.seat) {
g_error("No seat Wayland global available.");
exit(1);
}
if (!instance.wayland.virtual_keyboard_manager) {
g_error("No virtual keyboard manager Wayland global available.");
exit(1);
}
instance.context = create_context();
// set up dbus
// TODO: make dbus errors non-always-fatal
// dbus is not strictly necessary for the useful operation
// if text-input is used, as it can bring the keyboard in and out
GBusType bus_type;
if (opt_system)
bus_type = G_BUS_TYPE_SYSTEM;
@ -191,16 +223,13 @@ main (int argc, char **argv)
break;
}
// TODO: make dbus errors non-always-fatal
// dbus is not strictly necessary for the useful operation
// if text-input is used, as it can bring the keyboard in and out
EekboardService *service = eekboard_service_new (connection, EEKBOARD_SERVICE_PATH);
if (service == NULL) {
g_printerr ("Can't create server\n");
g_printerr ("Can't create dbus server\n");
exit (1);
} else {
eekboard_service_set_context(service, context);
eekboard_service_set_context(service, instance.context);
}
guint owner_id = g_bus_own_name_on_connection (connection,
@ -226,6 +255,6 @@ main (int argc, char **argv)
g_object_unref (connection);
g_main_loop_unref (loop);
squeek_wayland_deinit (&wayland);
squeek_wayland_deinit (&instance.wayland);
return 0;
}

View File

@ -2,12 +2,14 @@
#define WAYLAND_H
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "virtual-keyboard-unstable-v1-client-protocol.h"
#include <gmodule.h>
struct squeek_wayland {
struct zwlr_layer_shell_v1 *layer_shell;
struct zwp_virtual_keyboard_manager_v1 *virtual_keyboard_manager;
GPtrArray *outputs; // *wl_output
struct wl_seat *seat;
};