[PATCH v2 3/3] editor: correctly handle multiple seats

Philipp Brüschweiler blei42 at gmail.com
Mon Aug 13 05:35:07 PDT 2012


Text fields are drawn as activated if at least one seat has activated
the corresponding text model.
---
 clients/editor.c | 18 +++++++++++-------
 1 Datei geändert, 11 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)

diff --git a/clients/editor.c b/clients/editor.c
index a5347fe..76bbcb3 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -35,7 +35,7 @@ struct text_entry {
 	struct widget *widget;
 	struct window *window;
 	char *text;
-	int active;
+	int activation_count;
 	struct rectangle allocation;
 	struct text_model *model;
 };
@@ -114,9 +114,11 @@ text_model_activated(void *data,
 {
 	struct text_entry *entry = data;
 
-	entry->active = 1;
+	entry->activation_count++;
+	assert(entry->activation_count > 0);
 
-	widget_schedule_redraw(entry->widget);
+	if (entry->activation_count == 1)
+		widget_schedule_redraw(entry->widget);
 }
 
 static void
@@ -125,9 +127,11 @@ text_model_deactivated(void *data,
 {
 	struct text_entry *entry = data;
 
-	entry->active = 0;
+	entry->activation_count--;
+	assert(entry->activation_count >= 0);
 
-	widget_schedule_redraw(entry->widget);
+	if (entry->activation_count == 0)
+		widget_schedule_redraw(entry->widget);
 }
 
 static const struct text_model_listener text_model_listener = {
@@ -155,7 +159,7 @@ text_entry_create(struct editor *editor, const char *text)
 	entry->widget = editor->widget;
 	entry->window = editor->window;
 	entry->text = strdup(text);
-	entry->active = 0;
+	entry->activation_count = 0;
 	entry->model = text_model_factory_create_text_model(editor->text_model_factory, surface);
 	text_model_add_listener(entry->model, &text_model_listener, entry);
 
@@ -183,7 +187,7 @@ text_entry_draw(struct text_entry *entry, cairo_t *cr)
 	cairo_rectangle(cr, 0, 0, entry->allocation.width, entry->allocation.height);
 	cairo_set_source_rgba(cr, 1, 1, 1, 0.5);
 	cairo_fill(cr);
-	if (entry->active) {
+	if (entry->activation_count > 0) {
 		cairo_rectangle(cr, 0, 0, entry->allocation.width, entry->allocation.height);
 		cairo_set_source_rgba(cr, 0, 0, 1, 0.5);
 		cairo_stroke(cr);
-- 
1.7.11.4



More information about the wayland-devel mailing list