diff --git a/page/api.ts b/page/api.ts index 2fab75c..123e54d 100644 --- a/page/api.ts +++ b/page/api.ts @@ -262,7 +262,7 @@ hoverables.addEventListener('wheel', e => { fcitx._page((e).deltaY > 0) }) -const distribution = process.env.FCITX_DISTRIBUTION +const distribution = process.env.FCITX_DISTRIBUTION ?? '' let fcitx: FCITX @@ -292,6 +292,8 @@ if (distribution === 'fcitx5-js') { document.head.append(style) } +fcitx.distribution = distribution + // JavaScript APIs that webview_candidate_window.cpp calls fcitx.setCandidates = setCandidates fcitx.setLayout = setLayout diff --git a/page/global.d.ts b/page/global.d.ts index 5853b51..2b9e6a5 100644 --- a/page/global.d.ts +++ b/page/global.d.ts @@ -22,6 +22,8 @@ declare global { } type FCITX = { + distribution: string + // C++ APIs that api.ts calls _onload?: () => void _log: (s: string) => void diff --git a/page/ux.ts b/page/ux.ts index ff47549..f023b6d 100644 --- a/page/ux.ts +++ b/page/ux.ts @@ -184,11 +184,16 @@ decoration.addEventListener('mousemove', e => { dragging = true const dx = e.clientX - startX const dy = e.clientY - startY + if (window.fcitx.distribution === 'fcitx5-js') { + // On desktop mouse is always at where drag starts in the html, + // but on f5j mouse can be anywhere during drag. + startX = e.clientX + startY = e.clientY + } dX += dx dY += dy dragOffset = Math.max(dragOffset, dX * dX + dY * dY) - // minus because macOS has bottom-left (0, 0) - resize(dx, -dy, true, false) + resize(dx, dy, true, false) }) decoration.addEventListener('mouseup', e => { diff --git a/src/platform/js.cpp b/src/platform/js.cpp index 6e66e94..3dec931 100644 --- a/src/platform/js.cpp +++ b/src/platform/js.cpp @@ -18,7 +18,7 @@ void WebviewCandidateWindow::set_transparent_background() {} void WebviewCandidateWindow::update_accent_color() {} -void WebviewCandidateWindow::hide() { std::cerr << "hide" << std::endl; } +void WebviewCandidateWindow::hide() { EM_ASM(fcitx.hidePanel()); } void WebviewCandidateWindow::write_clipboard(const std::string &html) {} diff --git a/src/platform/macos.mm b/src/platform/macos.mm index f1db7ed..c3979c3 100644 --- a/src/platform/macos.mm +++ b/src/platform/macos.mm @@ -200,7 +200,7 @@ NSRect getNearestScreenFrame(double x, double y) { if (dragging) { x_ += dx; - y_ += dy; + y_ -= dy; // minus because macOS has bottom-left (0, 0) } else { if (layout_ == layout_t::vertical && writing_mode_ == writing_mode_t::vertical_rl) {