[PATCH weston 1/4 v2] Implement text cursor position protocol.

Scott Moreau oreaus at gmail.com
Tue May 22 09:43:56 PDT 2012


>
> Shouldn't we only update position when the user actually presses a
> key?  What if you're dumping a lot of data to the terminal?
>

Yes, you are right. I know about this but never fixed it.


>
> >  void
> > +window_set_text_cursor_position(struct window *window, int32_t x,
> int32_t y)
> > +{
> > +     struct text_cursor_position *text_cursor_position =
> window->display->text_cursor_position;
>
> Break the line after '='?
>

Yes.


>
> > +     text_cursor_position_notify(text_cursor_position, window->surface,
> x, y);
> > +}
>
> Let's check for window->display->text_cursor_position == NULL so it
> will work even if the compositor doesn't have that extension.
>

Ok.


>
> >
> >  WL_EXPORT void
> > +weston_text_cursor_position_notify(struct weston_surface *surface,
> > +                                             int32_t x, int32_t y)
> > +{
> > +     struct weston_output *output;
> > +     int32_t surface_x, surface_y;
> > +     int32_t cur_pos_x, cur_pos_y;
> > +
> > +     weston_surface_to_global(surface, 0, 0, &surface_x, &surface_y);
> > +
> > +     cur_pos_x = surface_x + x;
> > +     cur_pos_y = surface_y + y;
>
> This should just be
>
>  weston_surface_to_global(surface, x, y, &surface_x, &surface_y);
>
> weston_surface_to_global() takes a coordinate in surface space (which
> x, y is) and translates that into global space.
>

Please see v3 of this patch. v2 does not handle transformed surfaces
correctly.


>
> > +     wl_list_for_each(output, &surface->compositor->output_list, link)
> > +             if (output->zoom.active &&
> > +                 pixman_region32_contains_point(&output->region,
> > +                                                     cur_pos_x,
> cur_pos_y, NULL))
> > +                     weston_output_update_zoom(output, cur_pos_x * 256,
> cur_pos_y * 256);
>
> Use wl_fixed_from_int here.  Alternatively, just make the protocol
> take wl_fixed_t for x and y (and change the client to send wl_fixed_t
> x and y), and then use weston_surface_to_global_fixed().
>

Ah, I did not realize this function exists.


>
> > +}
> > +
> > +WL_EXPORT void
> >  weston_output_update_zoom(struct weston_output *output, wl_fixed_t fx,
> wl_fixed_t fy)
> >  {
> >       float ratio;
> > @@ -2641,6 +2661,7 @@ weston_compositor_init(struct weston_compositor
> *ec, struct wl_display *display)
> >       weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
> >
> >       screenshooter_create(ec);
> > +     text_cursor_position_notifier_create(ec);
> >
> >       ec->ping_handler = NULL;
> >
> > diff --git a/src/compositor.h b/src/compositor.h
> > index 7af423d..59a97a7 100644
> > --- a/src/compositor.h
> > +++ b/src/compositor.h
> > @@ -554,6 +554,8 @@ weston_compositor_shutdown(struct weston_compositor
> *ec);
> >  void
> >  weston_output_update_zoom(struct weston_output *output, int x, int y);
> >  void
> > +weston_text_cursor_position_notify(struct weston_surface *surface, int
> x, int y);
> > +void
> >  weston_output_update_matrix(struct weston_output *output);
> >  void
> >  weston_output_move(struct weston_output *output, int x, int y);
> > @@ -589,6 +591,9 @@ tty_activate_vt(struct tty *tty, int vt);
> >  void
> >  screenshooter_create(struct weston_compositor *ec);
> >
> > +void
> > +text_cursor_position_notifier_create(struct weston_compositor *ec);
> > +
> >  struct weston_process;
> >  typedef void (*weston_process_cleanup_func_t)(struct weston_process
> *process,
> >                                           int status);
> > diff --git a/src/text-cursor-position.c b/src/text-cursor-position.c
> > new file mode 100644
> > index 0000000..2c07dca
> > --- /dev/null
> > +++ b/src/text-cursor-position.c
> > @@ -0,0 +1,86 @@
> > +/*
> > + * Copyright © 2012 Scott Moreau
> > + *
> > + * Permission to use, copy, modify, distribute, and sell this software
> and
> > + * its documentation for any purpose is hereby granted without fee,
> provided
> > + * that the above copyright notice appear in all copies and that both
> that
> > + * copyright notice and this permission notice appear in supporting
> > + * documentation, and that the name of the copyright holders not be
> used in
> > + * advertising or publicity pertaining to distribution of the software
> > + * without specific, written prior permission.  The copyright holders
> make
> > + * no representations about the suitability of this software for any
> > + * purpose.  It is provided "as is" without express or implied warranty.
> > + *
> > + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> > + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
> > + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
> > + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
> > + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
> > + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
> > + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> > + */
> > +
> > +#include <stdlib.h>
> > +
> > +#include "compositor.h"
> > +#include "text-cursor-position-server-protocol.h"
> > +
> > +struct text_cursor_position {
> > +     struct wl_object base;
> > +     struct weston_compositor *ec;
> > +     struct wl_global *global;
> > +     struct wl_listener destroy_listener;
> > +};
> > +
> > +static void
> > +text_cursor_position_notify(struct wl_client *client,
> > +                         struct wl_resource *resource,
> > +                         struct wl_resource *surface_resource,
> > +                         uint32_t x, uint32_t y)
> > +{
> > +     weston_text_cursor_position_notify((struct weston_surface *)
> surface_resource, x, y);
> > +}
> > +
> > +struct text_cursor_position_interface
> text_cursor_position_implementation = {
> > +     text_cursor_position_notify
> > +};
> > +
> > +static void
> > +bind_text_cursor_position(struct wl_client *client,
> > +          void *data, uint32_t version, uint32_t id)
> > +{
> > +     wl_client_add_object(client, &text_cursor_position_interface,
> > +                          &text_cursor_position_implementation, id,
> data);
> > +}
> > +
> > +static void
> > +text_cursor_position_notifier_destroy(struct wl_listener *listener,
> void *data)
> > +{
> > +     struct text_cursor_position *text_cursor_position =
> > +             container_of(listener, struct text_cursor_position,
> destroy_listener);
> > +
> > +     wl_display_remove_global(text_cursor_position->ec->wl_display,
> text_cursor_position->global);
> > +     free(text_cursor_position);
> > +}
> > +
> > +void
> > +text_cursor_position_notifier_create(struct weston_compositor *ec)
> > +{
> > +     struct text_cursor_position *text_cursor_position;
> > +
> > +     text_cursor_position = malloc(sizeof *text_cursor_position);
> > +     if (text_cursor_position == NULL)
> > +             return;
> > +
> > +     text_cursor_position->base.interface =
> &text_cursor_position_interface;
> > +     text_cursor_position->base.implementation =
> > +             (void(**)(void)) &text_cursor_position_implementation;
> > +     text_cursor_position->ec = ec;
> > +
> > +     text_cursor_position->global =
> wl_display_add_global(ec->wl_display,
> > +
> &text_cursor_position_interface,
> > +                                             text_cursor_position,
> bind_text_cursor_position);
> > +
> > +     text_cursor_position->destroy_listener.notify =
> text_cursor_position_notifier_destroy;
> > +     wl_signal_add(&ec->destroy_signal,
> &text_cursor_position->destroy_listener);
> > +}
>
>
Please see v3 of this patch.


Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20120522/ac8e75d0/attachment-0001.htm>


More information about the wayland-devel mailing list