text: Rename and extend text_model key event
authorJan Arne Petersen <jpetersen@openismus.com>
Sun, 18 Nov 2012 18:06:43 +0000 (19:06 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 27 Nov 2012 18:02:26 +0000 (13:02 -0500)
Rename the key event in text_model to keysym and add serial, time and
modifiers arguments. Add a modifiers_map event to transfer an array of
0-terminated modifier names, so that a mapping of modifiers to the
modifier bit mask is possible.

Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
clients/editor.c
clients/keyboard.c
protocol/input-method.xml
protocol/text.xml
src/text-backend.c

index 348041c..24ccace 100644 (file)
@@ -361,10 +361,20 @@ text_model_preedit_styling(void *data,
 }
 
 static void
-text_model_key(void *data,
-              struct text_model *text_model,
-               uint32_t key,
-               uint32_t state)
+text_model_modifiers_map(void *data,
+                        struct text_model *text_model,
+                        struct wl_array *map)
+{
+}
+
+static void
+text_model_keysym(void *data,
+                 struct text_model *text_model,
+                 uint32_t serial,
+                 uint32_t time,
+                 uint32_t key,
+                 uint32_t state,
+                 uint32_t modifiers)
 {
        struct text_entry *entry = data;
        const char *state_label;
@@ -454,7 +464,8 @@ static const struct text_model_listener text_model_listener = {
        text_model_preedit_string,
        text_model_delete_surrounding_text,
        text_model_preedit_styling,
-       text_model_key,
+       text_model_modifiers_map,
+       text_model_keysym,
        text_model_selection_replacement,
        text_model_direction,
        text_model_locale,
index 1b2a9ba..d1e5dbf 100644 (file)
@@ -234,7 +234,7 @@ virtual_keyboard_commit_preedit(struct virtual_keyboard *keyboard)
 }
 
 static void
-keyboard_handle_key(struct keyboard *keyboard, const struct key *key)
+keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *key)
 {
        const char *label = keyboard->state == keyboardstate_default ? key->label : key->alt;
 
@@ -259,8 +259,10 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key)
                        break;
                case keytype_enter:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_KP_Enter, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_KP_Enter, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
                case keytype_space:
                        keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
@@ -277,28 +279,38 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key)
                        break;
                case keytype_tab:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_Tab, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_Tab, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
                case keytype_arrow_up:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_Up, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_Up, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
                case keytype_arrow_left:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_Left, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_Left, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
                case keytype_arrow_right:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_Right, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_Right, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
                case keytype_arrow_down:
                        virtual_keyboard_commit_preedit(keyboard->keyboard);
-                       input_method_context_key(keyboard->keyboard->context,
-                                                XKB_KEY_Down, WL_KEYBOARD_KEY_STATE_PRESSED);
+                       input_method_context_keysym(keyboard->keyboard->context,
+                                                   display_get_serial(keyboard->keyboard->display),
+                                                   time, 
+                                                   XKB_KEY_Down, WL_KEYBOARD_KEY_STATE_PRESSED, 0);
                        break;
        }
 }
@@ -330,7 +342,7 @@ button_handler(struct widget *widget,
        for (i = 0; i < sizeof(keys) / sizeof(*keys); ++i) {
                col -= keys[i].width;
                if (col < 0) {
-                       keyboard_handle_key(keyboard, &keys[i]);
+                       keyboard_handle_key(keyboard, time, &keys[i]);
                        break;
                }
        }
index 09ab10c..69b1277 100644 (file)
       <arg name="index" type="int"/>
       <arg name="length" type="uint"/>
     </request>
-    <request name="key">
-      <arg name="key" type="uint"/>
+    <request name="modifiers_map">
+      <arg name="map" type="array"/>
+    </request>
+    <request 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_surrounfing_text, etc. The key event follows
+        the wl_keyboard key event convention. State is a XKB keysym, state a
+        wl_keyboard key_state.
+      </description>
+      <arg name="serial" type="uint"/>
+      <arg name="time" type="uint"/>
+      <arg name="sym" type="uint"/>
       <arg name="state" type="uint"/>
+      <arg name="modifiers" type="uint"/>
     </request>
     <event name="surrounding_text">
       <description summary="surrounding text event">
index 1b3a4b5..4701f7d 100644 (file)
       <arg name="length" type="uint"/>
     </event>
     <event name="preedit_styling"/>
-    <event name="key">
-      <description summary="key">
+    <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>
+    <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_surrounfing_text, etc. The key event follows
-        the wl_keyboard key event convention. Key is a XKB keycode, state a
-        wl_keyboard key_state.
+        the wl_keyboard key event convention. State is a XKB keysym, state a
+       wl_keyboard key_state. Modifiers are a mask for effective modifiers
+       (where the modfier indices are set by the modifiers_map event)
       </description>
-      <arg name="key" type="uint"/>
+      <arg name="serial" type="uint"/>
+      <arg name="time" type="uint"/>
+      <arg name="sym" type="uint"/>
       <arg name="state" type="uint"/>
+      <arg name="modifiers" type="uint"/>
     </event>
     <event name="selection_replacement"/>
     <event name="direction"/>
index ae1f16c..ece89bb 100644 (file)
@@ -350,14 +350,28 @@ input_method_context_delete_surrounding_text(struct wl_client *client,
 }
 
 static void
-input_method_context_key(struct wl_client *client,
-                        struct wl_resource *resource,
-                        uint32_t key,
-                        uint32_t state)
+input_method_context_modifiers_map(struct wl_client *client,
+                                  struct wl_resource *resource,
+                                  struct wl_array *map)
+{
+       struct input_method_context *context = resource->data;
+
+       text_model_send_modifiers_map(&context->model->resource, map);
+}
+
+static void
+input_method_context_keysym(struct wl_client *client,
+                           struct wl_resource *resource,
+                           uint32_t serial,
+                           uint32_t time,
+                           uint32_t sym,
+                           uint32_t state,
+                           uint32_t modifiers)
 {
        struct input_method_context *context = resource->data;
 
-       text_model_send_key(&context->model->resource, key, state);
+       text_model_send_keysym(&context->model->resource, serial, time,
+                              sym, state, modifiers);
 }
 
 static const struct input_method_context_interface input_method_context_implementation = {
@@ -365,7 +379,8 @@ static const struct input_method_context_interface input_method_context_implemen
        input_method_context_commit_string,
        input_method_context_preedit_string,
        input_method_context_delete_surrounding_text,
-       input_method_context_key
+       input_method_context_modifiers_map,
+       input_method_context_keysym
 };
 
 static void