diff --git a/.gitignore b/.gitignore index 2d07436..d87e967 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ pnpm-lock.yaml dist .parcel-cache .cache +test-results diff --git a/include/webview_candidate_window.hpp b/include/webview_candidate_window.hpp index c1babf0..8b4f3b9 100644 --- a/include/webview_candidate_window.hpp +++ b/include/webview_candidate_window.hpp @@ -75,8 +75,8 @@ class WebviewCandidateWindow : public CandidateWindow { void resize(double dx, double dy, double anchor_top, double anchor_right, double anchor_bottom, double anchor_left, double panel_top, double panel_right, double panel_bottom, double panel_left, - double panel_radius, double width, double height, - bool dragging); + double panel_radius, double border_width, double width, + double height, bool dragging); void write_clipboard(const std::string &html); void *platform_data = nullptr; diff --git a/page/global.d.ts b/page/global.d.ts index 75fa0bd..fa6e60f 100644 --- a/page/global.d.ts +++ b/page/global.d.ts @@ -34,7 +34,7 @@ declare global { _scroll: (start: number, length: number) => void _askActions: (index: number) => void _action: (index: number, id: number) => void - _resize: (dx: number, dy: number, anchorTop: number, anchorRight: number, anchorBottom: number, anchorLeft: number, panelTop: number, panelRight: number, panelBottom: number, panelLeft: number, panelRadius: number, fullWidth: number, fullHeight: number, dragging: boolean) => void + _resize: (dx: number, dy: number, anchorTop: number, anchorRight: number, anchorBottom: number, anchorLeft: number, panelTop: number, panelRight: number, panelBottom: number, panelLeft: number, panelRadius: number, borderWidth: number, fullWidth: number, fullHeight: number, dragging: boolean) => void // JavaScript APIs that webview_candidate_window.mm calls setCandidates: (cands: Candidate[], highlighted: number, markText: string, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) => void diff --git a/page/ux.ts b/page/ux.ts index 9139ce5..559bc60 100644 --- a/page/ux.ts +++ b/page/ux.ts @@ -82,8 +82,10 @@ export function resize( } const pRect = panel.getBoundingClientRect() - const pRadius = Math.max(...getComputedStyle(panel).borderRadius.split(' ').map(Number.parseFloat)) - window.fcitx._resize(dx, dy, anchorTop, anchorRight, anchorBottom, anchorLeft, pRect.top, pRect.right, pRect.bottom, pRect.left, pRadius, right, bottom, dragging) + const { borderRadius, borderWidth } = getComputedStyle(panel) + const bWidth = Math.max(...borderWidth.split(' ').map(Number.parseFloat)) + const pRadius = Math.max(...borderRadius.split(' ').map(Number.parseFloat)) + window.fcitx._resize(dx, dy, anchorTop, anchorRight, anchorBottom, anchorLeft, pRect.top, pRect.right, pRect.bottom, pRect.left, pRadius, bWidth, right, bottom, dragging) } adaptWindowSize(hasContextmenu) if (!dragging) { diff --git a/src/platform/js.cpp b/src/platform/js.cpp index d2e56d0..eb0ddaf 100644 --- a/src/platform/js.cpp +++ b/src/platform/js.cpp @@ -27,8 +27,8 @@ void WebviewCandidateWindow::resize(double dx, double dy, double anchor_top, double anchor_left, double panel_top, double panel_right, double panel_bottom, double panel_left, double panel_radius, - double width, double height, - bool dragging) { + double border_width, double width, + double height, bool dragging) { EM_ASM(fcitx.placePanel($0, $1, $2, $3, $4), dx, dy, anchor_top, anchor_left, dragging); } diff --git a/src/platform/linux.cpp b/src/platform/linux.cpp index c4dd360..a3dc446 100644 --- a/src/platform/linux.cpp +++ b/src/platform/linux.cpp @@ -46,8 +46,8 @@ void WebviewCandidateWindow::resize(double dx, double dy, double anchor_top, double anchor_left, double panel_top, double panel_right, double panel_bottom, double panel_left, double panel_radius, - double width, double height, - bool dragging) { + double border_width, double width, + double height, bool dragging) { gtk_widget_show_all(static_cast(w_->window())); } diff --git a/src/platform/macos.mm b/src/platform/macos.mm index 465076a..2da3e44 100644 --- a/src/platform/macos.mm +++ b/src/platform/macos.mm @@ -231,8 +231,8 @@ NSRect getNearestScreenFrame(double x, double y) { double anchor_left, double panel_top, double panel_right, double panel_bottom, double panel_left, double panel_radius, - double width, double height, - bool dragging) { + double border_width, double width, + double height, bool dragging) { const int gap = 4; const int preedit_height = 24; NSRect frame = getNearestScreenFrame(cursor_x_, cursor_y_); @@ -278,10 +278,10 @@ NSRect getNearestScreenFrame(double x, double y) { [window orderFront:nil]; // Update the blur view - panel_right -= 1; // Shrink the blur view a bit - panel_left += 1; // to avoid the border being too thick. - panel_top += 1; - panel_bottom -= 1; + panel_right -= border_width; // Shrink the blur view a bit + panel_left += border_width; // to avoid the border being too thick. + panel_top += border_width; + panel_bottom -= border_width; auto blurView = window.blurView; NSRect blurViewRect = NSMakeRect(panel_left, height - panel_bottom, diff --git a/src/webview_candidate_window.cpp b/src/webview_candidate_window.cpp index 2544a13..714da12 100644 --- a/src/webview_candidate_window.cpp +++ b/src/webview_candidate_window.cpp @@ -47,11 +47,12 @@ WebviewCandidateWindow::WebviewCandidateWindow() [this](double dx, double dy, double anchor_top, double anchor_right, double anchor_bottom, double anchor_left, double panel_top, double panel_right, double panel_bottom, double panel_left, - double panel_radius, double width, double height, - bool dragging) { + double panel_radius, double border_width, double width, + double height, bool dragging) { resize(dx, dy, anchor_top, anchor_right, anchor_bottom, anchor_left, panel_top, panel_right, panel_bottom, - panel_left, panel_radius, width, height, dragging); + panel_left, panel_radius, border_width, width, height, + dragging); }); bind("_select", [this](int i) { select_callback(i); }); diff --git a/tests/global.d.ts b/tests/global.d.ts index 35039ec..4b52455 100644 --- a/tests/global.d.ts +++ b/tests/global.d.ts @@ -1,6 +1,6 @@ declare global { type CppCall = { - resize: [number, number, number, number, number, number, number, number, number, number, number, number, number, boolean] + resize: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, boolean] } | { select: number } | { diff --git a/tests/util.ts b/tests/util.ts index bc26f5c..d4c6db1 100644 --- a/tests/util.ts +++ b/tests/util.ts @@ -10,9 +10,9 @@ export async function init(page: Page) { await page.evaluate(() => { window.fcitx.setTheme(2) window.cppCalls = [] - window.fcitx._resize = (dx: number, dy: number, anchorTop: number, anchorRight: number, anchorBottom: number, anchorLeft: number, panelTop: number, panelRight: number, panelBottom: number, panelLeft: number, panelRadius: number, fullWidth: number, fullHeight: number, dragging: boolean) => { + window.fcitx._resize = (dx: number, dy: number, anchorTop: number, anchorRight: number, anchorBottom: number, anchorLeft: number, panelTop: number, panelRight: number, panelBottom: number, panelLeft: number, panelRadius: number, borderWidth: number, fullWidth: number, fullHeight: number, dragging: boolean) => { window.cppCalls.push({ - resize: [dx, dy, anchorTop, anchorRight, anchorBottom, anchorLeft, panelTop, panelRight, panelBottom, panelLeft, panelRadius, fullWidth, fullHeight, dragging], + resize: [dx, dy, anchorTop, anchorRight, anchorBottom, anchorLeft, panelTop, panelRight, panelBottom, panelLeft, panelRadius, borderWidth, fullWidth, fullHeight, dragging], }) } window.fcitx._select = (index: number) => {