Skip to content

Commit 14c6d4a

Browse files
authored
initial uipanel (#9)
1 parent 887779c commit 14c6d4a

File tree

10 files changed

+105
-7
lines changed

10 files changed

+105
-7
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717

1818
- name: Lint
1919
run: |
20-
find src keyboard -name '*.cpp' -o -name '*.h' | xargs clang-format -Werror --dry-run
21-
swift-format lint -rs src keyboard
20+
find src keyboard iosfrontend uipanel -name '*.cpp' -o -name '*.h' | xargs clang-format -Werror --dry-run
21+
swift-format lint -rs src keyboard iosfrontend
2222
2323
build:
2424
needs: lint

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ find_host_package(Gettext)
5959
add_subdirectory(fcitx5)
6060

6161
add_subdirectory(iosfrontend)
62+
add_subdirectory(uipanel)
6263

6364
add_subdirectory(engines)
6465

iosfrontend/iosfrontend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
namespace fcitx {
55

66
IosFrontend::IosFrontend(Instance *instance)
7-
: instance_(instance),
8-
focusGroup_("ios", instance->inputContextManager()) {
7+
: instance_(instance), focusGroup_("ios", instance->inputContextManager()) {
98
createInputContext();
109
}
1110

@@ -28,7 +27,7 @@ void IosFrontend::focusIn(id client) {
2827
void IosFrontend::focusOut() { ic_->focusOut(); }
2928

3029
IosInputContext::IosInputContext(IosFrontend *frontend,
31-
InputContextManager &inputContextManager)
30+
InputContextManager &inputContextManager)
3231
: InputContext(inputContextManager, ""), frontend_(frontend) {
3332
CapabilityFlags flags = CapabilityFlag::Preedit;
3433
setCapabilityFlags(flags);

iosfrontend/iosfrontend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
#include <objc/objc.h>
43
#include <fcitx-config/configuration.h>
54
#include <fcitx/addonfactory.h>
65
#include <fcitx/addoninstance.h>
76
#include <fcitx/addonmanager.h>
87
#include <fcitx/focusgroup.h>
98
#include <fcitx/instance.h>
9+
#include <objc/objc.h>
1010

1111
namespace fcitx {
1212

@@ -43,7 +43,7 @@ class IosFrontendFactory : public AddonFactory {
4343
class IosInputContext : public InputContext {
4444
public:
4545
IosInputContext(IosFrontend *frontend,
46-
InputContextManager &inputContextManager);
46+
InputContextManager &inputContextManager);
4747
~IosInputContext();
4848

4949
const char *frontend() const override { return "ios"; }

keyboard/CMakeLists.txt

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

keyboard/fcitx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../fcitx5/src/modules/spell/spell.h"
22
#include "../iosfrontend/iosfrontend.h"
3+
#include "../uipanel/uipanel.h"
34
#include "nativestreambuf.h"
45
#include <fcitx-utils/event.h>
56
#include <fcitx-utils/eventdispatcher.h>
@@ -23,12 +24,15 @@ namespace fs = std::filesystem;
2324

2425
fcitx::SpellModuleFactory SpellModuleFactory;
2526
fcitx::IosFrontendFactory IosFrontendFactory;
27+
fcitx::UIPanelFactory UIPanelFactory;
2628

2729
fcitx::StaticAddonRegistry addons = {
2830
std::make_pair<std::string, fcitx::AddonFactory *>("spell",
2931
&SpellModuleFactory),
3032
std::make_pair<std::string, fcitx::AddonFactory *>("iosfrontend",
3133
&IosFrontendFactory),
34+
std::make_pair<std::string, fcitx::AddonFactory *>("uipanel",
35+
&UIPanelFactory),
3236
std::make_pair<std::string, fcitx::AddonFactory *>(ENGINE_ADDON,
3337
&EngineFactory),
3438
};

uipanel/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_library(uipanel STATIC uipanel.cpp)
2+
target_link_libraries(uipanel Fcitx5::Core)
3+
4+
configure_file(uipanel.conf.in.in uipanel.conf.in @ONLY)
5+
fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/uipanel.conf.in uipanel.conf)
6+
7+
add_custom_command(
8+
TARGET uipanel
9+
POST_BUILD COMMAND /bin/sh -c
10+
\"
11+
${CMAKE_COMMAND} -E copy
12+
${CMAKE_CURRENT_BINARY_DIR}/uipanel.conf
13+
${PROJECT_BINARY_DIR}/keyboard/$<CONFIG>${CMAKE_XCODE_EFFECTIVE_PLATFORMS}/keyboard.appex/share/fcitx5/addon/uipanel.conf
14+
\"
15+
)

uipanel/uipanel.conf.in.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Addon]
2+
Name=UIPanel
3+
Type=StaticLibrary
4+
Library=libuipanel
5+
Category=UI
6+
Version=@PROJECT_VERSION@
7+
Configurable=True

uipanel/uipanel.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <fcitx/inputpanel.h>
2+
3+
#include "uipanel.h"
4+
5+
namespace fcitx {
6+
7+
UIPanel::UIPanel(Instance *instance) : instance_(instance) {}
8+
9+
void UIPanel::update(UserInterfaceComponent component,
10+
InputContext *inputContext) {
11+
switch (component) {
12+
case UserInterfaceComponent::InputPanel: {
13+
const InputPanel &inputPanel = inputContext->inputPanel();
14+
int size = 0;
15+
if (const auto &list = inputPanel.candidateList()) {
16+
size = list->size();
17+
for (int i = 0; i < size; i++) {
18+
const auto &candidate = list->candidate(i);
19+
FCITX_INFO()
20+
<< instance_->outputFilter(inputContext, candidate.text())
21+
.toString();
22+
}
23+
}
24+
break;
25+
}
26+
case UserInterfaceComponent::StatusArea:
27+
break;
28+
}
29+
}
30+
31+
} // namespace fcitx

uipanel/uipanel.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
#include <fcitx/addonfactory.h>
4+
#include <fcitx/addoninstance.h>
5+
#include <fcitx/addonmanager.h>
6+
#include <fcitx/instance.h>
7+
8+
namespace fcitx {
9+
10+
class UIPanel final : public UserInterface {
11+
public:
12+
UIPanel(Instance *);
13+
virtual ~UIPanel() = default;
14+
15+
void reloadConfig() override {}
16+
const Configuration *getConfig() const override { return nullptr; }
17+
void setConfig(const RawConfig &config) override {}
18+
void setSubConfig(const std::string &path,
19+
const RawConfig &config) override {}
20+
21+
Instance *instance() { return instance_; }
22+
23+
bool available() override { return true; }
24+
void suspend() override {}
25+
void resume() override {}
26+
void update(UserInterfaceComponent component,
27+
InputContext *inputContext) override;
28+
29+
private:
30+
Instance *instance_;
31+
};
32+
33+
class UIPanelFactory : public AddonFactory {
34+
public:
35+
AddonInstance *create(AddonManager *manager) override {
36+
return new UIPanel(manager->instance());
37+
}
38+
};
39+
40+
} // namespace fcitx

0 commit comments

Comments
 (0)