ai-battery 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -257,6 +257,8 @@ public static class AiBatteryNative {
257
257
  public const int ProcessPowerThrottling = 4;
258
258
  public const uint PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1;
259
259
  public const uint PROCESS_POWER_THROTTLING_EXECUTION_SPEED = 0x1;
260
+ public const int PROCESS_PER_MONITOR_DPI_AWARE = 2;
261
+ public const int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4;
260
262
  public const int OBJID_WINDOW = 0;
261
263
  public const int GWL_EXSTYLE = -20;
262
264
  public const int WS_EX_TRANSPARENT = 0x20;
@@ -281,6 +283,14 @@ public static class AiBatteryNative {
281
283
  public const UInt32 SWP_NOMOVE = 0x0002;
282
284
  public const UInt32 SWP_NOACTIVATE = 0x0010;
283
285
  public const UInt32 SWP_SHOWWINDOW = 0x0040;
286
+ [DllImport("user32.dll", SetLastError=true)]
287
+ public static extern bool SetProcessDPIAware();
288
+ [DllImport("shcore.dll")]
289
+ public static extern int SetProcessDpiAwareness(int value);
290
+ [DllImport("user32.dll", SetLastError=true)]
291
+ public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);
292
+ [DllImport("user32.dll")]
293
+ public static extern uint GetDpiForWindow(IntPtr hWnd);
284
294
  [DllImport("user32.dll")]
285
295
  public static extern IntPtr GetForegroundWindow();
286
296
  [DllImport("user32.dll")]
@@ -325,6 +335,30 @@ public static class AiBatteryNative {
325
335
  "@
326
336
  Add-Type -TypeDefinition $nativeCode
327
337
 
338
+ function Enable-HudDpiAwareness {
339
+ try {
340
+ $context = [IntPtr]::new([AiBatteryNative]::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
341
+ if ([AiBatteryNative]::SetProcessDpiAwarenessContext($context)) { return "per-monitor-v2" }
342
+ } catch {
343
+ # Fall through to older Windows APIs.
344
+ }
345
+
346
+ try {
347
+ if ([AiBatteryNative]::SetProcessDpiAwareness([AiBatteryNative]::PROCESS_PER_MONITOR_DPI_AWARE) -eq 0) { return "per-monitor" }
348
+ } catch {
349
+ # Fall through to system DPI awareness.
350
+ }
351
+
352
+ try {
353
+ if ([AiBatteryNative]::SetProcessDPIAware()) { return "system" }
354
+ } catch {
355
+ # DPI awareness is a quality improvement; the HUD can still run without it.
356
+ }
357
+
358
+ return "default"
359
+ }
360
+ $script:hudDpiAwareness = Enable-HudDpiAwareness
361
+
328
362
  function Disable-ProcessPowerThrottling {
329
363
  # When a fullscreen app is in the foreground, Windows applies EcoQoS power
330
364
  # throttling to background processes like this HUD, which stretches the
@@ -685,7 +719,88 @@ if ($Once) {
685
719
 
686
720
  Add-Type -AssemblyName System.Windows.Forms
687
721
  Add-Type -AssemblyName System.Drawing
722
+ try {
723
+ [System.Windows.Forms.Application]::SetHighDpiMode([System.Windows.Forms.HighDpiMode]::PerMonitorV2) | Out-Null
724
+ } catch {
725
+ # Windows PowerShell/.NET Framework does not expose SetHighDpiMode; the
726
+ # native DPI awareness call above covers that runtime.
727
+ }
688
728
  [System.Windows.Forms.Application]::EnableVisualStyles()
729
+ try {
730
+ [System.Windows.Forms.Application]::SetCompatibleTextRenderingDefault($false)
731
+ } catch {
732
+ # The default is already GDI text rendering on older WinForms.
733
+ }
734
+
735
+ function Get-HudDpi {
736
+ try {
737
+ if ($form -and -not $form.IsDisposed -and $form.Handle -ne [IntPtr]::Zero) {
738
+ $windowDpi = [AiBatteryNative]::GetDpiForWindow($form.Handle)
739
+ if ($windowDpi -gt 0) { return [int]$windowDpi }
740
+ }
741
+ } catch {
742
+ # Fall back to the desktop graphics DPI below.
743
+ }
744
+
745
+ $graphics = $null
746
+ try {
747
+ $graphics = [System.Drawing.Graphics]::FromHwnd([IntPtr]::Zero)
748
+ if ($graphics.DpiX -gt 0) { return [int][math]::Round($graphics.DpiX) }
749
+ } catch {
750
+ # Use the WinForms baseline when the desktop DPI cannot be queried.
751
+ } finally {
752
+ if ($graphics) { $graphics.Dispose() }
753
+ }
754
+
755
+ return 96
756
+ }
757
+
758
+ function Update-HudDpiScale {
759
+ $dpi = [math]::Max(96, (Get-HudDpi))
760
+ $script:hudDpi = [int]$dpi
761
+ $script:hudScale = [double]$script:hudDpi / 96.0
762
+ }
763
+
764
+ function Scale-HudValue([double]$Value) {
765
+ if ($Value -eq 0) { return 0 }
766
+ $scaled = [int][math]::Round($Value * $script:hudScale)
767
+ if ($Value -gt 0) { return [math]::Max(1, $scaled) }
768
+ return $scaled
769
+ }
770
+
771
+ function New-HudPadding([int]$Left, [int]$Top, [int]$Right, [int]$Bottom) {
772
+ return [System.Windows.Forms.Padding]::new(
773
+ (Scale-HudValue $Left),
774
+ (Scale-HudValue $Top),
775
+ (Scale-HudValue $Right),
776
+ (Scale-HudValue $Bottom)
777
+ )
778
+ }
779
+
780
+ function New-HudBitmapSurface([int]$Width, [int]$Height) {
781
+ $scale = [math]::Max(1.0, [double]$script:hudScale)
782
+ $bitmapWidth = [math]::Max(1, [int][math]::Round($Width * $scale))
783
+ $bitmapHeight = [math]::Max(1, [int][math]::Round($Height * $scale))
784
+ $bitmap = [System.Drawing.Bitmap]::new($bitmapWidth, $bitmapHeight)
785
+ $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
786
+ if ([math]::Abs($scale - 1.0) -gt 0.001) {
787
+ $graphics.ScaleTransform([single]$scale, [single]$scale)
788
+ }
789
+ return @{
790
+ Bitmap = $bitmap
791
+ Graphics = $graphics
792
+ }
793
+ }
794
+
795
+ function Test-HudTransparentSurface {
796
+ $value = $env:AI_BATTERY_HUD_TRANSPARENT
797
+ if (-not $value) { $value = $env:CLAUDEX_BATTERY_HUD_TRANSPARENT }
798
+ if (-not $value) { return $true }
799
+ $normalized = ([string]$value).Trim().ToLowerInvariant()
800
+ return -not (@("0", "false", "no", "off", "solid") -contains $normalized)
801
+ }
802
+
803
+ Update-HudDpiScale
689
804
 
690
805
  function Get-LineText($Parts) {
691
806
  return "$($Parts.Prefix)[battery]$($Parts.Suffix)"
@@ -724,8 +839,8 @@ function New-ProviderTrayIcon([string]$ProviderLabel, [Nullable[int]]$Percent, [
724
839
  $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
725
840
  $graphics.Clear([System.Drawing.Color]::Transparent)
726
841
 
727
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
728
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
842
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
843
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
729
844
  $activeOutlineColor = if ($Running) { $outlineColor } else { $mutedColor }
730
845
  $fillColor = if ($Running) { Get-PercentColor $Percent } else { $mutedColor }
731
846
  $textColor = if ($Running) { [System.Drawing.Color]::FromArgb(245, 245, 245) } else { $mutedColor }
@@ -786,8 +901,8 @@ function New-SingleBatteryTrayIcon([Nullable[int]]$Percent) {
786
901
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
787
902
  $graphics.Clear([System.Drawing.Color]::Transparent)
788
903
 
789
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
790
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
904
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
905
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
791
906
  $fillColor = Get-PercentColor $Percent
792
907
  $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $outlineColor }), 2)
793
908
  $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
@@ -826,39 +941,43 @@ function New-SingleBatteryTrayIcon([Nullable[int]]$Percent) {
826
941
  return $icon
827
942
  }
828
943
 
829
- function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]$Width = 34, [int]$Height = 16) {
830
- $bitmap = [System.Drawing.Bitmap]::new($Width, $Height)
831
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
944
+ function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]$Width = 36, [int]$Height = 16, [bool]$DrawText = $true) {
945
+ $surface = New-HudBitmapSurface $Width $Height
946
+ $bitmap = $surface.Bitmap
947
+ $graphics = $surface.Graphics
832
948
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
833
- $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
949
+ $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::ClearTypeGridFit
950
+ $graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Half
834
951
  $graphics.Clear([System.Drawing.Color]::Transparent)
835
952
 
836
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
837
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
953
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
954
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
838
955
  $activeOutlineColor = if ($Running) { $outlineColor } else { $mutedColor }
839
956
  # The fill always keeps its charge color (matching the terminal bar);
840
957
  # running state is signalled by the outline and text colors instead.
841
958
  $fillColor = Get-PercentColor $Percent
842
- $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }), 1.6)
959
+ $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }), 1.0)
843
960
  $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
