[PATCH v2 26/28] text: add cursor_rectangle event to input_panel_surface

Jan Arne Petersen jpetersen at openismus.com
Thu Apr 18 07:47:40 PDT 2013


From: Jan Arne Petersen <jpetersen at openismus.com>

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 protocol/input-method.xml | 10 ++++++++++
 src/input-panel.c         | 37 ++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/protocol/input-method.xml b/protocol/input-method.xml
index f0c1184..5666e7b 100644
--- a/protocol/input-method.xml
+++ b/protocol/input-method.xml
@@ -269,5 +269,15 @@
         window hwne a text model is active.
       </description>
     </request>
+
+    <event name="cursor_rectangle">
+      <description summary="cursor rectangle">
+        Notify when the cursor rectangle relative to the input panel surface change.
+      </description>
+      <arg name="x" type="int"/>
+      <arg name="y" type="int"/>
+      <arg name="width" type="int"/>
+      <arg name="height" type="int"/>
+    </event>
   </interface>
 </protocol>
diff --git a/src/input-panel.c b/src/input-panel.c
index 711c164..70b1125 100644
--- a/src/input-panel.c
+++ b/src/input-panel.c
@@ -138,17 +138,19 @@ hide_input_panels(struct wl_listener *listener, void *data)
 }
 
 static void
-overlay_panel_get_position(struct input_panel_surface *surface,
-			   float *x, float *y)
+text_input_surface_get_cursor_rectangle(struct input_panel_surface *surface,
+					float *x1, float *y1,
+					float *x2, float *y2)
 {
 	struct input_panel *input_panel = surface->input_panel;
 
-	if (!surface->overlay_panel) {
+	if (!input_panel->text_input.surface || !weston_surface_is_mapped(input_panel->text_input.surface))
 		return;
-	}
 
-	*x = input_panel->text_input.surface->geometry.x + input_panel->text_input.cursor_rectangle.x2;
-	*y = input_panel->text_input.surface->geometry.y + input_panel->text_input.cursor_rectangle.y2;
+	*x1 = input_panel->text_input.surface->geometry.x + input_panel->text_input.cursor_rectangle.x1;
+	*y1 = input_panel->text_input.surface->geometry.y + input_panel->text_input.cursor_rectangle.y1;
+	*x2 = input_panel->text_input.surface->geometry.x + input_panel->text_input.cursor_rectangle.x2;
+	*y2 = input_panel->text_input.surface->geometry.y + input_panel->text_input.cursor_rectangle.y2;
 }
 
 static void
@@ -158,19 +160,24 @@ update_input_panels(struct wl_listener *listener, void *data)
 		container_of(listener, struct input_panel,
 			     update_input_panel_listener);
 	struct input_panel_surface *surface, *next;
-	float x = 0, y = 0;
+	float x1 = 0, y1 = 0, x2 = 0, y2 = 0;
 
 	memcpy(&input_panel->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
 
 	wl_list_for_each_safe(surface, next,
 			      &input_panel->surfaces, link) {
-		if (!surface->overlay_panel)
-			continue;
+		text_input_surface_get_cursor_rectangle(surface, &x1, &y1, &x2, &y2);
 		if (!weston_surface_is_mapped(surface->surface))
 			continue;
-		overlay_panel_get_position(surface, &x, &y);
-		weston_surface_set_position(surface->surface, x, y);
-		weston_surface_update_transform(surface->surface);
+		if (surface->overlay_panel) {
+			weston_surface_set_position(surface->surface, x2, y2);
+			weston_surface_update_transform(surface->surface);
+		}
+		wl_input_panel_surface_send_cursor_rectangle(&surface->resource,
+							     x1 - surface->surface->geometry.x,
+							     y1 - surface->surface->geometry.y,
+							     x2 - surface->surface->geometry.x,
+							     y2 - surface->surface->geometry.y);
 	}
 }
 
@@ -187,7 +194,11 @@ input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, in
 		return;
 
 	if (ip_surface->overlay_panel) {
-		overlay_panel_get_position(ip_surface, &x, &y);
+		float x1, y1, x2, y2;
+		text_input_surface_get_cursor_rectangle(ip_surface, &x1, &y1, &x2, &y2);
+
+		x = x2;
+		y = y2;
 	} else {
 		mode = ip_surface->output->current;
 
-- 
1.8.1.4



More information about the wayland-devel mailing list