Skip to content
Merged
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
55 changes: 52 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Text.Json;

namespace WeeklyUsageIndicator;
Expand Down Expand Up @@ -54,6 +55,7 @@ internal sealed class UsageIndicatorForm : Form
private bool _isRefreshing;
private bool _isHovered;
private bool _isDragging;
private bool _keepOnTop = true;
private Point _dragCursorStart;
private Point _dragFormStart;

Expand Down Expand Up @@ -137,7 +139,12 @@ private void BuildContextMenu()
Checked = true,
CheckOnClick = true
};
topMostItem.CheckedChanged += (_, _) => TopMost = topMostItem.Checked;
topMostItem.CheckedChanged += (_, _) =>
{
_keepOnTop = topMostItem.Checked;
TopMost = _keepOnTop;
ReassertTopMost();
};

var copyItem = new ToolStripMenuItem("현재 상태 복사");
copyItem.Click += (_, _) =>
Expand Down Expand Up @@ -166,6 +173,12 @@ private void PlaceNearTaskbar()
workingArea.Bottom - Height - 18);
}

private void ReassertTopMost()
{
if (!_keepOnTop || !Visible || !IsHandleCreated) return;
_ = NativeWindow.TrySetTopMost(Handle);
}

private void SyncCodexVisibility()
{
var codexIsRunning = _codexStateReader.IsRunning();
Expand Down Expand Up @@ -193,7 +206,11 @@ private void SyncCodexVisibility()

if (!Visible) Show();
Opacity = 1;
TopMost = true;
if (_keepOnTop)
{
TopMost = true;
ReassertTopMost();
}
}

private async Task RefreshUsageAsync(bool force = false)
Expand Down Expand Up @@ -388,6 +405,38 @@ private static GraphicsPath RoundedRectangle(RectangleF rectangle, float radius)
}
}

internal static class NativeWindow
{
private static readonly IntPtr HwndTopMost = new(-1);
private const uint SwpNoSize = 0x0001;
private const uint SwpNoMove = 0x0002;
private const uint SwpNoActivate = 0x0010;
private const uint SwpShowWindow = 0x0040;

public static bool TrySetTopMost(IntPtr windowHandle)
{
return SetWindowPos(
windowHandle,
HwndTopMost,
0,
0,
0,
0,
SwpNoSize | SwpNoMove | SwpNoActivate | SwpShowWindow);
}

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(
IntPtr windowHandle,
IntPtr insertAfter,
int x,
int y,
int width,
int height,
uint flags);
}

internal sealed class CodexDesktopStateReader
{
public bool IsRunning()
Expand Down Expand Up @@ -481,7 +530,7 @@ await CallCoreAsync(
{
name = "weekly-usage-indicator",
title = "Weekly Usage Indicator",
version = "1.1.0"
version = "1.1.1"
},
capabilities = new { experimentalApi = true }
},
Expand Down
2 changes: 1 addition & 1 deletion src/WeeklyUsageIndicator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>WeeklyUsageIndicator</AssemblyName>
<RootNamespace>WeeklyUsageIndicator</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
<Deterministic>true</Deterministic>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
Expand Down