burnrate 0.1.5

Desktop usage monitor for Claude Code, Codex, OpenRouter, and Runpod quotas, credits, spend, and subscription limits.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
use std::sync::Mutex;
use std::time::{Duration, Instant};

use chrono::Utc;
use tauri::{
    App, AppHandle, Emitter, Manager, PhysicalPosition, PhysicalSize, Wry,
    image::Image,
    menu::{IsMenuItem, Menu, MenuItem},
    tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
};

use crate::models::{SnapshotStatus, TraySummary, UsageSnapshot};

const TRAY_ID: &str = "main";
pub(crate) const MAIN_WINDOW: &str = "main";
pub(crate) const TRAY_WINDOW: &str = "tray";

/// After the popover hides (toggle or blur), ignore a re-show for this long.
/// Clicking the status item first blurs the popover (hiding it) and then fires
/// a click event; without this guard the click would immediately reopen it.
const TRAY_REOPEN_GUARD: Duration = Duration::from_millis(250);
/// Gap (in logical px, scaled to physical at use) between the popover and the
/// work-area edges, and the drop below the cursor.
const TRAY_MARGIN: f64 = 8.0;
const TRAY_OFFSET_Y: f64 = 12.0;

/// Runtime UI state for the tray popover window, managed by Tauri. Kept separate
/// from `AppState` so window concerns don't leak into config/provider state.
#[derive(Default)]
pub(crate) struct TrayWindowState {
    inner: Mutex<TrayWindowInner>,
}

#[derive(Default)]
struct TrayWindowInner {
    /// When the popover was last hidden (toggle or blur), to drive the reopen guard.
    last_hidden_at: Option<Instant>,
    /// Cursor anchor (global physical desktop coords) recorded at show time, so a
    /// later content resize can re-run `popup_position` and stay anchored on the
    /// monitor where the tray was clicked.
    last_anchor: Option<PhysicalPosition<f64>>,
}

impl TrayWindowState {
    fn mark_hidden(&self) {
        self.inner
            .lock()
            .expect("tray window state lock")
            .last_hidden_at = Some(Instant::now());
    }

    fn set_anchor(&self, anchor: PhysicalPosition<f64>) {
        self.inner
            .lock()
            .expect("tray window state lock")
            .last_anchor = Some(anchor);
    }

    pub(crate) fn anchor(&self) -> Option<PhysicalPosition<f64>> {
        self.inner
            .lock()
            .expect("tray window state lock")
            .last_anchor
    }

    fn should_suppress_show(&self, now: Instant) -> bool {
        self.inner
            .lock()
            .expect("tray window state lock")
            .last_hidden_at
            .is_some_and(|hidden| should_suppress_show(hidden, now, TRAY_REOPEN_GUARD))
    }
}

/// Pure timing decision for the reopen guard (unit-tested).
fn should_suppress_show(last_hidden_at: Instant, now: Instant, guard: Duration) -> bool {
    now.duration_since(last_hidden_at) < guard
}

/// Pure height clamp for the tray content resize (unit-tested): fit `content +
/// chrome` into `[min, work_height - 2*margin]`, never returning a height taller
/// than the available work area even on a very small screen.
pub(crate) fn clamp_tray_height(
    content_height: f64,
    chrome: f64,
    work_height: f64,
    margin: f64,
    min: f64,
) -> f64 {
    let available = (work_height - 2.0 * margin).max(1.0);
    let lower = min.min(available);
    (content_height + chrome).ceil().clamp(lower, available)
}

pub(crate) fn summarize(snapshots: &[UsageSnapshot]) -> TraySummary {
    let critical_count = snapshots
        .iter()
        .filter(|snapshot| {
            matches!(
                snapshot.status,
                SnapshotStatus::Exhausted | SnapshotStatus::Error
            )
        })
        .count();
    let warning_count = snapshots
        .iter()
        .filter(|snapshot| snapshot.status == SnapshotStatus::Warning)
        .count();
    let stale_count = snapshots
        .iter()
        .filter(|snapshot| snapshot.status == SnapshotStatus::Stale)
        .count();

    let status = if critical_count > 0 {
        SnapshotStatus::Exhausted
    } else if warning_count > 0 {
        SnapshotStatus::Warning
    } else if stale_count > 0 {
        SnapshotStatus::Stale
    } else if snapshots.is_empty() {
        SnapshotStatus::NotConfigured
    } else {
        SnapshotStatus::Healthy
    };

    let label = match status {
        SnapshotStatus::Healthy => "Burnrate: all quotas healthy".to_string(),
        SnapshotStatus::Warning => format!("Burnrate: {warning_count} warning"),
        SnapshotStatus::Exhausted => format!("Burnrate: {critical_count} critical"),
        SnapshotStatus::NotConfigured => "Burnrate: no enabled accounts".to_string(),
        SnapshotStatus::Error => "Burnrate: refresh error".to_string(),
        SnapshotStatus::Stale => "Burnrate: data is stale".to_string(),
    };

    TraySummary {
        label,
        status,
        critical_count,
        warning_count,
        updated_at: Utc::now(),
    }
}

