[PATCH] editor: react on Enter, Tab, and Up-Down arrow keys
Manuel Bachmann
manuel.bachmann at open.eurogiciel.org
Mon Apr 21 13:39:57 PDT 2014
Hi Bill,
> It looks like the text actually has the bytes "Enter" at the newlines,
rather than, say, a '\n'?
In fact, it is '\r' (carriage return) rather than '\n' (new line). In
renders correctly with Pango, though, and would paste gracefully to other
clients such as weston-terminal.
The only problem would be if we made weston-terminal save its text buffer
directly to a file, in which case most text editors would display an
uninterpreted special character. Note that we do not do that yet, though.
Regards,
Manuel
2014-04-21 21:49 GMT+02:00 Bill Spitzak <spitzak at gmail.com>:
> It looks like the text actually has the bytes "Enter" at the newlines,
> rather than, say, a '\n'?
>
>
> On 04/18/2014 03:52 AM, Manuel Bachmann wrote:
>
> This fixes :
> https://bugs.freedesktop.org/show_bug.cgi?id=77496
>
> Regards,
> Manuel
>
>
> 2014-04-18 12:50 GMT+02:00 Manuel Bachmann <
> manuel.bachmann at open.eurogiciel.org>:
>
>> The editor will now insert new lines and tabulations when
>> pressing the corresponding keys on the virtual keyboard.
>>
>> The Up and Down arrows can be used to navigate through
>> lines.
>>
>> Signed-off-by: Manuel Bachmann <manuel.bachmann at open.eurogiciel.org>
>> ---
>> clients/editor.c | 97
>> ++++++++++++++++++++++++++++++++++++++++++++++++------
>> 1 file changed, 87 insertions(+), 10 deletions(-)
>>
>> diff --git a/clients/editor.c b/clients/editor.c
>> index 76e2346..4c5c427 100644
>> --- a/clients/editor.c
>> +++ b/clients/editor.c
>> @@ -110,6 +110,47 @@ utf8_next_char(const char *p)
>> return NULL;
>> }
>>
>> +static void
>> +move_up(const char *p, uint32_t *cursor)
>> +{
>> + const char *posr, *posr_i;
>> + char text[16];
>> +
>> + xkb_keysym_to_utf8(XKB_KEY_Return, text, sizeof(text));
>> +
>> + posr = strstr(p, text);
>> + while (posr) {
>> + if (*cursor > (unsigned)(posr-p)) {
>> + posr_i = strstr(posr+1, text);
>> + if (!posr_i || !(*cursor > (unsigned)(posr_i-p)))
>> {
>> + *cursor = posr-p;
>> + break;
>> + }
>> + posr = posr_i;
>> + } else {
>> + break;
>> + }
>> + }
>> +}
>> +
>> +static void
>> +move_down(const char *p, uint32_t *cursor)
>> +{
>> + const char *posr;
>> + char text[16];
>> +
>> + xkb_keysym_to_utf8(XKB_KEY_Return, text, sizeof(text));
>> +
>> + posr = strstr(p, text);
>> + while (posr) {
>> + if (*cursor <= (unsigned)(posr-p)) {
>> + *cursor = posr-p + 1;
>> + break;
>> + }
>> + posr = strstr(posr+1, text);
>> + }
>> +}
>> +
>> static void text_entry_redraw_handler(struct widget *widget, void *data);
>> static void text_entry_button_handler(struct widget *widget,
>> struct input *input, uint32_t time,
>> @@ -374,6 +415,23 @@ text_input_keysym(void *data,
>> return;
>> }
>>
>> + if (key == XKB_KEY_Up ||
>> + key == XKB_KEY_Down) {
>> + if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
>> + return;
>> +
>> + if (key == XKB_KEY_Up)
>> + move_up(entry->text, &entry->cursor);
>> + else
>> + move_down(entry->text, &entry->cursor);
>> +
>> + if (!(modifiers & entry->keysym.shift_mask))
>> + entry->anchor = entry->cursor;
>> + widget_schedule_redraw(entry->widget);
>> +
>> + return;
>> + }
>> +
>> if (key == XKB_KEY_BackSpace) {
>> const char *start, *end;
>>
>> @@ -395,17 +453,20 @@ text_input_keysym(void *data,
>> return;
>> }
>>
>> - switch (key) {
>> - case XKB_KEY_Tab:
>> - key_label = "Tab";
>> - break;
>> - case XKB_KEY_KP_Enter:
>> - case XKB_KEY_Return:
>> - key_label = "Enter";
>> - break;
>> - }
>> + if (key == XKB_KEY_Tab ||
>> + key == XKB_KEY_KP_Enter ||
>> + key == XKB_KEY_Return) {
>> + char text[16];
>> +
>> + if (state != WL_KEYBOARD_KEY_STATE_RELEASED)
>> + return;
>> +
>> + xkb_keysym_to_utf8(key, text, sizeof(text));
>>
>> - fprintf(stderr, "%s key was %s.\n", key_label, state_label);
>> + text_entry_insert_at_cursor(entry, text, 0, 0);
>> +
>> + return;
>> + }
>> }
>>
>> static void
>> @@ -1208,6 +1269,22 @@ key_handler(struct window *window,
>> widget_schedule_redraw(entry->widget);
>> }
>> break;
>> + case XKB_KEY_Up:
>> + text_entry_commit_and_reset(entry);
>> +
>> + move_up(entry->text, &entry->cursor);
>> + if (!(input_get_modifiers(input) &
>> MOD_SHIFT_MASK))
>> + entry->anchor = entry->cursor;
>> + widget_schedule_redraw(entry->widget);
>> + break;
>> + case XKB_KEY_Down:
>> + text_entry_commit_and_reset(entry);
>> +
>> + move_down(entry->text, &entry->cursor);
>> + if (!(input_get_modifiers(input) &
>> MOD_SHIFT_MASK))
>> + entry->anchor = entry->cursor;
>> + widget_schedule_redraw(entry->widget);
>> + break;
>> case XKB_KEY_Escape:
>> break;
>> default:
>> --
>> 1.7.10.4
>>
>>
>
>
> --
> Regards,
>
>
>
> *Manuel BACHMANN Tizen Project VANNES-FR*
>
>
> _______________________________________________
> wayland-devel mailing listwayland-devel at lists.freedesktop.orghttp://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
--
Regards,
*Manuel BACHMANN Tizen Project VANNES-FR*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140421/347c4514/attachment-0001.html>
More information about the wayland-devel
mailing list