[PATCH v3 wayland-protocols] text: Create second version of text input protocol

Jan Arne Petersen janarne at gmail.com
Tue Feb 2 13:41:19 UTC 2016


Hi Silvan,

On 02/02/16 13:23, Silvan Jegen wrote:
> Hi
> 
> Please find some comments and spelling corrections below.
> 
> 
>> There were some shortcomings in the first version of the protocol which
>> makes it not really useful in real world applications. It is not really
>> possible to fix them in a compatible way so introduce a new v2 of the
>> protocol.
>>
>> Fixes some shortcomings of the first version:
>>
>> * Use only one wp_text_input per wl_seat (client side should be
>>   handled by client toolkit)
>> * Allow focus tracking without wl_keyboard present
>> * Improve update state handling
>> * Allow state requests
>> ---
>>  unstable/text-input/text-input-unstable-v2.xml | 481 +++++++++++++++++++++++++
>>  1 file changed, 481 insertions(+)
>>  create mode 100644 unstable/text-input/text-input-unstable-v2.xml
>>
>> diff --git a/unstable/text-input/text-input-unstable-v2.xml b/unstable/text-input/text-input-unstable-v2.xml
>> new file mode 100644
>> index 0000000..2fc5e7d
>> --- /dev/null
>> +++ b/unstable/text-input/text-input-unstable-v2.xml
>> @@ -0,0 +1,481 @@
>> +<?xml version="1.0" encoding="UTF-8"?>
>> +
>> +<protocol name="text_input_unstable_v2">
>> +  <copyright>
>> +    Copyright © 2012, 2013 Intel Corporation
>> +    Copyright © 2015, 2016 Jan Arne Petersen
>> +
>> +    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.
>> +  </copyright>
>> +
>> +  <interface name="zwp_text_input_v2" version="1">
>> +    <description summary="text input">
>> +      The zwp_text_input_v2 interface represents text input and input methods
> 
> s/repesents/represents/

fixed

>> +      associated with a seat. It provides enter/leave event to follow the
> 
> s/event/events/


fixed

>> +      text input focus for a seat.
>> +
>> +      Requests are used to enable/disable the text-input object and set
>> +      state information like surrounding and selected text or the content type.
>> +      The information about entered text is sent to the text-input object via
> 
> "about the entered text" may sound more natural.

fixed

>> +      the pre-edit and commit events. Using this interface removes the need
>> +      for applications to directly process hardware key events and compose text
>> +      out of them.
>> +
>> +      Text is UTF-8 encoded, indices and lengths are in bytes.
> 
> This seems problematic to me when dealing with multi-byte encoded
> Unicode points. The behavior should be better defined in that case.
> Please see comments further below.

>From v4:

"Text is valid UTF-8 encoded, indices and lengths are in bytes. Indices
have to always point to the first byte of an UTF-8 encoded code point.
Lengths are not allowed to contain just a part of an UTF-8 encoded code
point."

The protocol is usually not used by application developers directly but
by a toolkit which has to convert from toolkit strings/indices/lengths
to the protocol string/index/length format and back. Which seems to be
quite easy with above protocol definition. We could also use Unicode
characters for index/length should not make much a difference.

>> +      Serials are used to synchronize the state between the text input and
>> +      an input method. New serials are sent by the text input in the
>> +      update_state request and are used by the input method to indicate
>> +      the known text input state in evsents like preedit_string, commit_string,
> 
> s/evsents/events/

fixed

>> +      and keysym. The text input can then ignore events from the input method
>> +      which are based on an outdated state (for example after a reset).
>> +    </description>
>> +
>> +    <request name="destroy" type="destructor">
>> +      <description summary="Destroy the wp_text_input">
>> +       Destroy the wp_text_input object. Also disables all surfaces enabled
>> +       through this wp_text_input object
>> +      </description>
>> +    </request>
>> +
>> +    <request name="enable">
>> +      <description summary="enable text input for surface">
>> +       Enable text input in a surface (usually when a text entry inside of it
>> +       has focus).
>> +
>> +       This can be called before or after a surface gets text (or keyboard)
>> +       focus via the enter event. Text input to a surface is only active
>> +       when it has the current text (or keyboard) focus and is enabled.
>> +      </description>
>> +      <arg name="surface" type="object" interface="wl_surface"/>
>> +    </request>
>> +
>> +    <request name="disable">
>> +      <description summary="disable text input for surface">
>> +       Disable text input in a surface (typically when there is no focus on any
>> +       text entry inside the surface).
>> +      </description>
>> +      <arg name="surface" type="object" interface="wl_surface"/>
>> +    </request>
>> +
>> +    <request name="show_input_panel">
>> +      <description summary="show input panels">
>> +       Requests input panels (virtual keyboard) to show.
>> +
>> +       This should be used for example to show a virtual keyboard again
>> +       (with a tap) after it was closed by pressing on a close button on the
>> +       keyboard.
>> +      </description>
>> +    </request>
>> +
>> +    <request name="hide_input_panel">
>> +      <description summary="hide input panels">
>> +       Requests input panels (virtual keyboard) to hide.
>> +      </description>
>> +    </request>
>> +
>> +    <request name="reset">
>> +      <description summary="reset">
> 
> There is a description missing. Maybe something like
> 
> "Resets the state of the input method."?

