|
|
|
@ -59,7 +59,7 @@ struct text_entry { |
|
|
|
|
uint32_t delete_index; |
|
|
|
|
uint32_t delete_length; |
|
|
|
|
} pending_commit; |
|
|
|
|
struct text_input *text_input; |
|
|
|
|
struct wl_text_input *text_input; |
|
|
|
|
PangoLayout *layout; |
|
|
|
|
struct { |
|
|
|
|
xkb_mod_mask_t shift_mask; |
|
|
|
@ -72,7 +72,7 @@ struct text_entry { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct editor { |
|
|
|
|
struct text_input_manager *text_input_manager; |
|
|
|
|
struct wl_text_input_manager *text_input_manager; |
|
|
|
|
struct display *display; |
|
|
|
|
struct window *window; |
|
|
|
|
struct widget *widget; |
|
|
|
@ -146,7 +146,7 @@ static void text_entry_update(struct text_entry *entry); |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_commit_string(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t serial, |
|
|
|
|
const char *text) |
|
|
|
|
{ |
|
|
|
@ -179,7 +179,7 @@ text_input_commit_string(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_preedit_string(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t serial, |
|
|
|
|
const char *text, |
|
|
|
|
const char *commit) |
|
|
|
@ -195,13 +195,13 @@ text_input_preedit_string(void *data, |
|
|
|
|
entry->preedit_info.attr_list = NULL; |
|
|
|
|
|
|
|
|
|
text_entry_update(entry); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widget_schedule_redraw(entry->widget); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_delete_surrounding_text(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
int32_t index, |
|
|
|
|
uint32_t length) |
|
|
|
|
{ |
|
|
|
@ -228,7 +228,7 @@ text_input_delete_surrounding_text(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_cursor_position(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
int32_t index, |
|
|
|
|
int32_t anchor) |
|
|
|
|
{ |
|
|
|
@ -240,7 +240,7 @@ text_input_cursor_position(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_preedit_styling(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t index, |
|
|
|
|
uint32_t length, |
|
|
|
|
uint32_t style) |
|
|
|
@ -253,24 +253,24 @@ text_input_preedit_styling(void *data, |
|
|
|
|
entry->preedit_info.attr_list = pango_attr_list_new(); |
|
|
|
|
|
|
|
|
|
switch (style) { |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_DEFAULT: |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_UNDERLINE: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_DEFAULT: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_UNDERLINE: |
|
|
|
|
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_INCORRECT: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_INCORRECT: |
|
|
|
|
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR); |
|
|
|
|
attr2 = pango_attr_underline_color_new(65535, 0, 0); |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_SELECTION: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_SELECTION: |
|
|
|
|
attr1 = pango_attr_background_new(0.3 * 65535, 0.3 * 65535, 65535); |
|
|
|
|
attr2 = pango_attr_foreground_new(65535, 65535, 65535); |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT: |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_ACTIVE: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_ACTIVE: |
|
|
|
|
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); |
|
|
|
|
attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD); |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_PREEDIT_STYLE_INACTIVE: |
|
|
|
|
case WL_TEXT_INPUT_PREEDIT_STYLE_INACTIVE: |
|
|
|
|
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); |
|
|
|
|
attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535); |
|
|
|
|
break; |
|
|
|
@ -291,7 +291,7 @@ text_input_preedit_styling(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_preedit_cursor(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
int32_t index) |
|
|
|
|
{ |
|
|
|
|
struct text_entry *entry = data; |
|
|
|
@ -301,7 +301,7 @@ text_input_preedit_cursor(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_modifiers_map(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
struct wl_array *map) |
|
|
|
|
{ |
|
|
|
|
struct text_entry *entry = data; |
|
|
|
@ -311,7 +311,7 @@ text_input_modifiers_map(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_keysym(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t serial, |
|
|
|
|
uint32_t time, |
|
|
|
|
uint32_t key, |
|
|
|
@ -383,7 +383,7 @@ text_input_keysym(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_enter(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
struct wl_surface *surface) |
|
|
|
|
{ |
|
|
|
|
struct text_entry *entry = data; |
|
|
|
@ -401,7 +401,7 @@ text_input_enter(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_leave(void *data, |
|
|
|
|
struct text_input *text_input) |
|
|
|
|
struct wl_text_input *text_input) |
|
|
|
|
{ |
|
|
|
|
struct text_entry *entry = data; |
|
|
|
|
|
|
|
|
@ -409,21 +409,21 @@ text_input_leave(void *data, |
|
|
|
|
|
|
|
|
|
entry->active = 0; |
|
|
|
|
|
|
|
|
|
text_input_hide_input_panel(text_input); |
|
|
|
|
wl_text_input_hide_input_panel(text_input); |
|
|
|
|
|
|
|
|
|
widget_schedule_redraw(entry->widget); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_input_panel_state(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t state) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_language(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t serial, |
|
|
|
|
const char *language) |
|
|
|
|
{ |
|
|
|
@ -432,7 +432,7 @@ text_input_language(void *data, |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_input_text_direction(void *data, |
|
|
|
|
struct text_input *text_input, |
|
|
|
|
struct wl_text_input *text_input, |
|
|
|
|
uint32_t serial, |
|
|
|
|
uint32_t direction) |
|
|
|
|
{ |
|
|
|
@ -442,21 +442,21 @@ text_input_text_direction(void *data, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (direction) { |
|
|
|
|
case TEXT_INPUT_TEXT_DIRECTION_LTR: |
|
|
|
|
case WL_TEXT_INPUT_TEXT_DIRECTION_LTR: |
|
|
|
|
pango_direction = PANGO_DIRECTION_LTR; |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_TEXT_DIRECTION_RTL: |
|
|
|
|
case WL_TEXT_INPUT_TEXT_DIRECTION_RTL: |
|
|
|
|
pango_direction = PANGO_DIRECTION_RTL; |
|
|
|
|
break; |
|
|
|
|
case TEXT_INPUT_TEXT_DIRECTION_AUTO: |
|
|
|
|
case WL_TEXT_INPUT_TEXT_DIRECTION_AUTO: |
|
|
|
|
default: |
|
|
|
|
pango_direction = PANGO_DIRECTION_NEUTRAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pango_context_set_base_dir(context, pango_direction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const struct text_input_listener text_input_listener = { |
|
|
|
|
static const struct wl_text_input_listener text_input_listener = { |
|
|
|
|
text_input_enter, |
|
|
|
|
text_input_leave, |
|
|
|
|
text_input_modifiers_map, |
|
|
|
@ -485,8 +485,8 @@ text_entry_create(struct editor *editor, const char *text) |
|
|
|
|
entry->active = 0; |
|
|
|
|
entry->cursor = strlen(text); |
|
|
|
|
entry->anchor = entry->cursor; |
|
|
|
|
entry->text_input = text_input_manager_create_text_input(editor->text_input_manager); |
|
|
|
|
text_input_add_listener(entry->text_input, &text_input_listener, entry); |
|
|
|
|
entry->text_input = wl_text_input_manager_create_text_input(editor->text_input_manager); |
|
|
|
|
wl_text_input_add_listener(entry->text_input, &text_input_listener, entry); |
|
|
|
|
|
|
|
|
|
widget_set_redraw_handler(entry->widget, text_entry_redraw_handler); |
|
|
|
|
widget_set_button_handler(entry->widget, text_entry_button_handler); |
|
|
|
@ -498,7 +498,7 @@ static void |
|
|
|
|
text_entry_destroy(struct text_entry *entry) |
|
|
|
|
{ |
|
|
|
|
widget_destroy(entry->widget); |
|
|
|
|
text_input_destroy(entry->text_input); |
|
|
|
|
wl_text_input_destroy(entry->text_input); |
|
|
|
|
g_clear_object(&entry->layout); |
|
|
|
|
free(entry->text); |
|
|
|
|
free(entry); |
|
|
|
@ -566,25 +566,25 @@ text_entry_activate(struct text_entry *entry, |
|
|
|
|
struct wl_surface *surface = window_get_wl_surface(entry->window); |
|
|
|
|
|
|
|
|
|
if (entry->click_to_show && entry->active) { |
|
|
|
|
text_input_show_input_panel(entry->text_input); |
|
|
|
|
wl_text_input_show_input_panel(entry->text_input); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!entry->click_to_show) |
|
|
|
|
text_input_show_input_panel(entry->text_input); |
|
|
|
|
wl_text_input_show_input_panel(entry->text_input); |
|
|
|
|
|
|
|
|
|
text_input_activate(entry->text_input, |
|
|
|
|
seat, |
|
|
|
|
surface); |
|
|
|
|
wl_text_input_activate(entry->text_input, |
|
|
|
|
seat, |
|
|
|
|
surface); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
text_entry_deactivate(struct text_entry *entry, |
|
|
|
|
struct wl_seat *seat) |
|
|
|
|
{ |
|
|
|
|
text_input_deactivate(entry->text_input, |
|
|
|
|
seat); |
|
|
|
|
wl_text_input_deactivate(entry->text_input, |
|
|
|
|
seat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
@ -593,7 +593,7 @@ text_entry_update_layout(struct text_entry *entry) |
|
|
|
|
char *text; |
|
|
|
|
PangoAttrList *attr_list; |
|
|
|
|
|
|
|
|
|
assert(((unsigned int)entry->cursor) <= strlen(entry->text) + |
|
|
|
|
assert((entry->cursor) <= strlen(entry->text) + |
|
|
|
|
(entry->preedit.text ? strlen(entry->preedit.text) : 0)); |
|
|
|
|
|
|
|
|
|
if (entry->preedit.text) { |
|
|
|
@ -655,24 +655,24 @@ text_entry_update(struct text_entry *entry) |
|
|
|
|
{ |
|
|
|
|
struct rectangle cursor_rectangle; |
|
|
|
|
|
|
|
|
|
text_input_set_content_type(entry->text_input, |
|
|
|
|
TEXT_INPUT_CONTENT_HINT_NONE, |
|
|
|
|
entry->content_purpose); |
|
|
|
|
wl_text_input_set_content_type(entry->text_input, |
|
|
|
|
WL_TEXT_INPUT_CONTENT_HINT_NONE, |
|
|
|
|
entry->content_purpose); |
|
|
|
|
|
|
|
|
|
text_input_set_surrounding_text(entry->text_input, |
|
|
|
|
entry->text, |
|
|
|
|
entry->cursor, |
|
|
|
|
entry->anchor); |
|
|
|
|
wl_text_input_set_surrounding_text(entry->text_input, |
|
|
|
|
entry->text, |
|
|
|
|
entry->cursor, |
|
|
|
|
entry->anchor); |
|
|
|
|
|
|
|
|
|
if (entry->preferred_language) |
|
|
|
|
text_input_set_preferred_language(entry->text_input, |
|
|
|
|
entry->preferred_language); |
|
|
|
|
wl_text_input_set_preferred_language(entry->text_input, |
|
|
|
|
entry->preferred_language); |
|
|
|
|
|
|
|
|
|
text_entry_get_cursor_rectangle(entry, &cursor_rectangle); |
|
|
|
|
text_input_set_cursor_rectangle(entry->text_input, cursor_rectangle.x, cursor_rectangle.y, |
|
|
|
|
cursor_rectangle.width, cursor_rectangle.height); |
|
|
|
|
wl_text_input_set_cursor_rectangle(entry->text_input, cursor_rectangle.x, cursor_rectangle.y, |
|
|
|
|
cursor_rectangle.width, cursor_rectangle.height); |
|
|
|
|
|
|
|
|
|
text_input_commit_state(entry->text_input, ++entry->serial); |
|
|
|
|
wl_text_input_commit_state(entry->text_input, ++entry->serial); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
@ -733,7 +733,7 @@ text_entry_commit_and_reset(struct text_entry *entry) |
|
|
|
|
free(commit); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
text_input_reset(entry->text_input); |
|
|
|
|
wl_text_input_reset(entry->text_input); |
|
|
|
|
text_entry_update(entry); |
|
|
|
|
entry->reset_serial = entry->serial; |
|
|
|
|
} |
|
|
|
@ -779,9 +779,9 @@ text_entry_try_invoke_preedit_action(struct text_entry *entry, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
|
|
|
|
text_input_invoke_action(entry->text_input, |
|
|
|
|
button, |
|
|
|
|
cursor - entry->cursor); |
|
|
|
|
wl_text_input_invoke_action(entry->text_input, |
|
|
|
|
button, |
|
|
|
|
cursor - entry->cursor); |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
@ -1134,10 +1134,10 @@ global_handler(struct display *display, uint32_t name, |
|
|
|
|
{ |
|
|
|
|
struct editor *editor = data; |
|
|
|
|
|
|
|
|
|
if (!strcmp(interface, "text_input_manager")) { |
|
|
|
|
if (!strcmp(interface, "wl_text_input_manager")) { |
|
|
|
|
editor->text_input_manager = |
|
|
|
|
display_bind(display, name, |
|
|
|
|
&text_input_manager_interface, 1); |
|
|
|
|
&wl_text_input_manager_interface, 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1183,7 +1183,7 @@ main(int argc, char *argv[]) |
|
|
|
|
if (preferred_language) |
|
|
|
|
editor.entry->preferred_language = strdup(preferred_language); |
|
|
|
|
editor.editor = text_entry_create(&editor, "Numeric"); |
|
|
|
|
editor.editor->content_purpose = TEXT_INPUT_CONTENT_PURPOSE_NUMBER; |
|
|
|
|
editor.editor->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NUMBER; |
|
|
|
|
editor.editor->click_to_show = click_to_show; |
|
|
|
|
|
|
|
|
|
window_set_title(editor.window, "Text Editor"); |
|
|
|
|