{
cairo_text_extents_t extents;
int i;
+ double d;
+
+ if (layout->num_glyphs == 0)
+ return 0;
cairo_scaled_font_glyph_extents(layout->font,
layout->glyphs, layout->num_glyphs,
&extents);
- for (i = 1; i < layout->num_glyphs; i++) {
- if (layout->glyphs[i].x >= x) {
- return i - 1;
- }
+ if (x < 0)
+ return 0;
+
+ for (i = 0; i < layout->num_glyphs - 1; ++i) {
+ d = layout->glyphs[i + 1].x - layout->glyphs[i].x;
+ if (x < layout->glyphs[i].x + d/2)
+ return i;
}
- if (x >= layout->glyphs[layout->num_glyphs - 1].x && x < extents.width)
+ d = extents.width - layout->glyphs[layout->num_glyphs - 1].x;
+ if (x < layout->glyphs[layout->num_glyphs - 1].x + d/2)
return layout->num_glyphs - 1;
return layout->num_glyphs;
{
struct text_entry *entry = data;
- if (index > strlen(text)) {
+ if (index > strlen(text))
fprintf(stderr, "Invalid cursor index %d\n", index);
- index = strlen(text);
- }
text_entry_delete_selected_text(entry);
text_entry_insert_at_cursor(entry, text);
}
static void
-global_handler(struct wl_display *display, uint32_t id,
+global_handler(struct display *display, uint32_t name,
const char *interface, uint32_t version, void *data)
{
struct editor *editor = data;
if (!strcmp(interface, "text_model_factory")) {
- editor->text_model_factory = wl_display_bind(display, id,
- &text_model_factory_interface);
+ editor->text_model_factory =
+ display_bind(display, name,
+ &text_model_factory_interface, 1);
}
}
fprintf(stderr, "failed to create display: %m\n");
return -1;
}
- wl_display_add_global_listener(display_get_display(editor.display),
- global_handler, &editor);
+ display_set_user_data(editor.display, &editor);
+ display_set_global_handler(editor.display, global_handler);
editor.window = window_create(editor.display);
editor.widget = frame_create(editor.window, &editor);