Skip to content

Commit

Permalink
[WIP]capnproto message 001
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Sep 28, 2023
1 parent 60c7a71 commit 72bcce4
Show file tree
Hide file tree
Showing 13 changed files with 833 additions and 2 deletions.
398 changes: 396 additions & 2 deletions RimeWithWeasel/RimeWithWeasel.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions RimeWithWeasel/RimeWithWeasel.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="protocal.capnp.cpp" />
<ClCompile Include="RimeWithWeasel.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand Down
3 changes: 3 additions & 0 deletions RimeWithWeasel/RimeWithWeasel.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<ClCompile Include="WeaselUtility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="protocal.capnp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\RimeWithWeasel.h">
Expand Down
5 changes: 5 additions & 0 deletions RimeWithWeasel/prepare.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set PATH=%PATH%;C:\Users\DELL\Desktop\Dev\weasel_new\capnp\win32\bin
capnp compile -oc++ protocal.capnp
move /Y protocal.capnp.c++ protocal.capnp.cpp
echo #include "stdafx.h" >> protocal.capnp.cpp
move /Y protocal.capnp.h ..\include\
150 changes: 150 additions & 0 deletions RimeWithWeasel/protocal.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
@0xd43fa5654901f1dc;

struct WeaselCommit {
# Text to commit to input field.
text @0 :Text;
}

struct WeaselCandidate {
text @0 :Text;
comment @1 :Text;
label @2 :Text;
}

struct WeaselStatus {
schemaId @0 :Text;
schemaName @1 :Text;
isDisabled @2 :Bool;
isComposing @3 :Bool;
isAsciiMode @4 :Bool;
isFullShape @5 :Bool;
isSimplified @6 :Bool;
isTraditional @7 :Bool;
isAsciiPunct @8 :Bool;
}

struct WeaselContext {
# Input context.
struct WeaselPreedit {
str @0:Text;
start @1:UInt32;
end @2:UInt32;
cursor@3:UInt32;
}

struct WeaselCandidateInfo {
currentPage@0: UInt32;
isLastPage@1: Bool;
totalPages@2: UInt32;
highlighted@3: UInt32;
candies@4: List(Text);
comments@5: List(Text);
labels@6: List(Text);
}
preedit@0: WeaselPreedit;
candidateInfo@1: WeaselCandidateInfo;
}

struct WeaselUIStyle {
#UIStyle
enum CAntiAliasMode {
default @0;
clearType @1;
grayScale @2;
aliased @3;
forceDword@4;
}
enum CPreeditType {
composition @0;
preview @1;
previewAll @2;
}
enum CLayoutType {
layoutVertical @0;
layoutHorizontal @1;
layoutVerticalText @2;
layoutVerticalFullscreen @3;
layoutHorizontalFullscreen @4;
layoutTypeLast @5;
}
enum CLayoutAlignType {
alignBottom @0;
alignCenter @1;
alignTop @2;
}
antialiasMode @0:CAntiAliasMode;
algnType @1:CLayoutAlignType;
preeditType @2:CPreeditType;
layoutType @3:CLayoutType;
verticalTextLeftToRight @4:Bool;
verticalTextWithWrap @5:Bool;
pagingOnScroll @6:Bool;
fontFace @7:Text;
labelFontFace @8:Text;
commentFontFace @9:Text;
mouseHoverMs @10:Int32;
fontPoint @11:Int32;
labelFontPoint @12:Int32;
commentFontPoint @13:Int32;
inlinePreedit @14:Bool;
displayTrayIcon @15:Bool;
asciiTipFollowCursor @16:Bool;
currentZhungIcon @17:Text;
currentAsciiIcon @18:Text;
currentHalfIcon @19:Text;
currentFullIcon @20:Text;
enhancedPosition @21:Bool;
labelTextFormat @22:Text;
markText @23:Text;
minWidth @24:Int32;
maxWidth @25:Int32;
minHeight @26:Int32;
maxHeight @27:Int32;
border @28:Int32;
marginX @29:Int32;
marginY @30:Int32;
spacing @31:Int32;
candidateSpacing @32:Int32;
hiliteSpacing@33:Int32;
hilitePaddingX@34:Int32;
hilitePaddingY@35:Int32;
roundCorner@36:Int32;
roundCornerEx@37:Int32;
shadowRadius@38:Int32;
shadowOffsetX@39:Int32;
shadowOffsetY@40:Int32;
verticalAutoReverse@41:Bool;

textColor@42:Int32;
candidateTextColor@43:Int32;
candidateBackColor@44:Int32;
candidateShadowColor@45:Int32;
candidateBorderColor@46:Int32;
labelTextColor@47:Int32;
commentTextColor@48:Int32;
backColor@49:Int32;
shadowColor@50:Int32;
borderColor@51:Int32;
hilitedTextColor@52:Int32;
hilitedBackColor@53:Int32;
hilitedShadowColor@54:Int32;
hilitedCandidateTextColor@55:Int32;
hilitedCandidateBackColor@56:Int32;
hilitedCandidateShadowColor@57:Int32;
hilitedCandidateBorderColor@58:Int32;
hilitedLabelTextColor@59:Int32;
hilitedCommentTextColor@60:Int32;
hilitedMarkColor@61:Int32;
prevpageColor@62:Int32;
nextpageColor@63:Int32;
clientCaps@64:Int32;
}

