File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # [ 0701] Loro Collab: 适配 ImGUI
2+ ## 如何测试
3+
4+ ```
5+ xmake f --loro=yes --qt_frontend=no
6+ xmake b stem
7+ xmake r stem
8+ ```
9+
10+ 起服务器
11+ ```
12+ cd tools/loro-server/ && npm install && node server.js
13+ ```
14+
15+ 使用多 ImGui 客户端测试协作
Original file line number Diff line number Diff line change 2727
2828#include < GLFW/glfw3.h> // system clipboard (glfwSet/GetClipboardString)
2929
30+ #ifdef LORO_ENABLED
31+ #include " loro_collab.hpp" // loro_collab_disconnect
32+ #endif
33+
3034#ifndef GL_SILENCE_DEPRECATION
3135#define GL_SILENCE_DEPRECATION
3236#endif
@@ -512,6 +516,11 @@ im_interpose () {
512516
513517void
514518gui_close () {
519+ #ifdef LORO_ENABLED
520+ // 关闭协作会话的 WS,避免进程退出时 curl 在半操作中 teardown(镜像
521+ // qt_gui.cpp 的 gui_close)。
522+ loro_collab_disconnect ();
523+ #endif
515524 if (s_glfw_initialized) {
516525 glfwTerminate ();
517526 s_glfw_initialized= false ;
Original file line number Diff line number Diff line change 2929#include " im_menu.hpp" // im_render_main_menu / im_render_active_popup / im_has_active_popup
3030#include " im_simple_widget.hpp" // editor canvas (main_widget)
3131
32+ #ifdef LORO_ENABLED
33+ #include " loro_collab.hpp" // loro_collab_poll / apply / disconnect
34+ #endif
35+
3236#include " backends/imgui_impl_glfw.h"
3337#include " backends/imgui_impl_opengl3.h"
3438#ifndef __EMSCRIPTEN__
@@ -736,6 +740,22 @@ im_tm_widget_rep::im_main_loop () {
736740
737741 // Drive one TeXmacs tick. 驱动编辑器。
738742 im_interpose ();
743+ #ifdef LORO_ENABLED
744+ // 驱动协同会话:drain WS 回调 + apply_remote。节流到 ~6Hz,镜像
745+ // qt_gui.cpp 的 loro_collab_poll/apply 接入点。Native 与 WASM 都走
746+ // im_main_loop,此处一处覆盖两平台。放在 iconified 检查之前,使最小化时
747+ // 仍保持 CRDT 同步(不依赖渲染管线)。远程光标由 kernel 的
748+ // draw_remote_cursors 画进同一纹理,无需此处处理。
749+ {
750+ static time_t last_loro_poll_time= 0 ;
751+ time_t now = texmacs_time ();
752+ if (now - last_loro_poll_time >= 1000 / 6 ) {
753+ loro_collab_poll ();
754+ loro_collab_apply ();
755+ last_loro_poll_time= now;
756+ }
757+ }
758+ #endif
739759 if (glfwGetWindowAttrib (window, GLFW_ICONIFIED ) != 0 ) {
740760 ImGui_ImplGlfw_Sleep (10 );
741761 return ;
You can’t perform that action at this time.
0 commit comments