[RFC weston 08/12] text-backend: Change resources to wl_resource pointers
Jason Ekstrand
jason at jlekstrand.net
Fri Jun 14 08:07:59 PDT 2013
Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
src/text-backend.c | 148 +++++++++++++++++++++++++++--------------------------
1 file changed, 76 insertions(+), 72 deletions(-)
diff --git a/src/text-backend.c b/src/text-backend.c
index 27afdff..55d4485 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -37,7 +37,7 @@ struct input_method_context;
struct text_backend;
struct text_input {
- struct wl_resource resource;
+ struct wl_resource *resource;
struct weston_compositor *ec;
@@ -77,7 +77,7 @@ struct input_method {
};
struct input_method_context {
- struct wl_resource resource;
+ struct wl_resource *resource;
struct text_input *model;
struct input_method *input_method;
@@ -120,22 +120,21 @@ deactivate_text_input(struct text_input *text_input,
if (input_method->context && input_method->input_method_binding) {
input_method_context_end_keyboard_grab(input_method->context);
wl_input_method_send_deactivate(input_method->input_method_binding,
- &input_method->context->resource);
+ input_method->context->resource);
}
wl_list_remove(&input_method->link);
input_method->model = NULL;
input_method->context = NULL;
wl_signal_emit(&ec->hide_input_panel_signal, ec);
- wl_text_input_send_leave(&text_input->resource);
+ wl_text_input_send_leave(text_input->resource);
}
}
static void
destroy_text_input(struct wl_resource *resource)
{
- struct text_input *text_input =
- container_of(resource, struct text_input, resource);
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link)
@@ -151,13 +150,13 @@ text_input_set_surrounding_text(struct wl_client *client,
uint32_t cursor,
uint32_t anchor)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_surrounding_text(&input_method->context->resource,
+ wl_input_method_context_send_surrounding_text(input_method->context->resource,
text,
cursor,
anchor);
@@ -170,7 +169,7 @@ text_input_activate(struct wl_client *client,
struct wl_resource *seat,
struct wl_resource *surface)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_seat *weston_seat = seat->data;
struct input_method *input_method = weston_seat->input_method;
struct text_input *old = weston_seat->input_method->model;
@@ -197,7 +196,7 @@ text_input_activate(struct wl_client *client,
wl_signal_emit(&ec->update_input_panel_signal, &text_input->cursor_rectangle);
}
- wl_text_input_send_enter(&text_input->resource, text_input->surface->resource);
+ wl_text_input_send_enter(text_input->resource, text_input->surface->resource);
}
static void
@@ -205,7 +204,7 @@ text_input_deactivate(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *seat)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_seat *weston_seat = seat->data;
deactivate_text_input(text_input,
@@ -216,13 +215,13 @@ static void
text_input_reset(struct wl_client *client,
struct wl_resource *resource)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_reset(&input_method->context->resource);
+ wl_input_method_context_send_reset(input_method->context->resource);
}
}
@@ -234,7 +233,7 @@ text_input_set_cursor_rectangle(struct wl_client *client,
int32_t width,
int32_t height)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_compositor *ec = text_input->ec;
text_input->cursor_rectangle.x1 = x;
@@ -251,13 +250,13 @@ text_input_set_content_type(struct wl_client *client,
uint32_t hint,
uint32_t purpose)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_content_type(&input_method->context->resource, hint, purpose);
+ wl_input_method_context_send_content_type(input_method->context->resource, hint, purpose);
}
}
@@ -267,13 +266,13 @@ text_input_invoke_action(struct wl_client *client,
uint32_t button,
uint32_t index)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_invoke_action(&input_method->context->resource, button, index);
+ wl_input_method_context_send_invoke_action(input_method->context->resource, button, index);
}
}
@@ -282,13 +281,13 @@ text_input_commit_state(struct wl_client *client,
struct wl_resource *resource,
uint32_t serial)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_commit_state(&input_method->context->resource, serial);
+ wl_input_method_context_send_commit_state(input_method->context->resource, serial);
}
}
@@ -296,7 +295,7 @@ static void
text_input_show_input_panel(struct wl_client *client,
struct wl_resource *resource)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_compositor *ec = text_input->ec;
text_input->input_panel_visible = 1;
@@ -311,7 +310,7 @@ static void
text_input_hide_input_panel(struct wl_client *client,
struct wl_resource *resource)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_compositor *ec = text_input->ec;
text_input->input_panel_visible = 0;
@@ -325,13 +324,13 @@ text_input_set_preferred_language(struct wl_client *client,
struct wl_resource *resource,
const char *language)
{
- struct text_input *text_input = resource->data;
+ struct text_input *text_input = wl_resource_get_user_data(resource);
struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context)
continue;
- wl_input_method_context_send_preferred_language(&input_method->context->resource,
+ wl_input_method_context_send_preferred_language(input_method->context->resource,
language);
}
}
@@ -354,24 +353,20 @@ static void text_input_manager_create_text_input(struct wl_client *client,
struct wl_resource *resource,
uint32_t id)
{
- struct text_input_manager *text_input_manager = resource->data;
+ struct text_input_manager *text_input_manager = wl_resource_get_user_data(resource);
struct text_input *text_input;
text_input = calloc(1, sizeof *text_input);
- text_input->resource.object.id = id;
- text_input->resource.object.interface = &wl_text_input_interface;
- text_input->resource.object.implementation =
- (void (**)(void)) &text_input_implementation;
-
- text_input->resource.data = text_input;
- text_input->resource.destroy = destroy_text_input;
+ text_input->resource = wl_client_add_object(client,
+ &wl_text_input_interface,
+ &text_input_implementation,
+ id, text_input);
+ wl_resource_set_destructor(text_input->resource, destroy_text_input);
text_input->ec = text_input_manager->ec;
wl_list_init(&text_input->input_methods);
-
- wl_client_add_resource(client, &text_input->resource);
};
static const struct wl_text_input_manager_interface text_input_manager_implementation = {
@@ -436,9 +431,10 @@ input_method_context_commit_string(struct wl_client *client,
uint32_t serial,
const char *text)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_commit_string(&context->model->resource, serial, text);
+ wl_text_input_send_commit_string(context->model->resource, serial, text);
}
static void
@@ -448,9 +444,10 @@ input_method_context_preedit_string(struct wl_client *client,
const char *text,
const char *commit)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_preedit_string(&context->model->resource, serial, text, commit);
+ wl_text_input_send_preedit_string(context->model->resource, serial, text, commit);
}
static void
@@ -460,9 +457,10 @@ input_method_context_preedit_styling(struct wl_client *client,
uint32_t length,
uint32_t style)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_preedit_styling(&context->model->resource, index, length, style);
+ wl_text_input_send_preedit_styling(context->model->resource, index, length, style);
}
static void
@@ -470,9 +468,10 @@ input_method_context_preedit_cursor(struct wl_client *client,
struct wl_resource *resource,
int32_t cursor)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_preedit_cursor(&context->model->resource, cursor);
+ wl_text_input_send_preedit_cursor(context->model->resource, cursor);
}
static void
@@ -481,9 +480,10 @@ input_method_context_delete_surrounding_text(struct wl_client *client,
int32_t index,
uint32_t length)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_delete_surrounding_text(&context->model->resource, index, length);
+ wl_text_input_send_delete_surrounding_text(context->model->resource, index, length);
}
static void
@@ -492,9 +492,10 @@ input_method_context_cursor_position(struct wl_client *client,
int32_t index,
int32_t anchor)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_cursor_position(&context->model->resource, index, anchor);
+ wl_text_input_send_cursor_position(context->model->resource, index, anchor);
}
static void
@@ -502,9 +503,10 @@ input_method_context_modifiers_map(struct wl_client *client,
struct wl_resource *resource,
struct wl_array *map)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_modifiers_map(&context->model->resource, map);
+ wl_text_input_send_modifiers_map(context->model->resource, map);
}
static void
@@ -516,16 +518,18 @@ input_method_context_keysym(struct wl_client *client,
uint32_t state,
uint32_t modifiers)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
- wl_text_input_send_keysym(&context->model->resource, serial, time,
+ wl_text_input_send_keysym(context->model->resource, serial, time,
sym, state, modifiers);
}
static void
unbind_keyboard(struct wl_resource *resource)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context =
+ wl_resource_get_user_data(resource);
input_method_context_end_keyboard_grab(context);
context->keyboard = NULL;
@@ -544,7 +548,7 @@ input_method_context_grab_key(struct weston_keyboard_grab *grab,
if (!keyboard->input_method_resource)
return;
- display = wl_client_get_display(keyboard->input_method_resource->client);
+ display = wl_client_get_display(wl_resource_get_client(keyboard->input_method_resource));
serial = wl_display_next_serial(display);
wl_keyboard_send_key(keyboard->input_method_resource,
serial, time, key, state_w);
@@ -575,14 +579,14 @@ input_method_context_grab_keyboard(struct wl_client *client,
struct wl_resource *resource,
uint32_t id)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
struct wl_resource *cr;
struct weston_seat *seat = context->input_method->seat;
struct weston_keyboard *keyboard = seat->keyboard;
cr = wl_client_add_object(client, &wl_keyboard_interface,
NULL, id, context);
- cr->destroy = unbind_keyboard;
+ wl_resource_set_destructor(cr, unbind_keyboard);
context->keyboard = cr;
@@ -605,7 +609,7 @@ input_method_context_key(struct wl_client *client,
uint32_t key,
uint32_t state_w)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
struct weston_seat *seat = context->input_method->seat;
struct weston_keyboard *keyboard = seat->keyboard;
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
@@ -622,7 +626,7 @@ input_method_context_modifiers(struct wl_client *client,
uint32_t mods_locked,
uint32_t group)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
struct weston_seat *seat = context->input_method->seat;
struct weston_keyboard *keyboard = seat->keyboard;
@@ -640,9 +644,9 @@ input_method_context_language(struct wl_client *client,
uint32_t serial,
const char *language)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
- wl_text_input_send_language(&context->model->resource, serial, language);
+ wl_text_input_send_language(context->model->resource, serial, language);
}
static void
@@ -651,9 +655,9 @@ input_method_context_text_direction(struct wl_client *client,
uint32_t serial,
uint32_t direction)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
- wl_text_input_send_text_direction(&context->model->resource, serial, direction);
+ wl_text_input_send_text_direction(context->model->resource, serial, direction);
}
@@ -677,7 +681,7 @@ static const struct wl_input_method_context_interface input_method_context_imple
static void
destroy_input_method_context(struct wl_resource *resource)
{
- struct input_method_context *context = resource->data;
+ struct input_method_context *context = wl_resource_get_user_data(resource);
if (context->keyboard) {
wl_resource_destroy(context->keyboard);
@@ -691,6 +695,7 @@ input_method_context_create(struct text_input *model,
struct input_method *input_method)
{
struct input_method_context *context;
+ struct wl_resource *binding;
if (!input_method->input_method_binding)
return;
@@ -699,21 +704,20 @@ input_method_context_create(struct text_input *model,
if (context == NULL)
return;
- context->resource.destroy = destroy_input_method_context;
- context->resource.object.id = 0;
- context->resource.object.interface = &wl_input_method_context_interface;
- context->resource.object.implementation =
- (void (**)(void)) &input_method_context_implementation;
- context->resource.data = context;
- wl_signal_init(&context->resource.destroy_signal);
+ binding = input_method->input_method_binding;
+ context->resource = wl_client_new_object(wl_resource_get_client(binding),
+ &wl_input_method_context_interface,
+ &input_method_context_implementation,
+ context);
+ wl_resource_set_destructor(context->resource,
+ destroy_input_method_context);
context->model = model;
context->input_method = input_method;
input_method->context = context;
- wl_client_add_resource(input_method->input_method_binding->client, &context->resource);
- wl_input_method_send_activate(input_method->input_method_binding, &context->resource);
+ wl_input_method_send_activate(binding, context->resource);
}
static void
@@ -735,7 +739,7 @@ input_method_context_end_keyboard_grab(struct input_method_context *context)
static void
unbind_input_method(struct wl_resource *resource)
{
- struct input_method *input_method = resource->data;
+ struct input_method *input_method = wl_resource_get_user_data(resource);
struct text_backend *text_backend = input_method->text_backend;
input_method->input_method_binding = NULL;
@@ -774,7 +778,7 @@ bind_input_method(struct wl_client *client,
return;
}
- resource->destroy = unbind_input_method;
+ wl_resource_set_destructor(resource, unbind_input_method);
input_method->input_method_binding = resource;
text_backend->input_method.binding = resource;
--
1.8.1.4
More information about the wayland-devel
mailing list