diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-05 23:56:33 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-05 23:56:33 +0200 |
commit | 75270d78419e94ad5a6a808e3c448af9f591762a (patch) | |
tree | 7915c32cbd29c9c8f37412d83fb97a19d8e8fbc0 /src/plugins/relay | |
parent | 6526cc230a80d8aa05d36c70c1d97f0e7ccf182d (diff) | |
download | weechat-75270d78419e94ad5a6a808e3c448af9f591762a.zip |
relay/api: add optional synchronization of input
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/api/relay-api-protocol.c | 47 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-protocol.h | 4 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api.c | 35 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api.h | 4 |
4 files changed, 89 insertions, 1 deletions
diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index a025db3cc..c3035edcd 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -266,6 +266,47 @@ relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data, } /* + * Callback for signal "input_text_changed". + */ + +int +relay_api_protocol_signal_input_cb (const void *pointer, void *data, + const char *signal, + const char *type_data, + void *signal_data) +{ + struct t_relay_client *ptr_client; + struct t_gui_buffer *ptr_buffer; + cJSON *json; + long long buffer_id; + + /* make C compiler happy */ + (void) data; + (void) type_data; + + ptr_client = (struct t_relay_client *)pointer; + if (!ptr_client || !relay_client_valid (ptr_client)) + return WEECHAT_RC_OK; + + ptr_buffer = (struct t_gui_buffer *)signal_data; + if (!ptr_buffer || relay_buffer_is_relay (ptr_buffer)) + return WEECHAT_RC_OK; + + json = relay_api_msg_buffer_to_json ( + ptr_buffer, 0, 0, 0, + RELAY_API_DATA(ptr_client, sync_colors)); + + if (json) + { + buffer_id = relay_api_get_buffer_id (ptr_buffer); + relay_api_msg_send_event (ptr_client, signal, buffer_id, "buffer", json); + cJSON_Delete (json); + } + + return WEECHAT_RC_OK; +} + +/* * Callback for signals "upgrade*". */ @@ -763,7 +804,7 @@ RELAY_API_PROTOCOL_CALLBACK(ping) RELAY_API_PROTOCOL_CALLBACK(sync) { - cJSON *json_body, *json_sync, *json_nicks, *json_colors; + cJSON *json_body, *json_sync, *json_nicks, *json_input, *json_colors; if (client->websocket != RELAY_CLIENT_WEBSOCKET_READY) { @@ -777,6 +818,7 @@ RELAY_API_PROTOCOL_CALLBACK(sync) RELAY_API_DATA(client, sync_enabled) = 1; RELAY_API_DATA(client, sync_nicks) = 1; + RELAY_API_DATA(client, sync_input) = 1; RELAY_API_DATA(client, sync_colors) = RELAY_API_COLORS_ANSI; json_body = cJSON_Parse (client->http_req->body); @@ -788,6 +830,9 @@ RELAY_API_PROTOCOL_CALLBACK(sync) json_nicks = cJSON_GetObjectItem (json_body, "nicks"); if (json_nicks && cJSON_IsBool (json_nicks)) RELAY_API_DATA(client, sync_nicks) = (cJSON_IsTrue (json_nicks)) ? 1 : 0; + json_input = cJSON_GetObjectItem (json_body, "input"); + if (json_input && cJSON_IsBool (json_input)) + RELAY_API_DATA(client, sync_input) = (cJSON_IsTrue (json_input)) ? 1 : 0; json_colors = cJSON_GetObjectItem (json_body, "colors"); if (json_colors && cJSON_IsString (json_colors)) RELAY_API_DATA(client, sync_colors) = relay_api_search_colors ( diff --git a/src/plugins/relay/api/relay-api-protocol.h b/src/plugins/relay/api/relay-api-protocol.h index 63e930fa2..f1aa8e896 100644 --- a/src/plugins/relay/api/relay-api-protocol.h +++ b/src/plugins/relay/api/relay-api-protocol.h @@ -45,6 +45,10 @@ extern int relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable); +extern int relay_api_protocol_signal_input_cb (const void *pointer, void *data, + const char *signal, + const char *type_data, + void *signal_data); extern int relay_api_protocol_signal_upgrade_cb (const void *pointer, void *data, const char *signal, diff --git a/src/plugins/relay/api/relay-api.c b/src/plugins/relay/api/relay-api.c index fda7d06f3..990ff1425 100644 --- a/src/plugins/relay/api/relay-api.c +++ b/src/plugins/relay/api/relay-api.c @@ -121,6 +121,24 @@ relay_api_hook_signals (struct t_relay_client *client) RELAY_API_DATA(client, hook_hsignal_nicklist) = NULL; } } + if (RELAY_API_DATA(client, sync_input)) + { + if (!RELAY_API_DATA(client, hook_signal_input)) + { + RELAY_API_DATA(client, hook_signal_input) = + weechat_hook_signal ("input_text_changed;input_text_cursor_moved", + &relay_api_protocol_signal_input_cb, + client, NULL); + } + } + else + { + if (RELAY_API_DATA(client, hook_signal_input)) + { + weechat_unhook (RELAY_API_DATA(client, hook_signal_input)); + RELAY_API_DATA(client, hook_signal_input) = NULL; + } + } if (!RELAY_API_DATA(client, hook_signal_upgrade)) { RELAY_API_DATA(client, hook_signal_upgrade) = @@ -147,6 +165,11 @@ relay_api_unhook_signals (struct t_relay_client *client) weechat_unhook (RELAY_API_DATA(client, hook_hsignal_nicklist)); RELAY_API_DATA(client, hook_hsignal_nicklist) = NULL; } + if (RELAY_API_DATA(client, hook_signal_input)) + { + weechat_unhook (RELAY_API_DATA(client, hook_signal_input)); + RELAY_API_DATA(client, hook_signal_input) = NULL; + } if (RELAY_API_DATA(client, hook_signal_upgrade)) { weechat_unhook (RELAY_API_DATA(client, hook_signal_upgrade)); @@ -204,6 +227,7 @@ relay_api_alloc (struct t_relay_client *client) RELAY_API_DATA(client, hook_signal_buffer) = NULL; RELAY_API_DATA(client, hook_hsignal_nicklist) = NULL; + RELAY_API_DATA(client, hook_signal_input) = NULL; RELAY_API_DATA(client, hook_signal_upgrade) = NULL; RELAY_API_DATA(client, buffers_closing) = weechat_hashtable_new ( 32, @@ -213,6 +237,7 @@ relay_api_alloc (struct t_relay_client *client) NULL); RELAY_API_DATA(client, sync_enabled) = 0; RELAY_API_DATA(client, sync_nicks) = 0; + RELAY_API_DATA(client, sync_input) = 0; RELAY_API_DATA(client, sync_colors) = RELAY_API_COLORS_ANSI; } @@ -232,6 +257,7 @@ relay_api_alloc_with_infolist (struct t_relay_client *client, RELAY_API_DATA(client, hook_signal_buffer) = NULL; RELAY_API_DATA(client, hook_hsignal_nicklist) = NULL; + RELAY_API_DATA(client, hook_signal_input) = NULL; RELAY_API_DATA(client, hook_signal_upgrade) = NULL; RELAY_API_DATA(client, buffers_closing) = weechat_hashtable_new ( 32, @@ -243,6 +269,8 @@ relay_api_alloc_with_infolist (struct t_relay_client *client, infolist, "sync_enabled"); RELAY_API_DATA(client, sync_nicks) = weechat_infolist_integer ( infolist, "sync_nicks"); + RELAY_API_DATA(client, sync_input) = weechat_infolist_integer ( + infolist, "sync_input"); RELAY_API_DATA(client, sync_colors) = weechat_infolist_integer ( infolist, "sync_colors"); @@ -281,6 +309,7 @@ relay_api_free (struct t_relay_client *client) { weechat_unhook (RELAY_API_DATA(client, hook_signal_buffer)); weechat_unhook (RELAY_API_DATA(client, hook_hsignal_nicklist)); + weechat_unhook (RELAY_API_DATA(client, hook_signal_input)); weechat_unhook (RELAY_API_DATA(client, hook_signal_upgrade)); weechat_hashtable_free (RELAY_API_DATA(client, buffers_closing)); @@ -317,12 +346,16 @@ relay_api_add_to_infolist (struct t_infolist_item *item, return 0; if (!weechat_infolist_new_var_pointer (item, "hook_hsignal_nicklist", RELAY_API_DATA(client, hook_hsignal_nicklist))) return 0; + if (!weechat_infolist_new_var_pointer (item, "hook_signal_input", RELAY_API_DATA(client, hook_signal_input))) + return 0; if (!weechat_infolist_new_var_pointer (item, "hook_signal_upgrade", RELAY_API_DATA(client, hook_signal_upgrade))) return 0; if (!weechat_infolist_new_var_integer (item, "sync_enabled", RELAY_API_DATA(client, sync_enabled))) return 0; if (!weechat_infolist_new_var_integer (item, "sync_nicks", RELAY_API_DATA(client, sync_nicks))) return 0; + if (!weechat_infolist_new_var_integer (item, "sync_input", RELAY_API_DATA(client, sync_input))) + return 0; if (!weechat_infolist_new_var_integer (item, "sync_colors", RELAY_API_DATA(client, sync_colors))) return 0; @@ -340,6 +373,7 @@ relay_api_print_log (struct t_relay_client *client) { weechat_log_printf (" hook_signal_buffer. . . : %p", RELAY_API_DATA(client, hook_signal_buffer)); weechat_log_printf (" hook_hsignal_nicklist . : %p", RELAY_API_DATA(client, hook_hsignal_nicklist)); + weechat_log_printf (" hook_signal_input . . . : %p", RELAY_API_DATA(client, hook_signal_input)); weechat_log_printf (" hook_signal_upgrade . . : %p", RELAY_API_DATA(client, hook_signal_upgrade)); weechat_log_printf (" buffers_closing. . . . .: %p (hashtable: '%s')", RELAY_API_DATA(client, buffers_closing), @@ -348,6 +382,7 @@ relay_api_print_log (struct t_relay_client *client) "keys_values")); weechat_log_printf (" sync_enabled. . . . . . : %d", RELAY_API_DATA(client, sync_enabled)); weechat_log_printf (" sync_nicks. . . . . . . : %d", RELAY_API_DATA(client, sync_nicks)); + weechat_log_printf (" sync_input. . . . . . . : %d", RELAY_API_DATA(client, sync_input)); weechat_log_printf (" sync_colors . . . . . . : %d", RELAY_API_DATA(client, sync_colors)); } } diff --git a/src/plugins/relay/api/relay-api.h b/src/plugins/relay/api/relay-api.h index be089ee7b..2bef4723b 100644 --- a/src/plugins/relay/api/relay-api.h +++ b/src/plugins/relay/api/relay-api.h @@ -55,10 +55,14 @@ struct t_relay_api_data { struct t_hook *hook_signal_buffer; /* hook for signals "buffer_*" */ struct t_hook *hook_hsignal_nicklist; /* hook for hsignals "nicklist_*" */ + struct t_hook *hook_signal_input; /* hook for signal */ + /* "input_text_changed" */ struct t_hook *hook_signal_upgrade; /* hook for signals "upgrade*" */ struct t_hashtable *buffers_closing; /* ptr -> "id" of buffers closing */ int sync_enabled; /* 1 if sync is enabled */ int sync_nicks; /* 1 if nicks are synchronized */ + int sync_input; /* 1 if input is synchronized */ + /* (WeeChat -> client) */ enum t_relay_api_colors sync_colors; /* colors to send with sync */ }; |