Skip to content

Commit c4fe919

Browse files
committed
hallelujah
1 parent 94a062b commit c4fe919

File tree

10 files changed

+186
-1
lines changed

10 files changed

+186
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ jobs:
4242
- name: Build
4343
run: |
4444
git apply --directory=fcitx5 patches/fcitx5.patch
45+
git apply --directory=engines/fcitx5-hallelujah patches/hallelujah.patch
4546
PKG_CONFIG_PATH=build/sysroot/usr/lib/pkgconfig cmake -B build -G Xcode \
47+
-DENGINE=hallelujah \
4648
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.cmake \
4749
-DIOS_PLATFORM=SIMULATOR
4850
cmake --build build --config Release

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "fcitx5"]
22
path = fcitx5
33
url = https://github.com/fcitx/fcitx5
4+
[submodule "engines/fcitx5-hallelujah"]
5+
path = engines/fcitx5-hallelujah
6+
url = https://github.com/fcitx-contrib/fcitx5-hallelujah

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ include(AddSwift)
2626
set(KEYBOARD_NAME "Keyboard")
2727
set(KEYBOARD_LANGUAGE "zh-Hans")
2828

29+
set(ENGINE "" CACHE STRING "fcitx5 engine to bundle")
30+
31+
if (ENGINE STREQUAL "hallelujah")
32+
add_definitions(-DHALLELUJAH)
33+
endif()
34+
2935
# For dependencies not to be find via pkg-config
3036
set(LibIntl_DIR "build/sysroot/usr/lib/cmake")
3137
find_package(LibIntl)
@@ -54,5 +60,7 @@ add_subdirectory(fcitx5)
5460

5561
add_subdirectory(iosfrontend)
5662

63+
add_subdirectory(engines)
64+
5765
add_subdirectory(keyboard)
5866
add_subdirectory(src)

engines/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory("fcitx5-${ENGINE}")

engines/fcitx5-hallelujah

Submodule fcitx5-hallelujah added at ac94e7d

install-deps.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
deps=(
22
fmt
3+
json-c
34
libintl
45
libuv
6+
marisa
57
)
68

79
EXTRACT_DIR=build/sysroot/usr
@@ -19,5 +21,6 @@ for dep in "${deps[@]}"; do
1921
tar xjvf cache/$file -C $EXTRACT_DIR
2022
done
2123

22-
sed -i '' "s|=/usr/include|=$(pwd)/$EXTRACT_DIR/include|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc
24+
sed -i '' "s|=/usr/include|=$(pwd)/$EXTRACT_DIR/include|" $EXTRACT_DIR/lib/pkgconfig/{json-c,libuv,marisa}.pc
2325
sed -i '' "s|-L\${libdir} -luv|$(pwd)/$EXTRACT_DIR/lib/libuv.a|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc
26+
sed -E -i '' "s|Libs:.*-l(.*)|Libs: $(pwd)/$EXTRACT_DIR/lib/lib\1.a|" $EXTRACT_DIR/lib/pkgconfig/json-c.pc

keyboard/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ target_link_libraries(keyboard PRIVATE
1818
spell
1919
iosfrontend
2020
SwiftFrontend
21+
"${ENGINE}"
2122
)