struct WeaselRespondData {
commit @0:WeaselCommit;
status @1:WeaselStatus;
context @2:WeaselContext;
inlinePreedit@3:Bool;
style@4:WeaselUIStyle;

}
134 changes: 134 additions & 0 deletions WeaselIPC/ResponseParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
#include <StringAlgorithm.hpp>
#include <WeaselIPC.h>
#include "Deserializer.h"
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <kj/array.h>
#include "protocal.capnp.h"

#ifdef _WIN64
#pragma comment(lib, "capnp-x64.lib")
#pragma comment(lib, "kj-x64.lib")
#else
#pragma comment(lib, "capnp.lib")
#pragma comment(lib, "kj.lib")
#endif

using namespace capnp;
using namespace weasel;

#define TO_WSTRING(str) string_to_wstring(str, CP_UTF8)

ResponseParser::ResponseParser(std::wstring* commit, Context* context, Status* status, Config* config, UIStyle* style)
: p_commit(commit), p_context(context), p_status(status), p_config(config), p_style(style)
{
Expand All @@ -30,6 +45,125 @@ bool ResponseParser::operator() (LPWSTR buffer, UINT length)
return bs.good();
}

bool ResponseParser::operator() (char* buffer, UINT length)
{
auto received_array = kj::ArrayPtr<capnp::word>(reinterpret_cast<capnp::word*>(buffer), length / sizeof(capnp::word));
capnp::FlatArrayMessageReader msg_char_reader(received_array);
auto reader = msg_char_reader.getRoot<WeaselRespondData>();
// get commit
if (reader.hasCommit()) {
auto _str = std::string(reader.getCommit().getText());
*p_commit = string_to_wstring(_str, CP_UTF8);
}
// get status
if (reader.hasStatus()) {
auto _sta = reader.getStatus();
p_status->ascii_mode = _sta.getIsAsciiMode();
p_status->composing = _sta.getIsComposing();
p_status->disabled = _sta.getIsDisabled();
p_status->full_shape = _sta.getIsFullShape();
p_status->schema_id = string_to_wstring(std::string(_sta.getSchemaId()), CP_UTF8);
p_status->schema_name = string_to_wstring(std::string(_sta.getSchemaName()), CP_UTF8);
}
// get context
if (reader.hasContext()) {
auto _ctx = reader.getContext();
if (_ctx.hasCandidateInfo()) {
auto _cinfo = _ctx.getCandidateInfo();
p_context->cinfo.currentPage = _cinfo.getCurrentPage();
p_context->cinfo.highlighted = _cinfo.getHighlighted();
p_context->cinfo.is_last_page = _cinfo.getIsLastPage();
auto _labels = _cinfo.getLabels();
auto _candies = _cinfo.getCandies();
auto _comments = _cinfo.getComments();
auto number_of_candidates = _candies.size();
auto number_of_labels = _labels.size();
auto number_of_comments = _comments.size();
for (auto i = 0; i < number_of_candidates; i++) {
p_context->cinfo.candies.at(i).str = TO_WSTRING(std::string(_candies[i]));
}
for (auto i = 0; i < number_of_labels; i++) {
p_context->cinfo.labels.at(i).str = TO_WSTRING(std::string(_labels[i]));
}
for (auto i = 0; i < number_of_comments; i++) {
p_context->cinfo.comments.at(i).str = TO_WSTRING(std::string(_comments[i]));
}
}
}
// get UIStyle
if (reader.hasStyle()) {
auto _style = reader.getStyle();
p_style->align_type = static_cast<UIStyle::LayoutAlignType>(_style.getAlgnType());
p_style->antialias_mode = static_cast<UIStyle::AntiAliasMode>(_style.getAntialiasMode());
p_style->preedit_type = static_cast<UIStyle::PreeditType>(_style.getPreeditType());
p_style->layout_type = static_cast<UIStyle::LayoutType>(_style.getLayoutType());
p_style->vertical_text_left_to_right = _style.getVerticalTextLeftToRight();
p_style->vertical_text_with_wrap = _style.getVerticalTextWithWrap();
p_style->paging_on_scroll = _style.getPagingOnScroll();
p_style->font_face = TO_WSTRING(std::string(_style.getFontFace()));
p_style->label_font_face = TO_WSTRING(std::string(_style.getLabelFontFace()));
p_style->comment_font_face = TO_WSTRING(std::string(_style.getCommentFontFace()));
p_style->mouse_hover_ms = _style.getMouseHoverMs();
p_style->font_point = _style.getFontPoint();
p_style->label_font_point = _style.getLabelFontPoint();
p_style->comment_font_point = _style.getCommentFontPoint();
p_style->inline_preedit = _style.getInlinePreedit();
p_style->display_tray_icon = _style.getDisplayTrayIcon();
p_style->ascii_tip_follow_cursor = _style.getAsciiTipFollowCursor();
p_style->current_zhung_icon = TO_WSTRING(std::string(_style.getCurrentZhungIcon()));
p_style->current_ascii_icon = TO_WSTRING(std::string(_style.getCurrentAsciiIcon()));
p_style->current_half_icon = TO_WSTRING(std::string(_style.getCurrentHalfIcon()));
p_style->current_full_icon = TO_WSTRING(std::string(_style.getCurrentFullIcon()));
p_style->enhanced_position = _style.getEnhancedPosition();
p_style->label_text_format = TO_WSTRING(std::string(_style.getLabelTextFormat()));
p_style->mark_text = TO_WSTRING(std::string(_style.getMarkText()));
p_style->min_width = _style.getMinWidth();
p_style->max_width = _style.getMaxWidth();
p_style->min_height = _style.getMinHeight();
p_style->max_height = _style.getMaxHeight();
p_style->border = _style.getBorder();
p_style->margin_x = _style.getMarginX();
p_style->margin_y = _style.getMarginY();
p_style->spacing = _style.getSpacing();
p_style->candidate_spacing = _style.getCandidateSpacing();
p_style->hilite_spacing = _style.getHiliteSpacing();
p_style->hilite_padding_x = _style.getHilitePaddingX();
p_style->hilite_padding_y = _style.getHilitePaddingY();
p_style->round_corner = _style.getRoundCorner();
p_style->round_corner_ex = _style.getRoundCornerEx();
p_style->shadow_radius = _style.getShadowRadius();
p_style->shadow_offset_x = _style.getShadowOffsetX();
p_style->shadow_offset_y = _style.getShadowOffsetY();
p_style->vertical_auto_reverse = _style.getVerticalAutoReverse();
p_style->text_color = _style.getTextColor();
p_style->candidate_text_color = _style.getCandidateTextColor();
p_style->candidate_back_color = _style.getCandidateBackColor();
p_style->candidate_shadow_color = _style.getCandidateShadowColor();
p_style->candidate_border_color = _style.getCandidateBorderColor();
p_style->label_text_color = _style.getLabelTextColor();
p_style->comment_text_color = _style.getCommentTextColor();
p_style->back_color = _style.getBackColor();
p_style->shadow_color = _style.getShadowColor();
p_style->border_color = _style.getBorderColor();
p_style->hilited_text_color = _style.getHilitedTextColor();
p_style->hilited_back_color = _style.getHilitedBackColor();
p_style->hilited_shadow_color = _style.getHilitedShadowColor();
p_style->hilited_candidate_text_color = _style.getHilitedCandidateTextColor();
p_style->hilited_candidate_back_color = _style.getHilitedCandidateBackColor();
p_style->hilited_candidate_shadow_color = _style.getHilitedCandidateShadowColor();
p_style->hilited_candidate_border_color = _style.getHilitedCandidateBorderColor();
p_style->hilited_label_text_color = _style.getHilitedLabelTextColor();
p_style->hilited_comment_text_color = _style.getHilitedCommentTextColor();
p_style->hilited_mark_color = _style.getHilitedMarkColor();
p_style->prevpage_color = _style.getPrevpageColor();
p_style->nextpage_color = _style.getNextpageColor();
p_style->client_caps = _style.getClientCaps();
}
// config
p_config->inline_preedit = reader.getInlinePreedit();
return true;
}