pub(crate) fn install(app: &mut App<Wry>) -> tauri::Result<()> {
    rebuild(app.handle())
}

pub(crate) fn rebuild(app: &AppHandle<Wry>) -> tauri::Result<()> {
    let preferences =
        MenuItem::with_id(app, "preferences", "Open Preferences", true, None::<&str>)?;
    let refresh = MenuItem::with_id(app, "refresh", "Refresh", true, None::<&str>)?;
    let quit = MenuItem::with_id(app, "quit", "Quit Burnrate", true, None::<&str>)?;
    // Only advertise "Check for Updates…" where the in-app updater actually
    // works (a signed, bundled macOS app); on other builds it would be a no-op.
    let check_updates = if crate::updater::updater_available() {
        Some(MenuItem::with_id(
            app,
            "check-updates",
            "Check for Updates…",
            true,
            None::<&str>,
        )?)
    } else {
        None
    };
    let mut items: Vec<&dyn IsMenuItem<Wry>> = vec![&preferences, &refresh];
    if let Some(ref check_updates) = check_updates {
        items.push(check_updates);
    }
    items.push(&quit);
    let menu = Menu::with_items(app, &items)?;

    let _ = app.remove_tray_by_id(TRAY_ID);

    TrayIconBuilder::with_id(TRAY_ID)
        .icon(tray_icon()?)
        .icon_as_template(true)
        .tooltip("Burnrate")
        .menu(&menu)
        .show_menu_on_left_click(false)
        .on_menu_event(|app, event| match event.id().as_ref() {
            "preferences" => show_main_window(app),
            "refresh" => {
                let _ = app.emit("burnrate-refresh-requested", ());
            }
            "check-updates" => {
                let _ = app.emit("burnrate-check-update-requested", ());
            }
            "quit" => app.exit(0),
            _ => {}
        })
        .on_tray_icon_event(|tray, event| {
            if let TrayIconEvent::Click {
                button: MouseButton::Left,
                button_state: MouseButtonState::Up,
                position,
                ..
            } = event
            {
                show_tray_window(tray.app_handle(), position);
            }
        })
        .build(app)?;

    Ok(())
}

#[cfg(target_os = "macos")]
pub(crate) fn apply_activation_policy(app: &AppHandle<Wry>, hide_from_dock: bool) {
    let policy = if hide_from_dock {
        tauri::ActivationPolicy::Accessory
    } else {
        tauri::ActivationPolicy::Regular
    };
    let _ = app.set_activation_policy(policy);
}

#[cfg(not(target_os = "macos"))]
pub(crate) fn apply_activation_policy(_app: &AppHandle<Wry>, _hide_from_dock: bool) {}

/// On macOS the Dock icon comes from the `.app` bundle's `CFBundleIconFile`. A
/// bare binary (`cargo build` / `cargo install burnrate`) has no bundle, so
/// when Preferences flips the activation policy to `Regular` the Dock shows a
/// generic executable icon. Set the application icon at runtime from the
/// embedded PNG so the unbundled binary still shows the Burnrate icon. The
/// bundled app already ships a multi-resolution `icon.icns`, so leave it be.
#[cfg(target_os = "macos")]
pub(crate) fn set_dock_icon_if_unbundled() {
    use objc2::{AnyThread, MainThreadMarker};
    use objc2_app_kit::{NSApplication, NSImage};
    use objc2_foundation::NSData;

    const ICON_PNG: &[u8] = include_bytes!("../icons/icon.png");

    if running_in_app_bundle() {
        return;
    }
    let Some(mtm) = MainThreadMarker::new() else {
        return;
    };
    let data = NSData::with_bytes(ICON_PNG);
    let Some(image) = NSImage::initWithData(NSImage::alloc(), &data) else {
        return;
    };
    let app = NSApplication::sharedApplication(mtm);
    // SAFETY: `NSApplication` is touched on the main thread (proven by `mtm`)
    // and `image` is a valid, freshly-decoded `NSImage`.
    unsafe { app.setApplicationIconImage(Some(&image)) };
}

#[cfg(not(target_os = "macos"))]
pub(crate) fn set_dock_icon_if_unbundled() {}

