Skip to content

Commit

Permalink
f5j: drag and hide panel (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Aug 23, 2024
1 parent f1de408 commit 073a5f5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion page/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ hoverables.addEventListener('wheel', e => {
fcitx._page((<WheelEvent>e).deltaY > 0)
})

const distribution = process.env.FCITX_DISTRIBUTION
const distribution = <string>process.env.FCITX_DISTRIBUTION ?? ''

let fcitx: FCITX

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions page/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ declare global {
}

type FCITX = {
distribution: string

// C++ APIs that api.ts calls
_onload?: () => void
_log: (s: string) => void
Expand Down
9 changes: 7 additions & 2 deletions page/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 073a5f5

Please sign in to comment.