Skip to content

Commit ca40f24

Browse files
committed
drop upstreamed patch
1 parent 769c3ae commit ca40f24

File tree

7 files changed

+152
-193
lines changed

7 files changed

+152
-193
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
1010
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE")
1111
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE")
1212
add_compile_options(-fPIC -fexceptions)
13+
# createDefaultEventLoop is called by libFcitx5Utils.so but implemented in event_js.cpp.
14+
add_link_options(-sERROR_ON_UNDEFINED_SYMBOLS=0)
1315

1416
set(PREBUILDER_LIB_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/lib")
1517
set(PREBUILDER_SHARE_DIR "${PROJECT_BINARY_DIR}/sysroot/usr/share")

fcitx5-webview

patches/fcitx5.patch

Lines changed: 2 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index aa90bad4..b4641520 100644
3-
--- a/CMakeLists.txt
4-
+++ b/CMakeLists.txt
5-
@@ -70,7 +70,7 @@ if (NOT TARGET Systemd::Systemd)
6-
pkg_get_variable(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "dbus-1" "system_bus_default_address")
7-
endif()
8-
9-
- if (NOT LIBUV_TARGET)
10-
+ if (NOT LIBUV_TARGET AND NOT EMSCRIPTEN)
11-
if (NOT (TARGET PkgConfig::LibUV))
12-
pkg_check_modules(LibUV REQUIRED IMPORTED_TARGET "libuv")
13-
endif()
141
diff --git a/src/lib/fcitx-config/CMakeLists.txt b/src/lib/fcitx-config/CMakeLists.txt
152
index 85c9865b..3a995ca1 100644
163
--- a/src/lib/fcitx-config/CMakeLists.txt
@@ -26,32 +13,10 @@ index 85c9865b..3a995ca1 100644
2613
)
2714
target_include_directories(Fcitx5Config PUBLIC
2815
diff --git a/src/lib/fcitx-utils/CMakeLists.txt b/src/lib/fcitx-utils/CMakeLists.txt
29-
index dd67e07d..21680660 100644
16+
index a1f18886..6f9a5832 100644
3017
--- a/src/lib/fcitx-utils/CMakeLists.txt
3118
+++ b/src/lib/fcitx-utils/CMakeLists.txt
32-
@@ -27,14 +27,18 @@ if (ENABLE_DBUS)
33-
endif()
34-
endif()
35-
36-
-if (NOT TARGET Systemd::Systemd)
37-
+if (TARGET Systemd::Systemd)
38-
set(FCITX_UTILS_SOURCES
39-
${FCITX_UTILS_SOURCES}
40-
- event_libuv.cpp)
41-
+ event_sdevent.cpp)
42-
+elseif (EMSCRIPTEN)
43-
+ set(FCITX_UTILS_SOURCES
44-
+ ${FCITX_UTILS_SOURCES}
45-
+ event_js.cpp)
46-
else()
47-
set(FCITX_UTILS_SOURCES
48-
${FCITX_UTILS_SOURCES}
49-
- event_sdevent.cpp)
50-
+ event_libuv.cpp)
51-
endif()
52-
53-
set(FCITX_UTILS_SOURCES
54-
@@ -121,8 +125,7 @@ ecm_setup_version(PROJECT
19+
@@ -119,8 +119,7 @@ ecm_setup_version(PROJECT
5520

5621
add_library(Fcitx5Utils SHARED ${FCITX_UTILS_SOURCES})
5722
set_target_properties(Fcitx5Utils
@@ -61,160 +26,6 @@ index dd67e07d..21680660 100644
6126
EXPORT_NAME Utils
6227
)
6328
target_include_directories(Fcitx5Utils PUBLIC
64-
@@ -135,7 +138,7 @@ if(LIBKVM_FOUND)
65-
endif()
66-
67-
if (NOT TARGET Systemd::Systemd)
68-
- target_link_libraries(Fcitx5Utils PRIVATE ${LIBUV_TARGET})
69-
+ # target_link_libraries(Fcitx5Utils PRIVATE ${LIBUV_TARGET})
70-
if (ENABLE_DBUS)
71-
target_link_libraries(Fcitx5Utils PRIVATE PkgConfig::DBus)
72-
endif()
73-
diff --git a/src/lib/fcitx-utils/event_js.cpp b/src/lib/fcitx-utils/event_js.cpp
74-
new file mode 100644
75-
index 00000000..68f7ee7f
76-
--- /dev/null
77-
+++ b/src/lib/fcitx-utils/event_js.cpp
78-
@@ -0,0 +1,139 @@
79-
+#include <cassert>
80-
+#include <emscripten.h>
81-
+#include "event.h"
82-
+#include "log.h"
83-
+
84-
+namespace fcitx {
85-
+
86-
+template <typename Interface>
87-
+struct JSEventSourceBase : public Interface {
88-
+public:
89-
+ ~JSEventSourceBase() override {}
90-
+
91-
+ bool isEnabled() const override { return enabled_; }
92-
+
93-
+ void setEnabled(bool enabled) override { enabled_ = enabled; }
94-
+
95-
+ bool isOneShot() const override { return oneShot_; }
96-
+
97-
+ void setOneShot() override { oneShot_ = true; }
98-
+
99-
+private:
100-
+ bool enabled_ = false;
101-
+ bool oneShot_ = false;
102-
+};
103-
+
104-
+struct JSEventSource : public JSEventSourceBase<EventSource> {
105-
+ JSEventSource(EventCallback _callback)
106-
+ : callback_(std::make_shared<EventCallback>(std::move(_callback))) {}
107-
+
108-
+ std::shared_ptr<EventCallback> callback_;
109-
+};
110-
+
111-
+struct JSEventSourceIO : public JSEventSourceBase<EventSourceIO> {
112-
+ JSEventSourceIO(IOCallback _callback) {}
113-
+
114-
+ int fd() const override { return 0; }
115-
+
116-
+ void setFd(int fd) override {}
117-
+
118-
+ IOEventFlags events() const override { return IOEventFlag::In; }
119-
+
120-
+ void setEvents(IOEventFlags flags) override {}
121-
+
122-
+ IOEventFlags revents() const override { return IOEventFlag::In; }
123-
+};
124-
+
125-
+void TimeEventCallback(void *arg);
126-
+
127-
+struct JSEventSourceTime : public JSEventSourceBase<EventSourceTime> {
128-
+ JSEventSourceTime(TimeCallback _callback, uint64_t time, clockid_t clockid)
129-
+ : callback_(std::make_shared<TimeCallback>(std::move(_callback))),
130-
+ time_(time), clockid_(clockid) {
131-
+ assert(clockid == CLOCK_MONOTONIC);
132-
+ setOneShot();
133-
+ }
134-
+
135-
+ void setOneShot() override {
136-
+ int t = std::max<int64_t>(0, time_ - now(CLOCK_MONOTONIC)) / 1000;
137-
+ emscripten_async_call(TimeEventCallback, this, t);
138-
+ }
139-
+
140-
+ uint64_t time() const override { return time_; }
141-
+
142-
+ void setTime(uint64_t time) override { time_ = time; }
143-
+
144-
+ uint64_t accuracy() const override { return 0; }
145-
+
146-
+ void setAccuracy(uint64_t time) override {}
147-
+
148-
+ clockid_t clock() const override { return clockid_; }
149-
+
150-
+ std::shared_ptr<TimeCallback> callback_;
151-
+
152-
+private:
153-
+ uint64_t time_;
154-
+ clockid_t clockid_;
155-
+};
156-
+
157-
+void TimeEventCallback(void *arg) {
158-
+ auto source = static_cast<JSEventSourceTime *>(arg);
159-
+ (*source->callback_)(source, source->time());
160-
+}
161-
+
162-
+class EventLoopPrivate {
163-
+public:
164-
+ EventLoopPrivate() {}
165-
+
166-
+ ~EventLoopPrivate() {}
167-
+};
168-
+
169-
+EventLoop::EventLoop() : d_ptr(std::make_unique<EventLoopPrivate>()) {}
170-
+
171-
+EventLoop::~EventLoop() = default;
172-
+
173-
+const char *EventLoop::impl() { return "js-event"; }
174-
+
175-
+void *EventLoop::nativeHandle() { return nullptr; }
176-
+
177-
+bool EventLoop::exec() { return true; }
178-
+
179-
+void EventLoop::exit() {}
180-
+
181-
+std::unique_ptr<EventSourceIO> EventLoop::addIOEvent(int fd, IOEventFlags flags,
182-
+ IOCallback callback) {
183-
+ FCITX_D();
184-
+ auto source = std::make_unique<JSEventSourceIO>(std::move(callback));
185-
+ return source;
186-
+}
187-
+
188-
+std::unique_ptr<EventSourceTime>
189-
+EventLoop::addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy,
190-
+ TimeCallback callback) {
191-
+ auto source =
192-
+ std::make_unique<JSEventSourceTime>(std::move(callback), usec, clock);
193-
+ return source;
194-
+}
195-
+
196-
+std::unique_ptr<EventSource> EventLoop::addExitEvent(EventCallback callback) {
197-
+ FCITX_D();
198-
+ auto source = std::make_unique<JSEventSource>(std::move(callback));
199-
+ return source;
200-
+}
201-
+
202-
+std::unique_ptr<EventSource> EventLoop::addDeferEvent(EventCallback callback) {
203-
+ return addTimeEvent(
204-
+ CLOCK_MONOTONIC, now(CLOCK_MONOTONIC), 0,
205-
+ [callback = std::move(callback)](EventSourceTime *source, uint64_t) {
206-
+ return callback(source);
207-
+ });
208-
+}
209-
+
210-
+std::unique_ptr<EventSource> EventLoop::addPostEvent(EventCallback callback) {
211-
+ return addTimeEvent(
212-
+ CLOCK_MONOTONIC, now(CLOCK_MONOTONIC), 0,
213-
+ [callback = std::move(callback)](EventSourceTime *source, uint64_t) {
214-
+ return callback(source);
215-
+ });
216-
+}
217-
+} // namespace fcitx
21829
diff --git a/src/lib/fcitx/CMakeLists.txt b/src/lib/fcitx/CMakeLists.txt
21930
index df15dd57..36312bab 100644
22031
--- a/src/lib/fcitx/CMakeLists.txt

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_executable(Fcitx5
44
input_method.cpp
55
config.cpp
66
action.cpp
7+
event_js.cpp
78
)
89

910
target_include_directories(Fcitx5 PRIVATE

src/event_js.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include "event_js.h"
2+
#include <emscripten.h>
3+
#include <fcitx-utils/event_p.h>
4+
#include <fcitx-utils/log.h>
5+
6+
namespace fcitx {
7+
8+
std::unique_ptr<EventLoopInterface> createDefaultEventLoop() {
9+
return std::make_unique<JSEventLoop>();
10+
}
11+
12+
const char *defaultEventLoopImplementation() { return "js"; }
13+
14+
template <typename Interface> struct JSEventSourceBase : public Interface {
15+
public:
16+
~JSEventSourceBase() override {}
17+
18+
bool isEnabled() const override { return enabled_; }
19+
20+
void setEnabled(bool enabled) override { enabled_ = enabled; }
21+
22+
bool isOneShot() const override { return oneShot_; }
23+
24+
void setOneShot() override { oneShot_ = true; }
25+
26+
private:
27+
bool enabled_ = false;
28+
bool oneShot_ = false;
29+
};
30+
31+
struct JSEventSource : public JSEventSourceBase<EventSource> {
32+
JSEventSource(EventCallback _callback)
33+
: callback_(std::make_shared<EventCallback>(std::move(_callback))) {}
34+
35+
std::shared_ptr<EventCallback> callback_;
36+
};
37+
38+
struct JSEventSourceIO : public JSEventSourceBase<EventSourceIO> {
39+
JSEventSourceIO(IOCallback _callback) {}
40+
41+
int fd() const override { return 0; }
42+
43+
void setFd(int fd) override {}
44+
45+
IOEventFlags events() const override { return IOEventFlag::In; }
46+
47+
void setEvents(IOEventFlags flags) override {}
48+
49+
IOEventFlags revents() const override { return IOEventFlag::In; }
50+
};
51+
52+
void TimeEventCallback(void *arg);
53+
54+
struct JSEventSourceTime : public JSEventSourceBase<EventSourceTime> {
55+
JSEventSourceTime(TimeCallback _callback, uint64_t time, clockid_t clockid)
56+
: callback_(std::make_shared<TimeCallback>(std::move(_callback))),
57+
time_(time), clockid_(clockid) {
58+
setOneShot();
59+
}
60+
61+
void setOneShot() override {
62+
int t = std::max<int64_t>(0, time_ - now(CLOCK_MONOTONIC)) / 1000;
63+
emscripten_async_call(TimeEventCallback, this, t);
64+
}
65+
66+
uint64_t time() const override { return time_; }
67+
68+
void setTime(uint64_t time) override { time_ = time; }
69+
70+
uint64_t accuracy() const override { return 0; }
71+
72+
void setAccuracy(uint64_t time) override {}
73+
74+
clockid_t clock() const override { return clockid_; }
75+
76+
std::shared_ptr<TimeCallback> callback_;
77+
78+
private:
79+
uint64_t time_;
80+
clockid_t clockid_;
81+
};
82+
83+
void TimeEventCallback(void *arg) {
84+
auto source = static_cast<JSEventSourceTime *>(arg);
85+
(*source->callback_)(source, source->time());
86+
}
87+
88+
std::unique_ptr<EventSourceIO>
89+
JSEventLoop::addIOEvent(int fd, IOEventFlags flags, IOCallback callback) {
90+
auto source = std::make_unique<JSEventSourceIO>(std::move(callback));
91+
return source;
92+
}
93+
94+
std::unique_ptr<EventSourceTime>
95+
JSEventLoop::addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy,
96+
TimeCallback callback) {
97+
auto source =
98+
std::make_unique<JSEventSourceTime>(std::move(callback), usec, clock);
99+
return source;
100+
}
101+
102+
std::unique_ptr<EventSource> JSEventLoop::addExitEvent(EventCallback callback) {
103+
auto source = std::make_unique<JSEventSource>(std::move(callback));
104+
return source;
105+
}
106+
107+
std::unique_ptr<EventSource>
108+
JSEventLoop::addDeferEvent(EventCallback callback) {
109+
return addTimeEvent(
110+
CLOCK_MONOTONIC, now(CLOCK_MONOTONIC), 0,
111+
[callback = std::move(callback)](EventSourceTime *source, uint64_t) {
112+
return callback(source);
113+
});
114+
}
115+
116+
std::unique_ptr<EventSource> JSEventLoop::addPostEvent(EventCallback callback) {
117+
FCITX_ERROR() << "Not implemented";
118+
return nullptr;
119+
}
120+
121+
} // namespace fcitx

src/event_js.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <fcitx-utils/eventloopinterface.h>
4+
5+
namespace fcitx {
6+
class JSEventLoop : public EventLoopInterface {
7+
public:
8+
JSEventLoop() = default;
9+
~JSEventLoop() override = default;
10+
bool exec() override { return true; }
11+
void exit() override {}
12+
const char *implementation() const override { return "js"; }
13+
void *nativeHandle() override { return nullptr; }
14+
15+
std::unique_ptr<EventSourceIO> addIOEvent(int fd, IOEventFlags flags,
16+
IOCallback callback) override;
17+
std::unique_ptr<EventSourceTime>
18+
addTimeEvent(clockid_t clock, uint64_t usec, uint64_t accuracy,
19+
TimeCallback callback) override;
20+
std::unique_ptr<EventSource> addExitEvent(EventCallback callback) override;
21+
std::unique_ptr<EventSource> addDeferEvent(EventCallback callback) override;
22+
std::unique_ptr<EventSource> addPostEvent(EventCallback callback) override;
23+
};
24+
} // namespace fcitx

0 commit comments

Comments
 (0)