void ResponseParser::Feed(const std::wstring& line)
{
// ignore blank lines and comments
Expand Down
5 changes: 5 additions & 0 deletions WeaselIPC/WeaselIPC.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RimeWithWeasel\RimeWithWeasel.vcxproj">
<Project>{1c497821-bd63-4f02-9094-32b185b62f23}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
4 changes: 4 additions & 0 deletions WeaselIPCServer/WeaselServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ DWORD ServerImpl::OnStartSession(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lP
return m_pRequestHandler->AddSession(
reinterpret_cast<LPWSTR>(channel->ReceiveBuffer()),
[this](std::wstring &msg) -> bool {
//[this](char* buffer, UINT length) -> bool {
*channel << msg;
//channel->WriteBuffer(buffer, length);
return true;
}
);
Expand All @@ -206,7 +208,9 @@ DWORD ServerImpl::OnKeyEvent(WEASEL_IPC_COMMAND uMsg, DWORD wParam, DWORD lParam
return 0;

auto eat = [this](std::wstring &msg) -> bool {
//auto eat = [this](char* buffer, UINT length) -> bool {
*channel << msg;
//channel->WriteBuffer(buffer, length);
return true;
};
return m_pRequestHandler->ProcessKeyEvent(KeyEvent(wParam), lParam, eat);
Expand Down
Loading

0 comments on commit 72bcce4

Please sign in to comment.