Request got removed (instead update_state with the "reset" flag is used)

>> +      </description>
>> +    </request>
>> +
>> +    <request name="set_surrounding_text">
>> +      <description summary="sets the surrounding text">
>> +       Sets the plain surrounding text around the input position. Text is
>> +       UTF-8 encoded. Cursor is the byte offset within the
>> +       surrounding text. Anchor is the byte offset of the
>> +       selection anchor within the surrounding text. If there is no selected
>> +       text anchor is the same as cursor.
> 
> Adding a comma here makes the text more readable.
> 
> "text, anchor is the same as cursor."

fixed

>> +
>> +       Make sure to always send some text before and after the cursor
>> +       except when the cursor is at the beginning or end of text.
>> +
>> +       When there was a
> 
> This line should be removed (or completed... :P).

Completed missing text:

"When there was a configure_surrounding_text event take the
 before_cursor and after_cursor arguments into account for picking how
 much surrounding text to send.

 There is a maximum length of wayland messages so text can not be
 longer than 4000 bytes."

>> +      </description>
>> +      <arg name="text" type="string"/>
>> +      <arg name="cursor" type="uint"/>
>> +      <arg name="anchor" type="int"/>
>> +    </request>
>> +
>> +    <enum name="content_hint" bitfield="true">
>> +      <description summary="content hint">
>> +       Content hint is a bitmask to allow to modify the behavior of the text
>> +       input.
>> +      </description>
>> +      <entry name="none" value="0x0" summary="no special behaviour"/>
>> +      <entry name="auto_completion" value="0x1" summary="suggest word completions"/>
>> +      <entry name="auto_correction" value="0x2" summary="suggest word corrections"/>
>> +      <entry name="auto_capitalization" value="0x4" summary="switch to uppercase letters at the start of a sentence"/>
>> +      <entry name="lowercase" value="0x8" summary="prefer lowercase letters"/>
>> +      <entry name="uppercase" value="0x10" summary="prefer uppercase letters"/>
>> +      <entry name="titlecase" value="0x20" summary="prefer casing for titles and headings (can be language dependent)"/>
>> +      <entry name="hidden_text" value="0x40" summary="characters should be hidden"/>
>> +      <entry name="sensitive_data" value="0x80" summary="typed text should not be stored"/>
>> +      <entry name="latin" value="0x100" summary="just latin characters should be entered"/>
>> +      <entry name="multiline" value="0x200" summary="the text input is multiline"/>
>> +    </enum>
>> +
>> +    <enum name="content_purpose">
>> +      <description summary="content purpose">
>> +       The content purpose allows to specify the primary purpose of a text
>> +       input.
>> +
>> +       This allows an input method to show special purpose input panels with
>> +       extra characters or to disallow some characters.
>> +      </description>
>> +      <entry name="normal" value="0" summary="default input, allowing all characters"/>
>> +      <entry name="alpha" value="1" summary="allow only alphabetic characters"/>
>> +      <entry name="digits" value="2" summary="allow only digits"/>
>> +      <entry name="number" value="3" summary="input a number (including decimal separator and sign)"/>
>> +      <entry name="phone" value="4" summary="input a phone number"/>
>> +      <entry name="url" value="5" summary="input an URL"/>
>> +      <entry name="email" value="6" summary="input an email address"/>
>> +      <entry name="name" value="7" summary="input a name of a person"/>
>> +      <entry name="password" value="8" summary="input a password (combine with password or sensitive_data hint)"/>
>> +      <entry name="date" value="9" summary="input a date"/>
>> +      <entry name="time" value="10" summary="input a time"/>
>> +      <entry name="datetime" value="11" summary="input a date and time"/>
>> +      <entry name="terminal" value="12" summary="input for a terminal"/>
>> +    </enum>
>> +
>> +    <request name="set_content_type">
>> +      <description summary="set content purpose and hint">
>> +       Sets the content purpose and content hint. While the purpose is the
>> +       basic purpose of an input field, the hint flags allow to modify some
>> +       of the behavior.
>> +
>> +       When no content type is explicitly set, a normal content purpose with
>> +       default hints (auto completion, auto correction, auto capitalization)
>> +       should be assumed.
>> +      </description>
>> +      <arg name="hint" type="uint" enum="content_hint"/>
>> +      <arg name="purpose" type="uint" enum="content_purpose"/>
>> +    </request>
>> +
>> +    <request name="set_cursor_rectangle">
>> +      <description summary="set cursor position">
>> +       Sets the cursor outline as a rectangle relative to the surface.
>> +
>> +       Allows the compositor to put a window with word suggestions near the
>> +       cursor.
>> +      </description>
>> +      <arg name="x" type="int"/>
>> +      <arg name="y" type="int"/>
>> +      <arg name="width" type="int"/>
>> +      <arg name="height" type="int"/>
>> +    </request>
>> +
>> +    <request name="set_preferred_language">
>> +      <description summary="sets preferred language">
>> +       Sets a specific language. This allows for example a virtual keyboard to
>> +       show a language specific layout. The "language" argument is a RFC-3066
>> +       format language tag.
>> +
>> +       It could be used for example in a word processor to indicate language of
>> +       currently edited document or in an instant message application which
>> +       tracks languages of contacts.
>> +      </description>
>> +      <arg name="language" type="string"/>
>> +    </request>
>> +
>> +    <enum name="update_state">
>> +      <description summary="update_state flags">
>> +       Defines the reason for sending an updated state.
>> +      </description>
>> +      <entry name="change" value="0" summary="updated state because it changed"/>
>> +      <entry name="full" value="1" summary="full state after demand_full_state event"/>
>> +      <entry name="reset" value="2" summary="full state after reset"/>
>> +      <entry name="enter" value="3" summary="full state after switching focus to a different widget on client side"/>
>> +    </enum>
>> +
>> +    <request name="update_state">
>> +      <description summary="update state">
>> +       Allows to atomically send state updates from client.
>> +
>> +       This request should follow after a batch of state updating requests
>> +       like set_surrounding_text, set_content_type, set_cursor_rectangle and
>> +       set_preferred_language.
>> +
>> +       The flags field indicates why an updated state is sent to the input
>> +       method.
>> +
>> +       Reset should be used by an editor widget after the text was changed
>> +       outside of the normal input method flow.
>> +
>> +       For "change" it is enough to send the changed state, else the full
>> +       state should be send.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="used to identify the known state"/>
>> +      <arg name="flags" type="uint" enum="update_state"/>
>> +    </request>
>> +
>> +    <request name="invoke_action">
>> +      <description summary="invokes an action">
>> +       Allows to invoke an action when tapping or clicking the currently
>> +       composed word in the text input.
>> +
>> +       This can be used by input methods to offer more word suggestions.
>> +      </description>
>> +      <arg name="button" type="uint"/>
>> +      <arg name="index" type="uint"/>
>> +    </request>
>> +
>> +    <event name="enter">
>> +      <description summary="enter event">
>> +       Notification that this seat's text-input focus is on a certain surface.
>> +
>> +       When the seat has one or more keyboards the text-input focus follows the
>> +       keyboard focus.
>> +      </description>
>> +      <arg name="serial" type="uint"/>
>> +      <arg name="surface" type="object" interface="wl_surface"/>
>> +    </event>
>> +
>> +    <event name="leave">
>> +      <description summary="leave event">
>> +       Notification that this seat's text-input focus is no longer on
>> +       a certain surface.
>> +
>> +       The leave notification is sent before the enter notification
>> +       for the new focus.
>> +
>> +       When the seat has one or more keyboards the text-input focus follows the
>> +       keyboard focus.
>> +      </description>
>> +      <arg name="serial" type="uint"/>
>> +      <arg name="surface" type="object" interface="wl_surface"/>
>> +    </event>
>> +
>> +    <event name="modifiers_map">
>> +      <description summary="modifiers map">
>> +       Transfer an array of 0-terminated modifiers names. The position in
>> +       the array is the index of the modifier as used in the modifiers
>> +       bitmask in the keysym event.
>> +      </description>
>> +      <arg name="map" type="array"/>
>> +    </event>
>> +
>> +    <enum name="input_panel_visibility">
>> +    <entry name="hidden" value="0"
>> +          summary="the input panel (virtual keyboard) is hidden"/>
>> +    <entry name="hidden" value="1"
> 
> The entry name should be "visible" not "hidden" I assume.

