Skip to content

Commit

Permalink
feat(rime_api): add RimeApi::set_input (rime#771)
Browse files Browse the repository at this point in the history
resolve rime#547
  • Loading branch information
imfuxiao authored and fxliang committed Feb 2, 2024
1 parent 62e0f25 commit 7630d62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,17 @@ const char* RimeGetStateLabel(RimeSessionId session_id,
.str;
}

RIME_API Bool RimeSetInput(RimeSessionId session_id, const char* input) {
an<Session> session(Service::instance().GetSession(session_id));
if (!session)
return False;
Context* ctx = session->context();
if (!ctx)
return False;
ctx->set_input(input);
return True;
}

RIME_API RimeApi* rime_get_api() {
static RimeApi s_api = {0};
if (!s_api.data_size) {
Expand Down Expand Up @@ -1177,6 +1188,7 @@ RIME_API RimeApi* rime_get_api() {
s_api.delete_candidate = &RimeDeleteCandidate;
s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage;
s_api.get_state_label_abbreviated = &RimeGetStateLabelAbbreviated;
s_api.set_input = &RimeSetInput;
}
return &s_api;
}
3 changes: 3 additions & 0 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ RIME_API Bool RimeConfigUpdateSignature(RimeConfig* config, const char* signer);
RIME_API Bool RimeSimulateKeySequence(RimeSessionId session_id,
const char* key_sequence);

RIME_API Bool RimeSetInput(RimeSessionId session_id, const char* input);
// Module

/*!
Expand Down Expand Up @@ -644,6 +645,8 @@ typedef struct rime_api_t {
const char* option_name,
Bool state,
Bool abbreviated);

Bool (*set_input)(RimeSessionId session_id, const char* input);
} RimeApi;

//! API entry
Expand Down

0 comments on commit 7630d62

Please sign in to comment.