Skip to content

Commit ffa5220

Browse files
committedFeb 19, 2024·
Foundation for hangeul <-> alphabet switch feature
1 parent be714bb commit ffa5220

File tree

7 files changed

+77
-1
lines changed

7 files changed

+77
-1
lines changed
 

‎Typoon/Typoon.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<ClCompile Include="platform\windows\main.cpp" />
3232
<ClCompile Include="platform\windows\window_focus.cpp" />
3333
<ClCompile Include="platform\windows\wnd_proc.cpp" />
34+
<ClCompile Include="switch\switch_hangeul_alphabet.cpp" />
3435
<ClCompile Include="utils\config.cpp" />
3536
<ClCompile Include="utils\logger.cpp" />
3637
<ClCompile Include="utils\string.cpp" />
@@ -57,6 +58,7 @@
5758
<ClInclude Include="platform\windows\log.h" />
5859
<ClInclude Include="platform\windows\wnd_proc.h" />
5960
<ClInclude Include="resource.h" />
61+
<ClInclude Include="switch\switch_hangeul_alphabet.h" />
6062
<ClInclude Include="utils\config.h" />
6163
<ClInclude Include="utils\json5_util.h" />
6264
<ClInclude Include="utils\logger.h" />

‎Typoon/Typoon.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
<ClCompile Include="platform\windows\crash_handler.cpp">
8585
<Filter>Source Files</Filter>
8686
</ClCompile>
87+
<ClCompile Include="switch\switch_hangeul_alphabet.cpp">
88+
<Filter>Source Files</Filter>
89+
</ClCompile>
8790
</ItemGroup>
8891
<ItemGroup>
8992
<ClInclude Include="utils\logger.h">
@@ -161,6 +164,9 @@
161164
<ClInclude Include="low_level\crash_handler.h">
162165
<Filter>Header Files</Filter>
163166
</ClInclude>
167+
<ClInclude Include="switch\switch_hangeul_alphabet.h">
168+
<Filter>Header Files</Filter>
169+
</ClInclude>
164170
</ItemGroup>
165171
<ItemGroup>
166172
<ResourceCompile Include="Typoon.rc">

‎Typoon/platform/windows/main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../../common/common.h"
1212
#include "../../match/trigger_trees_per_program.h"
1313
#include "../../parse/parse_match.h"
14+
#include "../../switch/switch_hangeul_alphabet.h"
1415
#include "../../utils/config.h"
1516

1617
#include "log.h"
@@ -74,7 +75,9 @@ int wWinMain(HINSTANCE hInstance, [[maybe_unused]] HINSTANCE hPrevInstance, [[ma
7475
setup_trigger_trees(get_config().matchFilePath);
7576
update_trigger_tree_program_overrides(get_config().programOverrides);
7677
start_hot_key_watcher(window);
78+
setup_switcher();
7779

80+
// TODO: Factor out non-platform-dependent code.
7881
FileChangeWatcher matchChangeWatcher;
7982
const auto lambdaAfterTreeReconstruct = [&matchChangeWatcher]()
8083
{
@@ -192,6 +195,7 @@ int wWinMain(HINSTANCE hInstance, [[maybe_unused]] HINSTANCE hPrevInstance, [[ma
192195
teardown_trigger_trees();
193196
end_hot_key_watcher();
194197
remove_tray_icon();
198+
teardown_switcher();
195199

196200
#ifdef _DEBUG
197201
fclose(fDummy);
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "switch_hangeul_alphabet.h"
2+
3+
#include <algorithm>
4+
5+
#include "../input_multicast/input_multicast.h"
6+
#include "../utils/config.h"
7+
8+
// TODO: listen for config change and resize - make a config change event
9+
std::wstring stroke;
10+
wchar_t letter_being_composed = 0;
11+
12+
13+
void on_input(const InputMessage(&inputs)[MAX_INPUT_COUNT], int length, bool clearAllAgents)
14+
{
15+
if (clearAllAgents)
16+
{
17+
std::ranges::fill(stroke, L'\0');
18+
}
19+
20+
for (int i = 0; i < length; i++)
21+
{
22+
const auto [inputLetter, isBeingComposed] = inputs[i];
23+
24+
if (isBeingComposed)
25+
{
26+
letter_being_composed = inputLetter;
27+
}
28+
else
29+
{
30+
std::ranges::shift_left(stroke, 1);
31+
stroke.back() = inputLetter;
32+
}
33+
}
34+
}
35+
36+
37+
void setup_switcher()
38+
{
39+
input_listeners.emplace_back("switch_hangeul_alphabet", on_input);
40+
stroke.resize(get_config().strokeBuffer, 0);
41+
}
42+
43+
44+
void teardown_switcher()
45+
{
46+
std::erase_if(input_listeners, [](const std::pair<std::string, InputListener>& pair) { return pair.first == "switch_hangeul_alphabet"; });
47+
}
48+
49+
50+
void switch_hangeul_alphabet()
51+
{
52+
53+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
4+
void setup_switcher();
5+
void teardown_switcher();
6+
7+
void switch_hangeul_alphabet();

‎Typoon/utils/config.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct ConfigForParse
6666
std::filesystem::path match_file_path = "match/matches.json5";
6767
int max_backspace_count = 5;
6868
std::string cursor_placeholder = "|_|";
69+
int stroke_buffer = 15;
6970

7071
bool notify_config_load = true;
7172
bool notify_match_load = true;
@@ -82,6 +83,7 @@ struct ConfigForParse
8283
std::move(match_file_path),
8384
max_backspace_count,
8485
{ cursor_placeholder.begin(), cursor_placeholder.end() },
86+
stroke_buffer,
8587
notify_config_load,
8688
notify_match_load,
8789
notify_on_off,
@@ -100,7 +102,8 @@ struct ConfigForParse
100102
};
101103

102104

103-
JSON5_CLASS(ConfigForParse, match_file_path, max_backspace_count, cursor_placeholder, notify_config_load, notify_match_load, notify_on_off, hotkey_toggle_on_off, hotkey_get_program_name, program_overrides)
105+
JSON5_CLASS(ConfigForParse, match_file_path, max_backspace_count, cursor_placeholder, stroke_buffer,
106+
notify_config_load, notify_match_load, notify_on_off, hotkey_toggle_on_off, hotkey_get_program_name, program_overrides)
104107

105108
Config config;
106109

‎Typoon/utils/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Config
2121
std::filesystem::path matchFilePath;
2222
int maxBackspaceCount;
2323
std::wstring cursorPlaceholder;
24+
int strokeBuffer;
2425

2526
bool notifyConfigLoad;
2627
bool notifyMatchLoad;

0 commit comments

Comments
 (0)
Please sign in to comment.