#[cfg(target_os = "macos")]
pub(crate) fn running_in_app_bundle() -> bool {
    std::env::current_exe()
        .map(|path| path_is_in_app_bundle(&path.to_string_lossy()))
        .unwrap_or(false)
}

#[cfg(target_os = "macos")]
fn path_is_in_app_bundle(path: &str) -> bool {
    path.contains(".app/Contents/MacOS/")
}

pub(crate) fn update_summary(app: &AppHandle<Wry>, summary: &TraySummary) {
    if let Some(tray) = app.tray_by_id(TRAY_ID) {
        let _ = tray.set_tooltip(Some(summary.label.as_str()));
    }
}

pub(crate) fn show_main_window(app: &AppHandle<Wry>) {
    if let Some(window) = app.get_webview_window(MAIN_WINDOW) {
        if let Ok(icon) = app_icon() {
            let _ = window.set_icon(icon);
        }
        #[cfg(target_os = "macos")]
        {
            apply_activation_policy(app, false);
            let _ = app.show();
        }
        let _ = window.unminimize();
        let _ = window.show();
        let _ = window.set_focus();
    }
}

pub(crate) fn close_main_window(app: &AppHandle<Wry>) {
    if let Some(window) = app.get_webview_window(MAIN_WINDOW) {
        let _ = window.hide();
    }
    #[cfg(target_os = "macos")]
    apply_activation_policy(app, true);
}

fn show_tray_window(app: &AppHandle<Wry>, position: tauri::PhysicalPosition<f64>) {
    let Some(window) = app.get_webview_window(TRAY_WINDOW) else {
        return;
    };
    // Clicking the tray icon while open closes it.
    if window.is_visible().unwrap_or(false) {
        hide_tray_window(app);
        return;
    }
    let tray_state = app.state::<TrayWindowState>();
    // Beat the blur→click race: a status-item click first blurs (hides) the
    // popover, then fires this event; suppress the immediate reopen.
    if tray_state.should_suppress_show(Instant::now()) {
        return;
    }

    // Work in global physical pixels anchored to the monitor under the cursor —
    // not the window's current monitor — so the popover opens on whichever
    // display the tray was clicked on, and lands correctly under mixed DPI.
    let (scale, work_pos, work_size) = cursor_monitor_geometry(app, position);
    // outer_size() is physical at the window's *current* monitor scale; the
    // popover will render at the cursor monitor's scale, so convert through
    // logical to size it for the target display (mixed-DPI correctness).
    let current_scale = window.scale_factor().unwrap_or(scale);
    let window_size = window
        .outer_size()
        .map(|size| {
            let logical = size.to_logical::<f64>(current_scale);
            PhysicalSize::new(logical.width * scale, logical.height * scale)
        })
        .unwrap_or_else(|_| PhysicalSize::new(360.0 * scale, 440.0 * scale));
    tray_state.set_anchor(position);
    let target = popup_position(
        position,
        window_size,
        work_pos,
        work_size,
        TRAY_MARGIN * scale,
        TRAY_OFFSET_Y * scale,
    );
    // Position while still hidden (physical coords are unambiguous across
    // monitors), then reveal.
    let _ = window.set_position(PhysicalPosition::new(
        target.x.round() as i32,
        target.y.round() as i32,
    ));
    let _ = window.show();
    #[cfg(target_os = "macos")]
    activate_app();
    let _ = window.set_focus();
    let _ = app.emit("burnrate-refresh-requested", ());
}

/// Physical work-area geometry (scale, origin, size) of the monitor under
/// `point`, falling back to the primary monitor, then a sane default.
pub(crate) fn cursor_monitor_geometry(
    app: &AppHandle<Wry>,
    point: PhysicalPosition<f64>,
) -> (f64, PhysicalPosition<f64>, PhysicalSize<f64>) {
    let monitor = app
        .monitor_from_point(point.x, point.y)
        .ok()
        .flatten()
        .or_else(|| app.primary_monitor().ok().flatten());
    match monitor {
        Some(monitor) => {
            let area = monitor.work_area();
            (
                monitor.scale_factor(),
                PhysicalPosition::new(area.position.x as f64, area.position.y as f64),
                PhysicalSize::new(area.size.width as f64, area.size.height as f64),
            )
        }
        None => (
            1.0,
            PhysicalPosition::new(0.0, 0.0),
            PhysicalSize::new(1920.0, 1080.0),
        ),
    }
}

pub(crate) fn hide_tray_window(app: &AppHandle<Wry>) {
    if let Some(window) = app.get_webview_window(TRAY_WINDOW) {
        let _ = window.hide();
    }
    app.state::<TrayWindowState>().mark_hidden();
}