fixed

>> +          summary="the input panel (virtual keyboard) is visible"/>
>> +    </enum>
>> +
>> +    <event name="input_panel_state">
>> +      <description summary="state of the input panel">
>> +       Notification that the visibility of the input panel (virtual keyboard)
>> +       changed.
>> +
>> +       The rectangle x, y, width, height defines the bounding rectangle on
>> +       the surface with text focus which is overlapped by the input panel
>> +       (virtual keyboard). That can be used to make widgets with text focus
>> +       visible.
>> +      </description>
>> +      <arg name="state" type="uint" enum="input_panel_visibility"/>
>> +      <arg name="x" type="int"/>
>> +      <arg name="y" type="int"/>
>> +      <arg name="width" type="int"/>
>> +      <arg name="height" type="int"/>
>> +    </event>
>> +
>> +    <event name="preedit_string">
>> +      <description summary="pre-edit">
>> +       Notify when a new composing text (pre-edit) should be set around the
>> +       current cursor position. Any previously set composing text should
>> +       be removed.
>> +
>> +       The commit text can be used to replace the composing text in some cases
>> +       (for example on unfocus).
>> +
>> +       The text input should also handle all preedit_style and preedit_cursor
>> +       events occurring directly before preedit_string.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="text" type="string"/>
>> +      <arg name="commit" type="string"/>
>> +    </event>
>> +
>> +    <enum name="preedit_style">
>> +      <entry name="default" value="0" summary="default style for composing text"/>
>> +      <entry name="none" value="1" summary="composing text should be shown the same as non-composing text"/>
>> +      <entry name="active" value="2" summary="composing text might be bold"/>
>> +      <entry name="inactive" value="3" summary="composing text might be cursive"/>
>> +      <entry name="highlight" value="4" summary="composing text might have a different background color"/>
>> +      <entry name="underline" value="5" summary="composing text might be underlined"/>
>> +      <entry name="selection" value="6" summary="composing text should be shown the same as selected text"/>
>> +      <entry name="incorrect" value="7" summary="composing text might be underlined with a red wavy line"/>
>> +    </enum>
>> +
>> +    <event name="preedit_styling">
>> +      <description summary="pre-edit styling">
>> +       Sets styling information on composing text. The style is applied for
>> +       length bytes from index relative to the beginning of the composing
> 
> Having the offset in bytes is odd here. If you have a Unicode code
> point that is encoded with 3 UTF-8 bytes and the offset includes only
> one of the bytes are you then supposed to apply the style on this code
> point? Or do you only apply the style if more than half of the encoded
> bytes of a code point are included in the offset...

