Implement text cursor position protocol.

Here we create a new client/compositor interface in weston to allow
clients to report their x/y cursor position to the compositor. These
values are then used to center the zoom area on this point. This
is useful for everyone, especially people who are visually impaired.
This commit is contained in:
Scott Moreau
2012-05-27 14:25:02 -06:00
committed by Kristian Høgsberg
parent d64bdf4755
commit 7a1b32a198
12 changed files with 219 additions and 10 deletions
+2
View File
@@ -10,6 +10,8 @@ libtoytoolkit.a
resizor
screenshooter-client-protocol.h
screenshooter-protocol.c
text-cursor-position-client-protocol.h
text-cursor-position-protocol.c
simple-egl
simple-shm
simple-touch
+5 -1
View File
@@ -57,7 +57,9 @@ noinst_LIBRARIES = libtoytoolkit.a
libtoytoolkit_a_SOURCES = \
window.c \
window.h
window.h \
text-cursor-position-protocol.c \
text-cursor-position-client-protocol.h
toolkit_libs = \
libtoytoolkit.a \
@@ -106,6 +108,8 @@ weston_tablet_shell_LDADD = $(toolkit_libs)
BUILT_SOURCES = \
screenshooter-client-protocol.h \
screenshooter-protocol.c \
text-cursor-position-client-protocol.h \
text-cursor-position-protocol.c \
desktop-shell-client-protocol.h \
desktop-shell-protocol.c \
tablet-shell-client-protocol.h \
+13 -1
View File
@@ -372,6 +372,7 @@ struct terminal {
int data_pitch, attr_pitch; /* The width in bytes of a line */
int width, height, start, row, column;
int saved_row, saved_column;
int send_cursor_position;
int fd, master;
uint32_t modifiers;
char escape[MAX_ESCAPE+1];
@@ -926,7 +927,7 @@ redraw_handler(struct widget *widget, void *data)
struct rectangle allocation;
cairo_t *cr;
int top_margin, side_margin;
int row, col;
int row, col, cursor_x, cursor_y;
union utf8_char *p_row;
union decoded_attr attr;
int text_x, text_y;
@@ -1022,6 +1023,16 @@ redraw_handler(struct widget *widget, void *data)
cairo_paint(cr);
cairo_destroy(cr);
cairo_surface_destroy(surface);
if (terminal->send_cursor_position) {
cursor_x = side_margin + allocation.x +
terminal->column * extents.max_x_advance;
cursor_y = top_margin + allocation.y +
terminal->row * extents.height;
window_set_text_cursor_position(terminal->window,
cursor_x, cursor_y);
terminal->send_cursor_position = 0;
}
}
static void
@@ -1029,6 +1040,7 @@ terminal_write(struct terminal *terminal, const char *data, size_t length)
{
if (write(terminal->master, data, length) < 0)
abort();
terminal->send_cursor_position = 1;
}
static void
+26
View File
@@ -61,6 +61,7 @@
#include <linux/input.h>
#include <wayland-client.h>
#include "../shared/cairo-util.h"
#include "text-cursor-position-client-protocol.h"
#include "window.h"
@@ -72,6 +73,7 @@ struct display {
struct wl_shell *shell;
struct wl_shm *shm;
struct wl_data_device_manager *data_device_manager;
struct text_cursor_position *text_cursor_position;
EGLDisplay dpy;
EGLConfig argb_config;
EGLContext argb_ctx;
@@ -149,6 +151,7 @@ struct window {
int resize_needed;
int type;
int transparent;
int send_cursor_position;
struct input *keyboard_device;
enum window_buffer_type buffer_type;
@@ -1823,6 +1826,9 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
if (!window || window->keyboard_device != input)
return;
if (state)
window->send_cursor_position = 1;
num_syms = xkb_key_get_syms(d->xkb.state, code, &syms);
xkb_state_update_key(d->xkb.state, code,
state ? XKB_KEY_DOWN : XKB_KEY_UP);
@@ -2609,6 +2615,21 @@ window_get_title(struct window *window)
return window->title;
}
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;
if (!window->send_cursor_position || !text_cursor_position)
return;
text_cursor_position_notify(text_cursor_position,
window->surface, x, y);
window->send_cursor_position = 0;
}
void
window_damage(struct window *window, int32_t x, int32_t y,
int32_t width, int32_t height)
@@ -2695,6 +2716,7 @@ window_create_internal(struct display *display, struct window *parent)
window->allocation.height = 0;
window->saved_allocation = window->allocation;
window->transparent = 1;
window->send_cursor_position = 0;
window->type = TYPE_NONE;
window->input_region = NULL;
window->opaque_region = NULL;
@@ -3097,6 +3119,10 @@ display_handle_global(struct wl_display *display, uint32_t id,
d->data_device_manager =
wl_display_bind(display, id,
&wl_data_device_manager_interface);
} else if (strcmp(interface, "text_cursor_position") == 0) {
d->text_cursor_position =
wl_display_bind(display, id,
&text_cursor_position_interface);
}
}
+3
View File
@@ -307,6 +307,9 @@ window_set_title(struct window *window, const char *title);
const char *
window_get_title(struct window *window);
void
window_set_text_cursor_position(struct window *window, int32_t x, int32_t y);
int
widget_set_tooltip(struct widget *parent, char *entry, float x, float y);