blob: 6f466369c392cdbc0474cd7adfafa8624c8557bd [file] [log] [blame]
Scott Moreau7a1b32a2012-05-27 14:25:02 -06001/*
2 * Copyright © 2011 Intel Corporation
3 * Copyright © 2012 Scott Moreau
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#include <stdlib.h>
25
26#include "compositor.h"
27#include "text-cursor-position-server-protocol.h"
28
29struct text_cursor_position {
30 struct wl_object base;
31 struct weston_compositor *ec;
32 struct wl_global *global;
33 struct wl_listener destroy_listener;
34};
35
36static void
37text_cursor_position_notify(struct wl_client *client,
38 struct wl_resource *resource,
39 struct wl_resource *surface_resource,
40 uint32_t x, uint32_t y)
41{
42 weston_text_cursor_position_notify((struct weston_surface *) surface_resource, x, y);
43}
44
45struct text_cursor_position_interface text_cursor_position_implementation = {
46 text_cursor_position_notify
47};
48
49static void
50bind_text_cursor_position(struct wl_client *client,
51 void *data, uint32_t version, uint32_t id)
52{
53 wl_client_add_object(client, &text_cursor_position_interface,
54 &text_cursor_position_implementation, id, data);
55}
56
57static void
58text_cursor_position_notifier_destroy(struct wl_listener *listener, void *data)
59{
60 struct text_cursor_position *text_cursor_position =
61 container_of(listener, struct text_cursor_position, destroy_listener);
62
63 wl_display_remove_global(text_cursor_position->ec->wl_display, text_cursor_position->global);
64 free(text_cursor_position);
65}
66
67void
68text_cursor_position_notifier_create(struct weston_compositor *ec)
69{
70 struct text_cursor_position *text_cursor_position;
71
72 text_cursor_position = malloc(sizeof *text_cursor_position);
73 if (text_cursor_position == NULL)
74 return;
75
76 text_cursor_position->base.interface = &text_cursor_position_interface;
77 text_cursor_position->base.implementation =
78 (void(**)(void)) &text_cursor_position_implementation;
79 text_cursor_position->ec = ec;
80
81 text_cursor_position->global = wl_display_add_global(ec->wl_display,
82 &text_cursor_position_interface,
83 text_cursor_position, bind_text_cursor_position);
84
85 text_cursor_position->destroy_listener.notify = text_cursor_position_notifier_destroy;
86 wl_signal_add(&ec->destroy_signal, &text_cursor_position->destroy_listener);
87}