see above

>> +       text (as byte offset). Multiple styles can be applied to a composing
>> +       text by sending multiple preedit_styling events.
>> +
>> +       This event is handled as part of a following preedit_string event.
>> +      </description>
>> +      <arg name="index" type="uint"/>
>> +      <arg name="length" type="uint"/>
>> +      <arg name="style" type="uint" enum="preedit_style"/>
>> +    </event>
>> +
>> +    <event name="preedit_cursor">
>> +      <description summary="pre-edit cursor">
>> +       Sets the cursor position inside the composing text (as byte
>> +       offset) relative to the start of the composing text. When index is a
>> +       negative number no cursor is shown.
> 
> If we use byte offsets we should define what should happen if the offset
> bytes do not include all bytes of an encoded code point.

see above

>> +
>> +       When no preedit_cursor event is sent the cursor will be at the end of
>> +       the composing text by default.
>> +
>> +       This event is handled as part of a following preedit_string event.
>> +      </description>
>> +      <arg name="index" type="int"/>
>> +    </event>
>> +
>> +    <event name="commit_string">
>> +      <description summary="commit">
>> +       Notify when text should be inserted into the editor widget. The text to
>> +       commit could be either just a single character after a key press or the
>> +       result of some composing (pre-edit). It could be also an empty text
>> +       when some text should be removed (see delete_surrounding_text) or when
>> +       the input cursor should be moved (see cursor_position).
>> +
>> +       Any previously set composing text should be removed.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="text" type="string"/>
>> +    </event>
>> +
>> +    <event name="cursor_position">
>> +      <description summary="set cursor to new position">
>> +       Notify when the cursor or anchor position should be modified.
>> +
>> +       This event should be handled as part of a following commit_string
>> +       event.
>> +
>> +       The text between anchor and index should be selected.
>> +      </description>
>> +      <arg name="index" type="int" summary="position of cursor"/>
> 
> If we have byte offsets here as well we would have to decide what to do
> in regards to multi-byte encoded Unicode points.
> 
> 
>> +      <arg name="anchor" type="int" summary="position of selection anchor"/>
>> +    </event>
>> +
>> +    <event name="delete_surrounding_text">
>> +      <description summary="delete surrounding text">
>> +       Notify when the text around the current cursor position should be
>> +       deleted.
>> +
>> +       Index is relative to the current cursor (in bytes).
>> +       Length is the length of deleted text (in bytes).
> 
> See comment about multi-byte-encoded Unicode points above.
> 
>> +
>> +       This event should be handled as part of a following commit_string
>> +       or preedit_string event.
>> +      </description>
>> +      <arg name="index" type="int"/>
>> +      <arg name="length" type="uint"/>
>> +    </event>
>> +
>> +    <event name="keysym">
>> +      <description summary="keysym">
>> +       Notify when a key event was sent. Key events should not be used
>> +       for normal text input operations, which should be done with
>> +       commit_string, delete_surrounding_text, etc. The key event follows
>> +       the wl_keyboard key event convention. Sym is a XKB keysym, state a
>> +       wl_keyboard key_state. Modifiers are a mask for effective modifiers
>> +       (where the modifier indices are set by the modifiers_map event)
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="time" type="uint"/>
>> +      <arg name="sym" type="uint"/>
>> +      <arg name="state" type="uint"/>
>> +      <arg name="modifiers" type="uint"/>
>> +    </event>
>> +
>> +    <event name="language">
>> +      <description summary="language">
>> +       Sets the language of the input text. The "language" argument is a RFC-3066
>> +       format language tag.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="language" type="string"/>
>> +    </event>
>> +
>> +    <enum name="text_direction">
>> +      <entry name="auto" value="0" summary="automatic text direction based on text and language"/>
>> +      <entry name="ltr" value="1" summary="left-to-right"/>
>> +      <entry name="rtl" value="2" summary="right-to-left"/>
>> +    </enum>
>> +
>> +    <event name="text_direction">
>> +      <description summary="text direction">
>> +       Sets the text direction of input text.
>> +
>> +       It is mainly needed for showing input cursor on correct side of the
>> +       editor when there is no input yet done and making sure neutral
>> +       direction text is laid out properly.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="direction" type="uint" enum="text_direction"/>
>> +    </event>
>> +
>> +    <event name="configure_surrounding_text">
>> +      <description summary="configure amount of surrounding text to be send from client">
> 
> s/send/sent/