keyboard/KeyboardViewController.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,67 @@ class KeyboardViewController: UIInputViewController {
88

99
@IBOutlet var nextKeyboardButton: UIButton!
1010

11+
let keys: [[String]] = [
12+
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
13+
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
14+
["a", "s", "d", "f", "g", "h", "j", "k", "l"],
15+
["z", "x", "c", "v", "b", "n", "m"],
16+
[" "],
17+
]
18+
19+
@objc private func keyPressed(_ sender: UIButton) {
20+
guard let title = sender.currentTitle else { return }
21+
if !processKey(title) {
22+
textDocumentProxy.insertText(title)
23+
}
24+
}
25+
26+
private func createButton(title: String) -> UIButton {
27+
let button = UIButton(type: .system)
28+
button.setTitle(title, for: .normal)
29+
button.titleLabel?.font = UIFont.systemFont(ofSize: 24)
30+
button.backgroundColor = UIColor.gray.withAlphaComponent(0.2)
31+
button.layer.cornerRadius = 8
32+
button.addTarget(self, action: #selector(keyPressed(_:)), for: .touchUpInside)
33+
return button
34+
}
35+
36+
private func setupKeyboardLayout() {
37+
// Create a vertical stack view for rows
38+
let stackView = UIStackView()
39+
stackView.axis = .vertical
40+
stackView.distribution = .fillEqually
41+
stackView.alignment = .fill
42+
stackView.spacing = 5
43+
44+
// Create buttons for each row and add them to the stack view
45+
for row in keys {
46+
let rowStackView = UIStackView()
47+
rowStackView.axis = .horizontal
48+
rowStackView.distribution = .fillEqually
49+
rowStackView.alignment = .fill
50+
rowStackView.spacing = 5
51+
52+
for key in row {
53+
let button = createButton(title: key)
54+
rowStackView.addArrangedSubview(button)
55+
}
56+
stackView.addArrangedSubview(rowStackView)
57+
}
58+
59+
// Add the stack view to the view controller's view
60+
stackView.translatesAutoresizingMaskIntoConstraints = false
61+
view.addSubview(stackView)
62+
63+
// Set up Auto Layout constraints for the stack view
64+
NSLayoutConstraint.activate([
65+
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10),
66+
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10),
67+
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 10),
68+
stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10),
69+
])
70+
}
71+
1172
override func updateViewConstraints() {
1273
super.updateViewConstraints()
1374

@@ -19,6 +80,7 @@ class KeyboardViewController: UIInputViewController {
1980

2081
startFcitx(Bundle.main.bundlePath)
2182
focusIn(self.textDocumentProxy)
83+
setupKeyboardLayout()
2284

2385
// Perform custom UI setup here
2486
self.nextKeyboardButton = UIButton(type: .system)

keyboard/fcitx.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
#include "fcitx.h"
1111
#include "util.h"
1212

13+
#if defined(HALLELUJAH)
14+
15+
#include "../engines/fcitx5-hallelujah/src/hallelujah.h"
16+
#define ENGINE_ADDON "hallelujah"
17+
fcitx::HallelujahFactory
18+
19+
#endif
20+
EngineFactory;
21+
1322
namespace fs = std::filesystem;
1423

1524
fcitx::SpellModuleFactory SpellModuleFactory;
@@ -20,6 +29,8 @@ fcitx::StaticAddonRegistry addons = {
2029
&SpellModuleFactory),
2130
std::make_pair<std::string, fcitx::AddonFactory *>("iosfrontend",
2231
&IosFrontendFactory),
32+
std::make_pair<std::string, fcitx::AddonFactory *>(ENGINE_ADDON,
33+
&EngineFactory),
2334
};
2435

2536
native_streambuf log_streambuf;
@@ -65,3 +76,8 @@ void startFcitx(const char *bundlePath) {
6576
void focusIn(id client) {
6677
return with_fcitx([client] { frontend->focusIn(client); });
6778
}
79+
80+
bool processKey(const char *key) {
81+
return with_fcitx(
82+
[key] { return frontend->keyEvent(fcitx::Key{key}, false); });
83+
}

patches/hallelujah.patch

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 02daeea..bcc8397 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -12,8 +12,6 @@ option(ENABLE_TEST "Build Test" On)
6+
option(BUILD_DATA "Build data" On)
7+
8+
find_package(Gettext REQUIRED)
9+
-find_package(Fcitx5Core 5.0.0 REQUIRED)
10+
-find_package(Fcitx5Module REQUIRED COMPONENTS Spell TestFrontend)
11+
find_package(PkgConfig REQUIRED)
12+
13+
if (NOT TARGET fmt::fmt)
14+
@@ -33,7 +31,7 @@ endif()
15+
add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-hallelujah\")
16+
fcitx5_add_i18n_definition()
17+
18+
-include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")
19+
+include("../../fcitx5/cmake/Fcitx5CompilerSettings.cmake")
20+
21+
add_subdirectory(src)
22+
if (ENABLE_TEST)
23+
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
24+
index 4e8b3f7..eef37ec 100644
25+
--- a/data/CMakeLists.txt
26+
+++ b/data/CMakeLists.txt
27+
@@ -5,3 +5,21 @@ add_custom_target(google ALL
28+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/google_227800_words.bin" DESTINATION ${DEST_DIR} COMPONENT config)
29+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/words.json" DESTINATION ${DEST_DIR} COMPONENT config)
30+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cedict.json" DESTINATION ${DEST_DIR} COMPONENT config)
31+
+
32+
+add_custom_command(
33+
+ TARGET google
34+
+ POST_BUILD COMMAND /bin/zsh -c
35+
+ \"
36+
+ ${CMAKE_COMMAND} -E copy
37+
+ ${CMAKE_CURRENT_BINARY_DIR}/google_227800_words.bin
38+
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/google_227800_words.bin
39+
+ \;
40+
+ ${CMAKE_COMMAND} -E copy
41+
+ ${CMAKE_CURRENT_SOURCE_DIR}/words.json
42+
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/words.json
43+
+ \;
44+
+ ${CMAKE_COMMAND} -E copy
45+
+ ${CMAKE_CURRENT_SOURCE_DIR}/cedict.json
46+
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/hallelujah/cedict.json
47+
+ \"
48+
+)
49+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
50+
index dcbd627..6b0f00d 100644
51+
--- a/src/CMakeLists.txt
52+
+++ b/src/CMakeLists.txt
53+
@@ -1,4 +1,4 @@
54+
-add_library(hallelujah MODULE hallelujah.cpp)
55+
+add_library(hallelujah STATIC hallelujah.cpp)
56+
target_link_libraries(hallelujah Fcitx5::Core Fcitx5::Module::Spell fmt::fmt ${MARISA_TARGET} ${JSONC_TARGET})
57+
install(TARGETS hallelujah DESTINATION "${FCITX_INSTALL_LIBDIR}/fcitx5")
58+
fcitx5_translate_desktop_file(hallelujah.conf.in hallelujah.conf)
59+
@@ -6,3 +6,17 @@ configure_file(hallelujah-addon.conf.in.in hallelujah-addon.conf.in)
60+
fcitx5_translate_desktop_file("${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf.in" hallelujah-addon.conf)
61+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hallelujah.conf" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/inputmethod" COMPONENT config)
62+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf" RENAME hallelujah.conf DESTINATION "${FCITX_INSTALL_PKGDATADIR}/addon" COMPONENT config)
63+
+
64+
+add_custom_command(
65+
+ TARGET hallelujah
66+
+ POST_BUILD COMMAND /bin/sh -c
67+
+ \"
68+
+ ${CMAKE_COMMAND} -E copy
69+
+ ${CMAKE_CURRENT_BINARY_DIR}/hallelujah-addon.conf
70+
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/hallelujah.conf
71+
+ \;
72+
+ ${CMAKE_COMMAND} -E copy
73+
+ ${CMAKE_CURRENT_BINARY_DIR}/hallelujah.conf
74+
+ ${CMAKE_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/inputmethod/hallelujah.conf
75+
+ \"
76+
+)
77+
diff --git a/src/hallelujah.h b/src/hallelujah.h
78+
index 115ad79..c35bd7e 100644
79+
--- a/src/hallelujah.h
80+
+++ b/src/hallelujah.h
81+
@@ -71,7 +71,6 @@ private:
82+
class HallelujahFactory : public AddonFactory {
83+
public:
84+
AddonInstance *create(AddonManager *manager) override {
85+
- registerDomain("fcitx5-hallelujah", FCITX_INSTALL_LOCALEDIR);
86+
return new HallelujahEngine(manager->instance());
87+
}
88+
};

0 commit comments

Comments
 (0)