844
961
  # A solid dark interior keeps the desktop from bleeding through the empty
845
962
  # part of the battery, so the percent text stays readable on any wallpaper.
846
963
  $interiorBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(46, 46, 46))
847
964
  $terminalBrush = [System.Drawing.SolidBrush]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }))
848
- $textBrush = [System.Drawing.SolidBrush]::new($(if ($Running) { [System.Drawing.Color]::FromArgb(250, 250, 250) } else { [System.Drawing.Color]::FromArgb(210, 210, 210) }))
849
- $textHaloBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(200, 15, 15, 15))
850
- $fontSize = if ($null -eq $Percent) { 7.8 } elseif ($Percent -ge 100) { 7.2 } else { 8.2 }
851
- $batteryFont = [System.Drawing.Font]::new("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Bold)
965
+ $textBrush = [System.Drawing.SolidBrush]::new($(if ($Running) { [System.Drawing.Color]::FromArgb(255, 255, 255) } else { [System.Drawing.Color]::FromArgb(235, 235, 235) }))
966
+ $batteryText = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
967
+ $fontSize = if ($batteryText.Length -ge 3) { 4.4 } elseif ($batteryText.Length -ge 2) { 5.1 } else { 5.8 }
968
+ $batteryFont = $null
852
969
  $centerFormat = [System.Drawing.StringFormat]::new()
853
970
  $centerFormat.Alignment = [System.Drawing.StringAlignment]::Center
854
971
  $centerFormat.LineAlignment = [System.Drawing.StringAlignment]::Center
972
+ $centerFormat.Trimming = [System.Drawing.StringTrimming]::None
973
+ $centerFormat.FormatFlags = [System.Drawing.StringFormatFlags]::NoWrap
855
974
 
856
975
  try {
857
976
  $bodyX = 1
858
977
  $bodyY = 3
859
978
  $bodyW = $Width - 6
860
979
  $bodyH = $Height - 6
861
- $capW = 3
980
+ $capW = 2
862
981
  $capH = [math]::Max(4, [math]::Floor($bodyH / 2))
863
982
  $capY = $bodyY + [math]::Floor(($bodyH - $capH) / 2)
864
983
 
@@ -875,23 +994,26 @@ function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]
875
994
  if ($clamped -gt 0 -and $fillW -lt 2) { $fillW = 2 }
876
995
  $graphics.FillRectangle($fillBrush, $bodyX + 3, $bodyY + 3, $fillW, $bodyH - 5)
877
996
  }