fixed

> Thanks for all this work!
> 
> 
> Cheers,
> 
> Silvan


Thanks,
Jan Arne

> 
> 
>> +       Configure what amount of surrounding text is sent by the
>> +       set_surrounding_text request on the following state information updates.
>> +      </description>
>> +      <arg name="before_cursor" type="int"/>
>> +      <arg name="after_cursor" type="int"/>
>> +    </event>
>> +
>> +    <event name="demand_full_state">
>> +      <description summary="demand the full state from client">
>> +       Ask to get full current state information sent from the client via
>> +       state requests (set_surrounding_text, set_content_hint, ...) and
>> +       update_state.
>> +      </description>
>> +      <arg name="serial" type="uint" summary="serial of the latest known text input state"/>
>> +      <arg name="flags" type="uint" summary="currently unused"/>
>> +    </event>
>> +  </interface>
>> +
>> +  <interface name="zwp_text_input_manager_v2" version="1">
>> +    <description summary="text input manager">
>> +      A factory for text-input objects. This object is a global singleton.
>> +    </description>
>> +
>> +    <request name="destroy" type="destructor">
>> +      <description summary="Destroy the wp_text_input_manager">
>> +       Destroy the wp_text_input_manager object.
>> +      </description>
>> +    </request>
>> +
>> +    <request name="get_text_input">
>> +      <description summary="create a new text input object">
>> +       Creates a new text-input object for a given seat.
>> +      </description>
>> +      <arg name="id" type="new_id" interface="zwp_text_input_v2"/>
>> +      <arg name="seat" type="object" interface="wl_seat"/>
>> +    </request>
>> +  </interface>
>> +</protocol>
>> --
>> 2.5.0
>>
>> _______________________________________________
>> wayland-devel mailing list
>> wayland-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/wayland-devel

-- 
Jan Arne Petersen | jan.petersen at kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts


More information about the wayland-devel mailing list