From de3b6a15c0267b3c1b52160b4d87dc63c2d5338a Mon Sep 17 00:00:00 2001 From: Jan Arne Petersen Date: Fri, 10 Aug 2012 16:47:21 +0200 Subject: [PATCH] text: Add activate/deactivate events Let the client know when a text model gets activated or deactiavted. --- clients/editor.c | 45 +++++++++++++++++++++++++++++---------------- protocol/text.xml | 4 +++- src/text-backend.c | 10 ++++++++++ 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/clients/editor.c b/clients/editor.c index 8f0e9d88..9cb73269 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -107,6 +107,28 @@ text_model_locale(void *data, { } +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 @@ static const struct text_model_listener text_model_listener = { 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 @@ button_handler(struct widget *widget, 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); } diff --git a/protocol/text.xml b/protocol/text.xml index 54866e15..ac12a1ab 100644 --- a/protocol/text.xml +++ b/protocol/text.xml @@ -33,7 +33,9 @@ - + + + diff --git a/src/text-backend.c b/src/text-backend.c index bed3f777..9113c9b7 100644 --- a/src/text-backend.c +++ b/src/text-backend.c @@ -54,6 +54,7 @@ deactivate_text_model(struct text_model *text_model) if (text_model->input_method->active_model == text_model) { text_model->input_method->active_model = NULL; wl_signal_emit(&ec->hide_input_panel_signal, ec); + text_model_send_deactivated(&text_model->resource); } } @@ -90,9 +91,18 @@ text_model_activate(struct wl_client *client, struct text_model *text_model = resource->data; struct weston_compositor *ec = text_model->input_method->ec; + if (text_model->input_method->active_model) { + if (text_model->input_method->active_model == text_model) + return; + + deactivate_text_model(text_model->input_method->active_model); + } + text_model->input_method->active_model = text_model; wl_signal_emit(&ec->show_input_panel_signal, ec); + + text_model_send_activated(&text_model->resource); } static void