text: Assign text_model to a wl_seat
Add a wl_seat argument to the activate and deactivate requests of text_method. On activation a text_model gets assigned to the input_method of the wl_seat specified in the activate request.
This commit is contained in:
committed by
Kristian Høgsberg
parent
de3b6a15c0
commit
e829adc514
+20
-8
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
struct text_entry {
|
struct text_entry {
|
||||||
struct widget *widget;
|
struct widget *widget;
|
||||||
|
struct window *window;
|
||||||
char *text;
|
char *text;
|
||||||
int active;
|
int active;
|
||||||
struct rectangle allocation;
|
struct rectangle allocation;
|
||||||
@@ -152,6 +153,7 @@ text_entry_create(struct editor *editor, const char *text)
|
|||||||
surface = window_get_wl_surface(editor->window);
|
surface = window_get_wl_surface(editor->window);
|
||||||
|
|
||||||
entry->widget = editor->widget;
|
entry->widget = editor->widget;
|
||||||
|
entry->window = editor->window;
|
||||||
entry->text = strdup(text);
|
entry->text = strdup(text);
|
||||||
entry->active = 0;
|
entry->active = 0;
|
||||||
entry->model = text_model_factory_create_text_model(editor->text_model_factory, surface);
|
entry->model = text_model_factory_create_text_model(editor->text_model_factory, surface);
|
||||||
@@ -271,15 +273,22 @@ rectangle_contains(struct rectangle *rectangle, int32_t x, int32_t y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_entry_activate(struct text_entry *entry)
|
text_entry_activate(struct text_entry *entry,
|
||||||
|
struct wl_seat *seat)
|
||||||
{
|
{
|
||||||
text_model_activate(entry->model);
|
struct wl_surface *surface = window_get_wl_surface(entry->window);
|
||||||
|
|
||||||
|
text_model_activate(entry->model,
|
||||||
|
seat,
|
||||||
|
surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_entry_deactivate(struct text_entry *entry)
|
text_entry_deactivate(struct text_entry *entry,
|
||||||
|
struct wl_seat *seat)
|
||||||
{
|
{
|
||||||
text_model_deactivate(entry->model);
|
text_model_deactivate(entry->model,
|
||||||
|
seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -291,6 +300,7 @@ button_handler(struct widget *widget,
|
|||||||
struct editor *editor = data;
|
struct editor *editor = data;
|
||||||
struct rectangle allocation;
|
struct rectangle allocation;
|
||||||
int32_t x, y;
|
int32_t x, y;
|
||||||
|
struct wl_seat *seat;
|
||||||
|
|
||||||
if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) {
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) {
|
||||||
return;
|
return;
|
||||||
@@ -306,13 +316,15 @@ button_handler(struct widget *widget,
|
|||||||
int32_t activate_editor = rectangle_contains(&editor->editor->allocation, x, y);
|
int32_t activate_editor = rectangle_contains(&editor->editor->allocation, x, y);
|
||||||
assert(!(activate_entry && activate_editor));
|
assert(!(activate_entry && activate_editor));
|
||||||
|
|
||||||
|
seat = input_get_seat(input);
|
||||||
|
|
||||||
if (activate_entry) {
|
if (activate_entry) {
|
||||||
text_entry_activate(editor->entry);
|
text_entry_activate(editor->entry, seat);
|
||||||
} else if (activate_editor) {
|
} else if (activate_editor) {
|
||||||
text_entry_activate(editor->editor);
|
text_entry_activate(editor->editor, seat);
|
||||||
} else {
|
} else {
|
||||||
text_entry_deactivate(editor->entry);
|
text_entry_deactivate(editor->entry, seat);
|
||||||
text_entry_deactivate(editor->editor);
|
text_entry_deactivate(editor->editor, seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
widget_schedule_redraw(widget);
|
widget_schedule_redraw(widget);
|
||||||
|
|||||||
+7
-2
@@ -6,8 +6,13 @@
|
|||||||
<request name="set_cursor_index">
|
<request name="set_cursor_index">
|
||||||
<arg name="index" type="uint"/>
|
<arg name="index" type="uint"/>
|
||||||
</request>
|
</request>
|
||||||
<request name="activate"/>
|
<request name="activate">
|
||||||
<request name="deactivate"/>
|
<arg name="seat" type="object" interface="wl_seat"/>
|
||||||
|
<arg name="surface" type="object" interface="wl_surface"/>
|
||||||
|
</request>
|
||||||
|
<request name="deactivate">
|
||||||
|
<arg name="seat" type="object" interface="wl_seat"/>
|
||||||
|
</request>
|
||||||
<request name="set_selected_text">
|
<request name="set_selected_text">
|
||||||
<arg name="text" type="string"/>
|
<arg name="text" type="string"/>
|
||||||
<arg name="index" type="int"/>
|
<arg name="index" type="int"/>
|
||||||
|
|||||||
+1
-1
@@ -2625,6 +2625,7 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
|
|||||||
&seat->new_drag_icon_listener);
|
&seat->new_drag_icon_listener);
|
||||||
|
|
||||||
clipboard_create(seat);
|
clipboard_create(seat);
|
||||||
|
input_method_create(ec, seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
@@ -3173,7 +3174,6 @@ weston_compositor_init(struct weston_compositor *ec,
|
|||||||
|
|
||||||
screenshooter_create(ec);
|
screenshooter_create(ec);
|
||||||
text_cursor_position_notifier_create(ec);
|
text_cursor_position_notifier_create(ec);
|
||||||
input_method_create(ec);
|
|
||||||
|
|
||||||
wl_data_device_manager_init(ec->wl_display);
|
wl_data_device_manager_init(ec->wl_display);
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -47,6 +47,7 @@ struct weston_surface;
|
|||||||
struct shell_surface;
|
struct shell_surface;
|
||||||
struct weston_seat;
|
struct weston_seat;
|
||||||
struct weston_output;
|
struct weston_output;
|
||||||
|
struct input_method;
|
||||||
|
|
||||||
enum weston_keyboard_modifier {
|
enum weston_keyboard_modifier {
|
||||||
MODIFIER_CTRL = (1 << 0),
|
MODIFIER_CTRL = (1 << 0),
|
||||||
@@ -235,6 +236,8 @@ struct weston_seat {
|
|||||||
struct xkb_state *state;
|
struct xkb_state *state;
|
||||||
enum weston_led leds;
|
enum weston_led leds;
|
||||||
} xkb_state;
|
} xkb_state;
|
||||||
|
|
||||||
|
struct input_method *input_method;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct weston_shader {
|
struct weston_shader {
|
||||||
@@ -739,7 +742,8 @@ void
|
|||||||
text_cursor_position_notifier_create(struct weston_compositor *ec);
|
text_cursor_position_notifier_create(struct weston_compositor *ec);
|
||||||
|
|
||||||
void
|
void
|
||||||
input_method_create(struct weston_compositor *ec);
|
input_method_create(struct weston_compositor *ec,
|
||||||
|
struct weston_seat *seat);
|
||||||
|
|
||||||
struct weston_process;
|
struct weston_process;
|
||||||
typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
|
typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
|
||||||
|
|||||||
+42
-28
@@ -30,9 +30,9 @@ struct input_method;
|
|||||||
struct text_model {
|
struct text_model {
|
||||||
struct wl_resource resource;
|
struct wl_resource resource;
|
||||||
|
|
||||||
struct wl_list link;
|
struct weston_compositor *ec;
|
||||||
|
|
||||||
struct input_method *input_method;
|
struct wl_list input_methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct input_method {
|
struct input_method {
|
||||||
@@ -42,17 +42,20 @@ struct input_method {
|
|||||||
struct wl_listener destroy_listener;
|
struct wl_listener destroy_listener;
|
||||||
|
|
||||||
struct weston_compositor *ec;
|
struct weston_compositor *ec;
|
||||||
struct wl_list models;
|
struct text_model *model;
|
||||||
struct text_model *active_model;
|
|
||||||
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
deactivate_text_model(struct text_model *text_model)
|
deactivate_text_model(struct text_model *text_model,
|
||||||
|
struct input_method *input_method)
|
||||||
{
|
{
|
||||||
struct weston_compositor *ec = text_model->input_method->ec;
|
struct weston_compositor *ec = text_model->ec;
|
||||||
|
|
||||||
if (text_model->input_method->active_model == text_model) {
|
if (input_method->model == text_model) {
|
||||||
text_model->input_method->active_model = NULL;
|
wl_list_remove(&input_method->link);
|
||||||
|
input_method->model = NULL;
|
||||||
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
wl_signal_emit(&ec->hide_input_panel_signal, ec);
|
||||||
text_model_send_deactivated(&text_model->resource);
|
text_model_send_deactivated(&text_model->resource);
|
||||||
}
|
}
|
||||||
@@ -63,10 +66,11 @@ destroy_text_model(struct wl_resource *resource)
|
|||||||
{
|
{
|
||||||
struct text_model *text_model =
|
struct text_model *text_model =
|
||||||
container_of(resource, struct text_model, resource);
|
container_of(resource, struct text_model, resource);
|
||||||
|
struct input_method *input_method, *next;
|
||||||
|
|
||||||
deactivate_text_model(text_model);
|
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link)
|
||||||
|
deactivate_text_model(text_model, input_method);
|
||||||
|
|
||||||
wl_list_remove(&text_model->link);
|
|
||||||
free(text_model);
|
free(text_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,19 +90,25 @@ text_model_set_cursor_index(struct wl_client *client,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
text_model_activate(struct wl_client *client,
|
text_model_activate(struct wl_client *client,
|
||||||
struct wl_resource *resource)
|
struct wl_resource *resource,
|
||||||
|
struct wl_resource *seat,
|
||||||
|
struct wl_resource *surface)
|
||||||
{
|
{
|
||||||
struct text_model *text_model = resource->data;
|
struct text_model *text_model = resource->data;
|
||||||
struct weston_compositor *ec = text_model->input_method->ec;
|
struct weston_seat *weston_seat = seat->data;
|
||||||
|
struct text_model *old = weston_seat->input_method->model;
|
||||||
|
struct weston_compositor *ec = text_model->ec;
|
||||||
|
|
||||||
if (text_model->input_method->active_model) {
|
if (old == text_model)
|
||||||
if (text_model->input_method->active_model == text_model)
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
deactivate_text_model(text_model->input_method->active_model);
|
if (old) {
|
||||||
|
deactivate_text_model(old,
|
||||||
|
weston_seat->input_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
text_model->input_method->active_model = text_model;
|
weston_seat->input_method->model = text_model;
|
||||||
|
wl_list_insert(&text_model->input_methods, &weston_seat->input_method->link);
|
||||||
|
|
||||||
wl_signal_emit(&ec->show_input_panel_signal, ec);
|
wl_signal_emit(&ec->show_input_panel_signal, ec);
|
||||||
|
|
||||||
@@ -107,11 +117,14 @@ text_model_activate(struct wl_client *client,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
text_model_deactivate(struct wl_client *client,
|
text_model_deactivate(struct wl_client *client,
|
||||||
struct wl_resource *resource)
|
struct wl_resource *resource,
|
||||||
|
struct wl_resource *seat)
|
||||||
{
|
{
|
||||||
struct text_model *text_model = resource->data;
|
struct text_model *text_model = resource->data;
|
||||||
|
struct weston_seat *weston_seat = seat->data;
|
||||||
|
|
||||||
deactivate_text_model(text_model);
|
deactivate_text_model(text_model,
|
||||||
|
weston_seat->input_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -144,7 +157,7 @@ text_model_set_content_type(struct wl_client *client,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
struct text_model_interface text_model_implementation = {
|
static const struct text_model_interface text_model_implementation = {
|
||||||
text_model_set_surrounding_text,
|
text_model_set_surrounding_text,
|
||||||
text_model_set_cursor_index,
|
text_model_set_cursor_index,
|
||||||
text_model_activate,
|
text_model_activate,
|
||||||
@@ -173,11 +186,11 @@ static void text_model_factory_create_text_model(struct wl_client *client,
|
|||||||
(void (**)(void)) &text_model_implementation;
|
(void (**)(void)) &text_model_implementation;
|
||||||
text_model->resource.data = text_model;
|
text_model->resource.data = text_model;
|
||||||
|
|
||||||
text_model->input_method = input_method;
|
text_model->ec = input_method->ec;
|
||||||
|
|
||||||
wl_client_add_resource(client, &text_model->resource);
|
wl_client_add_resource(client, &text_model->resource);
|
||||||
|
|
||||||
wl_list_insert(&input_method->models, &text_model->link);
|
wl_list_init(&text_model->input_methods);
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct text_model_factory_interface text_model_factory_implementation = {
|
static const struct text_model_factory_interface text_model_factory_implementation = {
|
||||||
@@ -207,8 +220,8 @@ input_method_commit_string(struct wl_client *client,
|
|||||||
{
|
{
|
||||||
struct input_method *input_method = resource->data;
|
struct input_method *input_method = resource->data;
|
||||||
|
|
||||||
if (input_method->active_model) {
|
if (input_method->model) {
|
||||||
text_model_send_commit_string(&input_method->active_model->resource, text, index);
|
text_model_send_commit_string(&input_method->model->resource, text, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,16 +276,15 @@ input_method_notifier_destroy(struct wl_listener *listener, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
input_method_create(struct weston_compositor *ec)
|
input_method_create(struct weston_compositor *ec,
|
||||||
|
struct weston_seat *seat)
|
||||||
{
|
{
|
||||||
struct input_method *input_method;
|
struct input_method *input_method;
|
||||||
|
|
||||||
input_method = calloc(1, sizeof *input_method);
|
input_method = calloc(1, sizeof *input_method);
|
||||||
|
|
||||||
input_method->ec = ec;
|
input_method->ec = ec;
|
||||||
input_method->active_model = NULL;
|
input_method->model = NULL;
|
||||||
|
|
||||||
wl_list_init(&input_method->models);
|
|
||||||
|
|
||||||
input_method->input_method_global =
|
input_method->input_method_global =
|
||||||
wl_display_add_global(ec->wl_display,
|
wl_display_add_global(ec->wl_display,
|
||||||
@@ -286,4 +298,6 @@ input_method_create(struct weston_compositor *ec)
|
|||||||
|
|
||||||
input_method->destroy_listener.notify = input_method_notifier_destroy;
|
input_method->destroy_listener.notify = input_method_notifier_destroy;
|
||||||
wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);
|
wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);
|
||||||
|
|
||||||
|
seat->input_method = input_method;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user