878
- $batteryText = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
879
- $textRect = [System.Drawing.RectangleF]::new($bodyX + 2, $bodyY, $bodyW - 3, $bodyH + 1)
880
- # A one-pixel dark halo keeps the number legible over the green/orange/red
881
- # fill as well as over the dark empty region.
882
- foreach ($shift in @(@(-1, 0), @(1, 0), @(0, -1), @(0, 1))) {
883
- $haloRect = [System.Drawing.RectangleF]::new($textRect.X + $shift[0], $textRect.Y + $shift[1], $textRect.Width, $textRect.Height)
884
- $graphics.DrawString($batteryText, $batteryFont, $textHaloBrush, $haloRect, $centerFormat)
997
+ if ($DrawText) {
998
+ $textRect = [System.Drawing.RectangleF]::new($bodyX + 3, $bodyY + 2.5, $bodyW - 6, $bodyH - 4)
999
+ do {
1000
+ if ($batteryFont) { $batteryFont.Dispose() }
1001
+ $fontFamily = if ($font) { $font.FontFamily.Name } else { "Segoe UI" }
1002
+ $batteryFont = [System.Drawing.Font]::new($fontFamily, $fontSize, [System.Drawing.FontStyle]::Regular)
1003
+ $textSize = $graphics.MeasureString($batteryText, $batteryFont)
1004
+ if ($textSize.Width -le ($textRect.Width + 1) -or $fontSize -le 4.0) { break }
1005
+ $fontSize -= 0.4
1006
+ } while ($true)
1007
+
1008
+ $graphics.DrawString($batteryText, $batteryFont, $textBrush, $textRect, $centerFormat)
885
1009
  }
886
- $graphics.DrawString($batteryText, $batteryFont, $textBrush, $textRect, $centerFormat)
887
1010
  } finally {
888
1011
  $outlinePen.Dispose()
889
1012
  $fillBrush.Dispose()
890
1013
  $interiorBrush.Dispose()
891
1014
  $terminalBrush.Dispose()
892
1015
  $textBrush.Dispose()
893
- $textHaloBrush.Dispose()
894
- $batteryFont.Dispose()
1016
+ if ($batteryFont) { $batteryFont.Dispose() }
895
1017
  $centerFormat.Dispose()
896
1018
  $graphics.Dispose()
897
1019
  }