/// Bring the process to the foreground so the borderless popover can become the
/// key window under Accessory activation policy (otherwise it never receives the
/// blur that dismisses it).
#[cfg(target_os = "macos")]
fn activate_app() {
    use objc2::MainThreadMarker;
    use objc2_app_kit::NSApplication;

    let Some(mtm) = MainThreadMarker::new() else {
        return;
    };
    let app = NSApplication::sharedApplication(mtm);
    // `activateIgnoringOtherApps` is deprecated in favor of `NSApp.activate`, but
    // it's the variant that reliably activates across the macOS versions we ship.
    #[allow(deprecated)]
    app.activateIgnoringOtherApps(true);
}

/// Give the tray popover the native macOS translucent material + rounded corners.
#[cfg(target_os = "macos")]
pub(crate) fn apply_tray_vibrancy(app: &AppHandle<Wry>) {
    use window_vibrancy::{NSVisualEffectMaterial, NSVisualEffectState, apply_vibrancy};

    if let Some(window) = app.get_webview_window(TRAY_WINDOW) {
        let _ = apply_vibrancy(
            &window,
            NSVisualEffectMaterial::Popover,
            Some(NSVisualEffectState::Active),
            Some(12.0),
        );
    }
}

#[cfg(not(target_os = "macos"))]
pub(crate) fn apply_tray_vibrancy(_app: &AppHandle<Wry>) {}

/// Place the popover's top-left so it's centered under `cursor` and dropped
/// `offset_y` below it, clamped to stay fully within the work area. All inputs
/// and the result are in the same physical-pixel space (the monitor under the
/// cursor), which keeps multi-monitor and mixed-DPI placement correct.
pub(crate) fn popup_position(
    cursor: PhysicalPosition<f64>,
    window_size: PhysicalSize<f64>,
    work_position: PhysicalPosition<f64>,
    work_size: PhysicalSize<f64>,
    margin: f64,
    offset_y: f64,
) -> PhysicalPosition<f64> {
    let min_x = work_position.x + margin;
    let min_y = work_position.y + margin;
    let max_x = (work_position.x + work_size.width - window_size.width - margin).max(min_x);
    let max_y = (work_position.y + work_size.height - window_size.height - margin).max(min_y);
    PhysicalPosition::new(
        (cursor.x - window_size.width / 2.0).clamp(min_x, max_x),
        (cursor.y + offset_y).clamp(min_y, max_y),
    )
}

fn tray_icon() -> tauri::Result<Image<'static>> {
    Image::from_bytes(include_bytes!("../icons/tray.png"))
}

fn app_icon() -> tauri::Result<Image<'static>> {
    Image::from_bytes(include_bytes!("../icons/icon.png"))
}

#[cfg(test)]
mod tests {
    use chrono::Utc;

    use super::*;
    use crate::models::{ProviderKind, UsageSnapshot};

    fn snapshot(status: SnapshotStatus) -> UsageSnapshot {
        UsageSnapshot {
            account_id: "account".to_string(),
            provider: ProviderKind::OpenRouter,
            label: "OpenRouter".to_string(),
            status,
            email: None,
            subscription: None,
            usage_buckets: Vec::new(),
            quota: None,
            message: None,
            fetched_at: Utc::now(),
        }
    }

    #[test]
    fn summary_promotes_errors_to_critical() {
        let summary = summarize(&[
            snapshot(SnapshotStatus::Healthy),
            snapshot(SnapshotStatus::Error),
        ]);

        assert_eq!(summary.status, SnapshotStatus::Exhausted);
        assert_eq!(summary.critical_count, 1);
    }

    #[test]
    fn summary_reports_empty_state() {
        let summary = summarize(&[]);

        assert_eq!(summary.status, SnapshotStatus::NotConfigured);
    }

    #[test]
    fn summary_reports_stale_when_cached_data_is_used() {
        let summary = summarize(&[snapshot(SnapshotStatus::Stale)]);

        assert_eq!(summary.status, SnapshotStatus::Stale);
        assert_eq!(summary.label, "Burnrate: data is stale");
    }

    #[test]
    fn tray_icon_loads_packaged_asset() {
        let icon = tray_icon().expect("tray icon should decode");

        assert_eq!(icon.width(), 32);
        assert_eq!(icon.height(), 32);
    }

    #[test]
    fn app_icon_loads_packaged_asset() {
        let icon = app_icon().expect("app icon should decode");

        assert!(icon.width() >= 128);
        assert!(icon.height() >= 128);
    }

