Skip to content

Commit

Permalink
fix blur shrunk when borderless (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Sep 29, 2024
1 parent 14689cd commit d36dd67
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pnpm-lock.yaml
dist
.parcel-cache
.cache
test-results
4 changes: 2 additions & 2 deletions include/webview_candidate_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion page/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions page/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GtkWidget *>(w_->window()));
}

Expand Down
12 changes: 6 additions & 6 deletions src/platform/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/webview_candidate_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down
2 changes: 1 addition & 1 deletion tests/global.d.ts
Original file line number Diff line number Diff line change
@@ -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
} | {
Expand Down
4 changes: 2 additions & 2 deletions tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit d36dd67

Please sign in to comment.