Skip to content

Commit 5708463

Browse files
kjkclaude
andcommitted
fix stale close button hover state in TabsCtrl
Use actual cursor position in Paint() instead of stale lastMousePos, and verify cursor is inside the client rect. Reset tabHighlightedClose on WM_MOUSELEAVE. Add null check for tabInfo before accessing canClose. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 5ea3e81 commit 5708463

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/wingui/TabsCtrl.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,16 @@ bool TabsCtrl::IsValidIdx(int idx) {
174174
}
175175

176176
void TabsCtrl::Paint(HDC hdc, const RECT& rc) {
177-
TabsCtrl::MouseState tabState = TabStateFromMousePosition(lastMousePos);
177+
// verify the cursor is actually inside the tab control; if not, ignore stale lastMousePos
178+
Point cursorPos = HwndGetCursorPos(hwnd);
179+
Rect clientRc = ClientRect(hwnd);
180+
bool mouseInside = clientRc.Contains(cursorPos);
181+
TabsCtrl::MouseState tabState;
182+
if (mouseInside) {
183+
tabState = TabStateFromMousePosition(cursorPos);
184+
}
178185
int tabUnderMouse = tabState.tabIdx;
179-
bool overClose = tabState.overClose && tabState.tabInfo->canClose;
186+
bool overClose = tabState.overClose && tabState.tabInfo && tabState.tabInfo->canClose;
180187
int selectedIdx = GetSelected();
181188
if (IsValidIdx(tabForceShowSelected)) {
182189
selectedIdx = tabForceShowSelected;
@@ -524,8 +531,9 @@ LRESULT TabsCtrl::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
524531
break;
525532

526533
case WM_MOUSELEAVE:
527-
if (tabHighlighted != tabUnderMouse) {
534+
if (tabHighlighted != tabUnderMouse || tabHighlightedClose != -1) {
528535
tabHighlighted = tabUnderMouse;
536+
tabHighlightedClose = -1;
529537
HwndScheduleRepaint(hwnd);
530538
}
531539
break;

0 commit comments

Comments
 (0)