- Anchor monitor to the bottom of the taskbar to help with any positioning issues
This commit is contained in:
Craig Constable 2026-03-30 12:46:14 +10:00
parent 7ef75f4c0b
commit ba84737ffb
3 changed files with 14 additions and 10 deletions

2
Cargo.lock generated
View File

@ -38,7 +38,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "claude-code-usage-monitor"
version = "1.2.9"
version = "1.2.10"
dependencies = [
"dirs",
"native-tls",

View File

@ -1,6 +1,6 @@
[package]
name = "claude-code-usage-monitor"
version = "1.2.9"
version = "1.2.10"
edition = "2021"
license = "MIT"
description = "Windows taskbar widget for monitoring Claude Code usage and rate limits"

View File

@ -1323,18 +1323,18 @@ fn position_at_taskbar() {
let widget_width = total_widget_width();
let widget_height = sc(WIDGET_HEIGHT);
let y = compute_anchor_y(anchor_top, anchor_height, widget_height);
if embedded {
// Child window: coordinates relative to parent (taskbar)
let x = tray_left - taskbar_rect.left - widget_width - tray_offset;
let y = (anchor_top - taskbar_rect.top) + (anchor_height - widget_height) / 2;
native_interop::move_window(hwnd, x, y, widget_width, widget_height);
native_interop::move_window(hwnd, x, y - taskbar_rect.top, widget_width, widget_height);
diagnose::log(format!(
"positioned embedded widget at x={x} y={y} w={widget_width} h={widget_height}"
"positioned embedded widget at x={x} y={} w={widget_width} h={widget_height}",
y - taskbar_rect.top
));
} else {
// Topmost popup: screen coordinates
let x = tray_left - widget_width - tray_offset;
let y = anchor_top + (anchor_height - widget_height) / 2;
native_interop::move_window(hwnd, x, y, widget_width, widget_height);
diagnose::log(format!(
"positioned fallback widget at x={x} y={y} w={widget_width} h={widget_height}"
@ -1342,6 +1342,12 @@ fn position_at_taskbar() {
}
}
fn compute_anchor_y(anchor_top: i32, anchor_height: i32, widget_height: i32) -> i32 {
let anchor_bottom = anchor_top + anchor_height;
let bottom_padding = (anchor_height - widget_height).clamp(0, sc(6));
(anchor_bottom - widget_height - bottom_padding).max(anchor_top)
}
/// WinEvent callback for tray icon location changes
unsafe extern "system" fn on_tray_location_changed(
_hook: HWINEVENTHOOK,
@ -1574,20 +1580,18 @@ unsafe extern "system" fn wnd_proc(
}
let widget_width = total_widget_width();
let widget_height = sc(WIDGET_HEIGHT);
let y = compute_anchor_y(anchor_top, anchor_height, widget_height);
if s.embedded {
let x = tray_left - taskbar_rect.left - widget_width - new_offset;
let y =
(anchor_top - taskbar_rect.top) + (anchor_height - widget_height) / 2;
native_interop::move_window(
hwnd_val,
x,
y,
y - taskbar_rect.top,
widget_width,
widget_height,
);
} else {
let x = tray_left - widget_width - new_offset;
let y = anchor_top + (anchor_height - widget_height) / 2;
native_interop::move_window(
hwnd_val,
x,