Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/desktop-tauri/src-tauri/src/floatbar/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,11 @@ pub fn resize(
height: f64,
click_through: bool,
) -> Result<(), String> {
let width = width.ceil().clamp(1.0, u32::MAX as f64) as u32;
let height = height.ceil().clamp(1.0, u32::MAX as f64) as u32;

window
.set_size(LogicalSize::new(width, height))
.set_size(PhysicalSize::new(width, height))
.map_err(|e| e.to_string())?;
apply_no_activate(window);
apply_click_through(window, click_through);
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src/floatbar/FloatBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ body.floatbar-window #root {
* group reads like a compact widget sitting on the Windows taskbar. */
.floatbar {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
gap: calc(4px * var(--floatbar-scale, 1));
Expand Down
40 changes: 40 additions & 0 deletions apps/desktop-tauri/src/floatbar/FloatBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,46 @@ describe("FloatBar", () => {
});
});

it("resizes the native window in physical pixels at the WebView DPI", async () => {
tauriMocks.getCachedProviders.mockResolvedValue([]);
tauriMocks.getSettingsSnapshot.mockResolvedValue(settings());
const originalDevicePixelRatio = window.devicePixelRatio;
Object.defineProperty(window, "devicePixelRatio", {
configurable: true,
value: 1.5,
});
const rectSpy = vi
.spyOn(HTMLElement.prototype, "getBoundingClientRect")
.mockReturnValue({
x: 0,
y: 0,
width: 100,
height: 20,
top: 0,
right: 100,
bottom: 20,
left: 0,
toJSON: () => ({}),
});

try {
renderFloatBar(bootstrap());

await waitFor(() => {
expect(coreMocks.invoke).toHaveBeenCalledWith("resize_float_bar", {
width: 162,
height: 42,
});
});
} finally {
rectSpy.mockRestore();
Object.defineProperty(window, "devicePixelRatio", {
configurable: true,
value: originalDevicePixelRatio,
});
}
});

it("uses the localized reset formatter in pill tooltips", async () => {
const resetsAt = new Date(Date.now() + 3 * 60 * 60_000 + 42 * 60_000).toISOString();
tauriMocks.getCachedProviders.mockResolvedValue([
Expand Down
16 changes: 14 additions & 2 deletions apps/desktop-tauri/src/floatbar/FloatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,14 @@ export default function FloatBar({ state }: { state: BootstrapState }) {
resizeRafRef.current = null;
const rect = el.getBoundingClientRect();
const padding = 8;
const w = Math.ceil(rect.width + padding);
const h = Math.ceil(rect.height + padding);
const dpr =
Number.isFinite(window.devicePixelRatio) && window.devicePixelRatio > 0
? window.devicePixelRatio
: 1;
// DOM measurements are CSS pixels; the native command accepts physical
// pixels so the window remains correctly sized on scaled displays.
const w = Math.ceil(Math.ceil(rect.width + padding) * dpr);
const h = Math.ceil(Math.ceil(rect.height + padding) * dpr);
const last = lastResizeRef.current;
if (last && Math.abs(last.w - w) <= 1 && Math.abs(last.h - h) <= 1) return;
lastResizeRef.current = { w, h };
Expand Down Expand Up @@ -411,6 +417,12 @@ export default function FloatBar({ state }: { state: BootstrapState }) {
return () => observer.disconnect();
}, [resizeToContent]);

useEffect(() => {
// Re-measure after moving onto a monitor with a different scale factor.
window.addEventListener("resize", resizeToContent);
return () => window.removeEventListener("resize", resizeToContent);
}, [resizeToContent]);

useEffect(
() => () => {
if (resizeRafRef.current !== null) {
Expand Down
Loading