2012-06-21 23:52:18 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Openismus GmbH
|
2012-09-10 01:08:30 +04:00
|
|
|
* Copyright © 2012 Intel Corporation
|
2012-06-21 23:52:18 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2012-06-21 23:52:18 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2012-06-21 23:52:18 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-12-06 00:38:39 +03:00
|
|
|
#include <stdbool.h>
|
2012-06-21 23:52:18 +04:00
|
|
|
#include <stdlib.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2012-11-18 22:06:42 +04:00
|
|
|
#include <string.h>
|
2013-05-14 20:48:26 +04:00
|
|
|
#include <unistd.h>
|
2013-05-14 20:09:31 +04:00
|
|
|
#include <time.h>
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2019-03-28 17:28:47 +03:00
|
|
|
#include <libweston/libweston.h>
|
2016-06-02 21:48:10 +03:00
|
|
|
#include "weston.h"
|
2015-11-17 11:00:29 +03:00
|
|
|
#include "text-input-unstable-v1-server-protocol.h"
|
2015-11-17 11:00:30 +03:00
|
|
|
#include "input-method-unstable-v1-server-protocol.h"
|
2015-06-16 01:37:10 +03:00
|
|
|
#include "shared/helpers.h"
|
2017-11-16 19:20:57 +03:00
|
|
|
#include "shared/timespec-util.h"
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2015-05-09 01:08:40 +03:00
|
|
|
struct text_input_manager;
|
2012-06-21 23:52:18 +04:00
|
|
|
struct input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
struct input_method_context;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input {
|
2013-06-14 19:07:59 +04:00
|
|
|
struct wl_resource *resource;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
struct weston_compositor *ec;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_list input_methods;
|
2012-08-10 18:47:23 +04:00
|
|
|
|
2013-05-08 17:54:37 +04:00
|
|
|
struct weston_surface *surface;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2013-04-18 18:47:28 +04:00
|
|
|
pixman_box32_t cursor_rectangle;
|
|
|
|
|
2014-12-06 00:38:39 +03:00
|
|
|
bool input_panel_visible;
|
2015-05-09 01:08:40 +03:00
|
|
|
|
|
|
|
struct text_input_manager *manager;
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager {
|
|
|
|
struct wl_global *text_input_manager_global;
|
2012-09-10 01:08:31 +04:00
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
|
2017-06-25 00:03:41 +03:00
|
|
|
struct text_input *current_text_input;
|
2015-05-09 01:08:40 +03:00
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
struct weston_compositor *ec;
|
|
|
|
};
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
struct input_method {
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *input_method_binding;
|
|
|
|
struct wl_global *input_method_global;
|
2012-06-21 23:52:18 +04:00
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
struct weston_seat *seat;
|
2015-05-09 01:08:41 +03:00
|
|
|
struct text_input *input;
|
2012-08-10 18:47:22 +04:00
|
|
|
|
|
|
|
struct wl_list link;
|
2012-08-10 18:47:23 +04:00
|
|
|
|
|
|
|
struct wl_listener keyboard_focus_listener;
|
|
|
|
|
2015-07-15 21:00:32 +03:00
|
|
|
bool focus_listener_initialized;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
|
|
struct input_method_context *context;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
struct text_backend *text_backend;
|
2012-09-10 01:08:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct input_method_context {
|
2013-06-14 19:07:59 +04:00
|
|
|
struct wl_resource *resource;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
struct text_input *input;
|
2012-11-18 22:06:45 +04:00
|
|
|
struct input_method *input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
struct wl_resource *keyboard;
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend {
|
|
|
|
struct weston_compositor *compositor;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *path;
|
2021-09-15 07:54:29 +03:00
|
|
|
bool overlay_keyboard;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct wl_client *client;
|
2013-05-14 20:09:31 +04:00
|
|
|
|
|
|
|
unsigned deathcount;
|
2017-11-16 19:21:01 +03:00
|
|
|
struct timespec deathstamp;
|
2012-11-18 22:06:42 +04:00
|
|
|
} input_method;
|
|
|
|
|
2015-06-25 23:49:49 +03:00
|
|
|
struct wl_listener client_listener;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct wl_listener seat_created_listener;
|
|
|
|
};
|
|
|
|
|
2014-12-06 00:38:37 +03:00
|
|
|
static void
|
2015-05-09 01:08:41 +03:00
|
|
|
input_method_context_create(struct text_input *input,
|
2014-12-06 00:38:37 +03:00
|
|
|
struct input_method *input_method);
|
|
|
|
static void
|
|
|
|
input_method_context_end_keyboard_grab(struct input_method_context *context);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2014-12-06 00:38:37 +03:00
|
|
|
static void
|
|
|
|
input_method_init_seat(struct weston_seat *seat);
|
2012-08-10 18:47:23 +04:00
|
|
|
|
2012-07-12 00:25:30 +04:00
|
|
|
static void
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(struct input_method *input_method)
|
2012-07-12 00:25:30 +04:00
|
|
|
{
|
2015-05-09 01:08:41 +03:00
|
|
|
struct text_input *text_input = input_method->input;
|
2013-04-18 18:47:24 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2012-07-12 00:25:30 +04:00
|
|
|
|
2015-05-09 01:08:40 +03:00
|
|
|
if (input_method->context && input_method->input_method_binding) {
|
|
|
|
input_method_context_end_keyboard_grab(input_method->context);
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_v1_send_deactivate(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->input_method_binding,
|
|
|
|
input_method->context->resource);
|
2016-11-10 18:47:56 +03:00
|
|
|
input_method->context->input = NULL;
|
2015-05-09 01:08:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&input_method->link);
|
2015-05-09 01:08:41 +03:00
|
|
|
input_method->input = NULL;
|
2015-05-09 01:08:40 +03:00
|
|
|
input_method->context = NULL;
|
|
|
|
|
|
|
|
if (wl_list_empty(&text_input->input_methods) &&
|
2017-06-25 00:03:41 +03:00
|
|
|
text_input->input_panel_visible &&
|
|
|
|
text_input->manager->current_text_input == text_input) {
|
2012-07-22 19:51:42 +04:00
|
|
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
2015-05-09 01:08:40 +03:00
|
|
|
text_input->input_panel_visible = false;
|
2012-07-12 00:25:30 +04:00
|
|
|
}
|
2017-06-25 00:03:41 +03:00
|
|
|
|
|
|
|
if (text_input->manager->current_text_input == text_input)
|
|
|
|
text_input->manager->current_text_input = NULL;
|
|
|
|
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_leave(text_input->resource);
|
2012-07-12 00:25:30 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
destroy_text_input(struct wl_resource *resource)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2012-08-10 18:47:22 +04:00
|
|
|
struct input_method *input_method, *next;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link)
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(input_method);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
free(text_input);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_surrounding_text(struct wl_client *client,
|
2012-06-21 23:52:18 +04:00
|
|
|
struct wl_resource *resource,
|
2012-09-10 01:08:40 +04:00
|
|
|
const char *text,
|
|
|
|
uint32_t cursor,
|
|
|
|
uint32_t anchor)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2012-09-10 01:08:32 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2012-09-10 01:08:32 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_surrounding_text(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource, text, cursor, anchor);
|
2012-09-10 01:08:32 +04:00
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_activate(struct wl_client *client,
|
2013-04-18 18:47:39 +04:00
|
|
|
struct wl_resource *resource,
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_resource *seat,
|
|
|
|
struct wl_resource *surface)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-06-14 19:08:00 +04:00
|
|
|
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
|
2018-02-15 14:07:09 +03:00
|
|
|
struct input_method *input_method;
|
2013-04-18 18:47:24 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2015-05-09 01:08:40 +03:00
|
|
|
struct text_input *current;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2018-02-15 14:07:09 +03:00
|
|
|
if (!weston_seat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input_method = weston_seat->input_method;
|
2015-05-09 01:08:41 +03:00
|
|
|
if (input_method->input == text_input)
|
2012-08-10 18:47:22 +04:00
|
|
|
return;
|
2012-08-10 18:47:21 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (input_method->input)
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(input_method);
|
2012-08-10 18:47:21 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
input_method->input = text_input;
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_insert(&text_input->input_methods, &input_method->link);
|
2012-08-10 18:47:23 +04:00
|
|
|
input_method_init_seat(weston_seat);
|
|
|
|
|
2013-06-14 19:07:53 +04:00
|
|
|
text_input->surface = wl_resource_get_user_data(surface);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:33 +04:00
|
|
|
input_method_context_create(text_input, input_method);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2017-06-25 00:03:41 +03:00
|
|
|
current = text_input->manager->current_text_input;
|
2015-05-09 01:08:40 +03:00
|
|
|
|
|
|
|
if (current && current != text_input) {
|
|
|
|
current->input_panel_visible = false;
|
|
|
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:28 +04:00
|
|
|
if (text_input->input_panel_visible) {
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_signal_emit(&ec->show_input_panel_signal,
|
|
|
|
text_input->surface);
|
|
|
|
wl_signal_emit(&ec->update_input_panel_signal,
|
|
|
|
&text_input->cursor_rectangle);
|
2013-04-18 18:47:28 +04:00
|
|
|
}
|
2017-06-25 00:03:41 +03:00
|
|
|
text_input->manager->current_text_input = text_input;
|
2012-08-10 18:47:21 +04:00
|
|
|
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_enter(text_input->resource,
|
|
|
|
text_input->surface->resource);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_deactivate(struct wl_client *client,
|
2012-08-10 18:47:22 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *seat)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:08:00 +04:00
|
|
|
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2018-02-15 14:07:09 +03:00
|
|
|
if (weston_seat && weston_seat->input_method->input)
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(weston_seat->input_method);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:46 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_reset(struct wl_client *client,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct wl_resource *resource)
|
2012-09-10 01:08:46 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2012-09-10 01:08:46 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2012-09-10 01:08:46 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_reset(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource);
|
2012-09-10 01:08:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_cursor_rectangle(struct wl_client *client,
|
2013-04-18 18:47:23 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-04-18 18:47:28 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
|
|
|
|
|
|
|
text_input->cursor_rectangle.x1 = x;
|
|
|
|
text_input->cursor_rectangle.y1 = y;
|
|
|
|
text_input->cursor_rectangle.x2 = x + width;
|
|
|
|
text_input->cursor_rectangle.y2 = y + height;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_signal_emit(&ec->update_input_panel_signal,
|
|
|
|
&text_input->cursor_rectangle);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_content_type(struct wl_client *client,
|
2013-01-17 00:26:43 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t hint,
|
|
|
|
uint32_t purpose)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-01-17 00:26:43 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2013-01-17 00:26:43 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_content_type(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource, hint, purpose);
|
2013-01-17 00:26:43 +04:00
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2013-01-17 00:26:46 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_invoke_action(struct wl_client *client,
|
2013-01-17 00:26:46 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t button,
|
|
|
|
uint32_t index)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-01-17 00:26:46 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2013-01-17 00:26:46 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_invoke_action(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource, button, index);
|
2013-01-17 00:26:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:20 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_commit_state(struct wl_client *client,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial)
|
2013-01-31 18:52:20 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-01-31 18:52:20 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2013-01-31 18:52:20 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_commit_state(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource, serial);
|
2013-01-31 18:52:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:21 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_show_input_panel(struct wl_client *client,
|
2013-01-31 18:52:21 +04:00
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-04-18 18:47:24 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2014-12-06 00:38:39 +03:00
|
|
|
text_input->input_panel_visible = true;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2017-06-25 00:03:41 +03:00
|
|
|
if (!wl_list_empty(&text_input->input_methods) &&
|
|
|
|
text_input == text_input->manager->current_text_input) {
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_signal_emit(&ec->show_input_panel_signal,
|
|
|
|
text_input->surface);
|
|
|
|
wl_signal_emit(&ec->update_input_panel_signal,
|
|
|
|
&text_input->cursor_rectangle);
|
2013-04-18 18:47:28 +04:00
|
|
|
}
|
2013-01-31 18:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_hide_input_panel(struct wl_client *client,
|
2013-01-31 18:52:21 +04:00
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-04-18 18:47:24 +04:00
|
|
|
struct weston_compositor *ec = text_input->ec;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2014-12-06 00:38:39 +03:00
|
|
|
text_input->input_panel_visible = false;
|
2013-01-31 18:52:21 +04:00
|
|
|
|
2015-05-09 01:08:40 +03:00
|
|
|
if (!wl_list_empty(&text_input->input_methods) &&
|
2017-06-25 00:03:41 +03:00
|
|
|
text_input == text_input->manager->current_text_input)
|
2013-01-31 18:52:21 +04:00
|
|
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_set_preferred_language(struct wl_client *client,
|
2013-04-18 18:47:15 +04:00
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *language)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct text_input *text_input = wl_resource_get_user_data(resource);
|
2013-04-18 18:47:15 +04:00
|
|
|
struct input_method *input_method, *next;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_list_for_each_safe(input_method, next,
|
|
|
|
&text_input->input_methods, link) {
|
2013-04-18 18:47:15 +04:00
|
|
|
if (!input_method->context)
|
|
|
|
continue;
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_context_v1_send_preferred_language(
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method->context->resource, language);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:29 +03:00
|
|
|
static const struct zwp_text_input_v1_interface text_input_implementation = {
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_activate,
|
|
|
|
text_input_deactivate,
|
|
|
|
text_input_show_input_panel,
|
|
|
|
text_input_hide_input_panel,
|
|
|
|
text_input_reset,
|
|
|
|
text_input_set_surrounding_text,
|
|
|
|
text_input_set_content_type,
|
|
|
|
text_input_set_cursor_rectangle,
|
|
|
|
text_input_set_preferred_language,
|
|
|
|
text_input_commit_state,
|
|
|
|
text_input_invoke_action
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
static void text_input_manager_create_text_input(struct wl_client *client,
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *resource,
|
2012-09-10 01:08:30 +04:00
|
|
|
uint32_t id)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct text_input_manager *text_input_manager =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input *text_input;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2014-11-21 09:21:57 +03:00
|
|
|
text_input = zalloc(sizeof *text_input);
|
|
|
|
if (text_input == NULL)
|
|
|
|
return;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
text_input->resource =
|
2015-11-17 11:00:29 +03:00
|
|
|
wl_resource_create(client, &zwp_text_input_v1_interface, 1, id);
|
2013-06-28 05:17:02 +04:00
|
|
|
wl_resource_set_implementation(text_input->resource,
|
|
|
|
&text_input_implementation,
|
|
|
|
text_input, destroy_text_input);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input->ec = text_input_manager->ec;
|
2015-05-09 01:08:40 +03:00
|
|
|
text_input->manager = text_input_manager;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
wl_list_init(&text_input->input_methods);
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2015-11-17 11:00:29 +03:00
|
|
|
static const struct zwp_text_input_manager_v1_interface manager_implementation = {
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create_text_input
|
2012-07-12 00:25:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
bind_text_input_manager(struct wl_client *client,
|
2012-07-12 00:25:31 +04:00
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager = data;
|
2013-06-28 05:17:02 +04:00
|
|
|
struct wl_resource *resource;
|
2012-07-12 00:25:31 +04:00
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
/* No checking for duplicate binding necessary. */
|
|
|
|
resource =
|
|
|
|
wl_resource_create(client,
|
2015-11-17 11:00:29 +03:00
|
|
|
&zwp_text_input_manager_v1_interface, 1, id);
|
2013-06-28 05:17:02 +04:00
|
|
|
if (resource)
|
|
|
|
wl_resource_set_implementation(resource,
|
2015-06-09 23:29:28 +03:00
|
|
|
&manager_implementation,
|
2013-06-28 05:17:02 +04:00
|
|
|
text_input_manager, NULL);
|
2012-09-10 01:08:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_notifier_destroy(struct wl_listener *listener, void *data)
|
2012-09-10 01:08:31 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager =
|
2015-06-09 23:29:28 +03:00
|
|
|
container_of(listener,
|
|
|
|
struct text_input_manager,
|
|
|
|
destroy_listener);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2018-08-07 16:35:02 +03:00
|
|
|
wl_list_remove(&text_input_manager->destroy_listener.link);
|
2013-07-09 03:03:57 +04:00
|
|
|
wl_global_destroy(text_input_manager->text_input_manager_global);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
free(text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create(struct weston_compositor *ec)
|
2012-09-10 01:08:31 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_manager *text_input_manager;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2014-11-21 09:21:57 +03:00
|
|
|
text_input_manager = zalloc(sizeof *text_input_manager);
|
|
|
|
if (text_input_manager == NULL)
|
|
|
|
return;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager->ec = ec;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager->text_input_manager_global =
|
2013-07-09 03:03:57 +04:00
|
|
|
wl_global_create(ec->wl_display,
|
2015-11-17 11:00:29 +03:00
|
|
|
&zwp_text_input_manager_v1_interface, 1,
|
2013-07-09 03:03:57 +04:00
|
|
|
text_input_manager, bind_text_input_manager);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
text_input_manager->destroy_listener.notify =
|
|
|
|
text_input_manager_notifier_destroy;
|
|
|
|
wl_signal_add(&ec->destroy_signal,
|
|
|
|
&text_input_manager->destroy_listener);
|
2012-07-12 00:25:31 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method_context_destroy(struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
2012-09-10 01:08:32 +04:00
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
static void
|
|
|
|
input_method_context_commit_string(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
2013-01-17 00:26:39 +04:00
|
|
|
uint32_t serial,
|
2013-01-31 18:52:23 +04:00
|
|
|
const char *text)
|
2012-09-10 01:08:32 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_commit_string(context->input->resource,
|
|
|
|
serial, text);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:43 +04:00
|
|
|
static void
|
|
|
|
input_method_context_preedit_string(struct wl_client *client,
|
2013-01-17 00:26:38 +04:00
|
|
|
struct wl_resource *resource,
|
2013-01-17 00:26:39 +04:00
|
|
|
uint32_t serial,
|
2013-01-17 00:26:38 +04:00
|
|
|
const char *text,
|
|
|
|
const char *commit)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-01-17 00:26:38 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_preedit_string(context->input->resource,
|
|
|
|
serial, text, commit);
|
2013-01-17 00:26:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_preedit_styling(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t index,
|
|
|
|
uint32_t length,
|
|
|
|
uint32_t style)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-01-17 00:26:38 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_preedit_styling(context->input->resource,
|
|
|
|
index, length, style);
|
2013-01-17 00:26:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_preedit_cursor(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t cursor)
|
2012-09-10 01:08:43 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-09-10 01:08:43 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_preedit_cursor(context->input->resource,
|
|
|
|
cursor);
|
2012-09-10 01:08:43 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:44 +04:00
|
|
|
static void
|
|
|
|
input_method_context_delete_surrounding_text(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t index,
|
|
|
|
uint32_t length)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-09-10 01:08:44 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_delete_surrounding_text(
|
2015-06-09 23:29:28 +03:00
|
|
|
context->input->resource, index, length);
|
2012-09-10 01:08:44 +04:00
|
|
|
}
|
|
|
|
|
2013-01-31 18:52:23 +04:00
|
|
|
static void
|
|
|
|
input_method_context_cursor_position(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t index,
|
|
|
|
int32_t anchor)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-01-31 18:52:23 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_cursor_position(context->input->resource,
|
|
|
|
index, anchor);
|
2013-01-31 18:52:23 +04:00
|
|
|
}
|
|
|
|
|
2012-09-10 01:08:45 +04:00
|
|
|
static void
|
2012-11-18 22:06:43 +04:00
|
|
|
input_method_context_modifiers_map(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_array *map)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-11-18 22:06:43 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_modifiers_map(context->input->resource,
|
|
|
|
map);
|
2012-11-18 22:06:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_keysym(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t sym,
|
|
|
|
uint32_t state,
|
|
|
|
uint32_t modifiers)
|
2012-09-10 01:08:45 +04:00
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-09-10 01:08:45 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_keysym(context->input->resource,
|
|
|
|
serial, time,
|
|
|
|
sym, state, modifiers);
|
2012-09-10 01:08:45 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
static void
|
|
|
|
unbind_keyboard(struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
|
|
|
input_method_context_end_keyboard_grab(context);
|
|
|
|
context->keyboard = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 23:25:39 +04:00
|
|
|
input_method_context_grab_key(struct weston_keyboard_grab *grab,
|
2017-11-16 19:20:57 +03:00
|
|
|
const struct timespec *time, uint32_t key,
|
|
|
|
uint32_t state_w)
|
2012-11-18 22:06:45 +04:00
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
2013-01-17 00:26:50 +04:00
|
|
|
struct wl_display *display;
|
2012-11-18 22:06:45 +04:00
|
|
|
uint32_t serial;
|
2017-11-16 19:20:57 +03:00
|
|
|
uint32_t msecs;
|
2013-01-17 00:26:50 +04:00
|
|
|
|
|
|
|
if (!keyboard->input_method_resource)
|
|
|
|
return;
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
display = wl_client_get_display(
|
|
|
|
wl_resource_get_client(keyboard->input_method_resource));
|
2013-01-17 00:26:50 +04:00
|
|
|
serial = wl_display_next_serial(display);
|
2017-11-16 19:20:57 +03:00
|
|
|
msecs = timespec_to_msec(time);
|
2013-01-17 00:26:50 +04:00
|
|
|
wl_keyboard_send_key(keyboard->input_method_resource,
|
2017-11-16 19:20:57 +03:00
|
|
|
serial, msecs, key, state_w);
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-09 23:29:28 +03:00
|
|
|
input_method_context_grab_modifier(struct weston_keyboard_grab *grab,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
2012-11-18 22:06:45 +04:00
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = grab->keyboard;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
if (!keyboard->input_method_resource)
|
2012-11-18 22:06:45 +04:00
|
|
|
return;
|
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
wl_keyboard_send_modifiers(keyboard->input_method_resource,
|
2012-11-18 22:06:45 +04:00
|
|
|
serial, mods_depressed, mods_latched,
|
|
|
|
mods_locked, group);
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:18:05 +04:00
|
|
|
static void
|
|
|
|
input_method_context_grab_cancel(struct weston_keyboard_grab *grab)
|
|
|
|
{
|
|
|
|
weston_keyboard_end_grab(grab->keyboard);
|
|
|
|
}
|
|
|
|
|
2013-04-18 23:25:39 +04:00
|
|
|
static const struct weston_keyboard_grab_interface input_method_context_grab = {
|
2012-11-18 22:06:45 +04:00
|
|
|
input_method_context_grab_key,
|
|
|
|
input_method_context_grab_modifier,
|
2013-10-26 01:18:05 +04:00
|
|
|
input_method_context_grab_cancel,
|
2012-11-18 22:06:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_grab_keyboard(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-11-18 22:06:45 +04:00
|
|
|
struct wl_resource *cr;
|
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2021-08-16 08:51:45 +03:00
|
|
|
if (!keyboard)
|
|
|
|
return;
|
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
cr = wl_resource_create(client, &wl_keyboard_interface, 1, id);
|
|
|
|
wl_resource_set_implementation(cr, NULL, context, unbind_keyboard);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
|
|
|
context->keyboard = cr;
|
|
|
|
|
2017-06-28 19:41:43 +03:00
|
|
|
weston_keyboard_send_keymap(keyboard, cr);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-04-18 23:25:39 +04:00
|
|
|
if (keyboard->grab != &keyboard->default_grab) {
|
|
|
|
weston_keyboard_end_grab(keyboard);
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
2013-04-18 23:25:39 +04:00
|
|
|
weston_keyboard_start_grab(keyboard, &keyboard->input_method_grab);
|
2013-01-17 00:26:50 +04:00
|
|
|
keyboard->input_method_resource = cr;
|
2012-11-18 22:06:45 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:46 +04:00
|
|
|
static void
|
|
|
|
input_method_context_key(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t key,
|
|
|
|
uint32_t state_w)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-11-18 22:06:46 +04:00
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
|
2017-11-16 19:20:57 +03:00
|
|
|
struct timespec ts;
|
2012-11-18 22:06:46 +04:00
|
|
|
|
2017-11-16 19:20:57 +03:00
|
|
|
timespec_from_msec(&ts, time);
|
|
|
|
|
|
|
|
default_grab->interface->key(default_grab, &ts, key, state_w);
|
2012-11-18 22:06:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_modifiers(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-11-18 22:06:46 +04:00
|
|
|
|
|
|
|
struct weston_seat *seat = context->input_method->seat;
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
|
2012-11-18 22:06:46 +04:00
|
|
|
|
|
|
|
default_grab->interface->modifiers(default_grab,
|
|
|
|
serial, mods_depressed,
|
|
|
|
mods_latched, mods_locked,
|
|
|
|
group);
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
static void
|
|
|
|
input_method_context_language(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
const char *language)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 18:47:15 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_language(context->input->resource,
|
|
|
|
serial, language);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_context_text_direction(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t direction)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2013-04-18 18:47:15 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (context->input)
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_send_text_direction(context->input->resource,
|
|
|
|
serial, direction);
|
2013-04-18 18:47:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
static const struct zwp_input_method_context_v1_interface context_implementation = {
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method_context_destroy,
|
2012-09-10 01:08:43 +04:00
|
|
|
input_method_context_commit_string,
|
|
|
|
input_method_context_preedit_string,
|
2013-01-17 00:26:38 +04:00
|
|
|
input_method_context_preedit_styling,
|
|
|
|
input_method_context_preedit_cursor,
|
2012-09-10 01:08:45 +04:00
|
|
|
input_method_context_delete_surrounding_text,
|
2013-01-31 18:52:23 +04:00
|
|
|
input_method_context_cursor_position,
|
2012-11-18 22:06:43 +04:00
|
|
|
input_method_context_modifiers_map,
|
2012-11-18 22:06:45 +04:00
|
|
|
input_method_context_keysym,
|
2012-11-18 22:06:46 +04:00
|
|
|
input_method_context_grab_keyboard,
|
|
|
|
input_method_context_key,
|
2013-04-18 18:47:15 +04:00
|
|
|
input_method_context_modifiers,
|
|
|
|
input_method_context_language,
|
|
|
|
input_method_context_text_direction
|
2012-06-21 23:52:18 +04:00
|
|
|
};
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
static void
|
|
|
|
destroy_input_method_context(struct wl_resource *resource)
|
|
|
|
{
|
2015-06-09 23:29:28 +03:00
|
|
|
struct input_method_context *context =
|
|
|
|
wl_resource_get_user_data(resource);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
if (context->keyboard)
|
2012-11-18 22:06:45 +04:00
|
|
|
wl_resource_destroy(context->keyboard);
|
|
|
|
|
2015-05-09 01:08:40 +03:00
|
|
|
if (context->input_method && context->input_method->context == context)
|
|
|
|
context->input_method->context = NULL;
|
|
|
|
|
2012-09-10 01:08:32 +04:00
|
|
|
free(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-05-09 01:08:41 +03:00
|
|
|
input_method_context_create(struct text_input *input,
|
2013-04-18 18:47:33 +04:00
|
|
|
struct input_method *input_method)
|
2012-09-10 01:08:32 +04:00
|
|
|
{
|
|
|
|
struct input_method_context *context;
|
2013-06-14 19:07:59 +04:00
|
|
|
struct wl_resource *binding;
|
2012-09-10 01:08:32 +04:00
|
|
|
|
|
|
|
if (!input_method->input_method_binding)
|
|
|
|
return;
|
|
|
|
|
2014-11-21 09:21:57 +03:00
|
|
|
context = zalloc(sizeof *context);
|
2012-09-10 01:08:32 +04:00
|
|
|
if (context == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-06-14 19:07:59 +04:00
|
|
|
binding = input_method->input_method_binding;
|
2013-06-28 05:17:02 +04:00
|
|
|
context->resource =
|
|
|
|
wl_resource_create(wl_resource_get_client(binding),
|
2015-11-17 11:00:30 +03:00
|
|
|
&zwp_input_method_context_v1_interface,
|
|
|
|
1, 0);
|
2013-06-28 05:17:02 +04:00
|
|
|
wl_resource_set_implementation(context->resource,
|
2015-06-09 23:29:28 +03:00
|
|
|
&context_implementation,
|
2013-06-28 05:17:02 +04:00
|
|
|
context, destroy_input_method_context);
|
2012-09-10 01:08:32 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
context->input = input;
|
2012-11-18 22:06:45 +04:00
|
|
|
context->input_method = input_method;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = context;
|
|
|
|
|
|
|
|
|
2015-11-17 11:00:30 +03:00
|
|
|
zwp_input_method_v1_send_activate(binding, context->resource);
|
2012-09-10 01:08:32 +04:00
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:45 +04:00
|
|
|
static void
|
|
|
|
input_method_context_end_keyboard_grab(struct input_method_context *context)
|
|
|
|
{
|
2014-12-08 19:48:29 +03:00
|
|
|
struct weston_keyboard_grab *grab;
|
|
|
|
struct weston_keyboard *keyboard;
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
keyboard = weston_seat_get_keyboard(context->input_method->seat);
|
|
|
|
if (!keyboard)
|
2014-12-08 19:48:29 +03:00
|
|
|
return;
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
grab = &keyboard->input_method_grab;
|
2014-12-08 19:48:29 +03:00
|
|
|
keyboard = grab->keyboard;
|
|
|
|
if (!keyboard)
|
2013-01-17 00:26:50 +04:00
|
|
|
return;
|
|
|
|
|
2014-12-08 19:48:29 +03:00
|
|
|
if (keyboard->grab == grab)
|
|
|
|
weston_keyboard_end_grab(keyboard);
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2013-01-17 00:26:50 +04:00
|
|
|
keyboard->input_method_resource = NULL;
|
|
|
|
}
|
2012-11-18 22:06:45 +04:00
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
static void
|
|
|
|
unbind_input_method(struct wl_resource *resource)
|
|
|
|
{
|
2013-06-14 19:07:59 +04:00
|
|
|
struct input_method *input_method = wl_resource_get_user_data(resource);
|
2012-07-12 00:25:31 +04:00
|
|
|
|
2021-05-07 15:58:10 +03:00
|
|
|
if (!input_method)
|
|
|
|
return;
|
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
input_method->input_method_binding = NULL;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = NULL;
|
2012-07-12 00:25:31 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
static void
|
|
|
|
bind_input_method(struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
2012-07-12 00:25:31 +04:00
|
|
|
struct input_method *input_method = data;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct text_backend *text_backend = input_method->text_backend;
|
2012-07-12 00:25:31 +04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
resource =
|
2015-11-17 11:00:30 +03:00
|
|
|
wl_resource_create(client,
|
|
|
|
&zwp_input_method_v1_interface, 1, id);
|
2012-07-12 00:25:31 +04:00
|
|
|
|
2013-04-18 18:47:31 +04:00
|
|
|
if (input_method->input_method_binding != NULL) {
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_resource_post_error(resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
2013-04-18 18:47:31 +04:00
|
|
|
"interface object already bound");
|
|
|
|
return;
|
|
|
|
}
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2013-04-18 18:47:31 +04:00
|
|
|
if (text_backend->input_method.client != client) {
|
2015-06-09 23:29:28 +03:00
|
|
|
wl_resource_post_error(resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"permission to bind "
|
|
|
|
"input_method denied");
|
2012-07-12 00:25:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
wl_resource_set_implementation(resource, NULL, input_method,
|
|
|
|
unbind_input_method);
|
2013-04-18 18:47:31 +04:00
|
|
|
input_method->input_method_binding = resource;
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_notifier_destroy(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2012-07-22 19:51:42 +04:00
|
|
|
struct input_method *input_method =
|
|
|
|
container_of(listener, struct input_method, destroy_listener);
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (input_method->input)
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(input_method);
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2021-05-07 15:58:10 +03:00
|
|
|
if (input_method->input_method_binding)
|
|
|
|
wl_resource_set_user_data(input_method->input_method_binding, NULL);
|
|
|
|
|
2013-07-09 03:03:57 +04:00
|
|
|
wl_global_destroy(input_method->input_method_global);
|
2013-07-24 19:57:32 +04:00
|
|
|
wl_list_remove(&input_method->destroy_listener.link);
|
2021-05-07 15:58:10 +03:00
|
|
|
input_method->seat->input_method = NULL;
|
2012-09-10 01:08:31 +04:00
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
free(input_method);
|
|
|
|
}
|
|
|
|
|
2012-08-10 18:47:23 +04:00
|
|
|
static void
|
|
|
|
handle_keyboard_focus(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2013-04-18 23:25:39 +04:00
|
|
|
struct weston_keyboard *keyboard = data;
|
2012-08-10 18:47:23 +04:00
|
|
|
struct input_method *input_method =
|
2015-06-09 23:29:28 +03:00
|
|
|
container_of(listener, struct input_method,
|
|
|
|
keyboard_focus_listener);
|
2013-05-08 17:54:37 +04:00
|
|
|
struct weston_surface *surface = keyboard->focus;
|
2012-08-10 18:47:23 +04:00
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (!input_method->input)
|
2012-08-10 18:47:23 +04:00
|
|
|
return;
|
|
|
|
|
2015-05-09 01:08:41 +03:00
|
|
|
if (!surface || input_method->input->surface != surface)
|
2015-05-09 01:08:40 +03:00
|
|
|
deactivate_input_method(input_method);
|
2012-08-10 18:47:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_method_init_seat(struct weston_seat *seat)
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
|
|
|
|
|
2012-08-10 18:47:23 +04:00
|
|
|
if (seat->input_method->focus_listener_initialized)
|
|
|
|
return;
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
if (keyboard) {
|
2015-06-09 23:29:28 +03:00
|
|
|
seat->input_method->keyboard_focus_listener.notify =
|
|
|
|
handle_keyboard_focus;
|
2015-08-01 00:55:32 +03:00
|
|
|
wl_signal_add(&keyboard->focus_signal,
|
2015-06-09 23:29:28 +03:00
|
|
|
&seat->input_method->keyboard_focus_listener);
|
2015-08-01 00:55:32 +03:00
|
|
|
keyboard->input_method_grab.interface =
|
2015-06-09 23:29:28 +03:00
|
|
|
&input_method_context_grab;
|
2012-08-10 18:47:23 +04:00
|
|
|
}
|
|
|
|
|
2015-07-15 21:00:32 +03:00
|
|
|
seat->input_method->focus_listener_initialized = true;
|
2012-08-10 18:47:23 +04:00
|
|
|
}
|
|
|
|
|
2022-04-19 08:41:02 +03:00
|
|
|
static void launch_input_method(void *data);
|
2013-05-14 20:09:31 +04:00
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
2015-06-25 23:49:49 +03:00
|
|
|
respawn_input_method_process(struct text_backend *text_backend)
|
2012-11-18 22:06:42 +04:00
|
|
|
{
|
2017-11-16 19:21:01 +03:00
|
|
|
struct timespec time;
|
|
|
|
int64_t tdiff;
|
2013-05-14 20:09:31 +04:00
|
|
|
|
|
|
|
/* if input_method dies more than 5 times in 10 seconds, give up */
|
2017-11-16 19:21:01 +03:00
|
|
|
weston_compositor_get_time(&time);
|
|
|
|
tdiff = timespec_sub_to_msec(&time,
|
|
|
|
&text_backend->input_method.deathstamp);
|
|
|
|
if (tdiff > 10000) {
|
2013-05-14 20:09:31 +04:00
|
|
|
text_backend->input_method.deathstamp = time;
|
|
|
|
text_backend->input_method.deathcount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_backend->input_method.deathcount++;
|
|
|
|
if (text_backend->input_method.deathcount > 5) {
|
2015-06-25 23:49:49 +03:00
|
|
|
weston_log("input_method disconnected, giving up.\n");
|
2013-05-14 20:09:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-25 23:49:49 +03:00
|
|
|
weston_log("input_method disconnected, respawning...\n");
|
2013-05-14 20:09:31 +04:00
|
|
|
launch_input_method(text_backend);
|
2012-11-18 22:06:42 +04:00
|
|
|
}
|
|
|
|
|
2015-06-25 23:49:49 +03:00
|
|
|
static void
|
|
|
|
input_method_client_notifier(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct text_backend *text_backend;
|
|
|
|
|
|
|
|
text_backend = container_of(listener, struct text_backend,
|
|
|
|
client_listener);
|
|
|
|
|
|
|
|
text_backend->input_method.client = NULL;
|
|
|
|
respawn_input_method_process(text_backend);
|
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
2022-04-19 08:41:02 +03:00
|
|
|
launch_input_method(void *data)
|
2012-11-18 22:06:42 +04:00
|
|
|
{
|
2022-04-19 08:41:02 +03:00
|
|
|
struct text_backend *text_backend = data;
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
if (!text_backend->input_method.path)
|
|
|
|
return;
|
2015-06-09 23:28:06 +03:00
|
|
|
|
|
|
|
if (strcmp(text_backend->input_method.path, "") == 0)
|
|
|
|
return;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2021-09-15 07:54:29 +03:00
|
|
|
if (text_backend->input_method.overlay_keyboard)
|
|
|
|
setenv("WESTON_KEYBOARD_SURFACE_TYPE", "overlay", 1);
|
|
|
|
|
2015-06-09 23:29:28 +03:00
|
|
|
text_backend->input_method.client =
|
2015-06-25 23:49:49 +03:00
|
|
|
weston_client_start(text_backend->compositor,
|
|
|
|
text_backend->input_method.path);
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2015-06-25 23:49:49 +03:00
|
|
|
if (!text_backend->input_method.client) {
|
2015-06-09 23:29:28 +03:00
|
|
|
weston_log("not able to start %s\n",
|
|
|
|
text_backend->input_method.path);
|
2015-06-25 23:49:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_backend->client_listener.notify = input_method_client_notifier;
|
|
|
|
wl_client_add_destroy_listener(text_backend->input_method.client,
|
|
|
|
&text_backend->client_listener);
|
2012-11-18 22:06:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-06-11 00:15:30 +03:00
|
|
|
text_backend_seat_created(struct text_backend *text_backend,
|
|
|
|
struct weston_seat *seat)
|
2012-06-21 23:52:18 +04:00
|
|
|
{
|
|
|
|
struct input_method *input_method;
|
2012-11-18 22:06:42 +04:00
|
|
|
struct weston_compositor *ec = seat->compositor;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2014-11-21 09:21:57 +03:00
|
|
|
input_method = zalloc(sizeof *input_method);
|
|
|
|
if (input_method == NULL)
|
|
|
|
return;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-09-10 01:08:31 +04:00
|
|
|
input_method->seat = seat;
|
2015-05-09 01:08:41 +03:00
|
|
|
input_method->input = NULL;
|
2015-07-15 21:00:32 +03:00
|
|
|
input_method->focus_listener_initialized = false;
|
2012-09-10 01:08:32 +04:00
|
|
|
input_method->context = NULL;
|
2012-11-18 22:06:42 +04:00
|
|
|
input_method->text_backend = text_backend;
|
2012-06-21 23:52:18 +04:00
|
|
|
|
2012-07-12 00:25:31 +04:00
|
|
|
input_method->input_method_global =
|
2015-11-17 11:00:30 +03:00
|
|
|
wl_global_create(ec->wl_display,
|
|
|
|
&zwp_input_method_v1_interface, 1,
|
2013-07-09 03:03:57 +04:00
|
|
|
input_method, bind_input_method);
|
2012-07-12 00:25:31 +04:00
|
|
|
|
2012-06-21 23:52:18 +04:00
|
|
|
input_method->destroy_listener.notify = input_method_notifier_destroy;
|
2013-05-07 06:27:40 +04:00
|
|
|
wl_signal_add(&seat->destroy_signal, &input_method->destroy_listener);
|
2012-08-10 18:47:22 +04:00
|
|
|
|
|
|
|
seat->input_method = input_method;
|
2012-11-18 22:06:42 +04:00
|
|
|
}
|
|
|
|
|
2015-06-11 00:15:30 +03:00
|
|
|
static void
|
|
|
|
handle_seat_created(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct weston_seat *seat = data;
|
|
|
|
struct text_backend *text_backend =
|
|
|
|
container_of(listener, struct text_backend,
|
|
|
|
seat_created_listener);
|
|
|
|
|
|
|
|
text_backend_seat_created(text_backend, seat);
|
|
|
|
}
|
|
|
|
|
2012-11-18 22:06:42 +04:00
|
|
|
static void
|
|
|
|
text_backend_configuration(struct text_backend *text_backend)
|
|
|
|
{
|
2016-06-02 21:48:11 +03:00
|
|
|
struct weston_config *config = wet_get_config(text_backend->compositor);
|
2013-05-24 05:45:51 +04:00
|
|
|
struct weston_config_section *section;
|
2014-08-21 20:32:38 +04:00
|
|
|
char *client;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2016-06-02 21:48:11 +03:00
|
|
|
section = weston_config_get_section(config,
|
2013-05-24 05:45:51 +04:00
|
|
|
"input-method", NULL, NULL);
|
2018-12-15 16:51:57 +03:00
|
|
|
client = wet_get_libexec_path("weston-keyboard");
|
2013-05-24 05:45:51 +04:00
|
|
|
weston_config_section_get_string(section, "path",
|
|
|
|
&text_backend->input_method.path,
|
2014-08-21 20:32:38 +04:00
|
|
|
client);
|
2021-09-15 07:54:29 +03:00
|
|
|
weston_config_section_get_bool(section, "overlay-keyboard",
|
|
|
|
&text_backend->input_method.overlay_keyboard,
|
|
|
|
false);
|
2014-08-21 20:32:38 +04:00
|
|
|
free(client);
|
2012-11-18 22:06:42 +04:00
|
|
|
}
|
|
|
|
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 16:09:17 +03:00
|
|
|
WL_EXPORT void
|
|
|
|
text_backend_destroy(struct text_backend *text_backend)
|
2012-11-18 22:06:42 +04:00
|
|
|
{
|
2018-08-07 16:35:02 +03:00
|
|
|
wl_list_remove(&text_backend->seat_created_listener.link);
|
|
|
|
|
2015-06-25 23:49:49 +03:00
|
|
|
if (text_backend->input_method.client) {
|
|
|
|
/* disable respawn */
|
|
|
|
wl_list_remove(&text_backend->client_listener.link);
|
2012-11-18 22:06:42 +04:00
|
|
|
wl_client_destroy(text_backend->input_method.client);
|
2015-06-25 23:49:49 +03:00
|
|
|
}
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
free(text_backend->input_method.path);
|
|
|
|
free(text_backend);
|
2012-06-21 23:52:18 +04:00
|
|
|
}
|
2012-08-10 18:47:23 +04:00
|
|
|
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 16:09:17 +03:00
|
|
|
WL_EXPORT struct text_backend *
|
2012-11-18 22:06:42 +04:00
|
|
|
text_backend_init(struct weston_compositor *ec)
|
|
|
|
{
|
|
|
|
struct text_backend *text_backend;
|
2015-06-11 00:15:30 +03:00
|
|
|
struct weston_seat *seat;
|
2022-04-19 08:41:02 +03:00
|
|
|
struct wl_event_loop *loop;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2014-11-21 09:21:57 +03:00
|
|
|
text_backend = zalloc(sizeof(*text_backend));
|
|
|
|
if (text_backend == NULL)
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 16:09:17 +03:00
|
|
|
return NULL;
|
2012-11-18 22:06:42 +04:00
|
|
|
|
|
|
|
text_backend->compositor = ec;
|
|
|
|
|
2015-06-11 00:15:30 +03:00
|
|
|
text_backend_configuration(text_backend);
|
|
|
|
|
|
|
|
wl_list_for_each(seat, &ec->seat_list, link)
|
|
|
|
text_backend_seat_created(text_backend, seat);
|
2012-11-18 22:06:42 +04:00
|
|
|
text_backend->seat_created_listener.notify = handle_seat_created;
|
|
|
|
wl_signal_add(&ec->seat_created_signal,
|
|
|
|
&text_backend->seat_created_listener);
|
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_manager_create(ec);
|
2012-11-18 22:06:42 +04:00
|
|
|
|
2022-04-19 08:41:02 +03:00
|
|
|
loop = wl_display_get_event_loop(ec->wl_display);
|
|
|
|
wl_event_loop_add_idle(loop, launch_input_method, text_backend);
|
2015-06-25 23:49:47 +03:00
|
|
|
|
text_backend: make destructor call explicit
We used to rely on the order in which the
weston_compositor::destroy_signal callbacks happened, to not access
freed memory. Don't know when, but this broke at least with ivi-shell,
which caused crashes in random places on compositor shutdown.
Valgrind found the following:
Invalid write of size 8
at 0xC2EDC69: unbind_input_panel (input-panel-ivi.c:340)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea360 is 208 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0D7: wl_list_remove (wayland-util.c:57)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea370 is 224 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Invalid write of size 8
at 0x4E3E0E7: wl_list_remove (wayland-util.c:58)
by 0xC2EDEE9: destroy_input_panel_surface (input-panel-ivi.c:191)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3BC7B: wl_resource_destroy (wayland-server.c:550)
by 0x40DB8B: wl_signal_emit (wayland-server-core.h:264)
by 0x40DB8B: weston_surface_destroy (compositor.c:1883)
by 0x40DB8B: weston_surface_destroy (compositor.c:1873)
by 0x4E3B6BB: destroy_resource (wayland-server.c:537)
by 0x4E3E085: for_each_helper.isra.0 (wayland-util.c:359)
by 0x4E3E60D: wl_map_for_each (wayland-util.c:365)
by 0x4E3BEC7: wl_client_destroy (wayland-server.c:675)
by 0x4182F2: text_backend_notifier_destroy (text-backend.c:1047)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Address 0x67ea368 is 216 bytes inside a block of size 232 free'd
at 0x4C2A6BC: free (vg_replace_malloc.c:473)
by 0x4084FB: wl_signal_emit (wayland-server-core.h:264)
by 0x4084FB: main (compositor.c:5465)
Looking at the first of these, unbind_input_panel() gets called when the
text-backend destroys its helper client which has bound to input_panel
interface. This happens after the shell's destroy_signal callback has
been called, so the shell has already been freed.
The other two errors come from
wl_list_remove(&input_panel_surface->link);
which has gone stale when the shell was destroyed
(shell->input_panel.surfaces list).
Rather than creating even more destroy listeners and hooking them up in
spaghetti, modify text-backend to not hook up to the compositor destroy
signal. Instead, make it the text_backend_init() callers' responsibility
to also call text_backend_destroy() appropriately, before the shell goes
away.
This fixed all the above Valgrind errors, and avoid a crash with
ivi-shell when exiting Weston.
Also using desktop-shell exhibited similar Valgrind errors which are
fixed by this patch, but those didn't happen to cause any crashes AFAIK.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-06-24 16:09:17 +03:00
|
|
|
return text_backend;
|
2012-11-18 22:06:42 +04:00
|
|
|
}
|