2012-08-21 20:28:49 +04:00
|
|
|
/*
|
2012-09-10 01:08:30 +04:00
|
|
|
* Copyright © 2012 Intel Corporation
|
2012-08-21 20:28:49 +04:00
|
|
|
*
|
2015-06-12 01:39:40 +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-08-21 20:28:49 +04:00
|
|
|
*
|
2015-06-12 01:39:40 +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-08-21 20:28:49 +04:00
|
|
|
*/
|
|
|
|
|
2014-04-07 15:40:35 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-08-21 20:28:49 +04:00
|
|
|
#include <string.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2012-12-12 08:03:56 +04:00
|
|
|
#include <stdio.h>
|
2014-11-20 04:18:34 +03:00
|
|
|
|
2012-12-12 08:03:56 +04:00
|
|
|
#include "weston-test-client-helper.h"
|
2015-11-17 11:00:29 +03:00
|
|
|
#include "text-input-unstable-v1-client-protocol.h"
|
2012-08-21 20:28:49 +04:00
|
|
|
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_state {
|
2012-12-12 08:03:56 +04:00
|
|
|
int activated;
|
|
|
|
int deactivated;
|
2012-08-21 20:28:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_commit_string(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
uint32_t serial,
|
|
|
|
const char *text)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_preedit_string(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
uint32_t serial,
|
2012-12-12 08:03:56 +04:00
|
|
|
const char *text,
|
2013-02-19 22:26:55 +04:00
|
|
|
const char *commit)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_delete_surrounding_text(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2012-12-12 08:03:56 +04:00
|
|
|
int32_t index,
|
|
|
|
uint32_t length)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-19 22:26:55 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_cursor_position(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
int32_t index,
|
|
|
|
int32_t anchor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-12 08:03:56 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_preedit_styling(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
uint32_t index,
|
|
|
|
uint32_t length,
|
|
|
|
uint32_t style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_preedit_cursor(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
int32_t index)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_modifiers_map(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2012-12-12 08:03:56 +04:00
|
|
|
struct wl_array *map)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_keysym(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2012-12-12 08:03:56 +04:00
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t sym,
|
|
|
|
uint32_t state,
|
|
|
|
uint32_t modifiers)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_enter(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2012-12-12 08:03:56 +04:00
|
|
|
struct wl_surface *surface)
|
|
|
|
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_state *state = data;
|
2012-08-21 20:28:49 +04:00
|
|
|
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("%s\n", __FUNCTION__);
|
2012-08-21 20:28:49 +04:00
|
|
|
|
2012-12-12 08:03:56 +04:00
|
|
|
state->activated += 1;
|
2012-08-21 20:28:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_leave(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input)
|
2012-08-21 20:28:49 +04:00
|
|
|
{
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_state *state = data;
|
2012-12-12 08:03:56 +04:00
|
|
|
|
|
|
|
state->deactivated += 1;
|
2012-08-21 20:28:49 +04:00
|
|
|
}
|
|
|
|
|
2013-02-19 22:26:55 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_input_panel_state(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-02-19 22:26:55 +04:00
|
|
|
uint32_t state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:47:15 +04:00
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_language(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-04-18 18:47:15 +04:00
|
|
|
uint32_t serial,
|
|
|
|
const char *language)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_text_direction(void *data,
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_v1 *text_input,
|
2013-04-18 18:47:15 +04:00
|
|
|
uint32_t serial,
|
|
|
|
uint32_t direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:29 +03:00
|
|
|
static const struct zwp_text_input_v1_listener text_input_listener = {
|
2013-04-18 18:47:24 +04:00
|
|
|
text_input_enter,
|
|
|
|
text_input_leave,
|
|
|
|
text_input_modifiers_map,
|
|
|
|
text_input_input_panel_state,
|
|
|
|
text_input_preedit_string,
|
|
|
|
text_input_preedit_styling,
|
|
|
|
text_input_preedit_cursor,
|
|
|
|
text_input_commit_string,
|
|
|
|
text_input_cursor_position,
|
|
|
|
text_input_delete_surrounding_text,
|
|
|
|
text_input_keysym,
|
|
|
|
text_input_language,
|
|
|
|
text_input_text_direction
|
2012-12-12 08:03:56 +04:00
|
|
|
};
|
|
|
|
|
2012-08-21 20:28:49 +04:00
|
|
|
TEST(text_test)
|
|
|
|
{
|
2012-12-12 08:03:56 +04:00
|
|
|
struct client *client;
|
|
|
|
struct global *global;
|
2015-11-17 11:00:29 +03:00
|
|
|
struct zwp_text_input_manager_v1 *factory;
|
|
|
|
struct zwp_text_input_v1 *text_input;
|
2013-04-18 18:47:24 +04:00
|
|
|
struct text_input_state state;
|
2012-12-12 08:03:56 +04:00
|
|
|
|
2015-03-26 13:56:10 +03:00
|
|
|
client = create_client_and_test_surface(100, 100, 100, 100);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(client);
|
|
|
|
|
|
|
|
factory = NULL;
|
|
|
|
wl_list_for_each(global, &client->global_list, link) {
|
2015-11-17 11:00:29 +03:00
|
|
|
if (strcmp(global->interface, "zwp_text_input_manager_v1") == 0)
|
2012-12-12 08:03:56 +04:00
|
|
|
factory = wl_registry_bind(client->wl_registry,
|
|
|
|
global->name,
|
2015-11-17 11:00:29 +03:00
|
|
|
&zwp_text_input_manager_v1_interface, 1);
|
2012-12-12 08:03:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(factory);
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof state);
|
2015-11-17 11:00:29 +03:00
|
|
|
text_input = zwp_text_input_manager_v1_create_text_input(factory);
|
|
|
|
zwp_text_input_v1_add_listener(text_input,
|
|
|
|
&text_input_listener,
|
|
|
|
&state);
|
2012-12-12 08:03:56 +04:00
|
|
|
|
|
|
|
/* Make sure our test surface has keyboard focus. */
|
2015-02-24 18:32:14 +03:00
|
|
|
weston_test_activate_surface(client->test->weston_test,
|
2012-12-12 08:03:56 +04:00
|
|
|
client->surface->wl_surface);
|
2012-12-12 16:26:41 +04:00
|
|
|
client_roundtrip(client);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(client->input->keyboard->focus == client->surface);
|
|
|
|
|
|
|
|
/* Activate test model and make sure we get enter event. */
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_activate(text_input, client->input->wl_seat,
|
|
|
|
client->surface->wl_surface);
|
2012-12-12 16:26:41 +04:00
|
|
|
client_roundtrip(client);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(state.activated == 1 && state.deactivated == 0);
|
|
|
|
|
|
|
|
/* Deactivate test model and make sure we get leave event. */
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_deactivate(text_input, client->input->wl_seat);
|
2012-12-12 16:26:41 +04:00
|
|
|
client_roundtrip(client);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(state.activated == 1 && state.deactivated == 1);
|
|
|
|
|
|
|
|
/* Activate test model again. */
|
2015-11-17 11:00:29 +03:00
|
|
|
zwp_text_input_v1_activate(text_input, client->input->wl_seat,
|
|
|
|
client->surface->wl_surface);
|
2012-12-12 16:26:41 +04:00
|
|
|
client_roundtrip(client);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(state.activated == 2 && state.deactivated == 1);
|
|
|
|
|
|
|
|
/* Take keyboard focus away and verify we get leave event. */
|
2015-02-24 18:32:14 +03:00
|
|
|
weston_test_activate_surface(client->test->weston_test, NULL);
|
2012-12-12 16:26:41 +04:00
|
|
|
client_roundtrip(client);
|
2012-12-12 08:03:56 +04:00
|
|
|
assert(state.activated == 2 && state.deactivated == 2);
|
2012-08-21 20:28:49 +04:00
|
|
|
}
|