text: Add activate/deactivate events
Let the client know when a text model gets activated or deactiavted.
diff --git a/clients/editor.c b/clients/editor.c
index 8f0e9d8..9cb7326 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -107,6 +107,28 @@
{
}
+static void
+text_model_activated(void *data,
+ struct text_model *text_model)
+{
+ struct text_entry *entry = data;
+
+ entry->active = 1;
+
+ widget_schedule_redraw(entry->widget);
+}
+
+static void
+text_model_deactivated(void *data,
+ struct text_model *text_model)
+{
+ struct text_entry *entry = data;
+
+ entry->active = 0;
+
+ widget_schedule_redraw(entry->widget);
+}
+
static const struct text_model_listener text_model_listener = {
text_model_commit_string,
text_model_preedit_string,
@@ -114,7 +136,9 @@
text_model_key,
text_model_selection_replacement,
text_model_direction,
- text_model_locale
+ text_model_locale,
+ text_model_activated,
+ text_model_deactivated
};
static struct text_entry*
@@ -283,24 +307,13 @@
assert(!(activate_entry && activate_editor));
if (activate_entry) {
- if (editor->editor->active)
- text_entry_deactivate(editor->editor);
- if (!editor->entry->active)
- text_entry_activate(editor->entry);
+ text_entry_activate(editor->entry);
} else if (activate_editor) {
- if (editor->entry->active)
- text_entry_deactivate(editor->entry);
- if (!editor->editor->active)
- text_entry_activate(editor->editor);
+ text_entry_activate(editor->editor);
} else {
- if (editor->entry->active)
- text_entry_deactivate(editor->entry);
- if (editor->editor->active)
- text_entry_deactivate(editor->editor);
+ text_entry_deactivate(editor->entry);
+ text_entry_deactivate(editor->editor);
}
- editor->entry->active = activate_entry;
- editor->editor->active = activate_editor;
- assert(!(editor->entry->active && editor->editor->active));
widget_schedule_redraw(widget);
}