diff --git a/src/iaccessible.h b/src/iaccessible.h index 752187b..6e5909d 100644 --- a/src/iaccessible.h +++ b/src/iaccessible.h @@ -514,4 +514,24 @@ bool IsOnDialog(HWND hwnd, POINT pt) { return flag; } +// Whether the mouse is on the close button of a tab. +// Should be used together with `IsOnOneTab` to search the close button. +bool IsOnCloseButton(NodePtr top, POINT pt) { + bool flag = false; + TraversalAccessible( + top, + [&pt, &flag](NodePtr child) { + if (GetAccessibleRole(child) == ROLE_SYSTEM_PUSHBUTTON) { + GetAccessibleSize(child, [&pt, &flag](RECT rect) { + if (PtInRect(&rect, pt)) { + flag = true; + } + }); + } + return flag; + }, + true); // raw_traversal + return flag; +} + #endif // IACCESSIBLE_H_ diff --git a/src/tabbookmark.h b/src/tabbookmark.h index 756281f..a04b151 100644 --- a/src/tabbookmark.h +++ b/src/tabbookmark.h @@ -123,18 +123,18 @@ int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) { } bool is_on_one_tab = IsOnOneTab(top_container_view, pmouse->pt); + bool is_on_close_button = IsOnCloseButton(top_container_view, pmouse->pt); bool is_only_one_tab = IsOnlyOneTab(top_container_view); - - if (is_on_one_tab) { - if (is_only_one_tab) { - ExecuteCommand(IDC_NEW_TAB, hwnd); - ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); - } else { - ExecuteCommand(IDC_CLOSE_TAB, hwnd); - } - return 1; + if (!is_on_one_tab || is_on_close_button) { + return 0; } - return 0; + if (is_only_one_tab) { + ExecuteCommand(IDC_NEW_TAB, hwnd); + ExecuteCommand(IDC_WINDOW_CLOSE_OTHER_TABS, hwnd); + } else { + ExecuteCommand(IDC_CLOSE_TAB, hwnd); + } + return 1; } // Right-click to close tab (Hold Shift to show the original menu).