    #[cfg(target_os = "macos")]
    #[test]
    fn detects_app_bundle_versus_bare_binary() {
        assert!(path_is_in_app_bundle(
            "/Applications/Burnrate.app/Contents/MacOS/burnrate"
        ));
        assert!(!path_is_in_app_bundle(
            "/Users/dev/Projects/burnrate/target/release/burnrate"
        ));
        assert!(!path_is_in_app_bundle("/usr/local/bin/burnrate"));
    }

    #[test]
    fn popup_position_clamps_to_work_area() {
        let size = PhysicalSize::new(380.0, 520.0);
        let work_pos = PhysicalPosition::new(0.0, 0.0);
        let work_size = PhysicalSize::new(1024.0, 768.0);
        let position = popup_position(
            PhysicalPosition::new(20.0, -40.0),
            size,
            work_pos,
            work_size,
            8.0,
            12.0,
        );

        assert_eq!(position.x, 8.0);
        assert_eq!(position.y, 8.0);

        let position = popup_position(
            PhysicalPosition::new(1000.0, 760.0),
            size,
            work_pos,
            work_size,
            8.0,
            12.0,
        );

        assert_eq!(position.x, 636.0);
        assert_eq!(position.y, 240.0);
    }

    #[test]
    fn popup_position_anchors_to_a_secondary_monitor() {
        // A second monitor sitting to the right of the primary (origin 1440,0).
        // The popover must land on it, not be clamped back to the primary.
        let size = PhysicalSize::new(360.0, 440.0);
        let work_pos = PhysicalPosition::new(1440.0, 0.0);
        let work_size = PhysicalSize::new(1440.0, 900.0);
        let position = popup_position(
            PhysicalPosition::new(1700.0, 100.0),
            size,
            work_pos,
            work_size,
            8.0,
            12.0,
        );

        // x: 1700 - 180 = 1520 (within [1448, 2512]); y: 100 + 12 = 112.
        assert_eq!(position.x, 1520.0);
        assert_eq!(position.y, 112.0);
        assert!(position.x >= 1448.0, "stays on the secondary monitor");
    }

    #[test]
    fn install_removes_existing_tray_before_rebuild() {
        let src = include_str!("tray.rs");
        let remove_pos = src
            .find("remove_tray_by_id(TRAY_ID)")
            .expect("tray rebuild should remove the previous tray by id");
        let build_pos = src
            .find("TrayIconBuilder::with_id(TRAY_ID)")
            .expect("tray rebuild should build the tray by id");

        assert!(remove_pos < build_pos);
    }

    #[test]
    fn suppresses_reopen_within_guard_window() {
        let now = Instant::now();
        let guard = Duration::from_millis(250);
        // Hidden 50ms ago → within the guard → suppress the reopen.
        assert!(should_suppress_show(
            now - Duration::from_millis(50),
            now,
            guard
        ));
        // Hidden 300ms ago → guard elapsed → allow the show.
        assert!(!should_suppress_show(
            now - Duration::from_millis(300),
            now,
            guard
        ));
        // Exactly at the boundary → allowed (strict `<`).
        assert!(!should_suppress_show(now - guard, now, guard));
    }

    #[test]
    fn clamp_tray_height_fits_content_within_work_area() {
        let margin = 8.0;
        // Below the floor → clamped up to the minimum.
        assert_eq!(clamp_tray_height(50.0, 0.0, 1000.0, margin, 200.0), 200.0);
        // Normal content → ceil(content + chrome).
        assert_eq!(clamp_tray_height(500.4, 2.0, 1000.0, margin, 200.0), 503.0);
        // Taller than the work area → clamped down to the available height.
        assert_eq!(
            clamp_tray_height(5000.0, 0.0, 1000.0, margin, 200.0),
            1000.0 - 2.0 * margin
        );
        // Tiny screen (available < min) → fit the screen, not the minimum.
        assert_eq!(clamp_tray_height(500.0, 0.0, 10.0, margin, 200.0), 1.0);
    }

    #[test]
    fn popup_position_keeps_tall_window_on_screen() {
        // A resized (taller) popover anchored near the bottom edge still clamps
        // fully on-screen.
        let size = PhysicalSize::new(360.0, 700.0);
        let position = popup_position(
            PhysicalPosition::new(500.0, 760.0),
            size,
            PhysicalPosition::new(0.0, 0.0),
            PhysicalSize::new(1024.0, 768.0),
            8.0,
            12.0,
        );

        assert_eq!(position.y, 768.0 - 700.0 - 8.0);
        assert!(position.y >= 8.0);
        assert_eq!(position.x, 320.0);
    }
}