@@ -913,7 +1035,7 @@ function New-StatusMenuLabel($Font, [int]$Width, $Align = [System.Drawing.Conten
913
1035
 
914
1036
  function New-StatusMenuRow($Font) {
915
1037
  $panel = New-Object System.Windows.Forms.FlowLayoutPanel
916
- $panel.Width = 252
1038
+ $panel.Width = 276
917
1039
  $panel.Height = 22
918
1040
  $panel.FlowDirection = [System.Windows.Forms.FlowDirection]::LeftToRight
919
1041
  $panel.WrapContents = $false
@@ -923,14 +1045,14 @@ function New-StatusMenuRow($Font) {
923
1045
 
924
1046
  $name = New-StatusMenuLabel $Font 44
925
1047
  $icon = New-Object System.Windows.Forms.PictureBox
926
- $icon.Width = 36
1048
+ $icon.Width = 40
927
1049
  $icon.Height = 20
928
- $icon.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1050
+ $icon.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
929
1051
  $icon.Margin = [System.Windows.Forms.Padding]::new(0)
930
1052
  $icon.BackColor = [System.Drawing.SystemColors]::Menu
931
1053
  $percent = New-StatusMenuLabel $Font 0 ([System.Drawing.ContentAlignment]::MiddleRight)
932
- $reset = New-StatusMenuLabel $Font 58
933
- $week = New-StatusMenuLabel $Font 50
1054
+ $reset = New-StatusMenuLabel $Font 66
1055
+ $week = New-StatusMenuLabel $Font 56
934
1056
  $extra = New-StatusMenuLabel $Font 58
935
1057
 
936
1058
  foreach ($control in @($name, $icon, $percent, $reset, $week, $extra)) {
@@ -1091,16 +1213,21 @@ if ($Mode -eq "tray") {
1091
1213
  $form = New-Object System.Windows.Forms.Form
1092
1214
  $form.Text = "AI Battery"
1093
1215
  $form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
1094
- $form.Width = $Width
1095
- $form.Height = if ($Mode -eq "floating") { 44 } elseif ($Mode -eq "statusline") { 44 } else { 54 }
1216
+ $form.Width = Scale-HudValue $Width
1217
+ $form.Height = if ($Mode -eq "floating") { Scale-HudValue 44 } elseif ($Mode -eq "statusline") { Scale-HudValue 44 } else { Scale-HudValue 54 }
1096
1218
  $script:hudTwoRowHeight = $form.Height
1097
- $script:hudOneRowHeight = [math]::Max(20, $form.Height - 18)
1219
+ $script:hudOneRowHeight = [math]::Max((Scale-HudValue 20), $form.Height - (Scale-HudValue 18))
1098
1220
  $form.TopMost = $true
1099
1221
  $form.ShowInTaskbar = $false
1100
1222
  $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
1101
- $transparentBackColor = [System.Drawing.Color]::FromArgb(18, 18, 18)
1102
- $form.BackColor = $transparentBackColor
1103
- $form.TransparencyKey = $transparentBackColor
1223
+ $script:hudTransparentSurface = Test-HudTransparentSurface
1224
+ if ($script:hudTransparentSurface) {
1225
+ $transparentBackColor = [System.Drawing.Color]::FromArgb(18, 18, 18)
1226
+ $form.BackColor = $transparentBackColor
1227
+ $form.TransparencyKey = $transparentBackColor
1228
+ } else {
1229
+ $form.BackColor = [System.Drawing.Color]::FromArgb(24, 24, 24)
1230
+ }
1104
1231
  $form.Opacity = [math]::Max(0.2, [math]::Min(1.0, $Opacity))
1105
1232
 
1106
1233
  $font = [System.Drawing.Font]::new("Segoe UI", $(if ($Mode -eq "statusline") { 8.5 } else { 9 }), [System.Drawing.FontStyle]::Regular)
@@ -1112,9 +1239,9 @@ $panel.RowCount = 2
1112
1239
  $panel.ColumnCount = 1
1113
1240
  $panel.GrowStyle = [System.Windows.Forms.TableLayoutPanelGrowStyle]::FixedSize
1114
1241
  $panel.Padding = if ($Mode -eq "floating" -or $Mode -eq "statusline") {
1115
- [System.Windows.Forms.Padding]::new(6, 4, 2, 3)
1242
+ New-HudPadding 6 4 2 3
1116
1243
  } else {
1117
- [System.Windows.Forms.Padding]::new(10, 7, 10, 6)
1244
+ New-HudPadding 10 7 10 6
1118
1245
  }
1119
1246
  $panel.BackColor = $form.BackColor
1120
1247
  $panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
@@ -1136,42 +1263,71 @@ function New-HudLabel([int]$RightMargin = 0) {
1136
1263
  $label = New-Object System.Windows.Forms.Label
1137
1264
  $label.AutoSize = $false
1138
1265
  $label.Width = 0
1139
- $label.Height = 18
1266
+ $label.Height = Scale-HudValue 18
1140
1267
  $label.Font = $font
1141
1268
  $label.UseCompatibleTextRendering = $false
1142
1269
  $label.BackColor = $form.BackColor
1143
- $label.Margin = [System.Windows.Forms.Padding]::new(0, 0, $RightMargin, 0)
1270
+ $label.Margin = New-HudPadding 0 0 $RightMargin 0
1144
1271
  $label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
1145
1272
  return $label
1146
1273
  }
1147
1274
 
1148
1275
  function New-HudIconBox {
1149
1276
  $box = New-Object System.Windows.Forms.PictureBox
1150
- $box.Width = 36
1151
- $box.Height = 18
1152
- $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1277
+ $box.Width = Scale-HudValue 40
1278
+ $box.Height = Scale-HudValue 18
1279
+ $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
1153
1280
  $box.BackColor = $form.BackColor
1154
- $box.Margin = [System.Windows.Forms.Padding]::new(0, 0, 2, 0)
1281
+ $box.ForeColor = [System.Drawing.Color]::White
1282
+ $box.Margin = New-HudPadding 0 0 2 0
1283
+ $box.add_Paint({
1284
+ param($sender, $event)
1285
+ $text = [string]$sender.AccessibleName
1286
+ if ([string]::IsNullOrWhiteSpace($text)) { return }
1287
+
1288
+ $drawFont = $null
1289
+ $disposeDrawFont = $false
1290
+ try {
1291
+ $drawFont = $font
1292
+ if (-not $drawFont) {
1293
+ $drawFont = [System.Drawing.Font]::new("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
1294
+ $disposeDrawFont = $true
1295
+ }
1296
+ $rect = [System.Drawing.Rectangle]::new(
1297
+ (Scale-HudValue 2),
1298
+ 0,
1299
+ [math]::Max(1, $sender.Width - (Scale-HudValue 4)),
1300
+ $sender.Height
1301
+ )
1302
+ $flags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor
1303
+ [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor
1304
+ [System.Windows.Forms.TextFormatFlags]::SingleLine -bor
1305
+ [System.Windows.Forms.TextFormatFlags]::NoPadding
1306
+ [System.Windows.Forms.TextRenderer]::DrawText($event.Graphics, $text, $drawFont, $rect, $sender.ForeColor, $flags)
1307
+ } finally {
1308
+ if ($disposeDrawFont -and $drawFont) { $drawFont.Dispose() }
1309
+ }
1310
+ })
1155
1311
  return $box
1156
1312
  }
1157
1313
 
1158
1314
  function New-HudLineIconBox {
1159
1315
  $box = New-Object System.Windows.Forms.PictureBox
1160
- $box.Width = 21
1161
- $box.Height = 18
1316
+ $box.Width = Scale-HudValue 21
1317
+ $box.Height = Scale-HudValue 18
1162
1318
  $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1163
1319
  $box.BackColor = $form.BackColor
1164
- $box.Margin = [System.Windows.Forms.Padding]::new(3, 0, 0, 0)
1320
+ $box.Margin = New-HudPadding 3 0 0 0
1165
1321
  return $box
1166
1322
  }
1167
1323
 
1168
1324
  function New-HudDivider {
1169
1325
  $divider = New-Object System.Windows.Forms.Panel
1170
1326
  $divider.AutoSize = $false
1171
- $divider.Width = 1
1172
- $divider.Height = 12
1327
+ $divider.Width = Scale-HudValue 1
1328
+ $divider.Height = Scale-HudValue 12
1173
1329
  $divider.BackColor = Get-DividerColor
1174
- $divider.Margin = [System.Windows.Forms.Padding]::new(4, 3, 4, 3)
1330
+ $divider.Margin = New-HudPadding 4 3 4 3
1175
1331
  return $divider
1176
1332
  }
1177
1333
 
@@ -1194,10 +1350,10 @@ $claudeExtraLabel = New-HudLabel
1194
1350
 
1195
1351
  foreach ($label in @($codexPrefixLabel, $claudePrefixLabel)) {
1196
1352
  $label.AutoSize = $false
1197
- $label.Width = 48
1353
+ $label.Width = Scale-HudValue 48
1198
1354
  }
1199
1355
  foreach ($label in @($codexIconLabel, $claudeIconLabel)) {
1200
- $label.Width = 38
1356
+ $label.Width = Scale-HudValue 42
1201
1357
  }
1202
1358
 
1203
1359
  $codexHudControls = @($codexPrefixLabel, $codexIconLabel, $codexDivider1, $codexResetLabel, $codexDivider2, $codexWeekLabel, $codexExtraLabel)
@@ -1224,7 +1380,7 @@ $panel.Controls.Add($claudeRow, 0, 1) | Out-Null
1224
1380
  $form.Controls.Add($panel)
1225
1381
 
1226
1382
  $hitForm = $null
1227
- if (-not $ClickThrough) {
1383
+ if ((-not $ClickThrough) -and $script:hudTransparentSurface) {
1228
1384
  $hitForm = New-Object System.Windows.Forms.Form
1229
1385
  $hitForm.Text = "AI Battery hit area"
1230
1386
  $hitForm.Width = $form.Width
@@ -1685,15 +1841,23 @@ function Stop-FullscreenEventHooks {
1685
1841
 
1686
1842
  function Set-HudBatteryImage($Box, [Nullable[int]]$Percent, [bool]$Running) {
1687
1843
  $oldImage = $Box.Image
1688
- $Box.Image = New-BatteryImage $Percent $Running
1844
+ $Box.Image = New-BatteryImage $Percent $Running 36 16 $false
1845
+ $Box.AccessibleName = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
1846
+ $Box.ForeColor = if ($Running) {
1847
+ [System.Drawing.Color]::FromArgb(255, 255, 255)
1848
+ } else {
1849
+ [System.Drawing.Color]::FromArgb(235, 235, 235)
1850
+ }
1689
1851
  $Box.Visible = $true
1690
1852
  $Box.Tag = $true
1853
+ $Box.Invalidate()
1691
1854
  if ($oldImage) { $oldImage.Dispose() }
1692
1855
  }
1693
1856
 
1694
1857
  function New-HudGlyphImage([string]$Kind, [System.Drawing.Color]$Color, [int]$Width = 21, [int]$Height = 18) {
1695
- $bitmap = [System.Drawing.Bitmap]::new($Width, $Height)
1696
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
1858
+ $surface = New-HudBitmapSurface $Width $Height
1859
+ $bitmap = $surface.Bitmap
1860
+ $graphics = $surface.Graphics
1697
1861
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1698
1862
  $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
1699
1863
  $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
@@ -1831,7 +1995,11 @@ function Set-HudMetricLabel($Label, [string]$Value, [System.Drawing.Color]$Color
1831
1995
  $Label.Visible = $false
1832
1996
  $Label.Tag = $false
1833
1997
  } else {
1834
- $Label.Width = if ($null -ne $FixedWidth -and $FixedWidth -gt 0) { [int]$FixedWidth } else { (Get-LabelTextWidth $Label) + 1 }
1998
+ $Label.Width = if ($null -ne $FixedWidth -and $FixedWidth -gt 0) {
1999
+ [int]$FixedWidth
2000
+ } else {
2001
+ (Get-LabelTextWidth $Label) + (Scale-HudValue 1)
2002
+ }
1835
2003
  $Label.Visible = $true
1836
2004
  $Label.Tag = $true
1837
2005
  }
@@ -1844,22 +2012,40 @@ function Set-HudDivider($Divider, [string]$Value) {
1844
2012
  $Divider.Tag = $false
1845
2013
  } else {
1846
2014
  $Divider.Visible = $true
1847
- $Divider.Width = 1
2015
+ $Divider.Width = Scale-HudValue 1
1848
2016
  $Divider.Tag = $true
1849
2017
  }
1850
2018
  }
1851
2019
 
1852
- function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel) {
2020
+ function Get-HudTextWidth([string]$Value, $Font = $font) {
2021
+ if ([string]::IsNullOrWhiteSpace($Value)) { return 0 }
2022
+ return [System.Windows.Forms.TextRenderer]::MeasureText(
2023
+ $Value,
2024
+ $Font,
2025
+ [System.Drawing.Size]::new(1000, 1000),
2026
+ [System.Windows.Forms.TextFormatFlags]::NoPadding
2027
+ ).Width
2028
+ }
2029
+
2030
+ function Get-SharedHudColumnWidth([string[]]$Values, [int]$Minimum = 0) {
2031
+ $width = Scale-HudValue $Minimum
2032
+ foreach ($value in $Values) {
2033
+ $width = [math]::Max($width, (Get-HudTextWidth $value) + (Scale-HudValue 1))
2034
+ }
2035
+ return [int]$width
2036
+ }
2037
+
2038
+ function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel, [Nullable[int]]$ResetWidth = $null, [Nullable[int]]$WeekWidth = $null) {
1853
2039
  $PrefixLabel.Text = $Parts.Prefix
1854
2040
  $PrefixLabel.ForeColor = $Parts.TextColor
1855
- $PrefixLabel.Width = 48
2041
+ $PrefixLabel.Width = Scale-HudValue 48
1856
2042
  $PrefixLabel.Visible = $true
1857
2043
  $PrefixLabel.Tag = $true
1858
2044
  Set-HudBatteryImage $BatteryBox $Parts.Percent $Parts.Running
1859
2045
  Set-HudDivider $Divider1 $Parts.ResetValue
1860
- Set-HudMetricLabel $ResetLabel $Parts.ResetValue $Parts.TextColor 52
2046
+ Set-HudMetricLabel $ResetLabel $Parts.ResetValue $Parts.TextColor $ResetWidth
1861
2047
  Set-HudDivider $Divider2 $Parts.WeekValue
1862
- Set-HudMetricLabel $WeekLabel $Parts.WeekValue $Parts.TextColor 52
2048
+ Set-HudMetricLabel $WeekLabel $Parts.WeekValue $Parts.TextColor $WeekWidth
1863
2049
  Set-HudMetricLabel $ExtraLabel $Parts.ExtraText $Parts.TextColor
1864
2050
  }
1865
2051
 
@@ -1906,8 +2092,8 @@ function Resize-HudToContent {
1906
2092
  $contentWidth = [math]::Max($codexWidth, $claudeWidth)
1907
2093
  $desiredWidth = $panel.Padding.Left + $panel.Padding.Right +
1908
2094
  $contentWidth +
1909
- 1
1910
- $desiredWidth = [math]::Max(150, [int][math]::Ceiling($desiredWidth))
2095
+ (Scale-HudValue 1)
2096
+ $desiredWidth = [math]::Max((Scale-HudValue 150), [int][math]::Ceiling($desiredWidth))
1911
2097
 
1912
2098
  $bothRows = $script:codexRowVisible -and $script:claudeRowVisible
1913
2099
  $desiredHeight = [int]$(if ($bothRows) { $script:hudTwoRowHeight } else { $script:hudOneRowHeight })
@@ -1936,7 +2122,7 @@ function Resize-HudToContent {
1936
2122
  function Show-HudMessage([string]$Message) {
1937
2123
  $codexPrefixLabel.Text = $Message
1938
2124
  $codexPrefixLabel.ForeColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
1939
- $codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + 1
2125
+ $codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + (Scale-HudValue 1)
1940
2126
  $codexPrefixLabel.Visible = $true
1941
2127
  $codexPrefixLabel.Tag = $true
1942
2128
  foreach ($label in @($codexResetLabel, $codexWeekLabel, $codexExtraLabel, $claudePrefixLabel, $claudeResetLabel, $claudeWeekLabel, $claudeExtraLabel)) {
@@ -1974,16 +2160,28 @@ function Update-HudFromSnapshot($Snapshot) {
1974
2160
  $texts = ConvertTo-HudTexts $Snapshot
1975
2161
  $script:codexRowVisible = [bool]$texts.CodexVisible
1976
2162
  $script:claudeRowVisible = [bool]$texts.ClaudeVisible
2163
+ $resetValues = @()
2164
+ $weekValues = @()
2165
+ if ($texts.CodexVisible) {
2166
+ if ($texts.Codex.ResetValue) { $resetValues += $texts.Codex.ResetValue }
2167
+ if ($texts.Codex.WeekValue) { $weekValues += $texts.Codex.WeekValue }
2168
+ }
2169
+ if ($texts.ClaudeVisible) {
2170
+ if ($texts.Claude.ResetValue) { $resetValues += $texts.Claude.ResetValue }
2171
+ if ($texts.Claude.WeekValue) { $weekValues += $texts.Claude.WeekValue }
2172
+ }
2173
+ $resetWidth = Get-SharedHudColumnWidth $resetValues
2174
+ $weekWidth = Get-SharedHudColumnWidth $weekValues
1977
2175
  if ($texts.CodexVisible) {
1978
2176
  $codexRow.Visible = $true
1979
- Set-HudParts $texts.Codex $codexPrefixLabel $codexIconLabel $codexDivider1 $codexResetLabel $codexDivider2 $codexWeekLabel $codexExtraLabel
2177
+ Set-HudParts $texts.Codex $codexPrefixLabel $codexIconLabel $codexDivider1 $codexResetLabel $codexDivider2 $codexWeekLabel $codexExtraLabel $resetWidth $weekWidth
1980
2178
  } else {
1981
2179
  $codexRow.Visible = $false
1982
2180
  Set-HudControlsVisible $codexHudControls $false
1983
2181
  }
1984
2182
  if ($texts.ClaudeVisible) {
1985
2183
  $claudeRow.Visible = $true
1986
- Set-HudParts $texts.Claude $claudePrefixLabel $claudeIconLabel $claudeDivider1 $claudeResetLabel $claudeDivider2 $claudeWeekLabel $claudeExtraLabel
2184
+ Set-HudParts $texts.Claude $claudePrefixLabel $claudeIconLabel $claudeDivider1 $claudeResetLabel $claudeDivider2 $claudeWeekLabel $claudeExtraLabel $resetWidth $weekWidth
1987
2185
  } else {
1988
2186
  $claudeRow.Visible = $false
1989
2187
  Set-HudControlsVisible $claudeHudControls $false
package/bin/ai-battery.js CHANGED
@@ -1532,6 +1532,25 @@ function codexRunnerExists(runnerPath = codexRunnerPath()) {
1532
1532
  return isExecutable(runnerPath);
1533
1533
  }
1534
1534
 
1535
+ function requestedRowptyConptyMode() {
1536
+ return String(process.env.AI_BATTERY_ROWPTY_CONPTY || process.env.CLAUDEX_BATTERY_ROWPTY_CONPTY || "os").toLowerCase();
1537
+ }
1538
+
1539
+ function bundledRowptyConptyRequested() {
1540
+ return ["bundled", "node-pty", "nodepty", "auto", "default"].includes(requestedRowptyConptyMode());
1541
+ }
1542
+
1543
+ function rowptyDiagnostic(rowpty, platform = process.platform) {
1544
+ if (platform !== "win32") return null;
1545
+ const bundledConpty = rowpty ? fs.existsSync(path.join(path.dirname(rowpty), "conpty.dll")) : false;
1546
+ return {
1547
+ path: rowpty,
1548
+ installed: Boolean(rowpty),
1549
+ bundledConpty,
1550
+ bundledConptyRequested: bundledRowptyConptyRequested()
1551
+ };
1552
+ }
1553
+
1535
1554
  function diagnoseCodex() {
1536
1555
  const config = readConfig();
1537
1556
  const configuredWrapper = config.codexWrapper?.wrapperPath || codexWrapperPathInDir(defaultCodexShimDir());
@@ -1574,13 +1593,11 @@ function diagnoseCodex() {
1574
1593
  notes.push(`AI Battery runner is missing or not executable: ${runnerPath}`);
1575
1594
  }
1576
1595
  const rowpty = process.platform === "win32" ? rowptyExePath() : null;
1577
- const rowptyConpty = rowpty ? fs.existsSync(path.join(path.dirname(rowpty), "conpty.dll")) : false;
1578
- const requestedRowptyConpty = String(process.env.AI_BATTERY_ROWPTY_CONPTY || process.env.CLAUDEX_BATTERY_ROWPTY_CONPTY || "os").toLowerCase();
1579
- const bundledRowptyConptyRequested = ["bundled", "node-pty", "nodepty", "auto", "default"].includes(requestedRowptyConpty);
1596
+ const rowptyInfo = rowptyDiagnostic(rowpty);
1580
1597
  if (wrapperInstalled && process.platform === "win32" && !rowpty) {
1581
1598
  notes.push("rowpty.exe not found, so the Codex bottom row uses the overlay fallback. Run: ai-battery setup codex (compiles it locally with the in-box csc.exe).");
1582
1599
  }
1583
- if (rowpty && bundledRowptyConptyRequested && !rowptyConpty) {
1600
+ if (rowpty && rowptyInfo?.bundledConptyRequested && !rowptyInfo.bundledConpty) {
1584
1601
  notes.push("Bundled ConPTY was requested, but conpty.dll is not next to rowpty.exe. Run: ai-battery setup codex with the node-pty package installed, or unset AI_BATTERY_ROWPTY_CONPTY to use the faster OS ConPTY default.");
1585
1602
  }
1586
1603
  if (wrapperInstalled && process.platform !== "win32" && !python3) {
@@ -1601,9 +1618,7 @@ function diagnoseCodex() {
1601
1618
  wrapperInstalled,
1602
1619
  runnerPath,
1603
1620
  runnerExists,
1604
- rowpty: process.platform === "win32"
1605
- ? { path: rowpty, installed: Boolean(rowpty), bundledConpty: rowptyConpty, bundledConptyRequested }
1606
- : null,
1621
+ rowpty: rowptyInfo,
1607
1622
  statusLine,
1608
1623
  python3,
1609
1624
  originalCommand: configuredOriginal,
@@ -4471,6 +4486,7 @@ export {
4471
4486
  removeAiBatteryShellPathBlock,
4472
4487
  percentValue,
4473
4488
  providerRunningInProcesses,
4489
+ rowptyDiagnostic,
4474
4490
  sameFilePath,
4475
4491
  visibleWidth,
4476
4492
  uninstallClaudeStatusline,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-battery",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Tiny terminal battery meter for local Codex and Claude Code usage.",
5
5
  "type": "module",
6
6
  "keywords": [